@pyreon/rocketstyle 0.11.5 → 0.11.6
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/README.md +32 -32
- package/lib/index.d.ts +25 -6
- package/lib/index.js +99 -88
- package/package.json +25 -24
- package/src/__tests__/attrs.test.ts +49 -49
- package/src/__tests__/chaining.test.ts +27 -27
- package/src/__tests__/collection.test.ts +12 -12
- package/src/__tests__/compose.test.ts +10 -10
- package/src/__tests__/context.test.ts +65 -65
- package/src/__tests__/createLocalProvider.test.ts +53 -53
- package/src/__tests__/dimensions.test.ts +54 -54
- package/src/__tests__/e2e-styler.test.ts +78 -136
- package/src/__tests__/hooks.test.ts +41 -70
- package/src/__tests__/isRocketComponent.test.ts +11 -11
- package/src/__tests__/misc.test.ts +91 -91
- package/src/__tests__/providerConsumer.test.ts +54 -126
- package/src/__tests__/rocketstyleIntegration.test.ts +180 -253
- package/src/__tests__/themeUtils.test.ts +173 -173
- package/src/cache/index.ts +1 -1
- package/src/constants/booleanTags.ts +25 -25
- package/src/constants/defaultDimensions.ts +5 -5
- package/src/constants/index.ts +16 -16
- package/src/context/context.ts +13 -10
- package/src/context/createLocalProvider.ts +22 -12
- package/src/context/localContext.ts +2 -2
- package/src/hoc/index.ts +1 -1
- package/src/hoc/rocketstyleAttrsHoc.ts +26 -29
- package/src/hooks/index.ts +2 -2
- package/src/hooks/usePseudoState.ts +3 -3
- package/src/hooks/useTheme.ts +14 -17
- package/src/index.ts +32 -15
- package/src/init.ts +12 -12
- package/src/isRocketComponent.ts +2 -2
- package/src/rocketstyle.ts +103 -109
- package/src/types/attrs.ts +2 -2
- package/src/types/config.ts +4 -4
- package/src/types/configuration.ts +5 -5
- package/src/types/dimensions.ts +5 -5
- package/src/types/hoc.ts +1 -1
- package/src/types/rocketComponent.ts +4 -4
- package/src/types/rocketstyle.ts +10 -10
- package/src/types/styles.ts +9 -4
- package/src/types/theme.ts +4 -4
- package/src/types/utils.ts +1 -1
- package/src/utils/attrs.ts +2 -2
- package/src/utils/chaining.ts +2 -2
- package/src/utils/compose.ts +1 -1
- package/src/utils/dimensions.ts +6 -6
- package/src/utils/statics.ts +2 -2
- package/src/utils/styles.ts +2 -2
- package/src/utils/theme.ts +10 -10
|
@@ -5,119 +5,119 @@ import {
|
|
|
5
5
|
getThemeByMode,
|
|
6
6
|
getThemeFromChain,
|
|
7
7
|
themeModeCallback,
|
|
8
|
-
} from
|
|
8
|
+
} from '../utils/theme'
|
|
9
9
|
|
|
10
|
-
describe(
|
|
11
|
-
it(
|
|
12
|
-
const cb = themeModeCallback(
|
|
13
|
-
expect(cb(
|
|
10
|
+
describe('themeModeCallback', () => {
|
|
11
|
+
it('returns light value for light mode', () => {
|
|
12
|
+
const cb = themeModeCallback('lightVal', 'darkVal')
|
|
13
|
+
expect(cb('light')).toBe('lightVal')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
it(
|
|
17
|
-
const cb = themeModeCallback(
|
|
18
|
-
expect(cb(undefined as any)).toBe(
|
|
19
|
-
expect(cb(
|
|
16
|
+
it('returns light value when mode is falsy', () => {
|
|
17
|
+
const cb = themeModeCallback('lightVal', 'darkVal')
|
|
18
|
+
expect(cb(undefined as any)).toBe('lightVal')
|
|
19
|
+
expect(cb('' as any)).toBe('lightVal')
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
it(
|
|
23
|
-
const cb = themeModeCallback(
|
|
24
|
-
expect(cb(
|
|
22
|
+
it('returns dark value for dark mode', () => {
|
|
23
|
+
const cb = themeModeCallback('lightVal', 'darkVal')
|
|
24
|
+
expect(cb('dark')).toBe('darkVal')
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
describe(
|
|
29
|
-
it(
|
|
28
|
+
describe('getThemeFromChain', () => {
|
|
29
|
+
it('returns empty for empty array', () => {
|
|
30
30
|
expect(getThemeFromChain([], {})).toEqual({})
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
it(
|
|
33
|
+
it('returns empty for null', () => {
|
|
34
34
|
expect(getThemeFromChain(null, {})).toEqual({})
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
it(
|
|
37
|
+
it('returns empty for undefined', () => {
|
|
38
38
|
expect(getThemeFromChain(undefined, {})).toEqual({})
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
it(
|
|
42
|
-
const fn1 = (_theme: any) => ({ color:
|
|
41
|
+
it('evaluates chain of callbacks and deep-merges results', () => {
|
|
42
|
+
const fn1 = (_theme: any) => ({ color: 'blue' })
|
|
43
43
|
const fn2 = (theme: any) => ({ bg: theme.primary })
|
|
44
|
-
const result = getThemeFromChain([fn1, fn2], { primary:
|
|
45
|
-
expect(result).toEqual({ color:
|
|
44
|
+
const result = getThemeFromChain([fn1, fn2], { primary: 'red' })
|
|
45
|
+
expect(result).toEqual({ color: 'blue', bg: 'red' })
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
it(
|
|
49
|
-
const fn1 = () => ({ color:
|
|
50
|
-
const fn2 = () => ({ color:
|
|
48
|
+
it('later callbacks override earlier ones', () => {
|
|
49
|
+
const fn1 = () => ({ color: 'blue' })
|
|
50
|
+
const fn2 = () => ({ color: 'red' })
|
|
51
51
|
const result = getThemeFromChain([fn1, fn2], {})
|
|
52
|
-
expect(result).toEqual({ color:
|
|
52
|
+
expect(result).toEqual({ color: 'red' })
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
it(
|
|
55
|
+
it('passes themeModeCallback and config.css to each callback', () => {
|
|
56
56
|
const fn = vi.fn(() => ({}))
|
|
57
57
|
getThemeFromChain([fn], { rootSize: 16 })
|
|
58
58
|
expect(fn).toHaveBeenCalledWith({ rootSize: 16 }, expect.any(Function), expect.anything())
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
describe(
|
|
63
|
-
it(
|
|
62
|
+
describe('getDimensionThemes', () => {
|
|
63
|
+
it('returns empty for empty dimensions', () => {
|
|
64
64
|
expect(getDimensionThemes({}, { dimensions: {} })).toEqual({})
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
67
|
+
it('returns empty when dimensions is falsy', () => {
|
|
68
68
|
expect(getDimensionThemes({}, { dimensions: undefined })).toEqual({})
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
it(
|
|
72
|
-
const theme = { primaryColor:
|
|
71
|
+
it('processes dimension theme chains', () => {
|
|
72
|
+
const theme = { primaryColor: 'blue' }
|
|
73
73
|
const options = {
|
|
74
|
-
dimensions: { states:
|
|
74
|
+
dimensions: { states: 'state' },
|
|
75
75
|
states: [
|
|
76
76
|
(t: any) => ({
|
|
77
77
|
primary: { color: t.primaryColor },
|
|
78
|
-
secondary: { color:
|
|
78
|
+
secondary: { color: 'green' },
|
|
79
79
|
}),
|
|
80
80
|
],
|
|
81
81
|
}
|
|
82
82
|
const result = getDimensionThemes(theme, options)
|
|
83
83
|
expect(result.state).toEqual({
|
|
84
|
-
primary: { color:
|
|
85
|
-
secondary: { color:
|
|
84
|
+
primary: { color: 'blue' },
|
|
85
|
+
secondary: { color: 'green' },
|
|
86
86
|
})
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
-
it(
|
|
89
|
+
it('skips dimensions without callback arrays', () => {
|
|
90
90
|
const options = {
|
|
91
|
-
dimensions: { states:
|
|
92
|
-
states: [() => ({ primary: { color:
|
|
91
|
+
dimensions: { states: 'state', sizes: 'size' },
|
|
92
|
+
states: [() => ({ primary: { color: 'red' } })],
|
|
93
93
|
}
|
|
94
94
|
const result = getDimensionThemes({}, options)
|
|
95
|
-
expect(result.state).toEqual({ primary: { color:
|
|
95
|
+
expect(result.state).toEqual({ primary: { color: 'red' } })
|
|
96
96
|
expect(result.size).toBeUndefined()
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
it(
|
|
99
|
+
it('strips nullable values from results', () => {
|
|
100
100
|
const options = {
|
|
101
|
-
dimensions: { states:
|
|
102
|
-
states: [() => ({ primary: { color:
|
|
101
|
+
dimensions: { states: 'state' },
|
|
102
|
+
states: [() => ({ primary: { color: 'red' }, secondary: null })],
|
|
103
103
|
}
|
|
104
104
|
const result = getDimensionThemes({}, options)
|
|
105
|
-
expect(result.state.primary).toEqual({ color:
|
|
105
|
+
expect(result.state.primary).toEqual({ color: 'red' })
|
|
106
106
|
expect(result.state.secondary).toBeUndefined()
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
it(
|
|
109
|
+
it('handles multi-key dimensions', () => {
|
|
110
110
|
const options = {
|
|
111
|
-
dimensions: { multiple: { propName:
|
|
112
|
-
multiple: [() => ({ a: { weight:
|
|
111
|
+
dimensions: { multiple: { propName: 'multiple', multi: true } },
|
|
112
|
+
multiple: [() => ({ a: { weight: 'bold' } })],
|
|
113
113
|
}
|
|
114
114
|
const result = getDimensionThemes({}, options)
|
|
115
|
-
expect(result.multiple).toEqual({ a: { weight:
|
|
115
|
+
expect(result.multiple).toEqual({ a: { weight: 'bold' } })
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
it(
|
|
118
|
+
it('skips empty callback arrays', () => {
|
|
119
119
|
const options = {
|
|
120
|
-
dimensions: { states:
|
|
120
|
+
dimensions: { states: 'state' },
|
|
121
121
|
states: [],
|
|
122
122
|
}
|
|
123
123
|
const result = getDimensionThemes({}, options)
|
|
@@ -125,68 +125,68 @@ describe("getDimensionThemes", () => {
|
|
|
125
125
|
})
|
|
126
126
|
})
|
|
127
127
|
|
|
128
|
-
describe(
|
|
129
|
-
it(
|
|
128
|
+
describe('calculateChainOptions (theme)', () => {
|
|
129
|
+
it('returns empty for null', () => {
|
|
130
130
|
expect(calculateChainOptions(null, [])).toEqual({})
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
-
it(
|
|
133
|
+
it('returns empty for undefined', () => {
|
|
134
134
|
expect(calculateChainOptions(undefined, [])).toEqual({})
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
-
it(
|
|
137
|
+
it('returns empty for empty array', () => {
|
|
138
138
|
expect(calculateChainOptions([], [])).toEqual({})
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
it(
|
|
141
|
+
it('evaluates chain and deep-merges results', () => {
|
|
142
142
|
const fn1 = () => ({ nested: { a: 1 } })
|
|
143
143
|
const fn2 = () => ({ nested: { b: 2 } })
|
|
144
144
|
const result = calculateChainOptions([fn1, fn2], [])
|
|
145
145
|
expect(result).toEqual({ nested: { a: 1, b: 2 } })
|
|
146
146
|
})
|
|
147
147
|
|
|
148
|
-
it(
|
|
148
|
+
it('passes args to each function', () => {
|
|
149
149
|
const fn = vi.fn(() => ({}))
|
|
150
|
-
calculateChainOptions([fn], [
|
|
151
|
-
expect(fn).toHaveBeenCalledWith(
|
|
150
|
+
calculateChainOptions([fn], ['arg1', 'arg2'])
|
|
151
|
+
expect(fn).toHaveBeenCalledWith('arg1', 'arg2')
|
|
152
152
|
})
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
describe(
|
|
156
|
-
it(
|
|
155
|
+
describe('getTheme', () => {
|
|
156
|
+
it('returns baseTheme when rocketstate has no matching dimension themes', () => {
|
|
157
157
|
const result = getTheme({
|
|
158
|
-
rocketstate: { state:
|
|
158
|
+
rocketstate: { state: 'unknown' },
|
|
159
159
|
themes: { state: {} },
|
|
160
|
-
baseTheme: { color:
|
|
160
|
+
baseTheme: { color: 'blue' },
|
|
161
161
|
})
|
|
162
|
-
expect(result.color).toBe(
|
|
162
|
+
expect(result.color).toBe('blue')
|
|
163
163
|
})
|
|
164
164
|
|
|
165
|
-
it(
|
|
165
|
+
it('merges dimension theme into baseTheme', () => {
|
|
166
166
|
const result = getTheme({
|
|
167
|
-
rocketstate: { state:
|
|
168
|
-
themes: { state: { primary: { color:
|
|
169
|
-
baseTheme: { color:
|
|
167
|
+
rocketstate: { state: 'primary' },
|
|
168
|
+
themes: { state: { primary: { color: 'red' } } },
|
|
169
|
+
baseTheme: { color: 'blue', bg: 'white' },
|
|
170
170
|
})
|
|
171
|
-
expect(result.color).toBe(
|
|
172
|
-
expect(result.bg).toBe(
|
|
171
|
+
expect(result.color).toBe('red')
|
|
172
|
+
expect(result.bg).toBe('white')
|
|
173
173
|
})
|
|
174
174
|
|
|
175
|
-
it(
|
|
175
|
+
it('handles array values for multi-key dimensions', () => {
|
|
176
176
|
const result = getTheme({
|
|
177
|
-
rocketstate: { multiple: [
|
|
177
|
+
rocketstate: { multiple: ['a', 'b'] },
|
|
178
178
|
themes: {
|
|
179
|
-
multiple: { a: { weight:
|
|
179
|
+
multiple: { a: { weight: 'bold' }, b: { style: 'italic' } },
|
|
180
180
|
},
|
|
181
181
|
baseTheme: {},
|
|
182
182
|
})
|
|
183
|
-
expect(result.weight).toBe(
|
|
184
|
-
expect(result.style).toBe(
|
|
183
|
+
expect(result.weight).toBe('bold')
|
|
184
|
+
expect(result.style).toBe('italic')
|
|
185
185
|
})
|
|
186
186
|
|
|
187
|
-
it(
|
|
187
|
+
it('later dimensions override earlier ones', () => {
|
|
188
188
|
const result = getTheme({
|
|
189
|
-
rocketstate: { state:
|
|
189
|
+
rocketstate: { state: 'primary', size: 'large' },
|
|
190
190
|
themes: {
|
|
191
191
|
state: { primary: { fontSize: 14 } },
|
|
192
192
|
size: { large: { fontSize: 20 } },
|
|
@@ -196,63 +196,63 @@ describe("getTheme", () => {
|
|
|
196
196
|
expect(result.fontSize).toBe(20)
|
|
197
197
|
})
|
|
198
198
|
|
|
199
|
-
it(
|
|
200
|
-
const baseTheme = { color:
|
|
199
|
+
it('does not mutate baseTheme', () => {
|
|
200
|
+
const baseTheme = { color: 'blue' }
|
|
201
201
|
getTheme({
|
|
202
|
-
rocketstate: { state:
|
|
203
|
-
themes: { state: { primary: { color:
|
|
202
|
+
rocketstate: { state: 'primary' },
|
|
203
|
+
themes: { state: { primary: { color: 'red' } } },
|
|
204
204
|
baseTheme,
|
|
205
205
|
})
|
|
206
|
-
expect(baseTheme.color).toBe(
|
|
206
|
+
expect(baseTheme.color).toBe('blue')
|
|
207
207
|
})
|
|
208
208
|
})
|
|
209
209
|
|
|
210
|
-
describe(
|
|
211
|
-
it(
|
|
210
|
+
describe('getTheme with transform dimensions', () => {
|
|
211
|
+
it('applies transform function values after all static dimensions', () => {
|
|
212
212
|
const result = getTheme({
|
|
213
|
-
rocketstate: { state:
|
|
213
|
+
rocketstate: { state: 'primary', modifier: 'outlined' },
|
|
214
214
|
themes: {
|
|
215
|
-
state: { primary: { backgroundColor:
|
|
215
|
+
state: { primary: { backgroundColor: 'blue', color: 'white' } },
|
|
216
216
|
modifier: {
|
|
217
217
|
outlined: (theme: any) => ({
|
|
218
218
|
color: theme.backgroundColor,
|
|
219
|
-
backgroundColor:
|
|
219
|
+
backgroundColor: 'transparent',
|
|
220
220
|
}),
|
|
221
221
|
},
|
|
222
222
|
},
|
|
223
|
-
baseTheme: { border:
|
|
223
|
+
baseTheme: { border: 'none' },
|
|
224
224
|
transformKeys: { modifier: true },
|
|
225
225
|
})
|
|
226
|
-
expect(result.color).toBe(
|
|
227
|
-
expect(result.backgroundColor).toBe(
|
|
228
|
-
expect(result.border).toBe(
|
|
226
|
+
expect(result.color).toBe('blue')
|
|
227
|
+
expect(result.backgroundColor).toBe('transparent')
|
|
228
|
+
expect(result.border).toBe('none')
|
|
229
229
|
})
|
|
230
230
|
|
|
231
|
-
it(
|
|
231
|
+
it('transform receives accumulated theme, appTheme, mode, and css', () => {
|
|
232
232
|
const transformFn = vi.fn((theme: any) => ({ derived: theme.color }))
|
|
233
|
-
const appTheme = { colors: { primary:
|
|
233
|
+
const appTheme = { colors: { primary: 'blue' } }
|
|
234
234
|
getTheme({
|
|
235
|
-
rocketstate: { state:
|
|
235
|
+
rocketstate: { state: 'primary', modifier: 'test' },
|
|
236
236
|
themes: {
|
|
237
|
-
state: { primary: { color:
|
|
237
|
+
state: { primary: { color: 'red' } },
|
|
238
238
|
modifier: { test: transformFn },
|
|
239
239
|
},
|
|
240
|
-
baseTheme: { bg:
|
|
240
|
+
baseTheme: { bg: 'white' },
|
|
241
241
|
transformKeys: { modifier: true },
|
|
242
242
|
appTheme,
|
|
243
243
|
})
|
|
244
244
|
expect(transformFn).toHaveBeenCalledWith(
|
|
245
|
-
expect.objectContaining({ bg:
|
|
245
|
+
expect.objectContaining({ bg: 'white', color: 'red' }),
|
|
246
246
|
appTheme,
|
|
247
247
|
expect.any(Function),
|
|
248
248
|
expect.anything(),
|
|
249
249
|
)
|
|
250
250
|
})
|
|
251
251
|
|
|
252
|
-
it(
|
|
253
|
-
const appTheme = { spacing: { lg:
|
|
252
|
+
it('transform can use appTheme values', () => {
|
|
253
|
+
const appTheme = { spacing: { lg: '2rem' } }
|
|
254
254
|
const result = getTheme({
|
|
255
|
-
rocketstate: { modifier:
|
|
255
|
+
rocketstate: { modifier: 'withSpacing' },
|
|
256
256
|
themes: {
|
|
257
257
|
modifier: {
|
|
258
258
|
withSpacing: (_theme: any, app: any) => ({
|
|
@@ -260,64 +260,64 @@ describe("getTheme with transform dimensions", () => {
|
|
|
260
260
|
}),
|
|
261
261
|
},
|
|
262
262
|
},
|
|
263
|
-
baseTheme: { color:
|
|
263
|
+
baseTheme: { color: 'red' },
|
|
264
264
|
transformKeys: { modifier: true },
|
|
265
265
|
appTheme,
|
|
266
266
|
})
|
|
267
|
-
expect(result.padding).toBe(
|
|
268
|
-
expect(result.color).toBe(
|
|
267
|
+
expect(result.padding).toBe('2rem')
|
|
268
|
+
expect(result.color).toBe('red')
|
|
269
269
|
})
|
|
270
270
|
|
|
271
|
-
it(
|
|
271
|
+
it('supports multiple transform values (multi dimension)', () => {
|
|
272
272
|
const result = getTheme({
|
|
273
|
-
rocketstate: { modifier: [
|
|
273
|
+
rocketstate: { modifier: ['outlined', 'rounded'] },
|
|
274
274
|
themes: {
|
|
275
275
|
modifier: {
|
|
276
276
|
outlined: (theme: any) => ({
|
|
277
277
|
color: theme.backgroundColor,
|
|
278
|
-
backgroundColor:
|
|
278
|
+
backgroundColor: 'transparent',
|
|
279
279
|
}),
|
|
280
|
-
rounded: () => ({ borderRadius:
|
|
280
|
+
rounded: () => ({ borderRadius: '999px' }),
|
|
281
281
|
},
|
|
282
282
|
},
|
|
283
|
-
baseTheme: { backgroundColor:
|
|
283
|
+
baseTheme: { backgroundColor: 'blue', color: 'white' },
|
|
284
284
|
transformKeys: { modifier: true },
|
|
285
285
|
})
|
|
286
|
-
expect(result.color).toBe(
|
|
287
|
-
expect(result.backgroundColor).toBe(
|
|
288
|
-
expect(result.borderRadius).toBe(
|
|
286
|
+
expect(result.color).toBe('blue')
|
|
287
|
+
expect(result.backgroundColor).toBe('transparent')
|
|
288
|
+
expect(result.borderRadius).toBe('999px')
|
|
289
289
|
})
|
|
290
290
|
|
|
291
|
-
it(
|
|
291
|
+
it('transforms compose — later transform sees earlier transform results', () => {
|
|
292
292
|
const result = getTheme({
|
|
293
|
-
rocketstate: { modifier: [
|
|
293
|
+
rocketstate: { modifier: ['first', 'second'] },
|
|
294
294
|
themes: {
|
|
295
295
|
modifier: {
|
|
296
|
-
first: () => ({ step:
|
|
296
|
+
first: () => ({ step: 'one' }),
|
|
297
297
|
second: (theme: any) => ({ sawStep: theme.step }),
|
|
298
298
|
},
|
|
299
299
|
},
|
|
300
300
|
baseTheme: {},
|
|
301
301
|
transformKeys: { modifier: true },
|
|
302
302
|
})
|
|
303
|
-
expect(result.step).toBe(
|
|
304
|
-
expect(result.sawStep).toBe(
|
|
303
|
+
expect(result.step).toBe('one')
|
|
304
|
+
expect(result.sawStep).toBe('one')
|
|
305
305
|
})
|
|
306
306
|
|
|
307
|
-
it(
|
|
307
|
+
it('works without transformKeys (backward compatible)', () => {
|
|
308
308
|
const result = getTheme({
|
|
309
|
-
rocketstate: { state:
|
|
310
|
-
themes: { state: { primary: { color:
|
|
311
|
-
baseTheme: { bg:
|
|
309
|
+
rocketstate: { state: 'primary' },
|
|
310
|
+
themes: { state: { primary: { color: 'red' } } },
|
|
311
|
+
baseTheme: { bg: 'white' },
|
|
312
312
|
})
|
|
313
|
-
expect(result.color).toBe(
|
|
314
|
-
expect(result.bg).toBe(
|
|
313
|
+
expect(result.color).toBe('red')
|
|
314
|
+
expect(result.bg).toBe('white')
|
|
315
315
|
})
|
|
316
316
|
|
|
317
|
-
it(
|
|
318
|
-
const fn = vi.fn(() => ({ color:
|
|
317
|
+
it('non-transform dimension treats function values as regular merge (not called as transform)', () => {
|
|
318
|
+
const fn = vi.fn(() => ({ color: 'red' }))
|
|
319
319
|
getTheme({
|
|
320
|
-
rocketstate: { state:
|
|
320
|
+
rocketstate: { state: 'primary' },
|
|
321
321
|
themes: { state: { primary: fn } },
|
|
322
322
|
baseTheme: {},
|
|
323
323
|
transformKeys: {},
|
|
@@ -325,25 +325,25 @@ describe("getTheme with transform dimensions", () => {
|
|
|
325
325
|
expect(fn).not.toHaveBeenCalled()
|
|
326
326
|
})
|
|
327
327
|
|
|
328
|
-
it(
|
|
329
|
-
const transformFn = vi.fn(() => ({ color:
|
|
328
|
+
it('transform dimension not in rocketstate is ignored', () => {
|
|
329
|
+
const transformFn = vi.fn(() => ({ color: 'red' }))
|
|
330
330
|
const result = getTheme({
|
|
331
|
-
rocketstate: { state:
|
|
331
|
+
rocketstate: { state: 'primary' },
|
|
332
332
|
themes: {
|
|
333
|
-
state: { primary: { color:
|
|
333
|
+
state: { primary: { color: 'blue' } },
|
|
334
334
|
modifier: { outlined: transformFn },
|
|
335
335
|
},
|
|
336
336
|
baseTheme: {},
|
|
337
337
|
transformKeys: { modifier: true },
|
|
338
338
|
})
|
|
339
339
|
expect(transformFn).not.toHaveBeenCalled()
|
|
340
|
-
expect(result.color).toBe(
|
|
340
|
+
expect(result.color).toBe('blue')
|
|
341
341
|
})
|
|
342
342
|
|
|
343
|
-
it(
|
|
344
|
-
const baseTheme = { color:
|
|
343
|
+
it('transform does not mutate baseTheme', () => {
|
|
344
|
+
const baseTheme = { color: 'blue', bg: 'white' }
|
|
345
345
|
getTheme({
|
|
346
|
-
rocketstate: { modifier:
|
|
346
|
+
rocketstate: { modifier: 'flip' },
|
|
347
347
|
themes: {
|
|
348
348
|
modifier: {
|
|
349
349
|
flip: (theme: any) => ({ color: theme.bg, bg: theme.color }),
|
|
@@ -352,25 +352,25 @@ describe("getTheme with transform dimensions", () => {
|
|
|
352
352
|
baseTheme,
|
|
353
353
|
transformKeys: { modifier: true },
|
|
354
354
|
})
|
|
355
|
-
expect(baseTheme.color).toBe(
|
|
356
|
-
expect(baseTheme.bg).toBe(
|
|
355
|
+
expect(baseTheme.color).toBe('blue')
|
|
356
|
+
expect(baseTheme.bg).toBe('white')
|
|
357
357
|
})
|
|
358
358
|
|
|
359
|
-
it(
|
|
359
|
+
it('transform with deep nested theme values', () => {
|
|
360
360
|
const result = getTheme({
|
|
361
|
-
rocketstate: { state:
|
|
361
|
+
rocketstate: { state: 'primary', modifier: 'outlined' },
|
|
362
362
|
themes: {
|
|
363
363
|
state: {
|
|
364
364
|
primary: {
|
|
365
|
-
backgroundColor:
|
|
366
|
-
color:
|
|
367
|
-
hover: { backgroundColor:
|
|
365
|
+
backgroundColor: 'blue',
|
|
366
|
+
color: 'white',
|
|
367
|
+
hover: { backgroundColor: 'darkblue' },
|
|
368
368
|
},
|
|
369
369
|
},
|
|
370
370
|
modifier: {
|
|
371
371
|
outlined: (theme: any) => ({
|
|
372
372
|
color: theme.backgroundColor,
|
|
373
|
-
backgroundColor:
|
|
373
|
+
backgroundColor: 'transparent',
|
|
374
374
|
hover: {
|
|
375
375
|
backgroundColor: theme.backgroundColor,
|
|
376
376
|
color: theme.color,
|
|
@@ -381,17 +381,17 @@ describe("getTheme with transform dimensions", () => {
|
|
|
381
381
|
baseTheme: {},
|
|
382
382
|
transformKeys: { modifier: true },
|
|
383
383
|
})
|
|
384
|
-
expect(result.color).toBe(
|
|
385
|
-
expect(result.backgroundColor).toBe(
|
|
384
|
+
expect(result.color).toBe('blue')
|
|
385
|
+
expect(result.backgroundColor).toBe('transparent')
|
|
386
386
|
const hover = result.hover as Record<string, any>
|
|
387
|
-
expect(hover.backgroundColor).toBe(
|
|
388
|
-
expect(hover.color).toBe(
|
|
387
|
+
expect(hover.backgroundColor).toBe('blue')
|
|
388
|
+
expect(hover.color).toBe('white')
|
|
389
389
|
})
|
|
390
390
|
|
|
391
|
-
it(
|
|
391
|
+
it('appTheme defaults to empty object when not provided', () => {
|
|
392
392
|
const transformFn = vi.fn(() => ({}))
|
|
393
393
|
getTheme({
|
|
394
|
-
rocketstate: { modifier:
|
|
394
|
+
rocketstate: { modifier: 'test' },
|
|
395
395
|
themes: { modifier: { test: transformFn } },
|
|
396
396
|
baseTheme: {},
|
|
397
397
|
transformKeys: { modifier: true },
|
|
@@ -404,60 +404,60 @@ describe("getTheme with transform dimensions", () => {
|
|
|
404
404
|
)
|
|
405
405
|
})
|
|
406
406
|
|
|
407
|
-
it(
|
|
407
|
+
it('transform with mode callback produces light/dark values', () => {
|
|
408
408
|
const result = getTheme({
|
|
409
|
-
rocketstate: { modifier:
|
|
409
|
+
rocketstate: { modifier: 'themed' },
|
|
410
410
|
themes: {
|
|
411
411
|
modifier: {
|
|
412
412
|
themed: (_theme: any, _app: any, mode: any) => ({
|
|
413
|
-
shadow: mode(
|
|
413
|
+
shadow: mode('0 2px 4px rgba(0,0,0,0.1)', 'none'),
|
|
414
414
|
}),
|
|
415
415
|
},
|
|
416
416
|
},
|
|
417
417
|
baseTheme: {},
|
|
418
418
|
transformKeys: { modifier: true },
|
|
419
419
|
})
|
|
420
|
-
expect(typeof result.shadow).toBe(
|
|
420
|
+
expect(typeof result.shadow).toBe('function')
|
|
421
421
|
})
|
|
422
422
|
})
|
|
423
423
|
|
|
424
|
-
describe(
|
|
425
|
-
it(
|
|
426
|
-
const result = getThemeByMode({ color:
|
|
427
|
-
expect(result).toEqual({ color:
|
|
424
|
+
describe('getThemeByMode', () => {
|
|
425
|
+
it('returns scalar values as-is', () => {
|
|
426
|
+
const result = getThemeByMode({ color: 'red', size: 16 }, 'light')
|
|
427
|
+
expect(result).toEqual({ color: 'red', size: 16 })
|
|
428
428
|
})
|
|
429
429
|
|
|
430
|
-
it(
|
|
431
|
-
const result = getThemeByMode({ nested: { color:
|
|
432
|
-
expect(result).toEqual({ nested: { color:
|
|
430
|
+
it('recursively processes nested objects', () => {
|
|
431
|
+
const result = getThemeByMode({ nested: { color: 'red' } }, 'light')
|
|
432
|
+
expect(result).toEqual({ nested: { color: 'red' } })
|
|
433
433
|
})
|
|
434
434
|
|
|
435
|
-
it(
|
|
436
|
-
const cb = themeModeCallback(
|
|
437
|
-
const result: any = getThemeByMode({ color: cb },
|
|
438
|
-
expect(result.color).toBe(
|
|
435
|
+
it('resolves mode callbacks for light', () => {
|
|
436
|
+
const cb = themeModeCallback('lightColor', 'darkColor')
|
|
437
|
+
const result: any = getThemeByMode({ color: cb }, 'light')
|
|
438
|
+
expect(result.color).toBe('lightColor')
|
|
439
439
|
})
|
|
440
440
|
|
|
441
|
-
it(
|
|
442
|
-
const cb = themeModeCallback(
|
|
443
|
-
const result: any = getThemeByMode({ color: cb },
|
|
444
|
-
expect(result.color).toBe(
|
|
441
|
+
it('resolves mode callbacks for dark', () => {
|
|
442
|
+
const cb = themeModeCallback('lightColor', 'darkColor')
|
|
443
|
+
const result: any = getThemeByMode({ color: cb }, 'dark')
|
|
444
|
+
expect(result.color).toBe('darkColor')
|
|
445
445
|
})
|
|
446
446
|
|
|
447
|
-
it(
|
|
448
|
-
const cb = themeModeCallback(
|
|
449
|
-
const result: any = getThemeByMode({ nested: { bg: cb } },
|
|
450
|
-
expect(result.nested.bg).toBe(
|
|
447
|
+
it('resolves nested mode callbacks', () => {
|
|
448
|
+
const cb = themeModeCallback('lightBg', 'darkBg')
|
|
449
|
+
const result: any = getThemeByMode({ nested: { bg: cb } }, 'light')
|
|
450
|
+
expect(result.nested.bg).toBe('lightBg')
|
|
451
451
|
})
|
|
452
452
|
|
|
453
|
-
it(
|
|
454
|
-
const cb = themeModeCallback(
|
|
453
|
+
it('handles mixed values and mode callbacks', () => {
|
|
454
|
+
const cb = themeModeCallback('#fff', '#000')
|
|
455
455
|
const result: any = getThemeByMode(
|
|
456
|
-
{ bg: cb, fontSize: 16, nested: { color:
|
|
457
|
-
|
|
456
|
+
{ bg: cb, fontSize: 16, nested: { color: 'static' } },
|
|
457
|
+
'dark',
|
|
458
458
|
)
|
|
459
|
-
expect(result.bg).toBe(
|
|
459
|
+
expect(result.bg).toBe('#000')
|
|
460
460
|
expect(result.fontSize).toBe(16)
|
|
461
|
-
expect(result.nested.color).toBe(
|
|
461
|
+
expect(result.nested.color).toBe('static')
|
|
462
462
|
})
|
|
463
463
|
})
|
package/src/cache/index.ts
CHANGED