react-native-mantine 0.1.11 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/lib/commonjs/components/Button/Button.styles.js +224 -0
  2. package/lib/commonjs/components/Button/Button.styles.js.map +1 -0
  3. package/lib/commonjs/components/Button/index.js +108 -0
  4. package/lib/commonjs/components/Button/index.js.map +1 -0
  5. package/lib/commonjs/components/Input/Input.styles.js +218 -0
  6. package/lib/commonjs/components/Input/Input.styles.js.map +1 -0
  7. package/lib/commonjs/components/Input/index.js +13 -0
  8. package/lib/commonjs/components/Input/index.js.map +1 -0
  9. package/lib/commonjs/components/index.js +13 -2
  10. package/lib/commonjs/components/index.js.map +1 -1
  11. package/lib/commonjs/theme/create-styles.js +2 -2
  12. package/lib/commonjs/theme/create-styles.js.map +1 -1
  13. package/lib/commonjs/theme/{generate-theme.js → create-theme.js} +4 -4
  14. package/lib/commonjs/theme/create-theme.js.map +1 -0
  15. package/lib/commonjs/theme/default-theme.js.map +1 -1
  16. package/lib/commonjs/theme/index.js +7 -0
  17. package/lib/commonjs/theme/index.js.map +1 -1
  18. package/lib/commonjs/theme/theme-provider.js +2 -2
  19. package/lib/commonjs/theme/theme-provider.js.map +1 -1
  20. package/lib/commonjs/theme/utils/rem.js +23 -0
  21. package/lib/commonjs/theme/utils/rem.js.map +1 -0
  22. package/lib/module/components/Button/Button.styles.js +220 -0
  23. package/lib/module/components/Button/Button.styles.js.map +1 -0
  24. package/lib/module/components/Button/index.js +101 -0
  25. package/lib/module/components/Button/index.js.map +1 -0
  26. package/lib/module/components/Input/Input.styles.js +214 -0
  27. package/lib/module/components/Input/Input.styles.js.map +1 -0
  28. package/lib/module/components/Input/index.js +4 -0
  29. package/lib/module/components/Input/index.js.map +1 -0
  30. package/lib/module/components/index.js +1 -0
  31. package/lib/module/components/index.js.map +1 -1
  32. package/lib/module/theme/create-styles.js +2 -2
  33. package/lib/module/theme/create-styles.js.map +1 -1
  34. package/lib/module/theme/{generate-theme.js → create-theme.js} +2 -2
  35. package/lib/module/theme/create-theme.js.map +1 -0
  36. package/lib/module/theme/default-theme.js.map +1 -1
  37. package/lib/module/theme/index.js +1 -0
  38. package/lib/module/theme/index.js.map +1 -1
  39. package/lib/module/theme/theme-provider.js +2 -2
  40. package/lib/module/theme/theme-provider.js.map +1 -1
  41. package/lib/module/theme/utils/rem.js +19 -0
  42. package/lib/module/theme/utils/rem.js.map +1 -0
  43. package/lib/typescript/commonjs/src/components/ActionIcon/ActionIcon.d.ts +1 -1
  44. package/lib/typescript/commonjs/src/components/ActionIcon/ActionIcon.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/src/components/Button/Button.styles.d.ts +26 -0
  46. package/lib/typescript/commonjs/src/components/Button/Button.styles.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/src/components/Button/index.d.ts +42 -0
  48. package/lib/typescript/commonjs/src/components/Button/index.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/components/Input/Input.styles.d.ts +20 -0
  50. package/lib/typescript/commonjs/src/components/Input/Input.styles.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/components/Input/index.d.ts +2 -0
  52. package/lib/typescript/commonjs/src/components/Input/index.d.ts.map +1 -0
  53. package/lib/typescript/commonjs/src/components/UnstyledButton/UnstyledButton.styles.d.ts +2 -2
  54. package/lib/typescript/commonjs/src/components/index.d.ts +1 -0
  55. package/lib/typescript/commonjs/src/components/index.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/src/theme/create-styles.d.ts +7 -3
  57. package/lib/typescript/commonjs/src/theme/create-styles.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/src/theme/create-theme.d.ts +3 -0
  59. package/lib/typescript/commonjs/src/theme/create-theme.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/theme/default-theme.d.ts +2 -2
  61. package/lib/typescript/commonjs/src/theme/default-theme.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/src/theme/index.d.ts +1 -0
  63. package/lib/typescript/commonjs/src/theme/index.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/src/theme/theme-provider.d.ts +4 -4
  65. package/lib/typescript/commonjs/src/theme/theme-provider.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/src/theme/types/DefaultProps.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/src/theme/utils/rem.d.ts +3 -0
  68. package/lib/typescript/commonjs/src/theme/utils/rem.d.ts.map +1 -0
  69. package/lib/typescript/module/src/components/ActionIcon/ActionIcon.d.ts +1 -1
  70. package/lib/typescript/module/src/components/ActionIcon/ActionIcon.d.ts.map +1 -1
  71. package/lib/typescript/module/src/components/Button/Button.styles.d.ts +26 -0
  72. package/lib/typescript/module/src/components/Button/Button.styles.d.ts.map +1 -0
  73. package/lib/typescript/module/src/components/Button/index.d.ts +42 -0
  74. package/lib/typescript/module/src/components/Button/index.d.ts.map +1 -0
  75. package/lib/typescript/module/src/components/Input/Input.styles.d.ts +20 -0
  76. package/lib/typescript/module/src/components/Input/Input.styles.d.ts.map +1 -0
  77. package/lib/typescript/module/src/components/Input/index.d.ts +2 -0
  78. package/lib/typescript/module/src/components/Input/index.d.ts.map +1 -0
  79. package/lib/typescript/module/src/components/UnstyledButton/UnstyledButton.styles.d.ts +2 -2
  80. package/lib/typescript/module/src/components/index.d.ts +1 -0
  81. package/lib/typescript/module/src/components/index.d.ts.map +1 -1
  82. package/lib/typescript/module/src/theme/create-styles.d.ts +7 -3
  83. package/lib/typescript/module/src/theme/create-styles.d.ts.map +1 -1
  84. package/lib/typescript/module/src/theme/create-theme.d.ts +3 -0
  85. package/lib/typescript/module/src/theme/create-theme.d.ts.map +1 -0
  86. package/lib/typescript/module/src/theme/default-theme.d.ts +2 -2
  87. package/lib/typescript/module/src/theme/default-theme.d.ts.map +1 -1
  88. package/lib/typescript/module/src/theme/index.d.ts +1 -0
  89. package/lib/typescript/module/src/theme/index.d.ts.map +1 -1
  90. package/lib/typescript/module/src/theme/theme-provider.d.ts +4 -4
  91. package/lib/typescript/module/src/theme/theme-provider.d.ts.map +1 -1
  92. package/lib/typescript/module/src/theme/types/DefaultProps.d.ts.map +1 -1
  93. package/lib/typescript/module/src/theme/utils/rem.d.ts +3 -0
  94. package/lib/typescript/module/src/theme/utils/rem.d.ts.map +1 -0
  95. package/package.json +1 -1
  96. package/src/components/ActionIcon/ActionIcon.tsx +1 -1
  97. package/src/components/Button/Button.styles.ts +232 -0
  98. package/src/components/Button/index.tsx +175 -0
  99. package/src/components/Input/Input.styles.ts +225 -0
  100. package/src/components/Input/index.ts +1 -0
  101. package/src/components/index.tsx +1 -0
  102. package/src/theme/create-styles.ts +15 -4
  103. package/src/theme/{generate-theme.ts → create-theme.ts} +3 -2
  104. package/src/theme/default-theme.ts +3 -3
  105. package/src/theme/index.tsx +1 -0
  106. package/src/theme/theme-provider.tsx +6 -6
  107. package/src/theme/theme.d.ts +2 -0
  108. package/src/theme/types/DefaultProps.ts +9 -4
  109. package/src/theme/utils/rem.ts +19 -0
  110. package/lib/commonjs/theme/generate-theme.js.map +0 -1
  111. package/lib/module/theme/generate-theme.js.map +0 -1
  112. package/lib/typescript/commonjs/src/theme/generate-theme.d.ts +0 -3
  113. package/lib/typescript/commonjs/src/theme/generate-theme.d.ts.map +0 -1
  114. package/lib/typescript/module/src/theme/generate-theme.d.ts +0 -3
  115. package/lib/typescript/module/src/theme/generate-theme.d.ts.map +0 -1
