clava 0.7.0 → 0.7.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/CHANGELOG.md +38 -0
- package/README.md +44 -8
- package/dist/index.d.ts +84 -11
- package/dist/index.js +168 -45
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +403 -47
- package/src/types.ts +110 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# clava
|
|
2
2
|
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
### Computed defaults read settled values in extension chains
|
|
6
|
+
|
|
7
|
+
A computed `defaultVariants` entry that returns `defaultValue` in a base recipe no longer hides the value that an extending [`cv`](https://clava.style/docs/reference/cv) recipe computes for the same variant. Other computed defaults and [`refine`](https://clava.style/docs/reference/refine) callbacks in the chain used to read the base value, so a recipe could settle on output that contradicted its own variants. They now read the value that the chain settles on.
|
|
8
|
+
|
|
9
|
+
As a result, some chains now reach the re-run limit and log its warning in development. This happens when computed defaults contradict each other, which used to settle without a warning. It also happens when two computed defaults in one recipe change each other's input on every run, as they already did when the base default was static.
|
|
10
|
+
|
|
11
|
+
### Other updates
|
|
12
|
+
|
|
13
|
+
- Fixed declaration emit errors (TS4023, TS4058, and TS2883) when a project with `declaration: true` exports the [`cv`](https://clava.style/docs/reference/cv) or [`cx`](https://clava.style/docs/reference/cx) that [`create`](https://clava.style/docs/reference/create) returns, [`splitProps`](https://clava.style/docs/reference/split-props), a recipe's `.jsx`, `.html`, `.htmlObj`, `.class`, or `.style` helper, or the result of `.jsx.style()` or `.htmlObj.style()`. The package now exports the [`ModalRecipe`](https://clava.style/docs/reference/modal-recipe), [`RecipeProps`](https://clava.style/docs/reference/recipe-props), [`SplitPropsFunction`](https://clava.style/docs/reference/split-props-function), [`JSXCSSProperties`](https://clava.style/docs/reference/jsx-css-properties), and [`HTMLCSSProperties`](https://clava.style/docs/reference/html-css-properties) types.
|
|
14
|
+
- Fixed [`getVariants`](https://clava.style/docs/reference/getVariants) returning a value that an extended recipe disables with `null` when a computed default or [`refine`](https://clava.style/docs/reference/refine) callback sets that value after the extended recipe runs.
|
|
15
|
+
- Fixed [`getVariants`](https://clava.style/docs/reference/getVariants) returning variants that render doesn't apply when a recipe disables a value and has an extend without callbacks, in a chain with computed defaults or [`refine`](https://clava.style/docs/reference/refine).
|
|
16
|
+
- Fixed [`getVariants`](https://clava.style/docs/reference/getVariants) returning values that an extended recipe disables with `null` when the chain has no computed defaults or [`refine`](https://clava.style/docs/reference/refine).
|
|
17
|
+
- Fixed a type error when calling [`cv`](https://clava.style/docs/reference/cv) inline inside `extend`, such as `cv({ extend: [cv({ variants })] })`.
|
|
18
|
+
- Fixed [`cv`](https://clava.style/docs/reference/cv) dropping a variant or value that a recipe defines again after a recipe it extends disabled it with `null`. The new definition now applies, and [`getVariants`](https://clava.style/docs/reference/getVariants) reports the value.
|
|
19
|
+
- Fixed [`cv`](https://clava.style/docs/reference/cv) types to keep the other values and variants when a recipe in `extend` disables a value or variant that another recipe in `extend` shares.
|
|
20
|
+
|
|
21
|
+
## 0.7.1
|
|
22
|
+
|
|
23
|
+
### Union recipes accept only shared variants
|
|
24
|
+
|
|
25
|
+
[`VariantPropsWithRecipe`](https://clava.style/docs/reference/variant-props-with-recipe) now rejects a variant that only some members of a recipe union define. Before, a component could receive `recipe` as a union and a variant that the selected member does not define. That member then ignored the variant at runtime, and `splitProps` forwarded it to the element.
|
|
26
|
+
|
|
27
|
+
If you pass a union-typed recipe together with a variant that only some members define, narrow the recipe first so the variant belongs to a member that defines it:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
// Error: `disclosure` does not define `$placement`.
|
|
31
|
+
<Disclosure recipe={isNav ? navDisclosure : disclosure} $placement="top" />;
|
|
32
|
+
|
|
33
|
+
// Narrow the recipe before passing the variant.
|
|
34
|
+
const element = isNav ? (
|
|
35
|
+
<Disclosure recipe={navDisclosure} $placement="top" />
|
|
36
|
+
) : (
|
|
37
|
+
<Disclosure recipe={disclosure} />
|
|
38
|
+
);
|
|
39
|
+
```
|
|
40
|
+
|
|
3
41
|
## 0.7.0
|
|
4
42
|
|
|
5
43
|
### Renamed Clava components to recipes
|
package/README.md
CHANGED
|
@@ -326,6 +326,24 @@ const plainButton = cv({
|
|
|
326
326
|
});
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
+
Extends run in order, so a recipe listed before this one in `extend` can still add a class for the removed value.
|
|
330
|
+
|
|
331
|
+
A recipe that extends a disabled variant or value can define it again. The new definition applies, and the disabled definitions from the recipes it extends stay removed:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
const loudIconButton = cv({
|
|
335
|
+
extend: [iconButton],
|
|
336
|
+
variants: {
|
|
337
|
+
intent: {
|
|
338
|
+
brand: "loud-brand",
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
loudIconButton({ intent: "brand" }).class;
|
|
344
|
+
// "button icon-button button-lg loud-brand"
|
|
345
|
+
```
|
|
346
|
+
|
|
329
347
|
You can extend any recipe mode, including `baseButton.jsx`, `baseButton.html`, and `baseButton.htmlObj`.
|
|
330
348
|
|
|
331
349
|
### Constraining Recipe Props
|
|
@@ -333,13 +351,13 @@ You can extend any recipe mode, including `baseButton.jsx`, `baseButton.html`, a
|
|
|
333
351
|
Use `RecipeLike<Base, R>` to accept recipes that supply every base variant with compatible input and output types. A recipe can be defined independently, extend another recipe, or compose mode helpers. The constraint keeps the base variants readable inside a generic component and preserves the selected recipe's variant props, `variantKeys`, and `propKeys`, including the mode-specific key lists.
|
|
334
352
|
|
|
335
353
|
```tsx
|
|
336
|
-
import type { ComponentProps } from "react";
|
|
337
354
|
import {
|
|
338
355
|
type RecipeLike,
|
|
339
356
|
type VariantPropsWithRecipe,
|
|
340
357
|
cv,
|
|
341
358
|
splitProps,
|
|
342
359
|
} from "clava";
|
|
360
|
+
import type { ComponentProps } from "react";
|
|
343
361
|
|
|
344
362
|
const disclosure = cv({ variants: { $open: "open" } });
|
|
345
363
|
|
|
@@ -394,6 +412,18 @@ Inside generic code, the key arrays stay tied to `R`. You can read `recipe.varia
|
|
|
394
412
|
|
|
395
413
|
Existing variants must remain compatible with the base's inputs and resolved values. Adding a new value to an existing variant, disabling a base value, or changing its value type can fail this constraint. These recipes can still be created with `cv`; they cannot be passed where the base variant contract is required.
|
|
396
414
|
|
|
415
|
+
When `R` is a union of recipes, the variant props include only the variants that every member defines. A variant that only some members define is rejected, because the recipe selected at runtime may not process it. The check compares variant names, not their values:
|
|
416
|
+
|
|
417
|
+
```tsx
|
|
418
|
+
declare const recipe: typeof navDisclosure | typeof disclosure;
|
|
419
|
+
|
|
420
|
+
<Disclosure recipe={recipe} $open />;
|
|
421
|
+
// Error: the disclosure member does not define `$placement`.
|
|
422
|
+
<Disclosure recipe={recipe} $placement="top" />;
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
This check applies to the type of `R`. A single recipe type still accepts any object that is structurally compatible with its props, so the helpers do not enforce that the props match the recipe passed at runtime.
|
|
426
|
+
|
|
397
427
|
Compatibility depends on the recipe's shape, not its `extend` list or extra metadata. Each member of a recipe union must supply every base variant. Both the base and selected recipe must be full recipes with `jsx`, `html`, and `htmlObj` helpers, even when the component calls only one mode. A mode helper such as `disclosure.jsx` is rejected, but a recipe that extends a mode helper is accepted.
|
|
398
428
|
|
|
399
429
|
## Refine
|
|
@@ -448,15 +478,17 @@ const input = cv({
|
|
|
448
478
|
|
|
449
479
|
`setVariants()` overrides explicit props. `addClass()` and `addStyle()` append output without changing resolved variant values. `getVariants()` includes values changed by computed `defaultVariants` and `setVariants()`.
|
|
450
480
|
|
|
451
|
-
When a computed default or `refine` callback changes variants, Clava re-runs the refine chain so later reads see the latest values.
|
|
481
|
+
When a computed default or `refine` callback changes variants, Clava re-runs the refine chain so later reads see the latest values. When a computed default changes a variant that another computed default computes later in the same run, only those later computed defaults receive the new value. Other callbacks keep the value from the previous run, so returning `defaultValue` from a base recipe doesn't hide the value that an extending recipe computes. A value that a recipe extending the first computed default's recipe disables is still written to the variants that all callbacks read, so that recipe removes it as before.
|
|
482
|
+
|
|
483
|
+
Re-runs are capped at 50 iterations, after which Clava stops and logs a warning in development. This happens when callbacks keep changing the variants that other callbacks read, such as computed defaults that contradict each other.
|
|
452
484
|
|
|
453
485
|
## Splitting Props
|
|
454
486
|
|
|
455
487
|
Use `splitProps()` to separate variant/style props from DOM or framework props without manually maintaining prop-name lists.
|
|
456
488
|
|
|
457
489
|
```tsx
|
|
458
|
-
import type { ComponentProps } from "react";
|
|
459
490
|
import { type VariantProps, cv, splitProps } from "clava";
|
|
491
|
+
import type { ComponentProps } from "react";
|
|
460
492
|
|
|
461
493
|
const button = cv({
|
|
462
494
|
class: "button",
|
|
@@ -502,8 +534,8 @@ const [dataProps, variantProps, otherProps] = splitProps(
|
|
|
502
534
|
Use `.jsx` for React components because it returns `className` and a camelCase style object.
|
|
503
535
|
|
|
504
536
|
```tsx
|
|
505
|
-
import type { ComponentProps } from "react";
|
|
506
537
|
import { type VariantProps, cv, splitProps } from "clava";
|
|
538
|
+
import type { ComponentProps } from "react";
|
|
507
539
|
|
|
508
540
|
const button = cv({
|
|
509
541
|
class: "button",
|
|
@@ -530,8 +562,8 @@ function Button(props: ButtonProps) {
|
|
|
530
562
|
Use `.htmlObj` for Solid components when you want `class` and hyphenated style object output.
|
|
531
563
|
|
|
532
564
|
```tsx
|
|
533
|
-
import type { ComponentProps } from "solid-js";
|
|
534
565
|
import { type VariantProps, cv, splitProps } from "clava";
|
|
566
|
+
import type { ComponentProps } from "solid-js";
|
|
535
567
|
|
|
536
568
|
const button = cv({
|
|
537
569
|
class: "button",
|
|
@@ -587,8 +619,8 @@ Use `RecipeLike<typeof recipe, R>` to constrain a generic component's recipe pro
|
|
|
587
619
|
Use `VariantProps<typeof recipe>` to add a Clava recipe's variant props to framework component props.
|
|
588
620
|
|
|
589
621
|
```ts
|
|
590
|
-
import type { ComponentProps } from "react";
|
|
591
622
|
import type { VariantProps } from "clava";
|
|
623
|
+
import type { ComponentProps } from "react";
|
|
592
624
|
|
|
593
625
|
interface ButtonProps
|
|
594
626
|
extends ComponentProps<"button">, VariantProps<typeof button> {}
|
|
@@ -629,7 +661,7 @@ const button: Recipe<{ size: { sm: string; lg: string } }> = cv({
|
|
|
629
661
|
});
|
|
630
662
|
```
|
|
631
663
|
|
|
632
|
-
The package also exports `ClassValue`, `StyleValue`, `StyleClassProps`, `StyleClassValue`, `JSXProps`, `HTMLProps`, `HTMLObjProps`, and `CVConfig`.
|
|
664
|
+
The package also exports `ClassValue`, `StyleValue`, `StyleClassProps`, `StyleClassValue`, `JSXProps`, `HTMLProps`, `HTMLObjProps`, `JSXCSSProperties`, `HTMLCSSProperties`, and `CVConfig`.
|
|
633
665
|
|
|
634
666
|
## Comparison
|
|
635
667
|
|
|
@@ -703,9 +735,13 @@ Both groups resolve one fixed prop set on every iteration, so every package with
|
|
|
703
735
|
|
|
704
736
|
`RecipeLike<Base, R>` constrains `R` to a structurally compatible recipe while preserving variant props and key arrays in generic components. See [Constraining Recipe Props](#constraining-recipe-props).
|
|
705
737
|
|
|
738
|
+
`ModalRecipe<V, R>` is the type of `recipe.jsx`, `recipe.html`, and `recipe.htmlObj`, where `V` is the resolved variant map and `R` is the output props.
|
|
739
|
+
|
|
740
|
+
`RecipeProps<V>` is the type of the props that a recipe accepts, where `V` is the resolved variant map.
|
|
741
|
+
|
|
706
742
|
`VariantPropsWithRecipe<Base, R, Name = "recipe">` combines the selected recipe's variant props with a recipe prop. The prop is optional when `R` is assignable to `Base` and required otherwise. `Name` selects the prop name.
|
|
707
743
|
|
|
708
|
-
`splitProps(props, source1, ...sources)` returns one object per source plus a final rest object.
|
|
744
|
+
`splitProps(props, source1, ...sources)` returns one object per source plus a final rest object. `SplitPropsFunction` is its type.
|
|
709
745
|
|
|
710
746
|
`cx(...classes)` joins class values with `clsx` and applies the factory's `transformClass`.
|
|
711
747
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ClassValue as ClassValue$1 } from "clsx";
|
|
2
2
|
import * as CSS from "csstype";
|
|
3
|
-
//#region src/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* A class value accepted by Clava. It supports strings, numbers, booleans,
|
|
6
5
|
* nullish values, and nested arrays.
|
|
@@ -20,7 +19,31 @@ type ClassValue = string | number | boolean | null | undefined | void | ClassVal
|
|
|
20
19
|
interface CustomProperties {
|
|
21
20
|
[key: `--${string}`]: string | number;
|
|
22
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The style object returned by a recipe's `.jsx()` mode. It uses camelCase CSS
|
|
24
|
+
* property names and supports CSS custom properties.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { type JSXCSSProperties, cv } from "clava";
|
|
29
|
+
*
|
|
30
|
+
* const button = cv({ style: { fontSize: "16px" } });
|
|
31
|
+
* const style: JSXCSSProperties = button.jsx.style();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
23
34
|
interface JSXCSSProperties extends CSS.Properties<string | number>, CustomProperties {}
|
|
35
|
+
/**
|
|
36
|
+
* The style object returned by a recipe's `.htmlObj()` mode. It uses hyphenated
|
|
37
|
+
* CSS property names and supports CSS custom properties.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { type HTMLCSSProperties, cv } from "clava";
|
|
42
|
+
*
|
|
43
|
+
* const button = cv({ style: { fontSize: "16px" } });
|
|
44
|
+
* const style: HTMLCSSProperties = button.htmlObj.style();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
24
47
|
interface HTMLCSSProperties extends CSS.PropertiesHyphen<string | number>, CustomProperties {}
|
|
25
48
|
type StyleProperty = JSXCSSProperties | HTMLCSSProperties | CSS.Properties<string | number> | CSS.PropertiesHyphen<string | number> | string;
|
|
26
49
|
/**
|
|
@@ -90,6 +113,19 @@ type RecipeResult = JSXProps | HTMLProps | HTMLObjProps | StyleClassProps;
|
|
|
90
113
|
type AllRecipeResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
|
|
91
114
|
type RecipeResultValue<K extends AllRecipeResultKeys> = K extends "style" ? StyleProperty : K extends "className" ? string : K extends "class" ? string : never;
|
|
92
115
|
type NullableRecipeResult = { [K in AllRecipeResultKeys]?: RecipeResultValue<K> | null; };
|
|
116
|
+
/**
|
|
117
|
+
* The props that a recipe accepts for the variant map `V`: its variant values
|
|
118
|
+
* plus `class`, `className`, and `style`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import type { RecipeProps } from "clava";
|
|
123
|
+
*
|
|
124
|
+
* type Variants = { size: { sm: string; lg: string } };
|
|
125
|
+
*
|
|
126
|
+
* const props: RecipeProps<Variants> = { size: "sm", class: "button" };
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
93
129
|
type RecipeProps<V = {}> = VariantValues<V> & NullableRecipeResult;
|
|
94
130
|
type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
95
131
|
type RecipePropKey<R extends RecipeResult> = keyof R | (R extends StyleClassProps ? "className" : never);
|
|
@@ -115,8 +151,36 @@ type SourceDefaults<S> = S extends {
|
|
|
115
151
|
type SourceResultWithStyling<T, S> = Pick<T, Extract<keyof T, SourceKeys<S>>> & Omit<SourceDefaults<S>, keyof T>;
|
|
116
152
|
type SourceResultWithoutStyling<T, S> = IsRecipe<S> extends true ? Pick<T, Extract<keyof T, SourceVariantKeys<S>>> & Omit<SourceDefaults<S>, keyof T> : Pick<T, Extract<keyof T, SourceKeys<S>>>;
|
|
117
153
|
type BuildSourceResults<T, Sources extends readonly KeySource[], StylingClaimed extends boolean, UsedKeys> = Sources extends readonly [infer Current extends KeySource, ...infer Rest extends readonly KeySource[]] ? [StylingClaimed extends true ? SourceResultWithoutStyling<T, Current> : SourceResultWithStyling<T, Current>, ...BuildSourceResults<T, Rest, StylingClaimed extends true ? true : IsRecipe<Current>, UsedKeys | SourceKeys<Current>>] : [Omit<T, UsedKeys & (string | number | symbol)>];
|
|
154
|
+
/**
|
|
155
|
+
* The type of `splitProps`. The first key source is required.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { type SplitPropsFunction, splitProps } from "clava";
|
|
160
|
+
*
|
|
161
|
+
* const split: SplitPropsFunction = splitProps;
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
118
164
|
type SplitPropsFunction = <T, const S1 extends KeySource, const Sources extends readonly KeySource[]>(props: T, source1: S1, ...sources: Sources) => SplitPropsFunctionResult<T, S1, Sources>;
|
|
119
165
|
type SplitPropsFunctionResult<T, S1 extends KeySource, Sources extends readonly KeySource[]> = [SourceResultWithStyling<T, S1>, ...BuildSourceResults<T, Sources, IsRecipe<S1>, SourceKeys<S1>>];
|
|
166
|
+
/**
|
|
167
|
+
* A callable Clava recipe with one output mode, such as the `.jsx`, `.html`,
|
|
168
|
+
* and `.htmlObj` helpers of a recipe returned by `cv()`.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { type JSXProps, type ModalRecipe, cv } from "clava";
|
|
173
|
+
*
|
|
174
|
+
* const button = cv({
|
|
175
|
+
* variants: {
|
|
176
|
+
* size: { sm: "button-sm", lg: "button-lg" },
|
|
177
|
+
* },
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* const jsxButton: ModalRecipe<{ size: { sm: string; lg: string } }, JSXProps> =
|
|
181
|
+
* button.jsx;
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
120
184
|
interface ModalRecipe<V, R extends RecipeResult> {
|
|
121
185
|
(props?: RecipeProps<V>): R;
|
|
122
186
|
class: (props?: RecipeProps<V>) => string;
|
|
@@ -150,6 +214,9 @@ interface Recipe<V extends Variants = {}, E extends AnyRecipe[] = [], R extends
|
|
|
150
214
|
htmlObj: ModalRecipe<MergeVariants<V, E>, HTMLObjProps>;
|
|
151
215
|
}
|
|
152
216
|
type AnyRecipe = Recipe<any, any, any> | ModalRecipe<any, any>;
|
|
217
|
+
type InferredRecipe<V extends Variants, E extends AnyRecipe[]> = {
|
|
218
|
+
recipe: Recipe<V, E>;
|
|
219
|
+
}[[V, E] extends [unknown, unknown] ? "recipe" : never];
|
|
153
220
|
type RecipeVariantKeys<T> = T extends {
|
|
154
221
|
variantKeys: (infer Key extends string)[];
|
|
155
222
|
} ? Key : never;
|
|
@@ -184,9 +251,13 @@ type RecipeLike<Base extends Recipe<any, any, any>, Candidate> = [MissingRecipeV
|
|
|
184
251
|
html: RecipeLikeMode<Base["html"], Candidate>;
|
|
185
252
|
htmlObj: RecipeLikeMode<Base["htmlObj"], Candidate>;
|
|
186
253
|
} : never;
|
|
187
|
-
type
|
|
254
|
+
type NormalizeSiblingValue<T> = T extends null ? never : VariantValue;
|
|
255
|
+
type NormalizeSiblingDefinition<T> = T extends null ? never : T extends undefined | ((...args: any[]) => any) | readonly unknown[] ? T : T extends Record<string, any> ? { [K in keyof T]: NormalizeSiblingValue<T[K]>; } : string;
|
|
256
|
+
type NormalizeSiblingVariants<T> = { [K in keyof T]: NormalizeSiblingDefinition<T[K]>; };
|
|
257
|
+
type MergeSiblingVariants<T> = T extends readonly [infer First, ...infer Rest] ? NormalizeSiblingVariants<ExtractVariants<First>> & MergeSiblingVariants<Rest> : {};
|
|
258
|
+
type MergeExtendedVariants<T> = T extends readonly [infer Only] ? ExtractVariants<Only> : MergeSiblingVariants<T>;
|
|
188
259
|
type ExtractVariants<T> = T extends ModalRecipe<infer V, any> ? V : {};
|
|
189
|
-
type MergeVariantDefinition<Child, Parent> = Child extends ((...args: any[]) => any) ? Child : Parent extends ((...args: any[]) => any) ? Child : Child extends Record<string, any> ? Parent extends Record<string, any> ? Omit<Parent, keyof Child> & Child : Child : Child;
|
|
260
|
+
type MergeVariantDefinition<Child, Parent> = Child extends ((...args: any[]) => any) ? Child : [Parent] extends [never] ? Child : Parent extends ((...args: any[]) => any) ? Child : Child extends Record<string, any> ? Parent extends Record<string, any> ? Omit<Parent, keyof Child> & Child : Child : Child;
|
|
190
261
|
type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]>; };
|
|
191
262
|
type MergeVariants<V, E extends AnyRecipe[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedVariants<E>>;
|
|
192
263
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
@@ -244,8 +315,6 @@ type Variant$1 = ClassValue | Record<string, VariantValue> | ((value: any) => Va
|
|
|
244
315
|
type Variants = Record<string, Variant$1>;
|
|
245
316
|
type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null; } : T | null;
|
|
246
317
|
type ExtendableVariants<V extends Variants, E extends AnyRecipe[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1; };
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/index.d.ts
|
|
249
318
|
/**
|
|
250
319
|
* Extracts the variant props inferred for a Clava recipe. Use it to add a
|
|
251
320
|
* recipe's variant props to framework component props.
|
|
@@ -279,6 +348,9 @@ export type VariantProps<T extends Pick<AnyRecipe, "getVariants">> = ReturnType<
|
|
|
279
348
|
* and required when the selected recipe adds variants. Pass a third type
|
|
280
349
|
* argument to use another prop name.
|
|
281
350
|
*
|
|
351
|
+
* When `R` is a union of recipes, the variant props include only the
|
|
352
|
+
* variants that every member defines.
|
|
353
|
+
*
|
|
282
354
|
* When inferring `R`, passing `undefined` or forwarding an optional recipe
|
|
283
355
|
* can fail the recipe constraint. Resolve the optional value before passing
|
|
284
356
|
* it, for example with `recipe: override ?? disclosure`.
|
|
@@ -298,7 +370,9 @@ export type VariantProps<T extends Pick<AnyRecipe, "getVariants">> = ReturnType<
|
|
|
298
370
|
* > = VariantPropsWithRecipe<typeof disclosure, R, "styles">;
|
|
299
371
|
* ```
|
|
300
372
|
*/
|
|
301
|
-
export type VariantPropsWithRecipe<Base extends Recipe<any, any, any>, R extends RecipeLike<Base, R>, Name extends string = "recipe"> = VariantProps<R> & ([R] extends [Base] ? { [Key in Name]?: R; } : { [Key in Name]: R; });
|
|
373
|
+
export type VariantPropsWithRecipe<Base extends Recipe<any, any, any>, R extends RecipeLike<Base, R>, Name extends string = "recipe"> = VariantProps<R> & PartialVariantKeys<R> & ([R] extends [Base] ? { [Key in Name]?: R; } : { [Key in Name]: R; });
|
|
374
|
+
type PartialVariantKeys<R extends Pick<AnyRecipe, "getVariants">, Key extends PropertyKey = Exclude<UnionKeys<VariantProps<R>>, keyof VariantProps<R>>> = [Key] extends [never] ? unknown : { [K in Key]?: never; };
|
|
375
|
+
type UnionKeys<T> = T extends unknown ? keyof T : never;
|
|
302
376
|
type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
|
|
303
377
|
/**
|
|
304
378
|
* Constrains a variant map to the same value keys as a variant on another
|
|
@@ -377,16 +451,15 @@ export declare const splitProps: SplitPropsFunction;
|
|
|
377
451
|
* Creates the cv and cx functions.
|
|
378
452
|
*/
|
|
379
453
|
export declare function create(params?: CreateParams): {
|
|
380
|
-
cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) =>
|
|
381
|
-
cx:
|
|
454
|
+
cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) => InferredRecipe<V, E>;
|
|
455
|
+
cx: typeof cx;
|
|
382
456
|
};
|
|
383
|
-
export declare const cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) =>
|
|
457
|
+
export declare const cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) => InferredRecipe<V, E>;
|
|
384
458
|
/**
|
|
385
459
|
* Joins class values without applying a class transform.
|
|
386
460
|
*
|
|
387
461
|
* This behaves like the `cx` function returned by `create()` with no options.
|
|
388
462
|
*/
|
|
389
463
|
export declare function cx(...classes: ClassValue$1[]): string;
|
|
390
|
-
|
|
391
|
-
export type { ClassValue, HTMLObjProps, HTMLProps, JSXProps, Recipe, RecipeLike, StyleClassProps, StyleClassValue, StyleValue };
|
|
464
|
+
export type { ClassValue, HTMLCSSProperties, HTMLObjProps, HTMLProps, JSXCSSProperties, JSXProps, ModalRecipe, Recipe, RecipeLike, RecipeProps, SplitPropsFunction, StyleClassProps, StyleClassValue, StyleValue };
|
|
392
465
|
//# sourceMappingURL=index.d.ts.map
|