@dashforge/tw 0.3.0-beta → 0.5.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 +246 -0
- package/PARITY.md +483 -0
- package/PERFORMANCE.md +169 -0
- package/dist/index.esm.js +1055 -2
- 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/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/Pagination/Pagination.d.ts +32 -0
- package/dist/src/components/Pagination/Pagination.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.helpers.d.ts +23 -0
- package/dist/src/components/Pagination/pagination.helpers.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.types.d.ts +120 -0
- package/dist/src/components/Pagination/pagination.types.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.variants.d.ts +150 -0
- package/dist/src/components/Pagination/pagination.variants.d.ts.map +1 -0
- 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/Skeleton/Skeleton.d.ts +23 -0
- package/dist/src/components/Skeleton/Skeleton.d.ts.map +1 -0
- package/dist/src/components/Skeleton/skeleton.types.d.ts +56 -0
- package/dist/src/components/Skeleton/skeleton.types.d.ts.map +1 -0
- package/dist/src/components/Skeleton/skeleton.variants.d.ts +110 -0
- package/dist/src/components/Skeleton/skeleton.variants.d.ts.map +1 -0
- 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/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 +22 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +8 -3
- 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/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/Pagination/Pagination.test.tsx +314 -0
- package/src/components/Pagination/Pagination.tsx +275 -0
- package/src/components/Pagination/pagination.helpers.ts +102 -0
- package/src/components/Pagination/pagination.types.ts +117 -0
- package/src/components/Pagination/pagination.variants.ts +111 -0
- 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/Skeleton/Skeleton.test.tsx +127 -0
- package/src/components/Skeleton/Skeleton.tsx +49 -0
- package/src/components/Skeleton/skeleton.types.ts +59 -0
- package/src/components/Skeleton/skeleton.variants.ts +86 -0
- 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/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 +57 -1
|
@@ -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>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
4
|
+
import { render, cleanup } from '@testing-library/react';
|
|
5
|
+
import { Skeleton } from './Skeleton.js';
|
|
6
|
+
|
|
7
|
+
void React;
|
|
8
|
+
afterEach(() => cleanup());
|
|
9
|
+
|
|
10
|
+
describe('Skeleton — rendering', () => {
|
|
11
|
+
it('renders a span with aria-hidden', () => {
|
|
12
|
+
const { container } = render(<Skeleton />);
|
|
13
|
+
const el = container.querySelector('span');
|
|
14
|
+
expect(el).not.toBeNull();
|
|
15
|
+
expect(el?.getAttribute('aria-hidden')).toBe('true');
|
|
16
|
+
expect(el?.getAttribute('role')).toBe('presentation');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('defaults to variant=text + animation=pulse', () => {
|
|
20
|
+
const { container } = render(<Skeleton />);
|
|
21
|
+
const cls = container.querySelector('span')!.className;
|
|
22
|
+
expect(cls).toContain('animate-pulse');
|
|
23
|
+
// text variant has a height of 1em
|
|
24
|
+
expect(cls).toContain('h-[1em]');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('Skeleton — variants', () => {
|
|
29
|
+
it.each(['text', 'rectangle', 'circle'] as const)(
|
|
30
|
+
'renders variant=%s without crashing',
|
|
31
|
+
(variant) => {
|
|
32
|
+
const { container } = render(<Skeleton variant={variant} />);
|
|
33
|
+
expect(container.querySelector('span')).not.toBeNull();
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
it('rectangle has rounded-md class', () => {
|
|
38
|
+
const { container } = render(<Skeleton variant="rectangle" />);
|
|
39
|
+
expect(container.querySelector('span')!.className).toContain('rounded-md');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('circle has rounded-full class', () => {
|
|
43
|
+
const { container } = render(<Skeleton variant="circle" />);
|
|
44
|
+
expect(container.querySelector('span')!.className).toContain('rounded-full');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('Skeleton — animations', () => {
|
|
49
|
+
it('animation=pulse adds animate-pulse', () => {
|
|
50
|
+
const { container } = render(<Skeleton animation="pulse" />);
|
|
51
|
+
expect(container.querySelector('span')!.className).toContain('animate-pulse');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('animation=none does NOT add animate-pulse', () => {
|
|
55
|
+
const { container } = render(<Skeleton animation="none" />);
|
|
56
|
+
expect(container.querySelector('span')!.className).not.toContain('animate-pulse');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('animation=wave adds overflow-hidden + after gradient', () => {
|
|
60
|
+
const { container } = render(<Skeleton animation="wave" />);
|
|
61
|
+
const cls = container.querySelector('span')!.className;
|
|
62
|
+
expect(cls).toContain('overflow-hidden');
|
|
63
|
+
expect(cls).toContain('relative');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('always carries motion-reduce safety regardless of animation', () => {
|
|
67
|
+
const { container } = render(<Skeleton animation="pulse" />);
|
|
68
|
+
expect(container.querySelector('span')!.className).toContain('motion-reduce:animate-none');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('Skeleton — dimensions', () => {
|
|
73
|
+
it('passes width as inline style', () => {
|
|
74
|
+
const { container } = render(<Skeleton width="200px" />);
|
|
75
|
+
expect((container.querySelector('span') as HTMLElement).style.width).toBe('200px');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('passes height as inline style', () => {
|
|
79
|
+
const { container } = render(<Skeleton variant="rectangle" height="120px" />);
|
|
80
|
+
expect((container.querySelector('span') as HTMLElement).style.height).toBe('120px');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('for circle, height defaults to width', () => {
|
|
84
|
+
const { container } = render(<Skeleton variant="circle" width="48px" />);
|
|
85
|
+
const el = container.querySelector('span') as HTMLElement;
|
|
86
|
+
expect(el.style.width).toBe('48px');
|
|
87
|
+
expect(el.style.height).toBe('48px');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('for circle, explicit height wins over width-default', () => {
|
|
91
|
+
const { container } = render(<Skeleton variant="circle" width="48px" height="64px" />);
|
|
92
|
+
const el = container.querySelector('span') as HTMLElement;
|
|
93
|
+
expect(el.style.width).toBe('48px');
|
|
94
|
+
expect(el.style.height).toBe('64px');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('Skeleton — sx + slotProps', () => {
|
|
99
|
+
it('appends sx to root className', () => {
|
|
100
|
+
const { container } = render(<Skeleton sx="my-custom-sx" />);
|
|
101
|
+
expect(container.querySelector('span')!.className).toContain('my-custom-sx');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('applies slotProps.root.className', () => {
|
|
105
|
+
const { container } = render(
|
|
106
|
+
<Skeleton slotProps={{ root: { className: 'slot-class' } }} />,
|
|
107
|
+
);
|
|
108
|
+
expect(container.querySelector('span')!.className).toContain('slot-class');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('sx wins over variant default on conflict via tailwind-merge', () => {
|
|
112
|
+
// variant=text emits `bg-neutral-200`; sx forces `bg-red-500`.
|
|
113
|
+
const { container } = render(<Skeleton sx="bg-red-500" />);
|
|
114
|
+
const cls = container.querySelector('span')!.className;
|
|
115
|
+
expect(cls).toContain('bg-red-500');
|
|
116
|
+
expect(cls).not.toContain('bg-neutral-200');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('Skeleton — accessibility', () => {
|
|
121
|
+
it('does not appear in role-based queries (aria-hidden + role=presentation)', () => {
|
|
122
|
+
const { container } = render(<Skeleton />);
|
|
123
|
+
const el = container.querySelector('span')!;
|
|
124
|
+
expect(el.getAttribute('aria-hidden')).toBe('true');
|
|
125
|
+
expect(el.getAttribute('role')).toBe('presentation');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn.js';
|
|
3
|
+
import { skeletonVariants } from './skeleton.variants.js';
|
|
4
|
+
import type { SkeletonProps } from './skeleton.types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Dashforge TW `<Skeleton>` — loading placeholder primitive.
|
|
8
|
+
*
|
|
9
|
+
* Renders as a non-interactive `<span aria-hidden="true">` so screen
|
|
10
|
+
* readers skip it. The surrounding component is responsible for
|
|
11
|
+
* announcing loading state via `aria-busy` or `aria-live` if needed.
|
|
12
|
+
*
|
|
13
|
+
* Variants:
|
|
14
|
+
* - `variant` — `text` (default, line shape) / `rectangle` / `circle`
|
|
15
|
+
* - `animation` — `pulse` (default) / `wave` / `none`
|
|
16
|
+
*
|
|
17
|
+
* Both animations are gated by `prefers-reduced-motion` (WCAG 2.3.3).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <Skeleton variant="text" width="200px" />
|
|
22
|
+
* <Skeleton variant="rectangle" width="100%" height="120px" />
|
|
23
|
+
* <Skeleton variant="circle" width="40px" />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function Skeleton(props: SkeletonProps) {
|
|
27
|
+
const { variant = 'text', animation = 'pulse', width, height, sx, slotProps } = props;
|
|
28
|
+
const v = skeletonVariants({ variant, animation });
|
|
29
|
+
|
|
30
|
+
// Width / height come through as inline style — Tailwind doesn't
|
|
31
|
+
// know about arbitrary user-supplied lengths. We default `circle`'s
|
|
32
|
+
// height to `width` so consumers don't have to repeat themselves.
|
|
33
|
+
const style: CSSProperties = {};
|
|
34
|
+
if (width != null) style.width = width;
|
|
35
|
+
if (height != null) {
|
|
36
|
+
style.height = height;
|
|
37
|
+
} else if (variant === 'circle' && width != null) {
|
|
38
|
+
style.height = width;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<span
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
role="presentation"
|
|
45
|
+
className={cn(v.root(), sx, slotProps?.root?.className)}
|
|
46
|
+
style={style}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SkeletonVariants } from './skeleton.variants.js';
|
|
2
|
+
|
|
3
|
+
export interface SkeletonSlotProps {
|
|
4
|
+
/** Root element override. */
|
|
5
|
+
root?: { className?: string };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Props for `<Skeleton>`.
|
|
10
|
+
*
|
|
11
|
+
* Visual loading placeholder shown while data / images / components
|
|
12
|
+
* are being prepared. Three shapes (`variant`), three animations
|
|
13
|
+
* (`animation`), and free-form `width` / `height` for arbitrary
|
|
14
|
+
* dimensions.
|
|
15
|
+
*
|
|
16
|
+
* Rendered as a non-interactive `<span aria-hidden="true">` so screen
|
|
17
|
+
* readers skip it entirely.
|
|
18
|
+
*
|
|
19
|
+
* Compose by nesting: e.g. avatar + two text lines for a card
|
|
20
|
+
* placeholder.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <Skeleton variant="text" width="200px" />
|
|
25
|
+
* <Skeleton variant="rectangle" width="100%" height="120px" />
|
|
26
|
+
* <Skeleton variant="circle" width="40px" />
|
|
27
|
+
*
|
|
28
|
+
* // Compose to mimic a card shape
|
|
29
|
+
* <div className="flex gap-3">
|
|
30
|
+
* <Skeleton variant="circle" width="48px" />
|
|
31
|
+
* <div className="flex flex-col gap-2 flex-1">
|
|
32
|
+
* <Skeleton variant="text" width="60%" />
|
|
33
|
+
* <Skeleton variant="text" width="40%" />
|
|
34
|
+
* </div>
|
|
35
|
+
* </div>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface SkeletonProps
|
|
39
|
+
extends Pick<SkeletonVariants, 'variant' | 'animation'> {
|
|
40
|
+
/**
|
|
41
|
+
* CSS width (e.g. `"200px"`, `"100%"`, `"60%"`).
|
|
42
|
+
*
|
|
43
|
+
* Defaults: `text` → `100%`, `rectangle` → `100%`, `circle` → `40px`.
|
|
44
|
+
*/
|
|
45
|
+
width?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* CSS height (e.g. `"1em"`, `"120px"`).
|
|
49
|
+
*
|
|
50
|
+
* Defaults: `text` → `1em`, `rectangle` → `100px`, `circle` → matches `width`.
|
|
51
|
+
*/
|
|
52
|
+
height?: string;
|
|
53
|
+
|
|
54
|
+
/** Root-level Tailwind override (wins via `tailwind-merge`). */
|
|
55
|
+
sx?: string;
|
|
56
|
+
|
|
57
|
+
/** Per-slot overrides. */
|
|
58
|
+
slotProps?: SkeletonSlotProps;
|
|
59
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<Skeleton>` variant recipe.
|
|
5
|
+
*
|
|
6
|
+
* Slots:
|
|
7
|
+
* - `root` — single element (atomic component)
|
|
8
|
+
*
|
|
9
|
+
* Variant axes:
|
|
10
|
+
* - `variant` (`text` | `rectangle` | `circle`) — shape / radius
|
|
11
|
+
* - `animation` (`pulse` | `wave` | `none`) — how the placeholder
|
|
12
|
+
* "breathes" while data loads. Always gated on
|
|
13
|
+
* `prefers-reduced-motion` (no exception — animations are
|
|
14
|
+
* purely cosmetic).
|
|
15
|
+
*
|
|
16
|
+
* Implementation notes:
|
|
17
|
+
*
|
|
18
|
+
* - `pulse` uses Tailwind's built-in `animate-pulse` (opacity
|
|
19
|
+
* 1.0 ↔ 0.5 over 2s, ease-in-out infinite).
|
|
20
|
+
* - `wave` overlays a moving gradient. Implemented with a
|
|
21
|
+
* `relative` container + an `::after` pseudo-element via a
|
|
22
|
+
* Tailwind arbitrary-value class. The gradient slides
|
|
23
|
+
* horizontally over the surface, mimicking the MUI Skeleton
|
|
24
|
+
* "wave" look.
|
|
25
|
+
* - Color uses neutral-200 (light) and neutral-800 (dark) for
|
|
26
|
+
* the base, picked up automatically by the dashforge preset's
|
|
27
|
+
* CSS-variable layer.
|
|
28
|
+
*
|
|
29
|
+
* Accessibility: the root has `aria-hidden="true"` (set on the JSX
|
|
30
|
+
* side, not here). Screen readers skip the skeleton entirely;
|
|
31
|
+
* the surrounding component is responsible for announcing
|
|
32
|
+
* loading state via `aria-busy` or `aria-live` if needed.
|
|
33
|
+
*/
|
|
34
|
+
export const skeletonVariants = tv({
|
|
35
|
+
slots: {
|
|
36
|
+
root: [
|
|
37
|
+
'block',
|
|
38
|
+
'bg-neutral-200 dark:bg-neutral-800',
|
|
39
|
+
'motion-reduce:animate-none',
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
variants: {
|
|
43
|
+
variant: {
|
|
44
|
+
text: {
|
|
45
|
+
root: 'rounded h-[1em] w-full',
|
|
46
|
+
},
|
|
47
|
+
rectangle: {
|
|
48
|
+
root: 'rounded-md w-full h-[100px]',
|
|
49
|
+
},
|
|
50
|
+
circle: {
|
|
51
|
+
root: 'rounded-full w-10 h-10',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
animation: {
|
|
55
|
+
pulse: {
|
|
56
|
+
root: 'animate-pulse',
|
|
57
|
+
},
|
|
58
|
+
wave: {
|
|
59
|
+
root: [
|
|
60
|
+
'relative overflow-hidden',
|
|
61
|
+
// The wave is rendered via an arbitrary-value ::after
|
|
62
|
+
// pseudo-element with a moving linear gradient. Tailwind
|
|
63
|
+
// doesn't ship a `wave` keyframe; we use the built-in
|
|
64
|
+
// `animate-pulse` as a fallback if a consumer needs to
|
|
65
|
+
// override. The gradient stop direction works in both
|
|
66
|
+
// light and dark mode (white shimmer in light, lighter
|
|
67
|
+
// overlay in dark).
|
|
68
|
+
'after:absolute after:inset-0',
|
|
69
|
+
'after:bg-gradient-to-r after:from-transparent after:via-white/40 after:to-transparent',
|
|
70
|
+
'dark:after:via-white/10',
|
|
71
|
+
'after:animate-pulse',
|
|
72
|
+
'after:motion-reduce:animate-none',
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
none: {
|
|
76
|
+
root: '',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
defaultVariants: {
|
|
81
|
+
variant: 'text',
|
|
82
|
+
animation: 'pulse',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export type SkeletonVariants = VariantProps<typeof skeletonVariants>;
|
|
@@ -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
|
+
}
|