Skip to content

Commit e6975e2

Browse files
committed
Merge branch 'master' into typescript/tab-controller-move-to-typescript
* master: configure 'max-len'; turn off 'jsx-no-bind' (#1087) remove unnecessary view (#1084) Counter Icon badge (#1081) checkbox variant - outline (#1067)
2 parents b747c91 + 290ab92 commit e6975e2

File tree

8 files changed

+68
-18
lines changed

8 files changed

+68
-18
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ module.exports = {
99
'no-mixed-operators': ['off'],
1010
'no-trailing-spaces': 'off',
1111
'operator-linebreak': 'off',
12-
'max-len': ['warn', {code: 120}],
12+
'max-len': ['warn', {code: 120, "ignoreComments": true, "ignoreStrings": true}],
1313
'react/jsx-no-bind': [
14-
'warn',
14+
'off',
1515
{
1616
ignoreRefs: true,
1717
allowArrowFunctions: false,

demo/src/assets/icons/bell.png

274 Bytes
Loading
454 Bytes
Loading
632 Bytes
Loading

demo/src/screens/componentScreens/BadgesScreen.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const BadgesSpace = 30;
55
const plusIcon = require('../../assets/icons/chevronUp.png');
66
const minusIcon = require('../../assets/icons/chevronDown.png');
77
const star = require('../../assets/icons/star.png');
8-
const search = require('../../assets/icons/search.png');
9-
8+
const bell = require('../../assets/icons/bell.png');
109

1110
export default class BadgesScreen extends Component {
1211
constructor(props) {
@@ -137,6 +136,15 @@ export default class BadgesScreen extends Component {
137136
</Text>
138137
</View>
139138
</View>
139+
140+
<Text text50 marginB-10 row center marginT-25>
141+
Counter Icon Badges
142+
</Text>
143+
<View row paddingH-15>
144+
<Badge marginR-10 withCounterIcon label={'9999'} labelFormatterLimit={3} icon={bell} backgroundColor={Colors.red30} iconStyle={{height: 18, width: 18}}/>
145+
<Badge marginR-10 withCounterIcon label={'4'} icon={bell} backgroundColor={Colors.red30} color={Colors.blue30} iconStyle={{height: 18, width: 18}}/>
146+
</View>
147+
140148
</ScrollView>
141149
);
142150
}

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/badge/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ImageSourcePropType, ImageStyle, StyleProp, StyleSheet, Text, TextStyle,
44
import {View as AnimatableView} from 'react-native-animatable';
55
import {extractAccessibilityProps, extractAnimationProps} from '../../commons/modifiers';
66
import {asBaseComponent} from '../../commons/new';
7-
import {BorderRadiuses, Colors, Typography} from '../../style';
7+
import {BorderRadiuses, Colors, Spacings, Typography} from '../../style';
88
import TouchableOpacity from '../touchableOpacity';
99
import Image from '../image';
1010
import View from '../view';
@@ -143,6 +143,15 @@ class Badge extends PureComponent<BadgeProps> {
143143
height: badgeHeight,
144144
minWidth: badgeHeight
145145
};
146+
if (icon && label) {
147+
style.paddingRight = 6;
148+
style.paddingLeft = 4;
149+
style.height = Spacings.s5;
150+
if (borderWidth) {
151+
style.height += borderWidth * 2;
152+
}
153+
return style;
154+
}
146155

147156
const isPimple = label === undefined;
148157
if (isPimple || icon) {
@@ -213,7 +222,8 @@ class Badge extends PureComponent<BadgeProps> {
213222
}
214223

215224
renderIcon() {
216-
const {icon, iconStyle, iconProps, borderColor} = this.props;
225+
const {icon, iconStyle, iconProps, borderColor, label} = this.props;
226+
const flex = label ? 0 : 1;
217227
return (
218228
<Image
219229
source={icon!}
@@ -222,7 +232,7 @@ class Badge extends PureComponent<BadgeProps> {
222232
borderColor={borderColor}
223233
{...iconProps}
224234
style={{
225-
flex: 1,
235+
flex,
226236
...iconStyle
227237
}}
228238
/>
@@ -237,6 +247,7 @@ class Badge extends PureComponent<BadgeProps> {
237247
containerStyle,
238248
hitSlop,
239249
icon,
250+
label,
240251
onPress,
241252
testId,
242253
testID,
@@ -264,8 +275,10 @@ class Badge extends PureComponent<BadgeProps> {
264275
activeOpacity={activeOpacity}
265276
hitSlop={hitSlop}
266277
{...animationProps}
278+
row
267279
>
268-
{icon ? this.renderIcon() : this.renderLabel()}
280+
{icon && this.renderIcon()}
281+
{label && this.renderLabel()}
269282
</Container>
270283
</View>
271284
);

src/components/checkbox/index.tsx

Lines changed: 35 additions & 10 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.
@@ -32,6 +35,10 @@ export interface CheckboxProps extends TouchableOpacityProps {
3235
* The Checkbox color
3336
*/
3437
color?: string;
38+
/**
39+
* alternative Checkbox outline style
40+
*/
41+
outline?: boolean;
3542
/**
3643
* The size of the checkbox. affect both width and height
3744
*/
@@ -158,14 +165,24 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
158165
}
159166
};
160167

161-
getColor() {
162-
const {color, disabled} = this.props;
163-
return disabled ? DEFAULT_DISABLED_COLOR : color || DEFAULT_COLOR;
164-
}
168+
getColor = () => (this.props.disabled ? DEFAULT_DISABLED_COLOR : this.props.color || DEFAULT_COLOR);
169+
170+
getBackgroundColor = () => (this.props.outline ? 'transparent' : this.getColor());
171+
172+
getTintColor = () => {
173+
const {outline, disabled, iconColor} = this.props;
174+
if (outline) {
175+
if (disabled) return DEFAULT_DISABLED_COLOR;
176+
else return iconColor || DEFAULT_COLOR;
177+
} else {
178+
if (disabled) return Colors.white;
179+
else return iconColor || Colors.white;
180+
}
181+
};
165182

166183
getBorderStyle() {
167184
const borderColor = {borderColor: this.getColor()};
168-
const borderStyle = [this.styles.container, {borderWidth: 2}, borderColor];
185+
const borderStyle = [this.styles.container, {borderWidth: DEFAULT_BORDER_WIDTH}, borderColor];
169186

170187
return borderStyle;
171188
}
@@ -185,14 +202,17 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
185202
>
186203
{
187204
<Animated.View
188-
style={[this.styles.container, {backgroundColor: this.getColor()}, {opacity: this.animationStyle.opacity}]}
205+
style={[
206+
this.styles.container,
207+
{opacity: this.animationStyle.opacity},
208+
{backgroundColor: this.getBackgroundColor()}
209+
]}
189210
>
190211
<Animated.Image
191212
style={[
192213
this.styles.selectedIcon,
193-
color && {tintColor: iconColor},
194214
{transform: this.animationStyle.transform},
195-
disabled && {tintColor: DEFAULT_ICON_COLOR}
215+
{tintColor: this.getTintColor()}
196216
]}
197217
source={selectedIcon || Assets.icons.checkSmall}
198218
testID={`${testID}.selected`}
@@ -219,13 +239,18 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
219239
}
220240

221241
function createStyles(props: CheckboxProps) {
222-
const {color = DEFAULT_COLOR, iconColor = DEFAULT_ICON_COLOR, size = DEFAULT_SIZE, borderRadius} = props;
242+
const {
243+
color = DEFAULT_COLOR,
244+
iconColor = DEFAULT_ICON_COLOR,
245+
size = DEFAULT_SIZE,
246+
borderRadius = DEFAULT_BORDER_RADIUS
247+
} = props;
223248

224249
return StyleSheet.create({
225250
container: {
226251
width: size,
227252
height: size,
228-
borderRadius: borderRadius || 8,
253+
borderRadius: borderRadius,
229254
alignItems: 'center',
230255
justifyContent: 'center',
231256
borderColor: color

0 commit comments

Comments
 (0)