|
| 1 | +import { Checkbox, HStack } from '@amalgama/react-native-ui-kit' |
| 2 | +import CodePreview from '@site/src/components/CodePreview'; |
| 3 | +import DynamicCheckbox from '@site/src/components/DynamicCheckbox'; |
| 4 | +import { useState } from 'react' |
| 5 | + |
| 6 | + |
| 7 | +# Checkbox |
| 8 | + |
| 9 | +## Import |
| 10 | + |
| 11 | +To add the `Checkbox` component to your project you can import it as follows: |
| 12 | + |
| 13 | +```tsx |
| 14 | +import { Checkbox } from '@amalgama/react-native-ui-kit'; |
| 15 | +``` |
| 16 | + |
| 17 | +## Examples |
| 18 | +<CodePreview> |
| 19 | + <DynamicCheckbox /> |
| 20 | +</CodePreview> |
| 21 | + |
| 22 | +```jsx |
| 23 | +import { Checkbox } from '@amalgama/react-native-ui-kit'; |
| 24 | +import React, { useState } from 'react'; |
| 25 | + |
| 26 | +const App = () => { |
| 27 | + const [ isSelected, setSelected ] = useState( false ); |
| 28 | + return ( |
| 29 | + <Checkbox |
| 30 | + isSelected={ isSelected } |
| 31 | + onChange={ () => { setSelected( !isSelected ); } } |
| 32 | + /> |
| 33 | + ); |
| 34 | +}; |
| 35 | +``` |
| 36 | + |
| 37 | +## Props |
| 38 | + |
| 39 | +### isSelected |
| 40 | +If the checkbox is selected or not. |
| 41 | + |
| 42 | +| TYPE | REQUIRED | DEFAULT | |
| 43 | +| ---- | -------- | ------- | |
| 44 | +| bool | No | false | |
| 45 | + |
| 46 | +<CodePreview> |
| 47 | + <HStack> |
| 48 | + <Checkbox /> |
| 49 | + <Checkbox isSelected /> |
| 50 | + </HStack> |
| 51 | +</CodePreview> |
| 52 | + |
| 53 | +### isIndeterminated |
| 54 | +If the checkbox is indeterminated or not. This is usually used for lists of checkboxes when some of their children are checked but not all of them. This is only a visual state, it only changes the checkbox icon. |
| 55 | + |
| 56 | +| TYPE | REQUIRED | DEFAULT | |
| 57 | +| ---- | -------- | ------- | |
| 58 | +| bool | No | false | |
| 59 | + |
| 60 | +<CodePreview> |
| 61 | + <Checkbox isIndeterminated/> |
| 62 | +</CodePreview> |
| 63 | + |
| 64 | +### disabled |
| 65 | +If the checkbox is disabled or not. |
| 66 | + |
| 67 | +| TYPE | REQUIRED | DEFAULT | |
| 68 | +| ---- | -------- | ------- | |
| 69 | +| bool | No | false | |
| 70 | + |
| 71 | +<CodePreview> |
| 72 | + <HStack> |
| 73 | + <Checkbox disabled /> |
| 74 | + <Checkbox disabled isSelected /> |
| 75 | + <Checkbox disabled isIndeterminated /> |
| 76 | + </HStack> |
| 77 | +</CodePreview> |
| 78 | + |
| 79 | +### onChange |
| 80 | +Invoked when the checkbox is pressed. |
| 81 | + |
| 82 | +| TYPE | REQUIRED | |
| 83 | +| -------- | -------- | |
| 84 | +| function | No | |
| 85 | + |
| 86 | +<CodePreview> |
| 87 | + <Checkbox onChange={ () => { window.alert( 'The checkbox was pressed!' ) } }/> |
| 88 | +</CodePreview> |
| 89 | + |
| 90 | +```jsx |
| 91 | +<Checkbox onChange={ () => { window.alert( 'The checkbox was pressed!' ) } }/> |
| 92 | +``` |
| 93 | + |
| 94 | +## Accessibility props |
| 95 | +[React Native accessibility docs](https://reactnative.dev/docs/accessibility) |
| 96 | + |
| 97 | +### accessible |
| 98 | +Sets the component to an accessibility element. It is set by default to `true`. |
| 99 | + |
| 100 | +### accessibilityRole |
| 101 | +Communicates the purpose of the component. It is set by default to `"checkbox"`. |
| 102 | + |
| 103 | +### accessibilityState |
| 104 | +Describes the current state of the element. By default, indicates if the `Checkbox` is `disabled`, `isSelected` and `isIndeterminated`. |
0 commit comments