@keystone-sites/marketing-design-system 1.0.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 (130) hide show
  1. package/AGENTS.md +163 -0
  2. package/README.md +85 -0
  3. package/assets/media/brand/ks-lockup.svg +13 -0
  4. package/assets/media/brand/ks-logomark.svg +4 -0
  5. package/assets/media/brand/ks-wordmark-inline.svg +13 -0
  6. package/assets/media/brand/ks-wordmark.svg +11 -0
  7. package/assets/media/fonts/gt-standard-standard-vf.woff2 +0 -0
  8. package/assets/media/fonts/pp-kyoto-variable-upright-vf.woff2 +0 -0
  9. package/base.css +111 -0
  10. package/css-vars.d.ts +10 -0
  11. package/grid/engine.css +368 -0
  12. package/grid/field-hash.ts +31 -0
  13. package/grid/field.tsx +48 -0
  14. package/grid/gates.cjs +34 -0
  15. package/grid/region.tsx +97 -0
  16. package/icons.tsx +1224 -0
  17. package/index.css +77 -0
  18. package/lib/autoplay-gate.ts +88 -0
  19. package/lib/focus-trap.ts +42 -0
  20. package/lib/grader.ts +131 -0
  21. package/lib/legal-data.ts +1 -0
  22. package/lib/legal.ts +41 -0
  23. package/lib/noise.tsx +114 -0
  24. package/lib/render-boundary.tsx +27 -0
  25. package/lib/scroll-lock.ts +25 -0
  26. package/lib/swipe.ts +124 -0
  27. package/lib/use-active-section.ts +43 -0
  28. package/lib/use-count-up.ts +26 -0
  29. package/lib/use-grader-search.ts +118 -0
  30. package/lib/use-video-carousel.ts +271 -0
  31. package/media.ts +558 -0
  32. package/package.json +201 -0
  33. package/primitives/button-inline.css +52 -0
  34. package/primitives/button-inline.tsx +38 -0
  35. package/primitives/buttons.css +449 -0
  36. package/primitives/buttons.tsx +263 -0
  37. package/primitives/case-study-button.css +71 -0
  38. package/primitives/case-study-button.tsx +28 -0
  39. package/primitives/case-study-card.css +318 -0
  40. package/primitives/case-study-card.tsx +116 -0
  41. package/primitives/closer-row.css +14 -0
  42. package/primitives/closer-row.tsx +22 -0
  43. package/primitives/cta-row.css +41 -0
  44. package/primitives/cta-row.tsx +39 -0
  45. package/primitives/disclosure.css +210 -0
  46. package/primitives/disclosure.tsx +144 -0
  47. package/primitives/faq-question.css +220 -0
  48. package/primitives/faq-question.tsx +55 -0
  49. package/primitives/field.css +225 -0
  50. package/primitives/field.tsx +266 -0
  51. package/primitives/footer-item.css +72 -0
  52. package/primitives/footer-item.tsx +42 -0
  53. package/primitives/grader-menu.tsx +84 -0
  54. package/primitives/grader.css +302 -0
  55. package/primitives/grader.tsx +284 -0
  56. package/primitives/modal.css +151 -0
  57. package/primitives/modal.tsx +90 -0
  58. package/primitives/notice.css +39 -0
  59. package/primitives/notice.tsx +56 -0
  60. package/primitives/persona-card.css +374 -0
  61. package/primitives/persona-card.tsx +74 -0
  62. package/primitives/picture.css +11 -0
  63. package/primitives/picture.tsx +41 -0
  64. package/primitives/plan-card.css +378 -0
  65. package/primitives/plan-card.tsx +91 -0
  66. package/primitives/prose.css +118 -0
  67. package/primitives/prose.tsx +170 -0
  68. package/primitives/ramps.css +84 -0
  69. package/primitives/slider.css +179 -0
  70. package/primitives/slider.tsx +69 -0
  71. package/primitives/slug.css +87 -0
  72. package/primitives/slug.tsx +37 -0
  73. package/primitives/status.css +298 -0
  74. package/primitives/status.tsx +222 -0
  75. package/primitives/strip.css +40 -0
  76. package/primitives/surface.css +78 -0
  77. package/primitives/surface.tsx +95 -0
  78. package/primitives/table.css +226 -0
  79. package/primitives/table.tsx +122 -0
  80. package/primitives/tabs.css +85 -0
  81. package/primitives/tabs.tsx +122 -0
  82. package/primitives/text.css +110 -0
  83. package/primitives/toc.css +65 -0
  84. package/primitives/toc.tsx +42 -0
  85. package/rules/design-system.md +154 -0
  86. package/rules/grid-and-layout.md +166 -0
  87. package/scripts/generate-exports.mjs +61 -0
  88. package/scripts/generate-type-css.mjs +130 -0
  89. package/sections/faq-island.tsx +102 -0
  90. package/sections/faq.css +213 -0
  91. package/sections/faq.tsx +46 -0
  92. package/sections/footer-nav.tsx +95 -0
  93. package/sections/footer-signature.css +183 -0
  94. package/sections/footer-signature.tsx +114 -0
  95. package/sections/footer.css +735 -0
  96. package/sections/footer.tsx +283 -0
  97. package/sections/gallery-overlay.css +213 -0
  98. package/sections/gallery-overlay.tsx +267 -0
  99. package/sections/landing-benefits.css +59 -0
  100. package/sections/landing-benefits.tsx +81 -0
  101. package/sections/landing-closer.css +23 -0
  102. package/sections/landing-closer.tsx +26 -0
  103. package/sections/landing-hero.css +80 -0
  104. package/sections/landing-hero.tsx +69 -0
  105. package/sections/landing-quote.css +19 -0
  106. package/sections/landing-quote.tsx +30 -0
  107. package/sections/landing-sample.ts +66 -0
  108. package/sections/landing.css +45 -0
  109. package/sections/landing.tsx +69 -0
  110. package/sections/load-orchestrator.tsx +43 -0
  111. package/sections/load.css +138 -0
  112. package/sections/nav-desktop.css +530 -0
  113. package/sections/nav-desktop.tsx +155 -0
  114. package/sections/nav-mobile.css +571 -0
  115. package/sections/nav-mobile.tsx +222 -0
  116. package/sections/nav.css +126 -0
  117. package/sections/nav.tsx +394 -0
  118. package/sections/site-chat-data.ts +16 -0
  119. package/sections/site-chat-open.tsx +25 -0
  120. package/sections/site-chat.tsx +67 -0
  121. package/site-links.ts +36 -0
  122. package/site.ts +2 -0
  123. package/themes/inverted.css +139 -0
  124. package/tokens/fonts.css +38 -0
  125. package/tokens/motion.css +125 -0
  126. package/tokens/primitives.css +163 -0
  127. package/tokens/semantic.css +153 -0
  128. package/tokens/type-styles.json +145 -0
  129. package/tokens/type.css +1548 -0
  130. package/widgets.css +78 -0
