Skip to content

Commit e208ed5

Browse files
committed
feat(typography): add docs and refactoring
1 parent da6703d commit e208ed5

9 files changed

Lines changed: 328 additions & 837 deletions

File tree

src/components/KitchenSink/KitchenSink.tsx

Lines changed: 23 additions & 233 deletions
Large diffs are not rendered by default.

src/components/Typography/Heading.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Box, Heading } from '..';
99

1010
# Heading
1111

12-
Composes React Native's `Text` component (i.e. you can pass its props)
12+
Composes React Native's `Text` component
1313

1414
### Usage
1515

src/components/Typography/Paragraph.mdx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,10 @@ import { Box, Paragraph } from '..';
99

1010
# Paragraph
1111

12-
Composes React Native's `Text` component (i.e. you can pass its props)
13-
14-
**Note!!!** In web environment sometimes you need to wrap `Paragraph` in a `<Box>` or provide a parent node with `display: flex` and `flex-direction: column` for centering to work properly. In React Native it is non issue because all nodes be default have these properties
12+
Composes React Native's `Text` component
1513

1614
### Usage
1715

18-
<Playground>
19-
<Box>
20-
<Paragraph
21-
color="primary"
22-
align="left"
23-
size="large" // small - large or number
24-
fontFamily="text"
25-
weight="normal"
26-
getStyles={(props, theme) => ({
27-
paragraphStyle: {},
28-
})}
29-
>
30-
Lorem ipsum dolar set amet
31-
</Paragraph>
32-
</Box>
33-
</Playground>
34-
35-
### Sizes
36-
3716
<Playground>
3817
<Box flexDirection="column">
3918
<Paragraph size="small">Lorem ipsum dolar set amet</Paragraph>
@@ -45,3 +24,21 @@ Composes React Native's `Text` component (i.e. you can pass its props)
4524
### Props
4625

4726
<Props of={Paragraph} />
27+
28+
### Customization
29+
30+
Using `getStyles` prop
31+
32+
```
33+
ParagraphStyles {
34+
textStyle: ParagraphStyle;
35+
}
36+
37+
getStyles={(ParagraphProps, Theme) => ParagraphStyles}
38+
```
39+
40+
Markup
41+
42+
```tsx
43+
<Paragraph paragraphStyle />
44+
```

src/components/Typography/Paragraph.styles.ts

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

3-
import {
4-
FontFamily,
5-
FontWeight,
6-
ParagraphSize,
7-
ParagraphSizes,
8-
TextColor,
9-
Theme,
10-
} from '../../theme/Theme';
11-
import { getFontFamily, getFontWeight, getTextColor } from './Text.styles';
12-
import { TextAlign } from './types';
13-
14-
export interface ParagraphStylesProps {
15-
align: TextAlign;
16-
size: ParagraphSize;
17-
color: TextColor;
18-
fontFamily: FontFamily;
19-
weight?: FontWeight;
20-
}
3+
import { ParagraphSize, ParagraphSizes, Theme } from '../../theme/Theme';
4+
import { ParagraphProps } from './Paragraph';
5+
import { getFontWeight, getTextColor } from './Text.styles';
216

227
export interface ParagraphStyles {
238
paragraphStyle: TextStyle;
249
}
2510

2611
export type GetParagraphStyles = (
27-
paragraphStylesProps: ParagraphStylesProps,
12+
props: ParagraphProps,
2813
theme: Theme,
2914
) => ParagraphStyles;
3015

@@ -38,7 +23,7 @@ export const getParagraphSize = (paragraphSizes: ParagraphSizes) => (
3823
};
3924

