Skip to content

Commit 2e3da45

Browse files
committed
feat(counter): fix styling elements
1 parent c08b190 commit 2e3da45

14 files changed

Lines changed: 399 additions & 70 deletions

File tree

src/components/Alert/Alert.mdx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ Give feedback to the user about an action or state
2727
</Box>
2828
</Playground>
2929

30+
### Props
31+
32+
<Props of={Alert} />
33+
3034
### Customization
3135

3236
Use `getStyles` prop
3337

34-
```
38+
```tsx
3539
AlertStyleProps {
3640
intent: Intent;
3741
}
@@ -46,6 +50,14 @@ AlertStyles {
4650
getStyles={(AlertStyleProps, Theme) => AlertStyles}
4751
```
4852

49-
### Props
53+
Markup
5054

51-
<Props of={Alert} />
55+
```tsx
56+
<View containerStyle>
57+
{icon}
58+
<View bodyStyle>
59+
<Text titleStyle>{title}</Text>
60+
<Text descriptionStyle>{description}</Text>
61+
</View>
62+
</View>
63+
```

src/components/Avatar/Avatar.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ Display avatar image, with default for name initials
2020
/>
2121
</Playground>
2222

23+
### Props
24+
25+
<Props of={Avatar} />
26+
2327
### Customization
2428

2529
Using `getStyles` prop
2630

27-
```
31+
```tsx
2832
AvatarStylesProps {
2933
name?: string;
3034
color: AvatarColor;
@@ -42,6 +46,11 @@ AvatarStyles {
4246
getStyles={(AvatarStylesProps, Theme) => AvatarStyles}
4347
```
4448

45-
### Props
49+
Markup
4650

47-
<Props of={Avatar} />
51+
```tsx
52+
<View containerStyle>
53+
<Text textStyle>{initials}</Text>
54+
<Image imageStyle />
55+
</View>
56+
```

src/components/Badge/Badge.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ Display to indicate status or feat of service
1818
</Box>
1919
</Playground>
2020

21+
### Props
22+
23+
<Props of={Badge} />
24+
2125
### Customization
2226

2327
Using `getStyles` prop
2428

25-
```
29+
```tsx
2630
BadgeStylesProps {
2731
shape: ContainerShape;
2832
size: ControlSize;
@@ -38,6 +42,10 @@ BadgeStyles {
3842
getStyles={(BadgeStylesProps, Theme) => BadgeStyles}
3943
```
4044

41-
### Props
45+
Markup
4246

43-
<Props of={Badge} />
47+
```tsx
48+
<View containerStyle>
49+
<Text textStyle>{title}</Text>
50+
</View>
51+
```

src/components/Button/Button.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Button component to trigger an action
4646
</Box>
4747
</Playground>
4848

49+
### Props
50+
51+
<Props of={Button} />
52+
4953
### Customization
5054

5155
Using `getStyles` prop
@@ -72,6 +76,16 @@ ButtonStyles {
7276
getStyles={(ButtonStylesProps, Theme) => ButtonStyles}
7377
```
7478

75-
### Props
79+
Markup
7680

77-
<Props of={Button} />
81+
```tsx
82+
<TouchableOpacity buttonStyle>
83+
<View innerButtonWrapperStyle>
84+
{iconBefore}
85+
<View buttonContentWrapperStyle>
86+
<Text textStyle />
87+
</View>
88+
{iconAfter}
89+
</View>
90+
</TouchableOpacity>
91+
```

src/components/Button/Button.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ export const Button = (props: ButtonProps) => {
145145
<View style={innerButtonWrapperStyle}>
146146
{iconBefore}
147147
<View style={buttonContentWrapperStyle}>
148-
{/*
149-
// @ts-ignore */}
150148
<ButtonContent {...props} textStyle={textStyle} />
151149
</View>
152150
{iconAfter}

src/components/Checkbox/Checkbox.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Checkbox for boolean values
2727
</Toggle>
2828
</Playground>
2929

30+
### Props
31+
32+
<Props of={Checkbox} />
33+
3034
### Customization
3135

3236
Using `getStyles` prop
@@ -48,6 +52,10 @@ CheckboxStyles {
4852
getStyles={(CheckboxStylesProps, Theme) => CheckboxStyles}
4953
```
5054

51-
### Props
55+
Markup
5256

53-
<Props of={Checkbox} />
57+
```tsx
58+
<TouchableOpacity touchableStyle>
59+
<View checkboxStyle>{icon}</View>
60+
</TouchableOpacity>
61+
```

src/components/Collapsible/Collapsible.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Component to reveal and hide content
3333
</Toggle>
3434
</Playground>
3535

36+
### Props
37+
38+
<Props of={Collapsible} />
39+
3640
### Customization
3741

3842
Using `getStyles` prop
@@ -53,6 +57,16 @@ CollapsibleStyles {
5357
getStyles={(CollapsibleStylesProps, Theme) => CollapsibleStyles}
5458
```
5559

56-
### Props
60+
Markup
5761

58-
<Props of={Collapsible} />
62+
```tsx
63+
<>
64+
<TouchableOpacity touchableStyle>
65+
<View outerWrapperStyle>
66+
<Text textStyle>{title}</Text>
67+
<View iconWrapperStyle>{icon}</View>
68+
</View>
69+
</TouchableOpacity>
70+
<View contentWrapperStyle>{children}</View>
71+
</>
72+
```

src/components/Counter/Counter.mdx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,49 @@ import { Counter, CounterState } from '..';
1313
<Playground>
1414
<CounterState initial={0}>
1515
{({ count, increment, decrement }) => (
16-
<Counter
17-
count={count}
18-
onDecrement={decrement}
19-
onIncrement={increment}
20-
min={0}
21-
max={10}
22-
component={null}
23-
getStyles={(props, theme) => ({
24-
containerStyle: {},
25-
counterStyle: {},
26-
countStyle: {},
27-
disabledStyle: {},
28-
ntextStyle: {},
29-
})}
30-
/>
16+
<Counter count={count} onDecrement={decrement} onIncrement={increment} />
3117
)}
3218
</CounterState>
3319
</Playground>
3420

3521
### Props
3622

3723
<Props of={Counter} />
24+
25+
### Customization
26+
27+
Using `getStyles` prop
28+
29+
```
30+
CounterStylesProps {
31+
count: number;
32+
}
33+
34+
CounterStyles {
35+
containerStyle: ViewStyle;
36+
counterStyle: ViewStyle;
37+
countStyle: ViewStyle;
38+
decrementWrapperStyle: ViewStyle;
39+
disabledStyle: ViewStyle;
40+
incrementWrapperStyle: ViewStyle;
41+
textStyle: TextStyle;
42+
}
43+
44+
getStyles={(CounterStylesProps, Theme) => CounterStyles}
45+
```
46+
47+
Markup
48+
49+
```tsx
50+
<View containerStyle>
51+
<View decrementWrapperStyle>
52+
<TouchableOpacity counterStyle>{icon}</TouchableOpacity>
53+
</View>
54+
<View countStyle>
55+
<Text textStyle>{count}</Text>
56+
</View>
57+
<View incrementWrapperStyle>
58+
<TouchableOpacity counterStyle>{icon}</TouchableOpacity>
59+
</View>
60+
</View>
61+
```

src/components/Counter/Counter.styles.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@ import { TextStyle, ViewStyle } from 'react-native';
22

33
import { Theme } from '../../theme/Theme';
44

5+
export interface CounterStylesProps {
6+
count: number;
7+
}
8+
59
export interface CounterStyles {
610
containerStyle: ViewStyle;
7-
countStyle: ViewStyle;
811
counterStyle: ViewStyle;
12+
countStyle: ViewStyle;
13+
decrementWrapperStyle: ViewStyle;
914
disabledStyle: ViewStyle;
15+
incrementWrapperStyle: ViewStyle;
1016
textStyle: TextStyle;
1117
}
1218

13-
export type GetCounterStyles = (props: {}, theme: Theme) => CounterStyles;
19+
export type GetCounterStyles = (
20+
props: CounterStylesProps,
21+
theme: Theme,
22+
) => CounterStyles;
1423

1524
export const getCounterStyles: GetCounterStyles = (props, theme) => {
1625
return {
@@ -32,9 +41,11 @@ export const getCounterStyles: GetCounterStyles = (props, theme) => {
3241
justifyContent: 'center',
3342
width: 40,
3443
},
44+
decrementWrapperStyle: { paddingRight: 16 },
3545
disabledStyle: {
3646
borderColor: theme.colors.border.default,
3747
},
48+
incrementWrapperStyle: { paddingLeft: 16 },
3849
textStyle: {},
3950
};
4051
};

src/components/Counter/Counter.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { DeepPartial } from 'ts-essentials';
44

55
import { useTheme } from '../../theme';
66
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
7-
import { Box } from '../Box';
87
import { Icon } from '../Icon';
98
import { Text } from '../Typography';
109
import {
@@ -14,13 +13,24 @@ import {
1413
} from './Counter.styles';
1514

1615
export interface CounterProps {
17-
count: number;
16+
/** Count to be displayed. */
17+
count?: number;
18+
19+
/** Minimum count for the counter. Upon reaching the limit, it will disable decrement button. */
1820
min?: number;
21+
22+
/** Maximum count for the counter. Upon reaching the limit, it will disable increment button. */
1923
max?: number;
20-
/* custom component in place of count */
24+
25+
/** Custom component in place of count */
2126
component?: React.ReactNode;
27+
28+
/** Called when increment button is pressed */
2229
onIncrement?: () => void;
30+
31+
/** Called when decrement button is pressed */
2332
onDecrement?: () => void;
33+
2434
/**
2535
* Inline styles for components
2636
*/
@@ -29,7 +39,7 @@ export interface CounterProps {
2939

3040
export const Counter = (props: CounterProps) => {
3141
const {
32-
count,
42+
count = 0,
3343
component,
3444
max,
3545
min,
@@ -44,22 +54,23 @@ export const Counter = (props: CounterProps) => {
4454
containerStyle,
4555
counterStyle,
4656
countStyle,
47-
textStyle,
57+
decrementWrapperStyle,
4858
disabledStyle,
59+
incrementWrapperStyle,
60+
textStyle,
4961
} = mergeStyles(
5062
getCounterStyles,
5163
getStyles,
5264
theme.components.getCounterStyles,
53-
)({}, theme);
65+
)({ count }, theme);
5466

5567
const isDecrementDisabled = min === count;
5668
const isIncrementDisabled = max === count;
5769

5870
return (
5971
<View style={containerStyle}>
60-
<Box paddingRight={16}>
72+
<View style={decrementWrapperStyle}>
6173
<TouchableOpacity
62-
activeOpacity={0.7}
6374
style={{
6475
...counterStyle,
6576
...(isDecrementDisabled && disabledStyle),
@@ -77,7 +88,7 @@ export const Counter = (props: CounterProps) => {
7788
}
7889
/>
7990
</TouchableOpacity>
80-
</Box>
91+
</View>
8192
{component || (
8293
<View style={countStyle}>
8394
<Text
@@ -86,9 +97,8 @@ export const Counter = (props: CounterProps) => {
8697
>{`${count}`}</Text>
8798
</View>
8899
)}
89-
<Box paddingLeft={16}>
100+
<View style={incrementWrapperStyle}>
90101
<TouchableOpacity
91-
activeOpacity={0.7}
92102
style={{
93103
...counterStyle,
94104
...(isIncrementDisabled && disabledStyle),
@@ -106,7 +116,7 @@ export const Counter = (props: CounterProps) => {
106116
}
107117
/>
108118
</TouchableOpacity>
109-
</Box>
119+
</View>
110120
</View>
111121
);
112122
};

0 commit comments

Comments
 (0)