@slipstream-ui/core 0.4.0 → 0.5.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 (92) hide show
  1. package/dist/index.d.mts +296 -15
  2. package/dist/index.d.ts +296 -15
  3. package/dist/index.js +1047 -473
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1096 -530
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/manifests/app-shell.manifest.json +50 -0
  8. package/dist/manifests/badge.manifest.json +9 -4
  9. package/dist/manifests/breadcrumb.manifest.json +6 -0
  10. package/dist/manifests/button.manifest.json +14 -0
  11. package/dist/manifests/confirm-dialog.manifest.json +132 -0
  12. package/dist/manifests/data-table.manifest.json +50 -0
  13. package/dist/manifests/dialog.manifest.json +7 -0
  14. package/dist/manifests/drawer.manifest.json +7 -0
  15. package/dist/manifests/link.manifest.json +106 -0
  16. package/dist/manifests/page-header.manifest.json +30 -0
  17. package/dist/manifests/pagination.manifest.json +6 -0
  18. package/dist/manifests/prose.manifest.json +75 -0
  19. package/dist/manifests/search.manifest.json +41 -9
  20. package/dist/manifests/section-heading.manifest.json +108 -0
  21. package/dist/manifests/select.manifest.json +6 -0
  22. package/dist/manifests/site-footer.manifest.json +94 -0
  23. package/dist/manifests/site-header.manifest.json +130 -0
  24. package/dist/manifests/table-of-contents.manifest.json +87 -0
  25. package/package.json +2 -2
  26. package/src/components/alert/Alert.tsx +2 -2
  27. package/src/components/app-shell/AppShell.test.tsx +49 -1
  28. package/src/components/app-shell/AppShell.tsx +147 -43
  29. package/src/components/badge/Badge.test.tsx +21 -0
  30. package/src/components/badge/Badge.tsx +6 -0
  31. package/src/components/breadcrumb/Breadcrumb.test.tsx +16 -0
  32. package/src/components/breadcrumb/Breadcrumb.tsx +10 -5
  33. package/src/components/button/Button.test.tsx +40 -2
  34. package/src/components/button/Button.tsx +31 -7
  35. package/src/components/confirm-dialog/ConfirmDialog.test.tsx +46 -0
  36. package/src/components/confirm-dialog/ConfirmDialog.tsx +86 -0
  37. package/src/components/confirm-dialog/index.ts +1 -0
  38. package/src/components/data-table/DataTable.test.tsx +92 -0
  39. package/src/components/data-table/DataTable.tsx +98 -7
  40. package/src/components/dialog/Dialog.test.tsx +7 -0
  41. package/src/components/dialog/Dialog.tsx +4 -1
  42. package/src/components/drawer/Drawer.test.tsx +11 -2
  43. package/src/components/drawer/Drawer.tsx +5 -2
  44. package/src/components/input/Input.tsx +1 -0
  45. package/src/components/link/Link.test.tsx +60 -0
  46. package/src/components/link/Link.tsx +85 -0
  47. package/src/components/link/index.ts +1 -0
  48. package/src/components/page-header/PageHeader.test.tsx +17 -0
  49. package/src/components/page-header/PageHeader.tsx +22 -6
  50. package/src/components/pagination/Pagination.test.tsx +8 -0
  51. package/src/components/pagination/Pagination.tsx +16 -6
  52. package/src/components/prose/Prose.test.tsx +35 -0
  53. package/src/components/prose/Prose.tsx +61 -0
  54. package/src/components/prose/index.ts +1 -0
  55. package/src/components/search/Search.test.tsx +16 -0
  56. package/src/components/search/Search.tsx +11 -2
  57. package/src/components/section-heading/SectionHeading.test.tsx +32 -0
  58. package/src/components/section-heading/SectionHeading.tsx +54 -0
  59. package/src/components/section-heading/index.ts +1 -0
  60. package/src/components/select/Select.tsx +9 -7
  61. package/src/components/site-footer/SiteFooter.test.tsx +30 -0
  62. package/src/components/site-footer/SiteFooter.tsx +79 -0
  63. package/src/components/site-footer/index.ts +1 -0
  64. package/src/components/site-header/SiteHeader.test.tsx +53 -0
  65. package/src/components/site-header/SiteHeader.tsx +124 -0
  66. package/src/components/site-header/index.ts +1 -0
  67. package/src/components/switch/Switch.test.tsx +10 -0
  68. package/src/components/switch/Switch.tsx +8 -3
  69. package/src/components/table-of-contents/TableOfContents.test.tsx +31 -0
  70. package/src/components/table-of-contents/TableOfContents.tsx +100 -0
  71. package/src/components/table-of-contents/index.ts +1 -0
  72. package/src/components/textarea/Textarea.tsx +1 -0
  73. package/src/index.ts +7 -0
  74. package/src/manifests/app-shell.manifest.json +50 -0
  75. package/src/manifests/badge.manifest.json +9 -4
  76. package/src/manifests/breadcrumb.manifest.json +6 -0
  77. package/src/manifests/button.manifest.json +14 -0
  78. package/src/manifests/confirm-dialog.manifest.json +132 -0
  79. package/src/manifests/data-table.manifest.json +50 -0
  80. package/src/manifests/dialog.manifest.json +7 -0
  81. package/src/manifests/drawer.manifest.json +7 -0
  82. package/src/manifests/link.manifest.json +106 -0
  83. package/src/manifests/page-header.manifest.json +30 -0
  84. package/src/manifests/pagination.manifest.json +6 -0
  85. package/src/manifests/prose.manifest.json +75 -0
  86. package/src/manifests/search.manifest.json +41 -9
  87. package/src/manifests/section-heading.manifest.json +108 -0
  88. package/src/manifests/select.manifest.json +6 -0
  89. package/src/manifests/site-footer.manifest.json +94 -0
  90. package/src/manifests/site-header.manifest.json +130 -0
  91. package/src/manifests/table-of-contents.manifest.json +87 -0
  92. package/src/test/tailwind-v4.test.ts +103 -0
