clava 0.0.2 → 0.1.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 +12 -0
- package/dist/index.d.ts +28 -19
- package/dist/index.js +24 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +39 -45
- package/src/test-react.ts +40 -0
- package/src/test-solid.ts +36 -0
- package/src/test.ts +141 -41
- package/src/types.ts +43 -285
- package/src/utils.ts +0 -1
package/src/test.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, test } from "vitest";
|
|
2
|
-
|
|
3
2
|
import type {
|
|
4
3
|
AnyComponent,
|
|
5
4
|
ComponentResult,
|
|
@@ -11,8 +10,12 @@ import type {
|
|
|
11
10
|
Component,
|
|
12
11
|
StyleProperty,
|
|
13
12
|
} from "./types.ts";
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import {
|
|
14
|
+
cv as cvBase,
|
|
15
|
+
create,
|
|
16
|
+
splitProps,
|
|
17
|
+
type VariantProps,
|
|
18
|
+
} from "./index.ts";
|
|
16
19
|
import {
|
|
17
20
|
htmlObjStyleToStyleValue,
|
|
18
21
|
htmlStyleToStyleValue,
|
|
@@ -83,17 +86,19 @@ function getConfigDescription(config: Config) {
|
|
|
83
86
|
return "custom";
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
function createCVFromConfig<T extends Config>(
|
|
89
|
+
function createCVFromConfig<T extends Config>(
|
|
90
|
+
config: T,
|
|
91
|
+
): T["defaultMode"] & T["transformClass"] extends never
|
|
92
|
+
? typeof cvBase
|
|
93
|
+
: ReturnType<typeof create>["cv"] {
|
|
87
94
|
const defaultMode = getConfigDefaultMode(config);
|
|
88
95
|
const transformClass = getConfigTransformClass(config);
|
|
89
96
|
const hasTransform = "transformClass" in config && config.transformClass;
|
|
90
97
|
if (!defaultMode && !hasTransform) {
|
|
91
98
|
return cvBase;
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
transformClass,
|
|
96
|
-
}).cv;
|
|
100
|
+
const { cv } = create({ defaultMode: defaultMode ?? "jsx", transformClass });
|
|
101
|
+
return cv as any;
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
function getModalComponent<
|
|
@@ -1033,6 +1038,63 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1033
1038
|
expect(getStyleClass(props)).toEqual({ class: cls("lg blue") });
|
|
1034
1039
|
});
|
|
1035
1040
|
|
|
1041
|
+
test("computed setDefaultVariants overrides defaultVariants", () => {
|
|
1042
|
+
const component = getModalComponent(
|
|
1043
|
+
mode,
|
|
1044
|
+
cv({
|
|
1045
|
+
variants: {
|
|
1046
|
+
size: { sm: "sm", lg: "lg" },
|
|
1047
|
+
color: { red: "red", blue: "blue" },
|
|
1048
|
+
},
|
|
1049
|
+
defaultVariants: { size: "sm", color: "red" },
|
|
1050
|
+
computed: ({ setDefaultVariants }) => {
|
|
1051
|
+
setDefaultVariants({ color: "blue" });
|
|
1052
|
+
},
|
|
1053
|
+
}),
|
|
1054
|
+
);
|
|
1055
|
+
const props = component();
|
|
1056
|
+
expect(getStyleClass(props)).toEqual({ class: cls("sm blue") });
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
test("computed setDefaultVariants overrides extended defaultVariants", () => {
|
|
1060
|
+
const base = cv({
|
|
1061
|
+
variants: { color: { red: "red", blue: "blue" } },
|
|
1062
|
+
defaultVariants: { color: "red" },
|
|
1063
|
+
});
|
|
1064
|
+
const component = getModalComponent(
|
|
1065
|
+
mode,
|
|
1066
|
+
cv({
|
|
1067
|
+
extend: [base],
|
|
1068
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1069
|
+
defaultVariants: { size: "sm" },
|
|
1070
|
+
computed: ({ setDefaultVariants }) => {
|
|
1071
|
+
setDefaultVariants({ color: "blue" });
|
|
1072
|
+
},
|
|
1073
|
+
}),
|
|
1074
|
+
);
|
|
1075
|
+
const props = component();
|
|
1076
|
+
expect(getStyleClass(props)).toEqual({ class: cls("blue sm") });
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
test("computed setDefaultVariants overrides child defaultVariants", () => {
|
|
1080
|
+
const base = cv({
|
|
1081
|
+
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1082
|
+
});
|
|
1083
|
+
const component = getModalComponent(
|
|
1084
|
+
mode,
|
|
1085
|
+
cv({
|
|
1086
|
+
extend: [base],
|
|
1087
|
+
variants: { color: { red: "red", blue: "blue" } },
|
|
1088
|
+
defaultVariants: { size: "sm", color: "red" },
|
|
1089
|
+
computed: ({ setDefaultVariants }) => {
|
|
1090
|
+
setDefaultVariants({ size: "lg" });
|
|
1091
|
+
},
|
|
1092
|
+
}),
|
|
1093
|
+
);
|
|
1094
|
+
const props = component();
|
|
1095
|
+
expect(getStyleClass(props)).toEqual({ class: cls("lg red") });
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1036
1098
|
test("computed with defaultVariants", () => {
|
|
1037
1099
|
const component = getModalComponent(
|
|
1038
1100
|
mode,
|
|
@@ -1299,7 +1361,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1299
1361
|
style: { color: "red" },
|
|
1300
1362
|
[classNameProp]: "extra",
|
|
1301
1363
|
};
|
|
1302
|
-
const [variantProps, otherProps] =
|
|
1364
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1303
1365
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1304
1366
|
Pick<
|
|
1305
1367
|
HTMLProperties<typeof component>,
|
|
@@ -1327,8 +1389,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1327
1389
|
style: "color: red;",
|
|
1328
1390
|
[classNameProp]: "extra",
|
|
1329
1391
|
};
|
|
1330
|
-
const [variantProps, otherProps] =
|
|
1331
|
-
|
|
1392
|
+
const [variantProps, otherProps] = splitProps(
|
|
1393
|
+
props,
|
|
1394
|
+
component.onlyVariants,
|
|
1395
|
+
);
|
|
1332
1396
|
expectTypeOf(variantProps).branded.toEqualTypeOf<{
|
|
1333
1397
|
size?: "sm" | "lg";
|
|
1334
1398
|
}>();
|
|
@@ -1382,7 +1446,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1382
1446
|
id: "test",
|
|
1383
1447
|
size: "lg",
|
|
1384
1448
|
};
|
|
1385
|
-
const [variantProps, otherProps] =
|
|
1449
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1386
1450
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1387
1451
|
Pick<
|
|
1388
1452
|
HTMLProperties<typeof component>,
|
|
@@ -1410,8 +1474,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1410
1474
|
[classNameProp]: "extra",
|
|
1411
1475
|
disabled: true,
|
|
1412
1476
|
};
|
|
1413
|
-
const [variantProps, extraProps, otherProps] =
|
|
1477
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1414
1478
|
props,
|
|
1479
|
+
component,
|
|
1415
1480
|
["disabled"],
|
|
1416
1481
|
);
|
|
1417
1482
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
@@ -1451,8 +1516,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1451
1516
|
color: "blue",
|
|
1452
1517
|
[classNameProp]: "extra",
|
|
1453
1518
|
};
|
|
1454
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1519
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1455
1520
|
props,
|
|
1521
|
+
component1,
|
|
1456
1522
|
component2,
|
|
1457
1523
|
);
|
|
1458
1524
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1496,8 +1562,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1496
1562
|
id: "test",
|
|
1497
1563
|
size: "lg",
|
|
1498
1564
|
};
|
|
1499
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1565
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1500
1566
|
props,
|
|
1567
|
+
component1,
|
|
1501
1568
|
component2,
|
|
1502
1569
|
);
|
|
1503
1570
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1523,8 +1590,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1523
1590
|
style: { backgroundColor: "yellow" },
|
|
1524
1591
|
[classNameProp]: "extra",
|
|
1525
1592
|
};
|
|
1526
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1593
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1527
1594
|
props,
|
|
1595
|
+
component1,
|
|
1528
1596
|
component2.onlyVariants,
|
|
1529
1597
|
);
|
|
1530
1598
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1562,8 +1630,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1562
1630
|
color: "blue",
|
|
1563
1631
|
disabled: true,
|
|
1564
1632
|
};
|
|
1565
|
-
const [comp1Props, extraProps, comp2Props, otherProps] =
|
|
1566
|
-
|
|
1633
|
+
const [comp1Props, extraProps, comp2Props, otherProps] = splitProps(
|
|
1634
|
+
props,
|
|
1635
|
+
component1,
|
|
1636
|
+
["disabled"],
|
|
1637
|
+
component2.onlyVariants,
|
|
1638
|
+
);
|
|
1567
1639
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1568
1640
|
expect(extraProps).toEqual({ disabled: true });
|
|
1569
1641
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
@@ -1584,8 +1656,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1584
1656
|
id: "test",
|
|
1585
1657
|
size: "lg",
|
|
1586
1658
|
};
|
|
1587
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1659
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1588
1660
|
props,
|
|
1661
|
+
component1,
|
|
1589
1662
|
component2.onlyVariants,
|
|
1590
1663
|
);
|
|
1591
1664
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
@@ -1617,8 +1690,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1617
1690
|
defaultVariants: { color: "red" },
|
|
1618
1691
|
}),
|
|
1619
1692
|
);
|
|
1620
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1693
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1621
1694
|
{ id: "test" },
|
|
1695
|
+
component1,
|
|
1622
1696
|
component2.onlyVariants,
|
|
1623
1697
|
);
|
|
1624
1698
|
// Each gets its own defaults
|
|
@@ -1641,8 +1715,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1641
1715
|
size: "lg",
|
|
1642
1716
|
[classNameProp]: "extra",
|
|
1643
1717
|
};
|
|
1644
|
-
const [variantProps, otherProps] =
|
|
1645
|
-
|
|
1718
|
+
const [variantProps, otherProps] = splitProps(
|
|
1719
|
+
props,
|
|
1720
|
+
component.onlyVariants,
|
|
1721
|
+
);
|
|
1646
1722
|
expect(variantProps).toEqual({
|
|
1647
1723
|
size: "lg",
|
|
1648
1724
|
color: "red",
|
|
@@ -1662,8 +1738,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1662
1738
|
[classNameProp]: "extra",
|
|
1663
1739
|
disabled: true,
|
|
1664
1740
|
};
|
|
1665
|
-
const [variantProps, extraProps, otherProps] =
|
|
1666
|
-
|
|
1741
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1742
|
+
props,
|
|
1743
|
+
component.onlyVariants,
|
|
1744
|
+
["disabled"],
|
|
1745
|
+
);
|
|
1667
1746
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1668
1747
|
expect(extraProps).toEqual({ disabled: true });
|
|
1669
1748
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1692,8 +1771,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1692
1771
|
color: "blue",
|
|
1693
1772
|
[classNameProp]: "extra",
|
|
1694
1773
|
};
|
|
1695
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1696
|
-
|
|
1774
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1775
|
+
props,
|
|
1776
|
+
component1.onlyVariants,
|
|
1777
|
+
component2.onlyVariants,
|
|
1778
|
+
);
|
|
1697
1779
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1698
1780
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
1699
1781
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1711,7 +1793,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1711
1793
|
id: "test",
|
|
1712
1794
|
size: "lg",
|
|
1713
1795
|
};
|
|
1714
|
-
const [variantProps, otherProps] =
|
|
1796
|
+
const [variantProps, otherProps] = splitProps(props, component);
|
|
1715
1797
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1716
1798
|
Pick<
|
|
1717
1799
|
HTMLProperties<typeof component>,
|
|
@@ -1736,8 +1818,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1736
1818
|
[classNameProp]: "extra",
|
|
1737
1819
|
disabled: true,
|
|
1738
1820
|
};
|
|
1739
|
-
const [variantProps, extraProps, otherProps] =
|
|
1821
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1740
1822
|
props,
|
|
1823
|
+
component,
|
|
1741
1824
|
["disabled"],
|
|
1742
1825
|
);
|
|
1743
1826
|
expect(variantProps).toEqual({
|
|
@@ -1769,8 +1852,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1769
1852
|
color: "blue",
|
|
1770
1853
|
[classNameProp]: "extra",
|
|
1771
1854
|
};
|
|
1772
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1855
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1773
1856
|
props,
|
|
1857
|
+
component1,
|
|
1774
1858
|
component2,
|
|
1775
1859
|
);
|
|
1776
1860
|
expect(comp1Props).toEqual({
|
|
@@ -1802,8 +1886,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1802
1886
|
id: "test",
|
|
1803
1887
|
size: "lg",
|
|
1804
1888
|
};
|
|
1805
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1889
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1806
1890
|
props,
|
|
1891
|
+
component1,
|
|
1807
1892
|
component2,
|
|
1808
1893
|
);
|
|
1809
1894
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1830,8 +1915,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1830
1915
|
style: { backgroundColor: "yellow" },
|
|
1831
1916
|
[classNameProp]: "extra",
|
|
1832
1917
|
};
|
|
1833
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1918
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1834
1919
|
props,
|
|
1920
|
+
component1,
|
|
1835
1921
|
component2.onlyVariants,
|
|
1836
1922
|
);
|
|
1837
1923
|
expect(comp1Props).toEqual({
|
|
@@ -1860,8 +1946,12 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1860
1946
|
color: "blue",
|
|
1861
1947
|
disabled: true,
|
|
1862
1948
|
};
|
|
1863
|
-
const [comp1Props, extraProps, comp2Props, otherProps] =
|
|
1864
|
-
|
|
1949
|
+
const [comp1Props, extraProps, comp2Props, otherProps] = splitProps(
|
|
1950
|
+
props,
|
|
1951
|
+
component1,
|
|
1952
|
+
["disabled"],
|
|
1953
|
+
component2.onlyVariants,
|
|
1954
|
+
);
|
|
1865
1955
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1866
1956
|
expect(extraProps).toEqual({ disabled: true });
|
|
1867
1957
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
@@ -1882,8 +1972,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1882
1972
|
id: "test",
|
|
1883
1973
|
size: "lg",
|
|
1884
1974
|
};
|
|
1885
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1975
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1886
1976
|
props,
|
|
1977
|
+
component1,
|
|
1887
1978
|
component2.onlyVariants,
|
|
1888
1979
|
);
|
|
1889
1980
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
@@ -1911,8 +2002,9 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1911
2002
|
HTMLProperties<typeof component2> = {
|
|
1912
2003
|
id: "test",
|
|
1913
2004
|
};
|
|
1914
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
2005
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1915
2006
|
props,
|
|
2007
|
+
component1,
|
|
1916
2008
|
component2.onlyVariants,
|
|
1917
2009
|
);
|
|
1918
2010
|
// Each gets its own defaults
|
|
@@ -1935,8 +2027,10 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1935
2027
|
size: "lg",
|
|
1936
2028
|
[classNameProp]: "extra",
|
|
1937
2029
|
};
|
|
1938
|
-
const [variantProps, otherProps] =
|
|
1939
|
-
|
|
2030
|
+
const [variantProps, otherProps] = splitProps(
|
|
2031
|
+
props,
|
|
2032
|
+
component.onlyVariants,
|
|
2033
|
+
);
|
|
1940
2034
|
expect(variantProps).toEqual({
|
|
1941
2035
|
size: "lg",
|
|
1942
2036
|
color: "red",
|
|
@@ -1956,8 +2050,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1956
2050
|
[classNameProp]: "extra",
|
|
1957
2051
|
disabled: true,
|
|
1958
2052
|
};
|
|
1959
|
-
const [variantProps, extraProps, otherProps] =
|
|
1960
|
-
|
|
2053
|
+
const [variantProps, extraProps, otherProps] = splitProps(
|
|
2054
|
+
props,
|
|
2055
|
+
component.onlyVariants,
|
|
2056
|
+
["disabled"],
|
|
2057
|
+
);
|
|
1961
2058
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1962
2059
|
expect(extraProps).toEqual({ disabled: true });
|
|
1963
2060
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
@@ -1986,8 +2083,11 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1986
2083
|
color: "blue",
|
|
1987
2084
|
[classNameProp]: "extra",
|
|
1988
2085
|
};
|
|
1989
|
-
const [comp1Props, comp2Props, otherProps] =
|
|
1990
|
-
|
|
2086
|
+
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
2087
|
+
props,
|
|
2088
|
+
component1.onlyVariants,
|
|
2089
|
+
component2.onlyVariants,
|
|
2090
|
+
);
|
|
1991
2091
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1992
2092
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
1993
2093
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|