@@ -12,72 +12,73 @@ import {
12
12
Platform ,
13
13
StyleProp ,
14
14
StyleSheet ,
15
- TextStyle ,
16
- TouchableOpacity ,
17
15
TouchableOpacityProps ,
18
16
View ,
19
17
ViewStyle ,
20
18
} from 'react-native' ;
19
+ import { Overwrite } from 'utility-types' ;
20
+ import {
21
+ FalsyText ,
22
+ RenderProp ,
23
+ TouchableWithoutFeedback ,
24
+ WebEventResponder ,
25
+ WebEventResponderCallbacks ,
26
+ WebEventResponderInstance ,
27
+ } from '../../devsupport' ;
21
28
import {
22
29
Interaction ,
23
30
styled ,
24
31
StyledComponentProps ,
25
32
StyleType ,
26
- } from '@kitten/theme' ;
27
- import {
28
- Text ,
29
- TextElement ,
30
- } from '../text/text.component' ;
33
+ } from '../../theme' ;
34
+ import { TextProps } from '../text/text.component' ;
31
35
import {
32
36
CheckMark ,
33
37
CheckMarkProps ,
34
- CheckMarkElement ,
35
- } from '../support/components/checkmark.component' ;
38
+ } from '../shared/checkmark.component' ;
36
39
import {
37
40
Minus ,
38
- MinusElement ,
39
41
MinusProps ,
40
- } from '../support/components/minus.component' ;
41
- import {
42
- isValidString ,
43
- WebEventResponder ,
44
- WebEventResponderCallbacks ,
45
- WebEventResponderInstance ,
46
- } from '../support/services' ;
42
+ } from '../shared/minus.component' ;
47
43
48
- export interface CheckBoxProps extends StyledComponentProps , TouchableOpacityProps {
49
- textStyle ?: StyleProp < TextStyle > ;
50
- text ?: string ;
44
+ type CheckBoxStyledProps = Overwrite < StyledComponentProps , {
45
+ appearance ?: 'default' | string ;
46
+ } > ;
47
+
48
+ export interface CheckBoxProps extends TouchableOpacityProps , CheckBoxStyledProps {
51
49
checked ?: boolean ;
52
50
indeterminate ?: boolean ;
53
- status ?: string ;
54
51
onChange ?: ( checked : boolean , indeterminate : boolean ) => void ;
52
+ text ?: RenderProp < TextProps > | React . ReactText ;
53
+ status ?: 'basic' | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'control' | string ;
55
54
}
56
55
57
56
export type CheckBoxElement = React . ReactElement < CheckBoxProps > ;
58
57
59
- type IconElement = CheckMarkElement | MinusElement ;
60
-
61
58
/**
62
59
* Styled `CheckBox` component.
63
60
*
64
61
* @extends React.Component
65
62
*
66
- * @property {boolean } checked - Determines whether component is checked.`
63
+ * @property {boolean } checked - Determines whether component is checked.
67
64
* Default is `false`.
68
65
*
69
- * @property {boolean } disabled - Determines whether component is disabled.
70
- * Default is `false.
66
+ * @property {boolean } indeterminate - Determines whether checked status is indeterminate.
67
+ * Will set indeterminate to false when the checked property is changed.
68
+ * Default is `false`.
71
69
*
72
70
* @property {string } status - Determines the status of the component.
73
71
* Can be `basic`, `primary`, `success`, `info`, `warning`, `danger` or `control`.
74
72
* Default is `basic`.
75
73
*
76
- * @property {string } text - Determines text of the component.
74
+ * @property {string | (props: TextProps) => ReactElement } text - A string or a function component
75
+ * to render near the checkbox.
76
+ * If it is a function, it will be called with props provided by Eva.
77
+ * Otherwise, renders a Text styled by Eva.
77
78
*
78
- * @property {StyleProp<TextStyle> } textStyle - Customizes text style .
79
- *
80
- * @property { (checked: boolean) => void } onChange - Fires on checkbox value change .
79
+ * @property {(checked: boolean, indeterminate: boolean) => void } onChange - Called on checkbox value change .
80
+ * Called with `checked` and `indeterminate` values.
81
+ * If `indeterminate` was provided in state, it should be changed to the value passed in this function .
81
82
*
82
83
* @property {TouchableOpacityProps } ...TouchableOpacityProps - Any props applied to TouchableOpacity component.
83
84
*
@@ -139,7 +140,7 @@ class CheckBoxComponent extends React.Component<CheckBoxProps> implements WebEve
139
140
}
140
141
} ;
141
142
142
- private getComponentStyle = ( source : StyleType ) : StyleType => {
143
+ private getComponentStyle = ( source : StyleType ) => {
143
144
const {
144
145
textMarginHorizontal,
145
146
textFontFamily,
@@ -159,8 +160,6 @@ class CheckBoxComponent extends React.Component<CheckBoxProps> implements WebEve
159
160
} = source ;
160
161
161
162
return {
162
- container : { } ,
163
- highlightContainer : { } ,
164
163
selectContainer : containerParameters ,
165
164
text : {
166
165
marginHorizontal : textMarginHorizontal ,
@@ -200,65 +199,42 @@ class CheckBoxComponent extends React.Component<CheckBoxProps> implements WebEve
200
199
} ;
201
200
} ;
202
201
203
- private renderTextElement = ( style : TextStyle ) : TextElement => {
204
- const { text, textStyle } = this . props ;
205
-
206
- return (
207
- < Text style = { [ style , styles . text , textStyle ] } > { text } </ Text >
208
- ) ;
209
- } ;
210
-
211
- private renderIconElement = ( style : SvgProps ) : IconElement => {
202
+ private renderIconElement = ( style : SvgProps ) : React . ReactElement < SvgProps > => {
212
203
const Icon : React . ComponentType < MinusProps | CheckMarkProps > = this . props . indeterminate ? Minus : CheckMark ;
213
204
return (
214
205
< Icon { ...style } />
215
206
) ;
216
207
} ;
217
208
218
- private renderComponentChildren = ( style : StyleType ) : React . ReactNodeArray => {
219
- const { text } = this . props ;
220
-
221
- return [
222
- this . renderIconElement ( style . icon ) ,
223
- isValidString ( text ) && this . renderTextElement ( style . text ) ,
224
- ] ;
225
- } ;
226
-
227
209
public render ( ) : React . ReactElement < TouchableOpacityProps > {
228
- const { eva, style, disabled, text, ...derivedProps } = this . props ;
210
+ const { eva, style, disabled, text, ...touchableProps } = this . props ;
229
211
230
- const {
231
- container,
232
- highlightContainer,
233
- highlight,
234
- selectContainer,
235
- ...componentStyle
236
- } = this . getComponentStyle ( eva . style ) ;
212
+ const evaStyle = this . getComponentStyle ( eva . style ) ;
237
213
238
- const selectContainerStyle : StyleProp < ViewStyle > = [ selectContainer , styles . selectContainer ] ;
214
+ const selectContainerStyle : StyleProp < ViewStyle > = [ evaStyle . selectContainer , styles . selectContainer ] ;
239
215
const hitSlopInsets : Insets = this . createHitSlopInsets ( selectContainerStyle ) ;
240
216
241
- const [ iconElement , textElement ] = this . renderComponentChildren ( componentStyle ) ;
242
-
243
217
return (
244
- < TouchableOpacity
245
- activeOpacity = { 1.0 }
246
- { ...derivedProps }
218
+ < TouchableWithoutFeedback
219
+ { ...touchableProps }
247
220
{ ...this . webEventResponder . eventHandlers }
248
- style = { [ container , styles . container , webStyles . container , style ] }
221
+ style = { [ styles . container , webStyles . container , style ] }
249
222
disabled = { disabled }
250
223
hitSlop = { hitSlopInsets }
251
224
onPress = { this . onPress }
252
225
onPressIn = { this . onPressIn }
253
226
onPressOut = { this . onPressOut } >
254
- < View style = { [ highlightContainer , styles . highlightContainer ] } >
255
- < View style = { [ highlight , styles . highlight ] } />
227
+ < View style = { styles . highlightContainer } >
228
+ < View style = { [ evaStyle . highlight , styles . highlight ] } />
256
229
< View style = { selectContainerStyle } >
257
- { iconElement }
230
+ { this . renderIconElement ( evaStyle . icon ) }
258
231
</ View >
259
232
</ View >
260
- { textElement }
261
- </ TouchableOpacity >
233
+ < FalsyText
234
+ style = { evaStyle . text }
235
+ component = { text }
236
+ />
237
+ </ TouchableWithoutFeedback >
262
238
) ;
263
239
}
264
240
}
@@ -279,8 +255,6 @@ const styles = StyleSheet.create({
279
255
highlight : {
280
256
position : 'absolute' ,
281
257
} ,
282
- icon : { } ,
283
- text : { } ,
284
258
} ) ;
285
259
286
260
const webStyles = Platform . OS === 'web' && StyleSheet . create ( {
0 commit comments