Skip to content

Commit 8074814

Browse files
committed
fix: refactor getStyles callbacks
1 parent e39b73e commit 8074814

66 files changed

Lines changed: 223 additions & 306 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/components/Alert/Alert.styles.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export interface AlertStyles {
1111
descriptionStyle: TextStyle;
1212
}
1313

14-
export type GetAlertStyles = (props: AlertProps, theme: Theme) => AlertStyles;
14+
export type GetAlertStyles = (
15+
props: AlertProps,
16+
theme: Theme,
17+
) => Partial<AlertStyles>;
1518

1619
export const getAlertStyles: GetAlertStyles = ({ intent = 'info' }, theme) => {
1720
return {

src/components/Alert/Alert.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as React from 'react';
22
import { View } from 'react-native';
3-
import { DeepPartial } from 'ts-essentials';
43

54
import { useTheme } from '../../theme';
6-
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
5+
import { mergeStyles } from '../../utils/mergeStyles';
76
import { Box } from '../Box';
87
import { Icon } from '../Icon';
98
import { Text } from '../Typography';
10-
import { AlertStyles, GetAlertStyles, getAlertStyles } from './Alert.styles';
9+
import { GetAlertStyles, getAlertStyles } from './Alert.styles';
1110

1211
export type Intent = 'danger' | 'info' | 'success' | 'warning';
1312

@@ -37,7 +36,7 @@ export interface AlertProps {
3736
actionNode?: React.ReactNode;
3837

3938
/** Callback to get element styles. */
40-
getStyles?: ReplaceReturnType<GetAlertStyles, DeepPartial<AlertStyles>>;
39+
getStyles?: GetAlertStyles;
4140

4241
/** Used to locate this view in end-to-end tests. */
4342
testID?: string;

src/components/Avatar/Avatar.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const getAvatarProps = (
5454
export type GetAvatarStyles = (
5555
props: AvatarProps,
5656
theme: Theme,
57-
) => AvatarStyles;
57+
) => Partial<AvatarStyles>;
5858

5959
const avatarScale: { [size in ControlSize]: number } = {
6060
large: 2,

src/components/Avatar/Avatar.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import * as React from 'react';
22
import { Image, ImageSourcePropType, View } from 'react-native';
3-
import { DeepPartial } from 'ts-essentials';
43

54
import { useTheme } from '../../theme';
65
import { ControlSize, FillColor } from '../../theme/Theme';
7-
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
6+
import { mergeStyles } from '../../utils/mergeStyles';
87
import { Text } from '../Typography';
9-
import {
10-
AvatarStyles,
11-
GetAvatarStyles,
12-
getAvatarStyles,
13-
} from './Avatar.styles';
8+
import { GetAvatarStyles, getAvatarStyles } from './Avatar.styles';
149

1510
// https://github.com/segmentio/evergreen/blob/master/source/avatar/README.md
1611
export type GetInitialsType = (name?: string, fallback?: string) => string;
@@ -60,7 +55,7 @@ export interface AvatarProps {
6055
accessibilityLabel?: string;
6156

6257
/** Callback to get element styles. */
63-
getStyles?: ReplaceReturnType<GetAvatarStyles, DeepPartial<AvatarStyles>>;
58+
getStyles?: GetAvatarStyles;
6459

6560
/** Used to locate this view in end-to-end tests. */
6661
testID?: string;

src/components/Badge/Badge.styles.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export interface BadgeStyles {
99
containerStyle: ViewStyle;
1010
}
1111

12-
export type GetBadgeStyles = (props: BadgeProps, theme: Theme) => BadgeStyles;
12+
export type GetBadgeStyles = (
13+
props: BadgeProps,
14+
theme: Theme,
15+
) => Partial<BadgeStyles>;
1316

1417
export const getBadgeStyles: GetBadgeStyles = (
1518
{ size = 'medium', color = 'neutral', isSolid = false, shape = 'rounded' },

src/components/Badge/Badge.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as React from 'react';
22
import { View } from 'react-native';
3-
import { DeepPartial } from 'ts-essentials';
43

54
import { useTheme } from '../../theme';
65
import { ContainerShape, ControlSize, FillColor } from '../../theme/Theme';
7-
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
6+
import { mergeStyles } from '../../utils/mergeStyles';
87
import { Text } from '../Typography';
9-
import { BadgeStyles, GetBadgeStyles, getBadgeStyles } from './Badge.styles';
8+
import { GetBadgeStyles, getBadgeStyles } from './Badge.styles';
109

1110
export interface BadgeProps {
1211
/** Title of the badge */
@@ -37,7 +36,7 @@ export interface BadgeProps {
3736
isSolid?: boolean;
3837

3938
/** Callback to get element styles. */
40-
getStyles?: ReplaceReturnType<GetBadgeStyles, DeepPartial<BadgeStyles>>;
39+
getStyles?: GetBadgeStyles;
4140

4241
/** Used to locate this view in end-to-end tests. */
4342
testID?: string;

src/components/Button/Button.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export interface ButtonStyles {
113113
export type GetButtonStyles = (
114114
props: ButtonProps,
115115
theme: Theme,
116-
) => ButtonStyles;
116+
) => Partial<ButtonStyles>;
117117

118118
export const getButtonStyles: GetButtonStyles = (props, theme) => {
119119
const {

src/components/Button/Button.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import {
55
TouchableOpacity,
66
View,
77
} from 'react-native';
8-
import { DeepPartial } from 'ts-essentials';
98

109
import { ButtonColor, ControlSize, useTheme } from '../../theme';
11-
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
10+
import { mergeStyles } from '../../utils/mergeStyles';
1211
import { Dots } from '../LoadingIndicators';
1312
import { Text } from '../Typography';
1413
import {
1514
ButtonAppearance,
16-
ButtonStyles,
1715
GetButtonStyles,
1816
getButtonStyles,
1917
} from './Button.styles';
@@ -86,7 +84,7 @@ export interface ButtonProps {
8684
accessible?: boolean;
8785

8886
/** Callback to get element styles. */
89-
getStyles?: ReplaceReturnType<GetButtonStyles, DeepPartial<ButtonStyles>>;
87+
getStyles?: GetButtonStyles;
9088

9189
/** Used to locate this view in end-to-end tests. */
9290
testID?: string;
@@ -144,14 +142,21 @@ export const Button = (props: ButtonProps) => {
144142
};
145143

146144
export interface ButtonContentProps extends ButtonProps {
147-
textStyle: TextStyle;
145+
textStyle?: TextStyle;
148146
}
149147

150148
const ButtonContent = (props: ButtonContentProps) => {
151149
const { isLoading, iconLoading, icon, title, textStyle } = props;
150+
const theme = useTheme();
152151

153152
if (isLoading) {
154-
return <>{iconLoading || <Dots color={textStyle.color} />}</>;
153+
return (
154+
<>
155+
{iconLoading || (
156+
<Dots color={textStyle ? textStyle.color : theme.colors.text.white} />
157+
)}
158+
</>
159+
);
155160
}
156161
if (icon) return <>{icon}</>;
157162
if (title) {

src/components/Checkbox/Checkbox.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface CheckboxStyles {
1313
export type GetCheckboxStyles = (
1414
props: CheckboxProps,
1515
theme: Theme,
16-
) => CheckboxStyles;
16+
) => Partial<CheckboxStyles>;
1717

1818
export const getCheckboxStyles: GetCheckboxStyles = (
1919
{ value, isDisabled, shape = 'rounded', size = 'medium' },

src/components/Checkbox/Checkbox.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import * as React from 'react';
22
import { GestureResponderEvent, TouchableOpacity, View } from 'react-native';
3-
import { DeepPartial } from 'ts-essentials';
43

54
import { ContainerShape, ControlSize, useTheme } from '../../theme';
6-
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
5+
import { mergeStyles } from '../../utils/mergeStyles';
76
import { Icon } from '../Icon';
8-
import {
9-
CheckboxStyles,
10-
GetCheckboxStyles,
11-
getCheckboxStyles,
12-
} from './Checkbox.styles';
7+
import { GetCheckboxStyles, getCheckboxStyles } from './Checkbox.styles';
138

149
export interface CheckboxProps {
1510
/**
@@ -51,7 +46,7 @@ export interface CheckboxProps {
5146
onPress?: (e: GestureResponderEvent) => void;
5247

5348
/** Callback to get element styles. */
54-
getStyles?: ReplaceReturnType<GetCheckboxStyles, DeepPartial<CheckboxStyles>>;
49+
getStyles?: GetCheckboxStyles;
5550

5651
/** Used to locate this view in end-to-end tests. */
5752
testID?: string;

0 commit comments

Comments
 (0)