@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,143 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
|
|
6
|
+
export type FileUploadProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'value' | 'onChange'> & {
|
|
7
|
+
/** Controlled selection. */
|
|
8
|
+
files?: File[];
|
|
9
|
+
/** Initial selection when uncontrolled. */
|
|
10
|
+
defaultFiles?: File[];
|
|
11
|
+
/** Fired whenever the list changes (add, remove, drop, clear). */
|
|
12
|
+
onFilesChange?: (files: File[]) => void;
|
|
13
|
+
/** Drag-and-drop area copy. */
|
|
14
|
+
label?: string;
|
|
15
|
+
hint?: string;
|
|
16
|
+
/** Per-file progress (0-100) keyed by file name, rendered as a bar. */
|
|
17
|
+
progress?: Record<string, number>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function formatSize(bytes: number): string {
|
|
21
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
22
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
23
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Drag-and-drop file picker with a removable list. The native input drives
|
|
28
|
+
* selection (keyboard + mobile camera/file dialogs); the drop zone is a
|
|
29
|
+
* progressive enhancement. Files are plain `File` objects, so you own the
|
|
30
|
+
* upload transport and can render progress per file.
|
|
31
|
+
*/
|
|
32
|
+
export const FileUpload = React.forwardRef<HTMLInputElement, FileUploadProps>(function FileUpload(
|
|
33
|
+
{
|
|
34
|
+
files,
|
|
35
|
+
defaultFiles,
|
|
36
|
+
onFilesChange,
|
|
37
|
+
label = 'Drop files here or click to browse',
|
|
38
|
+
hint,
|
|
39
|
+
progress,
|
|
40
|
+
multiple = true,
|
|
41
|
+
accept,
|
|
42
|
+
disabled,
|
|
43
|
+
className,
|
|
44
|
+
id,
|
|
45
|
+
...props
|
|
46
|
+
},
|
|
47
|
+
ref
|
|
48
|
+
) {
|
|
49
|
+
const [internal, setInternal] = React.useState<File[]>(defaultFiles ?? []);
|
|
50
|
+
const [dragging, setDragging] = React.useState(false);
|
|
51
|
+
const current = files ?? internal;
|
|
52
|
+
const generatedId = React.useId();
|
|
53
|
+
const inputId = id ?? generatedId;
|
|
54
|
+
|
|
55
|
+
const commit = (next: File[]) => {
|
|
56
|
+
if (files === undefined) setInternal(next);
|
|
57
|
+
onFilesChange?.(next);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const add = (incoming: FileList | null) => {
|
|
61
|
+
if (!incoming || incoming.length === 0) return;
|
|
62
|
+
const list = Array.from(incoming);
|
|
63
|
+
commit(multiple ? [...current, ...list] : list.slice(0, 1));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className={cn('flex flex-col gap-3', className)}>
|
|
68
|
+
<div
|
|
69
|
+
onDragOver={(event) => {
|
|
70
|
+
if (disabled) return;
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
setDragging(true);
|
|
73
|
+
}}
|
|
74
|
+
onDragLeave={() => setDragging(false)}
|
|
75
|
+
onDrop={(event) => {
|
|
76
|
+
if (disabled) return;
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
setDragging(false);
|
|
79
|
+
add(event.dataTransfer.files);
|
|
80
|
+
}}
|
|
81
|
+
className={cn(
|
|
82
|
+
'rounded-lg border border-dashed border-border p-6 text-center transition-colors',
|
|
83
|
+
dragging && 'border-primary bg-primary/5',
|
|
84
|
+
disabled && 'opacity-50'
|
|
85
|
+
)}
|
|
86
|
+
>
|
|
87
|
+
<label htmlFor={inputId} className={cn('block text-sm', disabled ? 'cursor-not-allowed' : 'cursor-pointer')}>
|
|
88
|
+
{label}
|
|
89
|
+
<input
|
|
90
|
+
ref={ref}
|
|
91
|
+
id={inputId}
|
|
92
|
+
type="file"
|
|
93
|
+
multiple={multiple}
|
|
94
|
+
accept={accept}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
className="sr-only"
|
|
97
|
+
onChange={(event) => {
|
|
98
|
+
add(event.target.files);
|
|
99
|
+
event.target.value = '';
|
|
100
|
+
}}
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
</label>
|
|
104
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
105
|
+
{hint ?? (accept ? `Accepted: ${accept}` : 'Any file type')}
|
|
106
|
+
</p>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
{current.length > 0 && (
|
|
110
|
+
<ul aria-label="Selected files" className="space-y-2">
|
|
111
|
+
{current.map((file) => (
|
|
112
|
+
<li key={file.name} className="flex items-center justify-between gap-3 rounded-md border border-border px-3 py-2">
|
|
113
|
+
<div className="min-w-0">
|
|
114
|
+
<p className="truncate text-sm">{file.name}</p>
|
|
115
|
+
<p className="text-xs text-muted-foreground">{formatSize(file.size)}</p>
|
|
116
|
+
{progress?.[file.name] !== undefined && (
|
|
117
|
+
<div
|
|
118
|
+
role="progressbar"
|
|
119
|
+
aria-valuenow={progress[file.name]}
|
|
120
|
+
aria-valuemin={0}
|
|
121
|
+
aria-valuemax={100}
|
|
122
|
+
aria-label={`Uploading ${file.name}`}
|
|
123
|
+
className="mt-1 h-1.5 w-40 overflow-hidden rounded-full bg-muted"
|
|
124
|
+
>
|
|
125
|
+
<div className="h-full bg-primary" style={{ width: `${progress[file.name]}%` }} />
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
128
|
+
</div>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
onClick={() => commit(current.filter((entry) => entry.name !== file.name))}
|
|
132
|
+
aria-label={`Remove ${file.name}`}
|
|
133
|
+
className="rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
134
|
+
>
|
|
135
|
+
✕
|
|
136
|
+
</button>
|
|
137
|
+
</li>
|
|
138
|
+
))}
|
|
139
|
+
</ul>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FileUpload';
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { FilterBar } from './FilterBar';
|
|
6
|
+
|
|
7
|
+
describe('FilterBar', () => {
|
|
8
|
+
it('reports search input changes', async () => {
|
|
9
|
+
const user = userEvent.setup();
|
|
10
|
+
const onSearchChange = vi.fn();
|
|
11
|
+
render(<FilterBar searchValue="" onSearchChange={onSearchChange} searchPlaceholder="Search classes" />);
|
|
12
|
+
await user.type(screen.getByRole('searchbox', { name: 'Search classes' }), 'ab');
|
|
13
|
+
expect(onSearchChange).toHaveBeenCalled();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('shows a reset button with the active count and fires it', async () => {
|
|
17
|
+
const user = userEvent.setup();
|
|
18
|
+
const onReset = vi.fn();
|
|
19
|
+
render(<FilterBar onReset={onReset} activeCount={2}><span>filters</span></FilterBar>);
|
|
20
|
+
await user.click(screen.getByRole('button', { name: 'Reset (2)' }));
|
|
21
|
+
expect(onReset).toHaveBeenCalledOnce();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('has no accessibility violations', async () => {
|
|
25
|
+
const { container } = render(
|
|
26
|
+
<FilterBar searchValue="" onSearchChange={() => undefined} onReset={() => undefined}>
|
|
27
|
+
<select aria-label="Status"><option>All</option></select>
|
|
28
|
+
</FilterBar>
|
|
29
|
+
);
|
|
30
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
import { Button } from '../button/Button';
|
|
6
|
+
import { Input } from '../input/Input';
|
|
7
|
+
|
|
8
|
+
export type FilterBarProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
9
|
+
/** Controlled search text. */
|
|
10
|
+
searchValue?: string;
|
|
11
|
+
onSearchChange?: (value: string) => void;
|
|
12
|
+
/** Search placeholder; the search box is hidden when omitted. */
|
|
13
|
+
searchPlaceholder?: string;
|
|
14
|
+
/** Rendered after the search box — selects, toggles, date pickers. */
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
/** Shows a reset button when provided (pass the active filter count for the label). */
|
|
17
|
+
onReset?: () => void;
|
|
18
|
+
activeCount?: number;
|
|
19
|
+
/** Rendered at the far right (bulk actions, column settings). */
|
|
20
|
+
trailing?: React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Horizontal filter strip for list pages: search field, filter controls and
|
|
25
|
+
* a reset affordance. Scrolls horizontally on narrow screens instead of
|
|
26
|
+
* wrapping into a tall stack.
|
|
27
|
+
*/
|
|
28
|
+
export const FilterBar = React.forwardRef<HTMLDivElement, FilterBarProps>(function FilterBar(
|
|
29
|
+
{
|
|
30
|
+
searchValue,
|
|
31
|
+
onSearchChange,
|
|
32
|
+
searchPlaceholder = 'Search…',
|
|
33
|
+
onReset,
|
|
34
|
+
activeCount = 0,
|
|
35
|
+
trailing,
|
|
36
|
+
className,
|
|
37
|
+
children,
|
|
38
|
+
...props
|
|
39
|
+
},
|
|
40
|
+
ref
|
|
41
|
+
) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
ref={ref}
|
|
45
|
+
role="search"
|
|
46
|
+
className={cn(
|
|
47
|
+
'flex flex-wrap items-center gap-2 rounded-lg border border-border bg-card p-2',
|
|
48
|
+
className
|
|
49
|
+
)}
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
{onSearchChange !== undefined && (
|
|
53
|
+
<Input
|
|
54
|
+
type="search"
|
|
55
|
+
value={searchValue}
|
|
56
|
+
onChange={(event) => onSearchChange(event.target.value)}
|
|
57
|
+
placeholder={searchPlaceholder}
|
|
58
|
+
aria-label={searchPlaceholder}
|
|
59
|
+
className="h-9 w-full min-w-40 flex-1 sm:w-auto"
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
<div className="flex flex-wrap items-center gap-2">{children}</div>
|
|
63
|
+
{onReset && (
|
|
64
|
+
<Button type="button" variant="ghost" size="sm" onClick={onReset}>
|
|
65
|
+
Reset{activeCount > 0 ? ` (${activeCount})` : ''}
|
|
66
|
+
</Button>
|
|
67
|
+
)}
|
|
68
|
+
{trailing && <div className="ml-auto flex items-center gap-2">{trailing}</div>}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FilterBar';
|
|
@@ -14,6 +14,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
14
14
|
'placeholder:text-muted-foreground',
|
|
15
15
|
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
|
|
16
16
|
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
17
|
+
'aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20',
|
|
17
18
|
className
|
|
18
19
|
)}
|
|
19
20
|
ref={ref}
|
|
@@ -15,9 +15,12 @@ describe('InputGroup', () => {
|
|
|
15
15
|
);
|
|
16
16
|
const group = container.querySelector('[data-slot="input-group"]')!;
|
|
17
17
|
expect(group).toHaveClass('border', 'rounded-md', 'focus-within:ring-2');
|
|
18
|
-
// Chrome-stripping rides on descendant selectors in the
|
|
19
|
-
|
|
20
|
-
expect(group.className).toContain('[&_input]
|
|
18
|
+
// Chrome-stripping rides on important descendant selectors in the
|
|
19
|
+
// group's class so no inner border/outline can show at addon seams.
|
|
20
|
+
expect(group.className).toContain('[&_input]:!border-0');
|
|
21
|
+
expect(group.className).toContain('[&_input]:!bg-transparent');
|
|
22
|
+
expect(group.className).toContain('[&_input]:!ring-0');
|
|
23
|
+
expect(group.className).toContain('[&_input]:!outline-none');
|
|
21
24
|
expect(group.className).toContain('[&_input]:flex-1');
|
|
22
25
|
expect(group.querySelector('input')).toHaveAttribute('placeholder', 'Search');
|
|
23
26
|
});
|
|
@@ -56,12 +56,15 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
|
|
|
56
56
|
className={cn(
|
|
57
57
|
'flex h-10 w-full items-center overflow-hidden rounded-md border border-input bg-background',
|
|
58
58
|
'ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2',
|
|
59
|
-
// The group is the
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
'[&
|
|
59
|
+
// The group's outline is the only outline: force-strip every
|
|
60
|
+
// nested field's border, radius, ring, shadow and UA focus outline.
|
|
61
|
+
// Important flags defeat both the component's own utilities
|
|
62
|
+
// (Input ships `border` + `focus-visible:ring-2`) and browser
|
|
63
|
+
// defaults — no seams appear where an addon sits flush.
|
|
64
|
+
'[&_input]:h-full [&_input]:min-w-0 [&_input]:flex-1 [&_input]:rounded-none [&_input]:px-3 [&_input]:py-2',
|
|
65
|
+
'[&_input]:!border-0 [&_input]:!bg-transparent [&_input]:!shadow-none [&_input]:!outline-none [&_input]:!ring-0 [&_input]:!ring-offset-0',
|
|
66
|
+
'[&_textarea]:!border-0 [&_textarea]:!rounded-none [&_textarea]:!bg-transparent [&_textarea]:!shadow-none [&_textarea]:!outline-none [&_textarea]:!ring-0 [&_textarea]:!ring-offset-0',
|
|
67
|
+
'[&_select]:!border-0 [&_select]:!rounded-none [&_select]:!bg-transparent [&_select]:!shadow-none [&_select]:!outline-none [&_select]:!ring-0 [&_select]:!ring-offset-0',
|
|
65
68
|
'[&_input:disabled]:cursor-not-allowed',
|
|
66
69
|
className
|
|
67
70
|
)}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { Link } from './Link';
|
|
5
|
+
|
|
6
|
+
describe('Link', () => {
|
|
7
|
+
it('renders an anchor with the default variant', () => {
|
|
8
|
+
render(<Link href="/docs">Docs</Link>);
|
|
9
|
+
const link = screen.getByRole('link', { name: 'Docs' });
|
|
10
|
+
expect(link).toHaveAttribute('href', '/docs');
|
|
11
|
+
expect(link).toHaveClass('text-primary');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('auto-detects external URLs and adds rel/noopener', () => {
|
|
15
|
+
render(<Link href="https://example.com">Example</Link>);
|
|
16
|
+
const link = screen.getByRole('link', { name: /Example/ });
|
|
17
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
18
|
+
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
|
19
|
+
expect(screen.getByText('(opens in a new tab)')).toHaveClass('sr-only');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('never opens mailto/tel in a new tab', () => {
|
|
23
|
+
render(<Link href="mailto:hi@example.com">Mail</Link>);
|
|
24
|
+
expect(screen.getByRole('link', { name: 'Mail' })).not.toHaveAttribute('target');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('can opt out of external handling', () => {
|
|
28
|
+
render(
|
|
29
|
+
<Link href="https://example.com" external={false}>
|
|
30
|
+
Stay
|
|
31
|
+
</Link>
|
|
32
|
+
);
|
|
33
|
+
const link = screen.getByRole('link', { name: 'Stay' });
|
|
34
|
+
expect(link).not.toHaveAttribute('target');
|
|
35
|
+
expect(screen.queryByText('(opens in a new tab)')).not.toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('supports asChild with a router link', () => {
|
|
39
|
+
function RouterLink({ href, children, ...props }: React.ComponentProps<'a'>) {
|
|
40
|
+
return (
|
|
41
|
+
<a data-router href={href} {...props}>
|
|
42
|
+
{children}
|
|
43
|
+
</a>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
render(
|
|
47
|
+
<Link asChild variant="underline">
|
|
48
|
+
<RouterLink href="/posts">Posts</RouterLink>
|
|
49
|
+
</Link>
|
|
50
|
+
);
|
|
51
|
+
const link = screen.getByRole('link', { name: 'Posts' });
|
|
52
|
+
expect(link).toHaveAttribute('data-router');
|
|
53
|
+
expect(link).toHaveClass('underline');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('has no accessibility violations', async () => {
|
|
57
|
+
const { container } = render(<Link href="/docs">Docs</Link>);
|
|
58
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
5
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
6
|
+
import { cn } from '../../utils/cn';
|
|
7
|
+
|
|
8
|
+
const linkVariants = cva('inline-flex items-center gap-1 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-sm', {
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: 'text-primary hover:underline underline-offset-4',
|
|
12
|
+
muted: 'text-muted-foreground hover:text-foreground',
|
|
13
|
+
underline: 'underline underline-offset-4 hover:text-primary',
|
|
14
|
+
arrow: 'font-medium text-primary hover:underline underline-offset-4',
|
|
15
|
+
external: 'text-primary hover:underline underline-offset-4',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: { variant: 'default' },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> &
|
|
22
|
+
VariantProps<typeof linkVariants> & {
|
|
23
|
+
/** Render the child element (router Link) with link styling. */
|
|
24
|
+
asChild?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Force external handling (target=_blank + rel). Absolute http(s) hrefs
|
|
27
|
+
* are detected automatically; mailto:/tel: links never open a new tab.
|
|
28
|
+
*/
|
|
29
|
+
external?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ABSOLUTE = /^https?:\/\//i;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Inline link primitive with the project's link variants. Keeps a real
|
|
36
|
+
* `<a href>` (SEO, modified clicks, middle-click) and adds safe external
|
|
37
|
+
* handling: absolute URLs get target="_blank" + rel="noopener noreferrer"
|
|
38
|
+
* and a screen-reader note, unless `external={false}`.
|
|
39
|
+
*
|
|
40
|
+
* For client-side routing, wrap your router's link: `<Link asChild><RouterLink …/></Link>`.
|
|
41
|
+
*/
|
|
42
|
+
export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(
|
|
43
|
+
{ className, variant, asChild = false, external, target, rel, children, ...props },
|
|
44
|
+
ref
|
|
45
|
+
) {
|
|
46
|
+
const isAbsolute = typeof props.href === 'string' && ABSOLUTE.test(props.href);
|
|
47
|
+
const isExternal = external ?? isAbsolute;
|
|
48
|
+
const Comp = asChild ? Slot : 'a';
|
|
49
|
+
|
|
50
|
+
if (asChild) {
|
|
51
|
+
return (
|
|
52
|
+
<Comp
|
|
53
|
+
ref={ref}
|
|
54
|
+
className={cn(linkVariants({ variant }), className)}
|
|
55
|
+
target={isExternal ? target ?? '_blank' : target}
|
|
56
|
+
rel={isExternal ? rel ?? 'noopener noreferrer' : rel}
|
|
57
|
+
{...props}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</Comp>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Comp
|
|
66
|
+
ref={ref}
|
|
67
|
+
className={cn(linkVariants({ variant }), className)}
|
|
68
|
+
target={isExternal ? target ?? '_blank' : target}
|
|
69
|
+
rel={isExternal ? rel ?? 'noopener noreferrer' : rel}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
{isExternal && variant !== 'muted' && (
|
|
74
|
+
<>
|
|
75
|
+
<span aria-hidden="true" className="text-[0.75em]">
|
|
76
|
+
↗
|
|
77
|
+
</span>
|
|
78
|
+
<span className="sr-only">(opens in a new tab)</span>
|
|
79
|
+
</>
|
|
80
|
+
)}
|
|
81
|
+
</Comp>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type LinkVariant = NonNullable<VariantProps<typeof linkVariants>['variant']>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Link';
|
|
@@ -88,3 +88,24 @@ describe('Menu', () => {
|
|
|
88
88
|
expect(await axe(container)).toHaveNoViolations();
|
|
89
89
|
});
|
|
90
90
|
});
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
describe('MenuItem asChild', () => {
|
|
94
|
+
it('renders a link with menuitem semantics', async () => {
|
|
95
|
+
const user = userEvent.setup();
|
|
96
|
+
render(
|
|
97
|
+
<Menu>
|
|
98
|
+
<MenuTrigger>Options</MenuTrigger>
|
|
99
|
+
<MenuContent>
|
|
100
|
+
<MenuItem asChild>
|
|
101
|
+
<a href="/settings">Settings</a>
|
|
102
|
+
</MenuItem>
|
|
103
|
+
</MenuContent>
|
|
104
|
+
</Menu>
|
|
105
|
+
);
|
|
106
|
+
await user.click(screen.getByRole('button', { name: 'Options' }));
|
|
107
|
+
const item = screen.getByRole('menuitem', { name: 'Settings' });
|
|
108
|
+
expect(item.tagName).toBe('A');
|
|
109
|
+
expect(item).toHaveAttribute('href', '/settings');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
5
6
|
import { cn } from '../../utils/cn';
|
|
6
7
|
|
|
7
8
|
type MenuContextValue = {
|
|
@@ -214,16 +215,20 @@ MenuContent.displayName = 'MenuContent';
|
|
|
214
215
|
export type MenuItemProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
215
216
|
/** Renders the item in a destructive style. */
|
|
216
217
|
destructive?: boolean;
|
|
218
|
+
/** Render the child element (e.g. an <a>) as the menu item. */
|
|
219
|
+
asChild?: boolean;
|
|
217
220
|
};
|
|
218
221
|
|
|
219
222
|
/** A single action item in the menu. */
|
|
220
223
|
const MenuItem = React.forwardRef<HTMLButtonElement, MenuItemProps>(
|
|
221
|
-
({ className, destructive, onClick, ...props }, ref) => {
|
|
224
|
+
({ className, destructive, asChild = false, onClick, ...props }, ref) => {
|
|
222
225
|
const { setOpen } = React.useContext(MenuContext);
|
|
226
|
+
const Comp = asChild ? Slot : 'button';
|
|
227
|
+
const typeProp = asChild ? {} : { type: 'button' as const };
|
|
223
228
|
return (
|
|
224
|
-
<
|
|
229
|
+
<Comp
|
|
225
230
|
ref={ref}
|
|
226
|
-
|
|
231
|
+
{...typeProp}
|
|
227
232
|
role="menuitem"
|
|
228
233
|
onClick={(event) => {
|
|
229
234
|
onClick?.(event);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { MetricCard } from './MetricCard';
|
|
5
|
+
|
|
6
|
+
describe('MetricCard', () => {
|
|
7
|
+
it('renders label, value, delta and hint with a direction glyph', () => {
|
|
8
|
+
render(<MetricCard label="Revenue" value="$12,480" delta="+12.4%" trend="up" hint="vs last month" />);
|
|
9
|
+
expect(screen.getByText('Revenue')).toBeInTheDocument();
|
|
10
|
+
expect(screen.getByText('$12,480')).toBeInTheDocument();
|
|
11
|
+
expect(screen.getByText(/12.4%/)).toBeInTheDocument();
|
|
12
|
+
expect(screen.getByText('vs last month')).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('colors trends but never relies on color alone', () => {
|
|
16
|
+
const { rerender } = render(<MetricCard label="Churn" value="2.1%" delta="-0.4" trend="down" />);
|
|
17
|
+
const delta = screen.getByText(/-0.4/);
|
|
18
|
+
expect(delta).toHaveClass('text-destructive');
|
|
19
|
+
expect(delta.textContent).toContain('↓');
|
|
20
|
+
rerender(<MetricCard label="Churn" value="2.1%" delta="0" trend="flat" />);
|
|
21
|
+
expect(screen.getByText(/0/).textContent).toContain('→');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('has no accessibility violations', async () => {
|
|
25
|
+
const { container } = render(<MetricCard label="Users" value={1234} delta="+3%" trend="up" />);
|
|
26
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
|
|
4
|
+
export type MetricTrend = 'up' | 'down' | 'flat';
|
|
5
|
+
|
|
6
|
+
export type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string | number;
|
|
9
|
+
/** Secondary line under the value. */
|
|
10
|
+
hint?: string;
|
|
11
|
+
/** Signed change, e.g. "+12.4%" or "-3". */
|
|
12
|
+
delta?: string;
|
|
13
|
+
/** Direction colors the delta (green up / red down / muted flat). */
|
|
14
|
+
trend?: MetricTrend;
|
|
15
|
+
icon?: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const trendClasses: Record<MetricTrend, string> = {
|
|
19
|
+
up: 'text-success',
|
|
20
|
+
down: 'text-destructive',
|
|
21
|
+
flat: 'text-muted-foreground',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Compact KPI tile: label, value, optional delta with direction color and a
|
|
28
|
+
* supporting hint. Deltas always carry an arrow glyph so the direction is
|
|
29
|
+
* never communicated by color alone.
|
|
30
|
+
*/
|
|
31
|
+
export const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(
|
|
32
|
+
{ label, value, hint, delta, trend = 'flat', icon, className, ...props },
|
|
33
|
+
ref
|
|
34
|
+
) {
|
|
35
|
+
return (
|
|
36
|
+
<div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>
|
|
37
|
+
<div className="flex items-start justify-between gap-3">
|
|
38
|
+
<p className="text-sm text-muted-foreground">{label}</p>
|
|
39
|
+
{icon && <span className="text-muted-foreground [&_svg]:size-4">{icon}</span>}
|
|
40
|
+
</div>
|
|
41
|
+
<p className="mt-2 text-2xl font-semibold tabular-nums">{value}</p>
|
|
42
|
+
{(delta || hint) && (
|
|
43
|
+
<p className="mt-1 flex items-center gap-2 text-sm">
|
|
44
|
+
{delta && (
|
|
45
|
+
<span className={cn('font-medium tabular-nums', trendClasses[trend])}>
|
|
46
|
+
<span aria-hidden="true">{trendGlyph[trend]}</span> {delta}
|
|
47
|
+
</span>
|
|
48
|
+
)}
|
|
49
|
+
{hint && <span className="text-muted-foreground">{hint}</span>}
|
|
50
|
+
</p>
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MetricCard';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { PageHeader } from './PageHeader';
|
|
5
|
+
|
|
6
|
+
describe('PageHeader', () => {
|
|
7
|
+
it('renders a level-1 heading with description and actions', () => {
|
|
8
|
+
render(
|
|
9
|
+
<PageHeader
|
|
10
|
+
title="Classes"
|
|
11
|
+
description="Manage your weekly schedule."
|
|
12
|
+
actions={<button type="button">New</button>}
|
|
13
|
+
breadcrumbs={<a href="/">Home</a>}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
expect(screen.getByRole('heading', { level: 1, name: 'Classes' })).toBeInTheDocument();
|
|
17
|
+
expect(screen.getByText('Manage your weekly schedule.')).toBeInTheDocument();
|
|
18
|
+
expect(screen.getByRole('button', { name: 'New' })).toBeInTheDocument();
|
|
19
|
+
expect(screen.getByRole('link', { name: 'Home' })).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders children under the title row', () => {
|
|
23
|
+
render(<PageHeader title="Reports"><span>tabs</span></PageHeader>);
|
|
24
|
+
expect(screen.getByText('tabs')).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('has no accessibility violations', async () => {
|
|
28
|
+
const { container } = render(<PageHeader title="Dashboard" description="Overview" />);
|
|
29
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
describe('PageHeader hero options', () => {
|
|
35
|
+
it('renders eyebrow, hero size and centered alignment', () => {
|
|
36
|
+
render(
|
|
37
|
+
<PageHeader
|
|
38
|
+
title="Your AI knows the system"
|
|
39
|
+
eyebrow="AI-first"
|
|
40
|
+
size="hero"
|
|
41
|
+
align="center"
|
|
42
|
+
description="Ship correct UI the first time."
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByText('AI-first')).toBeInTheDocument();
|
|
46
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveClass('text-4xl');
|
|
47
|
+
});
|
|
48
|
+
});
|