@@ -43,6 +43,15 @@ export type PaginationProps = React.HTMLAttributes<HTMLElement> & {
43
43
  showLast?: boolean;
44
44
  /** Replace the default ‹ › « » glyphs. */
45
45
  icons?: PaginationIcons;
46
+ /** Localized landmark and control labels. */
47
+ labels?: {
48
+ pagination?: string;
49
+ first?: string;
50
+ previous?: string;
51
+ next?: string;
52
+ last?: string;
53
+ page?: (page: number) => string;
54
+ };
46
55
  };
47
56
 
48
57
  const controlClass =
@@ -72,6 +81,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
72
81
  showFirst,
73
82
  showLast,
74
83
  icons,
84
+ labels,
75
85
  className,
76
86
  ...props
77
87
  },
@@ -104,7 +114,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
104
114
  const nav = (
105
115
  <nav
106
116
  ref={ref}
107
- aria-label="Pagination"
117
+ aria-label={labels?.pagination ?? 'Pagination'}
108
118
  className={cn('flex items-center justify-center gap-1', summaryEnabled ? undefined : className)}
109
119
  {...props}
110
120
  >
@@ -113,7 +123,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
113
123
  type="button"
114
124
  onClick={() => onPageChange?.(1)}
115
125
  disabled={page <= 1}
116
- aria-label="First page"
126
+ aria-label={labels?.first ?? 'First page'}
117
127
  className={controlClass}
118
128
  >
119
129
  {icons?.first ?? '«'}
@@ -123,7 +133,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
123
133
  type="button"
124
134
  onClick={() => onPageChange?.(page - 1)}
125
135
  disabled={page <= 1}
126
- aria-label="Previous page"
136
+ aria-label={labels?.previous ?? 'Previous page'}
127
137
  className={controlClass}
128
138
  >
129
139
  {icons?.previous ?? '‹'}
@@ -143,7 +153,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
143
153
  type="button"
144
154
  onClick={() => onPageChange?.(entry)}
145
155
  aria-current={entry === page ? 'page' : undefined}
146
- aria-label={`Page ${entry}`}
156
+ aria-label={labels?.page?.(entry) ?? `Page ${entry}`}
147
157
  className={cn(
148
158
  'inline-flex h-8 w-8 items-center justify-center rounded-md border text-sm transition-colors',
149
159
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
@@ -160,7 +170,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
160
170
  type="button"
161
171
  onClick={() => onPageChange?.(page + 1)}
162
172
  disabled={page >= pageCount}
163
- aria-label="Next page"
173
+ aria-label={labels?.next ?? 'Next page'}
164
174
  className={controlClass}
165
175
  >
166
176
  {icons?.next ?? '›'}
@@ -170,7 +180,7 @@ const Pagination = React.forwardRef<HTMLElement, PaginationProps>(
170
180
  type="button"
171
181
  onClick={() => onPageChange?.(pageCount)}
172
182
  disabled={page >= pageCount}
173
- aria-label="Last page"
183
+ aria-label={labels?.last ?? 'Last page'}
174
184
  className={controlClass}
175
185
  >
176
186
  {icons?.last ?? '»'}
@@ -0,0 +1,35 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { axe } from 'jest-axe';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { Prose } from './Prose';
5
+
6
+ describe('Prose', () => {
7
+ it('styles rendered markdown elements', () => {
8
+ const { container } = render(
9
+ <Prose>
10
+ <h2>Heading</h2>
11
+ <p>Body <a href="/x">link</a> <code>inline()</code></p>
12
+ <ul><li>one</li></ul>
13
+ <pre><code>const x = 1;</code></pre>
14
+ <blockquote>quote</blockquote>
15
+ <table><thead><tr><th>H</th></tr></thead><tbody><tr><td>C</td></tr></tbody></table>
16
+ </Prose>
17
+ );
18
+ const root = container.firstChild as HTMLElement;
19
+ expect(root.className).toContain('[&_h2]:font-semibold');
20
+ expect(root.className).toContain('[&_pre]:overflow-x-auto');
21
+ expect(root.className).toContain('[&_table]:w-full');
22
+ expect(screen.getByRole('heading', { name: 'Heading' })).toBeInTheDocument();
23
+ expect(screen.getByRole('link', { name: 'link' })).toBeInTheDocument();
24
+ });
25
+
26
+ it('supports size presets', () => {
27
+ const { container } = render(<Prose size="lg"><p>x</p></Prose>);
28
+ expect((container.firstChild as HTMLElement).className).toContain('text-lg');
29
+ });
30
+
31
+ it('has no accessibility violations', async () => {
32
+ const { container } = render(<Prose><h2>Title</h2><p>Copy</p></Prose>);
33
+ expect(await axe(container)).toHaveNoViolations();
34
+ });
35
+ });
@@ -0,0 +1,61 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils/cn';
3
+
4
+ export type ProseProps = React.HTMLAttributes<HTMLDivElement> & {
5
+ /** Type scale. Default 'md'. */
6
+ size?: 'sm' | 'md' | 'lg';
7
+ };
8
+
9
+ const sizeClasses: Record<NonNullable<ProseProps['size']>, string> = {
10
+ sm: 'text-sm [&_h2]:text-xl [&_h3]:text-lg',
11
+ md: 'text-base [&_h2]:text-2xl [&_h3]:text-xl',
12
+ lg: 'text-lg [&_h2]:text-3xl [&_h3]:text-2xl',
13
+ };
14
+
15
+ /**
16
+ * Long-form content typography for rendered markdown/MDX output.
17
+ *
18
+ * Self-contained (no @tailwindcss/typography dependency): element styles ride
19
+ * on child selectors, so any MDX/remark renderer can drop its output inside.
20
+ * Keeps the content pipeline (Shiki, KaTeX, Mermaid) untouched.
21
+ */
22
+ export const Prose = React.forwardRef<HTMLDivElement, ProseProps>(function Prose(
23
+ { size = 'md', className, ...props },
24
+ ref
25
+ ) {
26
+ return (
27
+ <div
28
+ ref={ref}
29
+ className={cn(
30
+ 'max-w-none text-foreground',
31
+ sizeClasses[size],
32
+ // Headings
33
+ '[&_h1]:mb-4 [&_h1]:mt-10 [&_h1]:scroll-mt-24 [&_h1]:text-3xl [&_h1]:font-bold [&_h1]:tracking-tight',
34
+ '[&_h2]:mb-3 [&_h2]:mt-9 [&_h2]:scroll-mt-24 [&_h2]:font-semibold [&_h2]:tracking-tight',
35
+ '[&_h3]:mb-2 [&_h3]:mt-7 [&_h3]:scroll-mt-24 [&_h3]:font-semibold',
36
+ '[&_h4]:mb-2 [&_h4]:mt-6 [&_h4]:scroll-mt-24 [&_h4]:font-semibold',
37
+ // Body copy
38
+ '[&_p]:my-4 [&_p]:leading-7',
39
+ '[&_a]:text-primary [&_a]:underline [&_a]:decoration-primary/40 [&_a]:underline-offset-4 hover:[&_a]:decoration-primary',
40
+ '[&_strong]:font-semibold [&_strong]:text-foreground [&_em]:italic',
41
+ '[&_ul]:my-4 [&_ul]:list-disc [&_ul]:space-y-1.5 [&_ul]:pl-6',
42
+ '[&_ol]:my-4 [&_ol]:list-decimal [&_ol]:space-y-1.5 [&_ol]:pl-6',
43
+ '[&_li]:leading-7 [&_li>p]:my-0',
44
+ '[&_blockquote]:my-6 [&_blockquote]:border-l-2 [&_blockquote]:border-primary/40 [&_blockquote]:pl-4 [&_blockquote]:italic [&_blockquote]:text-muted-foreground',
45
+ // Code
46
+ '[&_code]:rounded [&_code]:bg-muted [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.875em]',
47
+ '[&_pre]:my-5 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:border [&_pre]:border-border [&_pre]:bg-muted/50 [&_pre]:p-4',
48
+ '[&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-sm',
49
+ // Media, rules, tables
50
+ '[&_hr]:my-8 [&_hr]:border-border',
51
+ '[&_img]:my-6 [&_img]:rounded-lg [&_img]:border [&_img]:border-border',
52
+ '[&_figure]:my-6 [&_figcaption]:mt-2 [&_figcaption]:text-center [&_figcaption]:text-xs [&_figcaption]:text-muted-foreground',
53
+ '[&_table]:my-6 [&_table]:w-full [&_table]:border-collapse [&_table]:text-sm',
54
+ '[&_th]:border-b [&_th]:border-border [&_th]:px-3 [&_th]:py-2 [&_th]:text-left [&_th]:font-semibold',
55
+ '[&_td]:border-b [&_td]:border-border [&_td]:px-3 [&_td]:py-2',
56
+ className
57
+ )}
58
+ {...props}
59
+ />
60
+ );
61
+ });
@@ -0,0 +1 @@
1
+ export * from './Prose';
@@ -70,3 +70,19 @@ describe('Search', () => {
70
70
  expect(await axe(container)).toHaveNoViolations();
71
71
  });
72
72
  });
73
+
74
+
75
+ describe('Search controlled value', () => {
76
+ it('follows the controlled value and clears when set to null', () => {
77
+ const options = [
78
+ { value: 'a', label: 'Alpha' },
79
+ { value: 'b', label: 'Beta' },
80
+ ];
81
+ const { rerender } = render(<Search options={options} value="a" aria-label="Pick" />);
82
+ expect(screen.getByRole('combobox')).toHaveValue('Alpha');
83
+ rerender(<Search options={options} value="b" aria-label="Pick" />);
84
+ expect(screen.getByRole('combobox')).toHaveValue('Beta');
85
+ rerender(<Search options={options} value={null} aria-label="Pick" />);
86
+ expect(screen.getByRole('combobox')).toHaveValue('');
87
+ });
88
+ });
@@ -18,6 +18,8 @@ export type SearchOption = {
18
18
  export type SearchProps = {
19
19
  /** The full option set; filtered client-side as the user types. */
20
20
  options: SearchOption[];
21
+ /** Controlled selected value (display follows it). null clears the selection. */
22
+ value?: string | null;
21
23
  /** Initially selected option value. Selection is reported via onValueChange. */
22
24
  defaultValue?: string;
23
25
  /** Called with the selected option's value. */
@@ -41,6 +43,7 @@ export type SearchProps = {
41
43
  */
42
44
  export function Search({
43
45
  options,
46
+ value,
44
47
  defaultValue,
45
48
  onValueChange,
46
49
  placeholder = 'Search…',
@@ -51,12 +54,18 @@ export function Search({
51
54
  className,
52
55
  'aria-label': ariaLabel,
53
56
  }: SearchProps) {
57
+ const activeValue = value === undefined ? defaultValue : value ?? undefined;
54
58
  const selected = React.useMemo(
55
- () => options.find((option) => option.value === defaultValue),
56
- [options, defaultValue]
59
+ () => options.find((option) => option.value === activeValue),
60
+ [options, activeValue]
57
61
  );
58
62
  const [query, setQuery] = React.useState(selected?.label ?? '');
59
63
 
64
+ // Controlled usage: follow the parent's value (including external clears).
65
+ React.useEffect(() => {
66
+ if (value !== undefined) setQuery(selected?.label ?? '');
67
+ }, [value, selected]);
68
+
60
69
  const filtered = React.useMemo(() => {
61
70
  if (!query.trim()) return options;
62
71
  const q = query.trim().toLowerCase();
@@ -0,0 +1,32 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { axe } from 'jest-axe';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { SectionHeading } from './SectionHeading';
5
+
6
+ describe('SectionHeading', () => {
7
+ it('renders eyebrow, title, description and actions at the requested level', () => {
8
+ render(
9
+ <SectionHeading
10
+ eyebrow="Components"
11
+ title="Built for agents"
12
+ description="Every component ships a spec."
13
+ level={3}
14
+ actions={<a href="/docs">All docs</a>}
15
+ />
16
+ );
17
+ expect(screen.getByText('Components')).toBeInTheDocument();
18
+ expect(screen.getByRole('heading', { level: 3, name: 'Built for agents' })).toBeInTheDocument();
19
+ expect(screen.getByText('Every component ships a spec.')).toBeInTheDocument();
20
+ expect(screen.getByRole('link', { name: 'All docs' })).toBeInTheDocument();
21
+ });
22
+
23
+ it('supports centered hero sizes', () => {
24
+ render(<SectionHeading title="Centered" align="center" size="lg" />);
25
+ expect(screen.getByRole('heading', { name: 'Centered' })).toHaveClass('text-3xl');
26
+ });
27
+
28
+ it('has no accessibility violations', async () => {
29
+ const { container } = render(<SectionHeading title="Section" description="Copy" />);
30
+ expect(await axe(container)).toHaveNoViolations();
31
+ });
32
+ });
@@ -0,0 +1,54 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils/cn';
3
+
4
+ export type SectionHeadingProps = React.HTMLAttributes<HTMLDivElement> & {
5
+ title: string;
6
+ description?: string;
7
+ /** Kicker above the title (category, step, overline). */
8
+ eyebrow?: React.ReactNode;
9
+ /** Right-aligned actions (link to all, buttons). */
10
+ actions?: React.ReactNode;
11
+ /** Heading level rendered for the title (default h2). */
12
+ level?: 2 | 3 | 4;
13
+ align?: 'left' | 'center';
14
+ size?: 'sm' | 'md' | 'lg';
15
+ };
16
+
17
+ const sizeClasses: Record<NonNullable<SectionHeadingProps['size']>, string> = {
18
+ sm: 'text-lg',
19
+ md: 'text-2xl',
20
+ lg: 'text-3xl',
21
+ };
22
+
23
+ /**
24
+ * Marketing/content section heading: eyebrow, title, description and an
25
+ * actions slot, with heading level and alignment control. Complements
26
+ * PageHeader (which owns the page's single h1).
27
+ */
28
+ export const SectionHeading = React.forwardRef<HTMLDivElement, SectionHeadingProps>(function SectionHeading(
29
+ { title, description, eyebrow, actions, level = 2, align = 'left', size = 'md', className, ...props },
30
+ ref
31
+ ) {
32
+ const Heading = `h${level}` as 'h2' | 'h3' | 'h4';
33
+
34
+ return (
35
+ <div
36
+ ref={ref}
37
+ className={cn(
38
+ 'flex flex-col gap-2',
39
+ align === 'center' ? 'items-center text-center' : 'sm:flex-row sm:items-end sm:justify-between',
40
+ className
41
+ )}
42
+ {...props}
43
+ >
44
+ <div className={cn('min-w-0', align === 'center' && 'flex flex-col items-center')}>
45
+ {eyebrow && <p className="mb-1 text-xs font-medium uppercase tracking-wide text-primary">{eyebrow}</p>}
46
+ <Heading className={cn('font-semibold tracking-tight', sizeClasses[size])}>{title}</Heading>
47
+ {description && (
48
+ <p className={cn('mt-2 max-w-2xl text-muted-foreground', align === 'center' ? 'mx-auto' : '')}>{description}</p>
49
+ )}
50
+ </div>
51
+ {actions && <div className="flex shrink-0 items-center gap-2">{actions}</div>}
52
+ </div>
53
+ );
54
+ });
@@ -0,0 +1 @@
1
+ export * from './SectionHeading';
@@ -30,6 +30,8 @@ export type SelectProps = Omit<
30
30
  value?: string | string[];
31
31
  defaultValue?: string | string[];
32
32
  onChange?: (value: string | string[]) => void;
33
+ /** Alias for onChange — the value-based callback used by most codebases. */
34
+ onValueChange?: (value: string | string[]) => void;
33
35
  };
34
36
 
35
37
  /**
@@ -39,7 +41,7 @@ export type SelectProps = Omit<
39
41
  * placeholder rows and native multi-select (string[] contract).
40
42
  */
41
43
  export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(function Select(
42
- { options, groups, label, placeholder, multiple = false, value, defaultValue, onChange, id, className, ...props },
44
+ { options, groups, label, placeholder, multiple = false, value, defaultValue, onChange, onValueChange, id, className, ...props },
43
45
  ref,
44
46
  ) {
45
47
  const generatedId = React.useId();
@@ -69,17 +71,17 @@ export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(function
69
71
  multiple && 'min-h-32',
70
72
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
71
73
  'disabled:cursor-not-allowed disabled:opacity-50',
74
+ 'aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20',
72
75
  className
73
76
  )}
74
77
  value={value as string | string[] | undefined}
75
78
  defaultValue={defaultValue as string | string[] | undefined}
76
79
  onChange={(event) => {
77
- if (!onChange) return;
78
- if (multiple) {
79
- onChange(Array.from(event.target.selectedOptions, (option) => option.value));
80
- return;
81
- }
82
- onChange(event.target.value);
80
+ const next = multiple
81
+ ? Array.from(event.target.selectedOptions, (option) => option.value)
82
+ : event.target.value;
83
+ onChange?.(next);
84
+ onValueChange?.(next);
83
85
  }}
84
86
  {...props}
85
87
  >
@@ -0,0 +1,30 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { axe } from 'jest-axe';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { SiteFooter } from './SiteFooter';
5
+
6
+ describe('SiteFooter', () => {
7
+ it('renders columns, external links and the legal bar', () => {
8
+ render(
9
+ <SiteFooter
10
+ brand={<span>Acme</span>}
11
+ tagline="Ship faster."
12
+ columns={[
13
+ { title: 'Product', links: [{ label: 'Docs', href: '/docs' }, { label: 'GitHub', href: 'https://github.com/x', external: true }] },
14
+ { title: 'Legal', links: [{ label: 'Privacy', href: '/privacy' }] },
15
+ ]}
16
+ legal={<span>© 2026 Acme</span>}
17
+ />
18
+ );
19
+ expect(screen.getByText('Acme')).toBeInTheDocument();
20
+ expect(screen.getByText('Ship faster.')).toBeInTheDocument();
21
+ expect(screen.getByRole('heading', { name: 'Product' })).toBeInTheDocument();
22
+ expect(screen.getByRole('link', { name: 'GitHub' })).toHaveAttribute('rel', 'noopener noreferrer');
23
+ expect(screen.getByText('© 2026 Acme')).toBeInTheDocument();
24
+ });
25
+
26
+ it('has no accessibility violations', async () => {
27
+ const { container } = render(<SiteFooter columns={[{ title: 'Docs', links: [{ label: 'Intro', href: '/docs' }] }]} />);
28
+ expect(await axe(container)).toHaveNoViolations();
29
+ });
30
+ });
@@ -0,0 +1,79 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils/cn';
3
+
4
+ export type SiteFooterLink = {
5
+ label: string;
6
+ href: string;
7
+ external?: boolean;
8
+ };
9
+
10
+ export type SiteFooterColumn = {
11
+ title: string;
12
+ links: SiteFooterLink[];
13
+ };
14
+
15
+ export type SiteFooterProps = React.HTMLAttributes<HTMLElement> & {
16
+ /** Brand slot (logo/lockup). */
17
+ brand?: React.ReactNode;
18
+ /** Short line under the brand. */
19
+ tagline?: string;
20
+ columns: SiteFooterColumn[];
21
+ /** Bottom bar (copyright, legal links). */
22
+ legal?: React.ReactNode;
23
+ /** Router link element. */
24
+ linkComponent?: React.ElementType;
25
+ };
26
+
27
+ /**
28
+ * Marketing footer: brand + tagline column, link columns, and a legal bar.
29
+ * Router-agnostic through `linkComponent`; external links get safe rel.
30
+ */
31
+ export function SiteFooter({
32
+ brand,
33
+ tagline,
34
+ columns,
35
+ legal,
36
+ linkComponent,
37
+ className,
38
+ ...props
39
+ }: SiteFooterProps) {
40
+ const Link = linkComponent ?? 'a';
41
+
42
+ return (
43
+ <footer className={cn('border-t border-border bg-muted/30', className)} {...props}>
44
+ <div className="mx-auto grid w-full max-w-7xl gap-8 px-4 py-12 sm:grid-cols-2 sm:px-6 lg:grid-cols-4">
45
+ <div className="min-w-0">
46
+ {brand}
47
+ {tagline && <p className="mt-3 max-w-56 text-sm text-muted-foreground">{tagline}</p>}
48
+ </div>
49
+ {columns.map((column) => (
50
+ <div key={column.title}>
51
+ <h3 className="mb-3 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
52
+ {column.title}
53
+ </h3>
54
+ <ul className="space-y-2 text-sm">
55
+ {column.links.map((link) => (
56
+ <li key={`${column.title}-${link.href}-${link.label}`}>
57
+ <Link
58
+ href={link.href}
59
+ {...(link.external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
60
+ className="text-muted-foreground transition-colors hover:text-foreground"
61
+ >
62
+ {link.label}
63
+ </Link>
64
+ </li>
65
+ ))}
66
+ </ul>
67
+ </div>
68
+ ))}
69
+ </div>
70
+ {legal && (
71
+ <div className="border-t border-border">
72
+ <div className="mx-auto flex w-full max-w-7xl flex-wrap items-center justify-between gap-2 px-4 py-4 text-xs text-muted-foreground sm:px-6">
73
+ {legal}
74
+ </div>
75
+ </div>
76
+ )}
77
+ </footer>
78
+ );
79
+ }
@@ -0,0 +1 @@
1
+ export * from './SiteFooter';
@@ -0,0 +1,53 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { axe } from 'jest-axe';
4
+ import { describe, expect, it } from 'vitest';
5
+ import { SiteHeader } from './SiteHeader';
6
+
7
+ const items = [
8
+ { href: '/docs', label: 'Docs' },
9
+ { href: '/changelog', label: 'Changelog' },
10
+ { href: 'https://github.com/x', label: 'GitHub', external: true },
11
+ ];
12
+
13
+ describe('SiteHeader', () => {
14
+ it('renders brand, navigation and external safety', () => {
15
+ render(<SiteHeader brand={<span>Acme</span>} items={items} activeHref="/docs/components" />);
16
+ expect(screen.getByRole('link', { name: 'Home' })).toBeInTheDocument();
17
+ const docs = screen.getByRole('link', { name: 'Docs' });
18
+ expect(docs).toHaveAttribute('aria-current', 'page'); // prefix match
19
+ expect(screen.getByRole('link', { name: 'Changelog' })).not.toHaveAttribute('aria-current');
20
+ const external = screen.getByRole('link', { name: 'GitHub' });
21
+ expect(external).toHaveAttribute('target', '_blank');
22
+ expect(external).toHaveAttribute('rel', 'noopener noreferrer');
23
+ });
24
+
25
+ it('respects exact matching', () => {
26
+ render(<SiteHeader brand={<span>Acme</span>} items={items} activeHref="/docs/components" match="exact" />);
27
+ expect(screen.getByRole('link', { name: 'Docs' })).not.toHaveAttribute('aria-current');
28
+ });
29
+
30
+ it('uses a router link component', () => {
31
+ function RouterLink({ href, children, ...props }: React.ComponentProps<'a'>) {
32
+ return (
33
+ <a data-router href={href} {...props}>
34
+ {children}
35
+ </a>
36
+ );
37
+ }
38
+ render(<SiteHeader brand={<span>Acme</span>} items={items} linkComponent={RouterLink} />);
39
+ expect(screen.getByRole('link', { name: 'Docs' })).toHaveAttribute('data-router');
40
+ });
41
+
42
+ it('opens the mobile drawer', async () => {
43
+ const user = userEvent.setup();
44
+ render(<SiteHeader brand={<span>Acme</span>} items={items} />);
45
+ await user.click(screen.getByRole('button', { name: 'Open menu' }));
46
+ expect(screen.getByRole('dialog', { name: 'Menu' })).toBeInTheDocument();
47
+ });
48
+
49
+ it('has no accessibility violations', async () => {
50
+ const { container } = render(<SiteHeader brand={<span>Acme</span>} items={items} activeHref="/docs" />);
51
+ expect(await axe(container)).toHaveNoViolations();
52
+ });
53
+ });
@@ -0,0 +1,124 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { cn } from '../../utils/cn';
5
+ import { Drawer } from '../drawer/Drawer';
6
+
7
+ export type SiteNavItem = {
8
+ href: string;
9
+ label: string;
10
+ /** Render with target=_blank + rel=noopener. */
11
+ external?: boolean;
12
+ };
13
+
14
+ export type SiteHeaderProps = React.HTMLAttributes<HTMLElement> & {
15
+ /** Brand slot — logo/lockup or wordmark. Wrapped in a link to "/". */
16
+ brand: React.ReactNode;
17
+ /** Primary navigation items. */
18
+ items: SiteNavItem[];
19
+ /** Current route for active styling (aria-current="page"). */
20
+ activeHref?: string;
21
+ /**
22
+ * Active matching: 'prefix' highlights /docs when on /docs/installation
23
+ * (default — marketing), 'exact' only the identical href (app chrome).
24
+ */
25
+ match?: 'prefix' | 'exact';
26
+ /** Right-aligned actions (theme toggle, GitHub, CTA). */
27
+ actions?: React.ReactNode;
28
+ /** Custom link element for routers (Next Link, react-router Link). */
29
+ linkComponent?: React.ElementType;
30
+ /** Pin to the top (default true). */
31
+ sticky?: boolean;
32
+ /** Title of the mobile navigation drawer. Default 'Menu'. */
33
+ mobileLabel?: string;
34
+ };
35
+
36
+ function isActive(itemHref: string, activeHref: string | undefined, match: 'prefix' | 'exact'): boolean {
37
+ if (!activeHref) return false;
38
+ if (itemHref === activeHref) return true;
39
+ if (match === 'exact') return false;
40
+ // Prefix match on path boundaries: /docs matches /docs/components, not /docsx.
41
+ return activeHref === itemHref || activeHref.startsWith(itemHref.endsWith('/') ? itemHref : `${itemHref}/`);
42
+ }
43
+
44
+ /**
45
+ * Marketing/site header: sticky bar with brand, horizontal navigation with
46
+ * prefix-aware active states, right-aligned actions and a mobile drawer.
47
+ * Router-agnostic through `linkComponent`.
48
+ */
49
+ export function SiteHeader({
50
+ brand,
51
+ items,
52
+ activeHref,
53
+ match = 'prefix',
54
+ actions,
55
+ linkComponent,
56
+ sticky = true,
57
+ mobileLabel = 'Menu',
58
+ className,
59
+ ...props
60
+ }: SiteHeaderProps) {
61
+ const [mobileOpen, setMobileOpen] = React.useState(false);
62
+ const Link = linkComponent ?? 'a';
63
+
64
+ const navLink = (item: SiteNavItem, extra?: string) => {
65
+ const active = isActive(item.href, activeHref, match);
66
+ return (
67
+ <Link
68
+ key={item.href}
69
+ href={item.href}
70
+ aria-current={active ? 'page' : undefined}
71
+ {...(item.external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
72
+ onClick={extra === 'mobile' ? () => setMobileOpen(false) : undefined}
73
+ className={cn(
74
+ 'rounded-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
75
+ extra === 'mobile'
76
+ ? 'block rounded-md px-3 py-2 text-base hover:bg-accent'
77
+ : 'text-sm hover:text-foreground',
78
+ active ? 'font-medium text-foreground' : 'text-muted-foreground'
79
+ )}
80
+ >
81
+ {item.label}
82
+ </Link>
83
+ );
84
+ };
85
+
86
+ return (
87
+ <>
88
+ <header
89
+ className={cn(
90
+ 'w-full border-b border-border bg-background/80 backdrop-blur supports-[backdrop-filter]:bg-background/60',
91
+ sticky && 'sticky top-0 z-40',
92
+ className
93
+ )}
94
+ {...props}
95
+ >
96
+ <nav className="mx-auto flex h-14 w-full max-w-7xl items-center justify-between gap-4 px-4 sm:px-6">
97
+ <div className="flex min-w-0 items-center gap-6">
98
+ <Link href="/" aria-label="Home" className="flex shrink-0 items-center">
99
+ {brand}
100
+ </Link>
101
+ <div className="hidden items-center gap-5 md:flex">{items.map((item) => navLink(item))}</div>
102
+ </div>
103
+ <div className="flex items-center gap-2">
104
+ {actions}
105
+ <button
106
+ type="button"
107
+ onClick={() => setMobileOpen(true)}
108
+ aria-label="Open menu"
109
+ className="rounded-md border border-border p-2 text-muted-foreground hover:bg-muted md:hidden"
110
+ >
111
+ <span aria-hidden="true">☰</span>
112
+ </button>
113
+ </div>
114
+ </nav>
115
+ </header>
116
+ <Drawer open={mobileOpen} onOpenChange={setMobileOpen} title={mobileLabel} side="right" size="sm" animate>
117
+ <nav aria-label="Mobile" className="flex flex-col gap-1">
118
+ {items.map((item) => navLink(item, 'mobile'))}
119
+ </nav>
120
+ {actions && <div className="mt-4 border-t border-border pt-4">{actions}</div>}
121
+ </Drawer>
122
+ </>
123
+ );
124
+ }
@@ -0,0 +1 @@
1
+ export * from './SiteHeader';