Skip to content

Commit c7387d8

Browse files
committed
wrapped up checkbox
1 parent 14a93ca commit c7387d8

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

src/components/Cell/index.stories.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
};
1010

1111
export const BasicUsage = () => (
12-
<div className='container column grey'>
12+
<div className='storybook__container column grey'>
1313
<Cell
1414
title={{ text: 'Title', fontSize: '14px' }}
1515
content={{ text: 'Content', fontSize: '12px' }}
@@ -23,7 +23,7 @@ export const BasicUsage = () => (
2323
);
2424

2525
export const cellIcon = () => (
26-
<div className='container column grey'>
26+
<div className='storybook__container column grey'>
2727
<Cell
2828
titleIcon={{ name: 'location-o', size: '12px' }}
2929
title={{ text: 'Title', fontSize: '14px' }}
@@ -34,39 +34,39 @@ export const cellIcon = () => (
3434
);
3535

3636
export const cellTag = () => (
37-
<div className='container column grey'>
37+
<div className='storybook__container column grey'>
3838
<Cell
3939
title={{ text: 'Title', fontSize: '14px' }}
40-
Tag={<Tag type='danger' text='Tag' />}
40+
tag={<Tag type='danger' text='Tag' />}
4141
content={{ text: 'Content', fontSize: '12px' }}
4242
/>
4343
</div>
4444
);
4545

4646
export const roundCell = () => (
47-
<div className='container column grey'>
47+
<div className='storybook__container column grey'>
4848
<Cell title={{ text: 'Title', fontSize: '14px' }} round />
4949
</div>
5050
);
5151

5252
export const valueOnly = () => (
53-
<div className='container column grey'>
53+
<div className='storybook__container column grey'>
5454
<Cell content={{ text: 'Content', fontSize: '14px' }} />
5555
</div>
5656
);
5757

5858
export const URL = () => (
59-
<div className='container column grey'>
59+
<div className='storybook__container column grey'>
6060
<Cell
6161
title={{ text: 'URL', fontSize: '14px' }}
62-
url='www.google.com'
62+
url='https://www.google.com'
6363
replace
6464
/>
6565
</div>
6666
);
6767

68-
export const Active = () => (
69-
<div className='container column grey'>
68+
export const OnClick = () => (
69+
<div className='storybook__container column grey'>
7070
<Cell
7171
title={{ text: 'Click', fontSize: '14px' }}
7272
click={(e) => {

src/components/Cell/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Cell = ({
1414
content,
1515
contentIcon,
1616
description,
17-
Tag,
17+
tag,
1818
url,
1919
replace,
2020
round,
@@ -66,7 +66,7 @@ const Cell = ({
6666
{title && (
6767
<span style={{ fontSize: title.fontSize }}>{title.text}</span>
6868
)}
69-
{Tag && Tag}
69+
{tag && tag}
7070
</div>
7171
<div {...contentProps}>
7272
{content && (

src/components/Cell/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface IProps {
66
content?: { text: string; fontSize: string };
77
contentIcon?: { name: string; size: string };
88
description?: { text: string; fontSize: string };
9-
Tag?: ReactElement;
9+
tag?: ReactElement;
1010
url?: string;
1111
replace?: boolean;
1212
round?: boolean;

src/components/Checkbox/index.stories.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ export const LabelDisable = () => (
3232
</div>
3333
);
3434

35-
export const Events = () => (
35+
export const OnChange = () => (
3636
<div className='storybook__container'>
37-
<Checkbox labelText='On Click' clicked={() => alert('clicked')} />
3837
<Checkbox
3938
labelText='On Change'
4039
changed={(checked) => alert(`Checkbox is checked: ${checked}`)}
4140
/>
4241
</div>
4342
);
43+
44+
export const OnClick = () => (
45+
<div className='storybook__container'>
46+
<Checkbox labelText='On Click' clicked={() => alert('clicked')} />
47+
</div>
48+
);

src/components/Checkbox/index.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const baseClass = 'vant-checkbox';
2222

2323
// TODO: Round/Square checkbox
2424
// TODO: Checkbox groups
25+
// TODO: Checkbox in Cells (Need to get Will to finish cell component)
2526

2627
const Checkbox = ({
27-
checked,
28+
checked = false,
2829
changed,
2930
clicked,
3031
name,
@@ -37,23 +38,27 @@ const Checkbox = ({
3738
}: IProps) => {
3839
const [isChecked, handleCheck] = useState(checked);
3940

41+
const handleClick = (e) => {
42+
return clicked && clicked(e);
43+
};
44+
4045
useEffect(() => {
41-
changed(isChecked);
46+
return changed && changed(isChecked);
4247
}, [isChecked]);
4348

4449
const handleContainerClick = (e) => {
4550
e.preventDefault();
4651
if (!disabled && !labelDisabled) {
4752
handleCheck(!isChecked);
48-
clicked(e);
53+
handleClick(e);
4954
}
5055
};
5156

5257
const handleIconClick = (e) => {
5358
e.preventDefault();
5459
if (!disabled) {
5560
handleCheck(!isChecked);
56-
clicked(e);
61+
handleClick(e);
5762
}
5863
};
5964

0 commit comments

Comments
 (0)