@@ -0,0 +1,95 @@
1
+ /** Surface: a raised sheet on the ground, and the layout kit that fills
2
+ * it — hairline-divided rows, a rhythm stack, a divider, a chip row.
3
+ * Styles live in surface.css. */
4
+
5
+ import type { CSSProperties, ElementType, ReactNode } from "react";
6
+
7
+ type DataAttrs = Record<`data-${string}`, string | undefined>;
8
+
9
+ export function Surface({
10
+ as: Tag = "div",
11
+ pad = "md",
12
+ elev,
13
+ tone,
14
+ id,
15
+ className,
16
+ style,
17
+ children,
18
+ ...rest
19
+ }: {
20
+ id?: string;
21
+ as?: ElementType;
22
+ pad?: "none" | "sm" | "md" | "lg";
23
+ elev?: "lift";
24
+ tone?: "well";
25
+ className?: string;
26
+ style?: CSSProperties;
27
+ children: ReactNode;
28
+ /** Data attributes (a stagger delay, a test id) pass through. */
29
+ [data: `data-${string}`]: string | undefined;
30
+ }) {
31
+ return (
32
+ <Tag
33
+ id={id}
34
+ className={className ? `surface ${className}` : "surface"}
35
+ data-pad={pad}
36
+ data-elev={elev}
37
+ data-tone={tone}
38
+ style={style}
39
+ {...(rest as DataAttrs)}
40
+ >
41
+ {children}
42
+ </Tag>
43
+ );
44
+ }
45
+
46
+ /** Stacked children divided by the surface hairline. */
47
+ export function Rows({
48
+ as: Tag = "div",
49
+ className,
50
+ children,
51
+ }: {
52
+ as?: ElementType;
53
+ className?: string;
54
+ children: ReactNode;
55
+ }) {
56
+ return <Tag className={className ? `rows ${className}` : "rows"}>{children}</Tag>;
57
+ }
58
+
59
+ /** One row: a flex line with the surface's gap; `Row.main` grows. */
60
+ export function Row({ className, children }: { className?: string; children: ReactNode }) {
61
+ return <div className={className ? `row ${className}` : "row"}>{children}</div>;
62
+ }
63
+
64
+ export function RowMain({ className, children }: { className?: string; children: ReactNode }) {
65
+ return <div className={className ? `row-main ${className}` : "row-main"}>{children}</div>;
66
+ }
67
+
68
+ /** Vertical rhythm between siblings, stepped by the spacing scale. */
69
+ export function Stack({
70
+ as: Tag = "div",
71
+ gap,
72
+ className,
73
+ children,
74
+ }: {
75
+ as?: ElementType;
76
+ gap?: "sm" | "lg" | "xl";
77
+ className?: string;
78
+ children: ReactNode;
79
+ }) {
80
+ return (
81
+ <Tag className={className ? `stack ${className}` : "stack"} data-gap={gap}>
82
+ {children}
83
+ </Tag>
84
+ );
85
+ }
86
+
87
+ /** A hairline with breathing room. */
88
+ export function Divider() {
89
+ return <hr className="divider" />;
90
+ }
91
+
92
+ /** A wrapping row of pills. */
93
+ export function Chips({ className, children }: { className?: string; children: ReactNode }) {
94
+ return <div className={className ? `chips ${className}` : "chips"}>{children}</div>;
95
+ }
@@ -0,0 +1,226 @@
1
+ /* Table: dense rows on a surface. Hairline row dividers, a raised head
2
+ row, and sort controls in the tab vocabulary (ink on hover, teal
3
+ tick when active). The wrap scrolls sideways so columns keep their
4
+ widths from the tablet band; below it, marked columns drop instead.
5
+ The body's type is the table's ts- step; cells restate only the
6
+ step that differs (head, primary, secondary, mono). */
7
+
8
+ /* Designed constants for this file. */
9
+ :root {
10
+ --table-pager-btn: 32px;
11
+ }
12
+
13
+ .table-wrap {
14
+ width: 100%;
15
+ overflow-x: auto;
16
+ scrollbar-width: thin;
17
+ }
18
+ .table {
19
+ width: 100%;
20
+ min-width: var(--table-min, 0);
21
+ border-collapse: collapse;
22
+ text-align: left;
23
+ color: var(--color-text-200);
24
+ }
25
+ .table thead th {
26
+ position: sticky;
27
+ top: 0;
28
+ z-index: 1;
29
+ padding: var(--space-md) var(--space-xl);
30
+ background: var(--color-bg-200);
31
+ border-bottom: 1px solid var(--color-border-050);
32
+ color: var(--color-text-400);
33
+ --font: var(--ts-text-xs-medium-font);
34
+ --ls: 0.06em;
35
+ --opsz: var(--ts-text-xs-medium-opsz);
36
+ font: var(--font);
37
+ letter-spacing: var(--ls);
38
+ font-variation-settings:
39
+ "opsz" var(--opsz),
40
+ var(--font-sans-slnt);
41
+ text-transform: uppercase;
42
+ white-space: nowrap;
43
+ vertical-align: bottom;
44
+ }
45
+ .table tbody td {
46
+ padding: var(--space-lg) var(--space-xl);
47
+ border-top: 1px solid var(--color-border-050);
48
+ vertical-align: top;
49
+ }
50
+ .table tbody tr:first-child td {
51
+ border-top: 0;
52
+ }
53
+ .table [data-align="end"],
54
+ .table [data-align="end"] .table-sort {
55
+ text-align: right;
56
+ justify-content: flex-end;
57
+ }
58
+ .table [data-numeric] {
59
+ font-variant-numeric: tabular-nums;
60
+ }
61
+ .table [data-nowrap] {
62
+ white-space: nowrap;
63
+ }
64
+ /* The phone band: no sideways scroll, marked columns drop. */
65
+ .table {
66
+ min-width: 0;
67
+ }
68
+ .table [data-narrow-hide] {
69
+ display: none;
70
+ }
71
+ @container (--rt) {
72
+ .table {
73
+ min-width: var(--table-min, 0);
74
+ }
75
+ .table [data-narrow-hide] {
76
+ display: revert;
77
+ }
78
+ }
79
+ .table :is(th, td):first-child {
80
+ padding-left: var(--space-2xl);
81
+ }
82
+ .table :is(th, td):last-child {
83
+ padding-right: var(--space-2xl);
84
+ }
85
+ .table tbody tr[data-interactive] {
86
+ cursor: pointer;
87
+ transition: background var(--motion-hover-duration) var(--motion-hover-ease);
88
+ }
89
+ @media (hover: hover) {
90
+ .table tbody tr[data-interactive]:hover td {
91
+ background: var(--color-bg-300);
92
+ }
93
+ }
94
+ .table tbody tr[data-interactive]:focus-visible {
95
+ outline: none;
96
+ }
97
+ .table tbody tr[data-interactive]:focus-visible td {
98
+ box-shadow: inset 0 0 0 var(--ring-w) var(--color-teal-200);
99
+ }
100
+ .table tbody tr[data-tone="group"] td {
101
+ background: var(--color-bg-100);
102
+ color: var(--color-text-100);
103
+ font: var(--ts-text-sm-medium-font);
104
+ letter-spacing: var(--ts-text-sm-medium-ls);
105
+ }
106
+ .table-primary {
107
+ color: var(--color-text-100);
108
+ font: var(--ts-text-sm-medium-font);
109
+ letter-spacing: var(--ts-text-sm-medium-ls);
110
+ }
111
+ .table-secondary {
112
+ display: block;
113
+ margin-top: var(--space-2xs);
114
+ color: var(--color-text-500);
115
+ font: var(--ts-text-xs-light-font);
116
+ letter-spacing: var(--ts-text-xs-light-ls);
117
+ }
118
+ .table-mono {
119
+ font-family: var(--font-mono);
120
+ font-size: 0.75rem;
121
+ }
122
+ .table-empty td {
123
+ padding-block: calc(var(--t) * 0.75);
124
+ text-align: center;
125
+ color: var(--color-text-400);
126
+ }
127
+
128
+ /* Sort control in the head cell. */
129
+ .table-sort {
130
+ appearance: none;
131
+ display: inline-flex;
132
+ align-items: center;
133
+ gap: var(--space-xs);
134
+ margin: 0;
135
+ padding: 0;
136
+ border: 0;
137
+ background: none;
138
+ color: inherit;
139
+ font: inherit;
140
+ letter-spacing: inherit;
141
+ text-transform: inherit;
142
+ cursor: pointer;
143
+ transition: color var(--motion-hover-duration) var(--motion-hover-ease);
144
+ }
145
+ .table-sort:hover {
146
+ color: var(--color-text-200);
147
+ }
148
+ .table-sort[data-active] {
149
+ color: var(--color-text-100);
150
+ }
151
+ .table-sort:focus-visible {
152
+ outline: none;
153
+ box-shadow: 0 0 0 var(--ring-w) var(--color-teal-200);
154
+ border-radius: var(--radius-xs);
155
+ }
156
+ .table-sort-tick {
157
+ flex: none;
158
+ opacity: 0.4;
159
+ transition:
160
+ transform var(--motion-hover-duration) var(--motion-hover-ease),
161
+ opacity var(--motion-hover-duration) var(--motion-hover-ease);
162
+ }
163
+ .table-sort[data-active] .table-sort-tick {
164
+ opacity: 1;
165
+ color: var(--color-teal-300);
166
+ }
167
+ .table-sort[data-dir="asc"] .table-sort-tick {
168
+ transform: rotate(180deg);
169
+ }
170
+
171
+ /* Pager: a summary on the left, page count and chevrons on the right. */
172
+ .pager {
173
+ display: flex;
174
+ align-items: center;
175
+ justify-content: space-between;
176
+ gap: var(--space-lg);
177
+ flex-wrap: wrap;
178
+ }
179
+ .pager-summary {
180
+ color: var(--color-text-400);
181
+ }
182
+ .pager-controls {
183
+ display: flex;
184
+ align-items: center;
185
+ gap: var(--space-sm);
186
+ margin-left: auto;
187
+ }
188
+ .pager-controls > p {
189
+ margin-right: var(--space-sm);
190
+ }
191
+ .pager-of {
192
+ color: var(--color-text-400);
193
+ }
194
+ .pager-btn {
195
+ appearance: none;
196
+ display: grid;
197
+ place-items: center;
198
+ width: var(--table-pager-btn);
199
+ height: var(--table-pager-btn);
200
+ border: 1px solid var(--color-border-100);
201
+ border-radius: var(--radius-full);
202
+ background: transparent;
203
+ color: var(--color-text-200);
204
+ cursor: pointer;
205
+ transition:
206
+ background var(--motion-hover-duration) var(--motion-hover-ease),
207
+ color var(--motion-hover-duration) var(--motion-hover-ease),
208
+ opacity var(--motion-hover-duration) var(--motion-hover-ease);
209
+ }
210
+ @media (hover: hover) {
211
+ .pager-btn:not(:disabled):hover {
212
+ background: var(--color-bg-300);
213
+ color: var(--color-text-100);
214
+ }
215
+ }
216
+ .pager-btn:disabled {
217
+ opacity: 0.35;
218
+ cursor: default;
219
+ }
220
+ .pager-btn:focus-visible {
221
+ outline: none;
222
+ box-shadow: 0 0 0 var(--ring-w) var(--color-teal-200);
223
+ }
224
+ .pager-btn svg {
225
+ display: block;
226
+ }
@@ -0,0 +1,122 @@
1
+ /** Table: dense rows of data with sortable columns, and the pager that
2
+ * walks them. Styles live in table.css. The consumer owns the rows,
3
+ * the sort state and the page. */
4
+
5
+ import type { ReactNode } from "react";
6
+ import { IconChevronDownSmall, IconChevronLeftSm, IconChevronRightSm } from "../icons";
7
+ import { Copy } from "./prose";
8
+
9
+ export type SortDir = "asc" | "desc";
10
+
11
+ export function Table({
12
+ label,
13
+ minWidth,
14
+ className,
15
+ children,
16
+ }: {
17
+ /** Accessible name for the table. */
18
+ label: string;
19
+ /** From the tablet anchor, columns keep this width and the wrap
20
+ * scrolls sideways; phones drop `data-narrow-hide` columns instead. */
21
+ minWidth?: number;
22
+ className?: string;
23
+ children: ReactNode;
24
+ }) {
25
+ return (
26
+ <div className={className ? `table-wrap ${className}` : "table-wrap"}>
27
+ <table
28
+ className="type type-fixed ts-text-sm-light table"
29
+ aria-label={label}
30
+ style={minWidth ? { "--table-min": `${minWidth}px` } : undefined}
31
+ >
32
+ {children}
33
+ </table>
34
+ </div>
35
+ );
36
+ }
37
+
38
+ export function SortHeader({
39
+ active,
40
+ dir,
41
+ onSort,
42
+ align,
43
+ narrowHide,
44
+ children,
45
+ }: {
46
+ active: boolean;
47
+ dir: SortDir;
48
+ onSort: () => void;
49
+ align?: "end";
50
+ /** Drop the column on phones. */
51
+ narrowHide?: boolean;
52
+ children: ReactNode;
53
+ }) {
54
+ return (
55
+ <th
56
+ scope="col"
57
+ aria-sort={active ? (dir === "asc" ? "ascending" : "descending") : "none"}
58
+ data-align={align}
59
+ data-narrow-hide={narrowHide || undefined}
60
+ >
61
+ <button
62
+ type="button"
63
+ className="table-sort"
64
+ data-active={active || undefined}
65
+ data-dir={active ? dir : undefined}
66
+ onClick={onSort}
67
+ >
68
+ <span>{children}</span>
69
+ <IconChevronDownSmall className="table-sort-tick" />
70
+ </button>
71
+ </th>
72
+ );
73
+ }
74
+
75
+ export function Pager({
76
+ page,
77
+ pages,
78
+ onPage,
79
+ disabled,
80
+ label,
81
+ summary,
82
+ }: {
83
+ page: number;
84
+ pages: number;
85
+ onPage: (page: number) => void;
86
+ disabled?: boolean;
87
+ /** Accessible name for the pager. */
88
+ label: string;
89
+ /** Optional text on the left, e.g. "25 of 1,204 businesses". */
90
+ summary?: ReactNode;
91
+ }) {
92
+ const last = Math.max(1, pages);
93
+ return (
94
+ <nav className="pager" aria-label={label}>
95
+ <Copy className="pager-summary">{summary}</Copy>
96
+ <div className="pager-controls">
97
+ <Copy weight="medium" num>
98
+ <span className="pager-page">{page}</span>
99
+ <span className="type type-fixed ts-text-sm-light pager-of"> / {last}</span>
100
+ </Copy>
101
+ <button
102
+ type="button"
103
+ className="pager-btn"
104
+ aria-label="Previous page"
105
+ disabled={disabled || page <= 1}
106
+ onClick={() => onPage(page - 1)}
107
+ >
108
+ <IconChevronLeftSm />
109
+ </button>
110
+ <button
111
+ type="button"
112
+ className="pager-btn"
113
+ aria-label="Next page"
114
+ disabled={disabled || page >= last}
115
+ onClick={() => onPage(page + 1)}
116
+ >
117
+ <IconChevronRightSm />
118
+ </button>
119
+ </div>
120
+ </nav>
121
+ );
122
+ }
@@ -0,0 +1,85 @@
1
+ /* Tabs: a strip of equal cells in the nav-bar vocabulary. The same
2
+ strip serves in-page anchor navigation (aria-current). Raised
3
+ chrome, hairline dividers, an underline that scales in like the nav
4
+ buttons. The strip is line-inclusive so its edges share lattice
5
+ pixels. Type comes from the cell's ts- step. */
6
+
7
+ .tabs {
8
+ display: flex;
9
+ align-items: stretch;
10
+ box-sizing: border-box;
11
+ width: calc(var(--t) * 12 + 1px);
12
+ height: calc(var(--knav-bar-h) + 1px);
13
+ margin: -1px 0 0;
14
+ padding: var(--space-none);
15
+ list-style: none;
16
+ border: 1px solid var(--color-border-000);
17
+ background: var(--color-bg-200);
18
+ overflow-x: auto;
19
+ scrollbar-width: none;
20
+ }
21
+ .tabs::-webkit-scrollbar {
22
+ display: none;
23
+ }
24
+ .tabs > li {
25
+ display: flex;
26
+ flex: 1 1 0;
27
+ min-width: max-content;
28
+ }
29
+ .tabs > li + li {
30
+ border-left: 1px solid var(--color-border-000);
31
+ }
32
+ .tab {
33
+ position: relative;
34
+ display: flex;
35
+ flex: 1 1 auto;
36
+ align-items: center;
37
+ justify-content: center;
38
+ gap: var(--space-sm);
39
+ padding-inline: var(--space-xl);
40
+ border: 0;
41
+ background: transparent;
42
+ color: var(--color-text-400);
43
+ text-decoration: none;
44
+ white-space: nowrap;
45
+ cursor: pointer;
46
+ transition: color var(--knav-ink-dur) var(--motion-hover-ease);
47
+ }
48
+ .tab::after {
49
+ content: "";
50
+ position: absolute;
51
+ left: 0;
52
+ right: 0;
53
+ bottom: -1px;
54
+ height: 2px;
55
+ background: var(--color-teal-300);
56
+ transform: scaleX(0);
57
+ transform-origin: center;
58
+ transition: transform var(--knav-underline-dur) var(--motion-drawer-ease);
59
+ }
60
+ .tab:hover {
61
+ color: var(--color-text-200);
62
+ }
63
+ .tab[aria-selected="true"],
64
+ .tab[aria-current="true"] {
65
+ color: var(--color-text-100);
66
+ }
67
+ .tab[aria-selected="true"]::after,
68
+ .tab[aria-current="true"]::after {
69
+ transform: scaleX(1);
70
+ }
71
+ .tab:focus-visible {
72
+ outline: none;
73
+ box-shadow: inset 0 0 0 var(--ring-w) var(--color-border-200);
74
+ z-index: 1;
75
+ }
76
+ .tab-count {
77
+ display: inline-grid;
78
+ place-items: center;
79
+ min-width: 18px;
80
+ height: 18px;
81
+ padding-inline: var(--space-xs);
82
+ border-radius: var(--radius-full);
83
+ background: var(--color-bg-400);
84
+ color: var(--color-text-200);
85
+ }
@@ -0,0 +1,122 @@
1
+ "use client";
2
+
3
+ /** Tabs: a strip of equal cells with roving keyboard focus. Styles live
4
+ * in tabs.css. The consumer owns the selected id and the panels. */
5
+
6
+ import { useEffect, useRef, type KeyboardEvent, type ReactNode } from "react";
7
+
8
+ export interface TabItem<Id extends string> {
9
+ id: Id;
10
+ label: ReactNode;
11
+ count?: number;
12
+ }
13
+
14
+ export function Tabs<Id extends string>({
15
+ items,
16
+ selected,
17
+ onSelect,
18
+ label,
19
+ idPrefix = "tab",
20
+ className,
21
+ }: {
22
+ items: readonly TabItem<Id>[];
23
+ selected: Id;
24
+ onSelect: (id: Id) => void;
25
+ /** Accessible name for the tab list. */
26
+ label: string;
27
+ idPrefix?: string;
28
+ className?: string;
29
+ }) {
30
+ const listRef = useRef<HTMLUListElement>(null);
31
+
32
+ function onKeyDown(e: KeyboardEvent<HTMLButtonElement>, index: number) {
33
+ const count = items.length;
34
+ let next: number | null = null;
35
+ if (e.key === "ArrowRight") next = (index + 1) % count;
36
+ else if (e.key === "ArrowLeft") next = (index + count - 1) % count;
37
+ else if (e.key === "Home") next = 0;
38
+ else if (e.key === "End") next = count - 1;
39
+ if (next == null) return;
40
+ e.preventDefault();
41
+ const target = items[next];
42
+ onSelect(target.id);
43
+ listRef.current?.querySelectorAll<HTMLButtonElement>(".tab")[next]?.focus();
44
+ }
45
+
46
+ return (
47
+ <ul
48
+ className={className ? `tabs ${className}` : "tabs"}
49
+ role="tablist"
50
+ aria-label={label}
51
+ ref={listRef}
52
+ >
53
+ {items.map((item, i) => {
54
+ const active = item.id === selected;
55
+ return (
56
+ <li key={item.id} role="presentation">
57
+ <button
58
+ type="button"
59
+ role="tab"
60
+ id={`${idPrefix}-${item.id}`}
61
+ className="type type-fixed ts-text-sm-regular tab"
62
+ aria-selected={active}
63
+ aria-controls={`${idPrefix}-panel-${item.id}`}
64
+ tabIndex={active ? 0 : -1}
65
+ onClick={() => onSelect(item.id)}
66
+ onKeyDown={(e) => onKeyDown(e, i)}
67
+ >
68
+ {item.label}
69
+ {item.count != null && (
70
+ <span className="type type-fixed ts-text-2xs-medium tab-count">{item.count}</span>
71
+ )}
72
+ </button>
73
+ </li>
74
+ );
75
+ })}
76
+ </ul>
77
+ );
78
+ }
79
+
80
+ export interface AnchorItem {
81
+ id: string;
82
+ label: ReactNode;
83
+ }
84
+
85
+ /** The tab strip as in-page navigation: links to section ids with the
86
+ * current one marked. The consumer owns the scroll spy. */
87
+ export function AnchorNav({
88
+ items,
89
+ activeId,
90
+ label,
91
+ className,
92
+ }: {
93
+ items: readonly AnchorItem[];
94
+ activeId: string;
95
+ label: string;
96
+ className?: string;
97
+ }) {
98
+ const listRef = useRef<HTMLUListElement>(null);
99
+ useEffect(() => {
100
+ const link = listRef.current?.querySelector<HTMLAnchorElement>(
101
+ `a[href="#${CSS.escape(activeId)}"]`,
102
+ );
103
+ link?.scrollIntoView({ block: "nearest", inline: "center", behavior: "smooth" });
104
+ }, [activeId]);
105
+ return (
106
+ <nav aria-label={label} className={className}>
107
+ <ul className="tabs" ref={listRef}>
108
+ {items.map((item) => (
109
+ <li key={item.id}>
110
+ <a
111
+ className="type type-fixed ts-text-sm-regular tab"
112
+ href={`#${item.id}`}
113
+ aria-current={item.id === activeId ? "true" : undefined}
114
+ >
115
+ {item.label}
116
+ </a>
117
+ </li>
118
+ ))}
119
+ </ul>
120
+ </nav>
121
+ );
122
+ }