@@ -35,17 +35,17 @@ focus and update a checkbox input with the keyboard.
35
35
36
36
## Quick Start
37
37
38
- [ Check out the example on CodeSandbox] ( https://codesandbox.io/s/accessiblecheckbox-examples-epc8b )
38
+ [ Check out the example on ** CodeSandbox** ] ( https://codesandbox.io/s/accessiblecheckbox-examples-epc8b )
39
39
40
40
``` jsx harmony
41
41
import {Checkbox , Checkmark } from ' @accessible/checkbox'
42
42
43
43
const MyCheckbox = () => (
44
- < label className= " my-checkbox" >
45
- < Checkbox name= " my-field-name" >
46
- < span className= " my-checkbox" >
47
- < Checkmark checkedClass= " checked" uncheckedClass= " unchecked" >
48
- < span className= " checkmark" / >
44
+ < label className= ' my-checkbox' >
45
+ < Checkbox name= ' my-field-name' >
46
+ < span className= ' my-checkbox' >
47
+ < Checkmark checkedClass= ' checked' uncheckedClass= ' unchecked' >
48
+ < span className= ' checkmark' / >
49
49
< / Checkmark>
50
50
< / span>
51
51
< / Checkbox>
@@ -56,7 +56,7 @@ const MyCheckbox = () => (
56
56
57
57
## API
58
58
59
- ### ` < Checkbox> `
59
+ ### & lt ; Checkbox& gt ;
60
60
61
61
Creates a visually hidden checkbox input that is focusable and accessible via keyboard navigation.
62
62
All props passed to this component are applied to the ` <input> ` . This also creates a context
@@ -65,28 +65,28 @@ deep in the tree.
65
65
66
66
#### Props
67
67
68
- | Prop | Type | Default | Required? | Description |
69
- | -------------- | ----------------------------------------------------------------------------------------------------------------- | ----------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
70
- | checked | ` boolean ` | ` undefined ` | No | Makes the checkbox a controlled component which can no longer be updated with ` check ` , ` uncheck ` , and ` toggle ` controls. |
71
- | defaultChecked | ` boolean ` | ` undefined ` | No | Set this to ` true ` to make the checkbox ` checked ` by default. |
72
- | onChange | ` (checked: boolean) => any ` | ` undefined ` | No | Called each time the ` checked ` state changes. |
73
- | children | < code > React.ReactNode &# 124 ; React.ReactNode [ ] &# 124 ; ((context: CheckboxContextValue) => React.ReactNode)</ code > | ` undefined ` | No | Your custom styled checkbox. |
68
+ | Prop | Type | Default | Required? | Description |
69
+ | -------------- | --------------------------- | ----------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
70
+ | checked | ` boolean ` | ` undefined ` | No | Makes the checkbox a controlled component which can no longer be updated with ` check ` , ` uncheck ` , and ` toggle ` controls. |
71
+ | defaultChecked | ` boolean ` | ` undefined ` | No | Set this to ` true ` to make the checkbox ` checked ` by default. |
72
+ | onChange | ` (checked: boolean) => any ` | ` undefined ` | No | Called each time the ` checked ` state changes. |
73
+ | children | ` React.ReactNode ` | ` undefined ` | No | Your custom styled checkbox. |
74
74
75
- ### ` < Checkmark> `
75
+ ### & lt ; Checkmark& gt ;
76
76
77
77
A convenient component for conditionally adding class names and styles when the component is checked/unchecked.
78
78
79
79
#### Props
80
80
81
- | Prop | Type | Default | Required? | Description |
82
- | -------------- | --------------------- | --------------------- | --------- | -------------------------------------------------------------------------------------- |
83
- | uncheckedClass | ` string ` | ` undefined ` | No | This class name will be applied to the child element when the checkbox is ` unchecked ` . |
84
- | checkedClass | ` string ` | ` "checkbox--checked" ` | No | This class name will be applied to the child element when the checkbox is ` checked ` . |
85
- | uncheckedStyle | ` React.CSSProperties ` | ` undefined ` | No | These styles will be applied to the child element when the checkbox is ` unchecked ` . |
86
- | checkedStyle | ` React.CSSProperties ` | ` undefined ` | No | These styles name will be applied to the child element when the checkbox is ` checked ` . |
87
- | children | ` React.ReactNode ` | ` undefined ` | Yes | The child you wish to render when the checkbox is checked. |
81
+ | Prop | Type | Default | Required? | Description |
82
+ | -------------- | --------------------- | ----------- | --------- | -------------------------------------------------------------------------------------- |
83
+ | uncheckedClass | ` string ` | ` undefined ` | No | This class name will be applied to the child element when the checkbox is ` unchecked ` . |
84
+ | checkedClass | ` string ` | ` undefined ` | No | This class name will be applied to the child element when the checkbox is ` checked ` . |
85
+ | uncheckedStyle | ` React.CSSProperties ` | ` undefined ` | No | These styles will be applied to the child element when the checkbox is ` unchecked ` . |
86
+ | checkedStyle | ` React.CSSProperties ` | ` undefined ` | No | These styles name will be applied to the child element when the checkbox is ` checked ` . |
87
+ | children | ` React.ReactNode ` | ` undefined ` | Yes | The child you wish to render when the checkbox is checked. |
88
88
89
- ### ` < Checked> `
89
+ ### & lt ; Checked& gt ;
90
90
91
91
The child of this component will only render when the ` <Checkbox> ` is in
92
92
a ` checked ` state. It must be a child of a ` <Checkbox> ` .
@@ -97,7 +97,7 @@ a `checked` state. It must be a child of a `<Checkbox>`.
97
97
| -------- | ----------------- | ----------- | --------- | ---------------------------------------------------------- |
98
98
| children | ` React.ReactNode ` | ` undefined ` | Yes | The child you wish to render when the checkbox is checked. |
99
99
100
- ### ` < Unchecked> `
100
+ ### & lt ; Unchecked& gt ;
101
101
102
102
The child of this component will only render when the ` <Checkbox> ` is in
103
103
an ` unchecked ` state. It must be a child of a ` <Checkbox> ` .
@@ -108,7 +108,7 @@ an `unchecked` state. It must be a child of a `<Checkbox>`.
108
108
| -------- | ----------------- | ----------- | --------- | ------------------------------------------------------------ |
109
109
| children | ` React.ReactNode ` | ` undefined ` | Yes | The child you wish to render when the checkbox is unchecked. |
110
110
111
- ### ` < Toggle> `
111
+ ### & lt ; Toggle& gt ;
112
112
113
113
This component clones its child and adds an ` onClick ` handler to toggle the ` <Checkbox> ` between
114
114
` checked ` and ` unchecked ` states. It must be a child of a ` <Checkbox> ` .
@@ -119,11 +119,11 @@ This component clones its child and adds an `onClick` handler to toggle the `<Ch
119
119
| -------- | ----------------- | ----------- | --------- | ------------------------------------------------------------ |
120
120
| children | ` React.ReactNode ` | ` undefined ` | Yes | The child you wish to render when the checkbox is unchecked. |
121
121
122
- ### ` useCheckbox() `
122
+ ### useCheckbox()
123
123
124
124
A React hook that returns the [ ` CheckboxContextValue ` ] ( #checkboxcontextvalue ) for the nearest ` <Checkbox> ` parent.
125
125
126
- ### ` CheckboxContextValue `
126
+ ### CheckboxContextValue
127
127
128
128
``` typescript
129
129
interface CheckboxContextValue {
@@ -142,31 +142,6 @@ interface CheckboxContextValue {
142
142
}
143
143
```
144
144
145
- ### ` useChecked() `
146
-
147
- Returns ` true ` when the ` <Checkbox> ` is checked, otherwise ` false `
148
-
149
- ### ` useFocused() `
150
-
151
- Returns ` true ` when the ` <Checkbox> ` is focused, otherwise ` false `
152
-
153
- ### ` useDisabled() `
154
-
155
- Returns ` true ` when the ` <Checkbox> ` is disabled, otherwise ` false `
156
-
157
- ### ` useControls() `
158
-
159
- This hook provides access to the ` <Checkbox> ` 's ` check ` , ` uncheck ` , and ` toggle ` functions
160
-
161
- #### Example
162
-
163
- ``` jsx harmony
164
- const Component = () => {
165
- const {check , uncheck , toggle } = useControls ()
166
- return < button onClick= {toggle}> Toggle me< / button>
167
- }
168
- ```
169
-
170
145
## LICENSE
171
146
172
147
MIT
0 commit comments