@react-native-styled-system/util 2.1.2
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.
- package/LICENSE +21 -0
- package/lib/commonjs/createTheme.js +44 -0
- package/lib/commonjs/createTheme.js.map +1 -0
- package/lib/commonjs/defaultTheme.js +412 -0
- package/lib/commonjs/defaultTheme.js.map +1 -0
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/createTheme.js +37 -0
- package/lib/module/createTheme.js.map +1 -0
- package/lib/module/defaultTheme.js +405 -0
- package/lib/module/defaultTheme.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/src/createTheme.d.ts +8 -0
- package/lib/typescript/src/createTheme.d.ts.map +1 -0
- package/lib/typescript/src/defaultTheme.d.ts +42 -0
- package/lib/typescript/src/defaultTheme.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +23 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +51 -0
- package/src/createTheme.test.ts +125 -0
- package/src/createTheme.ts +32 -0
- package/src/defaultTheme.ts +431 -0
- package/src/index.ts +3 -0
- package/src/types.ts +24 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createTheme } from './createTheme';
|
|
2
|
+
import type { ThemedDict } from './defaultTheme';
|
|
3
|
+
import { defaultTheme } from './defaultTheme';
|
|
4
|
+
|
|
5
|
+
describe('createTheme', () => {
|
|
6
|
+
describe('create mode (single argument)', () => {
|
|
7
|
+
it('returns all empty defaults when called without arguments', () => {
|
|
8
|
+
const theme = createTheme();
|
|
9
|
+
expect(theme).toEqual({
|
|
10
|
+
colors: {},
|
|
11
|
+
space: {},
|
|
12
|
+
sizes: {},
|
|
13
|
+
radii: {},
|
|
14
|
+
typography: {},
|
|
15
|
+
breakpoints: [],
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('returns all empty defaults when called with empty object', () => {
|
|
20
|
+
const theme = createTheme({});
|
|
21
|
+
expect(theme).toEqual({
|
|
22
|
+
colors: {},
|
|
23
|
+
space: {},
|
|
24
|
+
sizes: {},
|
|
25
|
+
radii: {},
|
|
26
|
+
typography: {},
|
|
27
|
+
breakpoints: [],
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('keeps provided groups and fills missing ones with empty defaults', () => {
|
|
32
|
+
const theme = createTheme({
|
|
33
|
+
colors: { primary: '#000' },
|
|
34
|
+
space: { '1': 4 },
|
|
35
|
+
});
|
|
36
|
+
expect(theme.colors).toEqual({ primary: '#000' });
|
|
37
|
+
expect(theme.space).toEqual({ '1': 4 });
|
|
38
|
+
expect(theme.sizes).toEqual({});
|
|
39
|
+
expect(theme.radii).toEqual({});
|
|
40
|
+
expect(theme.typography).toEqual({});
|
|
41
|
+
expect(theme.breakpoints).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('keeps provided breakpoints', () => {
|
|
45
|
+
const theme = createTheme({ breakpoints: [480, 768] });
|
|
46
|
+
expect(theme.breakpoints).toEqual([480, 768]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('extend mode (two arguments)', () => {
|
|
51
|
+
const base: ThemedDict = {
|
|
52
|
+
colors: { red: '#FF0000', blue: '#0000FF' },
|
|
53
|
+
space: { '1': 4, '2': 8 },
|
|
54
|
+
sizes: { sm: 16 },
|
|
55
|
+
radii: { md: 8 },
|
|
56
|
+
typography: { body: { fontSize: 16, lineHeight: 24 } },
|
|
57
|
+
breakpoints: [480, 768],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
it('returns base as-is when overrides is empty', () => {
|
|
61
|
+
const theme = createTheme(base, {});
|
|
62
|
+
expect(theme).toEqual(base);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('merges colors (keeps existing + adds new)', () => {
|
|
66
|
+
const theme = createTheme(base, { colors: { brand: '#FF6600' } });
|
|
67
|
+
expect(theme.colors).toEqual({ red: '#FF0000', blue: '#0000FF', brand: '#FF6600' });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('overrides existing token values', () => {
|
|
71
|
+
const theme = createTheme(base, { colors: { red: '#CC0000' } });
|
|
72
|
+
expect(theme.colors.red).toBe('#CC0000');
|
|
73
|
+
expect(theme.colors.blue).toBe('#0000FF');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('merges each token group independently', () => {
|
|
77
|
+
const theme = createTheme(base, {
|
|
78
|
+
space: { '3': 12 },
|
|
79
|
+
sizes: { lg: 32 },
|
|
80
|
+
radii: { lg: 16 },
|
|
81
|
+
typography: { h1: { fontSize: 32, fontWeight: 'bold', lineHeight: 40 } },
|
|
82
|
+
});
|
|
83
|
+
expect(theme.space).toEqual({ '1': 4, '2': 8, '3': 12 });
|
|
84
|
+
expect(theme.sizes).toEqual({ sm: 16, lg: 32 });
|
|
85
|
+
expect(theme.radii).toEqual({ md: 8, lg: 16 });
|
|
86
|
+
expect(theme.typography).toEqual({
|
|
87
|
+
body: { fontSize: 16, lineHeight: 24 },
|
|
88
|
+
h1: { fontSize: 32, fontWeight: 'bold', lineHeight: 40 },
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('replaces breakpoints when provided in overrides', () => {
|
|
93
|
+
const theme = createTheme(base, { breakpoints: [500, 1024, 1440] });
|
|
94
|
+
expect(theme.breakpoints).toEqual([500, 1024, 1440]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('falls back to base breakpoints when overrides omits breakpoints', () => {
|
|
98
|
+
const theme = createTheme(base, { colors: { brand: '#000' } });
|
|
99
|
+
expect(theme.breakpoints).toEqual([480, 768]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('does not mutate base or overrides', () => {
|
|
103
|
+
const baseCopy = JSON.parse(JSON.stringify(base));
|
|
104
|
+
const overrides = { colors: { brand: '#FF6600' } };
|
|
105
|
+
const overridesCopy = JSON.parse(JSON.stringify(overrides));
|
|
106
|
+
|
|
107
|
+
createTheme(base, overrides);
|
|
108
|
+
|
|
109
|
+
expect(base).toEqual(baseCopy);
|
|
110
|
+
expect(overrides).toEqual(overridesCopy);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('works with defaultTheme as base', () => {
|
|
114
|
+
const theme = createTheme(defaultTheme, {
|
|
115
|
+
colors: { brand: '#FF6600' },
|
|
116
|
+
space: { huge: 200 },
|
|
117
|
+
});
|
|
118
|
+
expect(theme.colors.brand).toBe('#FF6600');
|
|
119
|
+
expect(theme.colors.white).toBe('#FFFFFF');
|
|
120
|
+
expect(theme.space.huge).toBe(200);
|
|
121
|
+
expect(theme.space['1']).toBe(4);
|
|
122
|
+
expect(theme.breakpoints).toEqual(defaultTheme.breakpoints);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Theme } from './types';
|
|
2
|
+
|
|
3
|
+
type CreateThemeType = {
|
|
4
|
+
(config?: Partial<Theme>): Theme;
|
|
5
|
+
(base: Theme, overrides: Partial<Theme>): Theme;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const createTheme: CreateThemeType = (
|
|
9
|
+
baseOrConfig: Partial<Theme> = {},
|
|
10
|
+
overrides?: Partial<Theme>,
|
|
11
|
+
) => {
|
|
12
|
+
if (overrides !== undefined) {
|
|
13
|
+
return {
|
|
14
|
+
colors: { ...baseOrConfig.colors, ...overrides.colors },
|
|
15
|
+
space: { ...baseOrConfig.space, ...overrides.space },
|
|
16
|
+
sizes: { ...baseOrConfig.sizes, ...overrides.sizes },
|
|
17
|
+
radii: { ...baseOrConfig.radii, ...overrides.radii },
|
|
18
|
+
typography: { ...baseOrConfig.typography, ...overrides.typography },
|
|
19
|
+
breakpoints: overrides.breakpoints ?? baseOrConfig.breakpoints ?? [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
colors: {},
|
|
25
|
+
space: {},
|
|
26
|
+
sizes: {},
|
|
27
|
+
radii: {},
|
|
28
|
+
typography: {},
|
|
29
|
+
breakpoints: [],
|
|
30
|
+
...baseOrConfig,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import type { ColorsValue, RadiiValue, SizesValue, SpaceValue, TypographyValue } from './types';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Theme type from developer
|
|
5
|
+
*/
|
|
6
|
+
export interface ThemedDict {
|
|
7
|
+
space: Record<string | number, SpaceValue>;
|
|
8
|
+
sizes: Record<string | number, SizesValue>;
|
|
9
|
+
colors: Record<string | number, ColorsValue>;
|
|
10
|
+
radii: Record<string | number, RadiiValue>;
|
|
11
|
+
typography: Record<string | number, TypographyValue>;
|
|
12
|
+
breakpoints?: number[];
|
|
13
|
+
}
|
|
14
|
+
export const emptyThemedDict = {
|
|
15
|
+
space: {},
|
|
16
|
+
colors: {},
|
|
17
|
+
sizes: {},
|
|
18
|
+
radii: {},
|
|
19
|
+
typography: {},
|
|
20
|
+
breakpoints: [],
|
|
21
|
+
} satisfies ThemedDict;
|
|
22
|
+
|
|
23
|
+
const defaultSpace: Record<string, SpaceValue> = {
|
|
24
|
+
'0': 0,
|
|
25
|
+
'px': 1,
|
|
26
|
+
'0.5': 2,
|
|
27
|
+
'1': 4,
|
|
28
|
+
'2': 8,
|
|
29
|
+
'3': 12,
|
|
30
|
+
'4': 16,
|
|
31
|
+
'5': 20,
|
|
32
|
+
'6': 24,
|
|
33
|
+
'7': 28,
|
|
34
|
+
'8': 32,
|
|
35
|
+
'9': 36,
|
|
36
|
+
'10': 40,
|
|
37
|
+
'12': 48,
|
|
38
|
+
'14': 56,
|
|
39
|
+
'16': 64,
|
|
40
|
+
'20': 80,
|
|
41
|
+
'24': 96,
|
|
42
|
+
'32': 128,
|
|
43
|
+
'40': 160,
|
|
44
|
+
'48': 192,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const defaultColors: Record<string, ColorsValue> = {
|
|
48
|
+
'white': '#FFFFFF',
|
|
49
|
+
'black': '#000000',
|
|
50
|
+
'transparent': 'transparent',
|
|
51
|
+
|
|
52
|
+
'slate.50': '#f8fafc',
|
|
53
|
+
'slate.100': '#f1f5f9',
|
|
54
|
+
'slate.200': '#e2e8f0',
|
|
55
|
+
'slate.300': '#cad5e2',
|
|
56
|
+
'slate.400': '#90a1b9',
|
|
57
|
+
'slate.500': '#62748e',
|
|
58
|
+
'slate.600': '#45556c',
|
|
59
|
+
'slate.700': '#314158',
|
|
60
|
+
'slate.800': '#1d293d',
|
|
61
|
+
'slate.900': '#0f172b',
|
|
62
|
+
'slate.950': '#020618',
|
|
63
|
+
|
|
64
|
+
'gray.50': '#f9fafb',
|
|
65
|
+
'gray.100': '#f3f4f6',
|
|
66
|
+
'gray.200': '#e5e7eb',
|
|
67
|
+
'gray.300': '#d1d5dc',
|
|
68
|
+
'gray.400': '#99a1af',
|
|
69
|
+
'gray.500': '#6a7282',
|
|
70
|
+
'gray.600': '#4a5565',
|
|
71
|
+
'gray.700': '#364153',
|
|
72
|
+
'gray.800': '#1e2939',
|
|
73
|
+
'gray.900': '#101828',
|
|
74
|
+
'gray.950': '#030712',
|
|
75
|
+
|
|
76
|
+
'zinc.50': '#fafafa',
|
|
77
|
+
'zinc.100': '#f4f4f5',
|
|
78
|
+
'zinc.200': '#e4e4e7',
|
|
79
|
+
'zinc.300': '#d4d4d8',
|
|
80
|
+
'zinc.400': '#9f9fa9',
|
|
81
|
+
'zinc.500': '#71717b',
|
|
82
|
+
'zinc.600': '#52525c',
|
|
83
|
+
'zinc.700': '#3f3f46',
|
|
84
|
+
'zinc.800': '#27272a',
|
|
85
|
+
'zinc.900': '#18181b',
|
|
86
|
+
'zinc.950': '#09090b',
|
|
87
|
+
|
|
88
|
+
'neutral.50': '#fafafa',
|
|
89
|
+
'neutral.100': '#f5f5f5',
|
|
90
|
+
'neutral.200': '#e5e5e5',
|
|
91
|
+
'neutral.300': '#d4d4d4',
|
|
92
|
+
'neutral.400': '#a1a1a1',
|
|
93
|
+
'neutral.500': '#737373',
|
|
94
|
+
'neutral.600': '#525252',
|
|
95
|
+
'neutral.700': '#404040',
|
|
96
|
+
'neutral.800': '#262626',
|
|
97
|
+
'neutral.900': '#171717',
|
|
98
|
+
'neutral.950': '#0a0a0a',
|
|
99
|
+
|
|
100
|
+
'stone.50': '#fafaf9',
|
|
101
|
+
'stone.100': '#f5f5f4',
|
|
102
|
+
'stone.200': '#e7e5e4',
|
|
103
|
+
'stone.300': '#d7d3d1',
|
|
104
|
+
'stone.400': '#a6a09b',
|
|
105
|
+
'stone.500': '#79716b',
|
|
106
|
+
'stone.600': '#57534d',
|
|
107
|
+
'stone.700': '#44403b',
|
|
108
|
+
'stone.800': '#292524',
|
|
109
|
+
'stone.900': '#1c1917',
|
|
110
|
+
'stone.950': '#0c0a09',
|
|
111
|
+
|
|
112
|
+
'red.50': '#fef2f2',
|
|
113
|
+
'red.100': '#ffe2e2',
|
|
114
|
+
'red.200': '#ffc9c9',
|
|
115
|
+
'red.300': '#ffa2a2',
|
|
116
|
+
'red.400': '#ff6467',
|
|
117
|
+
'red.500': '#fb2c36',
|
|
118
|
+
'red.600': '#e7000b',
|
|
119
|
+
'red.700': '#c10007',
|
|
120
|
+
'red.800': '#9f0712',
|
|
121
|
+
'red.900': '#82181a',
|
|
122
|
+
'red.950': '#460809',
|
|
123
|
+
|
|
124
|
+
'orange.50': '#fff7ed',
|
|
125
|
+
'orange.100': '#ffedd4',
|
|
126
|
+
'orange.200': '#ffd6a7',
|
|
127
|
+
'orange.300': '#ffb869',
|
|
128
|
+
'orange.400': '#ff8903',
|
|
129
|
+
'orange.500': '#ff6900',
|
|
130
|
+
'orange.600': '#f54900',
|
|
131
|
+
'orange.700': '#ca3500',
|
|
132
|
+
'orange.800': '#9f2d00',
|
|
133
|
+
'orange.900': '#7e2a0c',
|
|
134
|
+
'orange.950': '#441306',
|
|
135
|
+
|
|
136
|
+
'amber.50': '#fffbeb',
|
|
137
|
+
'amber.100': '#fef3c6',
|
|
138
|
+
'amber.200': '#fee685',
|
|
139
|
+
'amber.300': '#ffd230',
|
|
140
|
+
'amber.400': '#ffb900',
|
|
141
|
+
'amber.500': '#fe9a00',
|
|
142
|
+
'amber.600': '#e17100',
|
|
143
|
+
'amber.700': '#bb4d00',
|
|
144
|
+
'amber.800': '#973c00',
|
|
145
|
+
'amber.900': '#7b3306',
|
|
146
|
+
'amber.950': '#461901',
|
|
147
|
+
|
|
148
|
+
'yellow.50': '#fefce8',
|
|
149
|
+
'yellow.100': '#fef9c2',
|
|
150
|
+
'yellow.200': '#fff085',
|
|
151
|
+
'yellow.300': '#ffdf20',
|
|
152
|
+
'yellow.400': '#fdc700',
|
|
153
|
+
'yellow.500': '#f0b100',
|
|
154
|
+
'yellow.600': '#d08700',
|
|
155
|
+
'yellow.700': '#a65f00',
|
|
156
|
+
'yellow.800': '#894b00',
|
|
157
|
+
'yellow.900': '#733e0a',
|
|
158
|
+
'yellow.950': '#432004',
|
|
159
|
+
|
|
160
|
+
'lime.50': '#f7fee7',
|
|
161
|
+
'lime.100': '#ecfcca',
|
|
162
|
+
'lime.200': '#d8f999',
|
|
163
|
+
'lime.300': '#bbf451',
|
|
164
|
+
'lime.400': '#9ae600',
|
|
165
|
+
'lime.500': '#7ccf00',
|
|
166
|
+
'lime.600': '#5ea500',
|
|
167
|
+
'lime.700': '#497d00',
|
|
168
|
+
'lime.800': '#3d6300',
|
|
169
|
+
'lime.900': '#35530e',
|
|
170
|
+
'lime.950': '#192e03',
|
|
171
|
+
|
|
172
|
+
'green.50': '#f0fdf4',
|
|
173
|
+
'green.100': '#dcfce7',
|
|
174
|
+
'green.200': '#b9f8cf',
|
|
175
|
+
'green.300': '#7bf1a7',
|
|
176
|
+
'green.400': '#06df72',
|
|
177
|
+
'green.500': '#00c950',
|
|
178
|
+
'green.600': '#00a63e',
|
|
179
|
+
'green.700': '#008235',
|
|
180
|
+
'green.800': '#026630',
|
|
181
|
+
'green.900': '#0d542b',
|
|
182
|
+
'green.950': '#032e15',
|
|
183
|
+
|
|
184
|
+
'emerald.50': '#ecfdf5',
|
|
185
|
+
'emerald.100': '#d0fae5',
|
|
186
|
+
'emerald.200': '#a4f4cf',
|
|
187
|
+
'emerald.300': '#5ee9b5',
|
|
188
|
+
'emerald.400': '#00d492',
|
|
189
|
+
'emerald.500': '#00bc7d',
|
|
190
|
+
'emerald.600': '#009966',
|
|
191
|
+
'emerald.700': '#007a55',
|
|
192
|
+
'emerald.800': '#006045',
|
|
193
|
+
'emerald.900': '#004f3b',
|
|
194
|
+
'emerald.950': '#002c22',
|
|
195
|
+
|
|
196
|
+
'teal.50': '#f0fdfa',
|
|
197
|
+
'teal.100': '#cbfbf1',
|
|
198
|
+
'teal.200': '#96f7e4',
|
|
199
|
+
'teal.300': '#46ecd4',
|
|
200
|
+
'teal.400': '#00d5bd',
|
|
201
|
+
'teal.500': '#00bba7',
|
|
202
|
+
'teal.600': '#009689',
|
|
203
|
+
'teal.700': '#00786f',
|
|
204
|
+
'teal.800': '#005f5a',
|
|
205
|
+
'teal.900': '#0b4f4a',
|
|
206
|
+
'teal.950': '#022f2e',
|
|
207
|
+
|
|
208
|
+
'cyan.50': '#ecfeff',
|
|
209
|
+
'cyan.100': '#cefafe',
|
|
210
|
+
'cyan.200': '#a2f4fd',
|
|
211
|
+
'cyan.300': '#53eafd',
|
|
212
|
+
'cyan.400': '#00d3f2',
|
|
213
|
+
'cyan.500': '#00b8db',
|
|
214
|
+
'cyan.600': '#0092b8',
|
|
215
|
+
'cyan.700': '#007595',
|
|
216
|
+
'cyan.800': '#005f78',
|
|
217
|
+
'cyan.900': '#104e64',
|
|
218
|
+
'cyan.950': '#053345',
|
|
219
|
+
|
|
220
|
+
'sky.50': '#f0f9ff',
|
|
221
|
+
'sky.100': '#dff2fe',
|
|
222
|
+
'sky.200': '#b8e6fe',
|
|
223
|
+
'sky.300': '#74d4ff',
|
|
224
|
+
'sky.400': '#00bcff',
|
|
225
|
+
'sky.500': '#00a6f4',
|
|
226
|
+
'sky.600': '#0084d1',
|
|
227
|
+
'sky.700': '#0069a8',
|
|
228
|
+
'sky.800': '#00598a',
|
|
229
|
+
'sky.900': '#024a70',
|
|
230
|
+
'sky.950': '#052f4a',
|
|
231
|
+
|
|
232
|
+
'blue.50': '#eff6ff',
|
|
233
|
+
'blue.100': '#dbeafe',
|
|
234
|
+
'blue.200': '#bedbff',
|
|
235
|
+
'blue.300': '#8ec5ff',
|
|
236
|
+
'blue.400': '#51a2ff',
|
|
237
|
+
'blue.500': '#2b7fff',
|
|
238
|
+
'blue.600': '#155dfb',
|
|
239
|
+
'blue.700': '#1447e6',
|
|
240
|
+
'blue.800': '#193cb8',
|
|
241
|
+
'blue.900': '#1c398e',
|
|
242
|
+
'blue.950': '#162556',
|
|
243
|
+
|
|
244
|
+
'indigo.50': '#eef2ff',
|
|
245
|
+
'indigo.100': '#e0e7ff',
|
|
246
|
+
'indigo.200': '#c7d2ff',
|
|
247
|
+
'indigo.300': '#a3b3ff',
|
|
248
|
+
'indigo.400': '#7c86ff',
|
|
249
|
+
'indigo.500': '#615fff',
|
|
250
|
+
'indigo.600': '#4f39f6',
|
|
251
|
+
'indigo.700': '#432dd7',
|
|
252
|
+
'indigo.800': '#372aac',
|
|
253
|
+
'indigo.900': '#312c85',
|
|
254
|
+
'indigo.950': '#1e1a4d',
|
|
255
|
+
|
|
256
|
+
'violet.50': '#f5f3ff',
|
|
257
|
+
'violet.100': '#ede9fe',
|
|
258
|
+
'violet.200': '#ddd6ff',
|
|
259
|
+
'violet.300': '#c4b4ff',
|
|
260
|
+
'violet.400': '#a684ff',
|
|
261
|
+
'violet.500': '#8e51ff',
|
|
262
|
+
'violet.600': '#7f22fe',
|
|
263
|
+
'violet.700': '#7008e7',
|
|
264
|
+
'violet.800': '#5d0ec0',
|
|
265
|
+
'violet.900': '#4d179a',
|
|
266
|
+
'violet.950': '#2f0d68',
|
|
267
|
+
|
|
268
|
+
'purple.50': '#faf5ff',
|
|
269
|
+
'purple.100': '#f3e8ff',
|
|
270
|
+
'purple.200': '#e9d4ff',
|
|
271
|
+
'purple.300': '#dab2ff',
|
|
272
|
+
'purple.400': '#c27aff',
|
|
273
|
+
'purple.500': '#ad46ff',
|
|
274
|
+
'purple.600': '#9810fa',
|
|
275
|
+
'purple.700': '#8200db',
|
|
276
|
+
'purple.800': '#6e11b0',
|
|
277
|
+
'purple.900': '#59168b',
|
|
278
|
+
'purple.950': '#3c0366',
|
|
279
|
+
|
|
280
|
+
'fuchsia.50': '#fdf4ff',
|
|
281
|
+
'fuchsia.100': '#fae8ff',
|
|
282
|
+
'fuchsia.200': '#f6cfff',
|
|
283
|
+
'fuchsia.300': '#f4a8ff',
|
|
284
|
+
'fuchsia.400': '#ed6aff',
|
|
285
|
+
'fuchsia.500': '#e12afb',
|
|
286
|
+
'fuchsia.600': '#c800de',
|
|
287
|
+
'fuchsia.700': '#a800b7',
|
|
288
|
+
'fuchsia.800': '#8a0194',
|
|
289
|
+
'fuchsia.900': '#721378',
|
|
290
|
+
'fuchsia.950': '#4b004f',
|
|
291
|
+
|
|
292
|
+
'pink.50': '#fdf2f8',
|
|
293
|
+
'pink.100': '#fce7f3',
|
|
294
|
+
'pink.200': '#fccee8',
|
|
295
|
+
'pink.300': '#fea5d5',
|
|
296
|
+
'pink.400': '#fb64b6',
|
|
297
|
+
'pink.500': '#f6339a',
|
|
298
|
+
'pink.600': '#e60076',
|
|
299
|
+
'pink.700': '#c6005b',
|
|
300
|
+
'pink.800': '#a3004c',
|
|
301
|
+
'pink.900': '#861043',
|
|
302
|
+
'pink.950': '#510424',
|
|
303
|
+
|
|
304
|
+
'rose.50': '#fff1f2',
|
|
305
|
+
'rose.100': '#ffe4e6',
|
|
306
|
+
'rose.200': '#ffccd2',
|
|
307
|
+
'rose.300': '#ffa1ad',
|
|
308
|
+
'rose.400': '#ff637e',
|
|
309
|
+
'rose.500': '#ff2056',
|
|
310
|
+
'rose.600': '#ec003f',
|
|
311
|
+
'rose.700': '#c70036',
|
|
312
|
+
'rose.800': '#a50036',
|
|
313
|
+
'rose.900': '#8b0836',
|
|
314
|
+
'rose.950': '#4d0218',
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const defaultRadii: Record<string, RadiiValue> = {
|
|
318
|
+
'none': 0,
|
|
319
|
+
'sm': 4,
|
|
320
|
+
'md': 8,
|
|
321
|
+
'lg': 12,
|
|
322
|
+
'xl': 16,
|
|
323
|
+
'2xl': 24,
|
|
324
|
+
'full': 9999,
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const defaultTypography: Record<string, TypographyValue> = {
|
|
328
|
+
h1: { fontSize: 32, fontWeight: 'bold', lineHeight: 40 },
|
|
329
|
+
h2: { fontSize: 24, fontWeight: 'bold', lineHeight: 32 },
|
|
330
|
+
h3: { fontSize: 20, fontWeight: '600', lineHeight: 28 },
|
|
331
|
+
body: { fontSize: 16, lineHeight: 24 },
|
|
332
|
+
caption: { fontSize: 14, lineHeight: 20 },
|
|
333
|
+
small: { fontSize: 12, lineHeight: 16 },
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const grayScales = ['slate', 'gray', 'zinc', 'neutral', 'stone'] as const;
|
|
337
|
+
|
|
338
|
+
export type BaseColor = (typeof grayScales)[number];
|
|
339
|
+
|
|
340
|
+
export type ThemeColor =
|
|
341
|
+
| BaseColor
|
|
342
|
+
| 'red'
|
|
343
|
+
| 'orange'
|
|
344
|
+
| 'amber'
|
|
345
|
+
| 'yellow'
|
|
346
|
+
| 'lime'
|
|
347
|
+
| 'green'
|
|
348
|
+
| 'emerald'
|
|
349
|
+
| 'teal'
|
|
350
|
+
| 'cyan'
|
|
351
|
+
| 'sky'
|
|
352
|
+
| 'blue'
|
|
353
|
+
| 'indigo'
|
|
354
|
+
| 'violet'
|
|
355
|
+
| 'purple'
|
|
356
|
+
| 'fuchsia'
|
|
357
|
+
| 'pink'
|
|
358
|
+
| 'rose';
|
|
359
|
+
|
|
360
|
+
export const createThemeColors = ({ base, theme }: { base: BaseColor; theme: ThemeColor }) => {
|
|
361
|
+
const b = (shade: number) => defaultColors[`${base}.${shade}`]!;
|
|
362
|
+
const t = (shade: number) => defaultColors[`${theme}.${shade}`]!;
|
|
363
|
+
const isGray = (grayScales as readonly string[]).includes(theme);
|
|
364
|
+
|
|
365
|
+
const light: Record<string, ColorsValue> = {
|
|
366
|
+
'background': '#FFFFFF',
|
|
367
|
+
'foreground': b(950),
|
|
368
|
+
'card': '#FFFFFF',
|
|
369
|
+
'card-foreground': b(950),
|
|
370
|
+
'popover': '#FFFFFF',
|
|
371
|
+
'popover-foreground': b(950),
|
|
372
|
+
'primary': isGray ? t(900) : t(600),
|
|
373
|
+
'primary-foreground': isGray ? t(50) : '#FFFFFF',
|
|
374
|
+
'secondary': b(100),
|
|
375
|
+
'secondary-foreground': b(900),
|
|
376
|
+
'muted': b(100),
|
|
377
|
+
'muted-foreground': b(500),
|
|
378
|
+
'accent': b(100),
|
|
379
|
+
'accent-foreground': b(900),
|
|
380
|
+
'destructive': defaultColors['red.600']!,
|
|
381
|
+
'destructive-foreground': b(50),
|
|
382
|
+
'border': b(200),
|
|
383
|
+
'input': b(200),
|
|
384
|
+
'ring': isGray ? b(400) : t(400),
|
|
385
|
+
'chart-1': defaultColors['orange.600']!,
|
|
386
|
+
'chart-2': defaultColors['teal.600']!,
|
|
387
|
+
'chart-3': defaultColors['cyan.900']!,
|
|
388
|
+
'chart-4': defaultColors['amber.400']!,
|
|
389
|
+
'chart-5': defaultColors['amber.500']!,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const dark: Record<string, ColorsValue> = {
|
|
393
|
+
'background': b(950),
|
|
394
|
+
'foreground': b(50),
|
|
395
|
+
'card': b(900),
|
|
396
|
+
'card-foreground': b(50),
|
|
397
|
+
'popover': b(900),
|
|
398
|
+
'popover-foreground': b(50),
|
|
399
|
+
'primary': isGray ? t(200) : t(500),
|
|
400
|
+
'primary-foreground': isGray ? t(900) : '#FFFFFF',
|
|
401
|
+
'secondary': b(800),
|
|
402
|
+
'secondary-foreground': b(50),
|
|
403
|
+
'muted': b(800),
|
|
404
|
+
'muted-foreground': b(400),
|
|
405
|
+
'accent': b(800),
|
|
406
|
+
'accent-foreground': b(50),
|
|
407
|
+
'destructive': defaultColors['red.400']!,
|
|
408
|
+
'destructive-foreground': b(50),
|
|
409
|
+
'border': b(800),
|
|
410
|
+
'input': b(800),
|
|
411
|
+
'ring': isGray ? b(500) : t(500),
|
|
412
|
+
'chart-1': defaultColors['blue.700']!,
|
|
413
|
+
'chart-2': defaultColors['emerald.500']!,
|
|
414
|
+
'chart-3': defaultColors['amber.500']!,
|
|
415
|
+
'chart-4': defaultColors['purple.500']!,
|
|
416
|
+
'chart-5': defaultColors['rose.500']!,
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
return { light, dark };
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const defaultSemanticColors = createThemeColors({ base: 'neutral', theme: 'neutral' });
|
|
423
|
+
|
|
424
|
+
export const defaultTheme = {
|
|
425
|
+
space: defaultSpace,
|
|
426
|
+
sizes: { ...defaultSpace, full: '100%' as const, half: '50%' as const },
|
|
427
|
+
colors: { ...defaultColors, ...defaultSemanticColors.light },
|
|
428
|
+
radii: defaultRadii,
|
|
429
|
+
typography: defaultTypography,
|
|
430
|
+
breakpoints: [480, 768, 1024],
|
|
431
|
+
} satisfies ThemedDict;
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TextStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type SpaceValue = number | 'auto' | `${number}%` | null;
|
|
4
|
+
export type SizesValue = number | 'auto' | `${number}%` | null;
|
|
5
|
+
export type ColorsValue = string;
|
|
6
|
+
export type RadiiValue = number;
|
|
7
|
+
export type TypographyValue = {
|
|
8
|
+
fontFamily?: TextStyle['fontFamily'];
|
|
9
|
+
fontSize?: TextStyle['fontSize'];
|
|
10
|
+
fontWeight?: TextStyle['fontWeight'];
|
|
11
|
+
lineHeight?: TextStyle['lineHeight'];
|
|
12
|
+
letterSpacing?: TextStyle['letterSpacing'];
|
|
13
|
+
textAlign?: TextStyle['textAlign'];
|
|
14
|
+
fontStyle?: TextStyle['fontStyle'];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type Theme = {
|
|
18
|
+
space: Record<string | number, SpaceValue>;
|
|
19
|
+
sizes: Record<string | number, SizesValue>;
|
|
20
|
+
colors: Record<string | number, ColorsValue>;
|
|
21
|
+
radii: Record<string | number, RadiiValue>;
|
|
22
|
+
typography: Record<string | number, TypographyValue>;
|
|
23
|
+
breakpoints?: number[];
|
|
24
|
+
};
|