callstack / callstack/react-native-paper

Replace status prop with checked in ToggleButton component

Aperta
#4,866 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
feature request
Lingua principale
TypeScript
Stelle
14.5k
Fork
2.2k
Merge medio
5g 23h
PR unite (30g)
12

Descrizione

**Is your feature request related to a problem? Please describe.**
The `ToggleButton` component currently uses a `status` prop with string values `checked` | `unchecked`. This adds unnecessary complexity for a binary state.

**Describe the solution you'd like**
Replace the `status` prop with a boolean `checked` prop.

Before:
```typescript
const ToggleButtonExample = () => {
const [status, setStatus] = React.useState('checked');

const onButtonToggle = () => {
setStatus(status === 'checked' ? 'unchecked' : 'checked');
};

return (

);
};
```

After:
```typescript
const ToggleButtonExample = () => {
const [isChecked, setIsChecked] = React.useState(true);

const onButtonToggle = () => {
setIsChecked(s => !s);
};

return (

);
};
```

**Additional context**
A boolean checked prop is simpler, clearer, and more consistent with common React patterns than using string values like 'checked' and 'unchecked'.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.