Skip to content

Commit 3ddd9c3

Browse files
Mackenzie BrowneMackenzie Browne
Mackenzie Browne
authored and
Mackenzie Browne
committed
Bugfixes, Revisions from Feedback, create DEFAULT_BORDER_RADIUS and DEFAULT_BORDER_WIDTH
1 parent ad595f2 commit 3ddd9c3

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/components/checkbox/index.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const DEFAULT_COLOR = Colors.blue30;
1515
const DEFAULT_ICON_COLOR = Colors.white;
1616
const DEFAULT_DISABLED_COLOR = Colors.grey50;
1717

18+
const DEFAULT_BORDER_WIDTH = 2;
19+
const DEFAULT_BORDER_RADIUS = 8;
20+
1821
export interface CheckboxProps extends TouchableOpacityProps {
1922
/**
2023
* The value of the Checkbox. If true the switch will be turned on. Default value is false.
@@ -163,14 +166,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
163166
}
164167
};
165168

166-
getColor() {
167-
const {color, disabled} = this.props;
168-
return disabled ? DEFAULT_DISABLED_COLOR : color || DEFAULT_COLOR;
169-
}
169+
getColor = () => this.props.disabled ? DEFAULT_DISABLED_COLOR : this.props.color || DEFAULT_COLOR;
170+
171+
getBackgroundColor = () => this.props.outline ? 'transparent' : this.getColor();
172+
173+
getTintColor = () => this.props.outline ? this.getColor() : DEFAULT_ICON_COLOR;
170174

171175
getBorderStyle() {
172176
const borderColor = {borderColor: this.getColor()};
173-
const borderStyle = [this.styles.container, {borderWidth: 2}, borderColor];
177+
const borderStyle = [this.styles.container, {borderWidth: DEFAULT_BORDER_WIDTH}, borderColor];
174178

175179
return borderStyle;
176180
}
@@ -185,7 +189,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
185189
testID,
186190
style,
187191
containerStyle,
188-
outline = false,
192+
outline,
189193
...others
190194
} = this.props;
191195

@@ -203,16 +207,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
203207
<Animated.View
204208
style={[
205209
this.styles.container,
206-
{backgroundColor: outline ? 'transparent' : disabled ? DEFAULT_DISABLED_COLOR : this.getColor()},
207-
{opacity: this.animationStyle.opacity}
210+
{opacity: this.animationStyle.opacity},
211+
{ backgroundColor: this.getBackgroundColor() }
208212
]}
209213
>
210214
<Animated.Image
211215
style={[
212216
this.styles.selectedIcon,
213-
color && {tintColor: outline ? this.getColor() : DEFAULT_ICON_COLOR},
214217
{transform: this.animationStyle.transform},
215-
disabled && {tintColor: outline ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR}
218+
{tintColor: this.getTintColor() }
216219
]}
217220
source={selectedIcon || Assets.icons.checkSmall}
218221
testID={`${testID}.selected`}
@@ -239,19 +242,19 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
239242
}
240243

241244
function createStyles(props: CheckboxProps) {
242-
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius, outline, disabled} = props;
245+
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius = DEFAULT_BORDER_RADIUS} = props;
243246

244247
return StyleSheet.create({
245248
container: {
246249
width: size,
247250
height: size,
248-
borderRadius: borderRadius || 8,
251+
borderRadius: borderRadius,
249252
alignItems: 'center',
250253
justifyContent: 'center',
251254
borderColor: color
252255
},
253256
selectedIcon: {
254-
tintColor: disabled ? DEFAULT_DISABLED_COLOR : outline ? color : iconColor,
257+
tintColor: iconColor,
255258
alignItems: 'center',
256259
justifyContent: 'center'
257260
},

0 commit comments

Comments
 (0)