clava 0.1.1 → 0.1.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 +6 -0
- package/dist/index.d.ts +22 -9
- package/dist/index.js +39 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +74 -46
- package/src/test-react.ts +3 -3
- package/src/test-solid.ts +1 -1
- package/src/test.ts +170 -303
- package/src/types.ts +130 -45
- package/src/utils.ts +15 -2
package/src/test.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, test } from "vitest";
|
|
2
2
|
import type {
|
|
3
3
|
AnyComponent,
|
|
4
|
+
Component,
|
|
4
5
|
ComponentResult,
|
|
5
|
-
|
|
6
|
+
ComputedVariants,
|
|
6
7
|
HTMLCSSProperties,
|
|
7
8
|
JSXCSSProperties,
|
|
8
|
-
|
|
9
|
-
ComputedVariants,
|
|
10
|
-
Component,
|
|
9
|
+
StyleClassValue,
|
|
11
10
|
StyleProperty,
|
|
11
|
+
Variants,
|
|
12
12
|
} from "./types.ts";
|
|
13
13
|
import {
|
|
14
|
-
|
|
14
|
+
type VariantProps,
|
|
15
15
|
create,
|
|
16
|
+
cv as cvBase,
|
|
16
17
|
splitProps,
|
|
17
|
-
type VariantProps,
|
|
18
18
|
} from "./index.ts";
|
|
19
19
|
import {
|
|
20
20
|
htmlObjStyleToStyleValue,
|
|
@@ -1363,10 +1363,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1363
1363
|
};
|
|
1364
1364
|
const [variantProps, otherProps] = splitProps(props, component);
|
|
1365
1365
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1366
|
-
Pick<
|
|
1367
|
-
HTMLProperties<typeof component>,
|
|
1368
|
-
"size" | "style" | "class" | "className"
|
|
1369
|
-
>
|
|
1366
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1370
1367
|
>();
|
|
1371
1368
|
expectTypeOf(otherProps).toEqualTypeOf<{ id?: string }>();
|
|
1372
1369
|
expect(variantProps).toEqual({
|
|
@@ -1377,7 +1374,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1377
1374
|
expect(otherProps).toEqual({ id: "test" });
|
|
1378
1375
|
});
|
|
1379
1376
|
|
|
1380
|
-
test("
|
|
1377
|
+
test("variantKeys splitProps", () => {
|
|
1381
1378
|
const component = getModalComponent(
|
|
1382
1379
|
mode,
|
|
1383
1380
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
@@ -1391,16 +1388,13 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1391
1388
|
};
|
|
1392
1389
|
const [variantProps, otherProps] = splitProps(
|
|
1393
1390
|
props,
|
|
1394
|
-
component.
|
|
1391
|
+
component.variantKeys,
|
|
1395
1392
|
);
|
|
1396
1393
|
expectTypeOf(variantProps).branded.toEqualTypeOf<{
|
|
1397
1394
|
size?: "sm" | "lg";
|
|
1398
1395
|
}>();
|
|
1399
1396
|
expectTypeOf(otherProps).toEqualTypeOf<
|
|
1400
|
-
Pick<
|
|
1401
|
-
HTMLProperties<typeof component>,
|
|
1402
|
-
"id" | "style" | "class" | "className"
|
|
1403
|
-
>
|
|
1397
|
+
Pick<typeof props, "id" | "style" | "class" | "className">
|
|
1404
1398
|
>();
|
|
1405
1399
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1406
1400
|
expect(otherProps).toEqual({
|
|
@@ -1410,28 +1404,41 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1410
1404
|
});
|
|
1411
1405
|
});
|
|
1412
1406
|
|
|
1413
|
-
test("
|
|
1407
|
+
test("variantKeys property", () => {
|
|
1414
1408
|
const component = getModalComponent(
|
|
1415
1409
|
mode,
|
|
1416
1410
|
cv({
|
|
1417
|
-
variants: { size: { sm: "sm",
|
|
1418
|
-
defaultVariants: { size: "sm" },
|
|
1411
|
+
variants: { size: { sm: "sm" }, color: { red: "red" } },
|
|
1419
1412
|
}),
|
|
1420
1413
|
);
|
|
1421
|
-
|
|
1422
|
-
expect(
|
|
1414
|
+
expectTypeOf(component.variantKeys).toEqualTypeOf<("size" | "color")[]>();
|
|
1415
|
+
expect(component.variantKeys).toEqual(["size", "color"]);
|
|
1423
1416
|
});
|
|
1424
1417
|
|
|
1425
|
-
test("
|
|
1426
|
-
const component =
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1418
|
+
test("propKeys property", () => {
|
|
1419
|
+
const component = getModalComponent(
|
|
1420
|
+
mode,
|
|
1421
|
+
cv({ variants: { size: { sm: "sm" }, color: { red: "red" } } }),
|
|
1422
|
+
);
|
|
1423
|
+
const classNameProp = getClassPropertyName(config);
|
|
1424
|
+
expectTypeOf(component.propKeys).toExtend<
|
|
1425
|
+
("class" | "className" | "style" | "size" | "color")[]
|
|
1431
1426
|
>();
|
|
1432
|
-
expect(component.
|
|
1433
|
-
|
|
1427
|
+
expect(component.propKeys).toEqual([
|
|
1428
|
+
classNameProp,
|
|
1429
|
+
"style",
|
|
1430
|
+
"size",
|
|
1431
|
+
"color",
|
|
1432
|
+
]);
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
test("propKeys on different modes", () => {
|
|
1436
|
+
const component = getModalComponent(
|
|
1437
|
+
mode,
|
|
1438
|
+
cv({ variants: { size: { sm: "sm" } } }),
|
|
1434
1439
|
);
|
|
1440
|
+
const classNameProp = getClassPropertyName(config);
|
|
1441
|
+
expect(component.propKeys).toEqual([classNameProp, "style", "size"]);
|
|
1435
1442
|
});
|
|
1436
1443
|
|
|
1437
1444
|
test("splitProps includes defaultVariants", () => {
|
|
@@ -1448,10 +1455,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1448
1455
|
};
|
|
1449
1456
|
const [variantProps, otherProps] = splitProps(props, component);
|
|
1450
1457
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1451
|
-
Pick<
|
|
1452
|
-
HTMLProperties<typeof component>,
|
|
1453
|
-
"size" | "color" | "style" | "class" | "className"
|
|
1454
|
-
>
|
|
1458
|
+
Pick<typeof props, "size" | "color" | "style" | "class" | "className">
|
|
1455
1459
|
>();
|
|
1456
1460
|
expect(variantProps).toEqual({
|
|
1457
1461
|
size: "lg",
|
|
@@ -1480,10 +1484,7 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1480
1484
|
["disabled"],
|
|
1481
1485
|
);
|
|
1482
1486
|
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1483
|
-
Pick<
|
|
1484
|
-
HTMLProperties<typeof component>,
|
|
1485
|
-
"size" | "style" | "class" | "className"
|
|
1486
|
-
>
|
|
1487
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1487
1488
|
>();
|
|
1488
1489
|
expect(variantProps).toEqual({
|
|
1489
1490
|
size: "lg",
|
|
@@ -1522,24 +1523,19 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1522
1523
|
component2,
|
|
1523
1524
|
);
|
|
1524
1525
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
1525
|
-
Pick<
|
|
1526
|
-
HTMLProperties<typeof component1>,
|
|
1527
|
-
"size" | "style" | "class" | "className"
|
|
1528
|
-
>
|
|
1526
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1529
1527
|
>();
|
|
1528
|
+
// First component gets class/style props
|
|
1530
1529
|
expect(comp1Props).toEqual({
|
|
1531
1530
|
size: "lg",
|
|
1532
1531
|
[classNameProp]: "extra",
|
|
1533
1532
|
});
|
|
1533
|
+
// Second component only gets variant props (no class/style)
|
|
1534
1534
|
expectTypeOf(comp2Props).branded.toEqualTypeOf<
|
|
1535
|
-
Pick<
|
|
1536
|
-
HTMLProperties<typeof component2>,
|
|
1537
|
-
"color" | "style" | "class" | "className"
|
|
1538
|
-
>
|
|
1535
|
+
Pick<typeof props, "color">
|
|
1539
1536
|
>();
|
|
1540
1537
|
expect(comp2Props).toEqual({
|
|
1541
1538
|
color: "blue",
|
|
1542
|
-
[classNameProp]: "extra",
|
|
1543
1539
|
});
|
|
1544
1540
|
expectTypeOf(otherProps).toEqualTypeOf<{ id?: string }>();
|
|
1545
1541
|
expect(otherProps).toEqual({ id: "test" });
|
|
@@ -1567,12 +1563,15 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1567
1563
|
component1,
|
|
1568
1564
|
component2,
|
|
1569
1565
|
);
|
|
1566
|
+
// First component gets variant props
|
|
1570
1567
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1568
|
+
// Second component only gets its own variant defaults (no class/style
|
|
1569
|
+
// since first claimed them)
|
|
1571
1570
|
expect(comp2Props).toEqual({ color: "red" });
|
|
1572
1571
|
expect(otherProps).toEqual({ id: "test" });
|
|
1573
1572
|
});
|
|
1574
1573
|
|
|
1575
|
-
test("splitProps
|
|
1574
|
+
test("splitProps second component excludes class and style", () => {
|
|
1576
1575
|
const component1 = getModalComponent(
|
|
1577
1576
|
mode,
|
|
1578
1577
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
@@ -1593,19 +1592,18 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1593
1592
|
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1594
1593
|
props,
|
|
1595
1594
|
component1,
|
|
1596
|
-
component2
|
|
1595
|
+
component2,
|
|
1597
1596
|
);
|
|
1598
1597
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
1599
|
-
Pick<
|
|
1600
|
-
HTMLProperties<typeof component1>,
|
|
1601
|
-
"size" | "style" | "class" | "className"
|
|
1602
|
-
>
|
|
1598
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1603
1599
|
>();
|
|
1600
|
+
// First component gets class/style
|
|
1604
1601
|
expect(comp1Props).toEqual({
|
|
1605
1602
|
size: "lg",
|
|
1606
1603
|
style: { backgroundColor: "yellow" },
|
|
1607
1604
|
[classNameProp]: "extra",
|
|
1608
1605
|
});
|
|
1606
|
+
// Second component only gets variant props
|
|
1609
1607
|
expectTypeOf(comp2Props).branded.toEqualTypeOf<{
|
|
1610
1608
|
color?: "red" | "blue";
|
|
1611
1609
|
}>();
|
|
@@ -1634,8 +1632,16 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1634
1632
|
props,
|
|
1635
1633
|
component1,
|
|
1636
1634
|
["disabled"],
|
|
1637
|
-
component2
|
|
1635
|
+
component2,
|
|
1638
1636
|
);
|
|
1637
|
+
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
1638
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1639
|
+
>();
|
|
1640
|
+
expectTypeOf(extraProps).branded.toEqualTypeOf<{ disabled?: boolean }>();
|
|
1641
|
+
expectTypeOf(comp2Props).branded.toEqualTypeOf<{
|
|
1642
|
+
color?: "red" | "blue";
|
|
1643
|
+
}>();
|
|
1644
|
+
expectTypeOf(otherProps).toEqualTypeOf<{ id?: string }>();
|
|
1639
1645
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1640
1646
|
expect(extraProps).toEqual({ disabled: true });
|
|
1641
1647
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
@@ -1659,15 +1665,14 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1659
1665
|
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1660
1666
|
props,
|
|
1661
1667
|
component1,
|
|
1662
|
-
component2
|
|
1668
|
+
component2,
|
|
1663
1669
|
);
|
|
1664
1670
|
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
1665
|
-
Pick<
|
|
1666
|
-
HTMLProperties<typeof component1>,
|
|
1667
|
-
"size" | "style" | "class" | "className"
|
|
1668
|
-
>
|
|
1671
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1669
1672
|
>();
|
|
1673
|
+
// First component gets class/style + size
|
|
1670
1674
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1675
|
+
// Second component only gets variant props (size appears in both)
|
|
1671
1676
|
expectTypeOf(comp2Props).branded.toEqualTypeOf<{
|
|
1672
1677
|
size?: "sm" | "lg";
|
|
1673
1678
|
}>();
|
|
@@ -1693,15 +1698,20 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1693
1698
|
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1694
1699
|
{ id: "test" },
|
|
1695
1700
|
component1,
|
|
1696
|
-
component2
|
|
1701
|
+
component2,
|
|
1697
1702
|
);
|
|
1698
1703
|
// Each gets its own defaults
|
|
1704
|
+
expectTypeOf(comp1Props).branded.toEqualTypeOf<{ size?: "sm" | "lg" }>();
|
|
1699
1705
|
expect(comp1Props).toEqual({ size: "sm" });
|
|
1706
|
+
expectTypeOf(comp2Props).branded.toEqualTypeOf<{
|
|
1707
|
+
color?: "red" | "blue";
|
|
1708
|
+
}>();
|
|
1700
1709
|
expect(comp2Props).toEqual({ color: "red" });
|
|
1710
|
+
expectTypeOf(otherProps).toEqualTypeOf<{ id: string }>();
|
|
1701
1711
|
expect(otherProps).toEqual({ id: "test" });
|
|
1702
1712
|
});
|
|
1703
1713
|
|
|
1704
|
-
test("
|
|
1714
|
+
test("variantKeys splitProps includes defaultVariants", () => {
|
|
1705
1715
|
const component = getModalComponent(
|
|
1706
1716
|
mode,
|
|
1707
1717
|
cv({
|
|
@@ -1717,16 +1727,17 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1717
1727
|
};
|
|
1718
1728
|
const [variantProps, otherProps] = splitProps(
|
|
1719
1729
|
props,
|
|
1720
|
-
component.
|
|
1730
|
+
component.variantKeys,
|
|
1721
1731
|
);
|
|
1732
|
+
// variantKeys is just an array, so no defaults are applied
|
|
1722
1733
|
expect(variantProps).toEqual({
|
|
1723
1734
|
size: "lg",
|
|
1724
|
-
color: "red",
|
|
1725
1735
|
});
|
|
1736
|
+
// color is in variantKeys but not in props, so it's not in either result
|
|
1726
1737
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
1727
1738
|
});
|
|
1728
1739
|
|
|
1729
|
-
test("
|
|
1740
|
+
test("variantKeys splitProps with key array", () => {
|
|
1730
1741
|
const component = getModalComponent(
|
|
1731
1742
|
mode,
|
|
1732
1743
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
@@ -1740,15 +1751,22 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1740
1751
|
};
|
|
1741
1752
|
const [variantProps, extraProps, otherProps] = splitProps(
|
|
1742
1753
|
props,
|
|
1743
|
-
component.
|
|
1754
|
+
component.variantKeys,
|
|
1744
1755
|
["disabled"],
|
|
1745
1756
|
);
|
|
1757
|
+
expectTypeOf(variantProps).branded.toEqualTypeOf<{
|
|
1758
|
+
size?: "sm" | "lg";
|
|
1759
|
+
}>();
|
|
1746
1760
|
expect(variantProps).toEqual({ size: "lg" });
|
|
1761
|
+
expectTypeOf(extraProps).branded.toEqualTypeOf<{ disabled?: boolean }>();
|
|
1747
1762
|
expect(extraProps).toEqual({ disabled: true });
|
|
1763
|
+
expectTypeOf(otherProps).toEqualTypeOf<
|
|
1764
|
+
Pick<typeof props, "id" | "class" | "className" | "style">
|
|
1765
|
+
>();
|
|
1748
1766
|
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
1749
1767
|
});
|
|
1750
1768
|
|
|
1751
|
-
test("
|
|
1769
|
+
test("variantKeys splitProps with component", () => {
|
|
1752
1770
|
const component1 = getModalComponent(
|
|
1753
1771
|
mode,
|
|
1754
1772
|
cv({
|
|
@@ -1773,164 +1791,129 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1773
1791
|
};
|
|
1774
1792
|
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1775
1793
|
props,
|
|
1776
|
-
component1.
|
|
1777
|
-
component2.
|
|
1794
|
+
component1.variantKeys,
|
|
1795
|
+
component2.variantKeys,
|
|
1778
1796
|
);
|
|
1797
|
+
expectTypeOf(comp1Props).branded.toEqualTypeOf<{ size?: "sm" | "lg" }>();
|
|
1779
1798
|
expect(comp1Props).toEqual({ size: "lg" });
|
|
1799
|
+
expectTypeOf(comp2Props).branded.toEqualTypeOf<{
|
|
1800
|
+
color?: "red" | "blue";
|
|
1801
|
+
}>();
|
|
1780
1802
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
test("splitProps includes defaultVariants", () => {
|
|
1785
|
-
const component = getModalComponent(
|
|
1786
|
-
mode,
|
|
1787
|
-
cv({
|
|
1788
|
-
variants: { size: { sm: "sm", lg: "lg" }, color: { red: "red" } },
|
|
1789
|
-
defaultVariants: { size: "sm", color: "red" },
|
|
1790
|
-
}),
|
|
1791
|
-
);
|
|
1792
|
-
const props: HTMLProperties<typeof component> = {
|
|
1793
|
-
id: "test",
|
|
1794
|
-
size: "lg",
|
|
1795
|
-
};
|
|
1796
|
-
const [variantProps, otherProps] = splitProps(props, component);
|
|
1797
|
-
expectTypeOf(variantProps).branded.toEqualTypeOf<
|
|
1798
|
-
Pick<
|
|
1799
|
-
HTMLProperties<typeof component>,
|
|
1800
|
-
"size" | "color" | "style" | "class" | "className"
|
|
1801
|
-
>
|
|
1803
|
+
expectTypeOf(otherProps).toEqualTypeOf<
|
|
1804
|
+
Pick<typeof props, "id" | "class" | "className" | "style">
|
|
1802
1805
|
>();
|
|
1803
|
-
expect(
|
|
1804
|
-
expectTypeOf(otherProps).toEqualTypeOf<{ id?: string }>();
|
|
1805
|
-
expect(otherProps).toEqual({ id: "test" });
|
|
1806
|
+
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
1806
1807
|
});
|
|
1807
1808
|
|
|
1808
|
-
test("splitProps with
|
|
1809
|
+
test("splitProps with array containing class before component", () => {
|
|
1809
1810
|
const component = getModalComponent(
|
|
1810
1811
|
mode,
|
|
1811
1812
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1812
1813
|
);
|
|
1813
1814
|
const classNameProp = getClassPropertyName(config);
|
|
1814
|
-
const props: HTMLProperties<typeof component>
|
|
1815
|
+
const props: HTMLProperties<typeof component> = {
|
|
1815
1816
|
id: "test",
|
|
1816
1817
|
size: "lg",
|
|
1817
|
-
style: {
|
|
1818
|
+
style: { backgroundColor: "yellow" },
|
|
1818
1819
|
[classNameProp]: "extra",
|
|
1819
|
-
disabled: true,
|
|
1820
1820
|
};
|
|
1821
|
-
|
|
1821
|
+
// Array gets class, component still gets class/style (arrays don't claim styling)
|
|
1822
|
+
const [arrayProps, compProps, otherProps] = splitProps(
|
|
1822
1823
|
props,
|
|
1824
|
+
[classNameProp],
|
|
1823
1825
|
component,
|
|
1824
|
-
["disabled"],
|
|
1825
1826
|
);
|
|
1826
|
-
|
|
1827
|
+
expectTypeOf(arrayProps).branded.toEqualTypeOf<
|
|
1828
|
+
Pick<typeof props, "class" | "className">
|
|
1829
|
+
>();
|
|
1830
|
+
expect(arrayProps).toEqual({ [classNameProp]: "extra" });
|
|
1831
|
+
// Component still gets class/style since arrays don't claim them
|
|
1832
|
+
expectTypeOf(compProps).branded.toEqualTypeOf<
|
|
1833
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1834
|
+
>();
|
|
1835
|
+
expect(compProps).toEqual({
|
|
1827
1836
|
size: "lg",
|
|
1828
|
-
style: {
|
|
1837
|
+
style: { backgroundColor: "yellow" },
|
|
1829
1838
|
[classNameProp]: "extra",
|
|
1830
1839
|
});
|
|
1831
|
-
expect(extraProps).toEqual({ disabled: true });
|
|
1832
1840
|
expect(otherProps).toEqual({ id: "test" });
|
|
1833
1841
|
});
|
|
1834
1842
|
|
|
1835
|
-
test("splitProps with
|
|
1836
|
-
const
|
|
1843
|
+
test("splitProps with array containing class and style before component", () => {
|
|
1844
|
+
const component = getModalComponent(
|
|
1837
1845
|
mode,
|
|
1838
1846
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1839
1847
|
);
|
|
1840
|
-
const component2 = getModalComponent(
|
|
1841
|
-
mode,
|
|
1842
|
-
cv({
|
|
1843
|
-
variants: { color: { red: "red", blue: "blue" } },
|
|
1844
|
-
defaultVariants: { color: "red" },
|
|
1845
|
-
}),
|
|
1846
|
-
);
|
|
1847
1848
|
const classNameProp = getClassPropertyName(config);
|
|
1848
|
-
const props: HTMLProperties<typeof
|
|
1849
|
-
HTMLProperties<typeof component2> = {
|
|
1849
|
+
const props: HTMLProperties<typeof component> = {
|
|
1850
1850
|
id: "test",
|
|
1851
1851
|
size: "lg",
|
|
1852
|
-
|
|
1852
|
+
style: { backgroundColor: "yellow" },
|
|
1853
1853
|
[classNameProp]: "extra",
|
|
1854
1854
|
};
|
|
1855
|
-
|
|
1855
|
+
// Array gets class and style, component still gets class/style (arrays don't claim styling)
|
|
1856
|
+
const [arrayProps, compProps, otherProps] = splitProps(
|
|
1856
1857
|
props,
|
|
1857
|
-
|
|
1858
|
-
|
|
1858
|
+
[classNameProp, "style"],
|
|
1859
|
+
component,
|
|
1859
1860
|
);
|
|
1860
|
-
|
|
1861
|
-
|
|
1861
|
+
expectTypeOf(arrayProps).branded.toEqualTypeOf<
|
|
1862
|
+
Pick<typeof props, "class" | "className" | "style">
|
|
1863
|
+
>();
|
|
1864
|
+
expect(arrayProps).toEqual({
|
|
1862
1865
|
[classNameProp]: "extra",
|
|
1866
|
+
style: { backgroundColor: "yellow" },
|
|
1863
1867
|
});
|
|
1864
|
-
//
|
|
1865
|
-
|
|
1866
|
-
|
|
1868
|
+
// Component still gets class/style since arrays don't claim them
|
|
1869
|
+
expectTypeOf(compProps).branded.toEqualTypeOf<
|
|
1870
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1871
|
+
>();
|
|
1872
|
+
expect(compProps).toEqual({
|
|
1873
|
+
size: "lg",
|
|
1874
|
+
style: { backgroundColor: "yellow" },
|
|
1867
1875
|
[classNameProp]: "extra",
|
|
1868
1876
|
});
|
|
1869
1877
|
expect(otherProps).toEqual({ id: "test" });
|
|
1870
1878
|
});
|
|
1871
1879
|
|
|
1872
|
-
test("splitProps with
|
|
1873
|
-
const
|
|
1874
|
-
mode,
|
|
1875
|
-
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1876
|
-
);
|
|
1877
|
-
const component2 = getModalComponent(
|
|
1878
|
-
mode,
|
|
1879
|
-
cv({
|
|
1880
|
-
variants: { color: { red: "red", blue: "blue" } },
|
|
1881
|
-
defaultVariants: { color: "red" },
|
|
1882
|
-
}),
|
|
1883
|
-
);
|
|
1884
|
-
const props: HTMLProperties<typeof component1> &
|
|
1885
|
-
HTMLProperties<typeof component2> = {
|
|
1886
|
-
id: "test",
|
|
1887
|
-
size: "lg",
|
|
1888
|
-
};
|
|
1889
|
-
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1890
|
-
props,
|
|
1891
|
-
component1,
|
|
1892
|
-
component2,
|
|
1893
|
-
);
|
|
1894
|
-
expect(comp1Props).toEqual({ size: "lg" });
|
|
1895
|
-
// component2's defaults should be included
|
|
1896
|
-
expect(comp2Props).toEqual({ color: "red" });
|
|
1897
|
-
expect(otherProps).toEqual({ id: "test" });
|
|
1898
|
-
});
|
|
1899
|
-
|
|
1900
|
-
test("splitProps with onlyVariants component excludes class and style", () => {
|
|
1901
|
-
const component1 = getModalComponent(
|
|
1880
|
+
test("splitProps with array after component", () => {
|
|
1881
|
+
const component = getModalComponent(
|
|
1902
1882
|
mode,
|
|
1903
1883
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1904
1884
|
);
|
|
1905
|
-
const component2 = getModalComponent(
|
|
1906
|
-
mode,
|
|
1907
|
-
cv({ variants: { color: { red: "red", blue: "blue" } } }),
|
|
1908
|
-
);
|
|
1909
1885
|
const classNameProp = getClassPropertyName(config);
|
|
1910
|
-
const props: HTMLProperties<typeof
|
|
1911
|
-
HTMLProperties<typeof component2> = {
|
|
1886
|
+
const props: HTMLProperties<typeof component> = {
|
|
1912
1887
|
id: "test",
|
|
1913
1888
|
size: "lg",
|
|
1914
|
-
color: "blue",
|
|
1915
1889
|
style: { backgroundColor: "yellow" },
|
|
1916
1890
|
[classNameProp]: "extra",
|
|
1917
1891
|
};
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
);
|
|
1923
|
-
|
|
1892
|
+
// Component gets class/style first, array also gets them
|
|
1893
|
+
const [compProps, arrayProps, otherProps] = splitProps(props, component, [
|
|
1894
|
+
classNameProp,
|
|
1895
|
+
"style",
|
|
1896
|
+
]);
|
|
1897
|
+
expectTypeOf(compProps).branded.toEqualTypeOf<
|
|
1898
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1899
|
+
>();
|
|
1900
|
+
expect(compProps).toEqual({
|
|
1924
1901
|
size: "lg",
|
|
1925
1902
|
style: { backgroundColor: "yellow" },
|
|
1926
1903
|
[classNameProp]: "extra",
|
|
1927
1904
|
});
|
|
1928
|
-
|
|
1929
|
-
|
|
1905
|
+
expectTypeOf(arrayProps).branded.toEqualTypeOf<
|
|
1906
|
+
Pick<typeof props, "class" | "className" | "style">
|
|
1907
|
+
>();
|
|
1908
|
+
expect(arrayProps).toEqual({
|
|
1909
|
+
[classNameProp]: "extra",
|
|
1910
|
+
style: { backgroundColor: "yellow" },
|
|
1911
|
+
});
|
|
1912
|
+
expectTypeOf(otherProps).toEqualTypeOf<{ id?: string }>();
|
|
1930
1913
|
expect(otherProps).toEqual({ id: "test" });
|
|
1931
1914
|
});
|
|
1932
1915
|
|
|
1933
|
-
test("splitProps
|
|
1916
|
+
test("splitProps array before multiple components", () => {
|
|
1934
1917
|
const component1 = getModalComponent(
|
|
1935
1918
|
mode,
|
|
1936
1919
|
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
@@ -1939,158 +1922,42 @@ for (const config of Object.values(CONFIGS)) {
|
|
|
1939
1922
|
mode,
|
|
1940
1923
|
cv({ variants: { color: { red: "red", blue: "blue" } } }),
|
|
1941
1924
|
);
|
|
1925
|
+
const classNameProp = getClassPropertyName(config);
|
|
1942
1926
|
const props: HTMLProperties<typeof component1> &
|
|
1943
1927
|
HTMLProperties<typeof component2> & { disabled?: boolean } = {
|
|
1944
1928
|
id: "test",
|
|
1945
1929
|
size: "lg",
|
|
1946
1930
|
color: "blue",
|
|
1947
1931
|
disabled: true,
|
|
1932
|
+
style: { backgroundColor: "yellow" },
|
|
1933
|
+
[classNameProp]: "extra",
|
|
1948
1934
|
};
|
|
1949
|
-
|
|
1935
|
+
// Array doesn't claim styling, so first component (comp1) gets styling
|
|
1936
|
+
const [disabledProps, comp1Props, comp2Props, otherProps] = splitProps(
|
|
1950
1937
|
props,
|
|
1951
|
-
component1,
|
|
1952
1938
|
["disabled"],
|
|
1953
|
-
component2.onlyVariants,
|
|
1954
|
-
);
|
|
1955
|
-
expect(comp1Props).toEqual({ size: "lg" });
|
|
1956
|
-
expect(extraProps).toEqual({ disabled: true });
|
|
1957
|
-
expect(comp2Props).toEqual({ color: "blue" });
|
|
1958
|
-
expect(otherProps).toEqual({ id: "test" });
|
|
1959
|
-
});
|
|
1960
|
-
|
|
1961
|
-
test("splitProps with shared keys between components", () => {
|
|
1962
|
-
const component1 = getModalComponent(
|
|
1963
|
-
mode,
|
|
1964
|
-
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1965
|
-
);
|
|
1966
|
-
const component2 = getModalComponent(
|
|
1967
|
-
mode,
|
|
1968
|
-
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
1969
|
-
);
|
|
1970
|
-
const props: HTMLProperties<typeof component1> &
|
|
1971
|
-
HTMLProperties<typeof component2> = {
|
|
1972
|
-
id: "test",
|
|
1973
|
-
size: "lg",
|
|
1974
|
-
};
|
|
1975
|
-
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
1976
|
-
props,
|
|
1977
|
-
component1,
|
|
1978
|
-
component2.onlyVariants,
|
|
1979
|
-
);
|
|
1980
|
-
expect(comp1Props).toEqual({ size: "lg" });
|
|
1981
|
-
// size should appear in both
|
|
1982
|
-
expect(comp2Props).toEqual({ size: "lg" });
|
|
1983
|
-
expect(otherProps).toEqual({ id: "test" });
|
|
1984
|
-
});
|
|
1985
|
-
|
|
1986
|
-
test("splitProps with defaultVariants from multiple components", () => {
|
|
1987
|
-
const component1 = getModalComponent(
|
|
1988
|
-
mode,
|
|
1989
|
-
cv({
|
|
1990
|
-
variants: { size: { sm: "sm", lg: "lg" } },
|
|
1991
|
-
defaultVariants: { size: "sm" },
|
|
1992
|
-
}),
|
|
1993
|
-
);
|
|
1994
|
-
const component2 = getModalComponent(
|
|
1995
|
-
mode,
|
|
1996
|
-
cv({
|
|
1997
|
-
variants: { color: { red: "red", blue: "blue" } },
|
|
1998
|
-
defaultVariants: { color: "red" },
|
|
1999
|
-
}),
|
|
2000
|
-
);
|
|
2001
|
-
const props: HTMLProperties<typeof component1> &
|
|
2002
|
-
HTMLProperties<typeof component2> = {
|
|
2003
|
-
id: "test",
|
|
2004
|
-
};
|
|
2005
|
-
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
2006
|
-
props,
|
|
2007
1939
|
component1,
|
|
2008
|
-
component2
|
|
2009
|
-
);
|
|
2010
|
-
// Each gets its own defaults
|
|
2011
|
-
expect(comp1Props).toEqual({ size: "sm" });
|
|
2012
|
-
expect(comp2Props).toEqual({ color: "red" });
|
|
2013
|
-
expect(otherProps).toEqual({ id: "test" });
|
|
2014
|
-
});
|
|
2015
|
-
|
|
2016
|
-
test("onlyVariants splitProps includes defaultVariants", () => {
|
|
2017
|
-
const component = getModalComponent(
|
|
2018
|
-
mode,
|
|
2019
|
-
cv({
|
|
2020
|
-
variants: { size: { sm: "sm", lg: "lg" }, color: { red: "red" } },
|
|
2021
|
-
defaultVariants: { size: "sm", color: "red" },
|
|
2022
|
-
}),
|
|
1940
|
+
component2,
|
|
2023
1941
|
);
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1942
|
+
expectTypeOf(disabledProps).branded.toEqualTypeOf<{
|
|
1943
|
+
disabled?: boolean;
|
|
1944
|
+
}>();
|
|
1945
|
+
expect(disabledProps).toEqual({ disabled: true });
|
|
1946
|
+
expectTypeOf(comp1Props).branded.toEqualTypeOf<
|
|
1947
|
+
Pick<typeof props, "size" | "style" | "class" | "className">
|
|
1948
|
+
>();
|
|
1949
|
+
// First component gets class/style
|
|
1950
|
+
expect(comp1Props).toEqual({
|
|
2027
1951
|
size: "lg",
|
|
1952
|
+
style: { backgroundColor: "yellow" },
|
|
2028
1953
|
[classNameProp]: "extra",
|
|
2029
|
-
};
|
|
2030
|
-
const [variantProps, otherProps] = splitProps(
|
|
2031
|
-
props,
|
|
2032
|
-
component.onlyVariants,
|
|
2033
|
-
);
|
|
2034
|
-
expect(variantProps).toEqual({
|
|
2035
|
-
size: "lg",
|
|
2036
|
-
color: "red",
|
|
2037
1954
|
});
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
const component = getModalComponent(
|
|
2043
|
-
mode,
|
|
2044
|
-
cv({ variants: { size: { sm: "sm", lg: "lg" } } }),
|
|
2045
|
-
);
|
|
2046
|
-
const classNameProp = getClassPropertyName(config);
|
|
2047
|
-
const props: HTMLProperties<typeof component> & { disabled?: boolean } = {
|
|
2048
|
-
id: "test",
|
|
2049
|
-
size: "lg",
|
|
2050
|
-
[classNameProp]: "extra",
|
|
2051
|
-
disabled: true,
|
|
2052
|
-
};
|
|
2053
|
-
const [variantProps, extraProps, otherProps] = splitProps(
|
|
2054
|
-
props,
|
|
2055
|
-
component.onlyVariants,
|
|
2056
|
-
["disabled"],
|
|
2057
|
-
);
|
|
2058
|
-
expect(variantProps).toEqual({ size: "lg" });
|
|
2059
|
-
expect(extraProps).toEqual({ disabled: true });
|
|
2060
|
-
expect(otherProps).toEqual({ id: "test", [classNameProp]: "extra" });
|
|
2061
|
-
});
|
|
2062
|
-
|
|
2063
|
-
test("onlyVariants splitProps with component", () => {
|
|
2064
|
-
const component1 = getModalComponent(
|
|
2065
|
-
mode,
|
|
2066
|
-
cv({
|
|
2067
|
-
variants: { size: { sm: "sm", lg: "lg" } },
|
|
2068
|
-
defaultVariants: { size: "sm" },
|
|
2069
|
-
}),
|
|
2070
|
-
);
|
|
2071
|
-
const component2 = getModalComponent(
|
|
2072
|
-
mode,
|
|
2073
|
-
cv({
|
|
2074
|
-
variants: { color: { red: "red", blue: "blue" } },
|
|
2075
|
-
defaultVariants: { color: "red" },
|
|
2076
|
-
}),
|
|
2077
|
-
);
|
|
2078
|
-
const classNameProp = getClassPropertyName(config);
|
|
2079
|
-
const props: HTMLProperties<typeof component1> &
|
|
2080
|
-
HTMLProperties<typeof component2> = {
|
|
2081
|
-
id: "test",
|
|
2082
|
-
size: "lg",
|
|
2083
|
-
color: "blue",
|
|
2084
|
-
[classNameProp]: "extra",
|
|
2085
|
-
};
|
|
2086
|
-
const [comp1Props, comp2Props, otherProps] = splitProps(
|
|
2087
|
-
props,
|
|
2088
|
-
component1.onlyVariants,
|
|
2089
|
-
component2.onlyVariants,
|
|
2090
|
-
);
|
|
2091
|
-
expect(comp1Props).toEqual({ size: "lg" });
|
|
1955
|
+
// Second component only gets variant props
|
|
1956
|
+
expectTypeOf(comp2Props).branded.toEqualTypeOf<
|
|
1957
|
+
Pick<typeof props, "color">
|
|
1958
|
+
>();
|
|
2092
1959
|
expect(comp2Props).toEqual({ color: "blue" });
|
|
2093
|
-
expect(otherProps).toEqual({ id: "test"
|
|
1960
|
+
expect(otherProps).toEqual({ id: "test" });
|
|
2094
1961
|
});
|
|
2095
1962
|
});
|
|
2096
1963
|
}
|