@dashforge/tw 0.4.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 +123 -0
- package/dist/index.esm.js +564 -2
- 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/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/index.d.ts +7 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- 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/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/index.ts +18 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { PaginationVariants } from './pagination.variants.js';
|
|
2
|
+
|
|
3
|
+
export interface PaginationSlotProps {
|
|
4
|
+
root?: { className?: string };
|
|
5
|
+
summary?: { className?: string };
|
|
6
|
+
list?: { className?: string };
|
|
7
|
+
pageButton?: { className?: string };
|
|
8
|
+
activeButton?: { className?: string };
|
|
9
|
+
navButton?: { className?: string };
|
|
10
|
+
ellipsis?: { className?: string };
|
|
11
|
+
pageSizeSelector?: { className?: string };
|
|
12
|
+
jumpInput?: { className?: string };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* I18n strings for `<Pagination>`. Default = English. Override the
|
|
17
|
+
* subset you need to translate; the rest fall back to defaults.
|
|
18
|
+
*/
|
|
19
|
+
export interface PaginationLabels {
|
|
20
|
+
first?: string;
|
|
21
|
+
prev?: string;
|
|
22
|
+
next?: string;
|
|
23
|
+
last?: string;
|
|
24
|
+
page?: string;
|
|
25
|
+
of?: string;
|
|
26
|
+
showing?: string;
|
|
27
|
+
perPage?: string;
|
|
28
|
+
goToPage?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Props for `<Pagination>`.
|
|
33
|
+
*
|
|
34
|
+
* Controlled component: the consumer owns `page` + `pageSize`. The
|
|
35
|
+
* component emits `onPageChange` / `onPageSizeChange` and recomputes
|
|
36
|
+
* the visible page range from `totalCount`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* const [page, setPage] = useState(1);
|
|
41
|
+
* const [pageSize, setPageSize] = useState(20);
|
|
42
|
+
*
|
|
43
|
+
* <Pagination
|
|
44
|
+
* page={page}
|
|
45
|
+
* pageSize={pageSize}
|
|
46
|
+
* totalCount={1437}
|
|
47
|
+
* onPageChange={setPage}
|
|
48
|
+
* onPageSizeChange={setPageSize}
|
|
49
|
+
* pageSizeOptions={[10, 20, 50, 100]}
|
|
50
|
+
* />
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export interface PaginationProps extends Pick<PaginationVariants, 'variant' | 'size'> {
|
|
54
|
+
/** Current page, **1-indexed**. */
|
|
55
|
+
page: number;
|
|
56
|
+
|
|
57
|
+
/** Items per page. */
|
|
58
|
+
pageSize: number;
|
|
59
|
+
|
|
60
|
+
/** Total items in the underlying data set (NOT total pages — we compute that). */
|
|
61
|
+
totalCount: number;
|
|
62
|
+
|
|
63
|
+
/** Fired when the user picks a different page. */
|
|
64
|
+
onPageChange: (page: number) => void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Fired when the user picks a different page size. Omit (or pass
|
|
68
|
+
* undefined) to hide the page-size selector.
|
|
69
|
+
*/
|
|
70
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Options shown in the page-size selector.
|
|
74
|
+
* @default [10, 20, 50, 100]
|
|
75
|
+
*/
|
|
76
|
+
pageSizeOptions?: number[];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* How many page buttons to show on each side of the current page.
|
|
80
|
+
* @default 1
|
|
81
|
+
*/
|
|
82
|
+
siblingCount?: number;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* How many page buttons to always show at the start/end of the
|
|
86
|
+
* sequence (acts as "boundary"). @default 1
|
|
87
|
+
*/
|
|
88
|
+
boundaryCount?: number;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Show first/last buttons (`«` / `»`). @default true
|
|
92
|
+
*/
|
|
93
|
+
showFirstLast?: boolean;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Show the direct page-jump input (variant=`default` only).
|
|
97
|
+
* @default true
|
|
98
|
+
*/
|
|
99
|
+
showJumpInput?: boolean;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Disable all interactive elements (kept rendered but inert).
|
|
103
|
+
*/
|
|
104
|
+
disabled?: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* I18n strings. Defaults are English; pass the subset you need
|
|
108
|
+
* to translate.
|
|
109
|
+
*/
|
|
110
|
+
labels?: PaginationLabels;
|
|
111
|
+
|
|
112
|
+
/** Root-level Tailwind override. */
|
|
113
|
+
sx?: string;
|
|
114
|
+
|
|
115
|
+
/** Per-slot overrides. */
|
|
116
|
+
slotProps?: PaginationSlotProps;
|
|
117
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `<Pagination>` variant recipe.
|
|
5
|
+
*
|
|
6
|
+
* Slots:
|
|
7
|
+
* - `root` — outer `<nav>` container
|
|
8
|
+
* - `summary` — "Showing X-Y of Z" text
|
|
9
|
+
* - `list` — `<ul>` of page buttons
|
|
10
|
+
* - `pageButton` — individual page number button
|
|
11
|
+
* - `activeButton` — modifier applied to the current page
|
|
12
|
+
* - `navButton` — first/prev/next/last buttons
|
|
13
|
+
* - `ellipsis` — `…` rendered when range gap
|
|
14
|
+
* - `pageSizeSelector` — native `<select>` for page size
|
|
15
|
+
* - `jumpInput` — direct page jump `<input>`
|
|
16
|
+
*
|
|
17
|
+
* Variant axes:
|
|
18
|
+
* - `variant` — `default` (full kit) | `compact` (number buttons +
|
|
19
|
+
* prev/next only) | `minimal` ("X / Y pages" + prev/next only).
|
|
20
|
+
* - `size` — `sm` | `md` (default) | `lg`. Drives padding + text
|
|
21
|
+
* size on the buttons.
|
|
22
|
+
*/
|
|
23
|
+
export const paginationVariants = tv({
|
|
24
|
+
slots: {
|
|
25
|
+
root: 'flex flex-wrap items-center gap-3',
|
|
26
|
+
summary: 'text-neutral-600 dark:text-neutral-400',
|
|
27
|
+
list: 'inline-flex items-center gap-1',
|
|
28
|
+
pageButton: [
|
|
29
|
+
'inline-flex items-center justify-center rounded-md',
|
|
30
|
+
'border border-neutral-300 dark:border-neutral-700',
|
|
31
|
+
'bg-white dark:bg-neutral-900',
|
|
32
|
+
'text-neutral-700 dark:text-neutral-300',
|
|
33
|
+
'hover:bg-neutral-50 dark:hover:bg-neutral-800',
|
|
34
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
35
|
+
'transition-colors motion-reduce:transition-none',
|
|
36
|
+
'disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none',
|
|
37
|
+
],
|
|
38
|
+
activeButton: [
|
|
39
|
+
'bg-primary-500 text-white border-primary-500',
|
|
40
|
+
'hover:bg-primary-600 dark:hover:bg-primary-400',
|
|
41
|
+
],
|
|
42
|
+
navButton: [
|
|
43
|
+
'inline-flex items-center justify-center rounded-md',
|
|
44
|
+
'border border-neutral-300 dark:border-neutral-700',
|
|
45
|
+
'bg-white dark:bg-neutral-900',
|
|
46
|
+
'text-neutral-700 dark:text-neutral-300',
|
|
47
|
+
'hover:bg-neutral-50 dark:hover:bg-neutral-800',
|
|
48
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
49
|
+
'transition-colors motion-reduce:transition-none',
|
|
50
|
+
'disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none',
|
|
51
|
+
],
|
|
52
|
+
ellipsis: 'inline-flex items-center justify-center text-neutral-500 px-1',
|
|
53
|
+
pageSizeSelector: [
|
|
54
|
+
'inline-flex items-center gap-2',
|
|
55
|
+
'text-neutral-700 dark:text-neutral-300',
|
|
56
|
+
],
|
|
57
|
+
jumpInput: [
|
|
58
|
+
'rounded-md border border-neutral-300 dark:border-neutral-700',
|
|
59
|
+
'bg-white dark:bg-neutral-900',
|
|
60
|
+
'text-neutral-900 dark:text-neutral-50',
|
|
61
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
62
|
+
'transition-colors motion-reduce:transition-none',
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
variants: {
|
|
66
|
+
// Note: variant-driven visibility is enforced via conditional JSX
|
|
67
|
+
// rendering (in `Pagination.tsx`), NOT via `hidden` Tailwind class.
|
|
68
|
+
// Reason: `display: none` keeps the elements in the DOM (and in the
|
|
69
|
+
// a11y tree depending on how it's applied), which leaks into
|
|
70
|
+
// testing-library `queryByText` and feels semantically wrong for
|
|
71
|
+
// "this UI piece doesn't exist in this variant". So compact and
|
|
72
|
+
// minimal slots stay empty here.
|
|
73
|
+
variant: {
|
|
74
|
+
default: {},
|
|
75
|
+
compact: {},
|
|
76
|
+
minimal: {},
|
|
77
|
+
},
|
|
78
|
+
size: {
|
|
79
|
+
sm: {
|
|
80
|
+
summary: 'text-xs',
|
|
81
|
+
pageButton: 'h-7 min-w-7 px-2 text-xs',
|
|
82
|
+
navButton: 'h-7 min-w-7 px-2 text-xs',
|
|
83
|
+
ellipsis: 'h-7 min-w-5 text-xs',
|
|
84
|
+
pageSizeSelector: 'text-xs',
|
|
85
|
+
jumpInput: 'h-7 px-2 text-xs w-14',
|
|
86
|
+
},
|
|
87
|
+
md: {
|
|
88
|
+
summary: 'text-sm',
|
|
89
|
+
pageButton: 'h-9 min-w-9 px-3 text-sm',
|
|
90
|
+
navButton: 'h-9 min-w-9 px-3 text-sm',
|
|
91
|
+
ellipsis: 'h-9 min-w-6 text-sm',
|
|
92
|
+
pageSizeSelector: 'text-sm',
|
|
93
|
+
jumpInput: 'h-9 px-2 text-sm w-16',
|
|
94
|
+
},
|
|
95
|
+
lg: {
|
|
96
|
+
summary: 'text-base',
|
|
97
|
+
pageButton: 'h-10 min-w-10 px-4 text-base',
|
|
98
|
+
navButton: 'h-10 min-w-10 px-4 text-base',
|
|
99
|
+
ellipsis: 'h-10 min-w-7 text-base',
|
|
100
|
+
pageSizeSelector: 'text-base',
|
|
101
|
+
jumpInput: 'h-10 px-3 text-base w-20',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
defaultVariants: {
|
|
106
|
+
variant: 'default',
|
|
107
|
+
size: 'md',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export type PaginationVariants = VariantProps<typeof paginationVariants>;
|
|
@@ -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>;
|
package/src/index.ts
CHANGED
|
@@ -262,6 +262,23 @@ export type {
|
|
|
262
262
|
} from './components/Accordion/accordion.types.js';
|
|
263
263
|
export { accordionVariants } from './components/Accordion/accordion.variants.js';
|
|
264
264
|
|
|
265
|
+
// F12 utilities: loading placeholder + pagination control.
|
|
266
|
+
|
|
267
|
+
export { Skeleton } from './components/Skeleton/Skeleton.js';
|
|
268
|
+
export type {
|
|
269
|
+
SkeletonProps,
|
|
270
|
+
SkeletonSlotProps,
|
|
271
|
+
} from './components/Skeleton/skeleton.types.js';
|
|
272
|
+
export { skeletonVariants } from './components/Skeleton/skeleton.variants.js';
|
|
273
|
+
|
|
274
|
+
export { Pagination } from './components/Pagination/Pagination.js';
|
|
275
|
+
export type {
|
|
276
|
+
PaginationProps,
|
|
277
|
+
PaginationSlotProps,
|
|
278
|
+
PaginationLabels,
|
|
279
|
+
} from './components/Pagination/pagination.types.js';
|
|
280
|
+
export { paginationVariants } from './components/Pagination/pagination.variants.js';
|
|
281
|
+
|
|
265
282
|
// ───── Hooks ─────
|
|
266
283
|
export { useAccessState } from './hooks/useAccessState.js';
|
|
267
284
|
|
|
@@ -276,4 +293,4 @@ export type { VariantProps } from 'tailwind-variants';
|
|
|
276
293
|
/**
|
|
277
294
|
* Package version (synced with `package.json` at publish time).
|
|
278
295
|
*/
|
|
279
|
-
export const VERSION = '0.
|
|
296
|
+
export const VERSION = '0.5.0-beta';
|