clava 0.3.0 → 0.4.1
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/CHANGELOG.md +86 -0
- package/README.md +38 -38
- package/dist/index.d.ts +19 -27
- package/dist/index.js +143 -86
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/src/index.ts +430 -215
- package/src/types.ts +38 -46
- package/src/utils.ts +31 -10
- package/tests/_utils.ts +7 -5
- package/tests/build.test.ts +81 -7
- package/tests/component-api.test.ts +28 -28
- package/tests/extend.test.ts +13 -8
- package/tests/{computed-variants.test.ts → function-variants.test.ts} +105 -25
- package/tests/prototype-pollution.test.ts +6 -6
- package/tests/{computed.test.ts → refine.test.ts} +292 -149
- package/tests/variants-inference.test.ts +252 -0
|
@@ -15,20 +15,20 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
15
15
|
const cls = getConfigTransformClass(config);
|
|
16
16
|
|
|
17
17
|
describe(getConfigDescription(config), () => {
|
|
18
|
-
test("
|
|
18
|
+
test("refine", () => {
|
|
19
19
|
const component = getModeComponent(
|
|
20
20
|
mode,
|
|
21
21
|
cv({
|
|
22
22
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
23
|
-
|
|
24
|
-
variants.size === "lg" ? "
|
|
23
|
+
refine: ({ variants }) =>
|
|
24
|
+
variants.size === "lg" ? "refine-lg" : null,
|
|
25
25
|
}),
|
|
26
26
|
);
|
|
27
27
|
const props = component({ size: "lg" });
|
|
28
|
-
expect(getStyleClass(props)).toEqual({ class: cls("lg
|
|
28
|
+
expect(getStyleClass(props)).toEqual({ class: cls("lg refine-lg") });
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
test("
|
|
31
|
+
test("refine with setVariants", () => {
|
|
32
32
|
const component = getModeComponent(
|
|
33
33
|
mode,
|
|
34
34
|
cv({
|
|
@@ -36,7 +36,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
36
36
|
size: { sm: "sm", lg: "lg" },
|
|
37
37
|
color: { red: "red", blue: "blue" },
|
|
38
38
|
},
|
|
39
|
-
|
|
39
|
+
refine: ({ variants, setVariants }) => {
|
|
40
40
|
if (variants.size === "lg") {
|
|
41
41
|
setVariants({ color: "red" });
|
|
42
42
|
}
|
|
@@ -47,7 +47,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
47
47
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
test("
|
|
50
|
+
test("refine re-runs when it changes variants", () => {
|
|
51
51
|
const component = getModeComponent(
|
|
52
52
|
mode,
|
|
53
53
|
cv({
|
|
@@ -55,23 +55,23 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
55
55
|
size: { sm: "sm", lg: "lg" },
|
|
56
56
|
color: { red: "red", blue: "blue" },
|
|
57
57
|
},
|
|
58
|
-
|
|
58
|
+
refine: ({ variants, setVariants, addClass }) => {
|
|
59
59
|
if (variants.size === "lg") {
|
|
60
60
|
setVariants({ color: "red" });
|
|
61
61
|
}
|
|
62
62
|
if (variants.color === "red") {
|
|
63
|
-
addClass("
|
|
63
|
+
addClass("refine-red");
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
}),
|
|
67
67
|
);
|
|
68
68
|
const props = component({ size: "lg" });
|
|
69
69
|
expect(getStyleClass(props)).toEqual({
|
|
70
|
-
class: cls("lg red
|
|
70
|
+
class: cls("lg red refine-red"),
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
test("
|
|
74
|
+
test("refine re-runs when setDefaultVariants changes variants", () => {
|
|
75
75
|
const component = getModeComponent(
|
|
76
76
|
mode,
|
|
77
77
|
cv({
|
|
@@ -79,35 +79,35 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
79
79
|
size: { sm: "sm", lg: "lg" },
|
|
80
80
|
color: { red: "red", blue: "blue" },
|
|
81
81
|
},
|
|
82
|
-
|
|
82
|
+
refine: ({ variants, setDefaultVariants, addClass }) => {
|
|
83
83
|
setDefaultVariants({ color: "red" });
|
|
84
84
|
if (variants.color === "red") {
|
|
85
85
|
setDefaultVariants({ size: "lg" });
|
|
86
86
|
}
|
|
87
87
|
if (variants.size === "lg") {
|
|
88
|
-
addClass("
|
|
88
|
+
addClass("refine-lg");
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
}),
|
|
92
92
|
);
|
|
93
93
|
const props = component();
|
|
94
94
|
expect(getStyleClass(props)).toEqual({
|
|
95
|
-
class: cls("lg red
|
|
95
|
+
class: cls("lg red refine-lg"),
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
test("
|
|
99
|
+
test("refine converges with NaN setDefaultVariants", () => {
|
|
100
100
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
101
101
|
const component = getModeComponent(
|
|
102
102
|
mode,
|
|
103
103
|
cv({
|
|
104
|
-
|
|
104
|
+
variants: {
|
|
105
105
|
value: (value: number) => (Number.isNaN(value) ? "nan" : null),
|
|
106
106
|
},
|
|
107
|
-
|
|
107
|
+
refine: ({ variants, setDefaultVariants, addClass }) => {
|
|
108
108
|
setDefaultVariants({ value: Number.NaN });
|
|
109
109
|
if (Number.isNaN(variants.value)) {
|
|
110
|
-
addClass("
|
|
110
|
+
addClass("refine-nan");
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
113
|
}),
|
|
@@ -116,7 +116,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
116
116
|
try {
|
|
117
117
|
const props = component();
|
|
118
118
|
expect(getStyleClass(props)).toEqual({
|
|
119
|
-
class: cls("nan
|
|
119
|
+
class: cls("nan refine-nan"),
|
|
120
120
|
});
|
|
121
121
|
expect(component.getVariants()).toEqual({ value: Number.NaN });
|
|
122
122
|
expect(warn).not.toHaveBeenCalled();
|
|
@@ -125,7 +125,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
test("
|
|
128
|
+
test("refine with setDefaultVariants", () => {
|
|
129
129
|
const component = getModeComponent(
|
|
130
130
|
mode,
|
|
131
131
|
cv({
|
|
@@ -133,7 +133,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
133
133
|
size: { sm: "sm", lg: "lg" },
|
|
134
134
|
color: { red: "red", blue: "blue" },
|
|
135
135
|
},
|
|
136
|
-
|
|
136
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
137
137
|
if (variants.size === "lg") {
|
|
138
138
|
setDefaultVariants({ color: "red" });
|
|
139
139
|
}
|
|
@@ -144,7 +144,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
144
144
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
-
test("
|
|
147
|
+
test("refine setDefaultVariants does not override props", () => {
|
|
148
148
|
const component = getModeComponent(
|
|
149
149
|
mode,
|
|
150
150
|
cv({
|
|
@@ -152,7 +152,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
152
152
|
size: { sm: "sm", lg: "lg" },
|
|
153
153
|
color: { red: "red", blue: "blue" },
|
|
154
154
|
},
|
|
155
|
-
|
|
155
|
+
refine: ({ setDefaultVariants }) => {
|
|
156
156
|
setDefaultVariants({ color: "red" });
|
|
157
157
|
},
|
|
158
158
|
}),
|
|
@@ -161,7 +161,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
161
161
|
expect(getStyleClass(props)).toEqual({ class: cls("lg blue") });
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
-
test("
|
|
164
|
+
test("refine setDefaultVariants overrides defaultVariants", () => {
|
|
165
165
|
const component = getModeComponent(
|
|
166
166
|
mode,
|
|
167
167
|
cv({
|
|
@@ -170,7 +170,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
170
170
|
color: { red: "red", blue: "blue" },
|
|
171
171
|
},
|
|
172
172
|
defaultVariants: { size: "sm", color: "red" },
|
|
173
|
-
|
|
173
|
+
refine: ({ setDefaultVariants }) => {
|
|
174
174
|
setDefaultVariants({ color: "blue" });
|
|
175
175
|
},
|
|
176
176
|
}),
|
|
@@ -179,7 +179,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
179
179
|
expect(getStyleClass(props)).toEqual({ class: cls("sm blue") });
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
test("
|
|
182
|
+
test("refine setDefaultVariants overrides extended defaultVariants", () => {
|
|
183
183
|
const base = cv({
|
|
184
184
|
variants: { color: { red: "red", blue: "blue" } },
|
|
185
185
|
defaultVariants: { color: "red" },
|
|
@@ -190,7 +190,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
190
190
|
extend: [base],
|
|
191
191
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
192
192
|
defaultVariants: { size: "sm" },
|
|
193
|
-
|
|
193
|
+
refine: ({ setDefaultVariants }) => {
|
|
194
194
|
setDefaultVariants({ color: "blue" });
|
|
195
195
|
},
|
|
196
196
|
}),
|
|
@@ -199,7 +199,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
199
199
|
expect(getStyleClass(props)).toEqual({ class: cls("blue sm") });
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
-
test("
|
|
202
|
+
test("refine setDefaultVariants overrides child defaultVariants", () => {
|
|
203
203
|
const base = cv({
|
|
204
204
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
205
205
|
});
|
|
@@ -209,7 +209,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
209
209
|
extend: [base],
|
|
210
210
|
variants: { color: { red: "red", blue: "blue" } },
|
|
211
211
|
defaultVariants: { size: "sm", color: "red" },
|
|
212
|
-
|
|
212
|
+
refine: ({ setDefaultVariants }) => {
|
|
213
213
|
setDefaultVariants({ size: "lg" });
|
|
214
214
|
},
|
|
215
215
|
}),
|
|
@@ -218,11 +218,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
218
218
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
219
219
|
});
|
|
220
220
|
|
|
221
|
-
test("
|
|
221
|
+
test("refine setDefaultVariants from parent overrides child defaultVariants", () => {
|
|
222
222
|
const base = cv({
|
|
223
223
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
224
224
|
defaultVariants: { size: "sm" },
|
|
225
|
-
|
|
225
|
+
refine: ({ setDefaultVariants }) => {
|
|
226
226
|
setDefaultVariants({ size: "lg" });
|
|
227
227
|
},
|
|
228
228
|
});
|
|
@@ -238,11 +238,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
238
238
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
test("
|
|
241
|
+
test("refine setDefaultVariants from parent overrides child defaultVariants based on props", () => {
|
|
242
242
|
const base = cv({
|
|
243
243
|
variants: { size: { sm: "sm", lg: "lg" }, enabled: "" },
|
|
244
244
|
defaultVariants: { size: "sm" },
|
|
245
|
-
|
|
245
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
246
246
|
if (!variants.enabled) return;
|
|
247
247
|
setDefaultVariants({ size: "lg" });
|
|
248
248
|
},
|
|
@@ -259,11 +259,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
259
259
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
260
260
|
});
|
|
261
261
|
|
|
262
|
-
test("
|
|
262
|
+
test("refine receives default variants from child", () => {
|
|
263
263
|
const base = cv({
|
|
264
264
|
variants: { size: { sm: "sm", lg: "lg" }, large: "" },
|
|
265
265
|
defaultVariants: { size: "sm" },
|
|
266
|
-
|
|
266
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
267
267
|
if (variants.large) {
|
|
268
268
|
setDefaultVariants({ size: "lg" });
|
|
269
269
|
}
|
|
@@ -281,11 +281,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
281
281
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
-
test("
|
|
284
|
+
test("refine receives default variants from grandchild", () => {
|
|
285
285
|
const base = cv({
|
|
286
286
|
variants: { size: { sm: "sm", lg: "lg" }, large: "" },
|
|
287
287
|
defaultVariants: { size: "sm" },
|
|
288
|
-
|
|
288
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
289
289
|
if (variants.large) {
|
|
290
290
|
setDefaultVariants({ size: "lg" });
|
|
291
291
|
}
|
|
@@ -304,10 +304,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
304
304
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
305
305
|
});
|
|
306
306
|
|
|
307
|
-
test("
|
|
307
|
+
test("refine receives default variants from intermediate component", () => {
|
|
308
308
|
const parent = cv({
|
|
309
309
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
310
|
-
|
|
310
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
311
311
|
if (!variants.size) {
|
|
312
312
|
setDefaultVariants({ size: "lg" });
|
|
313
313
|
}
|
|
@@ -319,11 +319,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
319
319
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
320
320
|
});
|
|
321
321
|
|
|
322
|
-
test("child
|
|
322
|
+
test("child refine setDefaultVariants overrides parent refine setDefaultVariants", () => {
|
|
323
323
|
const base = cv({
|
|
324
324
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
325
325
|
defaultVariants: { size: "sm" },
|
|
326
|
-
|
|
326
|
+
refine: ({ setDefaultVariants }) => {
|
|
327
327
|
setDefaultVariants({ size: "lg" });
|
|
328
328
|
},
|
|
329
329
|
});
|
|
@@ -333,23 +333,23 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
333
333
|
extend: [base],
|
|
334
334
|
variants: { color: { red: "red", blue: "blue" } },
|
|
335
335
|
defaultVariants: { size: "sm", color: "red" },
|
|
336
|
-
|
|
336
|
+
refine: ({ setDefaultVariants }) => {
|
|
337
337
|
setDefaultVariants({ size: "sm" });
|
|
338
338
|
},
|
|
339
339
|
}),
|
|
340
340
|
);
|
|
341
341
|
const props = component();
|
|
342
342
|
// Order: parent defaultVariants (sm) -> child defaultVariants (sm)
|
|
343
|
-
// -> parent
|
|
344
|
-
// -> child
|
|
343
|
+
// -> parent refine.setDefaultVariants (lg)
|
|
344
|
+
// -> child refine.setDefaultVariants (sm)
|
|
345
345
|
expect(getStyleClass(props)).toEqual({ class: cls("sm red") });
|
|
346
346
|
});
|
|
347
347
|
|
|
348
|
-
test("
|
|
348
|
+
test("refine in extended component does not see foreign variant keys", () => {
|
|
349
349
|
const base = cv({
|
|
350
350
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
351
351
|
defaultVariants: { size: "sm" },
|
|
352
|
-
|
|
352
|
+
refine: ({ variants, addClass }) => {
|
|
353
353
|
// `color` is added by the parent component below — it must not
|
|
354
354
|
// leak into base's `ctx.variants`, whose shape is declared as
|
|
355
355
|
// `{ size }` only.
|
|
@@ -374,14 +374,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
374
374
|
});
|
|
375
375
|
|
|
376
376
|
test("setDefaultVariants in extended component does not branch on foreign variant keys", () => {
|
|
377
|
-
// Same shape as the test above, but the base's `
|
|
377
|
+
// Same shape as the test above, but the base's `refine` reaches
|
|
378
378
|
// `setDefaultVariants` — covers the resolveDefaults pass (driving
|
|
379
379
|
// both class output and `getVariants`) rather than the render-time
|
|
380
380
|
// compute path.
|
|
381
381
|
const base = cv({
|
|
382
382
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
383
383
|
defaultVariants: { size: "sm" },
|
|
384
|
-
|
|
384
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
385
385
|
if ("color" in (variants as Record<string, unknown>)) {
|
|
386
386
|
setDefaultVariants({ size: "lg" });
|
|
387
387
|
}
|
|
@@ -402,10 +402,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
402
402
|
});
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
test("child setDefaultVariants receives
|
|
405
|
+
test("child setDefaultVariants receives refined variants from parent", () => {
|
|
406
406
|
const base = cv({
|
|
407
407
|
variants: { size: { sm: "sm", lg: "lg" }, small: "" },
|
|
408
|
-
|
|
408
|
+
refine: ({ setDefaultVariants }) => {
|
|
409
409
|
setDefaultVariants({ small: true });
|
|
410
410
|
},
|
|
411
411
|
});
|
|
@@ -415,7 +415,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
415
415
|
extend: [base],
|
|
416
416
|
variants: { color: { red: "red", blue: "blue" } },
|
|
417
417
|
defaultVariants: { size: "lg", color: "red" },
|
|
418
|
-
|
|
418
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
419
419
|
if (variants.small) {
|
|
420
420
|
setDefaultVariants({ size: "sm" });
|
|
421
421
|
}
|
|
@@ -426,11 +426,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
426
426
|
expect(getStyleClass(props)).toEqual({ class: cls("sm red") });
|
|
427
427
|
});
|
|
428
428
|
|
|
429
|
-
test("
|
|
429
|
+
test("refine re-runs when base component refine changes variants", () => {
|
|
430
430
|
const base = cv({
|
|
431
431
|
variants: { size: { sm: "sm", lg: "lg" }, active: "" },
|
|
432
432
|
defaultVariants: { size: "sm" },
|
|
433
|
-
|
|
433
|
+
refine: ({ variants, setVariants }) => {
|
|
434
434
|
if (variants.active) {
|
|
435
435
|
setVariants({ size: "lg" });
|
|
436
436
|
}
|
|
@@ -441,7 +441,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
441
441
|
cv({
|
|
442
442
|
extend: [base],
|
|
443
443
|
variants: { color: { red: "red", blue: "blue" } },
|
|
444
|
-
|
|
444
|
+
refine: ({ variants, setVariants }) => {
|
|
445
445
|
if (variants.size === "lg") {
|
|
446
446
|
setVariants({ color: "red" });
|
|
447
447
|
}
|
|
@@ -452,7 +452,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
452
452
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
453
453
|
});
|
|
454
454
|
|
|
455
|
-
test("base
|
|
455
|
+
test("base refine setDefaultVariants works after its own setVariants re-run", () => {
|
|
456
456
|
const base = cv({
|
|
457
457
|
variants: {
|
|
458
458
|
size: { sm: "sm", lg: "lg" },
|
|
@@ -460,7 +460,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
460
460
|
mode: { on: "on" },
|
|
461
461
|
},
|
|
462
462
|
defaultVariants: { size: "sm" },
|
|
463
|
-
|
|
463
|
+
refine: ({ variants, setVariants, setDefaultVariants }) => {
|
|
464
464
|
if (variants.active) {
|
|
465
465
|
setVariants({ mode: "on" });
|
|
466
466
|
}
|
|
@@ -474,13 +474,13 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
474
474
|
expect(getStyleClass(props)).toEqual({ class: cls("lg on") });
|
|
475
475
|
});
|
|
476
476
|
|
|
477
|
-
test("
|
|
477
|
+
test("refine setVariants uses the latest pending value", () => {
|
|
478
478
|
const component = getModeComponent(
|
|
479
479
|
mode,
|
|
480
480
|
cv({
|
|
481
481
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
482
482
|
defaultVariants: { size: "sm" },
|
|
483
|
-
|
|
483
|
+
refine: ({ setVariants }) => {
|
|
484
484
|
setVariants({ size: "lg" });
|
|
485
485
|
setVariants({ size: "sm" });
|
|
486
486
|
},
|
|
@@ -490,7 +490,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
490
490
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
491
491
|
});
|
|
492
492
|
|
|
493
|
-
test("
|
|
493
|
+
test("refine setVariants does not mutate props with plain extends", () => {
|
|
494
494
|
const base = cv({
|
|
495
495
|
variants: { color: { red: "red", blue: "blue" } },
|
|
496
496
|
});
|
|
@@ -499,7 +499,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
499
499
|
cv({
|
|
500
500
|
extend: [base],
|
|
501
501
|
variants: { active: "" },
|
|
502
|
-
|
|
502
|
+
refine: ({ variants, setVariants }) => {
|
|
503
503
|
if (variants.active) {
|
|
504
504
|
setVariants({ color: "red" });
|
|
505
505
|
}
|
|
@@ -519,7 +519,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
519
519
|
test("child setVariants keeps overriding base setDefaultVariants across re-runs", () => {
|
|
520
520
|
const base = cv({
|
|
521
521
|
variants: { color: { red: "red", blue: "blue" } },
|
|
522
|
-
|
|
522
|
+
refine: ({ setDefaultVariants }) => {
|
|
523
523
|
setDefaultVariants({ color: "blue" });
|
|
524
524
|
},
|
|
525
525
|
});
|
|
@@ -529,7 +529,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
529
529
|
extend: [base],
|
|
530
530
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
531
531
|
defaultVariants: { size: "sm" },
|
|
532
|
-
|
|
532
|
+
refine: ({ variants, setVariants }) => {
|
|
533
533
|
if (variants.size === "sm") {
|
|
534
534
|
setVariants({ color: "red" });
|
|
535
535
|
}
|
|
@@ -540,10 +540,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
540
540
|
expect(getStyleClass(props)).toEqual({ class: cls("red sm") });
|
|
541
541
|
});
|
|
542
542
|
|
|
543
|
-
test("
|
|
543
|
+
test("refine setVariants sticks across re-runs", () => {
|
|
544
544
|
const base = cv({
|
|
545
545
|
variants: { color: { red: "red", blue: "blue" } },
|
|
546
|
-
|
|
546
|
+
refine: ({ setDefaultVariants }) => {
|
|
547
547
|
setDefaultVariants({ color: "blue" });
|
|
548
548
|
},
|
|
549
549
|
});
|
|
@@ -552,7 +552,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
552
552
|
cv({
|
|
553
553
|
extend: [base],
|
|
554
554
|
variants: { color: { red: "", blue: "" }, done: "" },
|
|
555
|
-
|
|
555
|
+
refine: ({ variants, setVariants }) => {
|
|
556
556
|
if (!variants.done) {
|
|
557
557
|
setVariants({ color: "red", done: true });
|
|
558
558
|
}
|
|
@@ -563,14 +563,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
563
563
|
expect(getStyleClass(props)).toEqual({ class: cls("red") });
|
|
564
564
|
});
|
|
565
565
|
|
|
566
|
-
test("base
|
|
566
|
+
test("base refine setDefaultVariants can override child static defaults after a re-run", () => {
|
|
567
567
|
const base = cv({
|
|
568
568
|
variants: {
|
|
569
569
|
size: { sm: "sm", lg: "lg" },
|
|
570
570
|
active: "",
|
|
571
571
|
mode: { on: "on" },
|
|
572
572
|
},
|
|
573
|
-
|
|
573
|
+
refine: ({ variants, setVariants, setDefaultVariants }) => {
|
|
574
574
|
if (variants.active) {
|
|
575
575
|
setVariants({ mode: "on" });
|
|
576
576
|
}
|
|
@@ -590,13 +590,13 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
590
590
|
test("setVariants from earlier extends overrides setDefaultVariants from later extends", () => {
|
|
591
591
|
const first = cv({
|
|
592
592
|
variants: { color: { red: "first-red", blue: "first-blue" } },
|
|
593
|
-
|
|
593
|
+
refine: ({ setVariants }) => {
|
|
594
594
|
setVariants({ color: "red" });
|
|
595
595
|
},
|
|
596
596
|
});
|
|
597
597
|
const second = cv({
|
|
598
598
|
variants: { color: { red: "second-red", blue: "second-blue" } },
|
|
599
|
-
|
|
599
|
+
refine: ({ setDefaultVariants }) => {
|
|
600
600
|
setDefaultVariants({ color: "blue" });
|
|
601
601
|
},
|
|
602
602
|
});
|
|
@@ -610,13 +610,13 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
610
610
|
test("setDefaultVariants from later extends overrides setDefaultVariants from earlier extends", () => {
|
|
611
611
|
const first = cv({
|
|
612
612
|
variants: { color: { red: "first-red", blue: "first-blue" } },
|
|
613
|
-
|
|
613
|
+
refine: ({ setDefaultVariants }) => {
|
|
614
614
|
setDefaultVariants({ color: "red" });
|
|
615
615
|
},
|
|
616
616
|
});
|
|
617
617
|
const second = cv({
|
|
618
618
|
variants: { color: { red: "second-red", blue: "second-blue" } },
|
|
619
|
-
|
|
619
|
+
refine: ({ setDefaultVariants }) => {
|
|
620
620
|
setDefaultVariants({ color: "blue" });
|
|
621
621
|
},
|
|
622
622
|
});
|
|
@@ -630,7 +630,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
630
630
|
test("setDefaultVariants does not override stable setVariants on later passes", () => {
|
|
631
631
|
const base = cv({
|
|
632
632
|
variants: { color: { red: "base-red", blue: "base-blue" } },
|
|
633
|
-
|
|
633
|
+
refine: ({ setVariants }) => {
|
|
634
634
|
setVariants({ color: "red" });
|
|
635
635
|
},
|
|
636
636
|
});
|
|
@@ -639,7 +639,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
639
639
|
cv({
|
|
640
640
|
extend: [base],
|
|
641
641
|
variants: { color: { red: "child-red", blue: "child-blue" } },
|
|
642
|
-
|
|
642
|
+
refine: ({ variants, setDefaultVariants }) => {
|
|
643
643
|
if (variants.color === "red") {
|
|
644
644
|
setDefaultVariants({ color: "blue" });
|
|
645
645
|
}
|
|
@@ -660,7 +660,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
660
660
|
color: { red: "red", blue: "blue" },
|
|
661
661
|
done: "",
|
|
662
662
|
},
|
|
663
|
-
|
|
663
|
+
refine: ({ variants, setVariants, setDefaultVariants }) => {
|
|
664
664
|
if (!variants.done) {
|
|
665
665
|
setVariants({ color: "red", done: true });
|
|
666
666
|
}
|
|
@@ -674,14 +674,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
674
674
|
expect(getStyleClass(props)).toEqual({ class: cls("red") });
|
|
675
675
|
});
|
|
676
676
|
|
|
677
|
-
test("
|
|
677
|
+
test("refine warns when variants keep changing", () => {
|
|
678
678
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
679
679
|
const component = getModeComponent(
|
|
680
680
|
mode,
|
|
681
681
|
cv({
|
|
682
682
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
683
683
|
defaultVariants: { size: "sm" },
|
|
684
|
-
|
|
684
|
+
refine: ({ variants, setVariants }) => {
|
|
685
685
|
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
686
686
|
},
|
|
687
687
|
}),
|
|
@@ -690,21 +690,19 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
690
690
|
try {
|
|
691
691
|
component();
|
|
692
692
|
expect(warn).toHaveBeenCalledWith(
|
|
693
|
-
expect.stringContaining(
|
|
694
|
-
"Maximum computed update iterations exceeded",
|
|
695
|
-
),
|
|
693
|
+
expect.stringContaining("Maximum refine iterations exceeded"),
|
|
696
694
|
);
|
|
697
695
|
} finally {
|
|
698
696
|
warn.mockRestore();
|
|
699
697
|
}
|
|
700
698
|
});
|
|
701
699
|
|
|
702
|
-
test("
|
|
700
|
+
test("refine warning is shared across extended components", () => {
|
|
703
701
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
704
702
|
const base = cv({
|
|
705
703
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
706
704
|
defaultVariants: { size: "sm" },
|
|
707
|
-
|
|
705
|
+
refine: ({ variants, setVariants }) => {
|
|
708
706
|
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
709
707
|
},
|
|
710
708
|
});
|
|
@@ -714,10 +712,16 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
714
712
|
component();
|
|
715
713
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
716
714
|
expect(warn).toHaveBeenCalledWith(
|
|
717
|
-
expect.stringContaining(
|
|
718
|
-
|
|
715
|
+
expect.stringContaining("Maximum refine iterations exceeded"),
|
|
716
|
+
);
|
|
717
|
+
expect(warn).toHaveBeenCalledWith(
|
|
718
|
+
expect.stringMatching(
|
|
719
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bsize\b/,
|
|
719
720
|
),
|
|
720
721
|
);
|
|
722
|
+
expect(warn).toHaveBeenCalledWith(
|
|
723
|
+
expect.stringContaining("Component created at:"),
|
|
724
|
+
);
|
|
721
725
|
} finally {
|
|
722
726
|
warn.mockRestore();
|
|
723
727
|
}
|
|
@@ -730,7 +734,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
730
734
|
cv({
|
|
731
735
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
732
736
|
defaultVariants: { size: "sm" },
|
|
733
|
-
|
|
737
|
+
refine: ({ variants, setVariants }) => {
|
|
734
738
|
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
735
739
|
},
|
|
736
740
|
}),
|
|
@@ -739,16 +743,22 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
739
743
|
try {
|
|
740
744
|
component.getVariants();
|
|
741
745
|
expect(warn).toHaveBeenCalledWith(
|
|
742
|
-
expect.stringContaining(
|
|
743
|
-
|
|
746
|
+
expect.stringContaining("Maximum refine iterations exceeded"),
|
|
747
|
+
);
|
|
748
|
+
expect(warn).toHaveBeenCalledWith(
|
|
749
|
+
expect.stringMatching(
|
|
750
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bsize\b/,
|
|
744
751
|
),
|
|
745
752
|
);
|
|
753
|
+
expect(warn).toHaveBeenCalledWith(
|
|
754
|
+
expect.stringContaining("Component created at:"),
|
|
755
|
+
);
|
|
746
756
|
} finally {
|
|
747
757
|
warn.mockRestore();
|
|
748
758
|
}
|
|
749
759
|
});
|
|
750
760
|
|
|
751
|
-
test("
|
|
761
|
+
test("refine warning is omitted in production", () => {
|
|
752
762
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
753
763
|
vi.stubEnv("NODE_ENV", "production");
|
|
754
764
|
const component = getModeComponent(
|
|
@@ -756,7 +766,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
756
766
|
cv({
|
|
757
767
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
758
768
|
defaultVariants: { size: "sm" },
|
|
759
|
-
|
|
769
|
+
refine: ({ variants, setVariants }) => {
|
|
760
770
|
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
761
771
|
},
|
|
762
772
|
}),
|
|
@@ -771,7 +781,8 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
771
781
|
}
|
|
772
782
|
});
|
|
773
783
|
|
|
774
|
-
test("
|
|
784
|
+
test("refine warning names the variant key that did not stabilize", () => {
|
|
785
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
775
786
|
const component = getModeComponent(
|
|
776
787
|
mode,
|
|
777
788
|
cv({
|
|
@@ -779,7 +790,139 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
779
790
|
size: { sm: "sm", lg: "lg" },
|
|
780
791
|
color: { red: "red", blue: "blue" },
|
|
781
792
|
},
|
|
782
|
-
|
|
793
|
+
defaultVariants: { size: "sm", color: "red" },
|
|
794
|
+
refine: ({ variants, setVariants }) => {
|
|
795
|
+
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
796
|
+
},
|
|
797
|
+
}),
|
|
798
|
+
);
|
|
799
|
+
|
|
800
|
+
try {
|
|
801
|
+
component();
|
|
802
|
+
expect(warn).toHaveBeenCalledWith(
|
|
803
|
+
expect.stringMatching(
|
|
804
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bsize\b/,
|
|
805
|
+
),
|
|
806
|
+
);
|
|
807
|
+
expect(warn).toHaveBeenCalledWith(
|
|
808
|
+
expect.not.stringMatching(
|
|
809
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bcolor\b/,
|
|
810
|
+
),
|
|
811
|
+
);
|
|
812
|
+
} finally {
|
|
813
|
+
warn.mockRestore();
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
test("refine warning reports keys that oscillate at different cadences", () => {
|
|
818
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
819
|
+
// `size` flips every iteration, `color` flips every other iteration, so
|
|
820
|
+
// the final pair may agree on one of them — the warning must still name
|
|
821
|
+
// both keys because each contributed to a transition.
|
|
822
|
+
const component = getModeComponent(
|
|
823
|
+
mode,
|
|
824
|
+
cv({
|
|
825
|
+
variants: {
|
|
826
|
+
size: { sm: "sm", lg: "lg" },
|
|
827
|
+
color: { red: "red", blue: "blue" },
|
|
828
|
+
},
|
|
829
|
+
defaultVariants: { size: "sm", color: "red" },
|
|
830
|
+
refine: ({ variants, setVariants }) => {
|
|
831
|
+
setVariants({
|
|
832
|
+
size: variants.size === "sm" ? "lg" : "sm",
|
|
833
|
+
color:
|
|
834
|
+
variants.size === "sm"
|
|
835
|
+
? variants.color === "red"
|
|
836
|
+
? "blue"
|
|
837
|
+
: "red"
|
|
838
|
+
: variants.color,
|
|
839
|
+
});
|
|
840
|
+
},
|
|
841
|
+
}),
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
try {
|
|
845
|
+
component();
|
|
846
|
+
expect(warn).toHaveBeenCalledWith(
|
|
847
|
+
expect.stringMatching(
|
|
848
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bsize\b/,
|
|
849
|
+
),
|
|
850
|
+
);
|
|
851
|
+
expect(warn).toHaveBeenCalledWith(
|
|
852
|
+
expect.stringMatching(
|
|
853
|
+
/Variant\(s\) that did not stabilize: [^\n]*\bcolor\b/,
|
|
854
|
+
),
|
|
855
|
+
);
|
|
856
|
+
} finally {
|
|
857
|
+
warn.mockRestore();
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
test("refine warning includes the component creation stack", () => {
|
|
862
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
863
|
+
const component = getModeComponent(
|
|
864
|
+
mode,
|
|
865
|
+
cv({
|
|
866
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
867
|
+
defaultVariants: { size: "sm" },
|
|
868
|
+
refine: ({ variants, setVariants }) => {
|
|
869
|
+
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
870
|
+
},
|
|
871
|
+
}),
|
|
872
|
+
);
|
|
873
|
+
|
|
874
|
+
try {
|
|
875
|
+
component();
|
|
876
|
+
expect(warn).toHaveBeenCalledWith(
|
|
877
|
+
expect.stringContaining("Component created at:"),
|
|
878
|
+
);
|
|
879
|
+
expect(warn).toHaveBeenCalledWith(
|
|
880
|
+
expect.stringContaining("refine.test.ts"),
|
|
881
|
+
);
|
|
882
|
+
} finally {
|
|
883
|
+
warn.mockRestore();
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
test("refine warning omits the creation stack when cv ran in production", () => {
|
|
888
|
+
let captured = "";
|
|
889
|
+
const warn = vi
|
|
890
|
+
.spyOn(console, "warn")
|
|
891
|
+
.mockImplementation((message: unknown) => {
|
|
892
|
+
captured = String(message);
|
|
893
|
+
});
|
|
894
|
+
vi.stubEnv("NODE_ENV", "production");
|
|
895
|
+
const component = getModeComponent(
|
|
896
|
+
mode,
|
|
897
|
+
cv({
|
|
898
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
899
|
+
defaultVariants: { size: "sm" },
|
|
900
|
+
refine: ({ variants, setVariants }) => {
|
|
901
|
+
setVariants({ size: variants.size === "sm" ? "lg" : "sm" });
|
|
902
|
+
},
|
|
903
|
+
}),
|
|
904
|
+
);
|
|
905
|
+
|
|
906
|
+
try {
|
|
907
|
+
vi.unstubAllEnvs();
|
|
908
|
+
component();
|
|
909
|
+
expect(captured).toContain("Maximum refine iterations exceeded");
|
|
910
|
+
expect(captured).not.toContain("Component created at:");
|
|
911
|
+
} finally {
|
|
912
|
+
vi.unstubAllEnvs();
|
|
913
|
+
warn.mockRestore();
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
test("refine setDefaultVariants when explicitly passing undefined", () => {
|
|
918
|
+
const component = getModeComponent(
|
|
919
|
+
mode,
|
|
920
|
+
cv({
|
|
921
|
+
variants: {
|
|
922
|
+
size: { sm: "sm", lg: "lg" },
|
|
923
|
+
color: { red: "red", blue: "blue" },
|
|
924
|
+
},
|
|
925
|
+
refine: ({ setDefaultVariants }) => {
|
|
783
926
|
setDefaultVariants({ color: "red" });
|
|
784
927
|
},
|
|
785
928
|
}),
|
|
@@ -788,7 +931,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
788
931
|
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
789
932
|
});
|
|
790
933
|
|
|
791
|
-
test("
|
|
934
|
+
test("refine with defaultVariants", () => {
|
|
792
935
|
const component = getModeComponent(
|
|
793
936
|
mode,
|
|
794
937
|
cv({
|
|
@@ -797,15 +940,15 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
797
940
|
color: { red: "red", blue: "blue" },
|
|
798
941
|
},
|
|
799
942
|
defaultVariants: { size: "lg" },
|
|
800
|
-
|
|
801
|
-
variants.size === "lg" ? "
|
|
943
|
+
refine: ({ variants }) =>
|
|
944
|
+
variants.size === "lg" ? "refine-lg" : null,
|
|
802
945
|
}),
|
|
803
946
|
);
|
|
804
947
|
const props = component();
|
|
805
|
-
expect(getStyleClass(props)).toEqual({ class: cls("lg
|
|
948
|
+
expect(getStyleClass(props)).toEqual({ class: cls("lg refine-lg") });
|
|
806
949
|
});
|
|
807
950
|
|
|
808
|
-
test("
|
|
951
|
+
test("refine with defaultVariants from extended", () => {
|
|
809
952
|
const base = cv({
|
|
810
953
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
811
954
|
defaultVariants: { size: "lg" },
|
|
@@ -814,22 +957,22 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
814
957
|
mode,
|
|
815
958
|
cv({
|
|
816
959
|
extend: [base],
|
|
817
|
-
|
|
818
|
-
variants.size === "lg" ? "
|
|
960
|
+
refine: ({ variants }) =>
|
|
961
|
+
variants.size === "lg" ? "refine-lg" : null,
|
|
819
962
|
}),
|
|
820
963
|
);
|
|
821
964
|
const props = component();
|
|
822
|
-
expect(getStyleClass(props)).toEqual({ class: cls("lg
|
|
965
|
+
expect(getStyleClass(props)).toEqual({ class: cls("lg refine-lg") });
|
|
823
966
|
});
|
|
824
967
|
|
|
825
|
-
test("
|
|
968
|
+
test("refine from parent receives boolean default value from overridden variant in child", () => {
|
|
826
969
|
const base = cv({
|
|
827
970
|
variants: {
|
|
828
971
|
size: { sm: "sm", lg: "lg" },
|
|
829
972
|
border: { default: "default", true: "border", false: "" },
|
|
830
973
|
},
|
|
831
974
|
defaultVariants: { size: "lg" },
|
|
832
|
-
|
|
975
|
+
refine: ({ variants, setVariants }) => {
|
|
833
976
|
expect(variants.border).toBe(false);
|
|
834
977
|
if (!variants.border) {
|
|
835
978
|
setVariants({ size: "sm" });
|
|
@@ -840,7 +983,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
840
983
|
mode,
|
|
841
984
|
cv({
|
|
842
985
|
extend: [base],
|
|
843
|
-
|
|
986
|
+
variants: {
|
|
844
987
|
border: (_: boolean) => {},
|
|
845
988
|
},
|
|
846
989
|
defaultVariants: { border: false },
|
|
@@ -850,14 +993,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
850
993
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
851
994
|
});
|
|
852
995
|
|
|
853
|
-
test("
|
|
996
|
+
test("refine from parent receives boolean default value from overridden variant in grandchild", () => {
|
|
854
997
|
const base = cv({
|
|
855
998
|
variants: {
|
|
856
999
|
size: { sm: "sm", lg: "lg" },
|
|
857
1000
|
border: { default: "default", true: "border", false: "" },
|
|
858
1001
|
},
|
|
859
1002
|
defaultVariants: { size: "lg" },
|
|
860
|
-
|
|
1003
|
+
refine: ({ variants, setVariants }) => {
|
|
861
1004
|
expect(variants.border).toBe(false);
|
|
862
1005
|
if (!variants.border) {
|
|
863
1006
|
setVariants({ size: "sm" });
|
|
@@ -869,7 +1012,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
869
1012
|
mode,
|
|
870
1013
|
cv({
|
|
871
1014
|
extend: [base2],
|
|
872
|
-
|
|
1015
|
+
variants: {
|
|
873
1016
|
border: (_: boolean) => {},
|
|
874
1017
|
},
|
|
875
1018
|
defaultVariants: { border: false },
|
|
@@ -879,14 +1022,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
879
1022
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
880
1023
|
});
|
|
881
1024
|
|
|
882
|
-
test("
|
|
1025
|
+
test("refine from parent receives false prop from overridden variant in child", () => {
|
|
883
1026
|
const base = cv({
|
|
884
1027
|
variants: {
|
|
885
1028
|
size: { sm: "sm", lg: "lg" },
|
|
886
1029
|
border: { default: "default", true: "border", false: "" },
|
|
887
1030
|
},
|
|
888
1031
|
defaultVariants: { size: "lg" },
|
|
889
|
-
|
|
1032
|
+
refine: ({ variants, setVariants }) => {
|
|
890
1033
|
expect(variants.border).toBe(false);
|
|
891
1034
|
if (!variants.border) {
|
|
892
1035
|
setVariants({ size: "sm" });
|
|
@@ -897,7 +1040,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
897
1040
|
mode,
|
|
898
1041
|
cv({
|
|
899
1042
|
extend: [base],
|
|
900
|
-
|
|
1043
|
+
variants: {
|
|
901
1044
|
border: (_: boolean) => {},
|
|
902
1045
|
},
|
|
903
1046
|
}),
|
|
@@ -906,14 +1049,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
906
1049
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
907
1050
|
});
|
|
908
1051
|
|
|
909
|
-
test("
|
|
1052
|
+
test("refine from parent receives true prop from overridden variant in child", () => {
|
|
910
1053
|
const base = cv({
|
|
911
1054
|
variants: {
|
|
912
1055
|
size: { sm: "sm", lg: "lg" },
|
|
913
1056
|
border: { default: "default", true: "border", false: "" },
|
|
914
1057
|
},
|
|
915
1058
|
defaultVariants: { size: "lg" },
|
|
916
|
-
|
|
1059
|
+
refine: ({ variants, setVariants }) => {
|
|
917
1060
|
expect(variants.border).toBe(true);
|
|
918
1061
|
if (variants.border) {
|
|
919
1062
|
setVariants({ size: "sm" });
|
|
@@ -924,7 +1067,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
924
1067
|
mode,
|
|
925
1068
|
cv({
|
|
926
1069
|
extend: [base],
|
|
927
|
-
|
|
1070
|
+
variants: {
|
|
928
1071
|
border: (_: boolean) => {},
|
|
929
1072
|
},
|
|
930
1073
|
}),
|
|
@@ -933,14 +1076,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
933
1076
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
934
1077
|
});
|
|
935
1078
|
|
|
936
|
-
test("
|
|
1079
|
+
test("refine from parent receives true prop from overridden variant in grandchild", () => {
|
|
937
1080
|
const base = cv({
|
|
938
1081
|
variants: {
|
|
939
1082
|
size: { sm: "sm", lg: "lg" },
|
|
940
1083
|
border: { default: "default", true: "border", false: "" },
|
|
941
1084
|
},
|
|
942
1085
|
defaultVariants: { size: "lg" },
|
|
943
|
-
|
|
1086
|
+
refine: ({ variants, setVariants }) => {
|
|
944
1087
|
expect(variants.border).toBe(true);
|
|
945
1088
|
if (variants.border) {
|
|
946
1089
|
setVariants({ size: "sm" });
|
|
@@ -952,7 +1095,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
952
1095
|
mode,
|
|
953
1096
|
cv({
|
|
954
1097
|
extend: [base2],
|
|
955
|
-
|
|
1098
|
+
variants: {
|
|
956
1099
|
border: (_: boolean) => {},
|
|
957
1100
|
},
|
|
958
1101
|
}),
|
|
@@ -961,12 +1104,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
961
1104
|
expect(getStyleClass(props)).toEqual({ class: cls("sm") });
|
|
962
1105
|
});
|
|
963
1106
|
|
|
964
|
-
test("
|
|
1107
|
+
test("refine with style", () => {
|
|
965
1108
|
const component = getModeComponent(
|
|
966
1109
|
mode,
|
|
967
1110
|
cv({
|
|
968
1111
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
969
|
-
|
|
1112
|
+
refine: ({ variants }) =>
|
|
970
1113
|
variants.size === "lg" ? { style: { fontSize: "20px" } } : null,
|
|
971
1114
|
}),
|
|
972
1115
|
);
|
|
@@ -977,34 +1120,34 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
977
1120
|
});
|
|
978
1121
|
});
|
|
979
1122
|
|
|
980
|
-
test("
|
|
1123
|
+
test("refine with class and style", () => {
|
|
981
1124
|
const component = getModeComponent(
|
|
982
1125
|
mode,
|
|
983
1126
|
cv({
|
|
984
1127
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
985
|
-
|
|
1128
|
+
refine: ({ variants }) =>
|
|
986
1129
|
variants.size === "lg"
|
|
987
|
-
? { class: "
|
|
1130
|
+
? { class: "refine-lg", style: { fontSize: "20px" } }
|
|
988
1131
|
: null,
|
|
989
1132
|
}),
|
|
990
1133
|
);
|
|
991
1134
|
const props = component({ size: "lg" });
|
|
992
1135
|
expect(getStyleClass(props)).toEqual({
|
|
993
|
-
class: cls("lg
|
|
1136
|
+
class: cls("lg refine-lg"),
|
|
994
1137
|
fontSize: "20px",
|
|
995
1138
|
});
|
|
996
1139
|
});
|
|
997
1140
|
|
|
998
|
-
test("
|
|
1141
|
+
test("refine style does not accept numbers", () => {
|
|
999
1142
|
const component = getModeComponent(
|
|
1000
1143
|
mode,
|
|
1001
1144
|
cv({
|
|
1002
1145
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1003
1146
|
// @ts-expect-error
|
|
1004
|
-
|
|
1147
|
+
refine: ({ variants }) =>
|
|
1005
1148
|
variants.size === "lg"
|
|
1006
1149
|
? {
|
|
1007
|
-
class: "
|
|
1150
|
+
class: "refine-lg",
|
|
1008
1151
|
style: { fontSize: 20 },
|
|
1009
1152
|
}
|
|
1010
1153
|
: null,
|
|
@@ -1012,17 +1155,17 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1012
1155
|
);
|
|
1013
1156
|
const props = component({ size: "lg" });
|
|
1014
1157
|
expect(getStyleClass(props)).toEqual({
|
|
1015
|
-
class: cls("lg
|
|
1158
|
+
class: cls("lg refine-lg"),
|
|
1016
1159
|
fontSize: expect.toBeOneOf(["20", "20px"]),
|
|
1017
1160
|
});
|
|
1018
1161
|
});
|
|
1019
1162
|
|
|
1020
|
-
test("
|
|
1163
|
+
test("refine setVariants does not accept invalid keys", () => {
|
|
1021
1164
|
const component = getModeComponent(
|
|
1022
1165
|
mode,
|
|
1023
1166
|
cv({
|
|
1024
1167
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1025
|
-
|
|
1168
|
+
refine: ({ setVariants }) => {
|
|
1026
1169
|
setVariants({
|
|
1027
1170
|
// @ts-expect-error
|
|
1028
1171
|
invalidKey: "value",
|
|
@@ -1034,12 +1177,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1034
1177
|
expect(getStyleClass(props)).toEqual({ class: cls("lg") });
|
|
1035
1178
|
});
|
|
1036
1179
|
|
|
1037
|
-
test("
|
|
1180
|
+
test("refine setVariants does not accept invalid values", () => {
|
|
1038
1181
|
const component = getModeComponent(
|
|
1039
1182
|
mode,
|
|
1040
1183
|
cv({
|
|
1041
1184
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1042
|
-
|
|
1185
|
+
refine: ({ setVariants }) => {
|
|
1043
1186
|
setVariants({
|
|
1044
1187
|
// @ts-expect-error invalid value
|
|
1045
1188
|
size:
|
|
@@ -1054,12 +1197,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1054
1197
|
expect(getStyleClass(props)).toEqual({ class: "" });
|
|
1055
1198
|
});
|
|
1056
1199
|
|
|
1057
|
-
test("
|
|
1200
|
+
test("refine addClass with string", () => {
|
|
1058
1201
|
const component = getModeComponent(
|
|
1059
1202
|
mode,
|
|
1060
1203
|
cv({
|
|
1061
1204
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1062
|
-
|
|
1205
|
+
refine: ({ variants, addClass }) => {
|
|
1063
1206
|
if (variants.size === "lg") {
|
|
1064
1207
|
addClass("added-lg");
|
|
1065
1208
|
}
|
|
@@ -1070,12 +1213,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1070
1213
|
expect(getStyleClass(props)).toEqual({ class: cls("lg added-lg") });
|
|
1071
1214
|
});
|
|
1072
1215
|
|
|
1073
|
-
test("
|
|
1216
|
+
test("refine addClass with array", () => {
|
|
1074
1217
|
const component = getModeComponent(
|
|
1075
1218
|
mode,
|
|
1076
1219
|
cv({
|
|
1077
1220
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1078
|
-
|
|
1221
|
+
refine: ({ variants, addClass }) => {
|
|
1079
1222
|
if (variants.size === "lg") {
|
|
1080
1223
|
addClass(["added-lg", "extra-class"]);
|
|
1081
1224
|
}
|
|
@@ -1088,12 +1231,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1088
1231
|
});
|
|
1089
1232
|
});
|
|
1090
1233
|
|
|
1091
|
-
test("
|
|
1234
|
+
test("refine addStyle", () => {
|
|
1092
1235
|
const component = getModeComponent(
|
|
1093
1236
|
mode,
|
|
1094
1237
|
cv({
|
|
1095
1238
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1096
|
-
|
|
1239
|
+
refine: ({ variants, addStyle }) => {
|
|
1097
1240
|
if (variants.size === "lg") {
|
|
1098
1241
|
addStyle({ fontSize: "20px" });
|
|
1099
1242
|
}
|
|
@@ -1107,12 +1250,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1107
1250
|
});
|
|
1108
1251
|
});
|
|
1109
1252
|
|
|
1110
|
-
test("
|
|
1253
|
+
test("refine addClass combined with return value", () => {
|
|
1111
1254
|
const component = getModeComponent(
|
|
1112
1255
|
mode,
|
|
1113
1256
|
cv({
|
|
1114
1257
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1115
|
-
|
|
1258
|
+
refine: ({ variants, addClass }) => {
|
|
1116
1259
|
if (variants.size === "lg") {
|
|
1117
1260
|
addClass("added-class");
|
|
1118
1261
|
}
|
|
@@ -1126,12 +1269,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1126
1269
|
});
|
|
1127
1270
|
});
|
|
1128
1271
|
|
|
1129
|
-
test("
|
|
1272
|
+
test("refine addStyle combined with return value", () => {
|
|
1130
1273
|
const component = getModeComponent(
|
|
1131
1274
|
mode,
|
|
1132
1275
|
cv({
|
|
1133
1276
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1134
|
-
|
|
1277
|
+
refine: ({ variants, addStyle }) => {
|
|
1135
1278
|
if (variants.size === "lg") {
|
|
1136
1279
|
addStyle({ fontSize: "20px" });
|
|
1137
1280
|
}
|
|
@@ -1147,12 +1290,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1147
1290
|
});
|
|
1148
1291
|
});
|
|
1149
1292
|
|
|
1150
|
-
test("
|
|
1293
|
+
test("refine addClass and addStyle together", () => {
|
|
1151
1294
|
const component = getModeComponent(
|
|
1152
1295
|
mode,
|
|
1153
1296
|
cv({
|
|
1154
1297
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1155
|
-
|
|
1298
|
+
refine: ({ variants, addClass, addStyle }) => {
|
|
1156
1299
|
if (variants.size === "lg") {
|
|
1157
1300
|
addClass("added-lg");
|
|
1158
1301
|
addStyle({ fontSize: "20px" });
|
|
@@ -1167,12 +1310,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1167
1310
|
});
|
|
1168
1311
|
});
|
|
1169
1312
|
|
|
1170
|
-
test("
|
|
1313
|
+
test("refine addClass and addStyle with return value", () => {
|
|
1171
1314
|
const component = getModeComponent(
|
|
1172
1315
|
mode,
|
|
1173
1316
|
cv({
|
|
1174
1317
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1175
|
-
|
|
1318
|
+
refine: ({ variants, addClass, addStyle }) => {
|
|
1176
1319
|
if (variants.size === "lg") {
|
|
1177
1320
|
addClass("added-lg");
|
|
1178
1321
|
addStyle({ fontSize: "20px" });
|
|
@@ -1192,12 +1335,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1192
1335
|
});
|
|
1193
1336
|
});
|
|
1194
1337
|
|
|
1195
|
-
test("
|
|
1338
|
+
test("refine addClass multiple calls", () => {
|
|
1196
1339
|
const component = getModeComponent(
|
|
1197
1340
|
mode,
|
|
1198
1341
|
cv({
|
|
1199
1342
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1200
|
-
|
|
1343
|
+
refine: ({ variants, addClass }) => {
|
|
1201
1344
|
if (variants.size === "lg") {
|
|
1202
1345
|
addClass("first");
|
|
1203
1346
|
addClass("second");
|
|
@@ -1212,12 +1355,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1212
1355
|
});
|
|
1213
1356
|
});
|
|
1214
1357
|
|
|
1215
|
-
test("
|
|
1358
|
+
test("refine addStyle multiple calls merges styles", () => {
|
|
1216
1359
|
const component = getModeComponent(
|
|
1217
1360
|
mode,
|
|
1218
1361
|
cv({
|
|
1219
1362
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1220
|
-
|
|
1363
|
+
refine: ({ variants, addStyle }) => {
|
|
1221
1364
|
if (variants.size === "lg") {
|
|
1222
1365
|
addStyle({ fontSize: "20px" });
|
|
1223
1366
|
addStyle({ backgroundColor: "red" });
|
|
@@ -1235,12 +1378,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1235
1378
|
});
|
|
1236
1379
|
});
|
|
1237
1380
|
|
|
1238
|
-
test("
|
|
1381
|
+
test("refine addStyle later call overrides earlier", () => {
|
|
1239
1382
|
const component = getModeComponent(
|
|
1240
1383
|
mode,
|
|
1241
1384
|
cv({
|
|
1242
1385
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1243
|
-
|
|
1386
|
+
refine: ({ variants, addStyle }) => {
|
|
1244
1387
|
if (variants.size === "lg") {
|
|
1245
1388
|
addStyle({ fontSize: "16px" });
|
|
1246
1389
|
addStyle({ fontSize: "20px" });
|
|
@@ -1255,12 +1398,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1255
1398
|
});
|
|
1256
1399
|
});
|
|
1257
1400
|
|
|
1258
|
-
test("
|
|
1401
|
+
test("refine addStyle does not accept numbers", () => {
|
|
1259
1402
|
const component = getModeComponent(
|
|
1260
1403
|
mode,
|
|
1261
1404
|
cv({
|
|
1262
1405
|
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1263
|
-
|
|
1406
|
+
refine: ({ variants, addStyle }) => {
|
|
1264
1407
|
if (variants.size === "lg") {
|
|
1265
1408
|
addStyle({
|
|
1266
1409
|
// @ts-expect-error
|