@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,203 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/preact";
|
|
3
|
+
import { Dialog } from "./Dialog.js";
|
|
4
|
+
|
|
5
|
+
describe("Dialog", () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
open: true,
|
|
8
|
+
onClose: vi.fn(),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.clearAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
// Ensure body overflow is restored
|
|
17
|
+
document.body.style.overflow = "";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ── Rendering ──
|
|
21
|
+
|
|
22
|
+
it("renders nothing when closed", () => {
|
|
23
|
+
const { container } = render(
|
|
24
|
+
<Dialog open={false} onClose={defaultProps.onClose}>
|
|
25
|
+
Content
|
|
26
|
+
</Dialog>,
|
|
27
|
+
);
|
|
28
|
+
expect(container.innerHTML).toBe("");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("renders dialog when open", () => {
|
|
32
|
+
const { getByRole } = render(
|
|
33
|
+
<Dialog {...defaultProps}>Content</Dialog>,
|
|
34
|
+
);
|
|
35
|
+
expect(getByRole("dialog")).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders children inside the dialog", () => {
|
|
39
|
+
const { getByRole } = render(
|
|
40
|
+
<Dialog {...defaultProps}>
|
|
41
|
+
<p>Dialog content</p>
|
|
42
|
+
</Dialog>,
|
|
43
|
+
);
|
|
44
|
+
expect(getByRole("dialog")).toHaveTextContent("Dialog content");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ── ARIA ──
|
|
48
|
+
|
|
49
|
+
it("has role dialog", () => {
|
|
50
|
+
const { getByRole } = render(
|
|
51
|
+
<Dialog {...defaultProps}>Content</Dialog>,
|
|
52
|
+
);
|
|
53
|
+
expect(getByRole("dialog")).toBeTruthy();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("has aria-modal true", () => {
|
|
57
|
+
const { getByRole } = render(
|
|
58
|
+
<Dialog {...defaultProps}>Content</Dialog>,
|
|
59
|
+
);
|
|
60
|
+
expect(getByRole("dialog")).toHaveAttribute("aria-modal", "true");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("renders title with aria-labelledby linkage", () => {
|
|
64
|
+
const { getByRole, getByText } = render(
|
|
65
|
+
<Dialog {...defaultProps} title="My Dialog">
|
|
66
|
+
Content
|
|
67
|
+
</Dialog>,
|
|
68
|
+
);
|
|
69
|
+
const dialog = getByRole("dialog");
|
|
70
|
+
const titleEl = getByText("My Dialog");
|
|
71
|
+
const titleId = titleEl.getAttribute("id");
|
|
72
|
+
expect(dialog).toHaveAttribute("aria-labelledby", titleId);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("does not set aria-labelledby when no title", () => {
|
|
76
|
+
const { getByRole } = render(
|
|
77
|
+
<Dialog {...defaultProps}>Content</Dialog>,
|
|
78
|
+
);
|
|
79
|
+
expect(getByRole("dialog").hasAttribute("aria-labelledby")).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ── Title ──
|
|
83
|
+
|
|
84
|
+
it("renders the title text", () => {
|
|
85
|
+
const { getByText } = render(
|
|
86
|
+
<Dialog {...defaultProps} title="Confirm Action">
|
|
87
|
+
Content
|
|
88
|
+
</Dialog>,
|
|
89
|
+
);
|
|
90
|
+
expect(getByText("Confirm Action")).toBeTruthy();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ── Close button ──
|
|
94
|
+
|
|
95
|
+
it("close button calls onClose", () => {
|
|
96
|
+
const onClose = vi.fn();
|
|
97
|
+
const { getByLabelText } = render(
|
|
98
|
+
<Dialog open={true} onClose={onClose}>
|
|
99
|
+
Content
|
|
100
|
+
</Dialog>,
|
|
101
|
+
);
|
|
102
|
+
fireEvent.click(getByLabelText("Close"));
|
|
103
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// ── Escape key ──
|
|
107
|
+
|
|
108
|
+
it("Escape key calls onClose", () => {
|
|
109
|
+
const onClose = vi.fn();
|
|
110
|
+
const { getByRole } = render(
|
|
111
|
+
<Dialog open={true} onClose={onClose}>
|
|
112
|
+
Content
|
|
113
|
+
</Dialog>,
|
|
114
|
+
);
|
|
115
|
+
fireEvent.keyDown(getByRole("dialog").parentElement!, {
|
|
116
|
+
key: "Escape",
|
|
117
|
+
});
|
|
118
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("Escape key does not call onClose when closeOnEscape is false", () => {
|
|
122
|
+
const onClose = vi.fn();
|
|
123
|
+
const { getByRole } = render(
|
|
124
|
+
<Dialog open={true} onClose={onClose} closeOnEscape={false}>
|
|
125
|
+
Content
|
|
126
|
+
</Dialog>,
|
|
127
|
+
);
|
|
128
|
+
fireEvent.keyDown(getByRole("dialog").parentElement!, {
|
|
129
|
+
key: "Escape",
|
|
130
|
+
});
|
|
131
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ── Outside click ──
|
|
135
|
+
|
|
136
|
+
it("clicking backdrop calls onClose", () => {
|
|
137
|
+
const onClose = vi.fn();
|
|
138
|
+
const { container } = render(
|
|
139
|
+
<Dialog open={true} onClose={onClose}>
|
|
140
|
+
Content
|
|
141
|
+
</Dialog>,
|
|
142
|
+
);
|
|
143
|
+
const backdrop = container.querySelector(".strand-dialog__backdrop")!;
|
|
144
|
+
fireEvent.click(backdrop);
|
|
145
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("clicking inside dialog does not call onClose", () => {
|
|
149
|
+
const onClose = vi.fn();
|
|
150
|
+
const { getByRole } = render(
|
|
151
|
+
<Dialog open={true} onClose={onClose}>
|
|
152
|
+
Content
|
|
153
|
+
</Dialog>,
|
|
154
|
+
);
|
|
155
|
+
fireEvent.click(getByRole("dialog"));
|
|
156
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("backdrop click disabled when closeOnOutsideClick is false", () => {
|
|
160
|
+
const onClose = vi.fn();
|
|
161
|
+
const { container } = render(
|
|
162
|
+
<Dialog open={true} onClose={onClose} closeOnOutsideClick={false}>
|
|
163
|
+
Content
|
|
164
|
+
</Dialog>,
|
|
165
|
+
);
|
|
166
|
+
const backdrop = container.querySelector(".strand-dialog__backdrop")!;
|
|
167
|
+
fireEvent.click(backdrop);
|
|
168
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ── Custom className ──
|
|
172
|
+
|
|
173
|
+
it("merges custom className", () => {
|
|
174
|
+
const { getByRole } = render(
|
|
175
|
+
<Dialog {...defaultProps} className="custom-dialog">
|
|
176
|
+
Content
|
|
177
|
+
</Dialog>,
|
|
178
|
+
);
|
|
179
|
+
const dialog = getByRole("dialog");
|
|
180
|
+
expect(dialog.className).toContain("strand-dialog__panel");
|
|
181
|
+
expect(dialog.className).toContain("custom-dialog");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ── Scroll lock ──
|
|
185
|
+
|
|
186
|
+
it("sets body overflow hidden when open", () => {
|
|
187
|
+
render(<Dialog {...defaultProps}>Content</Dialog>);
|
|
188
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("restores body overflow when closed", () => {
|
|
192
|
+
const { rerender } = render(
|
|
193
|
+
<Dialog {...defaultProps}>Content</Dialog>,
|
|
194
|
+
);
|
|
195
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
196
|
+
rerender(
|
|
197
|
+
<Dialog open={false} onClose={defaultProps.onClose}>
|
|
198
|
+
Content
|
|
199
|
+
</Dialog>,
|
|
200
|
+
);
|
|
201
|
+
expect(document.body.style.overflow).toBe("");
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
import { useEffect, useRef, useCallback } from "preact/hooks";
|
|
6
|
+
|
|
7
|
+
export interface DialogProps
|
|
8
|
+
extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "title" | "open"> {
|
|
9
|
+
/** Whether the dialog is open */
|
|
10
|
+
open: boolean;
|
|
11
|
+
/** Called when the dialog should close */
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
/** Optional title rendered in the dialog header */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Close when clicking the backdrop */
|
|
16
|
+
closeOnOutsideClick?: boolean;
|
|
17
|
+
/** Close when pressing Escape */
|
|
18
|
+
closeOnEscape?: boolean;
|
|
19
|
+
/** Dialog content */
|
|
20
|
+
children?: ComponentChildren;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const FOCUSABLE_SELECTOR =
|
|
24
|
+
'a[href], button:not(:disabled), textarea:not(:disabled), input:not(:disabled), select:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
25
|
+
|
|
26
|
+
let dialogIdCounter = 0;
|
|
27
|
+
|
|
28
|
+
export const Dialog = forwardRef<HTMLDivElement, DialogProps>(
|
|
29
|
+
(
|
|
30
|
+
{
|
|
31
|
+
open,
|
|
32
|
+
onClose,
|
|
33
|
+
title,
|
|
34
|
+
closeOnOutsideClick = true,
|
|
35
|
+
closeOnEscape = true,
|
|
36
|
+
className = "",
|
|
37
|
+
children,
|
|
38
|
+
...rest
|
|
39
|
+
},
|
|
40
|
+
ref,
|
|
41
|
+
) => {
|
|
42
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
const previousFocusRef = useRef<Element | null>(null);
|
|
44
|
+
const idRef = useRef(`strand-dialog-title-${++dialogIdCounter}`);
|
|
45
|
+
const titleId = idRef.current;
|
|
46
|
+
|
|
47
|
+
// Focus trap and focus restoration
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!open) return;
|
|
50
|
+
|
|
51
|
+
previousFocusRef.current = document.activeElement;
|
|
52
|
+
|
|
53
|
+
// Small delay to allow the DOM to render before querying focusable elements
|
|
54
|
+
const raf = requestAnimationFrame(() => {
|
|
55
|
+
const panel = panelRef.current;
|
|
56
|
+
if (!panel) return;
|
|
57
|
+
const focusable = panel.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR);
|
|
58
|
+
if (focusable.length > 0) {
|
|
59
|
+
focusable[0].focus();
|
|
60
|
+
} else {
|
|
61
|
+
panel.focus();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return () => {
|
|
66
|
+
cancelAnimationFrame(raf);
|
|
67
|
+
const prev = previousFocusRef.current;
|
|
68
|
+
if (prev && prev instanceof HTMLElement) {
|
|
69
|
+
prev.focus();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, [open]);
|
|
73
|
+
|
|
74
|
+
// Scroll lock
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!open) return;
|
|
77
|
+
|
|
78
|
+
const original = document.body.style.overflow;
|
|
79
|
+
document.body.style.overflow = "hidden";
|
|
80
|
+
|
|
81
|
+
return () => {
|
|
82
|
+
document.body.style.overflow = original;
|
|
83
|
+
};
|
|
84
|
+
}, [open]);
|
|
85
|
+
|
|
86
|
+
// Keyboard handler
|
|
87
|
+
const handleKeyDown = useCallback(
|
|
88
|
+
(e: KeyboardEvent) => {
|
|
89
|
+
if (e.key === "Escape" && closeOnEscape) {
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
onClose();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (e.key === "Tab") {
|
|
96
|
+
const panel = panelRef.current;
|
|
97
|
+
if (!panel) return;
|
|
98
|
+
|
|
99
|
+
const focusable = Array.from(
|
|
100
|
+
panel.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
|
|
101
|
+
);
|
|
102
|
+
if (focusable.length === 0) return;
|
|
103
|
+
|
|
104
|
+
const first = focusable[0];
|
|
105
|
+
const last = focusable[focusable.length - 1];
|
|
106
|
+
|
|
107
|
+
if (e.shiftKey) {
|
|
108
|
+
if (document.activeElement === first) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
last.focus();
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
if (document.activeElement === last) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
first.focus();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
[closeOnEscape, onClose],
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const handleBackdropClick = useCallback(
|
|
124
|
+
(e: MouseEvent) => {
|
|
125
|
+
if (closeOnOutsideClick && e.target === e.currentTarget) {
|
|
126
|
+
onClose();
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[closeOnOutsideClick, onClose],
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
if (!open) return null;
|
|
133
|
+
|
|
134
|
+
const classes = ["strand-dialog__panel", className]
|
|
135
|
+
.filter(Boolean)
|
|
136
|
+
.join(" ");
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
className="strand-dialog__backdrop"
|
|
141
|
+
onClick={handleBackdropClick}
|
|
142
|
+
onKeyDown={handleKeyDown}
|
|
143
|
+
>
|
|
144
|
+
<div
|
|
145
|
+
ref={(el) => {
|
|
146
|
+
(panelRef as { current: HTMLDivElement | null }).current = el;
|
|
147
|
+
if (typeof ref === "function") ref(el);
|
|
148
|
+
else if (ref) (ref as { current: HTMLDivElement | null }).current = el;
|
|
149
|
+
}}
|
|
150
|
+
className={classes}
|
|
151
|
+
role="dialog"
|
|
152
|
+
aria-modal="true"
|
|
153
|
+
aria-labelledby={title ? titleId : undefined}
|
|
154
|
+
tabIndex={-1}
|
|
155
|
+
{...rest}
|
|
156
|
+
>
|
|
157
|
+
{title && (
|
|
158
|
+
<div className="strand-dialog__header">
|
|
159
|
+
<h2 id={titleId} className="strand-dialog__title">
|
|
160
|
+
{title}
|
|
161
|
+
</h2>
|
|
162
|
+
</div>
|
|
163
|
+
)}
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
className="strand-dialog__close"
|
|
167
|
+
aria-label="Close"
|
|
168
|
+
onClick={onClose}
|
|
169
|
+
>
|
|
170
|
+
×
|
|
171
|
+
</button>
|
|
172
|
+
<div className="strand-dialog__body">{children}</div>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
Dialog.displayName = "Dialog";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-divider {
|
|
5
|
+
border: 0;
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* ── Horizontal (hr) ── */
|
|
11
|
+
.strand-divider--horizontal {
|
|
12
|
+
width: 100%;
|
|
13
|
+
border-top: 1px solid var(--strand-gray-200);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* ── Vertical ── */
|
|
17
|
+
.strand-divider--vertical {
|
|
18
|
+
align-self: stretch;
|
|
19
|
+
border-left: 1px solid var(--strand-gray-200);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* ── Labeled ── */
|
|
23
|
+
.strand-divider--labeled {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
gap: var(--strand-space-3);
|
|
27
|
+
border-top: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.strand-divider__line {
|
|
31
|
+
flex: 1;
|
|
32
|
+
height: 0;
|
|
33
|
+
border-top: 1px solid var(--strand-gray-200);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.strand-divider__label {
|
|
37
|
+
font-family: var(--strand-font-mono);
|
|
38
|
+
font-size: var(--strand-text-xs);
|
|
39
|
+
font-weight: var(--strand-weight-medium);
|
|
40
|
+
color: var(--strand-gray-400);
|
|
41
|
+
letter-spacing: var(--strand-tracking-widest);
|
|
42
|
+
text-transform: uppercase;
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/preact";
|
|
3
|
+
import { Divider } from "./Divider.js";
|
|
4
|
+
|
|
5
|
+
describe("Divider", () => {
|
|
6
|
+
// ── Rendering ──
|
|
7
|
+
|
|
8
|
+
it("renders with separator role", () => {
|
|
9
|
+
const { getByRole } = render(<Divider />);
|
|
10
|
+
expect(getByRole("separator")).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// ── Direction ──
|
|
14
|
+
|
|
15
|
+
it("renders horizontal direction by default", () => {
|
|
16
|
+
const { getByRole } = render(<Divider />);
|
|
17
|
+
expect(getByRole("separator").className).toContain(
|
|
18
|
+
"strand-divider--horizontal",
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("renders vertical direction", () => {
|
|
23
|
+
const { getByRole } = render(<Divider direction="vertical" />);
|
|
24
|
+
expect(getByRole("separator").className).toContain(
|
|
25
|
+
"strand-divider--vertical",
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// ── Aria orientation ──
|
|
30
|
+
|
|
31
|
+
it("sets aria-orientation to horizontal by default", () => {
|
|
32
|
+
const { getByRole } = render(<Divider />);
|
|
33
|
+
expect(getByRole("separator")).toHaveAttribute(
|
|
34
|
+
"aria-orientation",
|
|
35
|
+
"horizontal",
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("sets aria-orientation to vertical", () => {
|
|
40
|
+
const { getByRole } = render(<Divider direction="vertical" />);
|
|
41
|
+
expect(getByRole("separator")).toHaveAttribute(
|
|
42
|
+
"aria-orientation",
|
|
43
|
+
"vertical",
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ── Label ──
|
|
48
|
+
|
|
49
|
+
it("renders label text", () => {
|
|
50
|
+
const { getByText } = render(<Divider label="OR" />);
|
|
51
|
+
expect(getByText("OR")).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("label has monospace styling class", () => {
|
|
55
|
+
const { getByText } = render(<Divider label="SECTION" />);
|
|
56
|
+
expect(getByText("SECTION").className).toContain(
|
|
57
|
+
"strand-divider__label",
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("labeled divider still has separator role", () => {
|
|
62
|
+
const { getByRole } = render(<Divider label="OR" />);
|
|
63
|
+
expect(getByRole("separator")).toBeTruthy();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ── Custom className ──
|
|
67
|
+
|
|
68
|
+
it("merges custom className", () => {
|
|
69
|
+
const { getByRole } = render(<Divider className="custom" />);
|
|
70
|
+
const el = getByRole("separator");
|
|
71
|
+
expect(el.className).toContain("strand-divider");
|
|
72
|
+
expect(el.className).toContain("custom");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ── Element types ──
|
|
76
|
+
|
|
77
|
+
it("renders hr element for horizontal without label", () => {
|
|
78
|
+
const { getByRole } = render(<Divider />);
|
|
79
|
+
expect(getByRole("separator").tagName).toBe("HR");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("renders div element for vertical", () => {
|
|
83
|
+
const { getByRole } = render(<Divider direction="vertical" />);
|
|
84
|
+
expect(getByRole("separator").tagName).toBe("DIV");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
export interface DividerProps {
|
|
7
|
+
/** Separator direction */
|
|
8
|
+
direction?: "horizontal" | "vertical";
|
|
9
|
+
/** Optional label text displayed in the middle of the line */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Additional CSS class */
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Divider = forwardRef<HTMLElement, DividerProps>(
|
|
16
|
+
({ direction = "horizontal", label, className = "" }, ref) => {
|
|
17
|
+
const isVertical = direction === "vertical";
|
|
18
|
+
|
|
19
|
+
if (isVertical) {
|
|
20
|
+
const classes = [
|
|
21
|
+
"strand-divider",
|
|
22
|
+
"strand-divider--vertical",
|
|
23
|
+
className,
|
|
24
|
+
]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(" ");
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
ref={ref as preact.Ref<HTMLDivElement>}
|
|
31
|
+
role="separator"
|
|
32
|
+
aria-orientation="vertical"
|
|
33
|
+
className={classes}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (label) {
|
|
39
|
+
const classes = [
|
|
40
|
+
"strand-divider",
|
|
41
|
+
"strand-divider--horizontal",
|
|
42
|
+
"strand-divider--labeled",
|
|
43
|
+
className,
|
|
44
|
+
]
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.join(" ");
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div
|
|
50
|
+
ref={ref as preact.Ref<HTMLDivElement>}
|
|
51
|
+
role="separator"
|
|
52
|
+
aria-orientation="horizontal"
|
|
53
|
+
className={classes}
|
|
54
|
+
>
|
|
55
|
+
<span className="strand-divider__line" />
|
|
56
|
+
<span className="strand-divider__label">{label}</span>
|
|
57
|
+
<span className="strand-divider__line" />
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const classes = [
|
|
63
|
+
"strand-divider",
|
|
64
|
+
"strand-divider--horizontal",
|
|
65
|
+
className,
|
|
66
|
+
]
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.join(" ");
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<hr
|
|
72
|
+
ref={ref as preact.Ref<HTMLHRElement>}
|
|
73
|
+
role="separator"
|
|
74
|
+
aria-orientation="horizontal"
|
|
75
|
+
className={classes}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
Divider.displayName = "Divider";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-form-field {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
gap: var(--strand-space-1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* ── Label ── */
|
|
11
|
+
.strand-form-field__label {
|
|
12
|
+
font-family: var(--strand-font-sans);
|
|
13
|
+
font-size: var(--strand-text-sm);
|
|
14
|
+
font-weight: var(--strand-weight-medium);
|
|
15
|
+
color: var(--strand-gray-700);
|
|
16
|
+
line-height: var(--strand-leading-snug);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* ── Required indicator ── */
|
|
20
|
+
.strand-form-field__required {
|
|
21
|
+
color: var(--strand-red-alert);
|
|
22
|
+
margin-left: var(--strand-space-1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* ── Control wrapper ── */
|
|
26
|
+
.strand-form-field__control {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* ── Hint ── */
|
|
32
|
+
.strand-form-field__hint {
|
|
33
|
+
margin: 0;
|
|
34
|
+
font-family: var(--strand-font-sans);
|
|
35
|
+
font-size: var(--strand-text-xs);
|
|
36
|
+
color: var(--strand-gray-500);
|
|
37
|
+
line-height: var(--strand-leading-normal);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ── Error message ── */
|
|
41
|
+
.strand-form-field__error {
|
|
42
|
+
margin: 0;
|
|
43
|
+
font-family: var(--strand-font-sans);
|
|
44
|
+
font-size: var(--strand-text-xs);
|
|
45
|
+
color: var(--strand-red-alert);
|
|
46
|
+
line-height: var(--strand-leading-normal);
|
|
47
|
+
}
|