@dillingerstaffing/strand-ui 0.1.0 → 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/LICENSE +21 -0
- package/dist/components/Alert/Alert.d.ts +16 -0
- package/dist/components/Alert/Alert.d.ts.map +1 -0
- package/dist/components/Alert/index.d.ts +3 -0
- package/dist/components/Alert/index.d.ts.map +1 -0
- package/dist/components/Avatar/Avatar.d.ts +16 -0
- package/dist/components/Avatar/Avatar.d.ts.map +1 -0
- package/dist/components/Avatar/index.d.ts +3 -0
- package/dist/components/Avatar/index.d.ts.map +1 -0
- package/dist/components/Badge/Badge.d.ts +18 -0
- package/dist/components/Badge/Badge.d.ts.map +1 -0
- package/dist/components/Badge/index.d.ts +3 -0
- package/dist/components/Badge/index.d.ts.map +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +16 -0
- package/dist/components/Breadcrumb/Breadcrumb.d.ts.map +1 -0
- package/dist/components/Breadcrumb/index.d.ts +3 -0
- package/dist/components/Breadcrumb/index.d.ts.map +1 -0
- package/dist/components/Button/Button.d.ts +22 -0
- package/dist/components/Button/Button.d.ts.map +1 -0
- package/dist/components/Button/index.d.ts +3 -0
- package/dist/components/Button/index.d.ts.map +1 -0
- package/dist/components/Card/Card.d.ts +12 -0
- package/dist/components/Card/Card.d.ts.map +1 -0
- package/dist/components/Card/index.d.ts +3 -0
- package/dist/components/Card/index.d.ts.map +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +20 -0
- package/dist/components/Checkbox/Checkbox.d.ts.map +1 -0
- package/dist/components/Checkbox/index.d.ts +3 -0
- package/dist/components/Checkbox/index.d.ts.map +1 -0
- package/dist/components/Container/Container.d.ts +10 -0
- package/dist/components/Container/Container.d.ts.map +1 -0
- package/dist/components/Container/index.d.ts +3 -0
- package/dist/components/Container/index.d.ts.map +1 -0
- package/dist/components/DataReadout/DataReadout.d.ts +12 -0
- package/dist/components/DataReadout/DataReadout.d.ts.map +1 -0
- package/dist/components/DataReadout/index.d.ts +3 -0
- package/dist/components/DataReadout/index.d.ts.map +1 -0
- package/dist/components/Dialog/Dialog.d.ts +20 -0
- package/dist/components/Dialog/Dialog.d.ts.map +1 -0
- package/dist/components/Dialog/index.d.ts +3 -0
- package/dist/components/Dialog/index.d.ts.map +1 -0
- package/dist/components/Divider/Divider.d.ts +13 -0
- package/dist/components/Divider/Divider.d.ts.map +1 -0
- package/dist/components/Divider/index.d.ts +3 -0
- package/dist/components/Divider/index.d.ts.map +1 -0
- package/dist/components/FormField/FormField.d.ts +22 -0
- package/dist/components/FormField/FormField.d.ts.map +1 -0
- package/dist/components/FormField/index.d.ts +3 -0
- package/dist/components/FormField/index.d.ts.map +1 -0
- package/dist/components/Grid/Grid.d.ts +12 -0
- package/dist/components/Grid/Grid.d.ts.map +1 -0
- package/dist/components/Grid/index.d.ts +3 -0
- package/dist/components/Grid/index.d.ts.map +1 -0
- package/dist/components/Input/Input.d.ts +18 -0
- package/dist/components/Input/Input.d.ts.map +1 -0
- package/dist/components/Input/index.d.ts +3 -0
- package/dist/components/Input/index.d.ts.map +1 -0
- package/dist/components/Link/Link.d.ts +12 -0
- package/dist/components/Link/Link.d.ts.map +1 -0
- package/dist/components/Link/index.d.ts +3 -0
- package/dist/components/Link/index.d.ts.map +1 -0
- package/dist/components/Nav/Nav.d.ts +19 -0
- package/dist/components/Nav/Nav.d.ts.map +1 -0
- package/dist/components/Nav/index.d.ts +3 -0
- package/dist/components/Nav/index.d.ts.map +1 -0
- package/dist/components/Progress/Progress.d.ts +14 -0
- package/dist/components/Progress/Progress.d.ts.map +1 -0
- package/dist/components/Progress/index.d.ts +3 -0
- package/dist/components/Progress/index.d.ts.map +1 -0
- package/dist/components/Radio/Radio.d.ts +22 -0
- package/dist/components/Radio/Radio.d.ts.map +1 -0
- package/dist/components/Radio/index.d.ts +3 -0
- package/dist/components/Radio/index.d.ts.map +1 -0
- package/dist/components/Section/Section.d.ts +12 -0
- package/dist/components/Section/Section.d.ts.map +1 -0
- package/dist/components/Section/index.d.ts +3 -0
- package/dist/components/Section/index.d.ts.map +1 -0
- package/dist/components/Select/Select.d.ts +24 -0
- package/dist/components/Select/Select.d.ts.map +1 -0
- package/dist/components/Select/index.d.ts +3 -0
- package/dist/components/Select/index.d.ts.map +1 -0
- package/dist/components/Skeleton/Skeleton.d.ts +14 -0
- package/dist/components/Skeleton/Skeleton.d.ts.map +1 -0
- package/dist/components/Skeleton/index.d.ts +3 -0
- package/dist/components/Skeleton/index.d.ts.map +1 -0
- package/dist/components/Slider/Slider.d.ts +20 -0
- package/dist/components/Slider/Slider.d.ts.map +1 -0
- package/dist/components/Slider/index.d.ts +3 -0
- package/dist/components/Slider/index.d.ts.map +1 -0
- package/dist/components/Spinner/Spinner.d.ts +10 -0
- package/dist/components/Spinner/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner/index.d.ts +3 -0
- package/dist/components/Spinner/index.d.ts.map +1 -0
- package/dist/components/Stack/Stack.d.ts +18 -0
- package/dist/components/Stack/Stack.d.ts.map +1 -0
- package/dist/components/Stack/index.d.ts +3 -0
- package/dist/components/Stack/index.d.ts.map +1 -0
- package/dist/components/Switch/Switch.d.ts +18 -0
- package/dist/components/Switch/Switch.d.ts.map +1 -0
- package/dist/components/Switch/index.d.ts +3 -0
- package/dist/components/Switch/index.d.ts.map +1 -0
- package/dist/components/Table/Table.d.ts +24 -0
- package/dist/components/Table/Table.d.ts.map +1 -0
- package/dist/components/Table/index.d.ts +3 -0
- package/dist/components/Table/index.d.ts.map +1 -0
- package/dist/components/Tabs/Tabs.d.ts +19 -0
- package/dist/components/Tabs/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs/index.d.ts +3 -0
- package/dist/components/Tabs/index.d.ts.map +1 -0
- package/dist/components/Tag/Tag.d.ts +18 -0
- package/dist/components/Tag/Tag.d.ts.map +1 -0
- package/dist/components/Tag/index.d.ts +3 -0
- package/dist/components/Tag/index.d.ts.map +1 -0
- package/dist/components/Textarea/Textarea.d.ts +22 -0
- package/dist/components/Textarea/Textarea.d.ts.map +1 -0
- package/dist/components/Textarea/index.d.ts +3 -0
- package/dist/components/Textarea/index.d.ts.map +1 -0
- package/dist/components/Toast/Toast.d.ts +33 -0
- package/dist/components/Toast/Toast.d.ts.map +1 -0
- package/dist/components/Toast/index.d.ts +3 -0
- package/dist/components/Toast/index.d.ts.map +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +16 -0
- package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip/index.d.ts +3 -0
- package/dist/components/Tooltip/index.d.ts.map +1 -0
- package/dist/css/strand-ui.css +2301 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/package.json +12 -11
- package/src/__tests__/build-output.test.ts +77 -0
- package/src/components/Alert/Alert.css +67 -0
- package/src/components/Alert/Alert.test.tsx +92 -0
- package/src/components/Alert/Alert.tsx +59 -0
- package/src/components/Alert/index.ts +2 -0
- package/src/components/Avatar/Avatar.css +55 -0
- package/src/components/Avatar/Avatar.test.tsx +123 -0
- package/src/components/Avatar/Avatar.tsx +67 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Badge/Badge.css +72 -0
- package/src/components/Badge/Badge.test.tsx +121 -0
- package/src/components/Badge/Badge.tsx +92 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/Breadcrumb/Breadcrumb.css +45 -0
- package/src/components/Breadcrumb/Breadcrumb.test.tsx +107 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +59 -0
- package/src/components/Breadcrumb/index.ts +2 -0
- package/src/components/Button/Button.css +188 -0
- package/src/components/Button/Button.test.tsx +171 -0
- package/src/components/Button/Button.tsx +78 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Card/Card.css +59 -0
- package/src/components/Card/Card.test.tsx +90 -0
- package/src/components/Card/Card.tsx +41 -0
- package/src/components/Card/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.css +97 -0
- package/src/components/Checkbox/Checkbox.test.tsx +92 -0
- package/src/components/Checkbox/Checkbox.tsx +137 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/Container/Container.css +25 -0
- package/src/components/Container/Container.test.tsx +82 -0
- package/src/components/Container/Container.tsx +37 -0
- package/src/components/Container/index.ts +2 -0
- package/src/components/DataReadout/DataReadout.css +30 -0
- package/src/components/DataReadout/DataReadout.test.tsx +105 -0
- package/src/components/DataReadout/DataReadout.tsx +29 -0
- package/src/components/DataReadout/index.ts +2 -0
- package/src/components/Dialog/Dialog.css +80 -0
- package/src/components/Dialog/Dialog.test.tsx +203 -0
- package/src/components/Dialog/Dialog.tsx +179 -0
- package/src/components/Dialog/index.ts +2 -0
- package/src/components/Divider/Divider.css +44 -0
- package/src/components/Divider/Divider.test.tsx +86 -0
- package/src/components/Divider/Divider.tsx +81 -0
- package/src/components/Divider/index.ts +2 -0
- package/src/components/FormField/FormField.css +47 -0
- package/src/components/FormField/FormField.test.tsx +99 -0
- package/src/components/FormField/FormField.tsx +79 -0
- package/src/components/FormField/index.ts +2 -0
- package/src/components/Grid/Grid.css +6 -0
- package/src/components/Grid/Grid.test.tsx +86 -0
- package/src/components/Grid/Grid.tsx +45 -0
- package/src/components/Grid/index.ts +2 -0
- package/src/components/Input/Input.css +80 -0
- package/src/components/Input/Input.test.tsx +95 -0
- package/src/components/Input/Input.tsx +69 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/Link/Link.css +24 -0
- package/src/components/Link/Link.test.tsx +88 -0
- package/src/components/Link/Link.tsx +31 -0
- package/src/components/Link/index.ts +2 -0
- package/src/components/Nav/Nav.css +169 -0
- package/src/components/Nav/Nav.test.tsx +174 -0
- package/src/components/Nav/Nav.tsx +101 -0
- package/src/components/Nav/index.ts +2 -0
- package/src/components/Progress/Progress.css +93 -0
- package/src/components/Progress/Progress.test.tsx +93 -0
- package/src/components/Progress/Progress.tsx +104 -0
- package/src/components/Progress/index.ts +2 -0
- package/src/components/Radio/Radio.css +98 -0
- package/src/components/Radio/Radio.test.tsx +80 -0
- package/src/components/Radio/Radio.tsx +72 -0
- package/src/components/Radio/index.ts +2 -0
- package/src/components/Section/Section.css +28 -0
- package/src/components/Section/Section.test.tsx +100 -0
- package/src/components/Section/Section.tsx +41 -0
- package/src/components/Section/index.ts +2 -0
- package/src/components/Select/Select.css +68 -0
- package/src/components/Select/Select.test.tsx +99 -0
- package/src/components/Select/Select.tsx +78 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/Skeleton/Skeleton.css +52 -0
- package/src/components/Skeleton/Skeleton.test.tsx +96 -0
- package/src/components/Skeleton/Skeleton.tsx +55 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Slider/Slider.css +107 -0
- package/src/components/Slider/Slider.test.tsx +85 -0
- package/src/components/Slider/Slider.tsx +66 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Spinner/Spinner.css +61 -0
- package/src/components/Spinner/Spinner.test.tsx +56 -0
- package/src/components/Spinner/Spinner.tsx +38 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/Stack/Stack.css +56 -0
- package/src/components/Stack/Stack.test.tsx +130 -0
- package/src/components/Stack/Stack.tsx +77 -0
- package/src/components/Stack/index.ts +2 -0
- package/src/components/Switch/Switch.css +94 -0
- package/src/components/Switch/Switch.test.tsx +98 -0
- package/src/components/Switch/Switch.tsx +80 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Table/Table.css +78 -0
- package/src/components/Table/Table.test.tsx +134 -0
- package/src/components/Table/Table.tsx +102 -0
- package/src/components/Table/index.ts +2 -0
- package/src/components/Tabs/Tabs.css +46 -0
- package/src/components/Tabs/Tabs.test.tsx +164 -0
- package/src/components/Tabs/Tabs.tsx +126 -0
- package/src/components/Tabs/index.ts +2 -0
- package/src/components/Tag/Tag.css +98 -0
- package/src/components/Tag/Tag.test.tsx +112 -0
- package/src/components/Tag/Tag.tsx +73 -0
- package/src/components/Tag/index.ts +2 -0
- package/src/components/Textarea/Textarea.css +73 -0
- package/src/components/Textarea/Textarea.test.tsx +89 -0
- package/src/components/Textarea/Textarea.tsx +102 -0
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toast/Toast.css +103 -0
- package/src/components/Toast/Toast.test.tsx +219 -0
- package/src/components/Toast/Toast.tsx +177 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.css +63 -0
- package/src/components/Tooltip/Tooltip.test.tsx +196 -0
- package/src/components/Tooltip/Tooltip.tsx +89 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/index.ts +99 -0
- package/src/test-setup.ts +7 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-tag {
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: var(--strand-space-1);
|
|
8
|
+
padding: var(--strand-space-1) var(--strand-space-2);
|
|
9
|
+
border-radius: var(--strand-radius-sm);
|
|
10
|
+
font-family: var(--strand-font-sans);
|
|
11
|
+
font-size: var(--strand-text-xs);
|
|
12
|
+
font-weight: var(--strand-weight-medium);
|
|
13
|
+
line-height: var(--strand-leading-snug);
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
border: 1px solid transparent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* ── Solid variant ── */
|
|
19
|
+
.strand-tag--solid.strand-tag--default {
|
|
20
|
+
background: var(--strand-surface-recessed);
|
|
21
|
+
color: var(--strand-gray-600);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.strand-tag--solid.strand-tag--teal {
|
|
25
|
+
background: rgba(20, 184, 166, 0.1);
|
|
26
|
+
color: #0D7377;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.strand-tag--solid.strand-tag--blue {
|
|
30
|
+
background: var(--strand-blue-glow);
|
|
31
|
+
color: var(--strand-blue-deep);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.strand-tag--solid.strand-tag--amber {
|
|
35
|
+
background: rgba(245, 158, 11, 0.1);
|
|
36
|
+
color: #92400E;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.strand-tag--solid.strand-tag--red {
|
|
40
|
+
background: rgba(239, 68, 68, 0.1);
|
|
41
|
+
color: #991B1B;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ── Outlined variant ── */
|
|
45
|
+
.strand-tag--outlined {
|
|
46
|
+
background: transparent;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.strand-tag--outlined.strand-tag--default {
|
|
50
|
+
border-color: var(--strand-gray-200);
|
|
51
|
+
color: var(--strand-gray-600);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.strand-tag--outlined.strand-tag--teal {
|
|
55
|
+
border-color: var(--strand-teal-vital);
|
|
56
|
+
color: #0D7377;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.strand-tag--outlined.strand-tag--blue {
|
|
60
|
+
border-color: var(--strand-blue-primary);
|
|
61
|
+
color: var(--strand-blue-deep);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.strand-tag--outlined.strand-tag--amber {
|
|
65
|
+
border-color: var(--strand-amber-caution);
|
|
66
|
+
color: #92400E;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.strand-tag--outlined.strand-tag--red {
|
|
70
|
+
border-color: var(--strand-red-alert);
|
|
71
|
+
color: #991B1B;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ── Remove button ── */
|
|
75
|
+
.strand-tag__remove {
|
|
76
|
+
display: inline-flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
padding: 0;
|
|
80
|
+
border: none;
|
|
81
|
+
background: none;
|
|
82
|
+
color: currentColor;
|
|
83
|
+
opacity: 0.6;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
border-radius: var(--strand-radius-sm);
|
|
86
|
+
transition: opacity var(--strand-duration-fast) ease;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.strand-tag__remove:hover {
|
|
90
|
+
opacity: 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ── Reduced motion ── */
|
|
94
|
+
@media (prefers-reduced-motion: reduce) {
|
|
95
|
+
.strand-tag__remove {
|
|
96
|
+
transition: none;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/preact";
|
|
3
|
+
import { Tag } from "./Tag.js";
|
|
4
|
+
|
|
5
|
+
describe("Tag", () => {
|
|
6
|
+
// ── Rendering ──
|
|
7
|
+
|
|
8
|
+
it("renders children text", () => {
|
|
9
|
+
const { getByText } = render(<Tag>Active</Tag>);
|
|
10
|
+
expect(getByText("Active")).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("renders as a span element", () => {
|
|
14
|
+
const { container } = render(<Tag>Test</Tag>);
|
|
15
|
+
expect(container.querySelector("span.strand-tag")).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// ── Variants ──
|
|
19
|
+
|
|
20
|
+
it("applies solid variant class by default", () => {
|
|
21
|
+
const { container } = render(<Tag>Test</Tag>);
|
|
22
|
+
const tag = container.querySelector(".strand-tag");
|
|
23
|
+
expect(tag?.className).toContain("strand-tag--solid");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("applies outlined variant class", () => {
|
|
27
|
+
const { container } = render(<Tag variant="outlined">Test</Tag>);
|
|
28
|
+
const tag = container.querySelector(".strand-tag");
|
|
29
|
+
expect(tag?.className).toContain("strand-tag--outlined");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// ── Status colors ──
|
|
33
|
+
|
|
34
|
+
it("applies default status class by default", () => {
|
|
35
|
+
const { container } = render(<Tag>Test</Tag>);
|
|
36
|
+
const tag = container.querySelector(".strand-tag");
|
|
37
|
+
expect(tag?.className).toContain("strand-tag--default");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("applies teal status class", () => {
|
|
41
|
+
const { container } = render(<Tag status="teal">Test</Tag>);
|
|
42
|
+
const tag = container.querySelector(".strand-tag");
|
|
43
|
+
expect(tag?.className).toContain("strand-tag--teal");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("applies blue status class", () => {
|
|
47
|
+
const { container } = render(<Tag status="blue">Test</Tag>);
|
|
48
|
+
const tag = container.querySelector(".strand-tag");
|
|
49
|
+
expect(tag?.className).toContain("strand-tag--blue");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("applies amber status class", () => {
|
|
53
|
+
const { container } = render(<Tag status="amber">Test</Tag>);
|
|
54
|
+
const tag = container.querySelector(".strand-tag");
|
|
55
|
+
expect(tag?.className).toContain("strand-tag--amber");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("applies red status class", () => {
|
|
59
|
+
const { container } = render(<Tag status="red">Test</Tag>);
|
|
60
|
+
const tag = container.querySelector(".strand-tag");
|
|
61
|
+
expect(tag?.className).toContain("strand-tag--red");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ── Removable ──
|
|
65
|
+
|
|
66
|
+
it("shows remove button when removable", () => {
|
|
67
|
+
const { getByLabelText } = render(<Tag removable>Test</Tag>);
|
|
68
|
+
expect(getByLabelText("Remove")).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("does not show remove button when not removable", () => {
|
|
72
|
+
const { queryByLabelText } = render(<Tag>Test</Tag>);
|
|
73
|
+
expect(queryByLabelText("Remove")).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("calls onRemove when remove button is clicked", () => {
|
|
77
|
+
const onRemove = vi.fn();
|
|
78
|
+
const { getByLabelText } = render(
|
|
79
|
+
<Tag removable onRemove={onRemove}>Test</Tag>,
|
|
80
|
+
);
|
|
81
|
+
fireEvent.click(getByLabelText("Remove"));
|
|
82
|
+
expect(onRemove).toHaveBeenCalledTimes(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// ── Custom className ──
|
|
86
|
+
|
|
87
|
+
it("merges custom className with component classes", () => {
|
|
88
|
+
const { container } = render(<Tag className="custom">Test</Tag>);
|
|
89
|
+
const tag = container.querySelector(".strand-tag");
|
|
90
|
+
expect(tag?.className).toContain("strand-tag");
|
|
91
|
+
expect(tag?.className).toContain("custom");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ── Typography ──
|
|
95
|
+
|
|
96
|
+
it("uses xs font size class", () => {
|
|
97
|
+
const { container } = render(<Tag>Test</Tag>);
|
|
98
|
+
const tag = container.querySelector(".strand-tag");
|
|
99
|
+
expect(tag).toBeTruthy();
|
|
100
|
+
// Font size is applied via CSS class .strand-tag which uses --strand-text-xs
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// ── Forwarded props ──
|
|
104
|
+
|
|
105
|
+
it("forwards additional props", () => {
|
|
106
|
+
const { container } = render(
|
|
107
|
+
<Tag data-testid="my-tag" id="tag-1">Test</Tag>,
|
|
108
|
+
);
|
|
109
|
+
const tag = container.querySelector(".strand-tag");
|
|
110
|
+
expect(tag?.getAttribute("id")).toBe("tag-1");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
export interface TagProps
|
|
7
|
+
extends Omit<JSX.HTMLAttributes<HTMLSpanElement>, "children"> {
|
|
8
|
+
/** Visual style variant */
|
|
9
|
+
variant?: "solid" | "outlined";
|
|
10
|
+
/** Color status */
|
|
11
|
+
status?: "default" | "teal" | "blue" | "amber" | "red";
|
|
12
|
+
/** Show remove button */
|
|
13
|
+
removable?: boolean;
|
|
14
|
+
/** Called when remove button is clicked */
|
|
15
|
+
onRemove?: () => void;
|
|
16
|
+
/** Tag text content */
|
|
17
|
+
children?: ComponentChildren;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Tag = forwardRef<HTMLSpanElement, TagProps>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
variant = "solid",
|
|
24
|
+
status = "default",
|
|
25
|
+
removable = false,
|
|
26
|
+
onRemove,
|
|
27
|
+
className = "",
|
|
28
|
+
children,
|
|
29
|
+
...rest
|
|
30
|
+
},
|
|
31
|
+
ref,
|
|
32
|
+
) => {
|
|
33
|
+
const classes = [
|
|
34
|
+
"strand-tag",
|
|
35
|
+
`strand-tag--${variant}`,
|
|
36
|
+
`strand-tag--${status}`,
|
|
37
|
+
className,
|
|
38
|
+
]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(" ");
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<span ref={ref} className={classes} {...rest}>
|
|
44
|
+
<span className="strand-tag__text">{children}</span>
|
|
45
|
+
{removable && (
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
className="strand-tag__remove"
|
|
49
|
+
aria-label="Remove"
|
|
50
|
+
onClick={onRemove}
|
|
51
|
+
>
|
|
52
|
+
<svg
|
|
53
|
+
width="12"
|
|
54
|
+
height="12"
|
|
55
|
+
viewBox="0 0 12 12"
|
|
56
|
+
fill="none"
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
>
|
|
59
|
+
<path
|
|
60
|
+
d="M3 3l6 6M9 3l-6 6"
|
|
61
|
+
stroke="currentColor"
|
|
62
|
+
stroke-width="1.5"
|
|
63
|
+
stroke-linecap="round"
|
|
64
|
+
/>
|
|
65
|
+
</svg>
|
|
66
|
+
</button>
|
|
67
|
+
)}
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
Tag.displayName = "Tag";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-textarea {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
background: var(--strand-surface-elevated);
|
|
9
|
+
border: 1px solid var(--strand-gray-200);
|
|
10
|
+
border-radius: var(--strand-radius-md);
|
|
11
|
+
transition:
|
|
12
|
+
border-color var(--strand-duration-fast) ease,
|
|
13
|
+
box-shadow var(--strand-duration-fast) ease;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.strand-textarea:focus-within {
|
|
17
|
+
border-color: var(--strand-blue-primary);
|
|
18
|
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* ── Field ── */
|
|
22
|
+
.strand-textarea__field {
|
|
23
|
+
width: 100%;
|
|
24
|
+
min-height: 80px;
|
|
25
|
+
padding: var(--strand-space-3) var(--strand-space-4);
|
|
26
|
+
background: transparent;
|
|
27
|
+
border: none;
|
|
28
|
+
font-family: var(--strand-font-sans);
|
|
29
|
+
font-size: var(--strand-text-base);
|
|
30
|
+
color: var(--strand-gray-900);
|
|
31
|
+
outline: none;
|
|
32
|
+
resize: vertical;
|
|
33
|
+
line-height: var(--strand-leading-normal);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.strand-textarea__field::placeholder {
|
|
37
|
+
color: var(--strand-gray-400);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ── Auto-resize ── */
|
|
41
|
+
.strand-textarea--auto-resize .strand-textarea__field {
|
|
42
|
+
resize: none;
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* ── Character count ── */
|
|
47
|
+
.strand-textarea__count {
|
|
48
|
+
align-self: flex-end;
|
|
49
|
+
padding: var(--strand-space-1) var(--strand-space-3) var(--strand-space-2);
|
|
50
|
+
font-family: var(--strand-font-sans);
|
|
51
|
+
font-size: var(--strand-text-xs);
|
|
52
|
+
color: var(--strand-gray-500);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* ── Error ── */
|
|
56
|
+
.strand-textarea--error {
|
|
57
|
+
border-color: var(--strand-red-alert);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.strand-textarea--error:focus-within {
|
|
61
|
+
border-color: var(--strand-red-alert);
|
|
62
|
+
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* ── Disabled ── */
|
|
66
|
+
.strand-textarea--disabled {
|
|
67
|
+
opacity: 0.4;
|
|
68
|
+
cursor: not-allowed;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.strand-textarea--disabled .strand-textarea__field {
|
|
72
|
+
cursor: not-allowed;
|
|
73
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/preact";
|
|
3
|
+
import { Textarea } from "./Textarea.js";
|
|
4
|
+
|
|
5
|
+
describe("Textarea", () => {
|
|
6
|
+
it("renders a textarea element", () => {
|
|
7
|
+
const { container } = render(<Textarea aria-label="Message" />);
|
|
8
|
+
expect(container.querySelector("textarea")).toBeTruthy();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("displays placeholder text", () => {
|
|
12
|
+
const { getByPlaceholderText } = render(
|
|
13
|
+
<Textarea placeholder="Enter message" aria-label="Message" />
|
|
14
|
+
);
|
|
15
|
+
expect(getByPlaceholderText("Enter message")).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("calls onInput when value changes", () => {
|
|
19
|
+
const onInput = vi.fn();
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<Textarea aria-label="Message" onInput={onInput} />
|
|
22
|
+
);
|
|
23
|
+
fireEvent.input(container.querySelector("textarea")!, {
|
|
24
|
+
target: { value: "hello" },
|
|
25
|
+
});
|
|
26
|
+
expect(onInput).toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("shows character count when showCount and maxLength are set", () => {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<Textarea aria-label="Message" showCount maxLength={100} value="hello" />
|
|
32
|
+
);
|
|
33
|
+
const count = container.querySelector(".strand-textarea__count");
|
|
34
|
+
expect(count).toBeTruthy();
|
|
35
|
+
expect(count!.textContent).toBe("5/100");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("does not show character count without showCount", () => {
|
|
39
|
+
const { container } = render(
|
|
40
|
+
<Textarea aria-label="Message" maxLength={100} value="hello" />
|
|
41
|
+
);
|
|
42
|
+
expect(container.querySelector(".strand-textarea__count")).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("applies auto-resize class when autoResize is true", () => {
|
|
46
|
+
const { container } = render(
|
|
47
|
+
<Textarea aria-label="Message" autoResize />
|
|
48
|
+
);
|
|
49
|
+
expect(
|
|
50
|
+
container.querySelector(".strand-textarea--auto-resize")
|
|
51
|
+
).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("applies error class when error is true", () => {
|
|
55
|
+
const { container } = render(<Textarea aria-label="Message" error />);
|
|
56
|
+
expect(
|
|
57
|
+
container.querySelector(".strand-textarea--error")
|
|
58
|
+
).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("sets aria-invalid when error is true", () => {
|
|
62
|
+
const { container } = render(<Textarea aria-label="Message" error />);
|
|
63
|
+
expect(container.querySelector("textarea")).toHaveAttribute(
|
|
64
|
+
"aria-invalid",
|
|
65
|
+
"true"
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("sets disabled attribute when disabled", () => {
|
|
70
|
+
const { container } = render(<Textarea aria-label="Message" disabled />);
|
|
71
|
+
expect(container.querySelector("textarea")).toBeDisabled();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("applies disabled class when disabled", () => {
|
|
75
|
+
const { container } = render(<Textarea aria-label="Message" disabled />);
|
|
76
|
+
expect(
|
|
77
|
+
container.querySelector(".strand-textarea--disabled")
|
|
78
|
+
).toBeTruthy();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("merges custom className", () => {
|
|
82
|
+
const { container } = render(
|
|
83
|
+
<Textarea aria-label="Message" className="custom" />
|
|
84
|
+
);
|
|
85
|
+
const wrapper = container.querySelector(".strand-textarea");
|
|
86
|
+
expect(wrapper?.className).toContain("custom");
|
|
87
|
+
expect(wrapper?.className).toContain("strand-textarea");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
import { useCallback, useRef } from "preact/hooks";
|
|
6
|
+
|
|
7
|
+
export interface TextareaProps
|
|
8
|
+
extends Omit<JSX.HTMLAttributes<HTMLTextAreaElement>, "onInput" | "value"> {
|
|
9
|
+
/** Auto-resize to fit content */
|
|
10
|
+
autoResize?: boolean;
|
|
11
|
+
/** Show character count (requires maxLength) */
|
|
12
|
+
showCount?: boolean;
|
|
13
|
+
/** Show error styling */
|
|
14
|
+
error?: boolean;
|
|
15
|
+
/** Maximum character count */
|
|
16
|
+
maxLength?: number;
|
|
17
|
+
/** Input handler */
|
|
18
|
+
onInput?: JSX.GenericEventHandler<HTMLTextAreaElement>;
|
|
19
|
+
/** Disabled state */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** Controlled value */
|
|
22
|
+
value?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
26
|
+
(
|
|
27
|
+
{
|
|
28
|
+
autoResize = false,
|
|
29
|
+
showCount = false,
|
|
30
|
+
error = false,
|
|
31
|
+
maxLength,
|
|
32
|
+
disabled,
|
|
33
|
+
className = "",
|
|
34
|
+
value,
|
|
35
|
+
onInput,
|
|
36
|
+
...rest
|
|
37
|
+
},
|
|
38
|
+
ref,
|
|
39
|
+
) => {
|
|
40
|
+
const internalRef = useRef<HTMLTextAreaElement | null>(null);
|
|
41
|
+
|
|
42
|
+
const setRef = useCallback(
|
|
43
|
+
(el: HTMLTextAreaElement | null) => {
|
|
44
|
+
internalRef.current = el;
|
|
45
|
+
if (typeof ref === "function") {
|
|
46
|
+
ref(el);
|
|
47
|
+
} else if (ref) {
|
|
48
|
+
(ref as { current: HTMLTextAreaElement | null }).current = el;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[ref],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleInput: JSX.GenericEventHandler<HTMLTextAreaElement> = useCallback(
|
|
55
|
+
(e) => {
|
|
56
|
+
if (autoResize && internalRef.current) {
|
|
57
|
+
internalRef.current.style.height = "auto";
|
|
58
|
+
internalRef.current.style.height = `${internalRef.current.scrollHeight}px`;
|
|
59
|
+
}
|
|
60
|
+
if (onInput) {
|
|
61
|
+
onInput(e);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
[autoResize, onInput],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const wrapperClasses = [
|
|
68
|
+
"strand-textarea",
|
|
69
|
+
error && "strand-textarea--error",
|
|
70
|
+
disabled && "strand-textarea--disabled",
|
|
71
|
+
autoResize && "strand-textarea--auto-resize",
|
|
72
|
+
className,
|
|
73
|
+
]
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.join(" ");
|
|
76
|
+
|
|
77
|
+
const currentLength =
|
|
78
|
+
typeof value === "string" ? value.length : 0;
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className={wrapperClasses}>
|
|
82
|
+
<textarea
|
|
83
|
+
ref={setRef}
|
|
84
|
+
className="strand-textarea__field"
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
aria-invalid={error ? "true" : undefined}
|
|
87
|
+
maxLength={maxLength}
|
|
88
|
+
value={value}
|
|
89
|
+
onInput={handleInput}
|
|
90
|
+
{...rest}
|
|
91
|
+
/>
|
|
92
|
+
{showCount && maxLength != null && (
|
|
93
|
+
<span className="strand-textarea__count" aria-live="polite">
|
|
94
|
+
{currentLength}/{maxLength}
|
|
95
|
+
</span>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
Textarea.displayName = "Textarea";
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Container ── */
|
|
4
|
+
.strand-toast__container {
|
|
5
|
+
position: fixed;
|
|
6
|
+
right: var(--strand-space-6);
|
|
7
|
+
bottom: var(--strand-space-6);
|
|
8
|
+
z-index: 1100;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column-reverse;
|
|
11
|
+
gap: var(--strand-space-3);
|
|
12
|
+
pointer-events: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* ── Toast ── */
|
|
16
|
+
.strand-toast {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
min-width: 280px;
|
|
21
|
+
max-width: 420px;
|
|
22
|
+
padding: var(--strand-space-4);
|
|
23
|
+
background: var(--strand-surface-elevated);
|
|
24
|
+
border-radius: var(--strand-radius-lg);
|
|
25
|
+
border-left: 4px solid transparent;
|
|
26
|
+
box-shadow: var(--strand-elevation-3);
|
|
27
|
+
font-family: var(--strand-font-sans);
|
|
28
|
+
font-size: var(--strand-text-sm);
|
|
29
|
+
pointer-events: auto;
|
|
30
|
+
animation: strand-toast-in var(--strand-duration-normal) var(--strand-ease-out-expo);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* ── Status accents ── */
|
|
34
|
+
.strand-toast--info {
|
|
35
|
+
border-left-color: var(--strand-blue-primary);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.strand-toast--success {
|
|
39
|
+
border-left-color: var(--strand-green-positive);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.strand-toast--warning {
|
|
43
|
+
border-left-color: var(--strand-amber-caution);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.strand-toast--error {
|
|
47
|
+
border-left-color: var(--strand-red-alert);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ── Message ── */
|
|
51
|
+
.strand-toast__message {
|
|
52
|
+
flex: 1;
|
|
53
|
+
min-width: 0;
|
|
54
|
+
color: var(--strand-gray-900);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* ── Dismiss button ── */
|
|
58
|
+
.strand-toast__dismiss {
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
display: inline-flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
width: 24px;
|
|
64
|
+
height: 24px;
|
|
65
|
+
margin-left: var(--strand-space-3);
|
|
66
|
+
padding: 0;
|
|
67
|
+
border: none;
|
|
68
|
+
border-radius: var(--strand-radius-md);
|
|
69
|
+
background: transparent;
|
|
70
|
+
color: var(--strand-gray-500);
|
|
71
|
+
font-size: var(--strand-text-base);
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
transition: background var(--strand-duration-fast) ease,
|
|
74
|
+
color var(--strand-duration-fast) ease;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.strand-toast__dismiss:hover {
|
|
78
|
+
background: var(--strand-gray-200);
|
|
79
|
+
color: var(--strand-gray-600);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ── Animations ── */
|
|
83
|
+
@keyframes strand-toast-in {
|
|
84
|
+
from {
|
|
85
|
+
opacity: 0;
|
|
86
|
+
transform: translateY(8px);
|
|
87
|
+
}
|
|
88
|
+
to {
|
|
89
|
+
opacity: 1;
|
|
90
|
+
transform: translateY(0);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ── Reduced motion ── */
|
|
95
|
+
@media (prefers-reduced-motion: reduce) {
|
|
96
|
+
.strand-toast {
|
|
97
|
+
animation: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.strand-toast__dismiss {
|
|
101
|
+
transition: none;
|
|
102
|
+
}
|
|
103
|
+
}
|