@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.
Files changed (261) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/Alert/Alert.d.ts +16 -0
  3. package/dist/components/Alert/Alert.d.ts.map +1 -0
  4. package/dist/components/Alert/index.d.ts +3 -0
  5. package/dist/components/Alert/index.d.ts.map +1 -0
  6. package/dist/components/Avatar/Avatar.d.ts +16 -0
  7. package/dist/components/Avatar/Avatar.d.ts.map +1 -0
  8. package/dist/components/Avatar/index.d.ts +3 -0
  9. package/dist/components/Avatar/index.d.ts.map +1 -0
  10. package/dist/components/Badge/Badge.d.ts +18 -0
  11. package/dist/components/Badge/Badge.d.ts.map +1 -0
  12. package/dist/components/Badge/index.d.ts +3 -0
  13. package/dist/components/Badge/index.d.ts.map +1 -0
  14. package/dist/components/Breadcrumb/Breadcrumb.d.ts +16 -0
  15. package/dist/components/Breadcrumb/Breadcrumb.d.ts.map +1 -0
  16. package/dist/components/Breadcrumb/index.d.ts +3 -0
  17. package/dist/components/Breadcrumb/index.d.ts.map +1 -0
  18. package/dist/components/Button/Button.d.ts +22 -0
  19. package/dist/components/Button/Button.d.ts.map +1 -0
  20. package/dist/components/Button/index.d.ts +3 -0
  21. package/dist/components/Button/index.d.ts.map +1 -0
  22. package/dist/components/Card/Card.d.ts +12 -0
  23. package/dist/components/Card/Card.d.ts.map +1 -0
  24. package/dist/components/Card/index.d.ts +3 -0
  25. package/dist/components/Card/index.d.ts.map +1 -0
  26. package/dist/components/Checkbox/Checkbox.d.ts +20 -0
  27. package/dist/components/Checkbox/Checkbox.d.ts.map +1 -0
  28. package/dist/components/Checkbox/index.d.ts +3 -0
  29. package/dist/components/Checkbox/index.d.ts.map +1 -0
  30. package/dist/components/Container/Container.d.ts +10 -0
  31. package/dist/components/Container/Container.d.ts.map +1 -0
  32. package/dist/components/Container/index.d.ts +3 -0
  33. package/dist/components/Container/index.d.ts.map +1 -0
  34. package/dist/components/DataReadout/DataReadout.d.ts +12 -0
  35. package/dist/components/DataReadout/DataReadout.d.ts.map +1 -0
  36. package/dist/components/DataReadout/index.d.ts +3 -0
  37. package/dist/components/DataReadout/index.d.ts.map +1 -0
  38. package/dist/components/Dialog/Dialog.d.ts +20 -0
  39. package/dist/components/Dialog/Dialog.d.ts.map +1 -0
  40. package/dist/components/Dialog/index.d.ts +3 -0
  41. package/dist/components/Dialog/index.d.ts.map +1 -0
  42. package/dist/components/Divider/Divider.d.ts +13 -0
  43. package/dist/components/Divider/Divider.d.ts.map +1 -0
  44. package/dist/components/Divider/index.d.ts +3 -0
  45. package/dist/components/Divider/index.d.ts.map +1 -0
  46. package/dist/components/FormField/FormField.d.ts +22 -0
  47. package/dist/components/FormField/FormField.d.ts.map +1 -0
  48. package/dist/components/FormField/index.d.ts +3 -0
  49. package/dist/components/FormField/index.d.ts.map +1 -0
  50. package/dist/components/Grid/Grid.d.ts +12 -0
  51. package/dist/components/Grid/Grid.d.ts.map +1 -0
  52. package/dist/components/Grid/index.d.ts +3 -0
  53. package/dist/components/Grid/index.d.ts.map +1 -0
  54. package/dist/components/Input/Input.d.ts +18 -0
  55. package/dist/components/Input/Input.d.ts.map +1 -0
  56. package/dist/components/Input/index.d.ts +3 -0
  57. package/dist/components/Input/index.d.ts.map +1 -0
  58. package/dist/components/Link/Link.d.ts +12 -0
  59. package/dist/components/Link/Link.d.ts.map +1 -0
  60. package/dist/components/Link/index.d.ts +3 -0
  61. package/dist/components/Link/index.d.ts.map +1 -0
  62. package/dist/components/Nav/Nav.d.ts +19 -0
  63. package/dist/components/Nav/Nav.d.ts.map +1 -0
  64. package/dist/components/Nav/index.d.ts +3 -0
  65. package/dist/components/Nav/index.d.ts.map +1 -0
  66. package/dist/components/Progress/Progress.d.ts +14 -0
  67. package/dist/components/Progress/Progress.d.ts.map +1 -0
  68. package/dist/components/Progress/index.d.ts +3 -0
  69. package/dist/components/Progress/index.d.ts.map +1 -0
  70. package/dist/components/Radio/Radio.d.ts +22 -0
  71. package/dist/components/Radio/Radio.d.ts.map +1 -0
  72. package/dist/components/Radio/index.d.ts +3 -0
  73. package/dist/components/Radio/index.d.ts.map +1 -0
  74. package/dist/components/Section/Section.d.ts +12 -0
  75. package/dist/components/Section/Section.d.ts.map +1 -0
  76. package/dist/components/Section/index.d.ts +3 -0
  77. package/dist/components/Section/index.d.ts.map +1 -0
  78. package/dist/components/Select/Select.d.ts +24 -0
  79. package/dist/components/Select/Select.d.ts.map +1 -0
  80. package/dist/components/Select/index.d.ts +3 -0
  81. package/dist/components/Select/index.d.ts.map +1 -0
  82. package/dist/components/Skeleton/Skeleton.d.ts +14 -0
  83. package/dist/components/Skeleton/Skeleton.d.ts.map +1 -0
  84. package/dist/components/Skeleton/index.d.ts +3 -0
  85. package/dist/components/Skeleton/index.d.ts.map +1 -0
  86. package/dist/components/Slider/Slider.d.ts +20 -0
  87. package/dist/components/Slider/Slider.d.ts.map +1 -0
  88. package/dist/components/Slider/index.d.ts +3 -0
  89. package/dist/components/Slider/index.d.ts.map +1 -0
  90. package/dist/components/Spinner/Spinner.d.ts +10 -0
  91. package/dist/components/Spinner/Spinner.d.ts.map +1 -0
  92. package/dist/components/Spinner/index.d.ts +3 -0
  93. package/dist/components/Spinner/index.d.ts.map +1 -0
  94. package/dist/components/Stack/Stack.d.ts +18 -0
  95. package/dist/components/Stack/Stack.d.ts.map +1 -0
  96. package/dist/components/Stack/index.d.ts +3 -0
  97. package/dist/components/Stack/index.d.ts.map +1 -0
  98. package/dist/components/Switch/Switch.d.ts +18 -0
  99. package/dist/components/Switch/Switch.d.ts.map +1 -0
  100. package/dist/components/Switch/index.d.ts +3 -0
  101. package/dist/components/Switch/index.d.ts.map +1 -0
  102. package/dist/components/Table/Table.d.ts +24 -0
  103. package/dist/components/Table/Table.d.ts.map +1 -0
  104. package/dist/components/Table/index.d.ts +3 -0
  105. package/dist/components/Table/index.d.ts.map +1 -0
  106. package/dist/components/Tabs/Tabs.d.ts +19 -0
  107. package/dist/components/Tabs/Tabs.d.ts.map +1 -0
  108. package/dist/components/Tabs/index.d.ts +3 -0
  109. package/dist/components/Tabs/index.d.ts.map +1 -0
  110. package/dist/components/Tag/Tag.d.ts +18 -0
  111. package/dist/components/Tag/Tag.d.ts.map +1 -0
  112. package/dist/components/Tag/index.d.ts +3 -0
  113. package/dist/components/Tag/index.d.ts.map +1 -0
  114. package/dist/components/Textarea/Textarea.d.ts +22 -0
  115. package/dist/components/Textarea/Textarea.d.ts.map +1 -0
  116. package/dist/components/Textarea/index.d.ts +3 -0
  117. package/dist/components/Textarea/index.d.ts.map +1 -0
  118. package/dist/components/Toast/Toast.d.ts +33 -0
  119. package/dist/components/Toast/Toast.d.ts.map +1 -0
  120. package/dist/components/Toast/index.d.ts +3 -0
  121. package/dist/components/Toast/index.d.ts.map +1 -0
  122. package/dist/components/Tooltip/Tooltip.d.ts +16 -0
  123. package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
  124. package/dist/components/Tooltip/index.d.ts +3 -0
  125. package/dist/components/Tooltip/index.d.ts.map +1 -0
  126. package/dist/css/strand-ui.css +2464 -0
  127. package/dist/index.d.ts +64 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/test-setup.d.ts +2 -0
  130. package/dist/test-setup.d.ts.map +1 -0
  131. package/package.json +25 -11
  132. package/src/__tests__/build-output.test.ts +200 -0
  133. package/src/__tests__/design-language.test.ts +137 -0
  134. package/src/__tests__/static.test.tsx +60 -0
  135. package/src/components/Alert/Alert.css +75 -0
  136. package/src/components/Alert/Alert.test.tsx +92 -0
  137. package/src/components/Alert/Alert.tsx +59 -0
  138. package/src/components/Alert/index.ts +2 -0
  139. package/src/components/Avatar/Avatar.css +55 -0
  140. package/src/components/Avatar/Avatar.test.tsx +123 -0
  141. package/src/components/Avatar/Avatar.tsx +67 -0
  142. package/src/components/Avatar/index.ts +2 -0
  143. package/src/components/Badge/Badge.css +72 -0
  144. package/src/components/Badge/Badge.test.tsx +121 -0
  145. package/src/components/Badge/Badge.tsx +92 -0
  146. package/src/components/Badge/index.ts +2 -0
  147. package/src/components/Breadcrumb/Breadcrumb.css +50 -0
  148. package/src/components/Breadcrumb/Breadcrumb.test.tsx +107 -0
  149. package/src/components/Breadcrumb/Breadcrumb.tsx +59 -0
  150. package/src/components/Breadcrumb/index.ts +2 -0
  151. package/src/components/Button/Button.css +195 -0
  152. package/src/components/Button/Button.test.tsx +171 -0
  153. package/src/components/Button/Button.tsx +78 -0
  154. package/src/components/Button/index.ts +2 -0
  155. package/src/components/Card/Card.css +68 -0
  156. package/src/components/Card/Card.test.tsx +90 -0
  157. package/src/components/Card/Card.tsx +41 -0
  158. package/src/components/Card/index.ts +2 -0
  159. package/src/components/Checkbox/Checkbox.css +97 -0
  160. package/src/components/Checkbox/Checkbox.test.tsx +92 -0
  161. package/src/components/Checkbox/Checkbox.tsx +137 -0
  162. package/src/components/Checkbox/index.ts +2 -0
  163. package/src/components/Container/Container.css +25 -0
  164. package/src/components/Container/Container.test.tsx +82 -0
  165. package/src/components/Container/Container.tsx +37 -0
  166. package/src/components/Container/index.ts +2 -0
  167. package/src/components/DataReadout/DataReadout.css +30 -0
  168. package/src/components/DataReadout/DataReadout.test.tsx +105 -0
  169. package/src/components/DataReadout/DataReadout.tsx +29 -0
  170. package/src/components/DataReadout/index.ts +2 -0
  171. package/src/components/Dialog/Dialog.css +81 -0
  172. package/src/components/Dialog/Dialog.test.tsx +203 -0
  173. package/src/components/Dialog/Dialog.tsx +179 -0
  174. package/src/components/Dialog/index.ts +2 -0
  175. package/src/components/Divider/Divider.css +44 -0
  176. package/src/components/Divider/Divider.test.tsx +86 -0
  177. package/src/components/Divider/Divider.tsx +81 -0
  178. package/src/components/Divider/index.ts +2 -0
  179. package/src/components/FormField/FormField.css +47 -0
  180. package/src/components/FormField/FormField.test.tsx +99 -0
  181. package/src/components/FormField/FormField.tsx +79 -0
  182. package/src/components/FormField/index.ts +2 -0
  183. package/src/components/Grid/Grid.css +27 -0
  184. package/src/components/Grid/Grid.test.tsx +86 -0
  185. package/src/components/Grid/Grid.tsx +45 -0
  186. package/src/components/Grid/index.ts +2 -0
  187. package/src/components/Input/Input.css +87 -0
  188. package/src/components/Input/Input.test.tsx +95 -0
  189. package/src/components/Input/Input.tsx +69 -0
  190. package/src/components/Input/index.ts +2 -0
  191. package/src/components/Link/Link.css +30 -0
  192. package/src/components/Link/Link.test.tsx +88 -0
  193. package/src/components/Link/Link.tsx +31 -0
  194. package/src/components/Link/index.ts +2 -0
  195. package/src/components/Nav/Nav.css +179 -0
  196. package/src/components/Nav/Nav.test.tsx +174 -0
  197. package/src/components/Nav/Nav.tsx +101 -0
  198. package/src/components/Nav/index.ts +2 -0
  199. package/src/components/Progress/Progress.css +93 -0
  200. package/src/components/Progress/Progress.test.tsx +93 -0
  201. package/src/components/Progress/Progress.tsx +104 -0
  202. package/src/components/Progress/index.ts +2 -0
  203. package/src/components/Radio/Radio.css +98 -0
  204. package/src/components/Radio/Radio.test.tsx +80 -0
  205. package/src/components/Radio/Radio.tsx +72 -0
  206. package/src/components/Radio/index.ts +2 -0
  207. package/src/components/Section/Section.css +28 -0
  208. package/src/components/Section/Section.test.tsx +100 -0
  209. package/src/components/Section/Section.tsx +41 -0
  210. package/src/components/Section/index.ts +2 -0
  211. package/src/components/Select/Select.css +75 -0
  212. package/src/components/Select/Select.test.tsx +99 -0
  213. package/src/components/Select/Select.tsx +78 -0
  214. package/src/components/Select/index.ts +2 -0
  215. package/src/components/Skeleton/Skeleton.css +52 -0
  216. package/src/components/Skeleton/Skeleton.test.tsx +96 -0
  217. package/src/components/Skeleton/Skeleton.tsx +55 -0
  218. package/src/components/Skeleton/index.ts +2 -0
  219. package/src/components/Slider/Slider.css +107 -0
  220. package/src/components/Slider/Slider.test.tsx +85 -0
  221. package/src/components/Slider/Slider.tsx +66 -0
  222. package/src/components/Slider/index.ts +2 -0
  223. package/src/components/Spinner/Spinner.css +61 -0
  224. package/src/components/Spinner/Spinner.test.tsx +56 -0
  225. package/src/components/Spinner/Spinner.tsx +38 -0
  226. package/src/components/Spinner/index.ts +2 -0
  227. package/src/components/Stack/Stack.css +71 -0
  228. package/src/components/Stack/Stack.test.tsx +130 -0
  229. package/src/components/Stack/Stack.tsx +77 -0
  230. package/src/components/Stack/index.ts +2 -0
  231. package/src/components/Switch/Switch.css +94 -0
  232. package/src/components/Switch/Switch.test.tsx +98 -0
  233. package/src/components/Switch/Switch.tsx +80 -0
  234. package/src/components/Switch/index.ts +2 -0
  235. package/src/components/Table/Table.css +83 -0
  236. package/src/components/Table/Table.test.tsx +134 -0
  237. package/src/components/Table/Table.tsx +102 -0
  238. package/src/components/Table/index.ts +2 -0
  239. package/src/components/Tabs/Tabs.css +51 -0
  240. package/src/components/Tabs/Tabs.test.tsx +164 -0
  241. package/src/components/Tabs/Tabs.tsx +126 -0
  242. package/src/components/Tabs/index.ts +2 -0
  243. package/src/components/Tag/Tag.css +98 -0
  244. package/src/components/Tag/Tag.test.tsx +112 -0
  245. package/src/components/Tag/Tag.tsx +73 -0
  246. package/src/components/Tag/index.ts +2 -0
  247. package/src/components/Textarea/Textarea.css +80 -0
  248. package/src/components/Textarea/Textarea.test.tsx +89 -0
  249. package/src/components/Textarea/Textarea.tsx +102 -0
  250. package/src/components/Textarea/index.ts +2 -0
  251. package/src/components/Toast/Toast.css +103 -0
  252. package/src/components/Toast/Toast.test.tsx +219 -0
  253. package/src/components/Toast/Toast.tsx +177 -0
  254. package/src/components/Toast/index.ts +2 -0
  255. package/src/components/Tooltip/Tooltip.css +63 -0
  256. package/src/components/Tooltip/Tooltip.test.tsx +196 -0
  257. package/src/components/Tooltip/Tooltip.tsx +89 -0
  258. package/src/components/Tooltip/index.ts +2 -0
  259. package/src/index.ts +99 -0
  260. package/src/static.css +47 -0
  261. package/src/test-setup.ts +7 -0
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { render, fireEvent } from "@testing-library/preact";
3
+ import { Input } from "./Input.js";
4
+
5
+ describe("Input", () => {
6
+ it("renders an input element", () => {
7
+ const { getByRole } = render(<Input aria-label="Name" />);
8
+ expect(getByRole("textbox")).toBeTruthy();
9
+ });
10
+
11
+ it("defaults to type text", () => {
12
+ const { getByRole } = render(<Input aria-label="Name" />);
13
+ expect(getByRole("textbox")).toHaveAttribute("type", "text");
14
+ });
15
+
16
+ it("accepts type email", () => {
17
+ const { container } = render(<Input type="email" aria-label="Email" />);
18
+ expect(container.querySelector("input")).toHaveAttribute("type", "email");
19
+ });
20
+
21
+ it("accepts type password", () => {
22
+ const { container } = render(<Input type="password" aria-label="Password" />);
23
+ expect(container.querySelector("input")).toHaveAttribute("type", "password");
24
+ });
25
+
26
+ it("accepts type number", () => {
27
+ const { container } = render(<Input type="number" aria-label="Count" />);
28
+ expect(container.querySelector("input")).toHaveAttribute("type", "number");
29
+ });
30
+
31
+ it("accepts type search", () => {
32
+ const { getByRole } = render(<Input type="search" aria-label="Search" />);
33
+ expect(getByRole("searchbox")).toBeTruthy();
34
+ });
35
+
36
+ it("renders placeholder text", () => {
37
+ const { getByPlaceholderText } = render(
38
+ <Input placeholder="Enter name" aria-label="Name" />
39
+ );
40
+ expect(getByPlaceholderText("Enter name")).toBeTruthy();
41
+ });
42
+
43
+ it("calls onChange when value changes", () => {
44
+ const onChange = vi.fn();
45
+ const { getByRole } = render(
46
+ <Input aria-label="Name" onChange={onChange} />
47
+ );
48
+ fireEvent.input(getByRole("textbox"), { target: { value: "hello" } });
49
+ expect(onChange).toHaveBeenCalled();
50
+ });
51
+
52
+ it("sets disabled attribute", () => {
53
+ const { getByRole } = render(<Input aria-label="Name" disabled />);
54
+ expect(getByRole("textbox")).toBeDisabled();
55
+ });
56
+
57
+ it("applies error class when error prop is true", () => {
58
+ const { container } = render(<Input aria-label="Name" error />);
59
+ expect(container.querySelector(".strand-input--error")).toBeTruthy();
60
+ });
61
+
62
+ it("sets aria-invalid when error is true", () => {
63
+ const { getByRole } = render(<Input aria-label="Name" error />);
64
+ expect(getByRole("textbox")).toHaveAttribute("aria-invalid", "true");
65
+ });
66
+
67
+ it("renders leading addon", () => {
68
+ const { container } = render(
69
+ <Input aria-label="Amount" leadingAddon={<span>$</span>} />
70
+ );
71
+ expect(container.querySelector(".strand-input__leading")).toBeTruthy();
72
+ });
73
+
74
+ it("renders trailing addon", () => {
75
+ const { container } = render(
76
+ <Input aria-label="Weight" trailingAddon={<span>kg</span>} />
77
+ );
78
+ expect(container.querySelector(".strand-input__trailing")).toBeTruthy();
79
+ });
80
+
81
+ it("merges custom className", () => {
82
+ const { container } = render(
83
+ <Input aria-label="Name" className="custom" />
84
+ );
85
+ expect(container.querySelector(".strand-input")?.className).toContain("custom");
86
+ });
87
+
88
+ it("forwards ref to input element", () => {
89
+ let inputEl: HTMLInputElement | null = null;
90
+ render(
91
+ <Input aria-label="Name" ref={(el: HTMLInputElement | null) => { inputEl = el; }} />
92
+ );
93
+ expect(inputEl).toBeInstanceOf(HTMLInputElement);
94
+ });
95
+ });
@@ -0,0 +1,69 @@
1
+ /*! Strand UI | MIT License | dillingerstaffing.com */
2
+
3
+ import type { JSX, ComponentChildren } from "preact";
4
+ import { forwardRef } from "preact/compat";
5
+
6
+ export interface InputProps
7
+ extends Omit<JSX.HTMLAttributes<HTMLInputElement>, "size"> {
8
+ /** Input type */
9
+ type?: "text" | "email" | "password" | "search" | "number";
10
+ /** Show error styling */
11
+ error?: boolean;
12
+ /** Element rendered before the input */
13
+ leadingAddon?: ComponentChildren;
14
+ /** Element rendered after the input */
15
+ trailingAddon?: ComponentChildren;
16
+ /** Disabled state */
17
+ disabled?: boolean;
18
+ }
19
+
20
+ export const Input = forwardRef<HTMLInputElement, InputProps>(
21
+ (
22
+ {
23
+ type = "text",
24
+ error = false,
25
+ leadingAddon,
26
+ trailingAddon,
27
+ className = "",
28
+ disabled,
29
+ ...rest
30
+ },
31
+ ref,
32
+ ) => {
33
+ const wrapperClasses = [
34
+ "strand-input",
35
+ error && "strand-input--error",
36
+ disabled && "strand-input--disabled",
37
+ leadingAddon && "strand-input--has-leading",
38
+ trailingAddon && "strand-input--has-trailing",
39
+ className,
40
+ ]
41
+ .filter(Boolean)
42
+ .join(" ");
43
+
44
+ return (
45
+ <div className={wrapperClasses}>
46
+ {leadingAddon && (
47
+ <span className="strand-input__leading" aria-hidden="true">
48
+ {leadingAddon}
49
+ </span>
50
+ )}
51
+ <input
52
+ ref={ref}
53
+ type={type}
54
+ className="strand-input__field"
55
+ disabled={disabled}
56
+ aria-invalid={error ? "true" : undefined}
57
+ {...rest}
58
+ />
59
+ {trailingAddon && (
60
+ <span className="strand-input__trailing" aria-hidden="true">
61
+ {trailingAddon}
62
+ </span>
63
+ )}
64
+ </div>
65
+ );
66
+ },
67
+ );
68
+
69
+ Input.displayName = "Input";
@@ -0,0 +1,2 @@
1
+ export { Input } from "./Input.js";
2
+ export type { InputProps } from "./Input.js";
@@ -0,0 +1,30 @@
1
+ /*! Strand UI | MIT License | dillingerstaffing.com */
2
+
3
+ .strand-link {
4
+ color: var(--strand-blue-primary);
5
+ text-decoration: none;
6
+ font-family: var(--strand-font-sans);
7
+ background-image: linear-gradient(currentColor, currentColor);
8
+ background-position: 0% 100%;
9
+ background-repeat: no-repeat;
10
+ background-size: 0% 1px;
11
+ transition: background-size var(--strand-duration-normal) var(--strand-ease-out-expo);
12
+ cursor: pointer;
13
+ }
14
+
15
+ .strand-link:hover {
16
+ background-size: 100% 1px;
17
+ }
18
+
19
+ /* ── Focus ring ── */
20
+ .strand-link:focus-visible {
21
+ outline: 2px solid var(--strand-blue-primary);
22
+ outline-offset: 2px;
23
+ }
24
+
25
+ /* ── Reduced motion ── */
26
+ @media (prefers-reduced-motion: reduce) {
27
+ .strand-link {
28
+ transition: none;
29
+ }
30
+ }
@@ -0,0 +1,88 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { render } from "@testing-library/preact";
3
+ import { Link } from "./Link.js";
4
+
5
+ describe("Link", () => {
6
+ // ── Rendering ──
7
+
8
+ it("renders an anchor element", () => {
9
+ const { getByRole } = render(<Link href="/about">About</Link>);
10
+ expect(getByRole("link").tagName).toBe("A");
11
+ });
12
+
13
+ it("has the correct href attribute", () => {
14
+ const { getByRole } = render(<Link href="/about">About</Link>);
15
+ expect(getByRole("link")).toHaveAttribute("href", "/about");
16
+ });
17
+
18
+ it("applies blue color class", () => {
19
+ const { getByRole } = render(<Link href="/about">About</Link>);
20
+ expect(getByRole("link").className).toContain("strand-link");
21
+ });
22
+
23
+ it("renders children text", () => {
24
+ const { getByRole } = render(<Link href="/about">About Us</Link>);
25
+ expect(getByRole("link")).toHaveTextContent("About Us");
26
+ });
27
+
28
+ // ── External ──
29
+
30
+ it("adds target _blank when external", () => {
31
+ const { getByRole } = render(
32
+ <Link href="https://example.com" external>
33
+ External
34
+ </Link>,
35
+ );
36
+ expect(getByRole("link")).toHaveAttribute("target", "_blank");
37
+ });
38
+
39
+ it("adds rel noopener noreferrer when external", () => {
40
+ const { getByRole } = render(
41
+ <Link href="https://example.com" external>
42
+ External
43
+ </Link>,
44
+ );
45
+ expect(getByRole("link")).toHaveAttribute("rel", "noopener noreferrer");
46
+ });
47
+
48
+ it("does not add target or rel when not external", () => {
49
+ const { getByRole } = render(<Link href="/about">About</Link>);
50
+ const link = getByRole("link");
51
+ expect(link).not.toHaveAttribute("target");
52
+ expect(link).not.toHaveAttribute("rel");
53
+ });
54
+
55
+ // ── Custom className ──
56
+
57
+ it("merges custom className with component class", () => {
58
+ const { getByRole } = render(
59
+ <Link href="/about" className="custom">
60
+ About
61
+ </Link>,
62
+ );
63
+ const link = getByRole("link");
64
+ expect(link.className).toContain("strand-link");
65
+ expect(link.className).toContain("custom");
66
+ });
67
+
68
+ // ── No text-decoration ──
69
+
70
+ it("does not have text-decoration class (relies on CSS reset)", () => {
71
+ const { getByRole } = render(<Link href="/about">About</Link>);
72
+ expect(getByRole("link").className).not.toContain("text-decoration");
73
+ });
74
+
75
+ // ── Accessibility ──
76
+
77
+ it("forwards additional props", () => {
78
+ const { getByRole } = render(
79
+ <Link href="/about" aria-label="Go to about page">
80
+ About
81
+ </Link>,
82
+ );
83
+ expect(getByRole("link")).toHaveAttribute(
84
+ "aria-label",
85
+ "Go to about page",
86
+ );
87
+ });
88
+ });
@@ -0,0 +1,31 @@
1
+ /*! Strand UI | MIT License | dillingerstaffing.com */
2
+
3
+ import type { JSX } from "preact";
4
+ import { forwardRef } from "preact/compat";
5
+
6
+ export interface LinkProps extends JSX.HTMLAttributes<HTMLAnchorElement> {
7
+ /** URL destination */
8
+ href: string;
9
+ /** Opens in new tab with rel="noopener noreferrer" */
10
+ external?: boolean;
11
+ }
12
+
13
+ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
14
+ ({ href, external = false, className = "", children, ...rest }, ref) => {
15
+ const classes = ["strand-link", className].filter(Boolean).join(" ");
16
+
17
+ return (
18
+ <a
19
+ ref={ref}
20
+ href={href}
21
+ className={classes}
22
+ {...(external && { target: "_blank", rel: "noopener noreferrer" })}
23
+ {...rest}
24
+ >
25
+ {children}
26
+ </a>
27
+ );
28
+ },
29
+ );
30
+
31
+ Link.displayName = "Link";
@@ -0,0 +1,2 @@
1
+ export { Link } from "./Link.js";
2
+ export type { LinkProps } from "./Link.js";
@@ -0,0 +1,179 @@
1
+ /*! Strand UI | MIT License | dillingerstaffing.com */
2
+
3
+ /* ── Nav bar ── */
4
+ .strand-nav {
5
+ position: relative;
6
+ width: 100%;
7
+ height: 64px;
8
+ background: var(--strand-surface-elevated);
9
+ border-bottom: 1px solid var(--strand-gray-200);
10
+ font-family: var(--strand-font-sans);
11
+ }
12
+
13
+ /* ── Inner layout ── */
14
+ .strand-nav__inner {
15
+ display: flex;
16
+ align-items: center;
17
+ height: 100%;
18
+ padding: 0 var(--strand-space-6);
19
+ max-width: 1280px;
20
+ margin: 0 auto;
21
+ }
22
+
23
+ /* ── Logo ── */
24
+ .strand-nav__logo {
25
+ flex-shrink: 0;
26
+ margin-right: var(--strand-space-8);
27
+ }
28
+
29
+ /* ── Desktop items ── */
30
+ .strand-nav__items {
31
+ display: flex;
32
+ align-items: center;
33
+ gap: var(--strand-space-6);
34
+ flex: 1;
35
+ }
36
+
37
+ /* ── Links ── */
38
+ .strand-nav__link {
39
+ color: var(--strand-gray-600);
40
+ text-decoration: none;
41
+ font-size: var(--strand-text-sm);
42
+ font-weight: var(--strand-weight-medium);
43
+ transition: color var(--strand-duration-fast) var(--strand-ease-out-quart);
44
+ }
45
+
46
+ .strand-nav__link:hover {
47
+ color: var(--strand-gray-900);
48
+ }
49
+
50
+ .strand-nav__link:focus-visible {
51
+ outline: 2px solid var(--strand-blue-primary);
52
+ outline-offset: 2px;
53
+ }
54
+
55
+ .strand-nav__link--active {
56
+ color: var(--strand-blue-primary);
57
+ font-weight: var(--strand-weight-medium);
58
+ }
59
+
60
+ /* ── Actions ── */
61
+ .strand-nav__actions {
62
+ display: flex;
63
+ align-items: center;
64
+ gap: var(--strand-space-3);
65
+ margin-left: auto;
66
+ }
67
+
68
+ /* ── Hamburger ── */
69
+ .strand-nav__hamburger {
70
+ display: none;
71
+ align-items: center;
72
+ justify-content: center;
73
+ width: 40px;
74
+ height: 40px;
75
+ margin-left: auto;
76
+ padding: 0;
77
+ border: none;
78
+ border-radius: var(--strand-radius-md);
79
+ background: transparent;
80
+ color: var(--strand-gray-600);
81
+ cursor: pointer;
82
+ transition: background var(--strand-duration-fast) var(--strand-ease-out-quart);
83
+ }
84
+
85
+ .strand-nav__hamburger:hover {
86
+ background: var(--strand-gray-200);
87
+ }
88
+
89
+ .strand-nav__hamburger:focus-visible {
90
+ outline: 2px solid var(--strand-blue-primary);
91
+ outline-offset: 2px;
92
+ }
93
+
94
+ .strand-nav__hamburger-icon {
95
+ display: block;
96
+ width: 20px;
97
+ height: 2px;
98
+ background: currentColor;
99
+ position: relative;
100
+ }
101
+
102
+ .strand-nav__hamburger-icon::before,
103
+ .strand-nav__hamburger-icon::after {
104
+ content: "";
105
+ position: absolute;
106
+ left: 0;
107
+ width: 100%;
108
+ height: 2px;
109
+ background: currentColor;
110
+ }
111
+
112
+ .strand-nav__hamburger-icon::before {
113
+ top: -6px;
114
+ }
115
+
116
+ .strand-nav__hamburger-icon::after {
117
+ top: 6px;
118
+ }
119
+
120
+ /* ── Mobile menu ── */
121
+ .strand-nav__mobile-menu {
122
+ display: none;
123
+ flex-direction: column;
124
+ width: 100%;
125
+ padding: var(--strand-space-4) var(--strand-space-6);
126
+ background: var(--strand-surface-elevated);
127
+ border-bottom: 1px solid var(--strand-gray-200);
128
+ }
129
+
130
+ .strand-nav__mobile-link {
131
+ display: block;
132
+ padding: var(--strand-space-3) 0;
133
+ color: var(--strand-gray-600);
134
+ text-decoration: none;
135
+ font-size: var(--strand-text-sm);
136
+ font-weight: var(--strand-weight-medium);
137
+ transition: color var(--strand-duration-fast) var(--strand-ease-out-quart);
138
+ }
139
+
140
+ .strand-nav__mobile-link:hover {
141
+ color: var(--strand-gray-900);
142
+ }
143
+
144
+ .strand-nav__mobile-link--active {
145
+ color: var(--strand-blue-primary);
146
+ }
147
+
148
+ /* ── Responsive ── */
149
+ @media (max-width: 767px) {
150
+ .strand-nav__items {
151
+ display: none;
152
+ }
153
+
154
+ .strand-nav__actions {
155
+ display: none;
156
+ }
157
+
158
+ .strand-nav__hamburger {
159
+ display: inline-flex;
160
+ }
161
+
162
+ .strand-nav__mobile-menu {
163
+ display: flex;
164
+ }
165
+
166
+ .strand-nav {
167
+ height: auto;
168
+ min-height: 64px;
169
+ }
170
+ }
171
+
172
+ /* ── Reduced motion ── */
173
+ @media (prefers-reduced-motion: reduce) {
174
+ .strand-nav__link,
175
+ .strand-nav__mobile-link,
176
+ .strand-nav__hamburger {
177
+ transition: none;
178
+ }
179
+ }
@@ -0,0 +1,174 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { render, fireEvent } from "@testing-library/preact";
3
+ import { Nav } from "./Nav.js";
4
+
5
+ const sampleItems = [
6
+ { label: "Home", href: "/", active: true },
7
+ { label: "About", href: "/about" },
8
+ { label: "Contact", href: "/contact" },
9
+ ];
10
+
11
+ describe("Nav", () => {
12
+ // ── Rendering ──
13
+
14
+ it("renders a nav element", () => {
15
+ const { container } = render(<Nav items={sampleItems} />);
16
+ expect(container.querySelector("nav")).toBeTruthy();
17
+ });
18
+
19
+ it("has aria-label Main navigation", () => {
20
+ const { getByRole } = render(<Nav items={sampleItems} />);
21
+ expect(getByRole("navigation")).toHaveAttribute(
22
+ "aria-label",
23
+ "Main navigation",
24
+ );
25
+ });
26
+
27
+ it("renders logo content", () => {
28
+ const { getByText } = render(
29
+ <Nav logo={<span>MyLogo</span>} items={sampleItems} />,
30
+ );
31
+ expect(getByText("MyLogo")).toBeTruthy();
32
+ });
33
+
34
+ it("renders navigation items", () => {
35
+ const { getByText } = render(<Nav items={sampleItems} />);
36
+ expect(getByText("Home")).toBeTruthy();
37
+ expect(getByText("About")).toBeTruthy();
38
+ expect(getByText("Contact")).toBeTruthy();
39
+ });
40
+
41
+ it("renders item hrefs", () => {
42
+ const { getByText } = render(<Nav items={sampleItems} />);
43
+ expect(getByText("Home").closest("a")).toHaveAttribute("href", "/");
44
+ expect(getByText("About").closest("a")).toHaveAttribute(
45
+ "href",
46
+ "/about",
47
+ );
48
+ });
49
+
50
+ // ── Active item ──
51
+
52
+ it("active item has active class", () => {
53
+ const { getByText } = render(<Nav items={sampleItems} />);
54
+ const homeLink = getByText("Home").closest("a")!;
55
+ expect(homeLink.className).toContain("strand-nav__link--active");
56
+ });
57
+
58
+ it("active item has aria-current page", () => {
59
+ const { getByText } = render(<Nav items={sampleItems} />);
60
+ const homeLink = getByText("Home").closest("a")!;
61
+ expect(homeLink).toHaveAttribute("aria-current", "page");
62
+ });
63
+
64
+ it("inactive item does not have active class", () => {
65
+ const { getByText } = render(<Nav items={sampleItems} />);
66
+ const aboutLink = getByText("About").closest("a")!;
67
+ expect(aboutLink.className).not.toContain("strand-nav__link--active");
68
+ });
69
+
70
+ // ── Actions ──
71
+
72
+ it("renders actions content", () => {
73
+ const { getByText } = render(
74
+ <Nav
75
+ items={sampleItems}
76
+ actions={<button type="button">Sign In</button>}
77
+ />,
78
+ );
79
+ expect(getByText("Sign In")).toBeTruthy();
80
+ });
81
+
82
+ // ── Hamburger ──
83
+
84
+ it("hamburger button has aria-expanded false initially", () => {
85
+ const { container } = render(<Nav items={sampleItems} />);
86
+ const hamburger = container.querySelector(".strand-nav__hamburger")!;
87
+ expect(hamburger).toHaveAttribute("aria-expanded", "false");
88
+ });
89
+
90
+ it("hamburger button has aria-label Menu", () => {
91
+ const { container } = render(<Nav items={sampleItems} />);
92
+ const hamburger = container.querySelector(".strand-nav__hamburger")!;
93
+ expect(hamburger).toHaveAttribute("aria-label", "Menu");
94
+ });
95
+
96
+ it("clicking hamburger toggles menu and updates aria attributes", () => {
97
+ const { container } = render(<Nav items={sampleItems} />);
98
+ const hamburger = container.querySelector(
99
+ ".strand-nav__hamburger",
100
+ ) as HTMLButtonElement;
101
+
102
+ // Initially closed
103
+ expect(hamburger).toHaveAttribute("aria-expanded", "false");
104
+ expect(hamburger).toHaveAttribute("aria-label", "Menu");
105
+ expect(
106
+ container.querySelector(".strand-nav__mobile-menu"),
107
+ ).toBeNull();
108
+
109
+ // Open
110
+ fireEvent.click(hamburger);
111
+ expect(hamburger).toHaveAttribute("aria-expanded", "true");
112
+ expect(hamburger).toHaveAttribute("aria-label", "Close menu");
113
+ expect(
114
+ container.querySelector(".strand-nav__mobile-menu"),
115
+ ).toBeTruthy();
116
+
117
+ // Close
118
+ fireEvent.click(hamburger);
119
+ expect(hamburger).toHaveAttribute("aria-expanded", "false");
120
+ expect(hamburger).toHaveAttribute("aria-label", "Menu");
121
+ });
122
+
123
+ it("mobile menu renders items when open", () => {
124
+ const { container, getByText } = render(<Nav items={sampleItems} />);
125
+ const hamburger = container.querySelector(
126
+ ".strand-nav__hamburger",
127
+ ) as HTMLButtonElement;
128
+ fireEvent.click(hamburger);
129
+
130
+ const mobileMenu = container.querySelector(".strand-nav__mobile-menu")!;
131
+ expect(mobileMenu).toBeTruthy();
132
+ // Items appear in both desktop and mobile, check mobile menu has them
133
+ const mobileLinks = mobileMenu.querySelectorAll(".strand-nav__mobile-link");
134
+ expect(mobileLinks.length).toBe(3);
135
+ });
136
+
137
+ it("mobile active item has active class", () => {
138
+ const { container } = render(<Nav items={sampleItems} />);
139
+ const hamburger = container.querySelector(
140
+ ".strand-nav__hamburger",
141
+ ) as HTMLButtonElement;
142
+ fireEvent.click(hamburger);
143
+
144
+ const mobileMenu = container.querySelector(".strand-nav__mobile-menu")!;
145
+ const activeLink = mobileMenu.querySelector(
146
+ ".strand-nav__mobile-link--active",
147
+ );
148
+ expect(activeLink).toBeTruthy();
149
+ expect(activeLink!.textContent).toBe("Home");
150
+ });
151
+
152
+ // ── Custom className ──
153
+
154
+ it("merges custom className", () => {
155
+ const { getByRole } = render(
156
+ <Nav items={sampleItems} className="custom-nav" />,
157
+ );
158
+ const nav = getByRole("navigation");
159
+ expect(nav.className).toContain("strand-nav");
160
+ expect(nav.className).toContain("custom-nav");
161
+ });
162
+
163
+ // ── Empty states ──
164
+
165
+ it("renders without items", () => {
166
+ const { getByRole } = render(<Nav />);
167
+ expect(getByRole("navigation")).toBeTruthy();
168
+ });
169
+
170
+ it("renders without logo", () => {
171
+ const { container } = render(<Nav items={sampleItems} />);
172
+ expect(container.querySelector(".strand-nav__logo")).toBeNull();
173
+ });
174
+ });