4025
export const getParagraphStyles: GetParagraphStyles = (
41-
{ size, color, fontFamily, align, weight },
26+
{ color = 'default', size = 'medium', align = 'left', weight },
4227
theme,
4328
) => {
4429
const sizeStyle = getParagraphSize(theme.paragraphSizes)(size);
@@ -47,7 +32,7 @@ export const getParagraphStyles: GetParagraphStyles = (
4732
paragraphStyle: {
4833
...sizeStyle,
4934
color: getTextColor(theme.colors.text)(color),
50-
fontFamily: getFontFamily(theme.fontFamilies)(fontFamily),
35+
fontFamily: theme.fontFamilies.text,
5136
fontWeight:
5237
getFontWeight(theme.fontWeights)(weight) || sizeStyle.fontWeight,
5338
marginBottom: theme.textSizes.medium.fontSize,

src/components/Typography/Paragraph.tsx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import { Text, TextProps } from 'react-native';
33
import { DeepPartial } from 'ts-essentials';
44

55
import { useTheme } from '../../theme';
6-
import {
7-
FontFamily,
8-
FontWeight,
9-
ParagraphSize,
10-
TextColor,
11-
} from '../../theme/Theme';
6+
import { FontWeight, TextColor, TextSize } from '../../theme/Theme';
127
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
138
import {
149
GetParagraphStyles,
@@ -19,13 +14,34 @@ import { TextAlign } from './types';
1914

2015
// @ts-ignore: need to override for web purposes
2116
export interface ParagraphProps extends TextProps {
22-
children: React.ReactNode;
17+
/**
18+
* Size of the paragraph.
19+
* @default "medium"
20+
*/
21+
size?: TextSize;
22+
23+
/**
24+
* Color of the paragraph.
25+
* @default "default"
26+
*/
2327
color?: TextColor;
24-
size?: ParagraphSize;
25-
weight?: FontWeight;
28+
29+
/**
30+
* Alignment of the paragraph.
31+
* @default "left"
32+
*/
2633
align?: TextAlign;
27-
fontFamily?: FontFamily;
2834

35+
/**
36+
* Weight of the paragraph.
37+
* @default paragraphSize.fontWeight
38+
*/
39+
weight?: FontWeight;
40+
41+
/** Text content */
42+
children?: React.ReactNode;
43+
44+
/** Callback to get element styles. */
2945
getStyles?: ReplaceReturnType<
3046
GetParagraphStyles,
3147
DeepPartial<ParagraphStyles>
@@ -36,7 +52,6 @@ export const Paragraph = (props: ParagraphProps) => {
3652
const {
3753
children,
3854
color = 'default',
39-
fontFamily = 'text',
4055
size = 'medium',
4156
align = 'left',
4257
weight,
@@ -49,7 +64,7 @@ export const Paragraph = (props: ParagraphProps) => {
4964
getParagraphStyles,
5065
getStyles,
5166
theme.components.getParagraphStyles,
52-
)({ align, size, color, fontFamily, weight }, theme);
67+
)(props, theme);
5368

5469
return (
5570
<Text

src/components/Typography/Text.mdx

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,7 @@ import { Box, Text } from '..';
99

1010
# Text
1111

12-
Composes React Native's `Text` component (i.e. you can pass its props)
13-
14-
**Note!!!** In web environment sometimes you need to wrap `Text` in a `<Box>` or provide a parent node with `display: flex` and `flex-direction: column` for centering to work properly. In React Native it is non issue because all nodes be default have these properties
15-
16-
### Usage
17-
18-
<Playground>
19-
<Box>
20-
<Text
21-
color="primary" // or custom
22-
align="left"
23-
size="large" // small - large or number
24-
fontFamily="text"
25-
weight="normal"
26-
isItalic
27-
isInline
28-
transform="uppercase"
29-
getStyles={(props, theme) => ({
30-
textStyle: {},
31-
})}
32-
>
33-
Lorem ipsum dolar set amet
34-
</Text>
35-
</Box>
36-
</Playground>
12+
Composes React Native's `Text`
3713

3814
### Sizes
3915

@@ -65,16 +41,6 @@ Composes React Native's `Text` component (i.e. you can pass its props)
6541
</Box>
6642
</Playground>
6743

68-
### Font Families
69-
70-
<Playground>
71-
<Box flexDirection="column">
72-
<Text fontFamily="heading">heading</Text>
73-
<Text fontFamily="text">text</Text>
74-
<Text fontFamily="mono">mono</Text>
75-
</Box>
76-
</Playground>
77-
7844
### Font Weights
7945

8046
<Playground>
@@ -87,20 +53,52 @@ Composes React Native's `Text` component (i.e. you can pass its props)
8753
</Box>
8854
</Playground>
8955

90-
### Variations
56+
### Alignments
9157

9258
<Playground>
9359
<Box flexDirection="column">
94-
<Text isItalic>Lorem ipsum dolar set amet</Text>
9560
<Text align="left">Lorem ipsum dolar set amet</Text>
9661
<Text align="center">Lorem ipsum dolar set amet</Text>
9762
<Text align="right">Lorem ipsum dolar set amet</Text>
63+
</Box>
64+
</Playground>
65+
66+
### Transforms
67+
68+
<Playground>
69+
<Box flexDirection="column">
9870
<Text transform="uppercase">Lorem ipsum dolar set amet</Text>
9971
<Text transform="lowercase">Lorem ipsum dolar set amet</Text>
10072
<Text transform="capitalize">Lorem ipsum dolar set amet</Text>
10173
</Box>
10274
</Playground>
10375

76+
### Italic
77+
78+
<Playground>
79+
<Box flexDirection="column">
80+
<Text isItalic>Lorem ipsum dolar set amet</Text>
81+
</Box>
82+
</Playground>
83+
10484
### Props
10585

10686
<Props of={Text} />
87+
88+
### Customization
89+
90+
Using `getStyles` prop
91+
92+
```
93+
TextStyles {
94+
textStyle: TextStyle;
95+
}
96+
97+
getStyles={(TextProps, Theme) => TextStyles}
98+
```
99+
100+
Markup
101+
102+
```tsx
103+
<Text textStyle />
104+
```

src/components/Typography/Text.styles.ts

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

33
import {
4-
FontFamilies,
5-
FontFamily,
64
FontWeight,
75
FontWeights,
86
RNFontWeight,
@@ -12,31 +10,13 @@ import {
1210
TextSizes,
1311
Theme,
1412
} from '../../theme/Theme';
15-
import { TextAlign, TextTransform } from './types';
16-
17-
export interface TextStylesProps {
18-
isItalic: boolean;
19-
size: TextSize;
20-
color: TextColor;
21-
align: TextAlign;
22-
transform?: TextTransform;
23-
fontFamily: FontFamily;
24-
isInline: boolean;
25-
weight?: FontWeight;
26-
}
13+
import { TextProps } from './Text';
2714

2815
export interface TextStyles {
2916
textStyle: TextStyle;
3017
}
3118

32-
export type GetTextStyles = (
33-
textStylesProps: TextStylesProps,
34-
theme: Theme,
35-
) => TextStyles;
36-
37-
export const getFontFamily = (fontFamilies: FontFamilies) => (
38-
fontFamily: FontFamily,
39-
) => fontFamilies[fontFamily];
19+
export type GetTextStyles = (props: TextProps, theme: Theme) => TextStyles;
4020

4121
export const getFontWeight = (fontWeights: FontWeights) => (
4222
fontWeight?: FontWeight,
@@ -68,7 +48,14 @@ export const getTextSize = (textSizes: TextSizes) => (
6848
};
6949

7050
export const getTextStyles: GetTextStyles = (
71-
{ size, color, fontFamily, isInline, isItalic, align, transform, weight },
51+
{
52+
color = 'default',
53+
size = 'medium',
54+
align = 'left',
55+
weight,
56+
isItalic = false,
57+
transform,
58+
},
7259
theme,
7360
) => {
7461
const sizeStyle = getTextSize(theme.textSizes)(size);
@@ -77,16 +64,10 @@ export const getTextStyles: GetTextStyles = (
7764
textStyle: {
7865
...sizeStyle,
7966
color: getTextColor(theme.colors.text)(color),
80-
fontFamily: getFontFamily(theme.fontFamilies)(fontFamily),
67+
fontFamily: theme.fontFamilies.text,
8168
fontWeight:
8269
getFontWeight(theme.fontWeights)(weight) || sizeStyle.fontWeight,
8370
textAlign: align,
84-
...(isInline
85-
? {
86-
alignSelf: 'flex-start',
87-
flexDirection: 'row',
88-
}
89-
: {}),
9071
...(isItalic && {
9172
fontStyle: 'italic',
9273
}),

0 commit comments

Comments
 (0)