diff --git a/example/src/Examples/ToggleButtonExample.tsx b/example/src/Examples/ToggleButtonExample.tsx index 29f47aef27..2253b9a3ba 100644 --- a/example/src/Examples/ToggleButtonExample.tsx +++ b/example/src/Examples/ToggleButtonExample.tsx @@ -6,11 +6,23 @@ import { ToggleButton, List } from 'react-native-paper'; import ScreenWrapper from '../ScreenWrapper'; type StatusState = 'checked' | 'unchecked'; +type Fruits = 'watermelon' | 'strawberries'; + +enum FontsEnum { + NoFormat = 'no-format', + Italic = 'italic', + Bold = 'bold', + Underline = 'underlined', + ColorText = 'format-color', +} const ToggleButtonExample = () => { - const [first, setFirst] = React.useState('bold'); - const [fruit, setFruit] = React.useState('watermelon'); + const [first, setFirst] = React.useState('bold'); + const [fruit, setFruit] = React.useState('watermelon'); const [status, setStatus] = React.useState('checked'); + const [font, setFont] = React.useState(FontsEnum.NoFormat); + + const handleFruit = (value: Fruits) => setFruit(value); return ( @@ -26,7 +38,7 @@ const ToggleButtonExample = () => { /> - + setFirst(value)} @@ -38,12 +50,21 @@ const ToggleButtonExample = () => { - + + + + + + + + + - setFruit(value)} - > + = { /** * Function to execute on selection change. */ - onValueChange: (value: string) => void | null; + onValueChange: (value: Value) => void; /** * Value of the currently selected toggle button. */ - value: string | null; + value: Value | null; /** * React elements containing toggle buttons. */ children: React.ReactNode; }; -type ToggleButtonContextType = { - value: string | null; - onValueChange: (item: string) => void | null; +type ToggleButtonContextType = { + value: Value | null; + onValueChange: (item: Value) => void; }; export const ToggleButtonGroupContext = + //@ts-expect-error: TS can't ensure the type from Group to children React.createContext(null as any); /** @@ -54,7 +55,11 @@ export const ToggleButtonGroupContext = * export default MyComponent; *``` */ -const ToggleButtonGroup = ({ value, onValueChange, children }: Props) => ( +const ToggleButtonGroup = ({ + value, + onValueChange, + children, +}: Props) => (