@@ -0,0 +1,175 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { UnstyledButton } from '../UnstyledButton';
3
+ import type {
4
+ DefaultProps,
5
+ MantineColor,
6
+ MantineNumberSize,
7
+ MantineSize,
8
+ Variants,
9
+ } from '../../theme/types';
10
+ import type { MantineGradient } from '../../theme/theme';
11
+ import type { LoaderProps } from '../Loader';
12
+ import { ActivityIndicator } from 'react-native';
13
+ import { useComponentDefaultProps } from '../../theme/theme-provider';
14
+ import useStyles from './Button.styles';
15
+ import { BoxView } from '../BoxView';
16
+
17
+ export type ButtonStylesNames = any;
18
+
19
+ export interface ButtonProps extends DefaultProps {
20
+ /** Predefined button size */
21
+ size?: MantineSize;
22
+
23
+ /** Button type attribute */
24
+ type?: 'submit' | 'button' | 'reset';
25
+
26
+ /** Button color from theme */
27
+ color?: MantineColor;
28
+
29
+ /** Adds icon before button label */
30
+ leftIcon?: React.ReactNode;
31
+
32
+ /** Adds icon after button label */
33
+ rightIcon?: React.ReactNode;
34
+
35
+ /** Sets button width to 100% of parent element */
36
+ fullWidth?: boolean;
37
+
38
+ /** Key of theme.radius or any valid CSS value to set border-radius, theme.defaultRadius by default */
39
+ radius?: MantineNumberSize;
40
+
41
+ /** Controls button appearance */
42
+ variant?: Variants<
43
+ 'filled' | 'outline' | 'light' | 'white' | 'default' | 'subtle' | 'gradient'
44
+ >;
45
+
46
+ /** Controls gradient settings in gradient variant only */
47
+ gradient?: MantineGradient;
48
+
49
+ /** Set text-transform to uppercase */
50
+ uppercase?: boolean;
51
+
52
+ /** Reduces vertical and horizontal spacing */
53
+ compact?: boolean;
54
+
55
+ /** Indicate loading state */
56
+ loading?: boolean;
57
+
58
+ /** Props spread to Loader component */
59
+ loaderProps?: LoaderProps;
60
+
61
+ /** Loader position relative to button label */
62
+ loaderPosition?: 'left' | 'right' | 'center';
63
+
64
+ /** Button label */
65
+ children?: React.ReactNode;
66
+
67
+ /** Disabled state */
68
+ disabled?: boolean;
69
+
70
+ style?: any;
71
+ }
72
+
73
+ const defaultProps: Partial<ButtonProps> = {
74
+ size: 'sm',
75
+ type: 'button',
76
+ variant: 'filled',
77
+ loaderPosition: 'left',
78
+ };
79
+
80
+ export const _Button = forwardRef<HTMLButtonElement, ButtonProps>(
81
+ (props, ref) => {
82
+ const {
83
+ // className,
84
+ size,
85
+ color,
86
+ type,
87
+ disabled,
88
+ children,
89
+ leftIcon,
90
+ rightIcon,
91
+ fullWidth,
92
+ variant,
93
+ radius,
94
+ uppercase,
95
+ compact,
96
+ loading,
97
+ loaderPosition,
98
+ loaderProps,
99
+ gradient,
100
+ // classNames,
101
+ // styles,
102
+ // unstyled,
103
+ style,
104
+ ...others
105
+ } = useComponentDefaultProps('Button', defaultProps, props);
106
+
107
+ const { styles, sx } = useStyles(
108
+ {
109
+ radius,
110
+ color,
111
+ fullWidth,
112
+ compact,
113
+ gradient,
114
+ withLeftIcon: !!leftIcon,
115
+ withRightIcon: !!rightIcon,
116
+ },
117
+ {
118
+ name: 'Button',
119
+ // unstyled, classNames, styles,
120
+ variant,
121
+ size,
122
+ }
123
+ );
124
+
125
+ // const colors = theme.fn.variant({ color, variant });
126
+
127
+ // const loader = (
128
+ // <Loader
129
+ // color={colors.color}
130
+ // size={`calc(${(getSize({ size, sizes }) as any).height} / 2)`}
131
+ // {...loaderProps}
132
+ // />
133
+ // );
134
+ const loader = <ActivityIndicator />;
135
+
136
+ return (
137
+ <UnstyledButton
138
+ style={sx(styles.root, style)}
139
+ // type={type}
140
+ // disabled={disabled}
141
+ data-button
142
+ data-disabled={disabled || undefined}
143
+ data-loading={loading || undefined}
144
+ ref={ref}
145
+ // unstyled={unstyled}
146
+ {...others}
147
+ >
148
+ <BoxView style={styles.inner}>
149
+ {(leftIcon || (loading && loaderPosition === 'left')) && (
150
+ <BoxView style={sx(styles.icon, styles.leftIcon)}>
151
+ {loading && loaderPosition === 'left' ? loader : leftIcon}
152
+ </BoxView>
153
+ )}
154
+
155
+ {loading && loaderPosition === 'center' && (
156
+ <BoxView style={styles.centerLoader}>{loader}</BoxView>
157
+ )}
158
+
159
+ <BoxView
160
+ style={styles.label}
161
+ // style={{ textTransform: uppercase ? 'uppercase' : undefined }}
162
+ >
163
+ {children}
164
+ </BoxView>
165
+
166
+ {(rightIcon || (loading && loaderPosition === 'right')) && (
167
+ <BoxView style={sx(styles.icon, styles.rightIcon)}>
168
+ {loading && loaderPosition === 'right' ? loader : rightIcon}
169
+ </BoxView>
170
+ )}
171
+ </BoxView>
172
+ </UnstyledButton>
173
+ );
174
+ }
175
+ ) as any;
@@ -0,0 +1,225 @@
1
+ import type { MantineNumberSize } from '../../theme/types';
2
+ import { rem } from '../../theme/utils/rem';
3
+
4
+ export interface InputStylesParams {
5
+ radius: MantineNumberSize;
6
+ multiline: boolean;
7
+ invalid: boolean;
8
+ rightSectionWidth: string | number;
9
+ withRightSection: boolean;
10
+ iconWidth: string | number;
11
+ offsetBottom: boolean;
12
+ offsetTop: boolean;
13
+ pointer: boolean;
14
+ }
15
+
16
+ export const sizes = {
17
+ xs: rem(30),
18
+ sm: rem(36),
19
+ md: rem(42),
20
+ lg: rem(50),
21
+ xl: rem(60),
22
+ };
23
+
24
+ // const INPUT_VARIANTS = ['default', 'filled', 'unstyled'];
25
+
26
+ // interface GetVariantStylesInput {
27
+ // theme: MantineTheme;
28
+ // variant: string;
29
+ // }
30
+
31
+ // function getVariantStyles({ theme, variant }: GetVariantStylesInput) {
32
+ // if (!INPUT_VARIANTS.includes(variant)) {
33
+ // return null;
34
+ // }
35
+
36
+ // if (variant === 'default') {
37
+ // return {
38
+ // 'border': `${rem(1)} solid ${
39
+ // theme.colorScheme === 'dark'
40
+ // ? theme.colors.dark[4]
41
+ // : theme.colors.gray[4]
42
+ // }`,
43
+ // 'backgroundColor':
44
+ // theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.white,
45
+ // 'transition': 'border-color 100ms ease',
46
+ // '&:focus, &:focus-within': theme.focusRingStyles.inputStyles(theme),
47
+ // };
48
+ // }
49
+
50
+ // if (variant === 'filled') {
51
+ // return {
52
+ // 'border': `${rem(1)} solid transparent`,
53
+ // 'backgroundColor':
54
+ // theme.colorScheme === 'dark'
55
+ // ? theme.colors.dark[5]
56
+ // : theme.colors.gray[1],
57
+ // '&:focus, &:focus-within': theme.focusRingStyles.inputStyles(theme),
58
+ // };
59
+ // }
60
+
61
+ // return {
62
+ // 'borderWidth': 0,
63
+ // 'color': theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
64
+ // 'backgroundColor': 'transparent',
65
+ // 'minHeight': rem(28),
66
+ // 'outline': 0,
67
+
68
+ // '&:focus, &:focus-within': {
69
+ // outline: 'none',
70
+ // borderColor: 'transparent',
71
+ // },
72
+
73
+ // '&:disabled': {
74
+ // 'backgroundColor': 'transparent',
75
+
76
+ // '&:focus, &:focus-within': {
77
+ // outline: 'none',
78
+ // borderColor: 'transparent',
79
+ // },
80
+ // },
81
+ // };
82
+ // }
83
+
84
+ // export default createStyles(
85
+ // (
86
+ // theme,
87
+ // {
88
+ // multiline,
89
+ // radius,
90
+ // invalid,
91
+ // rightSectionWidth,
92
+ // withRightSection,
93
+ // iconWidth,
94
+ // offsetBottom,
95
+ // offsetTop,
96
+ // pointer,
97
+ // }: InputStylesParams,
98
+ // { variant, size }
99
+ // ) => {
100
+ // const invalidColor = theme.fn.variant({
101
+ // variant: 'filled',
102
+ // color: 'red',
103
+ // }).background;
104
+ // const sizeStyles =
105
+ // variant === 'default' || variant === 'filled'
106
+ // ? {
107
+ // minHeight: getSize({ size, sizes }),
108
+ // paddingLeft: `calc(${getSize({ size, sizes })} / 3)`,
109
+ // paddingRight: withRightSection
110
+ // ? rightSectionWidth || getSize({ size, sizes })
111
+ // : `calc(${getSize({ size, sizes })} / 3)`,
112
+ // borderRadius: theme.fn.radius(radius),
113
+ // }
114
+ // : null;
115
+
116
+ // return {
117
+ // wrapper: {
118
+ // position: 'relative',
119
+ // marginTop: offsetTop ? `calc(${theme.spacing.xs} / 2)` : undefined,
120
+ // marginBottom: offsetBottom
121
+ // ? `calc(${theme.spacing.xs} / 2)`
122
+ // : undefined,
123
+ // },
124
+
125
+ // input: {
126
+ // ...theme.fn.fontStyles(),
127
+ // 'height': multiline
128
+ // ? variant === 'unstyled'
129
+ // ? undefined
130
+ // : 'auto'
131
+ // : getSize({ size, sizes }),
132
+ // 'WebkitTapHighlightColor': 'transparent',
133
+ // 'lineHeight': multiline
134
+ // ? theme.lineHeight
135
+ // : `calc(${getSize({ size, sizes })} - ${rem(2)})`,
136
+ // 'appearance': 'none',
137
+ // 'resize': 'none',
138
+ // 'boxSizing': 'border-box',
139
+ // 'fontSize': getSize({ size, sizes: theme.fontSizes }),
140
+ // 'width': '100%',
141
+ // 'color':
142
+ // theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
143
+ // 'display': 'block',
144
+ // 'textAlign': 'left',
145
+ // 'cursor': pointer ? 'pointer' : undefined,
146
+ // ...getVariantStyles({ theme, variant }),
147
+ // ...sizeStyles,
148
+
149
+ // '&:disabled, &[data-disabled]': {
150
+ // 'backgroundColor':
151
+ // theme.colorScheme === 'dark'
152
+ // ? theme.colors.dark[6]
153
+ // : theme.colors.gray[1],
154
+ // 'color': theme.colors.dark[2],
155
+ // 'opacity': 0.6,
156
+ // 'cursor': 'not-allowed',
157
+
158
+ // '&::placeholder': {
159
+ // color: theme.colors.dark[2],
160
+ // },
161
+ // },
162
+
163
+ // '&[data-invalid]': {
164
+ // 'color': invalidColor,
165
+ // 'borderColor': invalidColor,
166
+
167
+ // '&::placeholder': {
168
+ // opacity: 1,
169
+ // color: invalidColor,
170
+ // },
171
+ // },
172
+
173
+ // '&[data-with-icon]': {
174
+ // paddingLeft:
175
+ // typeof iconWidth === 'number'
176
+ // ? rem(iconWidth)
177
+ // : getSize({ size, sizes }),
178
+ // },
179
+
180
+ // '&::placeholder': {
181
+ // ...theme.fn.placeholderStyles(),
182
+ // opacity: 1,
183
+ // },
184
+
185
+ // '&::-webkit-inner-spin-button, &::-webkit-outer-spin-button, &::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration':
186
+ // {
187
+ // appearance: 'none',
188
+ // },
189
+
190
+ // '&[type=number]': {
191
+ // MozAppearance: 'textfield',
192
+ // },
193
+ // },
194
+
195
+ // icon: {
196
+ // pointerEvents: 'none',
197
+ // position: 'absolute',
198
+ // zIndex: 1,
199
+ // left: 0,
200
+ // top: 0,
201
+ // bottom: 0,
202
+ // display: 'flex',
203
+ // alignItems: 'center',
204
+ // justifyContent: 'center',
205
+ // width: iconWidth ? rem(iconWidth) : getSize({ size, sizes }),
206
+ // color: invalid
207
+ // ? theme.colors.red[theme.colorScheme === 'dark' ? 6 : 7]
208
+ // : theme.colorScheme === 'dark'
209
+ // ? theme.colors.dark[2]
210
+ // : theme.colors.gray[5],
211
+ // },
212
+
213
+ // rightSection: {
214
+ // position: 'absolute',
215
+ // top: 0,
216
+ // bottom: 0,
217
+ // right: 0,
218
+ // display: 'flex',
219
+ // alignItems: 'center',
220
+ // justifyContent: 'center',
221
+ // width: rightSectionWidth || getSize({ size, sizes }),
222
+ // },
223
+ // };
224
+ // }
225
+ // );
@@ -0,0 +1 @@
1
+ export { sizes as INPUT_SIZES } from './Input.styles';
@@ -2,5 +2,6 @@ export * from './BoxView';
2
2
  export * from './Group';
