Skip to content

Commit af2acff

Browse files
committed
src: types
1 parent 7b68618 commit af2acff

File tree

1 file changed

+306
-5
lines changed

1 file changed

+306
-5
lines changed

src/types.ts

Lines changed: 306 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,317 @@
99
*
1010
*/
1111

12-
import { ImageSourcePropType } from "react-native";
12+
import type { ImageSourcePropType } from 'react-native';
1313

14-
type Undefined<T> = { [P in keyof T]: P extends undefined ? T[P] : never};
14+
type Undefined<T> = { [P in keyof T]: P extends undefined ? T[P] : never };
1515

16-
type FilterFlags<Base, Condition> = {
17-
[Key in keyof Base]: Base[Key] extends Condition ? Key : never;
18-
};
16+
type FilterFlags<Base, Condition> = { [Key in keyof Base]: Base[Key] extends Condition ? Key : never; };
1917

2018
type AllowedNames<Base, Condition> = FilterFlags<Base, Condition>[keyof Base];
19+
2120
type SubType<Base, Condition> = Pick<Base, AllowedNames<Base, Condition>>;
2221

2322
export type OptionalKeys<T> = Exclude<keyof T, NonNullable<keyof SubType<Undefined<T>, never>>>;
2423

24+
export type ThemeProps<T> = {
25+
[name: string]: T;
26+
};
27+
28+
type ComponentsProps<T> = Omit<Pick<T, OptionalKeys<T>>, 'children' | 'variant'>;
29+
30+
export type VariantType<T> = ComponentsProps<T> & {
31+
variants?: {
32+
[name: string]: ComponentsProps<T>;
33+
};
34+
};
35+
36+
export type DefaultProps<Props extends object> = {
37+
[K in keyof Props]?: Props[K];
38+
};
39+
40+
export const borderProps = [
41+
'borderColor',
42+
'borderTopColor',
43+
'borderRightColor',
44+
'borderBottomColor',
45+
'borderLeftColor',
46+
'borderWidth',
47+
'borderTopWidth',
48+
'borderRightWidth',
49+
'borderLeftWidth',
50+
'borderBottomWidth',
51+
'borderStartWidth',
52+
'borderEndWidth',
53+
'borderStyle',
54+
] as const;
55+
export interface BorderPropsType {
56+
borderColor?: string;
57+
borderTopColor?: string;
58+
borderRightColor?: string;
59+
borderBottomColor?: string;
60+
borderLeftColor?: string;
61+
borderWidth?: number;
62+
borderTopWidth?: number;
63+
borderRightWidth?: number;
64+
borderLeftWidth?: number;
65+
borderBottomWidth?: number;
66+
borderStartWidth?: number;
67+
borderEndWidth?: number;
68+
borderStyle?: 'solid' | 'dotted' | 'dashed';
69+
}
70+
71+
export const spacingProps = [
72+
'm',
73+
'mt',
74+
'mr',
75+
'mb',
76+
'ml',
77+
'mx',
78+
'my',
79+
'ms',
80+
'p',
81+
'pt',
82+
'pr',
83+
'pb',
84+
'pl',
85+
'px',
86+
'py',
87+
'ps',
88+
] as const;
89+
export interface SpacingPropsType {
90+
m?: string | number;
91+
mt?: string | number;
92+
mr?: string | number;
93+
mb?: string | number;
94+
ml?: string | number;
95+
mx?: string | number;
96+
my?: string | number;
97+
ms?: string | number;
98+
p?: string | number;
99+
pt?: string | number;
100+
pr?: string | number;
101+
pb?: string | number;
102+
pl?: string | number;
103+
px?: string | number;
104+
py?: string | number;
105+
ps?: string | number;
106+
}
107+
108+
export const roundedProps = [
109+
'rounded',
110+
'roundedTopLeft',
111+
'roundedTopRight',
112+
'roundedBottomLeft',
113+
'roundedBottomRight',
114+
'roundedTop',
115+
'roundedLeft',
116+
'roundedRight',
117+
'roundedBottom',
118+
] as const;
119+
export interface RoundedPropsType {
120+
rounded?: string | number;
121+
roundedTopLeft?: string | number;
122+
roundedTopRight?: string | number;
123+
roundedBottomLeft?: string | number;
124+
roundedBottomRight?: string | number;
125+
roundedTop?: string | number;
126+
roundedLeft?: string | number;
127+
roundedRight?: string | number;
128+
roundedBottom?: string | number;
129+
}
130+
131+
export const shadowProps = ['shadow', 'shadowColor'] as const;
132+
export interface ShadowPropsType {
133+
shadow?: string | number;
134+
shadowColor?: string;
135+
}
136+
137+
export const dimensionProps = [
138+
'minH',
139+
'minW',
140+
'maxH',
141+
'maxW',
142+
'h',
143+
'w',
144+
] as const;
145+
export interface DimensionPropsType {
146+
minH?: number | string;
147+
minW?: number | string;
148+
maxH?: number | string;
149+
maxW?: number | string;
150+
h?: number | string;
151+
w?: number | string;
152+
}
153+
154+
export const flexProps = [
155+
'row',
156+
'flex',
157+
'flexDir',
158+
'flexWrap',
159+
'justifyContent',
160+
'alignSelf',
161+
'alignItems',
162+
] as const;
163+
export interface FlexPropsType {
164+
row?: boolean;
165+
flex?: number;
166+
flexDir?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
167+
flexWrap?: 'wrap' | 'nowrap' | 'wrap-reverse';
168+
justifyContent?:
169+
| 'flex-start'
170+
| 'flex-end'
171+
| 'center'
172+
| 'space-between'
173+
| 'space-around'
174+
| 'space-evenly';
175+
alignSelf?:
176+
| 'auto'
177+
| 'flex-start'
178+
| 'flex-end'
179+
| 'center'
180+
| 'stretch'
181+
| 'baseline';
182+
alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline';
183+
}
184+
185+
export const positionProps = [
186+
'position',
187+
'top',
188+
'right',
189+
'bottom',
190+
'left',
191+
] as const;
192+
export interface PositionPropsType {
193+
position?: 'absolute' | 'relative';
194+
top?: number;
195+
right?: number;
196+
bottom?: number;
197+
left?: number;
198+
}
199+
200+
export const backgroundProps = ['bg', 'bgImg', 'bgMode'] as const;
201+
export interface BackgroundPropsType {
202+
bg?: string;
203+
bgImg?: ImageSourcePropType;
204+
bgMode?: 'contain' | 'cover' | 'stretch' | 'repeat';
205+
}
206+
207+
export const textProps = [
208+
'color',
209+
'fontSize',
210+
'textDecorLine',
211+
'textDecorStyle',
212+
'fontStyle',
213+
'textDecorColor',
214+
'fontWeight',
215+
'fontFamily',
216+
'lineHeight',
217+
'textAlign',
218+
'textTransform',
219+
'letterSpacing',
220+
'textAlignVertical',
221+
] as const;
222+
export interface TextPropsType {
223+
color?: string;
224+
fontSize?: string | number;
225+
textDecorLine?:
226+
| 'none'
227+
| 'underline'
228+
| 'line-through'
229+
| 'underline line-through';
230+
textDecorStyle?: 'solid' | 'double' | 'dotted' | 'dashed';
231+
fontStyle?: 'normal' | 'italic';
232+
textDecorColor?: string;
233+
fontWeight?:
234+
| 'normal'
235+
| 'bold'
236+
| '100'
237+
| '200'
238+
| '300'
239+
| '400'
240+
| '500'
241+
| '600'
242+
| '700'
243+
| '800'
244+
| '900';
245+
fontFamily?: string;
246+
lineHeight?: number;
247+
textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify';
248+
textTransform?: 'none' | 'uppercase' | 'lowercase' | 'capitalize';
249+
letterSpacing?: number;
250+
textAlignVertical?: 'auto' | 'top' | 'bottom' | 'center';
251+
textDecorationLine?:
252+
| 'none'
253+
| 'underline'
254+
| 'line-through'
255+
| 'underline line-through';
256+
textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed';
257+
textDecorationColor?: string;
258+
textShadowColor?: string;
259+
textShadowOffset?: { width: number; height: number };
260+
textShadowRadius?: number;
261+
}
262+
263+
export const opacityProps = ['opacity'] as const;
264+
export interface OpacityPropsType {
265+
opacity?: number;
266+
}
267+
268+
export const overflowProps = ['overflow'] as const;
269+
export interface OverflowPropsType {
270+
overflow?: 'hidden' | 'visible' | 'scroll';
271+
}
272+
273+
export const zIndexProps = ['zIndex'] as const;
274+
export interface ZIndexPropsType {
275+
zIndex?: number;
276+
}
277+
278+
export const loadingProps = ['loading', 'loaderSize', 'loaderColor'] as const;
279+
export interface LoadingPropsType {
280+
loading?: boolean;
281+
loaderSize?: number | string;
282+
loaderColor?: string;
283+
}
284+
285+
export const preffixSuffixProps = ['preffix', 'suffix'] as const;
286+
export interface PrefixSuffixPropsType {
287+
suffix?: React.ReactNode;
288+
prefix?: React.ReactNode;
289+
}
290+
291+
export const inputProps = ['focusBorderColor'] as const;
292+
export interface InputPropsType {
293+
focusBorderColor?: string;
294+
}
295+
296+
export const disabledProps = ['disabled'] as const;
297+
export interface DisabledPropsType {
298+
disabled?: null | boolean;
299+
}
300+
301+
export const buttonProps = [
302+
'underlayColor',
303+
'block',
304+
'borderless',
305+
'rippleColor',
306+
'ripple',
307+
] as const;
308+
export interface ButtonPropsType {
309+
underlayColor?: string;
310+
block?: boolean;
311+
borderless?: boolean;
312+
rippleColor?: string;
313+
ripple?: boolean;
314+
}
315+
316+
export const overlayProps = ['overlayColor', 'overlayOpacity'] as const;
317+
export interface OverlayPropsType {
318+
overlayColor?: string;
319+
overlayOpacity?: number;
320+
}
321+
322+
export const variantProps = ['variant'] as const;
323+
export interface VariantPropsType {
324+
variant?: string;
325+
}

0 commit comments

Comments
 (0)