Skip to content

Commit 13042c0

Browse files
authored
added type definition for autocompletion in theme declaration + doc (#115)
1 parent 26dfa2b commit 13042c0

File tree

13 files changed

+65
-51
lines changed

13 files changed

+65
-51
lines changed

apps/docs/pages/docs/customization.en-US.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ const ComponentStyle: ComponentStyleConfig = {
8282
}
8383
```
8484

85-
Example of default Input theme :
85+
Example of default Input theme with type-safe props.
86+
Using `InputProps` allows autocompletion in defineStyle.
8687

8788
```js
88-
import { defineStyle, defineStyleConfig } from 'react-native-ficus-ui';
89+
import { defineStyle, defineStyleConfig, InputProps } from 'react-native-ficus-ui';
8990

90-
const baseStyle = defineStyle({
91+
const baseStyle = defineStyle<InputProps>({
9192
borderRadius: 'md',
9293
alignSelf: 'flex-start',
9394
fontWeight: 'bold',

packages/react-native-ficus-ui/src/components/input/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import {
2323
forwardRef,
2424
useStyleConfig,
2525
} from '../system';
26+
import { TextProps } from '../text';
2627
import { useInput } from './input.service';
2728
import { InputOptions } from './input.types';
2829

2930
export interface InputProps
3031
extends NativeFicusProps<'TextInput'>,
3132
PrefixSuffixProps,
33+
Omit<TextProps, 'textAlign' | 'textAlignVertical' | 'as'>,
3234
InputOptions,
3335
ThemingProps<'Input'> {}
3436

packages/react-native-ficus-ui/src/components/input/textarea.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import {
2121
forwardRef,
2222
useStyleConfig,
2323
} from '../system';
24+
import { TextProps } from '../text';
2425
import { useInput } from './input.service';
2526
import { InputOptions } from './input.types';
2627

2728
export interface TextareaProps
2829
extends NativeFicusProps<'TextInput'>,
2930
PrefixSuffixProps,
3031
InputOptions,
32+
Omit<TextProps, 'as' | 'textAlign' | 'textAlignVertical'>,
3133
ThemingProps<'Textarea'> {}
3234

3335
export const Textarea = forwardRef<TextareaProps, 'TextInput'>((props, ref) => {

packages/react-native-ficus-ui/src/components/select/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import {
1010
toStyleSheetObject,
1111
useStyleConfig,
1212
} from '../system';
13+
import { TextProps } from '../text';
1314
import { useSelect } from './select.service';
1415

1516
export interface SelectProps
1617
extends NativeFicusProps<'PickerSelect'>,
18+
Partial<Omit<TextProps, 'as' | 'style'>>,
1719
ThemingProps<'Select'> {}
1820

1921
export const Select = forwardRef<SelectProps, 'PickerSelect'>((props, ref) => {

packages/react-native-ficus-ui/src/theme/components/avatar.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AvatarBadgeProps } from '../../components/avatar/avatar-badge';
12
import { createMultiStyleConfigHelpers, defineStyle } from '../../style-system';
23
import { darkenColor, lightenColor, randomColorFromString } from '../utils';
34

@@ -12,7 +13,7 @@ const avatarParts = [
1213
const { definePartsStyle, defineMultiStyleConfig } =
1314
createMultiStyleConfigHelpers(avatarParts);
1415

15-
const baseStyleBagde = defineStyle({
16+
const baseStyleBagde = defineStyle<AvatarBadgeProps>({
1617
bg: 'green.400',
1718
borderRadius: '100%',
1819
borderWidth: 2,
@@ -23,8 +24,8 @@ const baseStyleBagde = defineStyle({
2324
const baseStyleExcessLabel = defineStyle({
2425
bg: 'gray.300',
2526
fontSize: 'sm',
26-
width: 30,
27-
height: 30,
27+
w: 30,
28+
h: 30,
2829
});
2930

3031
const baseStyleContainer = defineStyle((props) => {
@@ -39,8 +40,8 @@ const baseStyleContainer = defineStyle((props) => {
3940
bg,
4041
borderColor: 'white',
4142
verticalAlign: 'center',
42-
width: 30,
43-
height: 30,
43+
w: 30,
44+
h: 30,
4445
};
4546
});
4647

@@ -71,20 +72,20 @@ const AVATAR_BADGE_RATIO = 3;
7172
function getSize(size: number) {
7273
return definePartsStyle({
7374
container: {
74-
width: size,
75-
height: size,
75+
w: size,
76+
h: size,
7677
},
7778
excessLabel: {
78-
width: size,
79-
height: size,
79+
w: size,
80+
h: size,
8081
fontSize: size / 4,
8182
},
8283
label: {
8384
fontSize: size / 3,
8485
},
8586
badge: {
86-
width: size / AVATAR_BADGE_RATIO,
87-
height: size / AVATAR_BADGE_RATIO,
87+
w: size / AVATAR_BADGE_RATIO,
88+
h: size / AVATAR_BADGE_RATIO,
8889
top: size - size / AVATAR_BADGE_RATIO,
8990
right: 0,
9091
},

packages/react-native-ficus-ui/src/theme/components/badge.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { BadgeProps } from '../../components';
12
import { defineStyle, defineStyleConfig } from '../../style-system';
23

3-
const baseStyle = defineStyle({
4+
const baseStyle = defineStyle<BadgeProps>({
45
px: 4,
56
py: 2,
67
textTransform: 'uppercase',

packages/react-native-ficus-ui/src/theme/components/button.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { ButtonProps } from '../../components';
12
import { defineStyle, defineStyleConfig } from '../../style-system';
23
import { runIfFn } from '../utils/run-if-fn';
34

4-
const baseStyle = defineStyle({
5+
const baseStyle = defineStyle<ButtonProps>({
56
borderRadius: 'md',
67
alignSelf: 'flex-start',
78
fontWeight: 'bold',
@@ -107,7 +108,7 @@ const variantSolid = defineStyle((props) => {
107108
const variantLink = defineStyle((props) => {
108109
const { colorScheme: c } = props;
109110
return {
110-
padding: 0,
111+
p: 0,
111112
lineHeight: 18,
112113
textDecorationLine: 'underline',
113114
textDecorationColor: `${c}.500`,
@@ -131,32 +132,32 @@ const sizes = {
131132
xs: defineStyle({
132133
px: 6,
133134
fontSize: 12,
134-
height: 25,
135+
h: 25,
135136
}),
136137
sm: defineStyle({
137138
px: 10,
138139
fontSize: 13,
139-
height: 30,
140+
h: 30,
140141
}),
141142
md: defineStyle({
142143
px: 14,
143144
fontSize: 15,
144-
height: 35,
145+
h: 35,
145146
}),
146147
lg: defineStyle({
147148
px: 16,
148149
fontSize: 17,
149-
height: 40,
150+
h: 40,
150151
}),
151152
xl: defineStyle({
152153
px: 18,
153154
fontSize: 19,
154-
height: 45,
155+
h: 45,
155156
}),
156157
'2xl': defineStyle({
157158
px: 20,
158159
fontSize: 21,
159-
height: 47,
160+
h: 47,
160161
}),
161162
};
162163

packages/react-native-ficus-ui/src/theme/components/icon-button.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const variantSolid = defineStyle((props) => {
107107
const variantLink = defineStyle((props) => {
108108
const { colorScheme: c } = props;
109109
return {
110-
padding: 0,
110+
p: 0,
111111
lineHeight: 18,
112112
textDecorationLine: 'underline',
113113
textDecorationColor: `${c}.500`,
@@ -130,33 +130,33 @@ const variants = {
130130
const sizes = {
131131
xs: defineStyle({
132132
fontSize: 12,
133-
height: 25,
134-
width: 25,
133+
h: 25,
134+
w: 25,
135135
}),
136136
sm: defineStyle({
137137
fontSize: 13,
138-
height: 30,
139-
width: 30,
138+
h: 30,
139+
w: 30,
140140
}),
141141
md: defineStyle({
142142
fontSize: 15,
143-
height: 35,
144-
width: 35,
143+
h: 35,
144+
w: 35,
145145
}),
146146
lg: defineStyle({
147147
fontSize: 17,
148-
height: 40,
149-
width: 40,
148+
h: 40,
149+
w: 40,
150150
}),
151151
xl: defineStyle({
152152
fontSize: 19,
153-
height: 45,
154-
width: 45,
153+
h: 45,
154+
w: 45,
155155
}),
156156
'2xl': defineStyle({
157157
fontSize: 21,
158-
height: 47,
159-
width: 47,
158+
h: 47,
159+
w: 47,
160160
}),
161161
};
162162

packages/react-native-ficus-ui/src/theme/components/input.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { InputProps } from '../../components';
12
import { defineStyle, defineStyleConfig } from '../../style-system';
23

3-
const baseStyle = defineStyle({
4+
const baseStyle = defineStyle<InputProps>({
45
borderRadius: 'md',
56
alignSelf: 'flex-start',
67
fontWeight: 'bold',
@@ -9,7 +10,7 @@ const baseStyle = defineStyle({
910
fontSize: 'md',
1011
bg: 'white',
1112
color: 'gray.800',
12-
shadow: 0,
13+
shadow: 'none',
1314
_disabled: {
1415
opacity: 0.6,
1516
},
@@ -42,7 +43,7 @@ const variants = {
4243

4344
const sizes = {
4445
xs: defineStyle({
45-
height: 24,
46+
h: 24,
4647
px: 'sm',
4748
py: 0,
4849
fontSize: 'xs',
@@ -52,7 +53,7 @@ const sizes = {
5253
},
5354
}),
5455
sm: defineStyle({
55-
height: 32,
56+
h: 32,
5657
px: 'md',
5758
py: 'md',
5859
fontSize: 'sm',
@@ -62,7 +63,7 @@ const sizes = {
6263
},
6364
}),
6465
md: defineStyle({
65-
height: 40,
66+
h: 40,
6667
px: 'lg',
6768
py: 'lg',
6869
fontSize: 'md',
@@ -72,7 +73,7 @@ const sizes = {
7273
},
7374
}),
7475
lg: defineStyle({
75-
height: 48,
76+
h: 48,
7677
px: 'lg',
7778
py: 'lg',
7879
fontSize: 'md',

packages/react-native-ficus-ui/src/theme/components/pin-input.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { PinInputProps } from '../../components/pin-input';
12
import { defineStyle, defineStyleConfig } from '../../style-system';
23

3-
const baseStyle = defineStyle({
4+
const baseStyle = defineStyle<PinInputProps>({
45
alignSelf: 'flex-start',
56
justifyContent: 'flex-start',
67
});

0 commit comments

Comments
 (0)