@slipstream-ui/core 0.3.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.
- package/dist/index.d.mts +957 -56
- package/dist/index.d.ts +957 -56
- package/dist/index.js +2554 -777
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2524 -777
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/app-shell.manifest.json +206 -0
- package/dist/manifests/auth-layout.manifest.json +99 -0
- package/dist/manifests/autocomplete.manifest.json +53 -5
- package/dist/manifests/badge.manifest.json +20 -3
- package/dist/manifests/breadcrumb.manifest.json +6 -0
- package/dist/manifests/button.manifest.json +20 -2
- package/dist/manifests/card.manifest.json +53 -6
- package/dist/manifests/confirm-dialog.manifest.json +132 -0
- package/dist/manifests/data-table.manifest.json +50 -0
- package/dist/manifests/date-picker.manifest.json +87 -0
- package/dist/manifests/dialog.manifest.json +56 -4
- package/dist/manifests/drawer.manifest.json +25 -4
- package/dist/manifests/empty-state.manifest.json +108 -0
- package/dist/manifests/file-upload.manifest.json +103 -0
- package/dist/manifests/filter-bar.manifest.json +100 -0
- package/dist/manifests/link.manifest.json +106 -0
- package/dist/manifests/menu.manifest.json +13 -1
- package/dist/manifests/metric-card.manifest.json +105 -0
- package/dist/manifests/page-header.manifest.json +124 -0
- package/dist/manifests/pagination.manifest.json +68 -34
- package/dist/manifests/password-input.manifest.json +75 -0
- package/dist/manifests/prose.manifest.json +75 -0
- package/dist/manifests/search.manifest.json +41 -9
- package/dist/manifests/section-heading.manifest.json +108 -0
- package/dist/manifests/select-menu.manifest.json +142 -0
- package/dist/manifests/select.manifest.json +55 -12
- package/dist/manifests/site-footer.manifest.json +94 -0
- package/dist/manifests/site-header.manifest.json +130 -0
- package/dist/manifests/stepper.manifest.json +95 -0
- package/dist/manifests/table-card.manifest.json +123 -0
- package/dist/manifests/table-of-contents.manifest.json +87 -0
- package/dist/manifests/time-picker.manifest.json +86 -0
- package/dist/manifests/timeline.manifest.json +69 -0
- package/dist/manifests/toast.manifest.json +101 -25
- package/package.json +2 -2
- package/src/components/alert/Alert.tsx +2 -2
- package/src/components/app-shell/AppShell.test.tsx +148 -0
- package/src/components/app-shell/AppShell.tsx +266 -0
- package/src/components/app-shell/index.ts +1 -0
- package/src/components/auth-layout/AuthLayout.test.tsx +34 -0
- package/src/components/auth-layout/AuthLayout.tsx +47 -0
- package/src/components/auth-layout/index.ts +1 -0
- package/src/components/autocomplete/Autocomplete.test.tsx +53 -0
- package/src/components/autocomplete/Autocomplete.tsx +160 -41
- package/src/components/badge/Badge.test.tsx +35 -0
- package/src/components/badge/Badge.tsx +16 -4
- package/src/components/breadcrumb/Breadcrumb.test.tsx +16 -0
- package/src/components/breadcrumb/Breadcrumb.tsx +10 -5
- package/src/components/button/Button.test.tsx +67 -0
- package/src/components/button/Button.tsx +37 -3
- package/src/components/button-group/ButtonGroup.test.tsx +6 -8
- package/src/components/button-group/ButtonGroup.tsx +17 -9
- package/src/components/card/Card.test.tsx +14 -0
- package/src/components/card/Card.tsx +15 -8
- package/src/components/confirm-dialog/ConfirmDialog.test.tsx +46 -0
- package/src/components/confirm-dialog/ConfirmDialog.tsx +86 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/data-table/DataTable.test.tsx +92 -0
- package/src/components/data-table/DataTable.tsx +98 -7
- package/src/components/date-picker/DatePicker.test.tsx +30 -0
- package/src/components/date-picker/DatePicker.tsx +57 -0
- package/src/components/date-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.test.tsx +71 -1
- package/src/components/dialog/Dialog.tsx +116 -23
- package/src/components/dialog/index.ts +1 -2
- package/src/components/drawer/Drawer.test.tsx +59 -0
- package/src/components/drawer/Drawer.tsx +49 -8
- package/src/components/empty-state/EmptyState.test.tsx +30 -0
- package/src/components/empty-state/EmptyState.tsx +48 -0
- package/src/components/empty-state/index.ts +1 -0
- package/src/components/file-upload/FileUpload.test.tsx +43 -0
- package/src/components/file-upload/FileUpload.tsx +143 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-bar/FilterBar.test.tsx +32 -0
- package/src/components/filter-bar/FilterBar.tsx +71 -0
- package/src/components/filter-bar/index.ts +1 -0
- package/src/components/input/Input.tsx +1 -0
- package/src/components/input-group/InputGroup.test.tsx +6 -3
- package/src/components/input-group/InputGroup.tsx +9 -6
- package/src/components/link/Link.test.tsx +60 -0
- package/src/components/link/Link.tsx +85 -0
- package/src/components/link/index.ts +1 -0
- package/src/components/menu/Menu.test.tsx +21 -0
- package/src/components/menu/Menu.tsx +8 -3
- package/src/components/metric-card/MetricCard.test.tsx +28 -0
- package/src/components/metric-card/MetricCard.tsx +54 -0
- package/src/components/metric-card/index.ts +1 -0
- package/src/components/page-header/PageHeader.test.tsx +48 -0
- package/src/components/page-header/PageHeader.tsx +53 -0
- package/src/components/page-header/index.ts +1 -0
- package/src/components/pagination/Pagination.test.tsx +33 -0
- package/src/components/pagination/Pagination.tsx +69 -18
- package/src/components/password-input/PasswordInput.test.tsx +29 -0
- package/src/components/password-input/PasswordInput.tsx +41 -0
- package/src/components/password-input/index.ts +1 -0
- package/src/components/prose/Prose.test.tsx +35 -0
- package/src/components/prose/Prose.tsx +61 -0
- package/src/components/prose/index.ts +1 -0
- package/src/components/search/Search.test.tsx +16 -0
- package/src/components/search/Search.tsx +11 -2
- package/src/components/section-heading/SectionHeading.test.tsx +32 -0
- package/src/components/section-heading/SectionHeading.tsx +54 -0
- package/src/components/section-heading/index.ts +1 -0
- package/src/components/select/Select.test.tsx +40 -1
- package/src/components/select/Select.tsx +54 -14
- package/src/components/select/index.ts +1 -1
- package/src/components/select-menu/SelectMenu.test.tsx +105 -0
- package/src/components/select-menu/SelectMenu.tsx +368 -0
- package/src/components/select-menu/index.ts +1 -0
- package/src/components/site-footer/SiteFooter.test.tsx +30 -0
- package/src/components/site-footer/SiteFooter.tsx +79 -0
- package/src/components/site-footer/index.ts +1 -0
- package/src/components/site-header/SiteHeader.test.tsx +53 -0
- package/src/components/site-header/SiteHeader.tsx +124 -0
- package/src/components/site-header/index.ts +1 -0
- package/src/components/stepper/Stepper.test.tsx +35 -0
- package/src/components/stepper/Stepper.tsx +91 -0
- package/src/components/stepper/index.ts +1 -0
- package/src/components/switch/Switch.test.tsx +10 -0
- package/src/components/switch/Switch.tsx +8 -3
- package/src/components/table-card/TableCard.test.tsx +59 -0
- package/src/components/table-card/TableCard.tsx +48 -0
- package/src/components/table-card/index.ts +1 -0
- package/src/components/table-of-contents/TableOfContents.test.tsx +31 -0
- package/src/components/table-of-contents/TableOfContents.tsx +100 -0
- package/src/components/table-of-contents/index.ts +1 -0
- package/src/components/textarea/Textarea.tsx +1 -0
- package/src/components/time-picker/TimePicker.test.tsx +30 -0
- package/src/components/time-picker/TimePicker.tsx +56 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/timeline/Timeline.test.tsx +26 -0
- package/src/components/timeline/Timeline.tsx +53 -0
- package/src/components/timeline/index.ts +1 -0
- package/src/components/toast/Toast.test.tsx +5 -0
- package/src/components/toast/Toast.tsx +2 -16
- package/src/components/toast/Toaster.test.tsx +84 -0
- package/src/components/toast/Toaster.tsx +116 -0
- package/src/components/toast/index.ts +4 -0
- package/src/components/toast/toast-store.ts +117 -0
- package/src/index.ts +21 -0
- package/src/manifests/app-shell.manifest.json +206 -0
- package/src/manifests/auth-layout.manifest.json +99 -0
- package/src/manifests/autocomplete.manifest.json +53 -5
- package/src/manifests/badge.manifest.json +20 -3
- package/src/manifests/breadcrumb.manifest.json +6 -0
- package/src/manifests/button.manifest.json +20 -2
- package/src/manifests/card.manifest.json +53 -6
- package/src/manifests/confirm-dialog.manifest.json +132 -0
- package/src/manifests/data-table.manifest.json +50 -0
- package/src/manifests/date-picker.manifest.json +87 -0
- package/src/manifests/dialog.manifest.json +56 -4
- package/src/manifests/drawer.manifest.json +25 -4
- package/src/manifests/empty-state.manifest.json +108 -0
- package/src/manifests/file-upload.manifest.json +103 -0
- package/src/manifests/filter-bar.manifest.json +100 -0
- package/src/manifests/link.manifest.json +106 -0
- package/src/manifests/menu.manifest.json +13 -1
- package/src/manifests/metric-card.manifest.json +105 -0
- package/src/manifests/page-header.manifest.json +124 -0
- package/src/manifests/pagination.manifest.json +68 -34
- package/src/manifests/password-input.manifest.json +75 -0
- package/src/manifests/prose.manifest.json +75 -0
- package/src/manifests/search.manifest.json +41 -9
- package/src/manifests/section-heading.manifest.json +108 -0
- package/src/manifests/select-menu.manifest.json +142 -0
- package/src/manifests/select.manifest.json +55 -12
- package/src/manifests/site-footer.manifest.json +94 -0
- package/src/manifests/site-header.manifest.json +130 -0
- package/src/manifests/stepper.manifest.json +95 -0
- package/src/manifests/table-card.manifest.json +123 -0
- package/src/manifests/table-of-contents.manifest.json +87 -0
- package/src/manifests/time-picker.manifest.json +86 -0
- package/src/manifests/timeline.manifest.json +69 -0
- package/src/manifests/toast.manifest.json +101 -25
- package/src/test/tailwind-v4.test.ts +103 -0
|
@@ -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';
|
|
@@ -0,0 +1,35 @@
|
|
|
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, vi } from 'vitest';
|
|
5
|
+
import { Stepper } from './Stepper';
|
|
6
|
+
|
|
7
|
+
const steps = [{ label: 'Account' }, { label: 'Details', description: 'Studio info' }, { label: 'Review' }];
|
|
8
|
+
|
|
9
|
+
describe('Stepper', () => {
|
|
10
|
+
it('marks the active step with aria-current and states progress in text', () => {
|
|
11
|
+
render(<Stepper steps={steps} current={1} />);
|
|
12
|
+
const current = screen.getByText('Details').closest('[aria-current]');
|
|
13
|
+
expect(current).toHaveAttribute('aria-current', 'step');
|
|
14
|
+
expect(screen.getByText('(completed)')).toBeInTheDocument();
|
|
15
|
+
expect(screen.getByText('(upcoming)')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('makes steps clickable when onStepClick is provided', async () => {
|
|
19
|
+
const user = userEvent.setup();
|
|
20
|
+
const onStepClick = vi.fn();
|
|
21
|
+
render(<Stepper steps={steps} current={0} onStepClick={onStepClick} />);
|
|
22
|
+
await user.click(screen.getByRole('button', { name: /Review/ }));
|
|
23
|
+
expect(onStepClick).toHaveBeenCalledWith(2);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('supports vertical orientation', () => {
|
|
27
|
+
const { container } = render(<Stepper steps={steps} current={0} orientation="vertical" />);
|
|
28
|
+
expect(container.querySelector('ol')).toHaveClass('flex-col');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('has no accessibility violations', async () => {
|
|
32
|
+
const { container } = render(<Stepper steps={steps} current={1} />);
|
|
33
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
|
|
4
|
+
export type StepperStep = {
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type StepperProps = Omit<React.OlHTMLAttributes<HTMLOListElement>, 'onClick'> & {
|
|
10
|
+
steps: StepperStep[];
|
|
11
|
+
/** Zero-based index of the active step. */
|
|
12
|
+
current: number;
|
|
13
|
+
orientation?: 'horizontal' | 'vertical';
|
|
14
|
+
/** Makes completed/upcoming steps clickable. */
|
|
15
|
+
onStepClick?: (index: number) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Progress through a multi-step flow with proper semantics: an ordered list
|
|
20
|
+
* where the active step carries aria-current="step" and each marker states
|
|
21
|
+
* complete/current/upcoming in text, not only color.
|
|
22
|
+
*/
|
|
23
|
+
export const Stepper = React.forwardRef<HTMLOListElement, StepperProps>(function Stepper(
|
|
24
|
+
{ steps, current, orientation = 'horizontal', onStepClick, className, ...props },
|
|
25
|
+
ref
|
|
26
|
+
) {
|
|
27
|
+
return (
|
|
28
|
+
<ol
|
|
29
|
+
ref={ref}
|
|
30
|
+
className={cn(
|
|
31
|
+
'flex gap-4',
|
|
32
|
+
orientation === 'vertical' ? 'flex-col' : 'flex-wrap items-start',
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
{steps.map((step, index) => {
|
|
38
|
+
const state = index < current ? 'complete' : index === current ? 'current' : 'upcoming';
|
|
39
|
+
const interactive = Boolean(onStepClick);
|
|
40
|
+
const content = (
|
|
41
|
+
<>
|
|
42
|
+
<span
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
className={cn(
|
|
45
|
+
'flex h-7 w-7 shrink-0 items-center justify-center rounded-full border text-xs font-medium',
|
|
46
|
+
state === 'complete' && 'border-primary bg-primary text-primary-foreground',
|
|
47
|
+
state === 'current' && 'border-primary text-primary',
|
|
48
|
+
state === 'upcoming' && 'border-border text-muted-foreground'
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
{state === 'complete' ? '✓' : index + 1}
|
|
52
|
+
</span>
|
|
53
|
+
<span className="min-w-0">
|
|
54
|
+
<span className={cn('block text-sm', state === 'upcoming' ? 'text-muted-foreground' : 'font-medium')}>
|
|
55
|
+
{step.label}
|
|
56
|
+
</span>
|
|
57
|
+
{step.description && (
|
|
58
|
+
<span className="block text-xs text-muted-foreground">{step.description}</span>
|
|
59
|
+
)}
|
|
60
|
+
<span className="sr-only">
|
|
61
|
+
{state === 'complete' ? ' (completed)' : state === 'current' ? ' (current step)' : ' (upcoming)'}
|
|
62
|
+
</span>
|
|
63
|
+
</span>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<li key={step.label} className="flex min-w-0 items-start gap-2">
|
|
69
|
+
{interactive ? (
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
onClick={() => onStepClick?.(index)}
|
|
73
|
+
aria-current={state === 'current' ? 'step' : undefined}
|
|
74
|
+
className="flex items-start gap-2 rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
75
|
+
>
|
|
76
|
+
{content}
|
|
77
|
+
</button>
|
|
78
|
+
) : (
|
|
79
|
+
<div aria-current={state === 'current' ? 'step' : undefined} className="flex items-start gap-2">
|
|
80
|
+
{content}
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
{orientation === 'horizontal' && index < steps.length - 1 && (
|
|
84
|
+
<span aria-hidden="true" className="mt-3.5 hidden h-px w-8 bg-border sm:block" />
|
|
85
|
+
)}
|
|
86
|
+
</li>
|
|
87
|
+
);
|
|
88
|
+
})}
|
|
89
|
+
</ol>
|
|
90
|
+
);
|
|
91
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Stepper';
|
|
@@ -64,3 +64,13 @@ describe('Switch', () => {
|
|
|
64
64
|
expect(await axe(container)).toHaveNoViolations();
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
describe('Switch form submission', () => {
|
|
70
|
+
it('renders a hidden input while checked when name is provided', () => {
|
|
71
|
+
const { container, rerender } = render(<Switch name="notify" aria-label="Notify" defaultChecked />);
|
|
72
|
+
expect(container.querySelector('input[type="hidden"][name="notify"]')).toHaveValue('on');
|
|
73
|
+
rerender(<Switch name="notify" aria-label="Notify" checked={false} onCheckedChange={() => undefined} />);
|
|
74
|
+
expect(container.querySelector('input[type="hidden"][name="notify"]')).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -10,6 +10,8 @@ export type SwitchProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'o
|
|
|
10
10
|
defaultChecked?: boolean;
|
|
11
11
|
/** Fired when the user toggles the switch. */
|
|
12
12
|
onCheckedChange?: (checked: boolean) => void;
|
|
13
|
+
/** Name for form submission — renders a hidden "on" input while checked. */
|
|
14
|
+
name?: string;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -18,7 +20,7 @@ export type SwitchProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'o
|
|
|
18
20
|
* on/off state and keyboard users toggle with Enter or Space.
|
|
19
21
|
*/
|
|
20
22
|
const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
|
|
21
|
-
({ className, checked, defaultChecked, onCheckedChange, disabled, ...props }, ref) => {
|
|
23
|
+
({ className, checked, defaultChecked, onCheckedChange, disabled, name, ...props }, ref) => {
|
|
22
24
|
const [internalChecked, setInternalChecked] = React.useState(defaultChecked ?? false);
|
|
23
25
|
const isOn = checked ?? internalChecked;
|
|
24
26
|
|
|
@@ -28,7 +30,9 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
|
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
return (
|
|
31
|
-
|
|
33
|
+
<>
|
|
34
|
+
{name && isOn && <input type="hidden" name={name} value="on" />}
|
|
35
|
+
<button
|
|
32
36
|
type="button"
|
|
33
37
|
role="switch"
|
|
34
38
|
aria-checked={isOn}
|
|
@@ -51,7 +55,8 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
|
|
|
51
55
|
isOn ? 'translate-x-4' : 'translate-x-0'
|
|
52
56
|
)}
|
|
53
57
|
/>
|
|
54
|
-
|
|
58
|
+
</button>
|
|
59
|
+
</>
|
|
55
60
|
);
|
|
56
61
|
}
|
|
57
62
|
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { TableCard } from './TableCard';
|
|
5
|
+
|
|
6
|
+
describe('TableCard', () => {
|
|
7
|
+
it('renders header, toolbar, body and footer', () => {
|
|
8
|
+
render(
|
|
9
|
+
<TableCard
|
|
10
|
+
title="Classes"
|
|
11
|
+
description="12 active"
|
|
12
|
+
actions={<button type="button">New</button>}
|
|
13
|
+
toolbar={<span>filters</span>}
|
|
14
|
+
footer={<span>Showing 1–25 of 40</span>}
|
|
15
|
+
>
|
|
16
|
+
<table aria-label="Classes table">
|
|
17
|
+
<tbody>
|
|
18
|
+
<tr>
|
|
19
|
+
<td>Yoga</td>
|
|
20
|
+
</tr>
|
|
21
|
+
</tbody>
|
|
22
|
+
</table>
|
|
23
|
+
</TableCard>
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByRole('heading', { name: 'Classes' })).toBeInTheDocument();
|
|
26
|
+
expect(screen.getByRole('button', { name: 'New' })).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByText('filters')).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByRole('table', { name: 'Classes table' })).toBeInTheDocument();
|
|
29
|
+
expect(screen.getByText('Showing 1–25 of 40')).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders without chrome when no header props are given', () => {
|
|
33
|
+
const { container } = render(
|
|
34
|
+
<TableCard>
|
|
35
|
+
<span>body</span>
|
|
36
|
+
</TableCard>
|
|
37
|
+
);
|
|
38
|
+
expect(container.querySelector('h2')).toBeNull();
|
|
39
|
+
expect(screen.getByText('body')).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('supports padded (non-flush) content', () => {
|
|
43
|
+
const { container } = render(
|
|
44
|
+
<TableCard flush={false}>
|
|
45
|
+
<span>padded</span>
|
|
46
|
+
</TableCard>
|
|
47
|
+
);
|
|
48
|
+
expect(container.querySelector('.p-4')).not.toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('has no accessibility violations', async () => {
|
|
52
|
+
const { container } = render(
|
|
53
|
+
<TableCard title="Empty">
|
|
54
|
+
<p>Nothing to show</p>
|
|
55
|
+
</TableCard>
|
|
56
|
+
);
|
|
57
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
|
|
4
|
+
export type TableCardProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
title?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
/** Right-aligned header actions (create, export, column settings). */
|
|
8
|
+
actions?: React.ReactNode;
|
|
9
|
+
/** Row between the header and the table (filters, bulk actions). */
|
|
10
|
+
toolbar?: React.ReactNode;
|
|
11
|
+
/** Table/DataTable content. */
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/** Rendered under the table (pagination, summary). */
|
|
14
|
+
footer?: React.ReactNode;
|
|
15
|
+
/** Remove the inner padding so table edges reach the card border. */
|
|
16
|
+
flush?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Table shell: title/description + actions, an optional toolbar, an
|
|
21
|
+
* edge-to-edge table body and a footer row. Standardizes the chrome every
|
|
22
|
+
* list page grows around a Table or DataTable.
|
|
23
|
+
*/
|
|
24
|
+
export const TableCard = React.forwardRef<HTMLDivElement, TableCardProps>(function TableCard(
|
|
25
|
+
{ title, description, actions, toolbar, children, footer, flush = true, className, ...props },
|
|
26
|
+
ref
|
|
27
|
+
) {
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
ref={ref}
|
|
31
|
+
className={cn('overflow-hidden rounded-xl border border-border bg-card text-card-foreground', className)}
|
|
32
|
+
{...props}
|
|
33
|
+
>
|
|
34
|
+
{(title || description || actions) && (
|
|
35
|
+
<div className="flex flex-wrap items-start justify-between gap-3 border-b border-border px-4 py-3">
|
|
36
|
+
<div className="min-w-0">
|
|
37
|
+
{title && <h2 className="text-sm font-semibold">{title}</h2>}
|
|
38
|
+
{description && <p className="mt-0.5 text-sm text-muted-foreground">{description}</p>}
|
|
39
|
+
</div>
|
|
40
|
+
{actions && <div className="flex shrink-0 items-center gap-2">{actions}</div>}
|
|
41
|
+
</div>
|
|
42
|
+
)}
|
|
43
|
+
{toolbar && <div className="border-b border-border px-4 py-2">{toolbar}</div>}
|
|
44
|
+
<div className={cn(flush ? 'overflow-x-auto' : 'p-4')}>{children}</div>
|
|
45
|
+
{footer && <div className="border-t border-border px-4 py-3">{footer}</div>}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableCard';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { TableOfContents } from './TableOfContents';
|
|
5
|
+
|
|
6
|
+
const headings = [
|
|
7
|
+
{ id: 'intro', text: 'Introduction', level: 2 as const },
|
|
8
|
+
{ id: 'setup', text: 'Setup', level: 3 as const },
|
|
9
|
+
{ id: 'api', text: 'API', level: 2 as const },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
describe('TableOfContents', () => {
|
|
13
|
+
it('renders anchored headings with the active one marked', () => {
|
|
14
|
+
render(<TableOfContents headings={headings} activeId="setup" />);
|
|
15
|
+
expect(screen.getByRole('navigation', { name: 'On this page' })).toBeInTheDocument();
|
|
16
|
+
expect(screen.getByRole('link', { name: 'Setup' })).toHaveAttribute('aria-current', 'location');
|
|
17
|
+
expect(screen.getByRole('link', { name: 'Introduction' })).not.toHaveAttribute('aria-current');
|
|
18
|
+
expect(screen.getByRole('link', { name: 'API' })).toHaveAttribute('href', '#api');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('indents nested heading levels', () => {
|
|
22
|
+
render(<TableOfContents headings={headings} />);
|
|
23
|
+
const setupItem = screen.getByRole('link', { name: 'Setup' }).closest('li')!;
|
|
24
|
+
expect(setupItem.style.paddingLeft).toBe('0.75rem');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('has no accessibility violations', async () => {
|
|
28
|
+
const { container } = render(<TableOfContents headings={headings} activeId="intro" />);
|
|
29
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
30
|
+
});
|
|
31
|
+
});
|