-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathcreateText.ts
More file actions
76 lines (70 loc) · 1.72 KB
/
createText.ts
File metadata and controls
76 lines (70 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import {Text} from 'react-native';
import createRestyleComponent from './createRestyleComponent';
import {BaseTheme, RestyleFunctionContainer} from './types';
import {
color,
opacity,
spacing,
typography,
textShadow,
visible,
ColorProps,
OpacityProps,
SpacingProps,
FontSizeProps,
TextShadowProps,
TypographyProps,
VisibleProps,
spacingShorthand,
SpacingShorthandProps,
layout,
LayoutProps,
} from './restyleFunctions';
import createVariant, {VariantProps} from './createVariant';
type BaseTextProps<Theme extends BaseTheme> = ColorProps<Theme> &
OpacityProps<Theme> &
VisibleProps<Theme> &
TypographyProps<Theme> &
FontSizeProps<Theme> &
SpacingProps<Theme> &
LayoutProps<Theme> &
TextShadowProps<Theme> &
VariantProps<Theme, 'textVariants'>;
export type TextProps<
Theme extends BaseTheme,
EnableShorthand extends boolean = true,
> = EnableShorthand extends true
? BaseTextProps<Theme> & SpacingShorthandProps<Theme>
: BaseTextProps<Theme>;
export const textRestyleFunctions = [
color,
opacity,
visible,
typography,
spacing,
spacingShorthand,
textShadow,
layout,
createVariant({themeKey: 'textVariants'}),
];
const createText = <
Theme extends BaseTheme,
Props = React.ComponentProps<typeof Text> & {children?: React.ReactNode},
EnableShorthand extends boolean = true,
>(
BaseComponent: React.ComponentType<any> = Text,
) => {
return createRestyleComponent<
TextProps<Theme, EnableShorthand> &
Omit<Props, keyof TextProps<Theme, EnableShorthand>>,
Theme
>(
textRestyleFunctions as RestyleFunctionContainer<
TextProps<Theme, EnableShorthand>,
Theme
>[],
BaseComponent,
);
};
export default createText;