Skip to content

Commit 30e476e

Browse files
committed
feat: labeled checkbox
1 parent 1d3e62e commit 30e476e

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

src/components/Checkbox/Checkbox.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ Checkbox for boolean values
1515
<Playground>
1616
<Toggle initial={false}>
1717
{({ on, toggle }) => (
18-
<FormField label="Checkbox" labelPosition="right">
19-
<Checkbox
20-
shape="circle"
21-
value={on}
22-
onValueChange={toggle}
23-
size="medium"
24-
/>
25-
</FormField>
18+
<Checkbox
19+
shape="circle"
20+
value={on}
21+
onValueChange={toggle}
22+
label="Checkbox label"
23+
size="medium"
24+
/>
2625
)}
2726
</Toggle>
2827
</Playground>

src/components/Checkbox/Checkbox.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
import { ContainerShape, ControlSize, useTheme } from '../../theme';
1111
import { isControlSize } from '../../utils/ControlSize';
1212
import { getOverrides, WithOverrides } from '../../utils/Overrides';
13+
import { OptionalString } from '../../utils/types';
1314
import { Icon } from '../Icon';
15+
import { Label, LabelPosition, LabelProps } from '../Typography';
1416

1517
interface CheckboxBaseProps {
1618
/**
@@ -25,6 +27,17 @@ interface CheckboxBaseProps {
2527
*/
2628
value: boolean;
2729

30+
/**
31+
* Label of the field.
32+
*/
33+
label?: OptionalString;
34+
35+
/**
36+
* Position of the field.
37+
* @default "right"
38+
*/
39+
labelPosition?: LabelPosition;
40+
2841
/**
2942
* When true, the checkbox is disabled.
3043
* @default false
@@ -48,6 +61,7 @@ interface CheckboxBaseProps {
4861

4962
export interface CheckboxOverrides {
5063
Touchable: TouchableProps;
64+
Label: LabelProps;
5165
Check: CheckProps;
5266
}
5367

@@ -59,6 +73,8 @@ export const Checkbox = (props: CheckboxProps) => {
5973
size = 'medium',
6074
shape = 'rounded',
6175
value = false,
76+
label,
77+
labelPosition = 'right',
6278
isDisabled = false,
6379
onValueChange = () => {
6480
return;
@@ -91,13 +107,15 @@ export const Checkbox = (props: CheckboxProps) => {
91107

92108
return (
93109
<Touchable {...touchableProps}>
94-
<Check
95-
value={value}
96-
size={size}
97-
shape={shape}
98-
isDisabled={isDisabled}
99-
{...checkProps}
100-
/>
110+
<Label label={label} position={labelPosition}>
111+
<Check
112+
value={value}
113+
size={size}
114+
shape={shape}
115+
isDisabled={isDisabled}
116+
{...checkProps}
117+
/>
118+
</Label>
101119
</Touchable>
102120
);
103121
};

src/components/Form/FormField.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { View, ViewProps } from 'react-native';
55
import { useTheme } from '../../theme';
66
import { getOverrides, getStyle, WithOverrides } from '../../utils/Overrides';
77
import { OptionalString } from '../../utils/types';
8-
import { Label, LabelProps, Text, TextProps } from '../Typography';
9-
10-
type FormFieldLabelPosition = 'top' | 'left' | 'right';
8+
import {
9+
Label,
10+
LabelPosition,
11+
LabelProps,
12+
Text,
13+
TextProps,
14+
} from '../Typography';
1115

1216
interface FormFieldBaseProps {
1317
/**
@@ -24,7 +28,7 @@ interface FormFieldBaseProps {
2428
* Position of the field.
2529
* @default "top"
2630
*/
27-
labelPosition?: FormFieldLabelPosition;
31+
labelPosition?: LabelPosition;
2832

2933
/**
3034
* Description of the field.

src/components/Typography/Label.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getOverrides, getStyle, WithOverrides } from '../../utils/Overrides';
77
import { OptionalString } from '../../utils/types';
88
import { Text, TextProps } from './Text';
99

10-
type LabelPosition = 'top' | 'left' | 'right';
10+
export type LabelPosition = 'top' | 'left' | 'right';
1111

1212
interface LabelBaseProps {
1313
/**
@@ -109,7 +109,6 @@ const StyledWrapper = (props: WrapperProps) => {
109109
wrapperStyle = {
110110
flexDirection: 'row',
111111
alignItems: 'center',
112-
paddingLeft: 8,
113112
};
114113
break;
115114
case 'top':

0 commit comments

Comments
 (0)