1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
3
3
import classnames from '../../utils/classNames' ;
4
4
5
5
import './index.scss' ;
6
6
import Icon from '../Icons' ;
7
+ import Checkbox from '../Checkbox' ;
7
8
import { IProps } from './types' ;
8
9
9
10
const baseClass = 'vant-cell' ;
10
11
11
12
const Cell = ( {
13
+ url,
14
+ click,
12
15
title,
13
16
titleIcon,
14
17
content,
15
- contentIcon,
18
+ contentIcon = url || click ? { name : 'arrow' , size : '12px' } : null ,
16
19
description,
20
+ checkbox,
17
21
tag,
18
- url,
19
22
replace,
20
- round,
21
- click
23
+ round
22
24
} : IProps ) => {
25
+ const [ isActive , setActive ] = useState ( false ) ;
26
+
23
27
const CustomTag = url ? 'a' : 'div' ;
24
28
const containerProps = {
25
29
className : classnames ( `${ baseClass } __container` , [ ] ) ,
@@ -58,6 +62,14 @@ const Cell = ({
58
62
} ) ;
59
63
}
60
64
65
+ if ( checkbox ) {
66
+ Object . assign ( containerProps , {
67
+ onClick : ( ) => {
68
+ setActive ( ! isActive ) ;
69
+ }
70
+ } ) ;
71
+ }
72
+
61
73
return (
62
74
< CustomTag { ...containerProps } >
63
75
< div className = { `${ baseClass } __block` } >
@@ -68,14 +80,18 @@ const Cell = ({
68
80
) }
69
81
{ tag && tag }
70
82
</ 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
+ ) }
79
95
</ div >
80
96
{ description && (
81
97
< p style = { { fontSize : description . fontSize } } > { description . text } </ p >
0 commit comments