@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,72 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Wrapper ── */
|
|
4
|
+
.strand-badge {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
vertical-align: middle;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.strand-badge--inline {
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* ── Indicator (shared) ── */
|
|
15
|
+
.strand-badge__indicator {
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
font-family: var(--strand-font-sans);
|
|
20
|
+
font-weight: var(--strand-weight-semibold);
|
|
21
|
+
color: #fff;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Position at top-right when wrapping children */
|
|
25
|
+
.strand-badge:not(.strand-badge--inline) > .strand-badge__indicator {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 0;
|
|
28
|
+
right: 0;
|
|
29
|
+
transform: translate(50%, -50%);
|
|
30
|
+
z-index: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* ── Dot variant ── */
|
|
34
|
+
.strand-badge--dot {
|
|
35
|
+
width: 8px;
|
|
36
|
+
height: 8px;
|
|
37
|
+
border-radius: var(--strand-radius-full);
|
|
38
|
+
font-size: 0;
|
|
39
|
+
padding: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* ── Count variant ── */
|
|
43
|
+
.strand-badge--count {
|
|
44
|
+
min-width: 20px;
|
|
45
|
+
height: 20px;
|
|
46
|
+
padding: 0 var(--strand-space-1);
|
|
47
|
+
border-radius: var(--strand-radius-full);
|
|
48
|
+
font-size: var(--strand-text-xs);
|
|
49
|
+
line-height: 20px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ── Status colors ── */
|
|
53
|
+
.strand-badge--default {
|
|
54
|
+
background: var(--strand-gray-500);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.strand-badge--teal {
|
|
58
|
+
background: var(--strand-teal-vital);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.strand-badge--blue {
|
|
62
|
+
background: var(--strand-blue-primary);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.strand-badge--amber {
|
|
66
|
+
background: var(--strand-amber-caution);
|
|
67
|
+
color: var(--strand-blue-midnight);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.strand-badge--red {
|
|
71
|
+
background: var(--strand-red-alert);
|
|
72
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/preact";
|
|
3
|
+
import { Badge } from "./Badge.js";
|
|
4
|
+
|
|
5
|
+
describe("Badge", () => {
|
|
6
|
+
// ── Rendering ──
|
|
7
|
+
|
|
8
|
+
it("renders a span element", () => {
|
|
9
|
+
const { container } = render(<Badge count={5} />);
|
|
10
|
+
expect(container.firstElementChild?.tagName).toBe("SPAN");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// ── Count variant ──
|
|
14
|
+
|
|
15
|
+
it("displays count number", () => {
|
|
16
|
+
const { getByRole } = render(<Badge count={7} />);
|
|
17
|
+
expect(getByRole("status")).toHaveTextContent("7");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("truncates count at maxCount", () => {
|
|
21
|
+
const { getByRole } = render(<Badge count={150} maxCount={99} />);
|
|
22
|
+
expect(getByRole("status")).toHaveTextContent("99+");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("does not truncate count at maxCount boundary", () => {
|
|
26
|
+
const { getByRole } = render(<Badge count={99} maxCount={99} />);
|
|
27
|
+
expect(getByRole("status")).toHaveTextContent("99");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("supports custom maxCount", () => {
|
|
31
|
+
const { getByRole } = render(<Badge count={15} maxCount={9} />);
|
|
32
|
+
expect(getByRole("status")).toHaveTextContent("9+");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ── Dot variant ──
|
|
36
|
+
|
|
37
|
+
it("renders dot variant as small circle", () => {
|
|
38
|
+
const { container } = render(<Badge variant="dot" />);
|
|
39
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
40
|
+
expect(indicator?.className).toContain("strand-badge--dot");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ── Status colors ──
|
|
44
|
+
|
|
45
|
+
it("applies default status class by default", () => {
|
|
46
|
+
const { container } = render(<Badge count={1} />);
|
|
47
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
48
|
+
expect(indicator?.className).toContain("strand-badge--default");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("applies teal status class", () => {
|
|
52
|
+
const { container } = render(<Badge count={1} status="teal" />);
|
|
53
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
54
|
+
expect(indicator?.className).toContain("strand-badge--teal");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("applies red status class", () => {
|
|
58
|
+
const { container } = render(<Badge count={1} status="red" />);
|
|
59
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
60
|
+
expect(indicator?.className).toContain("strand-badge--red");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("applies amber status class", () => {
|
|
64
|
+
const { container } = render(<Badge count={1} status="amber" />);
|
|
65
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
66
|
+
expect(indicator?.className).toContain("strand-badge--amber");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("applies blue status class", () => {
|
|
70
|
+
const { container } = render(<Badge count={1} status="blue" />);
|
|
71
|
+
const indicator = container.querySelector(".strand-badge__indicator");
|
|
72
|
+
expect(indicator?.className).toContain("strand-badge--blue");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ── Children wrapping ──
|
|
76
|
+
|
|
77
|
+
it("wraps children and positions badge", () => {
|
|
78
|
+
const { getByText, container } = render(
|
|
79
|
+
<Badge count={3}>
|
|
80
|
+
<span>Inbox</span>
|
|
81
|
+
</Badge>,
|
|
82
|
+
);
|
|
83
|
+
expect(getByText("Inbox")).toBeTruthy();
|
|
84
|
+
const wrapper = container.firstElementChild;
|
|
85
|
+
expect(wrapper?.className).toContain("strand-badge");
|
|
86
|
+
expect(wrapper?.className).not.toContain("strand-badge--inline");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("renders inline without children", () => {
|
|
90
|
+
const { container } = render(<Badge count={5} />);
|
|
91
|
+
const wrapper = container.firstElementChild;
|
|
92
|
+
expect(wrapper?.className).toContain("strand-badge--inline");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ── Custom className ──
|
|
96
|
+
|
|
97
|
+
it("merges custom className", () => {
|
|
98
|
+
const { container } = render(<Badge count={1} className="custom" />);
|
|
99
|
+
const el = container.firstElementChild;
|
|
100
|
+
expect(el?.className).toContain("strand-badge");
|
|
101
|
+
expect(el?.className).toContain("custom");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// ── Accessibility ──
|
|
105
|
+
|
|
106
|
+
it("has aria-label for count variant", () => {
|
|
107
|
+
const { getByRole } = render(<Badge count={5} />);
|
|
108
|
+
expect(getByRole("status")).toHaveAttribute(
|
|
109
|
+
"aria-label",
|
|
110
|
+
"5 notifications",
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("has aria-label for dot variant", () => {
|
|
115
|
+
const { getByRole } = render(<Badge variant="dot" />);
|
|
116
|
+
expect(getByRole("status")).toHaveAttribute(
|
|
117
|
+
"aria-label",
|
|
118
|
+
"Status indicator",
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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 BadgeProps
|
|
7
|
+
extends Omit<JSX.HTMLAttributes<HTMLSpanElement>, "children"> {
|
|
8
|
+
/** Badge display mode */
|
|
9
|
+
variant?: "dot" | "count";
|
|
10
|
+
/** Color status */
|
|
11
|
+
status?: "default" | "teal" | "blue" | "amber" | "red";
|
|
12
|
+
/** Number to display (count variant only) */
|
|
13
|
+
count?: number;
|
|
14
|
+
/** Maximum count before showing "N+" */
|
|
15
|
+
maxCount?: number;
|
|
16
|
+
/** Wrapped content; when present badge is positioned at top-right */
|
|
17
|
+
children?: ComponentChildren;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
variant = "count",
|
|
24
|
+
status = "default",
|
|
25
|
+
count,
|
|
26
|
+
maxCount = 99,
|
|
27
|
+
className = "",
|
|
28
|
+
children,
|
|
29
|
+
...rest
|
|
30
|
+
},
|
|
31
|
+
ref,
|
|
32
|
+
) => {
|
|
33
|
+
const hasChildren = children != null && children !== false;
|
|
34
|
+
|
|
35
|
+
const displayValue =
|
|
36
|
+
variant === "count"
|
|
37
|
+
? count != null && count > maxCount
|
|
38
|
+
? `${maxCount}+`
|
|
39
|
+
: count
|
|
40
|
+
: null;
|
|
41
|
+
|
|
42
|
+
const ariaLabel =
|
|
43
|
+
variant === "dot"
|
|
44
|
+
? "Status indicator"
|
|
45
|
+
: count != null
|
|
46
|
+
? `${count} notifications`
|
|
47
|
+
: undefined;
|
|
48
|
+
|
|
49
|
+
const badgeClasses = [
|
|
50
|
+
"strand-badge__indicator",
|
|
51
|
+
`strand-badge--${variant}`,
|
|
52
|
+
`strand-badge--${status}`,
|
|
53
|
+
]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join(" ");
|
|
56
|
+
|
|
57
|
+
const badge = (
|
|
58
|
+
<span className={badgeClasses} aria-label={ariaLabel} role="status">
|
|
59
|
+
{displayValue}
|
|
60
|
+
</span>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!hasChildren) {
|
|
64
|
+
const inlineClasses = [
|
|
65
|
+
"strand-badge",
|
|
66
|
+
"strand-badge--inline",
|
|
67
|
+
className,
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join(" ");
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<span ref={ref} className={inlineClasses} {...rest}>
|
|
74
|
+
{badge}
|
|
75
|
+
</span>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const wrapperClasses = ["strand-badge", className]
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.join(" ");
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<span ref={ref} className={wrapperClasses} {...rest}>
|
|
85
|
+
{children}
|
|
86
|
+
{badge}
|
|
87
|
+
</span>
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
Badge.displayName = "Badge";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
.strand-breadcrumb__list {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: var(--strand-space-2);
|
|
7
|
+
list-style: none;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
font-family: var(--strand-font-sans);
|
|
11
|
+
font-size: var(--strand-text-sm);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.strand-breadcrumb__item {
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: var(--strand-space-2);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.strand-breadcrumb__separator {
|
|
21
|
+
color: var(--strand-gray-400);
|
|
22
|
+
user-select: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.strand-breadcrumb__link {
|
|
26
|
+
color: var(--strand-gray-500);
|
|
27
|
+
text-decoration: none;
|
|
28
|
+
transition: color var(--strand-duration-fast) ease;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.strand-breadcrumb__link:hover {
|
|
32
|
+
color: var(--strand-gray-600);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.strand-breadcrumb__current {
|
|
36
|
+
color: var(--strand-gray-600);
|
|
37
|
+
font-weight: var(--strand-weight-medium);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ── Reduced motion ── */
|
|
41
|
+
@media (prefers-reduced-motion: reduce) {
|
|
42
|
+
.strand-breadcrumb__link {
|
|
43
|
+
transition: none;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/preact";
|
|
3
|
+
import { Breadcrumb } from "./Breadcrumb.js";
|
|
4
|
+
|
|
5
|
+
const sampleItems = [
|
|
6
|
+
{ label: "Home", href: "/" },
|
|
7
|
+
{ label: "Products", href: "/products" },
|
|
8
|
+
{ label: "Widget" },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
describe("Breadcrumb", () => {
|
|
12
|
+
// ── Structure ──
|
|
13
|
+
|
|
14
|
+
it("renders nav with aria-label Breadcrumb", () => {
|
|
15
|
+
const { getByRole } = render(<Breadcrumb items={sampleItems} />);
|
|
16
|
+
const nav = getByRole("navigation");
|
|
17
|
+
expect(nav).toHaveAttribute("aria-label", "Breadcrumb");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("renders an ol element", () => {
|
|
21
|
+
const { container } = render(<Breadcrumb items={sampleItems} />);
|
|
22
|
+
expect(container.querySelector("ol")).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("renders all items", () => {
|
|
26
|
+
const { getAllByRole } = render(<Breadcrumb items={sampleItems} />);
|
|
27
|
+
expect(getAllByRole("listitem")).toHaveLength(3);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// ── Current page ──
|
|
31
|
+
|
|
32
|
+
it("last item has aria-current page", () => {
|
|
33
|
+
const { getByText } = render(<Breadcrumb items={sampleItems} />);
|
|
34
|
+
expect(getByText("Widget")).toHaveAttribute("aria-current", "page");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("last item is not a link", () => {
|
|
38
|
+
const { getByText } = render(<Breadcrumb items={sampleItems} />);
|
|
39
|
+
expect(getByText("Widget").tagName).toBe("SPAN");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ── Links ──
|
|
43
|
+
|
|
44
|
+
it("non-last items are rendered as links", () => {
|
|
45
|
+
const { getByText } = render(<Breadcrumb items={sampleItems} />);
|
|
46
|
+
expect(getByText("Home").tagName).toBe("A");
|
|
47
|
+
expect(getByText("Products").tagName).toBe("A");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("link items have correct href", () => {
|
|
51
|
+
const { getByText } = render(<Breadcrumb items={sampleItems} />);
|
|
52
|
+
expect(getByText("Home")).toHaveAttribute("href", "/");
|
|
53
|
+
expect(getByText("Products")).toHaveAttribute("href", "/products");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// ── Separator ──
|
|
57
|
+
|
|
58
|
+
it("renders default separator between items", () => {
|
|
59
|
+
const { container } = render(<Breadcrumb items={sampleItems} />);
|
|
60
|
+
const separators = container.querySelectorAll(
|
|
61
|
+
".strand-breadcrumb__separator",
|
|
62
|
+
);
|
|
63
|
+
expect(separators).toHaveLength(2);
|
|
64
|
+
expect(separators[0].textContent).toBe("/");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("renders custom separator", () => {
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<Breadcrumb items={sampleItems} separator=">" />,
|
|
70
|
+
);
|
|
71
|
+
const separators = container.querySelectorAll(
|
|
72
|
+
".strand-breadcrumb__separator",
|
|
73
|
+
);
|
|
74
|
+
expect(separators[0].textContent).toBe(">");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ── Custom className ──
|
|
78
|
+
|
|
79
|
+
it("merges custom className", () => {
|
|
80
|
+
const { getByRole } = render(
|
|
81
|
+
<Breadcrumb items={sampleItems} className="custom" />,
|
|
82
|
+
);
|
|
83
|
+
const nav = getByRole("navigation");
|
|
84
|
+
expect(nav.className).toContain("strand-breadcrumb");
|
|
85
|
+
expect(nav.className).toContain("custom");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ── Edge cases ──
|
|
89
|
+
|
|
90
|
+
it("single item renders correctly as current page", () => {
|
|
91
|
+
const { getByText, getAllByRole } = render(
|
|
92
|
+
<Breadcrumb items={[{ label: "Home" }]} />,
|
|
93
|
+
);
|
|
94
|
+
expect(getAllByRole("listitem")).toHaveLength(1);
|
|
95
|
+
expect(getByText("Home")).toHaveAttribute("aria-current", "page");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("separators have aria-hidden true", () => {
|
|
99
|
+
const { container } = render(<Breadcrumb items={sampleItems} />);
|
|
100
|
+
const separators = container.querySelectorAll(
|
|
101
|
+
".strand-breadcrumb__separator",
|
|
102
|
+
);
|
|
103
|
+
for (const sep of separators) {
|
|
104
|
+
expect(sep).toHaveAttribute("aria-hidden", "true");
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
export interface BreadcrumbItem {
|
|
7
|
+
label: string;
|
|
8
|
+
href?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BreadcrumbProps
|
|
12
|
+
extends Omit<JSX.HTMLAttributes<HTMLElement>, "children"> {
|
|
13
|
+
/** Breadcrumb path items; last item is treated as current page */
|
|
14
|
+
items: BreadcrumbItem[];
|
|
15
|
+
/** Separator character between items */
|
|
16
|
+
separator?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const Breadcrumb = forwardRef<HTMLElement, BreadcrumbProps>(
|
|
20
|
+
({ items, separator = "/", className = "", ...rest }, ref) => {
|
|
21
|
+
const classes = ["strand-breadcrumb", className]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join(" ");
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<nav ref={ref} aria-label="Breadcrumb" className={classes} {...rest}>
|
|
27
|
+
<ol className="strand-breadcrumb__list">
|
|
28
|
+
{items.map((item, index) => {
|
|
29
|
+
const isLast = index === items.length - 1;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<li key={`${item.label}-${index}`} className="strand-breadcrumb__item">
|
|
33
|
+
{index > 0 && (
|
|
34
|
+
<span className="strand-breadcrumb__separator" aria-hidden="true">
|
|
35
|
+
{separator}
|
|
36
|
+
</span>
|
|
37
|
+
)}
|
|
38
|
+
{isLast ? (
|
|
39
|
+
<span
|
|
40
|
+
className="strand-breadcrumb__current"
|
|
41
|
+
aria-current="page"
|
|
42
|
+
>
|
|
43
|
+
{item.label}
|
|
44
|
+
</span>
|
|
45
|
+
) : (
|
|
46
|
+
<a href={item.href} className="strand-breadcrumb__link">
|
|
47
|
+
{item.label}
|
|
48
|
+
</a>
|
|
49
|
+
)}
|
|
50
|
+
</li>
|
|
51
|
+
);
|
|
52
|
+
})}
|
|
53
|
+
</ol>
|
|
54
|
+
</nav>
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
Breadcrumb.displayName = "Breadcrumb";
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-btn {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
gap: var(--strand-space-2);
|
|
10
|
+
border: 1px solid transparent;
|
|
11
|
+
border-radius: var(--strand-radius-md);
|
|
12
|
+
font-family: var(--strand-font-sans);
|
|
13
|
+
font-weight: var(--strand-weight-medium);
|
|
14
|
+
line-height: var(--strand-leading-snug);
|
|
15
|
+
white-space: nowrap;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
user-select: none;
|
|
18
|
+
transition:
|
|
19
|
+
background var(--strand-duration-fast) ease,
|
|
20
|
+
border-color var(--strand-duration-fast) ease,
|
|
21
|
+
color var(--strand-duration-fast) ease,
|
|
22
|
+
transform var(--strand-duration-fast) var(--strand-ease-out-expo),
|
|
23
|
+
box-shadow var(--strand-duration-fast) ease;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.strand-btn:active:not(:disabled) {
|
|
27
|
+
transform: translateY(0);
|
|
28
|
+
transition-duration: 75ms;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.strand-btn:disabled {
|
|
32
|
+
opacity: 0.4;
|
|
33
|
+
cursor: not-allowed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* ── Sizes ── */
|
|
37
|
+
.strand-btn--sm {
|
|
38
|
+
padding: var(--strand-space-1) var(--strand-space-3);
|
|
39
|
+
font-size: var(--strand-text-sm);
|
|
40
|
+
min-height: 32px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.strand-btn--md {
|
|
44
|
+
padding: calc(var(--strand-space-2) + var(--strand-space-1) / 2) var(--strand-space-5);
|
|
45
|
+
font-size: var(--strand-text-sm);
|
|
46
|
+
min-height: 40px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.strand-btn--lg {
|
|
50
|
+
padding: var(--strand-space-3) var(--strand-space-6);
|
|
51
|
+
font-size: var(--strand-text-base);
|
|
52
|
+
min-height: 48px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* ── Icon-only ── */
|
|
56
|
+
.strand-btn--icon-only.strand-btn--sm {
|
|
57
|
+
padding: var(--strand-space-1);
|
|
58
|
+
min-width: 32px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.strand-btn--icon-only.strand-btn--md {
|
|
62
|
+
padding: var(--strand-space-2);
|
|
63
|
+
min-width: 40px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.strand-btn--icon-only.strand-btn--lg {
|
|
67
|
+
padding: var(--strand-space-3);
|
|
68
|
+
min-width: 48px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* ── Full width ── */
|
|
72
|
+
.strand-btn--full-width {
|
|
73
|
+
width: 100%;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ── Primary variant ── */
|
|
77
|
+
.strand-btn--primary {
|
|
78
|
+
background: var(--strand-blue-primary);
|
|
79
|
+
color: var(--strand-on-blue-primary);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.strand-btn--primary:hover:not(:disabled) {
|
|
83
|
+
background: var(--strand-blue-vivid);
|
|
84
|
+
transform: translateY(-1px);
|
|
85
|
+
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.strand-btn--primary:active:not(:disabled) {
|
|
89
|
+
background: var(--strand-blue-deep);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* ── Secondary variant ── */
|
|
93
|
+
.strand-btn--secondary {
|
|
94
|
+
background: var(--strand-surface-elevated);
|
|
95
|
+
color: var(--strand-blue-midnight);
|
|
96
|
+
border-color: var(--strand-gray-200);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.strand-btn--secondary:hover:not(:disabled) {
|
|
100
|
+
background: var(--strand-blue-glow);
|
|
101
|
+
border-color: var(--strand-blue-indicator);
|
|
102
|
+
transform: translateY(-1px);
|
|
103
|
+
box-shadow: var(--strand-elevation-1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.strand-btn--secondary:active:not(:disabled) {
|
|
107
|
+
background: var(--strand-blue-wash);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* ── Ghost variant ── */
|
|
111
|
+
.strand-btn--ghost {
|
|
112
|
+
background: transparent;
|
|
113
|
+
color: var(--strand-blue-primary);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.strand-btn--ghost:hover:not(:disabled) {
|
|
117
|
+
background: var(--strand-blue-glow);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.strand-btn--ghost:active:not(:disabled) {
|
|
121
|
+
background: var(--strand-blue-wash);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* ── Danger variant ── */
|
|
125
|
+
.strand-btn--danger {
|
|
126
|
+
background: var(--strand-red-alert);
|
|
127
|
+
color: var(--strand-on-red-alert);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.strand-btn--danger:hover:not(:disabled) {
|
|
131
|
+
background: #DC2626;
|
|
132
|
+
transform: translateY(-1px);
|
|
133
|
+
box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.strand-btn--danger:active:not(:disabled) {
|
|
137
|
+
background: #B91C1C;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* ── Loading state ── */
|
|
141
|
+
.strand-btn--loading {
|
|
142
|
+
pointer-events: none;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.strand-btn__spinner {
|
|
146
|
+
position: absolute;
|
|
147
|
+
width: 16px;
|
|
148
|
+
height: 16px;
|
|
149
|
+
border: 2px solid currentColor;
|
|
150
|
+
border-top-color: transparent;
|
|
151
|
+
border-radius: var(--strand-radius-full);
|
|
152
|
+
animation: strand-btn-spin 0.8s linear infinite;
|
|
153
|
+
opacity: 0.8;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.strand-btn--lg .strand-btn__spinner {
|
|
157
|
+
width: 20px;
|
|
158
|
+
height: 20px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@keyframes strand-btn-spin {
|
|
162
|
+
to {
|
|
163
|
+
transform: rotate(360deg);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* ── Content wrapper ── */
|
|
168
|
+
.strand-btn__content {
|
|
169
|
+
display: inline-flex;
|
|
170
|
+
align-items: center;
|
|
171
|
+
gap: var(--strand-space-2);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* ── Reduced motion ── */
|
|
175
|
+
@media (prefers-reduced-motion: reduce) {
|
|
176
|
+
.strand-btn {
|
|
177
|
+
transition: none;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.strand-btn:hover:not(:disabled) {
|
|
181
|
+
transform: none;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.strand-btn__spinner {
|
|
185
|
+
animation: none;
|
|
186
|
+
border-style: dotted;
|
|
187
|
+
}
|
|
188
|
+
}
|