Skip to content

Commit 48acace

Browse files
committed
feat(label): separate textstyle props
1 parent 7e6e725 commit 48acace

7 files changed

Lines changed: 51 additions & 11 deletions

File tree

docs/CustomizeTheme.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { ThemeProvider } from 'paramount-ui'
6767
getContainerStyles?: GetContainerStyles;
6868
getRowStyles?: GetRowStyles;
6969
getTextInputStyles?: GetIconTextInputStyles;
70+
getLabelStyles?: GetLabelStyles;
7071
getListItemStyles?: GetListItemStyles;
7172
getOverlayStyles?: GetOverlayStyles;
7273
getPickerButtonStyles?: GetPickerButtonStyles;

src/components/Form/FormField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const FormField = (props: FormFieldProps) => {
7272

7373
const labelContent = (
7474
<View style={labelWrapperStyle}>
75-
<Label getStyles={() => ({ textStyle: labelTextStyle })}>{label}</Label>
75+
<Label getStyles={() => ({ labelStyle: labelTextStyle })}>{label}</Label>
7676
</View>
7777
);
7878

src/components/Typography/Label.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ Composes `Text`
2828
Using `getStyles` prop
2929

3030
```
31-
TextStyles {
32-
textStyle: TextStyle;
31+
LabelStyles {
32+
labelStyle: LabelStyle;
3333
}
3434
35-
getStyles={(TextProps, Theme) => TextStyles}
35+
getStyles={(LabelProps, Theme) => LabelStyles}
3636
```
3737

3838
Markup
3939

4040
```tsx
41-
<Text textStyle />
41+
<Text labelStyle />
4242
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TextStyle } from 'react-native';
2+
3+
import { Theme } from '../../theme/Theme';
4+
import { LabelProps } from './Label';
5+
import { getTextStyles } from './Text.styles';
6+
7+
export interface LabelStyles {
8+
labelStyle: TextStyle;
9+
}
10+
11+
export type GetLabelStyles = (props: LabelProps, theme: Theme) => LabelStyles;
12+
13+
export const getLabelStyles: GetLabelStyles = (props, theme) => {
14+
const { getStyles, ...rest } = props;
15+
const { textStyle } = getTextStyles(rest, theme);
16+
17+
return { labelStyle: textStyle };
18+
};

src/components/Typography/Label.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
import * as React from 'react';
22
import { Platform } from 'react-native';
3+
import { DeepPartial } from 'ts-essentials';
34

5+
import { useTheme } from '../../theme';
6+
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
7+
import { GetLabelStyles, getLabelStyles, LabelStyles } from './Label.styles';
48
import { Text, TextProps } from './Text';
59

6-
export const Label = (props: TextProps) => {
7-
const { children, ...textProps } = props;
10+
// tslint:disable-next-line
11+
// @ts-ignore
12+
export interface LabelProps extends TextProps {
13+
/** Callback to get element styles. */
14+
getStyles?: ReplaceReturnType<GetLabelStyles, DeepPartial<LabelStyles>>;
15+
}
16+
17+
export const Label = (props: LabelProps) => {
18+
const { children, getStyles, ...textProps } = props;
19+
const theme = useTheme();
20+
21+
const { labelStyle } = mergeStyles(
22+
getLabelStyles,
23+
getStyles,
24+
theme.components.getLabelStyles,
25+
)(props, theme);
826

927
return (
1028
<Text
1129
// @ts-ignore
1230
accessibilityRole={Platform.OS === 'web' ? 'label' : 'none'}
31+
getStyles={() => ({ textStyle: labelStyle })}
1332
{...textProps}
1433
>
1534
{children}

src/theme/Theme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { GetTabStyles } from '../components/Tabs/Tab.styles';
3131
import { GetTabsStyles } from '../components/Tabs/Tabs.styles';
3232
import { GetToastStyles } from '../components/Toast/Toast.styles';
3333
import { GetHeadingStyles } from '../components/Typography/Heading.styles';
34+
import { GetLabelStyles } from '../components/Typography/Label.styles';
3435
import { GetParagraphStyles } from '../components/Typography/Paragraph.styles';
3536
import { GetTextStyles } from '../components/Typography/Text.styles';
3637
import { defaultTheme } from './defaultTheme';
@@ -273,6 +274,7 @@ export interface Theme {
273274
getContainerStyles?: GetContainerStyles;
274275
getRowStyles?: GetRowStyles;
275276
getTextInputStyles?: GetTextInputStyles;
277+
getLabelStyles?: GetLabelStyles;
276278
getListItemStyles?: GetListItemStyles;
277279
getOverlayStyles?: GetOverlayStyles;
278280
getPickerButtonStyles?: GetPickerButtonStyles;

tests/__snapshots__/snapshot.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16150,11 +16150,11 @@ exports[`Label_2 1`] = `<div />`;
1615016150
exports[`Label_3 1`] = `
1615116151
<pre>
1615216152
<code>
16153-
TextStyles {
16154-
textStyle: TextStyle;
16153+
LabelStyles {
16154+
labelStyle: LabelStyle;
1615516155
}
1615616156

16157-
getStyles={(TextProps, Theme) =&gt; TextStyles}
16157+
getStyles={(LabelProps, Theme) =&gt; LabelStyles}
1615816158

1615916159
</code>
1616016160
</pre>
@@ -16165,7 +16165,7 @@ exports[`Label_4 1`] = `
1616516165
<code
1616616166
className="language-tsx"
1616716167
>
16168-
&lt;Text textStyle /&gt;
16168+
&lt;Text labelStyle /&gt;
1616916169

1617016170
</code>
1617116171
</pre>

0 commit comments

Comments
 (0)