Skip to content

Commit 56adc10

Browse files
committed
feat(*): refactor style getters
1 parent 16f38a7 commit 56adc10

27 files changed

Lines changed: 176 additions & 311 deletions

src/components/Alert/Alert.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ Give feedback to the user about an action or state
3636
Use `getStyles` prop
3737

3838
```tsx
39-
AlertStyleProps {
40-
intent: Intent;
41-
}
42-
4339
AlertStyles {
4440
containerStyle: ViewStyle;
4541
bodyStyle: ViewStyle;
4642
titleStyle: TextStyle;
4743
descriptionStyle: TextStyle;
4844
}
4945

50-
getStyles={(AlertStyleProps, Theme) => AlertStyles}
46+
getStyles={(AlertProps, Theme) => AlertStyles}
5147
```
5248

5349
Markup

src/components/Alert/Alert.styles.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TextStyle, ViewStyle } from 'react-native';
22

3-
import { Intent } from '../../constants/Intent';
43
import { Theme } from '../../theme';
4+
import { AlertProps } from './Alert';
55

66
export interface AlertStyles {
77
containerStyle: ViewStyle;
@@ -10,16 +10,9 @@ export interface AlertStyles {
1010
descriptionStyle: TextStyle;
1111
}
1212

13-
export interface AlertStyleProps {
14-
intent: Intent;
15-
}
16-
17-
export type GetAlertStyles = (
18-
alertStyleProps: AlertStyleProps,
19-
theme: Theme,
20-
) => AlertStyles;
13+
export type GetAlertStyles = (props: AlertProps, theme: Theme) => AlertStyles;
2114

22-
export const getAlertStyles: GetAlertStyles = ({ intent }, theme) => {
15+
export const getAlertStyles: GetAlertStyles = ({ intent = 'info' }, theme) => {
2316
return {
2417
bodyStyle: {
2518
flex: 1,

src/components/Avatar/Avatar.mdx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,13 @@ Display avatar image, with default for name initials
2929
Using `getStyles` prop
3030

3131
```tsx
32-
AvatarStylesProps {
33-
name?: string;
34-
color: AvatarColor;
35-
isSolid: boolean;
36-
size: number;
37-
sizeLimitOneCharacter: number;
38-
}
39-
4032
AvatarStyles {
4133
containerStyle: ViewStyle;
4234
textStyle: TextStyle;
4335
imageStyle: ImageStyle;
4436
}
4537

46-
getStyles={(AvatarStylesProps, Theme) => AvatarStyles}
38+
getStyles={(AvatarProps, Theme) => AvatarStyles}
4739
```
4840

4941
Markup

src/components/Avatar/Avatar.styles.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ImageStyle, TextStyle, ViewStyle } from 'react-native';
22

33
import { FillColors, Fills, Theme } from '../../theme/Theme';
4+
import { AvatarProps } from './Avatar';
45

56
export const hashCode = (s?: string) => {
67
const str = String(s);
@@ -20,14 +21,6 @@ export const hashCode = (s?: string) => {
2021

2122
export type AvatarColor = 'automatic' | keyof FillColors;
2223

23-
export interface AvatarStylesProps {
24-
name?: string;
25-
color: AvatarColor;
26-
isSolid: boolean;
27-
size: number;
28-
sizeLimitOneCharacter: number;
29-
}
30-
3124
export interface AvatarStyles {
3225
containerStyle: ViewStyle;
3326
textStyle: TextStyle;
@@ -68,12 +61,18 @@ const getAvatarProps = (
6861
};
6962

7063
export type GetAvatarStyles = (
71-
avatarStylesProps: AvatarStylesProps,
64+
props: AvatarProps,
7265
theme: Theme,
7366
) => AvatarStyles;
7467

7568
export const getAvatarStyles: GetAvatarStyles = (
76-
{ name, color, isSolid, size = 24, sizeLimitOneCharacter = 20 },
69+
{
70+
name,
71+
color = 'automatic',
72+
isSolid = false,
73+
size = 48,
74+
sizeLimitOneCharacter = 20,
75+
},
7776
theme,
7877
) => {
7978
let colorProps;

src/components/Avatar/Avatar.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ export const Avatar = (props: AvatarProps) => {
7070
source,
7171
size = 48,
7272
name,
73-
isSolid = false,
74-
color = 'automatic',
7573
sizeLimitOneCharacter = 20,
7674
getStyles,
7775
testID,
@@ -93,16 +91,7 @@ export const Avatar = (props: AvatarProps) => {
9391
getAvatarStyles,
9492
getStyles,
9593
theme.components.getAvatarStyles,
96-
)(
97-
{
98-
color,
99-
isSolid,
100-
name,
101-
size,
102-
sizeLimitOneCharacter,
103-
},
104-
theme,
105-
);
94+
)(props, theme);
10695

10796
return (
10897
<View style={containerStyle} testID={testID}>

src/components/Badge/Badge.mdx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,12 @@ Display to indicate status or feat of service
2727
Using `getStyles` prop
2828

2929
```tsx
30-
BadgeStylesProps {
31-
shape: ContainerShape;
32-
size: ControlSize;
33-
color: FillColor;
34-
isSolid: boolean;
35-
}
36-
3730
BadgeStyles {
3831
textStyle: TextStyle;
3932
containerStyle: ViewStyle;
4033
}
4134

42-
getStyles={(BadgeStylesProps, Theme) => BadgeStyles}
35+
getStyles={(BadgeProps, Theme) => BadgeStyles}
4336
```
4437

4538
Markup

src/components/Badge/Badge.styles.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
11
import { TextStyle, ViewStyle } from 'react-native';
22

3-
import {
4-
ContainerShape,
5-
ControlSize,
6-
FillColor,
7-
Theme,
8-
} from '../../theme/Theme';
9-
10-
export interface BadgeStylesProps {
11-
shape: ContainerShape;
12-
size: ControlSize;
13-
color: FillColor;
14-
isSolid: boolean;
15-
}
3+
import { Theme } from '../../theme/Theme';
4+
import { BadgeProps } from './Badge';
165

176
export interface BadgeStyles {
187
textStyle: TextStyle;
198
containerStyle: ViewStyle;
209
}
2110

22-
export type GetBadgeStyles = (
23-
props: BadgeStylesProps,
24-
theme: Theme,
25-
) => BadgeStyles;
11+
export type GetBadgeStyles = (props: BadgeProps, theme: Theme) => BadgeStyles;
2612

2713
export const getBadgeStyles: GetBadgeStyles = (
28-
{ size, color, isSolid, shape },
14+
{ size = 'medium', color = 'neutral', isSolid = false, shape = 'rounded' },
2915
theme,
3016
) => {
3117
const shapeStyles = theme.containerShapes[shape];

src/components/Badge/Badge.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,15 @@ export interface BadgeProps {
4444
}
4545

4646
export const Badge = (props: BadgeProps) => {
47-
const {
48-
color = 'neutral',
49-
getStyles,
50-
isSolid = false,
51-
shape = 'rounded',
52-
size = 'medium',
53-
title,
54-
testID,
55-
} = props;
47+
const { getStyles, size = 'medium', title, testID } = props;
5648

5749
const theme = useTheme();
5850

5951
const { containerStyle, textStyle } = mergeStyles(
6052
getBadgeStyles,
6153
getStyles,
6254
theme.components.getBadgeStyles,
63-
)({ size, color, isSolid, shape }, theme);
55+
)(props, theme);
6456

6557
return (
6658
<View style={containerStyle} testID={testID}>

src/components/Button/Button.mdx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,14 @@ Button component to trigger an action
5555
Using `getStyles` prop
5656

5757
```
58-
ButtonStylesProps {
59-
appearance: ButtonAppearance;
60-
color: ButtonColor;
61-
size: ControlSize;
62-
isDisabled: boolean;
63-
isLoading: boolean;
64-
isInline: boolean;
65-
hasIconAfter?: boolean;
66-
hasIconBefore?: boolean;
67-
}
68-
6958
ButtonStyles {
7059
buttonStyle: ViewStyle;
7160
textStyle: TextStyle;
7261
innerButtonWrapperStyle: ViewStyle;
7362
buttonContentWrapperStyle: ViewStyle;
7463
}
7564
76-
getStyles={(ButtonStylesProps, Theme) => ButtonStyles}
65+
getStyles={(ButtonProps, Theme) => ButtonStyles}
7766
```
7867

7968
Markup

src/components/Button/Button.styles.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TextStyle, ViewStyle } from 'react-native';
22

3-
import { ButtonColor, ControlSize, Theme } from '../../theme/Theme';
3+
import { ButtonColor, Theme } from '../../theme/Theme';
4+
import { ButtonProps } from './Button';
45

56
export interface ButtonColorProps {
67
backgroundColor: string;
@@ -101,17 +102,6 @@ export const getButtonAppearances = (theme: Theme): ButtonAppearances => {
101102
};
102103
};
103104

104-
export interface ButtonStylesProps {
105-
appearance: ButtonAppearance;
106-
color: ButtonColor;
107-
size: ControlSize;
108-
isDisabled: boolean;
109-
isLoading: boolean;
110-
isInline: boolean;
111-
hasIconAfter?: boolean;
112-
hasIconBefore?: boolean;
113-
}
114-
115105
export interface ButtonStyles {
116106
buttonStyle: ViewStyle;
117107
textStyle: TextStyle;
@@ -120,21 +110,23 @@ export interface ButtonStyles {
120110
}
121111

122112
export type GetButtonStyles = (
123-
buttonStylesProps: ButtonStylesProps,
113+
props: ButtonProps,
124114
theme: Theme,
125115
) => ButtonStyles;
126116

127-
export const getButtonStyles: GetButtonStyles = (buttonStyleProps, theme) => {
117+
export const getButtonStyles: GetButtonStyles = (props, theme) => {
128118
const {
129-
appearance,
130-
color,
131-
size,
119+
appearance = 'primary',
120+
color = 'default',
121+
size = 'medium',
132122
isDisabled,
133123
isLoading,
124+
iconAfter,
125+
iconBefore,
134126
isInline,
135-
hasIconAfter,
136-
hasIconBefore,
137-
} = buttonStyleProps;
127+
} = props;
128+
const hasIconAfter = !!iconAfter;
129+
const hasIconBefore = !!iconBefore;
138130

139131
const buttonAppearances = getButtonAppearances(theme);
140132

0 commit comments

Comments
 (0)