clava 0.2.3 → 0.2.4

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # clava
2
2
 
3
+ ## 0.2.4
4
+
5
+ - Fixed [`cv`](https://clava.style/docs/reference/cv) variant props inferred from array class values to use boolean shorthand props.
6
+
3
7
  ## 0.2.3
4
8
 
5
9
  ### Improved runtime performance of `extend` chains and `getVariants` in `cv`
package/dist/index.d.ts CHANGED
@@ -79,7 +79,7 @@ type MergeVariants<V, CV, E extends AnyComponent[]> = NoInfer<CV> & Omit<MergeBa
79
79
  type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
80
80
  type VariantValue = ClassValue | StyleClassValue;
81
81
  type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K }[keyof T];
82
- type ExtractVariantValue<T> = T extends null ? never : T extends ((value: infer V) => any) ? V : T extends Record<string, any> ? StringToBoolean<NonNullKeys<T>> : T extends ClassValue ? boolean : never;
82
+ type ExtractVariantValue<T> = T extends null ? never : T extends ((value: infer V) => any) ? V : T extends readonly unknown[] ? boolean : T extends Record<string, any> ? StringToBoolean<NonNullKeys<T>> : T extends ClassValue ? boolean : never;
83
83
  type VariantValues<V> = { [K in keyof V]?: ExtractVariantValue<V[K]> };
84
84
  type StyleValue = CSS.Properties & {
85
85
  [key: `--${string}`]: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clava",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Clava library",
5
5
  "keywords": [
6
6
  "class variance",
package/src/types.ts CHANGED
@@ -248,11 +248,13 @@ type ExtractVariantValue<T> = T extends null
248
248
  ? never
249
249
  : T extends (value: infer V) => any
250
250
  ? V
251
- : T extends Record<string, any>
252
- ? StringToBoolean<NonNullKeys<T>>
253
- : T extends ClassValue
254
- ? boolean
255
- : never;
251
+ : T extends readonly unknown[]
252
+ ? boolean
253
+ : T extends Record<string, any>
254
+ ? StringToBoolean<NonNullKeys<T>>
255
+ : T extends ClassValue
256
+ ? boolean
257
+ : never;
256
258
 
257
259
  export type VariantValues<V> = {
258
260
  [K in keyof V]?: ExtractVariantValue<V[K]>;
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from "vitest";
1
+ import { describe, expect, expectTypeOf, test } from "vitest";
2
2
  import {
3
3
  CONFIGS,
4
4
  createCVFromConfig,
@@ -211,6 +211,34 @@ for (const config of Object.values(CONFIGS)) {
211
211
  expect(getStyleClass(props)).toEqual({ class: "" });
212
212
  });
213
213
 
214
+ test("array variant shorthand", () => {
215
+ const component = getModeComponent(
216
+ mode,
217
+ cv({
218
+ variants: {
219
+ interactive: ["interactive", "focusable"],
220
+ },
221
+ defaultVariants: { interactive: true },
222
+ }),
223
+ );
224
+ expectTypeOf(component.getVariants()).branded.toEqualTypeOf<{
225
+ interactive?: boolean;
226
+ }>();
227
+ expect(getStyleClass(component())).toEqual({
228
+ class: cls("interactive focusable"),
229
+ });
230
+ expect(getStyleClass(component({ interactive: false }))).toEqual({
231
+ class: "",
232
+ });
233
+ const props = component({
234
+ // @ts-expect-error array shorthand variants are boolean
235
+ interactive:
236
+ // no error
237
+ "interactive",
238
+ });
239
+ expect(getStyleClass(props)).toEqual({ class: "" });
240
+ });
241
+
214
242
  test("variant style does not accept numbers", () => {
215
243
  const component = getModeComponent(
216
244
  mode,