Skip to content

Commit ae86c4d

Browse files
committed
feat(text): add more text transforms
1 parent 128ce7c commit ae86c4d

5 files changed

Lines changed: 45 additions & 26 deletions

File tree

src/components/Typography/Paragraph.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface ParagraphProps extends TextProps {
2323
color?: TextColor;
2424
size?: ParagraphSize;
2525
theme: Theme;
26-
textAlign?: TextAlign;
26+
align?: TextAlign;
2727
fontFamily?: FontFamily;
2828

2929
getStyles?: ReplaceReturnType<
@@ -38,7 +38,7 @@ const ParagraphBase = (props: ParagraphProps) => {
3838
color = 'default',
3939
fontFamily = 'text',
4040
size = 'medium',
41-
textAlign,
41+
align,
4242
theme,
4343
getStyles,
4444
...textProps
@@ -53,7 +53,7 @@ const ParagraphBase = (props: ParagraphProps) => {
5353
<Text
5454
// @ts-ignore
5555
accessibilityLabel="p"
56-
style={[{ textAlign }, paragraphStyle]}
56+
style={[{ textAlign: align }, paragraphStyle]}
5757
{...textProps}
5858
>
5959
{children}

src/components/Typography/Text.styles.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@ import {
77
TextColors,
88
Theme,
99
} from '../../theme/ThemeInterface';
10+
import { TextAlign, TextTransform } from './types';
1011

1112
export interface TextSizes {
1213
small: TextStyle;
1314
medium: TextStyle;
1415
large: TextStyle;
1516
}
1617

17-
export interface ColorVariations {
18-
lightest: string;
19-
light: string;
20-
base: string;
21-
dark: string;
22-
darkest: string;
23-
}
24-
2518
export type TextSize = keyof TextSizes;
2619

2720
export interface TextVariables {
@@ -33,10 +26,6 @@ export interface TextVariables {
3326
export const getTextVariables = (theme: Theme): TextVariables => {
3427
return {
3528
size: {
36-
/**
37-
* It's useful to have xlarge because `Link` uses the `Text` component.
38-
* A `Link` could be used as xlarge in the context of a breadcrumb.
39-
*/
4029
large: {
4130
fontSize: theme.textSizes.large,
4231
fontWeight: '400',
@@ -66,9 +55,12 @@ export const getTextVariables = (theme: Theme): TextVariables => {
6655
};
6756

6857
export interface TextStylesProps {
69-
bold: boolean;
58+
isBold: boolean;
59+
isItalic: boolean;
7060
size: TextSize;
7161
color: TextColor;
62+
align: TextAlign;
63+
transform?: TextTransform;
7264
fontFamily: FontFamily;
7365
isInline: boolean;
7466
}
@@ -90,7 +82,7 @@ export const getTextColor = (textColors: TextColors) => (
9082
) => textColors[textColor];
9183

9284
export const getTextStyles: GetTextStyles = (
93-
{ size, color, fontFamily, isInline, bold },
85+
{ size, color, fontFamily, isInline, isBold, isItalic, align, transform },
9486
theme,
9587
) => {
9688
const textVariables = getTextVariables(theme);
@@ -99,16 +91,23 @@ export const getTextStyles: GetTextStyles = (
9991
textStyle: {
10092
color: getTextColor(textVariables.color)(color),
10193
fontFamily: getFontFamily(textVariables.fontFamily)(fontFamily),
94+
textAlign: align,
10295
...(isInline
10396
? {
10497
alignSelf: 'flex-start',
10598
flexDirection: 'row',
10699
}
107100
: {}),
108101
...textVariables.size[size],
109-
...(bold && {
102+
...(isBold && {
110103
fontWeight: '600',
111104
}),
105+
...(isItalic && {
106+
fontStyle: 'italic',
107+
}),
108+
...(transform && {
109+
textTransform: transform,
110+
}),
112111
},
113112
};
114113
};

src/components/Typography/Text.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import {
1111
import withTheme from '../../theme/withTheme';
1212
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
1313
import { GetTextStyles, getTextStyles, TextStyles } from './Text.styles';
14-
import { TextAlign } from './types';
14+
import { TextAlign, TextTransform } from './types';
1515

1616
export interface TextStyleProps {
1717
isInline?: boolean;
1818
size?: TextSize;
1919
color?: TextColor;
20-
textAlign?: TextAlign;
20+
align?: TextAlign;
21+
transform?: TextTransform;
2122
fontFamily?: FontFamily;
22-
bold?: boolean;
23+
isBold?: boolean;
24+
isItalic?: boolean;
2325
}
2426

2527
// @ts-ignore: need to override for web purposes
@@ -37,21 +39,23 @@ const TextBase = (props: TextProps) => {
3739
color = 'default',
3840
fontFamily = 'text',
3941
size = 'medium',
40-
textAlign,
42+
align = 'left',
4143
isInline = false,
4244
theme,
4345
getStyles,
44-
bold = false,
46+
isBold = false,
47+
isItalic = false,
48+
transform,
4549
...textProps
4650
} = props;
4751

4852
const { textStyle } = mergeStyles(getTextStyles, getStyles)(
49-
{ size, color, fontFamily, isInline, bold },
53+
{ size, color, fontFamily, isInline, isBold, isItalic, align, transform },
5054
theme,
5155
);
5256

5357
return (
54-
<RNText style={[{ textAlign }, textStyle]} {...textProps}>
58+
<RNText style={textStyle} {...textProps}>
5559
{children}
5660
</RNText>
5761
);

src/components/Typography/Typography.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ import { Box } from '../Layout';
8484

8585
<Playground>
8686
<Box flexDirection="column">
87-
<Text bold>A red flair silhouetted.</Text>
87+
<Text isBold>A red flair silhouetted.</Text>
88+
<Text isItalic>A red flair silhouetted.</Text>
89+
<Text isItalic isBold>
90+
A red flair silhouetted.
91+
</Text>
92+
<Text align="left">A red flair silhouetted.</Text>
93+
<Text align="center">A red flair silhouetted.</Text>
94+
<Text align="right">A red flair silhouetted.</Text>
95+
<Text transform="uppercase">A red flair silhouetted.</Text>
96+
<Text transform="lowercase">A red flair silhouetted.</Text>
97+
<Text transform="capitalize">A red flair silhouetted.</Text>
8898
</Box>
8999
</Playground>
90100

src/components/Typography/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
export type TextAlign = 'auto' | 'left' | 'right' | 'center' | 'justify';
2+
export type TextTransform =
3+
| 'none'
4+
| 'capitalize'
5+
| 'uppercase'
6+
| 'lowercase'
7+
| undefined;

0 commit comments

Comments
 (0)