Skip to content

Commit 59151c4

Browse files
committed
fix: pass through native props to components
1 parent fb46c8e commit 59151c4

7 files changed

Lines changed: 55 additions & 44 deletions

File tree

src/components/Alert/Alert.tsx

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

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

13-
export interface AlertProps {
13+
export interface AlertProps extends ViewProps {
1414
theme: Theme;
1515
title?: string;
1616
description?: string;
@@ -58,6 +58,7 @@ const AlertBase = (props: AlertProps) => {
5858
intent = 'info',
5959
getStyles,
6060
theme,
61+
...viewProps
6162
} = props;
6263

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

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

src/components/Avatar/Avatar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Image, ImageSourcePropType, View } from 'react-native';
2+
import { Image, ImageSourcePropType, View, ViewProps } 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 {
29+
export interface AvatarProps extends ViewProps {
3030
/**
3131
* The source attribute of the image.
3232
* When it's not available, render initials instead.
@@ -99,6 +99,7 @@ export const AvatarBase = (props: AvatarProps) => {
9999
forceShowInitials = false,
100100
sizeLimitOneCharacter = 20,
101101
getStyles,
102+
...viewProps
102103
} = props;
103104

104105
const { imageHasFailedLoading } = { imageHasFailedLoading: false };
@@ -125,7 +126,7 @@ export const AvatarBase = (props: AvatarProps) => {
125126
);
126127

127128
return (
128-
<View style={boxStyle}>
129+
<View style={boxStyle} {...viewProps}>
129130
{(imageUnavailable || forceShowInitials) && (
130131
<Text
131132
getStyles={() => ({

src/components/Badge/Badge.styles.ts

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

33
import { FillColor, Fills, Theme } from '../../theme/ThemeInterface';
4+
import { Shape, shapeMapping } from '../Layout/Box';
45

56
export interface BadgeSizes {
67
small: ViewStyle;
@@ -41,14 +42,15 @@ export const getBadgeVariables = (theme: Theme): BadgeVariables => {
4142
};
4243

4344
export interface BadgeStylesProps {
45+
shape: Shape;
4446
size: BadgeSize;
4547
color: FillColor;
4648
isSolid: boolean;
4749
}
4850

4951
export interface BadgeStyles {
5052
textStyle: TextStyle;
51-
boxStyle: ViewStyle;
53+
containerStyle: ViewStyle;
5254
}
5355

5456
export type GetBadgeStyles = (
@@ -57,11 +59,12 @@ export type GetBadgeStyles = (
5759
) => BadgeStyles;
5860

5961
export const getBadgeStyles: GetBadgeStyles = (
60-
{ size, color, isSolid },
62+
{ size, color, isSolid, shape },
6163
theme,
6264
) => {
6365
const badgeVariables = getBadgeVariables(theme);
6466

67+
const shapeStyles = shapeMapping[shape];
6568
const fills = isSolid
6669
? badgeVariables.fills.solid
6770
: badgeVariables.fills.subtle;
@@ -70,11 +73,17 @@ export const getBadgeStyles: GetBadgeStyles = (
7073
const { height, paddingLeft, paddingRight } = badgeVariables.sizes[size];
7174

7275
return {
73-
boxStyle: {
76+
containerStyle: {
77+
alignItems: 'center',
78+
alignSelf: 'flex-start',
7479
backgroundColor: colors.backgroundColor,
80+
display: 'flex',
81+
flexDirection: 'row',
7582
height,
83+
justifyContent: 'center',
7684
paddingLeft,
7785
paddingRight,
86+
...shapeStyles,
7887
},
7988
textStyle: {
8089
color: colors.color,

src/components/Badge/Badge.tsx

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

45
import { Theme, withTheme } from '../../theme';
@@ -13,7 +14,7 @@ import {
1314
getBadgeStyles,
1415
} from './Badge.styles';
1516

16-
export interface BadgeProps {
17+
export interface BadgeProps extends ViewProps {
1718
children: React.ReactNode;
1819
theme: Theme;
1920
color?: FillColor;
@@ -32,29 +33,16 @@ const BadgeBase = (props: BadgeProps) => {
3233
shape = 'rounded',
3334
size = 'small',
3435
theme,
36+
...viewProps
3537
} = props;
3638

37-
const { boxStyle, textStyle } = mergeStyles(getBadgeStyles, getStyles)(
38-
{ size, color, isSolid },
39+
const { containerStyle, textStyle } = mergeStyles(getBadgeStyles, getStyles)(
40+
{ size, color, isSolid, shape },
3941
theme,
4042
);
4143

4244
return (
43-
<Box
44-
shape={shape}
45-
style={{
46-
alignItems: 'center',
47-
alignSelf: 'flex-start',
48-
backgroundColor: boxStyle.backgroundColor,
49-
display: 'flex',
50-
flexDirection: 'row',
51-
height: boxStyle.height,
52-
justifyContent: 'center',
53-
paddingLeft: boxStyle.paddingLeft,
54-
paddingRight: boxStyle.paddingRight,
55-
...boxStyle,
56-
}}
57-
>
45+
<View style={containerStyle} {...viewProps}>
5846
<Strong
5947
size={size}
6048
getStyles={() => ({
@@ -63,7 +51,7 @@ const BadgeBase = (props: BadgeProps) => {
6351
>
6452
{children}
6553
</Strong>
66-
</Box>
54+
</View>
6755
);
6856
};
6957

src/components/Checkbox/Checkbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818

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

21-
export interface CheckboxProps {
21+
export interface CheckboxProps extends TouchableHighlightProps {
2222
theme: Theme;
2323
isChecked?: boolean;
2424
isDisabled?: boolean;
@@ -31,7 +31,7 @@ export interface CheckboxProps {
3131
getStyles?: ReplaceReturnType<GetCheckboxStyles, DeepPartial<CheckboxStyles>>;
3232
}
3333

34-
const CheckboxBase = (props: CheckboxProps & TouchableHighlightProps) => {
34+
const CheckboxBase = (props: CheckboxProps) => {
3535
const {
3636
isChecked = false,
3737
isDisabled = false,

src/components/Layout/Box.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,44 @@ export interface BoxProps extends ViewStyle {
2525
shape?: Shape;
2626
}
2727

28-
const shapeMap = {
28+
export const shapeMapping: {
29+
[shape: string]: ViewStyle;
30+
} = {
2931
circle: {
30-
borderRadius: '50%',
32+
borderRadius: 999,
3133
},
3234
pill: {
33-
borderRadius: '999px',
35+
borderRadius: 999,
3436
},
3537
rounded: {
36-
borderRadius: `${BASE_BORDER_RADII}px`,
38+
borderRadius: BASE_BORDER_RADII,
3739
},
3840
roundedBottom: {
39-
borderRadius: `0 0 ${BASE_BORDER_RADII}px ${BASE_BORDER_RADII}px`,
41+
borderBottomLeftRadius: BASE_BORDER_RADII,
42+
borderBottomRightRadius: BASE_BORDER_RADII,
4043
},
4144
roundedLeft: {
42-
borderRadius: `${BASE_BORDER_RADII}px 0 0 ${BASE_BORDER_RADII}px`,
45+
borderBottomLeftRadius: BASE_BORDER_RADII,
46+
borderTopLeftRadius: BASE_BORDER_RADII,
4347
},
4448
roundedRight: {
45-
borderRadius: `0 ${BASE_BORDER_RADII}px ${BASE_BORDER_RADII}px 0`,
49+
borderBottomRightRadius: BASE_BORDER_RADII,
50+
borderTopRightRadius: BASE_BORDER_RADII,
4651
},
4752
roundedTop: {
48-
borderRadius: `${BASE_BORDER_RADII}px ${BASE_BORDER_RADII}px 0 0`,
53+
borderTopLeftRadius: BASE_BORDER_RADII,
54+
borderTopRightRadius: BASE_BORDER_RADII,
4955
},
5056
square: {
51-
borderRadius: '0',
57+
borderRadius: 0,
5258
},
5359
};
5460

5561
const propToFn = {
5662
elevation: (elevation: 0 | 1 | 2 | 3 | 4, theme: Theme) => {
5763
return theme.elevations[elevation];
5864
},
59-
shape: (shape: Shape) => shapeMap[shape],
65+
shape: (shape: Shape) => shapeMapping[shape],
6066
};
6167

6268
const Box = ({ theme, ...props }: BoxProps) => {

src/components/Progress/Progress.tsx

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

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

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

2222
const ProgressBase = (props: ProgressProps) => {
23-
const { percent = 0, size = 'medium', getStyles, theme } = props;
23+
const {
24+
percent = 0,
25+
size = 'medium',
26+
getStyles,
27+
theme,
28+
...viewProps
29+
} = props;
2430
const { containerStyle, progressStyle } = mergeStyles(
2531
getProgressStyles,
2632
getStyles,
@@ -30,7 +36,7 @@ const ProgressBase = (props: ProgressProps) => {
3036
<Spring to={{ value: percent }}>
3137
{({ value }) => {
3238
return (
33-
<View style={containerStyle}>
39+
<View style={containerStyle} {...viewProps}>
3440
<View
3541
// @ts-ignore
3642
accessibilityRole={Platform.OS === 'web' ? 'progress' : 'none'}

0 commit comments

Comments
 (0)