clava 0.1.3 → 0.1.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 +6 -0
- package/dist/index.d.ts +5 -1
- package/package.json +3 -3
- package/src/test.ts +24 -0
- package/src/types.ts +18 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as CSS from "csstype";
|
|
|
5
5
|
type ClassValue = string | number | boolean | null | undefined | void | ClassValue[];
|
|
6
6
|
type JSXCSSProperties = CSS.Properties<string | number>;
|
|
7
7
|
type HTMLCSSProperties = CSS.PropertiesHyphen<string | number>;
|
|
8
|
+
type StyleProperty = JSXCSSProperties | HTMLCSSProperties | string;
|
|
8
9
|
interface JSXProps {
|
|
9
10
|
className: string;
|
|
10
11
|
style: JSXCSSProperties;
|
|
@@ -23,7 +24,10 @@ interface StyleProps {
|
|
|
23
24
|
htmlObj: HTMLObjProps;
|
|
24
25
|
}
|
|
25
26
|
type ComponentResult = JSXProps | HTMLProps | HTMLObjProps;
|
|
26
|
-
type
|
|
27
|
+
type AllComponentResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
|
|
28
|
+
type ComponentResultValue<K$1 extends AllComponentResultKeys> = K$1 extends "style" ? StyleProperty : K$1 extends "className" ? string : K$1 extends "class" ? string : never;
|
|
29
|
+
type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null };
|
|
30
|
+
type ComponentProps<V$1 = {}> = VariantValues<V$1> & NullableComponentResult;
|
|
27
31
|
type GetVariants<V$1> = (variants?: VariantValues<V$1>) => VariantValues<V$1>;
|
|
28
32
|
type KeySourceArray = readonly string[];
|
|
29
33
|
type KeySourceComponent = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clava",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Clava library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"class variance",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"clsx": "^2.
|
|
40
|
-
"csstype": "^3.
|
|
39
|
+
"clsx": "^2.0.0",
|
|
40
|
+
"csstype": "^3.0.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rolldown -c",
|
package/src/test.ts
CHANGED
|
@@ -336,6 +336,18 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
336
336
|
});
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
+
test("merge null class from props", () => {
|
|
340
|
+
const component = getModalComponent(mode, cv({ class: "foo bar" }));
|
|
341
|
+
const props = component({ class: null });
|
|
342
|
+
expect(getStyleClass(props)).toEqual({ class: cls("foo bar") });
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("merge null className from props", () => {
|
|
346
|
+
const component = getModalComponent(mode, cv({ class: "foo bar" }));
|
|
347
|
+
const props = component({ className: null });
|
|
348
|
+
expect(getStyleClass(props)).toEqual({ class: cls("foo bar") });
|
|
349
|
+
});
|
|
350
|
+
|
|
339
351
|
test("empty style", () => {
|
|
340
352
|
const component = getModalComponent(mode, cv({ style: {} }));
|
|
341
353
|
const props = component();
|
|
@@ -439,6 +451,18 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
439
451
|
});
|
|
440
452
|
});
|
|
441
453
|
|
|
454
|
+
test("merge null style from props", () => {
|
|
455
|
+
const component = getModalComponent(
|
|
456
|
+
mode,
|
|
457
|
+
cv({ style: { backgroundColor: "red" } }),
|
|
458
|
+
);
|
|
459
|
+
const props = component({ style: null });
|
|
460
|
+
expect(getStyleClass(props)).toEqual({
|
|
461
|
+
class: "",
|
|
462
|
+
backgroundColor: "red",
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
|
|
442
466
|
test("variant no value empty class", () => {
|
|
443
467
|
const component = getModalComponent(
|
|
444
468
|
mode,
|
package/src/types.ts
CHANGED
|
@@ -40,8 +40,24 @@ export interface StyleProps {
|
|
|
40
40
|
|
|
41
41
|
export type ComponentResult = JSXProps | HTMLProps | HTMLObjProps;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
type AllComponentResultKeys =
|
|
44
|
+
| keyof JSXProps
|
|
45
|
+
| keyof HTMLProps
|
|
46
|
+
| keyof HTMLObjProps;
|
|
47
|
+
|
|
48
|
+
type ComponentResultValue<K extends AllComponentResultKeys> = K extends "style"
|
|
49
|
+
? StyleProperty
|
|
50
|
+
: K extends "className"
|
|
51
|
+
? string
|
|
52
|
+
: K extends "class"
|
|
53
|
+
? string
|
|
54
|
+
: never;
|
|
55
|
+
|
|
56
|
+
export type NullableComponentResult = {
|
|
57
|
+
[K in AllComponentResultKeys]?: ComponentResultValue<K> | null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ComponentProps<V = {}> = VariantValues<V> & NullableComponentResult;
|
|
45
61
|
|
|
46
62
|
export type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
47
63
|
|