3
3
  export * from './Stack';
4
4
  export * from './Text';
5
+ export * from './Button';
5
6
  export * from './UnstyledButton';
6
7
  export * from './ActionIcon';
@@ -4,19 +4,30 @@ import { StyleSheet } from 'react-native';
4
4
 
5
5
  import { useTheme } from './theme-provider';
6
6
 
7
- import type { TTheme } from './default-theme';
7
+ import type { MantineTheme } from './default-theme';
8
8
 
9
9
  type NamedStyles<T> = {
10
10
  [P in keyof T]: ViewStyle | TextStyle | ImageStyle;
11
11
  };
12
12
 
13
+ type Variations =
14
+ | {
15
+ variant?: string;
16
+ size: string | number;
17
+ }
18
+ | any;
19
+
13
20
  export function createStyles<T = any>(
14
- input: (theme: TTheme, params: any) => NamedStyles<T>
21
+ input: (
22
+ theme: MantineTheme,
23
+ params: any,
24
+ variations?: Variations
25
+ ) => NamedStyles<T>
15
26
  ) {
16
27
  const getStyleObject = typeof input === 'function' ? input : () => input;
17
- function useStyles(params?: any) {
28
+ function useStyles(params?: any, variations?: Variations) {
18
29
  const theme = useTheme();
19
- const styleObject = getStyleObject(theme, params);
30
+ const styleObject = getStyleObject(theme, params, variations);
20
31
  const sx = (...args: any) => {
21
32
  return args;
22
33
  };
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_COLORS, DEFAULT_THEME } from './default-theme';
2
- import type { TTheme } from './default-theme';
3
- export const generateTheme = (theme?: Partial<TTheme>): TTheme => {
2
+ import type { MantineTheme } from './default-theme';
3
+
4
+ export const createTheme = (theme?: Partial<MantineTheme>): MantineTheme => {
4
5
  const { primaryShade = 7, other = {} } = theme || {};
5
6
  return {
6
7
  ...DEFAULT_THEME,
@@ -214,7 +214,7 @@ export const DEFAULT_COLORS: {
214
214
  const tintColorLight = '#2f95dc';
215
215
  const tintColorDark = '#fff';
216
216
 
217
- export const _DEFAULT_THEME: TTheme = {
217
+ export const _DEFAULT_THEME: MantineTheme = {
218
218
  fontFamily: 'System font',
219
219
  fontFamilyBold: 'System font',
220
220
  fontFamilySemiBold: 'System font',
@@ -261,7 +261,7 @@ export const _DEFAULT_THEME: TTheme = {
261
261
  xl: 20,
262
262
  },
263
263
 
264
- defaultRadius:8,
264
+ defaultRadius: 8,
265
265
  radius: {
266
266
  xs: 2,
267
267
  sm: 4,
@@ -319,7 +319,7 @@ export type ThemeSize = {
319
319
 
320
320
  export type themeMode = 'dark' | 'light';
321
321
 
322
- export type TTheme = {
322
+ export type MantineTheme = {
323
323
  fontFamily: string;
324
324
  fontFamilyBold: string;
325
325
 
@@ -2,3 +2,4 @@ export { ThemeProvider, useTheme, Theme } from './theme-provider';
2
2
  export { createStyles } from './create-styles';
3
3
  export { filterProps } from './filter-props';
4
4
  export { getSize } from './get-size';
5
+ export { createTheme } from './create-theme';
@@ -13,15 +13,15 @@ import type { ColorSchemeName } from 'react-native';
13
13
  import type { ReactNode } from 'react';
14
14
 
15
15
  import { Layout } from './constants';
16
- import type { TTheme } from './default-theme';
17
- import { generateTheme } from './generate-theme';
16
+ import type { MantineTheme } from './default-theme';
17
+ import { createTheme } from './create-theme';
18
18
 
19
19
  import { filterProps } from './filter-props';
20
20
  import useCachedResources from '../hooks/useCachedResources';
21
21
 
22
22
  type ThemeProps = {
23
23
  children: ReactNode;
24
- theme?: Partial<TTheme>;
24
+ theme?: Partial<MantineTheme>;
25
25
  forceMode?: 'light' | 'dark';
26
26
  };
27
27
 
@@ -33,7 +33,7 @@ export const ThemeProvider = ({
33
33
  forceMode,
34
34
  }: {
35
35
  children: React.ReactNode;
36
- theme: TTheme;
36
+ theme: MantineTheme;
37
37
  forceMode?: 'light' | 'dark';
38
38
  }): React.ReactElement => {
39
39
  const { colors, primaryShade, primaryColor, secondaryColor } = theme;
@@ -87,7 +87,7 @@ export const ThemeProvider = ({
87
87
  );
88
88
  };
89
89
 
90
- export const useTheme = (): TTheme => useContext(ThemeContext);
90
+ export const useTheme = (): MantineTheme => useContext(ThemeContext);
91
91
 
92
92
  export const Theme = ({
93
93
  children,
@@ -97,7 +97,7 @@ export const Theme = ({
97
97
  const loaded = useCachedResources();
98
98
 
99
99
  const theme = useMemo(() => {
100
- return generateTheme(themeOverwrite);
100
+ return createTheme(themeOverwrite);
101
101
  }, [themeOverwrite]);
102
102
 
103
103
  if (!loaded) {
@@ -11,3 +11,5 @@ export type Palette = [
11
11
  string,
12
12
  string,
13
13
  ];
14
+
15
+ export type MantineGradient = any;
@@ -1,6 +1,11 @@
1
- type CSSObject = any
2
- export type ClassNames<StylesNames extends string> = Partial<Record<StylesNames, string>>;
3
- export type Styles<StylesNames extends string, StylesParams extends Record<string, any> = never> =
1
+ type CSSObject = any;
2
+ export type ClassNames<StylesNames extends string> = Partial<
3
+ Record<StylesNames, string>
4
+ >;
5
+ export type Styles<
6
+ StylesNames extends string,
7
+ StylesParams extends Record<string, any> = never,
8
+ > =
4
9
  | Partial<Record<StylesNames, CSSObject>>
5
10
  | ((
6
11
  theme: any,
@@ -8,6 +13,6 @@ export type Styles<StylesNames extends string, StylesParams extends Record<strin
8
13
  context: any
9
14
  ) => Partial<Record<StylesNames, CSSObject>>);
10
15
 
11
- export interface DefaultProps {
16
+ export interface DefaultProps {
12
17
  style?: any;
13
18
  }
@@ -0,0 +1,19 @@
1
+ function createConverter(units: string) {
2
+ return (px: unknown) => {
3
+ if (typeof px === 'number') {
4
+ return `${px / 16}${units}`;
5
+ }
6
+
7
+ if (typeof px === 'string') {
8
+ const replaced = px.replace('px', '');
9
+ if (!Number.isNaN(Number(replaced))) {
10
+ return `${Number(replaced) / 16}${units}`;
11
+ }
12
+ }
13
+
14
+ return px as string;
15
+ };
16
+ }
17
+
18
+ export const rem = createConverter('rem');
19
+ export const em = createConverter('em');
@@ -1 +0,0 @@
1
- {"version":3,"names":["_defaultTheme","require","generateTheme","theme","primaryShade","other","DEFAULT_THEME","fontFamily","fontFamilyBold","fontFamilySemiBold","fontFamilyInput","primaryColor","secondaryColor","headings","colors","DEFAULT_COLORS","exports"],"sourceRoot":"../../../src","sources":["theme/generate-theme.ts"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAEO,MAAMC,aAAa,GAAIC,KAAuB,IAAa;EAChE,MAAM;IAAEC,YAAY,GAAG,CAAC;IAAEC,KAAK,GAAG,CAAC;EAAE,CAAC,GAAGF,KAAK,IAAI,CAAC,CAAC;EACpD,OAAO;IACL,GAAGG,2BAAa;IAChBF,YAAY,EAAEA,YAAY;IAC1BC,KAAK,EAAEA,KAAK;IACZE,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE,aAAa;IAC7BC,kBAAkB,EAAE,iBAAiB;IACrCC,eAAe,EAAE,QAAQ;IACzBC,YAAY,EAAE,MAAM;IACpBC,cAAc,EAAE,MAAM;IACtBC,QAAQ,EAAE;MACRN,UAAU,EAAE;IACd,CAAC;IACDO,MAAM,EAAEC;EACV,CAAC;AACH,CAAC;AAACC,OAAA,CAAAd,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["DEFAULT_COLORS","DEFAULT_THEME","generateTheme","theme","primaryShade","other","fontFamily","fontFamilyBold","fontFamilySemiBold","fontFamilyInput","primaryColor","secondaryColor","headings","colors"],"sourceRoot":"../../../src","sources":["theme/generate-theme.ts"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,aAAa,QAAQ,oBAAiB;AAE/D,OAAO,MAAMC,aAAa,GAAIC,KAAuB,IAAa;EAChE,MAAM;IAAEC,YAAY,GAAG,CAAC;IAAEC,KAAK,GAAG,CAAC;EAAE,CAAC,GAAGF,KAAK,IAAI,CAAC,CAAC;EACpD,OAAO;IACL,GAAGF,aAAa;IAChBG,YAAY,EAAEA,YAAY;IAC1BC,KAAK,EAAEA,KAAK;IACZC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE,aAAa;IAC7BC,kBAAkB,EAAE,iBAAiB;IACrCC,eAAe,EAAE,QAAQ;IACzBC,YAAY,EAAE,MAAM;IACpBC,cAAc,EAAE,MAAM;IACtBC,QAAQ,EAAE;MACRN,UAAU,EAAE;IACd,CAAC;IACDO,MAAM,EAAEb;EACV,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import type { TTheme } from './default-theme';
2
- export declare const generateTheme: (theme?: Partial<TTheme>) => TTheme;
3
- //# sourceMappingURL=generate-theme.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-theme.d.ts","sourceRoot":"","sources":["../../../../../src/theme/generate-theme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,eAAO,MAAM,aAAa,WAAY,OAAO,CAAC,MAAM,CAAC,KAAG,MAiBvD,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { TTheme } from './default-theme';
2
- export declare const generateTheme: (theme?: Partial<TTheme>) => TTheme;
3
- //# sourceMappingURL=generate-theme.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-theme.d.ts","sourceRoot":"","sources":["../../../../../src/theme/generate-theme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,eAAO,MAAM,aAAa,WAAY,OAAO,CAAC,MAAM,CAAC,KAAG,MAiBvD,CAAC"}