Skip to content

Commit b7dbcb2

Browse files
committed
Add Radio Group component docs, mobile example and web example
1 parent 167632a commit b7dbcb2

File tree

5 files changed

+315
-29
lines changed

5 files changed

+315
-29
lines changed

docs/docs/components/checkbox.md

+68-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Checkbox, HStack } from '@amalgama/react-native-ui-kit'
1+
import { Checkbox, HStack, Icon } from '@amalgama/react-native-ui-kit'
2+
import Feather from 'react-native-vector-icons/Feather';
23
import CodePreview from '@site/src/components/CodePreview';
34
import ExampleCheckbox from '@site/src/components/ExampleCheckbox';
45
import ExampleCheckboxGroup from '@site/src/components/ExampleCheckboxGroup';
@@ -39,7 +40,7 @@ const App = () => {
3940

4041
### Props
4142

42-
### selected
43+
#### selected
4344
If the checkbox is selected or not.
4445

4546
| TYPE | REQUIRED | DEFAULT |
@@ -58,7 +59,7 @@ If the checkbox is selected or not.
5859
<Checkbox selected />
5960
```
6061

61-
### indeterminated
62+
#### indeterminated
6263
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.
6364

6465
| TYPE | REQUIRED | DEFAULT |
@@ -73,7 +74,7 @@ If the checkbox is indeterminated or not. This is usually used for lists of chec
7374
<Checkbox indeterminated />
7475
```
7576

76-
### label
77+
#### label
7778
Shows a label text next to the checkbox icon.
7879

7980
| TYPE | REQUIRED |
@@ -88,7 +89,7 @@ Shows a label text next to the checkbox icon.
8889
<Checkbox label="Checkbox" />
8990
```
9091

91-
### value
92+
#### value
9293
If the checkbox is inside a `Checkbox.Group` this prop indicates the value for it.
9394

9495
| TYPE | REQUIRED |
@@ -99,7 +100,7 @@ If the checkbox is inside a `Checkbox.Group` this prop indicates the value for i
99100
If the `Checkbox` is inside a `Checkbox.Group` this prop is required and will throw an `Exception` if not set.
100101
:::
101102

102-
### disabled
103+
#### disabled
103104
If the checkbox is disabled or not.
104105

105106
| TYPE | REQUIRED | DEFAULT |
@@ -120,7 +121,7 @@ If the checkbox is disabled or not.
120121
<Checkbox disabled indeterminated />
121122
```
122123

123-
### onPress
124+
#### onPress
124125
Invoked when the checkbox is pressed.
125126

126127
| TYPE | REQUIRED |
@@ -135,6 +136,63 @@ Invoked when the checkbox is pressed.
135136
<Checkbox onPress={ () => { window.alert( 'The checkbox was pressed!' ) } }/>
136137
```
137138

139+
#### checkedIcon
140+
An icon component to show when the checkbox is selected. The default value is the `box-checked` icon from the `UIKitIcon` icons package.
141+
142+
<CodePreview>
143+
<Checkbox
144+
selected
145+
checkedIcon={<Icon as={Feather} name="x-square" />}
146+
/>
147+
</CodePreview>
148+
149+
```jsx
150+
import Feather from 'react-native-vector-icons/Feather';
151+
152+
<Checkbox
153+
selected
154+
checkedIcon={<Icon as={Feather} name="x-square" />}
155+
/>
156+
```
157+
158+
#### uncheckedIcon
159+
160+
An icon component to show when the checkbox is unselected. The default value is the `box-unchecked` icon from the `UIKitIcon` icons package.
161+
162+
<CodePreview>
163+
<Checkbox
164+
uncheckedIcon={<Icon as={Feather} name="square" />}
165+
/>
166+
</CodePreview>
167+
168+
```jsx
169+
import Feather from 'react-native-vector-icons/Feather';
170+
171+
<Checkbox
172+
uncheckedIcon={<Icon as={Feather} name="square" />}
173+
/>
174+
```
175+
176+
#### indeterminatedIcon
177+
178+
An icon component to show when the checkbox is inditerminated. The default value is the `box-indeterminated` icon from the `UIKitIcon` icons package.
179+
180+
<CodePreview>
181+
<Checkbox
182+
indeterminated
183+
indeterminatedIcon={<Icon as={Feather} name="minus-square" />}
184+
/>
185+
</CodePreview>
186+
187+
```jsx
188+
import EvilIcons from 'react-native-vector-icons/Feather';
189+
190+
<Checkbox
191+
indeterminated
192+
indeterminatedIcon={<Icon as={Feather} name="minus-square" />}
193+
/>
194+
```
195+
138196
## CheckboxGroup
139197

140198
### Examples
@@ -167,22 +225,22 @@ const ExampleCheckboxGroup = () => {
167225
168226
### Props
169227
170-
### value
228+
#### value
171229
A list containing the selected checkbox values.
172230
173231
| TYPE | REQUIRED | DEFAULT |
174232
| ---------| -------- | ------- |
175233
| string[] | No | [] |
176234
177235
178-
### onChange
236+
#### onChange
179237
Invoked when the group selection changes (because a new option was selected or a previous one was unselected) with the selected option values.
180238
181239
| TYPE | REQUIRED |
182240
| -------- | -------- |
183241
| function | No |
184242
185-
### disabled
243+
#### disabled
186244
If the checkbox is disabled or not.
187245
188246
| TYPE | REQUIRED | DEFAULT |

docs/docs/components/radio.md

+151-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {Radio, HStack} from '@amalgama/react-native-ui-kit'
2-
import {UIKitIcon} from '@amalgama/react-native-ui-kit/'
1+
import {Radio, HStack, Icon} from '@amalgama/react-native-ui-kit'
2+
import Feather from 'react-native-vector-icons/Feather';
33
import CodePreview from '@site/src/components/CodePreview'
44
import ExampleRadio from '@site/src/components/ExampleRadio'
5+
import ExampleRadioGroup from '@site/src/components/ExampleRadioGroup'
56
import {useState} from 'react'
67

78
# Radio
@@ -14,14 +15,32 @@ To add the `Radio` component to your project you can import it as follows:
1415
import {Radio} from '@amalgama/react-native-ui-kit';
1516
```
1617

17-
## Examples
18+
## Standalone
19+
20+
### Example
1821
<CodePreview>
1922
<ExampleRadio/>
2023
</CodePreview>
2124

22-
## Props
25+
```jsx
26+
import { Radio } from '@amalgama/react-native-ui-kit';
27+
import React, { useState } from 'react';
28+
29+
const ExampleRadio = () => {
30+
const [ isSelected, setSelected ] = useState( false );
31+
32+
return (
33+
<Radio
34+
selected={ isSelected }
35+
onPress={ () => { setSelected( prev => !prev ); } }
36+
/>
37+
);
38+
};
39+
```
40+
41+
### Props
2342

24-
### selected
43+
#### selected
2544
If the Radio is selected or not.
2645

2746
| TYPE | REQUIRED | DEFAULT |
@@ -35,7 +54,12 @@ If the Radio is selected or not.
3554
</HStack>
3655
</CodePreview>
3756

38-
### disabled
57+
```jsx
58+
<Radio />
59+
<Radio selected />
60+
```
61+
62+
#### disabled
3963
If the Radio is disabled or not.
4064

4165
| TYPE | REQUIRED | DEFAULT |
@@ -45,12 +69,16 @@ If the Radio is disabled or not.
4569
<CodePreview>
4670
<HStack>
4771
<Radio disabled />
48-
<Radio selected disabled />
72+
<Radio disabled selected />
4973
</HStack>
5074
</CodePreview>
5175

76+
```jsx
77+
<Radio disabled />
78+
<Radio disabled selected />
79+
```
5280

53-
### onPress
81+
#### onPress
5482
Invoked when the Radio is pressed.
5583

5684
| TYPE | REQUIRED |
@@ -65,7 +93,7 @@ Invoked when the Radio is pressed.
6593
<Radio onPress={ () => { window.alert( 'The Radio was pressed!' ) } }/>
6694
```
6795

68-
### label
96+
#### label
6997
Shows a label text next to the radio button icon.
7098

7199
| TYPE | REQUIRED |
@@ -80,25 +108,133 @@ Shows a label text next to the radio button icon.
80108
<Radio label="Radio" />
81109
```
82110

83-
### selectedIcon
111+
#### value
112+
If the radio is inside a `Radio.Group` this prop indicates the value for it.
113+
114+
| TYPE | REQUIRED |
115+
| ------ | -------- |
116+
| string | No |
117+
118+
:::caution
119+
If the `Radio` is inside a `Radio.Group` this prop is required and will throw an `Exception` if not set.
120+
:::
121+
122+
#### selectedIcon
84123
An icon component to show when the radio is selected. The default value is the `circle-filled` icon from the `UIKitIcon` icons package.
85124

125+
<CodePreview>
126+
<Radio
127+
selected
128+
__icon={{ style: { paddingTop: '1px' } }}
129+
selectedIcon={<Icon as={Feather} name="check-circle" />}
130+
/>
131+
</CodePreview>
132+
86133
```jsx
87-
import { UIKitIcon, Icon } from '@amalgama/react-native-ui-kit';
134+
import Feather from 'react-native-vector-icons/Feather';
88135

89136
<Radio
90-
selectedIcon={<Icon as={UIKitIcon} name="plus" />}
137+
selected
138+
selectedIcon={<Icon as={Feather} name="check-circle" />}
91139
/>
92140
```
93141

94-
### unselectedIcon
142+
#### unselectedIcon
95143

96144
An icon component to show when the radio is unselected. The default value is the `circle` icon from the `UIKitIcon` icons package.
97145

146+
<CodePreview>
147+
<Radio
148+
__icon={{ style: { paddingTop: '1px' } }}
149+
unselectedIcon={<Icon as={Feather} name="circle" />}
150+
/>
151+
</CodePreview>
152+
98153
```jsx
99-
import { UIKitIcon, Icon } from '@amalgama/react-native-ui-kit';
154+
import Feather from 'react-native-vector-icons/Feather';
100155

101156
<Radio
102-
unselectedIcon={<Icon as={UIKitIcon} name="plus" />}
157+
unselectedIcon={<Icon as={Feather} name="circle" />}
103158
/>
104159
```
160+
161+
## RadioGroup
162+
163+
### Example
164+
<CodePreview>
165+
<ExampleRadioGroup />
166+
</CodePreview>
167+
168+
```jsx
169+
import React, { useState } from 'react';
170+
import { Radio, Text, VStack } from '@amalgama/react-native-ui-kit';
171+
172+
const ExampleRadioGroup = () => {
173+
const [ value, setValue ] = useState();
174+
175+
return (
176+
<VStack>
177+
<Text variant="sh1">What is your favorite coding language?</Text>
178+
<Radio.Group value={value} onChange={setValue}>
179+
<Radio value="js" label="Javascript" />
180+
<Radio value="ts" label="Typescript" />
181+
<Radio value="rb" label="Ruby" />
182+
<Radio value="python" label="Python" />
183+
<Radio value="c" label="C" />
184+
<Radio value="cpp" label="C++" />
185+
</Radio.Group>
186+
</VStack>
187+
);
188+
};
189+
```
190+
191+
### Props
192+
193+
#### value
194+
A list containing the selected checkbox values.
195+
196+
| TYPE | REQUIRED | DEFAULT |
197+
| ---------| -------- | ------- |
198+
| string[] | No | [] |
199+
200+
201+
#### onChange
202+
Invoked when the group selection changes (because a new option was selected or a previous one was unselected) with the selected option values.
203+
204+
| TYPE | REQUIRED |
205+
| -------- | -------- |
206+
| function | No |
207+
208+
#### disabled
209+
If the checkbox is disabled or not.
210+
211+
| TYPE | REQUIRED | DEFAULT |
212+
| ---- | -------- | ------- |
213+
| bool | No | false |
214+
215+
<CodePreview>
216+
<ExampleRadioGroup disabled />
217+
</CodePreview>
218+
219+
```jsx
220+
import React, { useState } from 'react';
221+
import { Radio, Text, VStack } from '@amalgama/react-native-ui-kit';
222+
223+
const ExampleRadioGroup = () => {
224+
const [ value, setValue ] = useState();
225+
226+
return (
227+
<VStack>
228+
<Text variant="sh1">What is your favorite coding language?</Text>
229+
<Radio.Group disabled value={value} onChange={setValue}>
230+
<Radio value="js" label="Javascript" />
231+
<Radio value="ts" label="Typescript" />
232+
<Radio value="rb" label="Ruby" />
233+
<Radio value="python" label="Python" />
234+
<Radio value="c" label="C" />
235+
<Radio value="cpp" label="C++" />
236+
</Radio.Group>
237+
</VStack>
238+
);
239+
};
240+
```

0 commit comments

Comments
 (0)