@dashforge/tw 0.2.1-beta → 0.4.0-beta
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/CHANGELOG.md +257 -0
- package/CONSUMER-VALIDATION.md +130 -0
- package/PARITY.md +483 -0
- package/PERFORMANCE.md +169 -0
- package/dist/index.esm.js +801 -42
- package/dist/src/components/Accordion/Accordion.d.ts +21 -0
- package/dist/src/components/Accordion/Accordion.d.ts.map +1 -0
- package/dist/src/components/Accordion/accordion.types.d.ts +74 -0
- package/dist/src/components/Accordion/accordion.types.d.ts.map +1 -0
- package/dist/src/components/Accordion/accordion.variants.d.ts +58 -0
- package/dist/src/components/Accordion/accordion.variants.d.ts.map +1 -0
- package/dist/src/components/AppShell/AppShell.d.ts +14 -0
- package/dist/src/components/AppShell/AppShell.d.ts.map +1 -1
- package/dist/src/components/AppShell/appShell.variants.d.ts.map +1 -1
- package/dist/src/components/Autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/src/components/Autocomplete/autocomplete.variants.d.ts.map +1 -1
- package/dist/src/components/Breadcrumbs/breadcrumbs.variants.d.ts.map +1 -1
- package/dist/src/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/src/components/Dialog/Dialog.d.ts +17 -0
- package/dist/src/components/Dialog/Dialog.d.ts.map +1 -0
- package/dist/src/components/Dialog/dialog.types.d.ts +75 -0
- package/dist/src/components/Dialog/dialog.types.d.ts.map +1 -0
- package/dist/src/components/Dialog/dialog.variants.d.ts +80 -0
- package/dist/src/components/Dialog/dialog.variants.d.ts.map +1 -0
- package/dist/src/components/LeftNav/leftNav.variants.d.ts.map +1 -1
- package/dist/src/components/Popover/Popover.d.ts +15 -0
- package/dist/src/components/Popover/Popover.d.ts.map +1 -0
- package/dist/src/components/Popover/popover.types.d.ts +45 -0
- package/dist/src/components/Popover/popover.types.d.ts.map +1 -0
- package/dist/src/components/Popover/popover.variants.d.ts +34 -0
- package/dist/src/components/Popover/popover.variants.d.ts.map +1 -0
- package/dist/src/components/Snackbar/snackbar.variants.d.ts.map +1 -1
- package/dist/src/components/Switch/switch.variants.d.ts.map +1 -1
- package/dist/src/components/Tabs/Tabs.d.ts +15 -0
- package/dist/src/components/Tabs/Tabs.d.ts.map +1 -0
- package/dist/src/components/Tabs/tabs.types.d.ts +55 -0
- package/dist/src/components/Tabs/tabs.types.d.ts.map +1 -0
- package/dist/src/components/Tabs/tabs.variants.d.ts +82 -0
- package/dist/src/components/Tabs/tabs.variants.d.ts.map +1 -0
- package/dist/src/components/TextField/TextField.d.ts.map +1 -1
- package/dist/src/components/TextField/textField.types.d.ts +29 -3
- package/dist/src/components/TextField/textField.types.d.ts.map +1 -1
- package/dist/src/components/TextField/textField.variants.d.ts +6 -0
- package/dist/src/components/TextField/textField.variants.d.ts.map +1 -1
- package/dist/src/components/Tooltip/Tooltip.d.ts +29 -0
- package/dist/src/components/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/src/components/Tooltip/tooltip.types.d.ts +47 -0
- package/dist/src/components/Tooltip/tooltip.types.d.ts.map +1 -0
- package/dist/src/components/Tooltip/tooltip.variants.d.ts +34 -0
- package/dist/src/components/Tooltip/tooltip.variants.d.ts.map +1 -0
- package/dist/src/index.d.ts +16 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/components/Accordion/Accordion.test.tsx +95 -0
- package/src/components/Accordion/Accordion.tsx +97 -0
- package/src/components/Accordion/accordion.types.ts +66 -0
- package/src/components/Accordion/accordion.variants.ts +30 -0
- package/src/components/AppShell/AppShell.tsx +126 -1
- package/src/components/AppShell/appShell.variants.ts +8 -2
- package/src/components/Autocomplete/Autocomplete.tsx +77 -4
- package/src/components/Autocomplete/autocomplete.variants.ts +6 -0
- package/src/components/Breadcrumbs/breadcrumbs.variants.ts +5 -0
- package/src/components/Checkbox/Checkbox.tsx +43 -9
- package/src/components/Dialog/Dialog.test.tsx +96 -0
- package/src/components/Dialog/Dialog.tsx +93 -0
- package/src/components/Dialog/dialog.types.ts +62 -0
- package/src/components/Dialog/dialog.variants.ts +62 -0
- package/src/components/LeftNav/leftNav.variants.ts +12 -1
- package/src/components/Popover/Popover.test.tsx +72 -0
- package/src/components/Popover/Popover.tsx +55 -0
- package/src/components/Popover/popover.types.ts +42 -0
- package/src/components/Popover/popover.variants.ts +18 -0
- package/src/components/Snackbar/snackbar.variants.ts +4 -2
- package/src/components/Switch/switch.variants.ts +6 -1
- package/src/components/Tabs/Tabs.test.tsx +74 -0
- package/src/components/Tabs/Tabs.tsx +66 -0
- package/src/components/Tabs/tabs.types.ts +49 -0
- package/src/components/Tabs/tabs.variants.ts +58 -0
- package/src/components/TextField/TextField.tsx +29 -0
- package/src/components/TextField/textField.types.ts +23 -3
- package/src/components/TextField/textField.variants.ts +18 -0
- package/src/components/Tooltip/Tooltip.test.tsx +73 -0
- package/src/components/Tooltip/Tooltip.tsx +70 -0
- package/src/components/Tooltip/tooltip.types.ts +44 -0
- package/src/components/Tooltip/tooltip.variants.ts +18 -0
- package/src/index.ts +40 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { DialogVariants } from './dialog.variants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Per-slot className overrides for `<Dialog>`. Mirrors the
|
|
6
|
+
* canonical TW slotProps shape: `{ slot?: { className?: string } }`.
|
|
7
|
+
*/
|
|
8
|
+
export interface DialogSlotProps {
|
|
9
|
+
overlay?: { className?: string };
|
|
10
|
+
content?: { className?: string };
|
|
11
|
+
title?: { className?: string };
|
|
12
|
+
description?: { className?: string };
|
|
13
|
+
closeButton?: { className?: string };
|
|
14
|
+
body?: { className?: string };
|
|
15
|
+
actions?: { className?: string };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Props for the declarative `<Dialog>` component.
|
|
20
|
+
*
|
|
21
|
+
* Built on `@radix-ui/react-dialog`. Use this when:
|
|
22
|
+
* - You want full control over the dialog's open state (controlled
|
|
23
|
+
* from a parent component).
|
|
24
|
+
* - You want to mount a custom-styled dialog body / trigger that
|
|
25
|
+
* composes with the rest of your component tree.
|
|
26
|
+
* - You don't need an imperative `confirm()`-style return value
|
|
27
|
+
* (use `useDialog()` or `useConfirm()` for those).
|
|
28
|
+
*
|
|
29
|
+
* Three size variants (`sm` / `md` / `lg`) with sensible defaults.
|
|
30
|
+
* Backdrop + content animations respect `prefers-reduced-motion`.
|
|
31
|
+
*/
|
|
32
|
+
export interface DialogProps extends Pick<DialogVariants, 'size'> {
|
|
33
|
+
/** Controlled open state. */
|
|
34
|
+
open: boolean;
|
|
35
|
+
/** Called when the dialog requests to change open state. */
|
|
36
|
+
onOpenChange: (open: boolean) => void;
|
|
37
|
+
/** Dialog body — usually a `<DialogContent>` subtree. */
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
/** Dialog title (screen-reader announced via `aria-labelledby`). */
|
|
40
|
+
title?: ReactNode;
|
|
41
|
+
/** Dialog description (announced via `aria-describedby`). */
|
|
42
|
+
description?: ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Show the `×` close button in the top-right corner.
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
showCloseButton?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Disable closing on backdrop click.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
disableBackdropClose?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Disable closing on Escape key.
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
disableEscapeClose?: boolean;
|
|
58
|
+
/** Root className shortcut on the content element. */
|
|
59
|
+
sx?: string;
|
|
60
|
+
/** Per-slot overrides. */
|
|
61
|
+
slotProps?: DialogSlotProps;
|
|
62
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<Dialog>` variant recipe.
|
|
5
|
+
*
|
|
6
|
+
* Slots:
|
|
7
|
+
* - `overlay` — backdrop (Radix's `DialogOverlay`)
|
|
8
|
+
* - `content` — the dialog box itself
|
|
9
|
+
* - `title` — heading at the top
|
|
10
|
+
* - `description` — secondary text under the title
|
|
11
|
+
* - `closeButton` — top-right `×` button
|
|
12
|
+
* - `body` — main scrollable area
|
|
13
|
+
* - `actions` — footer action bar
|
|
14
|
+
*
|
|
15
|
+
* Three sizes (`sm` / `md` / `lg`) drive the content max-width.
|
|
16
|
+
* Motion is gated by `prefers-reduced-motion` so the slide-in
|
|
17
|
+
* animation collapses to an instant appear on users that opt out.
|
|
18
|
+
*/
|
|
19
|
+
export const dialogVariants = tv({
|
|
20
|
+
slots: {
|
|
21
|
+
overlay: [
|
|
22
|
+
'fixed inset-0 z-50 bg-neutral-950/60 backdrop-blur-sm',
|
|
23
|
+
'data-[state=open]:animate-in data-[state=open]:fade-in-0',
|
|
24
|
+
'data-[state=closed]:animate-out data-[state=closed]:fade-out-0',
|
|
25
|
+
'motion-reduce:transition-none motion-reduce:duration-0',
|
|
26
|
+
],
|
|
27
|
+
content: [
|
|
28
|
+
'fixed left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2',
|
|
29
|
+
'w-full bg-white dark:bg-neutral-900 rounded-lg shadow-xl',
|
|
30
|
+
'border border-neutral-200 dark:border-neutral-800',
|
|
31
|
+
'p-6 flex flex-col gap-4 max-h-[90vh]',
|
|
32
|
+
'focus:outline-none',
|
|
33
|
+
'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
|
34
|
+
'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
|
|
35
|
+
'motion-reduce:transition-none motion-reduce:duration-0',
|
|
36
|
+
],
|
|
37
|
+
title: 'text-lg font-semibold leading-tight text-neutral-900 dark:text-neutral-50',
|
|
38
|
+
description: 'text-sm text-neutral-600 dark:text-neutral-400',
|
|
39
|
+
closeButton: [
|
|
40
|
+
'absolute top-4 right-4 inline-flex items-center justify-center',
|
|
41
|
+
'h-8 w-8 rounded-md text-neutral-500 hover:text-neutral-900',
|
|
42
|
+
'dark:text-neutral-400 dark:hover:text-neutral-50',
|
|
43
|
+
'hover:bg-neutral-100 dark:hover:bg-neutral-800',
|
|
44
|
+
'focus:outline-none focus:ring-2 focus:ring-primary-500',
|
|
45
|
+
'transition-colors',
|
|
46
|
+
],
|
|
47
|
+
body: 'flex-1 overflow-y-auto',
|
|
48
|
+
actions: 'flex justify-end gap-2 pt-2',
|
|
49
|
+
},
|
|
50
|
+
variants: {
|
|
51
|
+
size: {
|
|
52
|
+
sm: { content: 'max-w-sm' },
|
|
53
|
+
md: { content: 'max-w-md' },
|
|
54
|
+
lg: { content: 'max-w-2xl' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
defaultVariants: {
|
|
58
|
+
size: 'md',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type DialogVariants = VariantProps<typeof dialogVariants>;
|
|
@@ -24,7 +24,10 @@ export const leftNavVariants = tv({
|
|
|
24
24
|
root: [
|
|
25
25
|
'flex flex-col h-full',
|
|
26
26
|
'bg-neutral-50 border-r border-neutral-200',
|
|
27
|
-
|
|
27
|
+
// Width transition (rail-mode toggle) — gated on
|
|
28
|
+
// prefers-reduced-motion (WCAG 2.3.3). The new width still
|
|
29
|
+
// applies, just without the animated tween.
|
|
30
|
+
'transition-[width] duration-200 motion-reduce:transition-none motion-reduce:duration-0',
|
|
28
31
|
],
|
|
29
32
|
brand: [
|
|
30
33
|
'flex items-center gap-2 px-3 h-14 shrink-0',
|
|
@@ -39,6 +42,14 @@ export const leftNavVariants = tv({
|
|
|
39
42
|
'transition-colors w-full',
|
|
40
43
|
'aria-disabled:opacity-50 aria-disabled:cursor-not-allowed',
|
|
41
44
|
'aria-disabled:hover:bg-transparent',
|
|
45
|
+
// Defensive `no-underline` — Tailwind's preflight removes the
|
|
46
|
+
// default browser anchor underline globally, but environments
|
|
47
|
+
// that DISABLE preflight (e.g. our docs-lab, where the tw
|
|
48
|
+
// section coexists with MUI's chrome) get raw browser defaults
|
|
49
|
+
// back. Without this, `<a>` items in the nav render underlined
|
|
50
|
+
// in those contexts. Explicit `no-underline` + `hover:no-underline`
|
|
51
|
+
// keeps the appearance consistent regardless of preflight state.
|
|
52
|
+
'no-underline hover:no-underline',
|
|
42
53
|
],
|
|
43
54
|
itemActive: 'bg-primary-100 text-primary-900 font-medium',
|
|
44
55
|
itemIcon: 'shrink-0 w-5 h-5 flex items-center justify-center',
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { describe, it, expect, afterEach, beforeAll } from 'vitest';
|
|
4
|
+
import { render, screen, cleanup } from '@testing-library/react';
|
|
5
|
+
import { Popover } from './Popover.js';
|
|
6
|
+
|
|
7
|
+
void React;
|
|
8
|
+
afterEach(() => cleanup());
|
|
9
|
+
|
|
10
|
+
// jsdom doesn't implement ResizeObserver — Radix Floating UI requires it.
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
13
|
+
(globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = class {
|
|
14
|
+
observe() {}
|
|
15
|
+
unobserve() {}
|
|
16
|
+
disconnect() {}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('Popover — rendering', () => {
|
|
22
|
+
it('renders the trigger always', () => {
|
|
23
|
+
render(
|
|
24
|
+
<Popover content={<p>Panel</p>}>
|
|
25
|
+
<button>Open panel</button>
|
|
26
|
+
</Popover>
|
|
27
|
+
);
|
|
28
|
+
expect(screen.queryByRole('button', { name: 'Open panel' })).not.toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renders content when controlled open=true', () => {
|
|
32
|
+
render(
|
|
33
|
+
<Popover content={<p>Panel content</p>} open onOpenChange={() => {}}>
|
|
34
|
+
<button>Open panel</button>
|
|
35
|
+
</Popover>
|
|
36
|
+
);
|
|
37
|
+
expect(screen.queryByText('Panel content')).not.toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('does not render content when open=false', () => {
|
|
41
|
+
render(
|
|
42
|
+
<Popover content={<p>Panel content</p>} open={false} onOpenChange={() => {}}>
|
|
43
|
+
<button>Open panel</button>
|
|
44
|
+
</Popover>
|
|
45
|
+
);
|
|
46
|
+
expect(screen.queryByText('Panel content')).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('Popover — placement', () => {
|
|
51
|
+
it.each(['top', 'right', 'bottom', 'left'] as const)(
|
|
52
|
+
'renders side=%s without crashing',
|
|
53
|
+
(side) => {
|
|
54
|
+
render(
|
|
55
|
+
<Popover content={<p>Panel</p>} open side={side} onOpenChange={() => {}}>
|
|
56
|
+
<button>T</button>
|
|
57
|
+
</Popover>
|
|
58
|
+
);
|
|
59
|
+
expect(screen.queryByText('Panel')).not.toBeNull();
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
it('applies width style', () => {
|
|
64
|
+
render(
|
|
65
|
+
<Popover content={<p>Panel</p>} open width="300px" onOpenChange={() => {}}>
|
|
66
|
+
<button>T</button>
|
|
67
|
+
</Popover>
|
|
68
|
+
);
|
|
69
|
+
const content = screen.getByText('Panel').closest('[role="dialog"]') as HTMLElement | null;
|
|
70
|
+
expect(content?.style.width).toBe('300px');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as RadixPopover from '@radix-ui/react-popover';
|
|
2
|
+
import { cn } from '../../utils/cn.js';
|
|
3
|
+
import { popoverVariants } from './popover.variants.js';
|
|
4
|
+
import type { PopoverProps } from './popover.types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Dashforge TW `<Popover>` — clickable floating content panel.
|
|
8
|
+
*
|
|
9
|
+
* Built on `@radix-ui/react-popover`:
|
|
10
|
+
* - Focus trap inside the popover (Tab cycles within).
|
|
11
|
+
* - Outside-click + Escape dismiss.
|
|
12
|
+
* - APG dialog-like semantics (`role="dialog"` on content).
|
|
13
|
+
* - Portal-rendered.
|
|
14
|
+
*
|
|
15
|
+
* Use `<Popover>` for menus / pickers / settings panels with
|
|
16
|
+
* interactive children. Use `<Tooltip>` for read-only hints.
|
|
17
|
+
*/
|
|
18
|
+
export function Popover(props: PopoverProps) {
|
|
19
|
+
const {
|
|
20
|
+
children,
|
|
21
|
+
content,
|
|
22
|
+
side = 'bottom',
|
|
23
|
+
align = 'center',
|
|
24
|
+
showArrow = false,
|
|
25
|
+
open,
|
|
26
|
+
onOpenChange,
|
|
27
|
+
sideOffset = 8,
|
|
28
|
+
width,
|
|
29
|
+
slotProps,
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
const v = popoverVariants();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<RadixPopover.Root open={open} onOpenChange={onOpenChange}>
|
|
36
|
+
<RadixPopover.Trigger asChild>{children}</RadixPopover.Trigger>
|
|
37
|
+
<RadixPopover.Portal>
|
|
38
|
+
<RadixPopover.Content
|
|
39
|
+
side={side}
|
|
40
|
+
align={align}
|
|
41
|
+
sideOffset={sideOffset}
|
|
42
|
+
style={width != null ? { width } : undefined}
|
|
43
|
+
className={cn(v.content(), slotProps?.content?.className)}
|
|
44
|
+
>
|
|
45
|
+
{content}
|
|
46
|
+
{showArrow && (
|
|
47
|
+
<RadixPopover.Arrow
|
|
48
|
+
className={cn(v.arrow(), slotProps?.arrow?.className)}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
</RadixPopover.Content>
|
|
52
|
+
</RadixPopover.Portal>
|
|
53
|
+
</RadixPopover.Root>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface PopoverSlotProps {
|
|
4
|
+
content?: { className?: string };
|
|
5
|
+
arrow?: { className?: string };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Props for `<Popover>`.
|
|
10
|
+
*
|
|
11
|
+
* Built on `@radix-ui/react-popover`. Use for richer floating UI
|
|
12
|
+
* than a tooltip — e.g. action menus, color pickers, settings
|
|
13
|
+
* panels.
|
|
14
|
+
*
|
|
15
|
+
* Differences vs `<Tooltip>`:
|
|
16
|
+
* - Popover is **clickable** and captures focus inside (focus trap).
|
|
17
|
+
* - Popover supports arbitrary interactive content (forms, buttons).
|
|
18
|
+
* - Popover dismisses on outside-click / Escape (Radix-managed).
|
|
19
|
+
* - No `role="tooltip"` — popovers are conceptually mini-dialogs.
|
|
20
|
+
*/
|
|
21
|
+
export interface PopoverProps {
|
|
22
|
+
/** The trigger element (wrapped in Radix's `asChild` slot). */
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
/** Popover body content. */
|
|
25
|
+
content: ReactNode;
|
|
26
|
+
/** Side of the trigger to render on. @default 'bottom' */
|
|
27
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
28
|
+
/** Alignment along the perpendicular axis. @default 'center' */
|
|
29
|
+
align?: 'start' | 'center' | 'end';
|
|
30
|
+
/** Show an arrow indicator. @default false */
|
|
31
|
+
showArrow?: boolean;
|
|
32
|
+
/** Controlled open state. */
|
|
33
|
+
open?: boolean;
|
|
34
|
+
/** Called when open state changes. */
|
|
35
|
+
onOpenChange?: (open: boolean) => void;
|
|
36
|
+
/** Side offset in pixels. @default 8 */
|
|
37
|
+
sideOffset?: number;
|
|
38
|
+
/** Width of the popover content. CSS value. */
|
|
39
|
+
width?: string;
|
|
40
|
+
/** Per-slot overrides. */
|
|
41
|
+
slotProps?: PopoverSlotProps;
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
export const popoverVariants = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
content: [
|
|
6
|
+
'z-50 rounded-md border border-neutral-200 dark:border-neutral-800',
|
|
7
|
+
'bg-white dark:bg-neutral-900 p-4 shadow-lg',
|
|
8
|
+
'text-sm text-neutral-900 dark:text-neutral-50',
|
|
9
|
+
'focus:outline-none',
|
|
10
|
+
'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
|
11
|
+
'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
|
|
12
|
+
'motion-reduce:transition-none motion-reduce:duration-0',
|
|
13
|
+
],
|
|
14
|
+
arrow: 'fill-white dark:fill-neutral-900',
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export type PopoverVariants = VariantProps<typeof popoverVariants>;
|
|
@@ -23,8 +23,10 @@ export const snackbarVariants = tv({
|
|
|
23
23
|
'rounded-lg border shadow-lg',
|
|
24
24
|
'text-sm bg-neutral-50 text-neutral-900',
|
|
25
25
|
// Subtle enter transition — opacity + translate, kept short so a
|
|
26
|
-
// burst of snackbars feels snappy.
|
|
27
|
-
|
|
26
|
+
// burst of snackbars feels snappy. Gated on motion-reduce
|
|
27
|
+
// (WCAG 2.3.3) — users who request reduced motion see snackbars
|
|
28
|
+
// pop in instantly without the slide animation.
|
|
29
|
+
'transition-all duration-200 motion-reduce:transition-none motion-reduce:duration-0',
|
|
28
30
|
'data-[state=entered]:opacity-100 data-[state=exited]:opacity-0',
|
|
29
31
|
],
|
|
30
32
|
icon: 'shrink-0 mt-0.5 w-5 h-5 inline-flex items-center justify-center',
|
|
@@ -25,7 +25,12 @@ export const switchVariants = tv({
|
|
|
25
25
|
],
|
|
26
26
|
thumb: [
|
|
27
27
|
'pointer-events-none inline-block rounded-full bg-white shadow ring-0',
|
|
28
|
-
|
|
28
|
+
// Slide animation gated on `prefers-reduced-motion: no-preference`
|
|
29
|
+
// (WCAG 2.3.3). The thumb still moves between positions instantly
|
|
30
|
+
// for users who request reduced motion — the data-state change
|
|
31
|
+
// applies the translate-x rule unconditionally, only the smooth
|
|
32
|
+
// transition between the two is suppressed.
|
|
33
|
+
'transition-transform motion-reduce:transition-none',
|
|
29
34
|
'data-[state=unchecked]:translate-x-0',
|
|
30
35
|
],
|
|
31
36
|
label: 'select-none cursor-pointer text-neutral-900',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
4
|
+
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
|
|
5
|
+
import { Tabs } from './Tabs.js';
|
|
6
|
+
|
|
7
|
+
void React;
|
|
8
|
+
afterEach(() => cleanup());
|
|
9
|
+
|
|
10
|
+
const items = [
|
|
11
|
+
{ value: 'overview', label: 'Overview', content: <p>Overview body</p> },
|
|
12
|
+
{ value: 'details', label: 'Details', content: <p>Details body</p> },
|
|
13
|
+
{ value: 'history', label: 'History', content: <p>History body</p> },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
describe('Tabs — rendering', () => {
|
|
17
|
+
it('renders all triggers and the default-active content', () => {
|
|
18
|
+
render(<Tabs items={items} />);
|
|
19
|
+
expect(screen.queryByRole('tab', { name: 'Overview' })).not.toBeNull();
|
|
20
|
+
expect(screen.queryByRole('tab', { name: 'Details' })).not.toBeNull();
|
|
21
|
+
expect(screen.queryByRole('tab', { name: 'History' })).not.toBeNull();
|
|
22
|
+
// Only the active panel renders content (others get data-state="inactive").
|
|
23
|
+
expect(screen.queryByText('Overview body')).not.toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('honors `defaultValue`', () => {
|
|
27
|
+
render(<Tabs items={items} defaultValue="history" />);
|
|
28
|
+
expect(screen.queryByText('History body')).not.toBeNull();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('switches active panel via controlled `value` rerender', () => {
|
|
32
|
+
const { rerender } = render(
|
|
33
|
+
<Tabs items={items} value="overview" onValueChange={() => {}} />
|
|
34
|
+
);
|
|
35
|
+
expect(screen.queryByText('Overview body')).not.toBeNull();
|
|
36
|
+
rerender(<Tabs items={items} value="details" onValueChange={() => {}} />);
|
|
37
|
+
expect(screen.queryByText('Details body')).not.toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('marks the active tab via aria-selected', () => {
|
|
41
|
+
render(<Tabs items={items} defaultValue="details" />);
|
|
42
|
+
const detailsTab = screen.getByRole('tab', { name: 'Details' });
|
|
43
|
+
expect(detailsTab.getAttribute('aria-selected')).toBe('true');
|
|
44
|
+
const overviewTab = screen.getByRole('tab', { name: 'Overview' });
|
|
45
|
+
expect(overviewTab.getAttribute('aria-selected')).toBe('false');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
void fireEvent; // imported for parity but not needed after the controlled-mode simplification
|
|
50
|
+
|
|
51
|
+
describe('Tabs — variants', () => {
|
|
52
|
+
it.each(['underline', 'pill'] as const)('renders variant=%s', (variant) => {
|
|
53
|
+
render(<Tabs items={items} variant={variant} />);
|
|
54
|
+
expect(screen.queryByRole('tablist')).not.toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it.each(['horizontal', 'vertical'] as const)('renders orientation=%s', (o) => {
|
|
58
|
+
render(<Tabs items={items} orientation={o} />);
|
|
59
|
+
const list = screen.getByRole('tablist');
|
|
60
|
+
expect(list.getAttribute('aria-orientation')).toBe(o);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('Tabs — disabled items', () => {
|
|
65
|
+
it('marks disabled triggers as disabled', () => {
|
|
66
|
+
const disabledItems = [
|
|
67
|
+
...items.slice(0, 2),
|
|
68
|
+
{ ...items[2]!, disabled: true },
|
|
69
|
+
];
|
|
70
|
+
render(<Tabs items={disabledItems} />);
|
|
71
|
+
const trigger = screen.getByRole('tab', { name: 'History' }) as HTMLButtonElement;
|
|
72
|
+
expect(trigger.disabled).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as RadixTabs from '@radix-ui/react-tabs';
|
|
2
|
+
import { cn } from '../../utils/cn.js';
|
|
3
|
+
import { tabsVariants } from './tabs.variants.js';
|
|
4
|
+
import type { TabsProps } from './tabs.types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Dashforge TW `<Tabs>` — declarative tab navigation.
|
|
8
|
+
*
|
|
9
|
+
* Built on `@radix-ui/react-tabs`:
|
|
10
|
+
* - APG tabs pattern (arrow-key navigation, automatic activation,
|
|
11
|
+
* `role="tablist"` + `role="tab"` + `role="tabpanel"`).
|
|
12
|
+
* - Controlled / uncontrolled (`value` / `defaultValue`).
|
|
13
|
+
*
|
|
14
|
+
* Two variant axes:
|
|
15
|
+
* - `variant` — `underline` (default) | `pill`
|
|
16
|
+
* - `orientation` — `horizontal` (default) | `vertical`
|
|
17
|
+
*/
|
|
18
|
+
export function Tabs(props: TabsProps) {
|
|
19
|
+
const {
|
|
20
|
+
items,
|
|
21
|
+
value,
|
|
22
|
+
defaultValue,
|
|
23
|
+
onValueChange,
|
|
24
|
+
variant = 'underline',
|
|
25
|
+
orientation = 'horizontal',
|
|
26
|
+
sx,
|
|
27
|
+
slotProps,
|
|
28
|
+
} = props;
|
|
29
|
+
|
|
30
|
+
const v = tabsVariants({ variant, orientation });
|
|
31
|
+
const resolvedDefault = defaultValue ?? items[0]?.value;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<RadixTabs.Root
|
|
35
|
+
value={value}
|
|
36
|
+
defaultValue={resolvedDefault}
|
|
37
|
+
onValueChange={onValueChange}
|
|
38
|
+
orientation={orientation}
|
|
39
|
+
className={cn(v.root(), sx, slotProps?.root?.className)}
|
|
40
|
+
>
|
|
41
|
+
<RadixTabs.List
|
|
42
|
+
className={cn(v.list(), slotProps?.list?.className)}
|
|
43
|
+
>
|
|
44
|
+
{items.map((item) => (
|
|
45
|
+
<RadixTabs.Trigger
|
|
46
|
+
key={item.value}
|
|
47
|
+
value={item.value}
|
|
48
|
+
disabled={item.disabled}
|
|
49
|
+
className={cn(v.trigger(), slotProps?.trigger?.className)}
|
|
50
|
+
>
|
|
51
|
+
{item.label}
|
|
52
|
+
</RadixTabs.Trigger>
|
|
53
|
+
))}
|
|
54
|
+
</RadixTabs.List>
|
|
55
|
+
{items.map((item) => (
|
|
56
|
+
<RadixTabs.Content
|
|
57
|
+
key={item.value}
|
|
58
|
+
value={item.value}
|
|
59
|
+
className={cn(v.content(), slotProps?.content?.className)}
|
|
60
|
+
>
|
|
61
|
+
{item.content}
|
|
62
|
+
</RadixTabs.Content>
|
|
63
|
+
))}
|
|
64
|
+
</RadixTabs.Root>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { TabsVariants } from './tabs.variants.js';
|
|
3
|
+
|
|
4
|
+
export interface TabsSlotProps {
|
|
5
|
+
root?: { className?: string };
|
|
6
|
+
list?: { className?: string };
|
|
7
|
+
trigger?: { className?: string };
|
|
8
|
+
content?: { className?: string };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Single tab item — paired `{ value, label, content }`. The `value`
|
|
13
|
+
* is the canonical id (selected via the `value` / `defaultValue`
|
|
14
|
+
* props on the root); the `label` is the trigger button text, and
|
|
15
|
+
* `content` is what renders in the panel when this tab is active.
|
|
16
|
+
*/
|
|
17
|
+
export interface TabItem {
|
|
18
|
+
value: string;
|
|
19
|
+
label: ReactNode;
|
|
20
|
+
/** Tab panel content. */
|
|
21
|
+
content: ReactNode;
|
|
22
|
+
/** Per-tab disabled flag. */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Props for `<Tabs>`.
|
|
28
|
+
*
|
|
29
|
+
* Built on `@radix-ui/react-tabs`. Two variant axes:
|
|
30
|
+
* - `variant` — `underline` (default) | `pill`
|
|
31
|
+
* - `orientation` — `horizontal` (default) | `vertical`
|
|
32
|
+
*
|
|
33
|
+
* Supports controlled (`value` + `onValueChange`) and uncontrolled
|
|
34
|
+
* (`defaultValue`) modes — the `value` prop wins when both are set.
|
|
35
|
+
*/
|
|
36
|
+
export interface TabsProps extends TabsVariants {
|
|
37
|
+
/** Tab items array (declarative — alternative to passing children). */
|
|
38
|
+
items: TabItem[];
|
|
39
|
+
/** Controlled active value. */
|
|
40
|
+
value?: string;
|
|
41
|
+
/** Default active value (uncontrolled). Defaults to first item's value. */
|
|
42
|
+
defaultValue?: string;
|
|
43
|
+
/** Fires when the active tab changes. */
|
|
44
|
+
onValueChange?: (value: string) => void;
|
|
45
|
+
/** Root className shortcut. */
|
|
46
|
+
sx?: string;
|
|
47
|
+
/** Per-slot overrides. */
|
|
48
|
+
slotProps?: TabsSlotProps;
|
|
49
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
export const tabsVariants = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
root: 'flex',
|
|
6
|
+
list: 'inline-flex items-center gap-1',
|
|
7
|
+
trigger: [
|
|
8
|
+
'inline-flex items-center justify-center whitespace-nowrap',
|
|
9
|
+
'text-sm font-medium transition-colors',
|
|
10
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
11
|
+
'disabled:opacity-50 disabled:pointer-events-none',
|
|
12
|
+
'motion-reduce:transition-none',
|
|
13
|
+
],
|
|
14
|
+
content: [
|
|
15
|
+
'mt-3 focus:outline-none',
|
|
16
|
+
'data-[state=inactive]:hidden',
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
variants: {
|
|
20
|
+
variant: {
|
|
21
|
+
underline: {
|
|
22
|
+
list: 'border-b border-neutral-200 dark:border-neutral-800',
|
|
23
|
+
trigger: [
|
|
24
|
+
'px-3 py-2 border-b-2 border-transparent text-neutral-600 dark:text-neutral-400',
|
|
25
|
+
'hover:text-neutral-900 dark:hover:text-neutral-50',
|
|
26
|
+
'data-[state=active]:border-primary-500 data-[state=active]:text-primary-700',
|
|
27
|
+
'dark:data-[state=active]:text-primary-400',
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
pill: {
|
|
31
|
+
list: 'rounded-lg bg-neutral-100 dark:bg-neutral-800 p-1',
|
|
32
|
+
trigger: [
|
|
33
|
+
'px-3 py-1.5 rounded-md text-neutral-600 dark:text-neutral-400',
|
|
34
|
+
'hover:text-neutral-900 dark:hover:text-neutral-50',
|
|
35
|
+
'data-[state=active]:bg-white dark:data-[state=active]:bg-neutral-900',
|
|
36
|
+
'data-[state=active]:text-neutral-900 dark:data-[state=active]:text-neutral-50',
|
|
37
|
+
'data-[state=active]:shadow-sm',
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
orientation: {
|
|
42
|
+
horizontal: {
|
|
43
|
+
root: 'flex-col',
|
|
44
|
+
list: 'flex-row',
|
|
45
|
+
},
|
|
46
|
+
vertical: {
|
|
47
|
+
root: 'flex-row gap-4',
|
|
48
|
+
list: 'flex-col items-stretch',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
defaultVariants: {
|
|
53
|
+
variant: 'underline',
|
|
54
|
+
orientation: 'horizontal',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export type TabsVariants = VariantProps<typeof tabsVariants>;
|
|
@@ -178,6 +178,22 @@ export function TextField(props: TextFieldProps) {
|
|
|
178
178
|
)}
|
|
179
179
|
|
|
180
180
|
<div className={cn(v.inputWrapper(), slotProps?.inputWrapper?.className)}>
|
|
181
|
+
{/*
|
|
182
|
+
* Prefix slot (Sprint 2 P4.1) — inline adornment rendered
|
|
183
|
+
* BEFORE the input. Mounts only when `slotProps.prefix.children`
|
|
184
|
+
* is provided so empty configs don't add layout cost. Common
|
|
185
|
+
* use: currency symbols (`$`, `€`), units (`@`, `#`), status
|
|
186
|
+
* icons. The slot wrapper carries `pointer-events-none` to
|
|
187
|
+
* avoid stealing focus from the input on click.
|
|
188
|
+
*/}
|
|
189
|
+
{slotProps?.prefix?.children !== undefined && (
|
|
190
|
+
<span
|
|
191
|
+
aria-hidden="true"
|
|
192
|
+
className={cn(v.prefix(), slotProps.prefix.className)}
|
|
193
|
+
>
|
|
194
|
+
{slotProps.prefix.children}
|
|
195
|
+
</span>
|
|
196
|
+
)}
|
|
181
197
|
<input
|
|
182
198
|
{...rest}
|
|
183
199
|
id={inputId}
|
|
@@ -196,6 +212,19 @@ export function TextField(props: TextFieldProps) {
|
|
|
196
212
|
ref={inputRef}
|
|
197
213
|
className={cn(v.input(), slotProps?.input?.className)}
|
|
198
214
|
/>
|
|
215
|
+
{/*
|
|
216
|
+
* Suffix slot (Sprint 2 P4.1) — same pattern as prefix,
|
|
217
|
+
* rendered AFTER the input. Typical use: unit labels (`USD`,
|
|
218
|
+
* `kg`, `%`), trailing icons, length counters.
|
|
219
|
+
*/}
|
|
220
|
+
{slotProps?.suffix?.children !== undefined && (
|
|
221
|
+
<span
|
|
222
|
+
aria-hidden="true"
|
|
223
|
+
className={cn(v.suffix(), slotProps.suffix.className)}
|
|
224
|
+
>
|
|
225
|
+
{slotProps.suffix.children}
|
|
226
|
+
</span>
|
|
227
|
+
)}
|
|
199
228
|
</div>
|
|
200
229
|
|
|
201
230
|
{resolvedHelperText && (
|