@dillingerstaffing/strand-ui 0.1.0 → 0.2.0
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 +2464 -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 +25 -11
- package/src/__tests__/build-output.test.ts +200 -0
- package/src/__tests__/design-language.test.ts +137 -0
- package/src/__tests__/static.test.tsx +60 -0
- package/src/components/Alert/Alert.css +75 -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 +50 -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 +195 -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 +68 -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 +81 -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 +27 -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 +87 -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 +30 -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 +179 -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 +75 -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 +71 -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 +83 -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 +51 -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 +80 -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/static.css +47 -0
- package/src/test-setup.ts +7 -0
|
@@ -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-2);
|
|
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
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/preact";
|
|
3
|
+
import { FormField } from "./FormField.js";
|
|
4
|
+
|
|
5
|
+
describe("FormField", () => {
|
|
6
|
+
it("renders label text", () => {
|
|
7
|
+
const { getByText } = render(
|
|
8
|
+
<FormField label="Name" htmlFor="name">
|
|
9
|
+
<input id="name" />
|
|
10
|
+
</FormField>
|
|
11
|
+
);
|
|
12
|
+
expect(getByText("Name")).toBeTruthy();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("renders children (input element)", () => {
|
|
16
|
+
const { container } = render(
|
|
17
|
+
<FormField label="Name" htmlFor="name">
|
|
18
|
+
<input id="name" />
|
|
19
|
+
</FormField>
|
|
20
|
+
);
|
|
21
|
+
expect(container.querySelector("input#name")).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("shows hint text when provided", () => {
|
|
25
|
+
const { getByText } = render(
|
|
26
|
+
<FormField label="Name" htmlFor="name" hint="Enter your full name">
|
|
27
|
+
<input id="name" />
|
|
28
|
+
</FormField>
|
|
29
|
+
);
|
|
30
|
+
expect(getByText("Enter your full name")).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("shows error text when provided", () => {
|
|
34
|
+
const { getByText } = render(
|
|
35
|
+
<FormField label="Name" htmlFor="name" error="Name is required">
|
|
36
|
+
<input id="name" />
|
|
37
|
+
</FormField>
|
|
38
|
+
);
|
|
39
|
+
expect(getByText("Name is required")).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("shows required indicator when required", () => {
|
|
43
|
+
const { container } = render(
|
|
44
|
+
<FormField label="Name" htmlFor="name" required>
|
|
45
|
+
<input id="name" />
|
|
46
|
+
</FormField>
|
|
47
|
+
);
|
|
48
|
+
const indicator = container.querySelector(".strand-form-field__required");
|
|
49
|
+
expect(indicator).toBeTruthy();
|
|
50
|
+
expect(indicator!.textContent).toBe("*");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("error replaces hint when both are present", () => {
|
|
54
|
+
const { queryByText } = render(
|
|
55
|
+
<FormField
|
|
56
|
+
label="Name"
|
|
57
|
+
htmlFor="name"
|
|
58
|
+
hint="Enter your full name"
|
|
59
|
+
error="Name is required"
|
|
60
|
+
>
|
|
61
|
+
<input id="name" />
|
|
62
|
+
</FormField>
|
|
63
|
+
);
|
|
64
|
+
expect(queryByText("Name is required")).toBeTruthy();
|
|
65
|
+
expect(queryByText("Enter your full name")).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("label has htmlFor attribute", () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<FormField label="Email" htmlFor="email">
|
|
71
|
+
<input id="email" />
|
|
72
|
+
</FormField>
|
|
73
|
+
);
|
|
74
|
+
const label = container.querySelector("label");
|
|
75
|
+
expect(label).toHaveAttribute("for", "email");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("applies error class when error is present", () => {
|
|
79
|
+
const { container } = render(
|
|
80
|
+
<FormField label="Name" htmlFor="name" error="Required">
|
|
81
|
+
<input id="name" />
|
|
82
|
+
</FormField>
|
|
83
|
+
);
|
|
84
|
+
expect(
|
|
85
|
+
container.querySelector(".strand-form-field--error")
|
|
86
|
+
).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("merges custom className", () => {
|
|
90
|
+
const { container } = render(
|
|
91
|
+
<FormField label="Name" htmlFor="name" className="custom">
|
|
92
|
+
<input id="name" />
|
|
93
|
+
</FormField>
|
|
94
|
+
);
|
|
95
|
+
const wrapper = container.querySelector(".strand-form-field");
|
|
96
|
+
expect(wrapper?.className).toContain("strand-form-field");
|
|
97
|
+
expect(wrapper?.className).toContain("custom");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { ComponentChildren } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
export interface FormFieldProps {
|
|
7
|
+
/** Label text */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Associates the label with a form control */
|
|
10
|
+
htmlFor: string;
|
|
11
|
+
/** Hint text displayed below the input */
|
|
12
|
+
hint?: string;
|
|
13
|
+
/** Error text displayed below the input (replaces hint) */
|
|
14
|
+
error?: string;
|
|
15
|
+
/** Show required indicator */
|
|
16
|
+
required?: boolean;
|
|
17
|
+
/** Additional CSS classes */
|
|
18
|
+
className?: string;
|
|
19
|
+
/** The wrapped form control */
|
|
20
|
+
children: ComponentChildren;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const FormField = forwardRef<HTMLDivElement, FormFieldProps>(
|
|
24
|
+
(
|
|
25
|
+
{
|
|
26
|
+
label,
|
|
27
|
+
htmlFor,
|
|
28
|
+
hint,
|
|
29
|
+
error,
|
|
30
|
+
required = false,
|
|
31
|
+
className = "",
|
|
32
|
+
children,
|
|
33
|
+
},
|
|
34
|
+
ref,
|
|
35
|
+
) => {
|
|
36
|
+
const classes = [
|
|
37
|
+
"strand-form-field",
|
|
38
|
+
error && "strand-form-field--error",
|
|
39
|
+
className,
|
|
40
|
+
]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join(" ");
|
|
43
|
+
|
|
44
|
+
const messageId = error
|
|
45
|
+
? `${htmlFor}-error`
|
|
46
|
+
: hint
|
|
47
|
+
? `${htmlFor}-hint`
|
|
48
|
+
: undefined;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div ref={ref} className={classes}>
|
|
52
|
+
<label className="strand-form-field__label" htmlFor={htmlFor}>
|
|
53
|
+
{label}
|
|
54
|
+
{required && (
|
|
55
|
+
<span className="strand-form-field__required" aria-hidden="true">
|
|
56
|
+
*
|
|
57
|
+
</span>
|
|
58
|
+
)}
|
|
59
|
+
</label>
|
|
60
|
+
<div className="strand-form-field__control">{children}</div>
|
|
61
|
+
{error ? (
|
|
62
|
+
<p
|
|
63
|
+
className="strand-form-field__error"
|
|
64
|
+
id={`${htmlFor}-error`}
|
|
65
|
+
role="alert"
|
|
66
|
+
>
|
|
67
|
+
{error}
|
|
68
|
+
</p>
|
|
69
|
+
) : hint ? (
|
|
70
|
+
<p className="strand-form-field__hint" id={`${htmlFor}-hint`}>
|
|
71
|
+
{hint}
|
|
72
|
+
</p>
|
|
73
|
+
) : null}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
FormField.displayName = "FormField";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
/* ── Base ── */
|
|
4
|
+
.strand-grid {
|
|
5
|
+
display: grid;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
max-width: 100%;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.strand-grid > * {
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* ── Column utilities ── */
|
|
16
|
+
.strand-grid--cols-2 { grid-template-columns: repeat(2, 1fr); }
|
|
17
|
+
.strand-grid--cols-3 { grid-template-columns: repeat(3, 1fr); }
|
|
18
|
+
.strand-grid--cols-4 { grid-template-columns: repeat(4, 1fr); }
|
|
19
|
+
|
|
20
|
+
/* ── Gap utilities ── */
|
|
21
|
+
.strand-grid--gap-1 { gap: var(--strand-space-1); }
|
|
22
|
+
.strand-grid--gap-2 { gap: var(--strand-space-2); }
|
|
23
|
+
.strand-grid--gap-3 { gap: var(--strand-space-3); }
|
|
24
|
+
.strand-grid--gap-4 { gap: var(--strand-space-4); }
|
|
25
|
+
.strand-grid--gap-5 { gap: var(--strand-space-5); }
|
|
26
|
+
.strand-grid--gap-6 { gap: var(--strand-space-6); }
|
|
27
|
+
.strand-grid--gap-8 { gap: var(--strand-space-8); }
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render } from "@testing-library/preact";
|
|
3
|
+
import { Grid } from "./Grid.js";
|
|
4
|
+
|
|
5
|
+
describe("Grid", () => {
|
|
6
|
+
// ── Rendering ──
|
|
7
|
+
|
|
8
|
+
it("renders a div element", () => {
|
|
9
|
+
const { container } = render(<Grid>content</Grid>);
|
|
10
|
+
expect(container.firstElementChild?.tagName).toBe("DIV");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("renders children in grid", () => {
|
|
14
|
+
const { getByText } = render(
|
|
15
|
+
<Grid>
|
|
16
|
+
<div>Item 1</div>
|
|
17
|
+
<div>Item 2</div>
|
|
18
|
+
<div>Item 3</div>
|
|
19
|
+
</Grid>,
|
|
20
|
+
);
|
|
21
|
+
expect(getByText("Item 1")).toBeTruthy();
|
|
22
|
+
expect(getByText("Item 2")).toBeTruthy();
|
|
23
|
+
expect(getByText("Item 3")).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ── Display ──
|
|
27
|
+
|
|
28
|
+
it("has display grid class", () => {
|
|
29
|
+
const { container } = render(<Grid>content</Grid>);
|
|
30
|
+
expect(container.firstElementChild?.className).toContain("strand-grid");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// ── Columns ──
|
|
34
|
+
|
|
35
|
+
it("defaults to 1 column in inline style", () => {
|
|
36
|
+
const { container } = render(<Grid>content</Grid>);
|
|
37
|
+
const el = container.firstElementChild as HTMLElement;
|
|
38
|
+
expect(el.style.gridTemplateColumns).toBe("repeat(1, 1fr)");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("applies custom column count in inline style", () => {
|
|
42
|
+
const { container } = render(<Grid columns={3}>content</Grid>);
|
|
43
|
+
const el = container.firstElementChild as HTMLElement;
|
|
44
|
+
expect(el.style.gridTemplateColumns).toBe("repeat(3, 1fr)");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("applies 4-column layout", () => {
|
|
48
|
+
const { container } = render(<Grid columns={4}>content</Grid>);
|
|
49
|
+
const el = container.firstElementChild as HTMLElement;
|
|
50
|
+
expect(el.style.gridTemplateColumns).toBe("repeat(4, 1fr)");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ── Gap ──
|
|
54
|
+
|
|
55
|
+
it("applies default gap as inline style", () => {
|
|
56
|
+
const { container } = render(<Grid>content</Grid>);
|
|
57
|
+
const el = container.firstElementChild as HTMLElement;
|
|
58
|
+
expect(el.style.gap).toBe("var(--strand-space-4)");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("applies custom gap as inline style", () => {
|
|
62
|
+
const { container } = render(<Grid gap={8}>content</Grid>);
|
|
63
|
+
const el = container.firstElementChild as HTMLElement;
|
|
64
|
+
expect(el.style.gap).toBe("var(--strand-space-8)");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// ── Custom className ──
|
|
68
|
+
|
|
69
|
+
it("merges custom className", () => {
|
|
70
|
+
const { container } = render(<Grid className="custom">content</Grid>);
|
|
71
|
+
const el = container.firstElementChild;
|
|
72
|
+
expect(el?.className).toContain("strand-grid");
|
|
73
|
+
expect(el?.className).toContain("custom");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ── Props forwarding ──
|
|
77
|
+
|
|
78
|
+
it("forwards additional props", () => {
|
|
79
|
+
const { container } = render(
|
|
80
|
+
<Grid data-testid="my-grid" id="g1">
|
|
81
|
+
content
|
|
82
|
+
</Grid>,
|
|
83
|
+
);
|
|
84
|
+
expect(container.firstElementChild).toHaveAttribute("id", "g1");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
import type { JSX } from "preact";
|
|
4
|
+
import { forwardRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
export interface GridProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
/** Number of equal-width columns */
|
|
8
|
+
columns?: number;
|
|
9
|
+
/** Gap between items, maps to --strand-space-{n} */
|
|
10
|
+
gap?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Grid = forwardRef<HTMLDivElement, GridProps>(
|
|
14
|
+
(
|
|
15
|
+
{
|
|
16
|
+
columns = 1,
|
|
17
|
+
gap = 4,
|
|
18
|
+
className = "",
|
|
19
|
+
style,
|
|
20
|
+
children,
|
|
21
|
+
...rest
|
|
22
|
+
},
|
|
23
|
+
ref,
|
|
24
|
+
) => {
|
|
25
|
+
const classes = ["strand-grid", className].filter(Boolean).join(" ");
|
|
26
|
+
|
|
27
|
+
const inlineStyle: Record<string, string> = {
|
|
28
|
+
gridTemplateColumns: `repeat(${columns}, 1fr)`,
|
|
29
|
+
gap: `var(--strand-space-${gap})`,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
ref={ref}
|
|
35
|
+
className={classes}
|
|
36
|
+
style={{ ...inlineStyle, ...(style as Record<string, string>) }}
|
|
37
|
+
{...rest}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
Grid.displayName = "Grid";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*! Strand UI | MIT License | dillingerstaffing.com */
|
|
2
|
+
|
|
3
|
+
.strand-input {
|
|
4
|
+
position: relative;
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
background: var(--strand-surface-elevated);
|
|
8
|
+
border: 1px solid var(--strand-gray-200);
|
|
9
|
+
border-radius: var(--strand-radius-md);
|
|
10
|
+
transition:
|
|
11
|
+
border-color var(--strand-duration-fast) var(--strand-ease-out-quart),
|
|
12
|
+
box-shadow var(--strand-duration-fast) var(--strand-ease-out-quart);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.strand-input:focus-within {
|
|
16
|
+
border-color: var(--strand-blue-primary);
|
|
17
|
+
box-shadow: var(--strand-focus-ring);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* ── Field ── */
|
|
21
|
+
.strand-input__field {
|
|
22
|
+
flex: 1;
|
|
23
|
+
width: 100%;
|
|
24
|
+
padding: var(--strand-space-3) var(--strand-space-4);
|
|
25
|
+
background: transparent;
|
|
26
|
+
border: none;
|
|
27
|
+
font-family: var(--strand-font-sans);
|
|
28
|
+
font-size: var(--strand-text-base);
|
|
29
|
+
color: var(--strand-gray-900);
|
|
30
|
+
outline: none;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.strand-input__field::placeholder {
|
|
34
|
+
color: var(--strand-gray-400);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ── Addons ── */
|
|
38
|
+
.strand-input__leading,
|
|
39
|
+
.strand-input__trailing {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
color: var(--strand-gray-500);
|
|
43
|
+
font-size: var(--strand-text-sm);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.strand-input__leading {
|
|
47
|
+
padding-left: var(--strand-space-3);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.strand-input__trailing {
|
|
51
|
+
padding-right: var(--strand-space-3);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.strand-input--has-leading .strand-input__field {
|
|
55
|
+
padding-left: var(--strand-space-2);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.strand-input--has-trailing .strand-input__field {
|
|
59
|
+
padding-right: var(--strand-space-2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* ── Error ── */
|
|
63
|
+
.strand-input--error {
|
|
64
|
+
border-color: var(--strand-red-alert);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.strand-input--error:focus-within {
|
|
68
|
+
border-color: var(--strand-red-alert);
|
|
69
|
+
box-shadow: var(--strand-focus-ring-error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* ── Disabled ── */
|
|
73
|
+
.strand-input--disabled {
|
|
74
|
+
opacity: 0.4;
|
|
75
|
+
cursor: not-allowed;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.strand-input--disabled .strand-input__field {
|
|
79
|
+
cursor: not-allowed;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ── Reduced motion ── */
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
.strand-input {
|
|
85
|
+
transition: none;
|
|
86
|
+
}
|
|
87
|
+
}
|