Skip to content

Commit d5a9510

Browse files
authored
Merge pull request mxdi9i7#69 from mxdi9i7/will/fixed-cell
Will/Cell Component
2 parents 4145a3f + e97c441 commit d5a9510

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

src/components/Cell/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $baseClass: 'vant-cell';
2121
.#{$baseClass}__block {
2222
display: flex;
2323
justify-content: space-between;
24+
cursor: pointer;
2425
}
2526

2627
.#{$baseClass}__title,

src/components/Cell/index.stories.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import Cell from '.';
34
import Tag from '../Tag';
45
import '../../styles/stories.scss';
@@ -65,6 +66,17 @@ export const URL = () => (
6566
</div>
6667
);
6768

69+
export const checkbox = () => (
70+
<div className='storybook__container column grey'>
71+
<Cell
72+
title={{ text: 'Title', fontSize: '14px' }}
73+
content={{ text: 'Content', fontSize: '12px' }}
74+
description={{ text: 'description', fontSize: '12px' }}
75+
checkbox={{ checkedColor: '#b90000' }}
76+
/>
77+
</div>
78+
);
79+
6880
export const OnClick = () => (
6981
<div className='storybook__container column grey'>
7082
<Cell

src/components/Cell/index.tsx

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22

33
import classnames from '../../utils/classNames';
44

55
import './index.scss';
66
import Icon from '../Icons';
7+
import Checkbox from '../Checkbox';
78
import { IProps } from './types';
89

910
const baseClass = 'vant-cell';
1011

1112
const Cell = ({
13+
url,
14+
click,
1215
title,
1316
titleIcon,
1417
content,
15-
contentIcon,
18+
contentIcon = url || click ? { name: 'arrow', size: '12px' } : null,
1619
description,
20+
checkbox,
1721
tag,
18-
url,
1922
replace,
20-
round,
21-
click
23+
round
2224
}: IProps) => {
25+
const [isActive, setActive] = useState(false);
26+
2327
const CustomTag = url ? 'a' : 'div';
2428
const containerProps = {
2529
className: classnames(`${baseClass}__container`, []),
@@ -58,6 +62,14 @@ const Cell = ({
5862
});
5963
}
6064

65+
if (checkbox) {
66+
Object.assign(containerProps, {
67+
onClick: () => {
68+
setActive(!isActive);
69+
}
70+
});
71+
}
72+
6173
return (
6274
<CustomTag {...containerProps}>
6375
<div className={`${baseClass}__block`}>
@@ -68,14 +80,18 @@ const Cell = ({
6880
)}
6981
{tag && tag}
7082
</div>
71-
<div {...contentProps}>
72-
{content && (
73-
<p style={{ fontSize: content.fontSize }}>{content.text}</p>
74-
)}
75-
{contentIcon && (
76-
<Icon name={contentIcon.name} size={contentIcon.size} />
77-
)}
78-
</div>
83+
{checkbox ? (
84+
<Checkbox isActive={isActive} checkedColor={checkbox.checkedColor} />
85+
) : (
86+
<div {...contentProps}>
87+
{content && (
88+
<p style={{ fontSize: content.fontSize }}>{content.text}</p>
89+
)}
90+
{contentIcon && (
91+
<Icon name={contentIcon.name} size={contentIcon.size} />
92+
)}
93+
</div>
94+
)}
7995
</div>
8096
{description && (
8197
<p style={{ fontSize: description.fontSize }}>{description.text}</p>

src/components/Cell/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ export interface IProps {
44
title?: { text: string; fontSize: string };
55
titleIcon?: { name: string; size: string };
66
content?: { text: string; fontSize: string };
7-
contentIcon?: { name: string; size: string };
7+
contentIcon?: { name: string; size: string } | null;
88
description?: { text: string; fontSize: string };
9+
checkbox?: { checkedColor: string };
910
tag?: ReactElement;
1011
url?: string;
1112
replace?: boolean;

src/components/Checkbox/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface IProps {
1414
labelText?: string;
1515
disabled?: boolean;
1616
labelDisabled?: boolean;
17+
isActive?: boolean;
1718
changed?: Function;
1819
clicked?: Function;
1920
}
@@ -34,7 +35,8 @@ const Checkbox = ({
3435
labelText,
3536
inactiveIcon = 'passed',
3637
disabled,
37-
labelDisabled
38+
labelDisabled,
39+
isActive
3840
}: IProps) => {
3941
const [isChecked, handleCheck] = useState(checked);
4042

@@ -46,6 +48,10 @@ const Checkbox = ({
4648
return changed && changed(isChecked);
4749
}, [isChecked]);
4850

51+
useEffect(() => {
52+
isActive ? handleCheck(true) : handleCheck(false);
53+
}, [isActive]);
54+
4955
const handleContainerClick = (e) => {
5056
e.preventDefault();
5157
if (!disabled && !labelDisabled) {

0 commit comments

Comments
 (0)