@dashforge/tw 0.4.0-beta → 0.6.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +391 -0
  2. package/dist/index.esm.js +2113 -2
  3. package/dist/src/components/Pagination/Pagination.d.ts +32 -0
  4. package/dist/src/components/Pagination/Pagination.d.ts.map +1 -0
  5. package/dist/src/components/Pagination/pagination.helpers.d.ts +23 -0
  6. package/dist/src/components/Pagination/pagination.helpers.d.ts.map +1 -0
  7. package/dist/src/components/Pagination/pagination.types.d.ts +120 -0
  8. package/dist/src/components/Pagination/pagination.types.d.ts.map +1 -0
  9. package/dist/src/components/Pagination/pagination.variants.d.ts +150 -0
  10. package/dist/src/components/Pagination/pagination.variants.d.ts.map +1 -0
  11. package/dist/src/components/Skeleton/Skeleton.d.ts +23 -0
  12. package/dist/src/components/Skeleton/Skeleton.d.ts.map +1 -0
  13. package/dist/src/components/Skeleton/skeleton.types.d.ts +56 -0
  14. package/dist/src/components/Skeleton/skeleton.types.d.ts.map +1 -0
  15. package/dist/src/components/Skeleton/skeleton.variants.d.ts +110 -0
  16. package/dist/src/components/Skeleton/skeleton.variants.d.ts.map +1 -0
  17. package/dist/src/components/Table/Table.d.ts +24 -0
  18. package/dist/src/components/Table/Table.d.ts.map +1 -0
  19. package/dist/src/components/Table/_internal/getNestedValue.d.ts +20 -0
  20. package/dist/src/components/Table/_internal/getNestedValue.d.ts.map +1 -0
  21. package/dist/src/components/Table/_internal/useColumnAutoDetect.d.ts +45 -0
  22. package/dist/src/components/Table/_internal/useColumnAutoDetect.d.ts.map +1 -0
  23. package/dist/src/components/Table/_internal/useControllableState.d.ts +23 -0
  24. package/dist/src/components/Table/_internal/useControllableState.d.ts.map +1 -0
  25. package/dist/src/components/Table/_internal/useDebouncedValue.d.ts +10 -0
  26. package/dist/src/components/Table/_internal/useDebouncedValue.d.ts.map +1 -0
  27. package/dist/src/components/Table/_internal/useTableFilter.d.ts +13 -0
  28. package/dist/src/components/Table/_internal/useTableFilter.d.ts.map +1 -0
  29. package/dist/src/components/Table/_internal/useTableSearch.d.ts +23 -0
  30. package/dist/src/components/Table/_internal/useTableSearch.d.ts.map +1 -0
  31. package/dist/src/components/Table/_internal/useTableSelection.d.ts +25 -0
  32. package/dist/src/components/Table/_internal/useTableSelection.d.ts.map +1 -0
  33. package/dist/src/components/Table/_internal/useTableSort.d.ts +20 -0
  34. package/dist/src/components/Table/_internal/useTableSort.d.ts.map +1 -0
  35. package/dist/src/components/Table/cells/RenderButton.d.ts +13 -0
  36. package/dist/src/components/Table/cells/RenderButton.d.ts.map +1 -0
  37. package/dist/src/components/Table/cells/RenderChip.d.ts +80 -0
  38. package/dist/src/components/Table/cells/RenderChip.d.ts.map +1 -0
  39. package/dist/src/components/Table/cells/RenderText.d.ts +21 -0
  40. package/dist/src/components/Table/cells/RenderText.d.ts.map +1 -0
  41. package/dist/src/components/Table/cells/RenderTwoLine.d.ts +20 -0
  42. package/dist/src/components/Table/cells/RenderTwoLine.d.ts.map +1 -0
  43. package/dist/src/components/Table/cells/RowActionsMenu.d.ts +36 -0
  44. package/dist/src/components/Table/cells/RowActionsMenu.d.ts.map +1 -0
  45. package/dist/src/components/Table/cells/index.d.ts +11 -0
  46. package/dist/src/components/Table/cells/index.d.ts.map +1 -0
  47. package/dist/src/components/Table/table.types.d.ts +304 -0
  48. package/dist/src/components/Table/table.types.d.ts.map +1 -0
  49. package/dist/src/components/Table/table.variants.d.ts +285 -0
  50. package/dist/src/components/Table/table.variants.d.ts.map +1 -0
  51. package/dist/src/index.d.ts +13 -1
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/src/components/Pagination/Pagination.test.tsx +314 -0
  55. package/src/components/Pagination/Pagination.tsx +275 -0
  56. package/src/components/Pagination/pagination.helpers.ts +102 -0
  57. package/src/components/Pagination/pagination.types.ts +117 -0
  58. package/src/components/Pagination/pagination.variants.ts +111 -0
  59. package/src/components/Skeleton/Skeleton.test.tsx +127 -0
  60. package/src/components/Skeleton/Skeleton.tsx +49 -0
  61. package/src/components/Skeleton/skeleton.types.ts +59 -0
  62. package/src/components/Skeleton/skeleton.variants.ts +86 -0
  63. package/src/components/Table/Table.test.tsx +603 -0
  64. package/src/components/Table/Table.tsx +816 -0
  65. package/src/components/Table/_internal/getNestedValue.test.ts +50 -0
  66. package/src/components/Table/_internal/getNestedValue.ts +32 -0
  67. package/src/components/Table/_internal/themeIdentity.test.ts +84 -0
  68. package/src/components/Table/_internal/useColumnAutoDetect.test.ts +123 -0
  69. package/src/components/Table/_internal/useColumnAutoDetect.ts +100 -0
  70. package/src/components/Table/_internal/useControllableState.ts +48 -0
  71. package/src/components/Table/_internal/useDebouncedValue.ts +24 -0
  72. package/src/components/Table/_internal/useTableFilter.ts +37 -0
  73. package/src/components/Table/_internal/useTableSearch.test.ts +115 -0
  74. package/src/components/Table/_internal/useTableSearch.ts +66 -0
  75. package/src/components/Table/_internal/useTableSelection.test.ts +100 -0
  76. package/src/components/Table/_internal/useTableSelection.ts +100 -0
  77. package/src/components/Table/_internal/useTableSort.test.ts +150 -0
  78. package/src/components/Table/_internal/useTableSort.ts +141 -0
  79. package/src/components/Table/cells/RenderButton.tsx +23 -0
  80. package/src/components/Table/cells/RenderChip.tsx +103 -0
  81. package/src/components/Table/cells/RenderText.tsx +37 -0
  82. package/src/components/Table/cells/RenderTwoLine.tsx +34 -0
  83. package/src/components/Table/cells/RowActionsMenu.tsx +147 -0
  84. package/src/components/Table/cells/index.ts +14 -0
  85. package/src/components/Table/table.types.ts +337 -0
  86. package/src/components/Table/table.variants.ts +207 -0
  87. package/src/index.ts +60 -1
@@ -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>;