Skip to content

Commit ad595f2

Browse files
Mackenzie BrowneMackenzie Browne
Mackenzie Browne
authored and
Mackenzie Browne
committed
add outline prop to checkbox
1 parent 9b5e7ab commit ad595f2

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

generatedTypes/components/checkbox/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export interface CheckboxProps extends TouchableOpacityProps {
1717
* The Checkbox color
1818
*/
1919
color?: string;
20+
/**
21+
* alternative Checkbox outline style
22+
*/
23+
outline?: boolean;
2024
/**
2125
* The size of the checkbox. affect both width and height
2226
*/

src/components/checkbox/index.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export interface CheckboxProps extends TouchableOpacityProps {
3232
* The Checkbox color
3333
*/
3434
color?: string;
35+
/**
36+
* alternative Checkbox outline style
37+
*/
38+
outline?: boolean;
3539
/**
3640
* The size of the checkbox. affect both width and height
3741
*/
@@ -172,7 +176,18 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
172176
}
173177

174178
renderCheckbox() {
175-
const {selectedIcon, color, iconColor, label, disabled, testID, style, containerStyle, ...others} = this.props;
179+
const {
180+
selectedIcon,
181+
color,
182+
iconColor,
183+
label,
184+
disabled,
185+
testID,
186+
style,
187+
containerStyle,
188+
outline = false,
189+
...others
190+
} = this.props;
176191

177192
return (
178193
//@ts-ignore
@@ -186,14 +201,18 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
186201
>
187202
{
188203
<Animated.View
189-
style={[this.styles.container, {backgroundColor: this.getColor()}, {opacity: this.animationStyle.opacity}]}
204+
style={[
205+
this.styles.container,
206+
{backgroundColor: outline ? 'transparent' : disabled ? DEFAULT_DISABLED_COLOR : this.getColor()},
207+
{opacity: this.animationStyle.opacity}
208+
]}
190209
>
191210
<Animated.Image
192211
style={[
193212
this.styles.selectedIcon,
194-
color && {tintColor: iconColor},
213+
color && {tintColor: outline ? this.getColor() : DEFAULT_ICON_COLOR},
195214
{transform: this.animationStyle.transform},
196-
disabled && {tintColor: DEFAULT_ICON_COLOR}
215+
disabled && {tintColor: outline ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR}
197216
]}
198217
source={selectedIcon || Assets.icons.checkSmall}
199218
testID={`${testID}.selected`}
@@ -220,7 +239,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
220239
}
221240

222241
function createStyles(props: CheckboxProps) {
223-
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius} = props;
242+
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius, outline, disabled} = props;
224243

225244
return StyleSheet.create({
226245
container: {
@@ -232,7 +251,7 @@ function createStyles(props: CheckboxProps) {
232251
borderColor: color
233252
},
234253
selectedIcon: {
235-
tintColor: iconColor,
254+
tintColor: disabled ? DEFAULT_DISABLED_COLOR : outline ? color : iconColor,
236255
alignItems: 'center',
237256
justifyContent: 'center'
238257
},

0 commit comments

Comments
 (0)