Skip to content

Commit 6158b3f

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

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
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: 12 additions & 3 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,7 @@ 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 {selectedIcon, color, iconColor = this.props.outline ? this.getColor() : DEFAULT_ICON_COLOR, label, disabled, testID, style, containerStyle, outline, ...others} = this.props;
176180

177181
return (
178182
//@ts-ignore
@@ -186,7 +190,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
186190
>
187191
{
188192
<Animated.View
189-
style={[this.styles.container, {backgroundColor: this.getColor()}, {opacity: this.animationStyle.opacity}]}
193+
style={[this.styles.container, {backgroundColor: outline ? 'transparent' : this.getColor()}, {opacity: this.animationStyle.opacity}]}
190194
>
191195
<Animated.Image
192196
style={[
@@ -220,7 +224,12 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
220224
}
221225

222226
function createStyles(props: CheckboxProps) {
223-
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius} = props;
227+
const {color = DEFAULT_COLOR, size = DEFAULT_SIZE, borderRadius} = props;
228+
229+
let iconColor = props.disabled ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR;
230+
if(props.outline) {
231+
iconColor = props.disabled ? DEFAULT_DISABLED_COLOR : DEFAULT_COLOR;
232+
}
224233

225234
return StyleSheet.create({
226235
container: {

0 commit comments

Comments
 (0)