Skip to content

Commit ff66244

Browse files
committed
feat: reduce api surface, change to testID
1 parent 0fb68ce commit ff66244

9 files changed

Lines changed: 54 additions & 48 deletions

File tree

src/components/Alert/Alert.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { TouchableOpacity, View, ViewProps } from 'react-native';
2+
import { TouchableOpacity, View } from 'react-native';
33
import { DeepPartial } from 'ts-essentials';
44

55
import { Intent } from '../../constants/Intent';
@@ -10,10 +10,11 @@ import { Spacing } from '../Layout';
1010
import { Strong, Text } from '../Typography';
1111
import { AlertStyles, GetAlertStyles, getAlertStyles } from './Alert.styles';
1212

13-
export interface AlertProps extends ViewProps {
13+
export interface AlertProps {
1414
theme: Theme;
1515
title?: string;
1616
description?: string;
17+
testID?: string;
1718
/* custom component, will take precedence over title and description */
1819
component?: React.ReactNode;
1920
onClose?: () => void;
@@ -58,7 +59,7 @@ const AlertBase = (props: AlertProps) => {
5859
intent = 'info',
5960
getStyles,
6061
theme,
61-
...viewProps
62+
testID,
6263
} = props;
6364

6465
const { containerStyle, bodyStyle } = mergeStyles(getAlertStyles, getStyles)(
@@ -67,7 +68,7 @@ const AlertBase = (props: AlertProps) => {
6768
);
6869

6970
return (
70-
<View style={containerStyle} {...viewProps}>
71+
<View style={containerStyle} testID={testID}>
7172
{icon || (
7273
<Spacing paddingRight={2} justifyContent="center">
7374
{resolveIcon(intent, theme)}

src/components/Avatar/Avatar.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Image, ImageSourcePropType, View, ViewProps } from 'react-native';
2+
import { Image, ImageSourcePropType, View } from 'react-native';
33
import { DeepPartial } from 'ts-essentials';
44

55
import { Theme, withTheme } from '../../theme';
@@ -26,7 +26,7 @@ export const globalGetInitials: GetInitialsType = (name, fallback = '?') => {
2626
.join('');
2727
};
2828

29-
export interface AvatarProps extends ViewProps {
29+
export interface AvatarProps {
3030
/**
3131
* The source attribute of the image.
3232
* When it's not available, render initials instead.
@@ -83,6 +83,8 @@ export interface AvatarProps extends ViewProps {
8383
theme: Theme;
8484

8585
getStyles?: ReplaceReturnType<GetAvatarStyles, DeepPartial<AvatarStyles>>;
86+
87+
testID?: string;
8688
}
8789

8890
export const AvatarBase = (props: AvatarProps) => {
@@ -99,7 +101,7 @@ export const AvatarBase = (props: AvatarProps) => {
99101
forceShowInitials = false,
100102
sizeLimitOneCharacter = 20,
101103
getStyles,
102-
...viewProps
104+
testID,
103105
} = props;
104106

105107
const { imageHasFailedLoading } = { imageHasFailedLoading: false };
@@ -126,7 +128,7 @@ export const AvatarBase = (props: AvatarProps) => {
126128
);
127129

128130
return (
129-
<View style={boxStyle} {...viewProps}>
131+
<View style={boxStyle} testID={testID}>
130132
{(imageUnavailable || forceShowInitials) && (
131133
<Text
132134
getStyles={() => ({

src/components/Badge/Badge.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { View, ViewProps } from 'react-native';
2+
import { View } from 'react-native';
33
import { DeepPartial } from 'ts-essentials';
44

55
import { Theme, withTheme } from '../../theme';
@@ -14,14 +14,15 @@ import {
1414
getBadgeStyles,
1515
} from './Badge.styles';
1616

17-
export interface BadgeProps extends ViewProps {
17+
export interface BadgeProps {
1818
children: React.ReactNode;
1919
theme: Theme;
2020
color?: FillColor;
2121
size?: BadgeSize;
2222
shape?: Shape;
2323
isSolid?: boolean;
2424
getStyles?: ReplaceReturnType<GetBadgeStyles, DeepPartial<BadgeStyles>>;
25+
testID?: string;
2526
}
2627

2728
const BadgeBase = (props: BadgeProps) => {
@@ -33,7 +34,7 @@ const BadgeBase = (props: BadgeProps) => {
3334
shape = 'rounded',
3435
size = 'small',
3536
theme,
36-
...viewProps
37+
testID,
3738
} = props;
3839

3940
const { containerStyle, textStyle } = mergeStyles(getBadgeStyles, getStyles)(
@@ -42,7 +43,7 @@ const BadgeBase = (props: BadgeProps) => {
4243
);
4344

4445
return (
45-
<View style={containerStyle} {...viewProps}>
46+
<View style={containerStyle} testID={testID}>
4647
<Strong
4748
size={size}
4849
getStyles={() => ({

src/components/Button/Button.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as React from 'react';
2-
import {
3-
TouchableHighlight,
4-
TouchableHighlightProps,
5-
View,
6-
} from 'react-native';
2+
import { AccessibilityProps, TouchableHighlight, View } from 'react-native';
73
import { DeepPartial } from 'ts-essentials';
84

95
import { Theme, withTheme } from '../../theme';
@@ -20,7 +16,7 @@ import {
2016
getButtonStyles,
2117
} from './Button.styles';
2218

23-
export interface ButtonProps extends TouchableHighlightProps {
19+
export interface ButtonProps extends AccessibilityProps {
2420
title?: string;
2521

2622
/**
@@ -98,6 +94,8 @@ export interface ButtonProps extends TouchableHighlightProps {
9894
* Inline styles for components
9995
*/
10096
getStyles?: ReplaceReturnType<GetButtonStyles, DeepPartial<ButtonStyles>>;
97+
98+
testID?: string;
10199
}
102100

103101
const ButtonBase = (props: ButtonProps) => {
@@ -118,8 +116,9 @@ const ButtonBase = (props: ButtonProps) => {
118116
},
119117
size = 'medium',
120118
theme,
119+
testID,
121120

122-
...touchableHighlightProps
121+
...accessibilityProps
123122
} = props;
124123

125124
const { buttonStyle, textStyle, focusColor } = mergeStyles(
@@ -145,7 +144,8 @@ const ButtonBase = (props: ButtonProps) => {
145144
disabled={!!(isDisabled || isLoading)}
146145
onPress={onPress}
147146
style={buttonStyle}
148-
{...touchableHighlightProps}
147+
testID={testID}
148+
{...accessibilityProps}
149149
>
150150
<View
151151
style={{

src/components/Checkbox/Checkbox.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22
import {
3+
AccessibilityProps,
34
GestureResponderEvent,
45
TouchableHighlight,
5-
TouchableHighlightProps,
66
View,
77
} from 'react-native';
88
import { DeepPartial } from 'ts-essentials';
@@ -18,7 +18,7 @@ import {
1818

1919
export type CheckboxShape = 'circle' | 'square';
2020

21-
export interface CheckboxProps extends TouchableHighlightProps {
21+
export interface CheckboxProps extends AccessibilityProps {
2222
theme: Theme;
2323
isChecked?: boolean;
2424
isDisabled?: boolean;
@@ -29,6 +29,7 @@ export interface CheckboxProps extends TouchableHighlightProps {
2929
shape?: CheckboxShape;
3030
onChange?: (e: GestureResponderEvent) => void | undefined;
3131
getStyles?: ReplaceReturnType<GetCheckboxStyles, DeepPartial<CheckboxStyles>>;
32+
testID?: string;
3233
}
3334

3435
const CheckboxBase = (props: CheckboxProps) => {
@@ -41,7 +42,8 @@ const CheckboxBase = (props: CheckboxProps) => {
4142
shape = 'square',
4243
theme,
4344
getStyles,
44-
...touchableHighlightProps
45+
testID,
46+
...accessibilityProps
4547
} = props;
4648

4749
const { checkboxStyle, checkboxFocusBackgroundColor } = mergeStyles(
@@ -62,7 +64,8 @@ const CheckboxBase = (props: CheckboxProps) => {
6264
: {
6365
disabled: true,
6466
})}
65-
{...touchableHighlightProps}
67+
testID={testID}
68+
{...accessibilityProps}
6669
>
6770
<View
6871
style={{

src/components/Layout/Box.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const propToFn = {
6666
};
6767

6868
const Box = ({ theme, ...props }: BoxProps) => {
69-
const { children, style: propStyle, ...viewStyles } = props;
69+
const { children, style: propStyle, testID, ...viewStyles } = props;
7070
const transformedStyles = [];
7171
const pureStyles = {};
7272

@@ -88,7 +88,9 @@ const Box = ({ theme, ...props }: BoxProps) => {
8888
}
8989

9090
return (
91-
<View style={[pureStyles, transformedStyles, propStyle]}>{children}</View>
91+
<View testID={testID} style={[pureStyles, transformedStyles, propStyle]}>
92+
{children}
93+
</View>
9294
);
9395
};
9496

src/components/ListItem/ListItem.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22
import {
3+
AccessibilityProps,
34
ImageSourcePropType,
45
TouchableHighlight,
5-
TouchableHighlightProps,
66
View,
77
} from 'react-native';
88
import { DeepPartial } from 'ts-essentials';
@@ -18,7 +18,7 @@ import {
1818
ListItemStyles,
1919
} from './ListItem.styles';
2020

21-
export interface ListItemProps extends TouchableHighlightProps {
21+
export interface ListItemProps extends AccessibilityProps {
2222
theme: Theme;
2323
size?: ListItemSize;
2424
isDisabled?: boolean;
@@ -28,6 +28,7 @@ export interface ListItemProps extends TouchableHighlightProps {
2828
avatarProps?: AvatarProps;
2929
rightIcon?: React.ReactNode;
3030
getStyles?: ReplaceReturnType<GetListItemStyles, DeepPartial<ListItemStyles>>;
31+
testID?: string;
3132
}
3233

3334
const ListItemBase = (props: ListItemProps) => {
@@ -41,7 +42,8 @@ const ListItemBase = (props: ListItemProps) => {
4142
rightIcon = null,
4243
theme,
4344
avatarProps,
44-
...touchableHighlightProps
45+
testID,
46+
...accessibilityProps
4547
} = props;
4648

4749
const {
@@ -59,7 +61,8 @@ const ListItemBase = (props: ListItemProps) => {
5961
disabled={isDisabled}
6062
underlayColor={focusBackgroundColor}
6163
style={containerStyle}
62-
{...touchableHighlightProps}
64+
testID={testID}
65+
{...accessibilityProps}
6366
>
6467
<View style={wrapperStyle}>
6568
<View style={leftWrapperStyle}>

src/components/Progress/Progress.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Platform, View, ViewProps } from 'react-native';
2+
import { Platform, View } from 'react-native';
33
import { Spring } from 'react-spring';
44
import { DeepPartial } from 'ts-essentials';
55

@@ -12,21 +12,16 @@ import {
1212
ProgressStyles,
1313
} from './Progress.styles';
1414

15-
export interface ProgressProps extends ViewProps {
15+
export interface ProgressProps {
1616
theme: Theme;
1717
percent?: number;
1818
size?: ProgressSize;
1919
getStyles?: ReplaceReturnType<GetProgressStyles, DeepPartial<ProgressStyles>>;
20+
testID?: string;
2021
}
2122

2223
const ProgressBase = (props: ProgressProps) => {
23-
const {
24-
percent = 0,
25-
size = 'medium',
26-
getStyles,
27-
theme,
28-
...viewProps
29-
} = props;
24+
const { percent = 0, size = 'medium', getStyles, theme, testID } = props;
3025
const { containerStyle, progressStyle } = mergeStyles(
3126
getProgressStyles,
3227
getStyles,
@@ -36,7 +31,7 @@ const ProgressBase = (props: ProgressProps) => {
3631
<Spring to={{ value: percent }}>
3732
{({ value }) => {
3833
return (
39-
<View style={containerStyle} {...viewProps}>
34+
<View style={containerStyle} testID={testID}>
4035
<View
4136
// @ts-ignore
4237
accessibilityRole={Platform.OS === 'web' ? 'progress' : 'none'}

src/components/Switch/Switch.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as React from 'react';
2-
import {
3-
Animated,
4-
TouchableOpacity,
5-
TouchableOpacityProps,
6-
} from 'react-native';
2+
import { AccessibilityProps, Animated, TouchableOpacity } from 'react-native';
73
import { DeepPartial } from 'ts-essentials';
84

95
import { Icon } from '../../icons';
@@ -16,14 +12,15 @@ import {
1612
} from './Switch.styles';
1713

1814
/* Copy pasted from https://github.com/react-native-seoul/react-native-switch-toggle */
19-
export interface SwitchProps extends TouchableOpacityProps {
15+
export interface SwitchProps extends AccessibilityProps {
2016
isSwitchedOn?: boolean;
2117
isDisabled?: boolean;
2218
onChange?: () => void;
2319
onIcon?: React.ReactNode;
2420
offIcon?: React.ReactNode;
2521
duration?: number;
2622
theme: Theme;
23+
testID?: string;
2724
/**
2825
* Inline styles for components
2926
*/
@@ -113,7 +110,8 @@ class SwitchBase extends React.Component<SwitchProps, SwitchState> {
113110
theme,
114111
isSwitchedOn,
115112
getStyles,
116-
...touchableOpacityProps
113+
testID,
114+
...accessibilityProps
117115
} = this.props;
118116
const { animXValue, circlePosXStart, circlePosXEnd } = this.state;
119117

@@ -137,7 +135,8 @@ class SwitchBase extends React.Component<SwitchProps, SwitchState> {
137135
flexDirection: 'row',
138136
flexWrap: 'wrap',
139137
}}
140-
{...touchableOpacityProps}
138+
testID={testID}
139+
{...accessibilityProps}
141140
>
142141
<Animated.View
143142
style={[

0 commit comments

Comments
 (0)