Skip to content

Commit b9f4332

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 b9f4332

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

src/components/checkbox/index.tsx

Lines changed: 16 additions & 24 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,31 +166,21 @@ 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
}
177181

178182
renderCheckbox() {
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;
183+
const {selectedIcon, color, iconColor, label, disabled, testID, style, containerStyle, ...others} = this.props;
191184

192185
return (
193186
//@ts-ignore
@@ -203,16 +196,15 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
203196
<Animated.View
204197
style={[
205198
this.styles.container,
206-
{backgroundColor: outline ? 'transparent' : disabled ? DEFAULT_DISABLED_COLOR : this.getColor()},
207-
{opacity: this.animationStyle.opacity}
199+
{opacity: this.animationStyle.opacity},
200+
{backgroundColor: this.getBackgroundColor()}
208201
]}
209202
>
210203
<Animated.Image
211204
style={[
212205
this.styles.selectedIcon,
213-
color && {tintColor: outline ? this.getColor() : DEFAULT_ICON_COLOR},
214206
{transform: this.animationStyle.transform},
215-
disabled && {tintColor: outline ? DEFAULT_DISABLED_COLOR : DEFAULT_ICON_COLOR}
207+
{tintColor: this.getTintColor()}
216208
]}
217209
source={selectedIcon || Assets.icons.checkSmall}
218210
testID={`${testID}.selected`}
@@ -239,19 +231,19 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
239231
}
240232

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

244236
return StyleSheet.create({
245237
container: {
246238
width: size,
247239
height: size,
248-
borderRadius: borderRadius || 8,
240+
borderRadius: borderRadius,
249241
alignItems: 'center',
250242
justifyContent: 'center',
251243
borderColor: color
252244
},
253245
selectedIcon: {
254-
tintColor: disabled ? DEFAULT_DISABLED_COLOR : outline ? color : iconColor,
246+
tintColor: iconColor,
255247
alignItems: 'center',
256248
justifyContent: 'center'
257249
},

0 commit comments

Comments
 (0)