@glyphui/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +137 -2
- package/dist/data-table.d.ts +110 -0
- package/dist/data-table.js +225 -0
- package/dist/field-DXZD0l8w.js +107 -0
- package/dist/field-context-B8cYheXz.js +321 -0
- package/dist/form.d.ts +79 -0
- package/dist/form.js +84 -0
- package/dist/index-BWK4czIG.d.ts +233 -0
- package/dist/index.d.ts +2155 -0
- package/dist/index.js +1529 -0
- package/dist/registry-BGSJoiLq.d.ts +9 -0
- package/dist/states-BxPjCUxz.js +287 -0
- package/dist/tv-DuMh7UH2.d.ts +6 -0
- package/package.json +113 -3
- package/src/components/avatar/avatar.styles.ts +22 -0
- package/src/components/avatar/avatar.tsx +62 -0
- package/src/components/avatar/index.ts +2 -0
- package/src/components/badge/badge.styles.ts +69 -0
- package/src/components/badge/badge.tsx +30 -0
- package/src/components/badge/index.ts +2 -0
- package/src/components/button/button.styles.ts +43 -0
- package/src/components/button/button.tsx +77 -0
- package/src/components/button/index.ts +2 -0
- package/src/components/card/card.styles.ts +32 -0
- package/src/components/card/card.tsx +91 -0
- package/src/components/card/index.ts +11 -0
- package/src/components/checkbox/checkbox.tsx +39 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/container/container.tsx +35 -0
- package/src/components/container/index.ts +1 -0
- package/src/components/eyebrow/eyebrow.styles.ts +14 -0
- package/src/components/eyebrow/eyebrow.tsx +19 -0
- package/src/components/eyebrow/index.ts +2 -0
- package/src/components/field/field-context.ts +40 -0
- package/src/components/field/field.styles.ts +23 -0
- package/src/components/field/field.tsx +109 -0
- package/src/components/field/index.ts +3 -0
- package/src/components/heading/heading.styles.ts +16 -0
- package/src/components/heading/heading.tsx +26 -0
- package/src/components/heading/index.ts +2 -0
- package/src/components/input/index.ts +2 -0
- package/src/components/input/input.styles.ts +36 -0
- package/src/components/input/input.tsx +33 -0
- package/src/components/kbd/index.ts +1 -0
- package/src/components/kbd/kbd.tsx +21 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.tsx +21 -0
- package/src/components/section/index.ts +1 -0
- package/src/components/section/section.tsx +39 -0
- package/src/components/segmented-control/index.ts +6 -0
- package/src/components/segmented-control/segmented-control.tsx +79 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select/select.tsx +133 -0
- package/src/components/separator/index.ts +1 -0
- package/src/components/separator/separator.tsx +29 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/skeleton.tsx +20 -0
- package/src/components/spinner/index.ts +2 -0
- package/src/components/spinner/spinner.styles.ts +19 -0
- package/src/components/spinner/spinner.tsx +42 -0
- package/src/components/stack/index.ts +1 -0
- package/src/components/stack/stack.tsx +62 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/switch.tsx +48 -0
- package/src/components/table/index.ts +10 -0
- package/src/components/table/table.tsx +90 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/tabs.tsx +92 -0
- package/src/components/text/index.ts +2 -0
- package/src/components/text/text.styles.ts +32 -0
- package/src/components/text/text.tsx +17 -0
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/textarea.tsx +27 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/tooltip.tsx +42 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-component-config.ts +42 -0
- package/src/hooks/use-controllable-state.ts +27 -0
- package/src/hooks/use-media-query.ts +14 -0
- package/src/hooks/use-scrolled.ts +14 -0
- package/src/index.ts +52 -0
- package/src/internal/icons.tsx +99 -0
- package/src/patterns/app-shell/app-shell-context.ts +27 -0
- package/src/patterns/app-shell/app-shell.styles.ts +127 -0
- package/src/patterns/app-shell/app-shell.tsx +81 -0
- package/src/patterns/app-shell/index.ts +16 -0
- package/src/patterns/app-shell/navbar.tsx +119 -0
- package/src/patterns/app-shell/page-header.tsx +30 -0
- package/src/patterns/app-shell/sidebar.tsx +163 -0
- package/src/patterns/async/async.tsx +83 -0
- package/src/patterns/async/index.ts +10 -0
- package/src/patterns/async/states.tsx +128 -0
- package/src/patterns/data-table/data-table.tsx +367 -0
- package/src/patterns/data-table/index.ts +2 -0
- package/src/patterns/form/form.tsx +150 -0
- package/src/patterns/form/index.ts +13 -0
- package/src/provider/color-mode.tsx +133 -0
- package/src/provider/glyph-context.ts +42 -0
- package/src/provider/glyph-provider.tsx +41 -0
- package/src/provider/index.ts +18 -0
- package/src/provider/theme-scope.tsx +36 -0
- package/src/provider/theme-style.tsx +19 -0
- package/src/register.ts +69 -0
- package/src/themes.ts +56 -0
- package/src/utils/cn.ts +12 -0
- package/src/utils/compose-refs.ts +11 -0
- package/src/utils/registry.ts +9 -0
- package/src/utils/styles.ts +13 -0
- package/src/utils/tv.ts +7 -0
- package/src/utils/tw-merge-config.ts +14 -0
- package/styles.css +178 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohak Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glyphui/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React components on Tailwind CSS v4 that take their whole look from **one typed theme file**, with the parts every app rebuilds already solved: forms, data tables, app layout, and loading / empty / error states.
|
|
4
|
+
|
|
5
|
+
[Live showcase](https://khalmohak.github.io/glyph/) · [GitHub](https://github.com/khalmohak/glyph) · [Changelog](https://github.com/khalmohak/glyph/blob/main/packages/ui/CHANGELOG.md)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @glyphui/ui
|
|
11
|
+
# optional: the form and data-table patterns
|
|
12
|
+
npm install react-hook-form @hookform/resolvers zod @tanstack/react-table
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires React 19 and Tailwind CSS 4.1 or later.
|
|
16
|
+
|
|
17
|
+
## Set up
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
/* index.css */
|
|
21
|
+
@import "tailwindcss";
|
|
22
|
+
@import "@glyphui/ui/styles.css";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// main.tsx
|
|
27
|
+
import { GlyphProvider, presets } from '@glyphui/ui'
|
|
28
|
+
|
|
29
|
+
createRoot(document.getElementById('root')!).render(
|
|
30
|
+
<GlyphProvider theme={presets.glyph} defaultMode="system">
|
|
31
|
+
<App />
|
|
32
|
+
</GlyphProvider>,
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To avoid a light flash for dark-mode visitors, run `getColorModeScript()` in `<head>`, or render `<ColorModeScript />` with an SSR framework.
|
|
37
|
+
|
|
38
|
+
## Your theme, in one file
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// glyph.theme.ts
|
|
42
|
+
import { defineTheme, presets } from '@glyphui/ui'
|
|
43
|
+
|
|
44
|
+
export default defineTheme({
|
|
45
|
+
name: 'acme',
|
|
46
|
+
extends: presets.glyph, // glyph · brutalist · editorial · playful
|
|
47
|
+
colors: {
|
|
48
|
+
light: { primary: 'oklch(55% 0.2 30)' },
|
|
49
|
+
dark: { primary: 'oklch(70% 0.19 45)' },
|
|
50
|
+
},
|
|
51
|
+
radius: { md: '6px', lg: '10px' },
|
|
52
|
+
font: { sans: '"Inter Variable", system-ui, sans-serif' },
|
|
53
|
+
components: {
|
|
54
|
+
Button: { defaultVariants: { size: 'lg' }, className: { base: 'tracking-tight' } },
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A theme controls:
|
|
60
|
+
- colors, separately for light and dark
|
|
61
|
+
- a nine-step type scale (size, line height, tracking, weight)
|
|
62
|
+
- radius, shadows, border width, motion and control height
|
|
63
|
+
- defaults and extra classes for each component
|
|
64
|
+
|
|
65
|
+
Everything is type-checked. A Button size or Card part that doesn't exist is a compile error.
|
|
66
|
+
|
|
67
|
+
The same tokens work in your own markup: `bg-primary`, `text-muted-foreground`, `rounded-lg`, `shadow-md`, `text-h2`, `font-display`.
|
|
68
|
+
|
|
69
|
+
## Components
|
|
70
|
+
|
|
71
|
+
`Button` · `IconButton` · `Badge` · `Card` · `Heading` · `Text` · `Eyebrow` · `Kbd` · `Avatar` · `Separator` · `Skeleton` · `Spinner` · `Label` · `Field` · `Input` · `Textarea` · `Checkbox` · `Switch` · `Select` · `SegmentedControl` · `Tabs` · `Tooltip` · `Table` · `Container` · `Section` · `Stack` · `ThemeScope`
|
|
72
|
+
|
|
73
|
+
Accessible behavior comes from [Radix UI](https://www.radix-ui.com/). Every component accepts `className`, and most accept `asChild`.
|
|
74
|
+
|
|
75
|
+
## Patterns
|
|
76
|
+
|
|
77
|
+
### Layout
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { AppShell, Sidebar, SidebarContent, SidebarItem, PageHeader } from '@glyphui/ui'
|
|
81
|
+
|
|
82
|
+
<AppShell sidebar={<Sidebar><SidebarContent>
|
|
83
|
+
<SidebarItem href="/inbox" icon={<Inbox />} badge={3} active>Inbox</SidebarItem>
|
|
84
|
+
</SidebarContent></Sidebar>}>
|
|
85
|
+
<PageHeader title="Inbox" actions={<Button>New</Button>} />
|
|
86
|
+
</AppShell>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The sidebar collapses to an icon strip on desktop and opens as a focus-trapped drawer on mobile. `Navbar` builds a responsive site header from `links` data. To use your router's link component, pass it to `GlyphProvider`: `linkComponent={RouterLink}`.
|
|
90
|
+
|
|
91
|
+
### Forms: `@glyphui/ui/form`
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { Form, FormField, FormSubmit, useForm } from '@glyphui/ui/form'
|
|
95
|
+
|
|
96
|
+
const form = useForm({ schema, defaultValues: { email: '' } }) // zod, valibot, arktype...
|
|
97
|
+
|
|
98
|
+
<Form form={form} onSubmit={async (values) => {
|
|
99
|
+
const res = await api.signup(values)
|
|
100
|
+
if (res.taken) return { errors: { email: 'Already registered' } }
|
|
101
|
+
}}>
|
|
102
|
+
<FormField control={form.control} name="email" label="Email">
|
|
103
|
+
{(field) => <Input {...field} />}
|
|
104
|
+
</FormField>
|
|
105
|
+
<FormSubmit>Sign up</FormSubmit>
|
|
106
|
+
</Form>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Field names are checked against the schema. Server errors you return appear on their fields. If `onSubmit` throws, the error appears above the form in `<FormError />`.
|
|
110
|
+
|
|
111
|
+
### Data tables: `@glyphui/ui/data-table`
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { createColumnHelper, DataTable } from '@glyphui/ui/data-table'
|
|
115
|
+
|
|
116
|
+
const col = createColumnHelper<Invoice>()
|
|
117
|
+
const columns = [
|
|
118
|
+
col.accessor('number', { header: 'Invoice' }),
|
|
119
|
+
col.accessor('total', { header: 'Total', meta: { align: 'right' } }),
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
<DataTable data={invoices} columns={columns} loading={isLoading} error={error}
|
|
123
|
+
onRetry={refetch} search selectable pageSize={20} />
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Includes sorting, search, row selection and pages, plus loading, empty, no-results and error states.
|
|
127
|
+
|
|
128
|
+
### Async states
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
<Async result={useQuery({ queryKey: ['projects'], queryFn })}>
|
|
132
|
+
{(projects) => <ProjectList projects={projects} />}
|
|
133
|
+
</Async>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { t as VariantProps } from "./tv-DuMh7UH2.js";
|
|
2
|
+
import { t as StylesEntry } from "./registry-BGSJoiLq.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { ColumnDef, ColumnDef as ColumnDef$1, RowData, SortingState, SortingState as SortingState$1, createColumnHelper } from "@tanstack/react-table";
|
|
5
|
+
//#region src/patterns/data-table/data-table.d.ts
|
|
6
|
+
declare module '@tanstack/react-table' {
|
|
7
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
8
|
+
/** Cell and header alignment. Use `right` for numbers. */
|
|
9
|
+
align?: 'left' | 'center' | 'right';
|
|
10
|
+
/** Extra classes for this column's cells. */
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const dataTableStyles: import("tailwind-variants").TVReturnType<{
|
|
15
|
+
variant: {
|
|
16
|
+
card: {
|
|
17
|
+
root: string[];
|
|
18
|
+
toolbar: string;
|
|
19
|
+
footer: string;
|
|
20
|
+
};
|
|
21
|
+
plain: {
|
|
22
|
+
root: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}, {
|
|
26
|
+
root: string;
|
|
27
|
+
toolbar: string;
|
|
28
|
+
search: string;
|
|
29
|
+
actions: string;
|
|
30
|
+
sortButton: string[];
|
|
31
|
+
footer: string;
|
|
32
|
+
pager: string;
|
|
33
|
+
}, undefined, {
|
|
34
|
+
variant: {
|
|
35
|
+
card: {
|
|
36
|
+
root: string[];
|
|
37
|
+
toolbar: string;
|
|
38
|
+
footer: string;
|
|
39
|
+
};
|
|
40
|
+
plain: {
|
|
41
|
+
root: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}, {
|
|
45
|
+
root: string;
|
|
46
|
+
toolbar: string;
|
|
47
|
+
search: string;
|
|
48
|
+
actions: string;
|
|
49
|
+
sortButton: string[];
|
|
50
|
+
footer: string;
|
|
51
|
+
pager: string;
|
|
52
|
+
}, import("tailwind-variants").TVReturnTypeLike<{
|
|
53
|
+
variant: {
|
|
54
|
+
card: {
|
|
55
|
+
root: string[];
|
|
56
|
+
toolbar: string;
|
|
57
|
+
footer: string;
|
|
58
|
+
};
|
|
59
|
+
plain: {
|
|
60
|
+
root: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}, {
|
|
64
|
+
root: string;
|
|
65
|
+
toolbar: string;
|
|
66
|
+
search: string;
|
|
67
|
+
actions: string;
|
|
68
|
+
sortButton: string[];
|
|
69
|
+
footer: string;
|
|
70
|
+
pager: string;
|
|
71
|
+
}>>;
|
|
72
|
+
declare module '@glyphui/tokens' {
|
|
73
|
+
interface GlyphComponentRegistry {
|
|
74
|
+
DataTable: StylesEntry<typeof dataTableStyles>;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
interface DataTableProps<T> extends VariantProps<typeof dataTableStyles> {
|
|
78
|
+
data: T[] | undefined;
|
|
79
|
+
/** Build with `createColumnHelper<T>()` for typed accessors. */
|
|
80
|
+
columns: ColumnDef$1<T, any>[];
|
|
81
|
+
/** Shows skeleton rows. */
|
|
82
|
+
loading?: boolean;
|
|
83
|
+
/** Shows an error state with a retry button when `onRetry` is set. */
|
|
84
|
+
error?: unknown;
|
|
85
|
+
onRetry?: () => unknown;
|
|
86
|
+
getRowId?: (row: T, index: number) => string;
|
|
87
|
+
/** Rows per page, or `false` to show every row. Default 10. */
|
|
88
|
+
pageSize?: number | false;
|
|
89
|
+
/** Adds a checkbox column. */
|
|
90
|
+
selectable?: boolean;
|
|
91
|
+
onSelectionChange?: (rows: T[]) => void;
|
|
92
|
+
/** Adds a search box that filters across all columns. */
|
|
93
|
+
search?: boolean | {
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
};
|
|
96
|
+
/** Extra controls at the end of the toolbar (filters, buttons). */
|
|
97
|
+
toolbar?: ReactNode;
|
|
98
|
+
/** Shown when there are no rows at all (not when a search matches nothing). */
|
|
99
|
+
empty?: ReactNode;
|
|
100
|
+
initialSorting?: SortingState$1;
|
|
101
|
+
'aria-label'?: string;
|
|
102
|
+
className?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A table with sorting, search, pagination and row selection, plus built-in loading,
|
|
106
|
+
* empty, no-results and error states. Columns are typed from your row type.
|
|
107
|
+
*/
|
|
108
|
+
export declare function DataTable<T>(inProps: DataTableProps<T>): import("react").JSX.Element;
|
|
109
|
+
//#endregion
|
|
110
|
+
export { type ColumnDef, type DataTableProps, type SortingState, createColumnHelper };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { E as tv, O as useComponentConfig, S as focusRing, _ as Button, a as ArrowUpIcon, c as ChevronLeftIcon, h as SearchIcon, i as ArrowDownIcon, l as ChevronRightIcon, u as ChevronsUpDownIcon, v as IconButton, w as themedBorder } from "./field-context-B8cYheXz.js";
|
|
3
|
+
import { a as Table, c as TableCell, d as TableRow, h as Input, l as TableHead, n as ErrorState, o as TableBody, p as Skeleton, t as EmptyState, u as TableHeader, v as Checkbox } from "./states-BxPjCUxz.js";
|
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { createColumnHelper, flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
7
|
+
//#region src/patterns/data-table/data-table.tsx
|
|
8
|
+
const dataTableStyles = tv({
|
|
9
|
+
slots: {
|
|
10
|
+
root: "flex min-w-0 flex-col",
|
|
11
|
+
toolbar: "flex flex-wrap items-center gap-2",
|
|
12
|
+
search: "w-full sm:max-w-64",
|
|
13
|
+
actions: "ml-auto flex items-center gap-2",
|
|
14
|
+
sortButton: ["-ml-1.5 inline-flex cursor-pointer items-center gap-1 rounded-xs px-1.5 py-1 hover:text-foreground [&>svg]:size-3.5", focusRing],
|
|
15
|
+
footer: "flex flex-wrap items-center justify-between gap-3 text-small text-muted-foreground tabular-nums",
|
|
16
|
+
pager: "flex items-center gap-1"
|
|
17
|
+
},
|
|
18
|
+
variants: { variant: {
|
|
19
|
+
card: {
|
|
20
|
+
root: ["overflow-hidden rounded-lg border-border bg-surface shadow-sm", themedBorder],
|
|
21
|
+
toolbar: "border-b border-border p-3",
|
|
22
|
+
footer: "border-t border-border px-4 py-2.5"
|
|
23
|
+
},
|
|
24
|
+
plain: { root: "gap-3" }
|
|
25
|
+
} },
|
|
26
|
+
defaultVariants: { variant: "card" }
|
|
27
|
+
});
|
|
28
|
+
const alignClass = {
|
|
29
|
+
left: "text-left",
|
|
30
|
+
center: "text-center",
|
|
31
|
+
right: "text-right"
|
|
32
|
+
};
|
|
33
|
+
const NO_ROWS = [];
|
|
34
|
+
function selectColumn() {
|
|
35
|
+
return {
|
|
36
|
+
id: "__select",
|
|
37
|
+
enableSorting: false,
|
|
38
|
+
enableGlobalFilter: false,
|
|
39
|
+
header: ({ table }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
40
|
+
className: "mt-0",
|
|
41
|
+
"aria-label": "Select all rows on this page",
|
|
42
|
+
checked: table.getIsAllPageRowsSelected() ? true : table.getIsSomePageRowsSelected() ? "indeterminate" : false,
|
|
43
|
+
onCheckedChange: (value) => table.toggleAllPageRowsSelected(value === true)
|
|
44
|
+
}),
|
|
45
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
46
|
+
className: "mt-0",
|
|
47
|
+
"aria-label": "Select row",
|
|
48
|
+
checked: row.getIsSelected(),
|
|
49
|
+
disabled: !row.getCanSelect(),
|
|
50
|
+
onCheckedChange: (value) => row.toggleSelected(value === true)
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A table with sorting, search, pagination and row selection, plus built-in loading,
|
|
56
|
+
* empty, no-results and error states. Columns are typed from your row type.
|
|
57
|
+
*/
|
|
58
|
+
function DataTable(inProps) {
|
|
59
|
+
const [props, slots] = useComponentConfig("DataTable", inProps);
|
|
60
|
+
const { data, columns, loading = false, error, onRetry, getRowId, pageSize = 10, selectable = false, onSelectionChange, search = false, toolbar, empty, initialSorting = [], variant, className, "aria-label": ariaLabel } = props;
|
|
61
|
+
const [sorting, setSorting] = useState(initialSorting);
|
|
62
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
63
|
+
const [globalFilter, setGlobalFilter] = useState("");
|
|
64
|
+
const allColumns = useMemo(() => selectable ? [selectColumn(), ...columns] : columns, [selectable, columns]);
|
|
65
|
+
const table = useReactTable({
|
|
66
|
+
data: data ?? NO_ROWS,
|
|
67
|
+
columns: allColumns,
|
|
68
|
+
state: {
|
|
69
|
+
sorting,
|
|
70
|
+
rowSelection,
|
|
71
|
+
globalFilter
|
|
72
|
+
},
|
|
73
|
+
onSortingChange: setSorting,
|
|
74
|
+
onRowSelectionChange: setRowSelection,
|
|
75
|
+
onGlobalFilterChange: setGlobalFilter,
|
|
76
|
+
enableRowSelection: selectable,
|
|
77
|
+
sortDescFirst: false,
|
|
78
|
+
getCoreRowModel: getCoreRowModel(),
|
|
79
|
+
getSortedRowModel: getSortedRowModel(),
|
|
80
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
81
|
+
...getRowId && { getRowId },
|
|
82
|
+
...pageSize !== false && {
|
|
83
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
84
|
+
initialState: { pagination: {
|
|
85
|
+
pageIndex: 0,
|
|
86
|
+
pageSize
|
|
87
|
+
} }
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
onSelectionChange?.(table.getSelectedRowModel().rows.map((row) => row.original));
|
|
92
|
+
}, [rowSelection]);
|
|
93
|
+
const s = dataTableStyles({ variant });
|
|
94
|
+
const columnCount = table.getVisibleLeafColumns().length;
|
|
95
|
+
const rows = table.getRowModel().rows;
|
|
96
|
+
const filteredTotal = table.getFilteredRowModel().rows.length;
|
|
97
|
+
const selectedCount = Object.keys(rowSelection).length;
|
|
98
|
+
const { pageIndex, pageSize: size } = table.getState().pagination;
|
|
99
|
+
const showFooter = pageSize !== false && !loading && !error && filteredTotal > 0;
|
|
100
|
+
const searchPlaceholder = typeof search === "object" ? search.placeholder : void 0;
|
|
101
|
+
const fullWidthRow = (content) => /* @__PURE__ */ jsx(TableRow, {
|
|
102
|
+
className: "hover:bg-transparent",
|
|
103
|
+
children: /* @__PURE__ */ jsx(TableCell, {
|
|
104
|
+
colSpan: columnCount,
|
|
105
|
+
className: "p-0",
|
|
106
|
+
children: content
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
let body;
|
|
110
|
+
if (loading) body = Array.from({ length: pageSize === false ? 5 : Math.min(pageSize, 8) }, (_, i) => /* @__PURE__ */ jsx(TableRow, {
|
|
111
|
+
className: "hover:bg-transparent",
|
|
112
|
+
children: table.getVisibleLeafColumns().map((column) => /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Skeleton, { className: column.id === "__select" ? "size-4" : "h-4 w-[70%]" }) }, column.id))
|
|
113
|
+
}, i));
|
|
114
|
+
else if (error) body = fullWidthRow(/* @__PURE__ */ jsx(ErrorState, {
|
|
115
|
+
error,
|
|
116
|
+
onRetry
|
|
117
|
+
}));
|
|
118
|
+
else if (rows.length === 0) body = fullWidthRow(globalFilter ? /* @__PURE__ */ jsx(EmptyState, {
|
|
119
|
+
icon: /* @__PURE__ */ jsx(SearchIcon, {}),
|
|
120
|
+
title: `No results for “${globalFilter}”`,
|
|
121
|
+
description: "Check the spelling or try a shorter search.",
|
|
122
|
+
action: /* @__PURE__ */ jsx(Button, {
|
|
123
|
+
variant: "outline",
|
|
124
|
+
size: "sm",
|
|
125
|
+
onClick: () => setGlobalFilter(""),
|
|
126
|
+
children: "Clear search"
|
|
127
|
+
})
|
|
128
|
+
}) : empty ?? /* @__PURE__ */ jsx(EmptyState, { title: "No rows yet" }));
|
|
129
|
+
else body = rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
|
|
130
|
+
"data-state": row.getIsSelected() ? "selected" : void 0,
|
|
131
|
+
children: row.getVisibleCells().map((cell) => {
|
|
132
|
+
const meta = cell.column.columnDef.meta;
|
|
133
|
+
return /* @__PURE__ */ jsx(TableCell, {
|
|
134
|
+
className: [alignClass[meta?.align ?? "left"], meta?.className].join(" "),
|
|
135
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
136
|
+
}, cell.id);
|
|
137
|
+
})
|
|
138
|
+
}, row.id));
|
|
139
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
140
|
+
"data-slot": "data-table",
|
|
141
|
+
className: s.root({ class: [slots.root, className] }),
|
|
142
|
+
children: [
|
|
143
|
+
(search || toolbar) && /* @__PURE__ */ jsxs("div", {
|
|
144
|
+
className: s.toolbar({ class: slots.toolbar }),
|
|
145
|
+
children: [search && /* @__PURE__ */ jsx(Input, {
|
|
146
|
+
size: "sm",
|
|
147
|
+
type: "search",
|
|
148
|
+
"aria-label": "Search rows",
|
|
149
|
+
placeholder: searchPlaceholder ?? "Search…",
|
|
150
|
+
prefix: /* @__PURE__ */ jsx(SearchIcon, {}),
|
|
151
|
+
value: globalFilter,
|
|
152
|
+
onChange: (event) => {
|
|
153
|
+
setGlobalFilter(event.target.value);
|
|
154
|
+
table.setPageIndex(0);
|
|
155
|
+
},
|
|
156
|
+
className: s.search({ class: slots.search })
|
|
157
|
+
}), toolbar && /* @__PURE__ */ jsx("div", {
|
|
158
|
+
className: s.actions({ class: slots.actions }),
|
|
159
|
+
children: toolbar
|
|
160
|
+
})]
|
|
161
|
+
}),
|
|
162
|
+
/* @__PURE__ */ jsxs(Table, {
|
|
163
|
+
"aria-label": ariaLabel,
|
|
164
|
+
"aria-busy": loading || void 0,
|
|
165
|
+
children: [/* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((group) => /* @__PURE__ */ jsx(TableRow, {
|
|
166
|
+
className: "hover:bg-transparent",
|
|
167
|
+
children: group.headers.map((header) => {
|
|
168
|
+
const column = header.column;
|
|
169
|
+
const sorted = column.getIsSorted();
|
|
170
|
+
const align = column.columnDef.meta?.align ?? "left";
|
|
171
|
+
const label = header.isPlaceholder ? null : flexRender(column.columnDef.header, header.getContext());
|
|
172
|
+
return /* @__PURE__ */ jsx(TableHead, {
|
|
173
|
+
className: alignClass[align],
|
|
174
|
+
"aria-sort": sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : void 0,
|
|
175
|
+
children: column.getCanSort() && !header.isPlaceholder ? /* @__PURE__ */ jsxs("button", {
|
|
176
|
+
type: "button",
|
|
177
|
+
onClick: column.getToggleSortingHandler(),
|
|
178
|
+
className: s.sortButton({ class: [slots.sortButton, align === "right" && "flex-row-reverse"] }),
|
|
179
|
+
children: [label, sorted === "asc" ? /* @__PURE__ */ jsx(ArrowUpIcon, {}) : sorted === "desc" ? /* @__PURE__ */ jsx(ArrowDownIcon, {}) : /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "opacity-40" })]
|
|
180
|
+
}) : label
|
|
181
|
+
}, header.id);
|
|
182
|
+
})
|
|
183
|
+
}, group.id)) }), /* @__PURE__ */ jsx(TableBody, { children: body })]
|
|
184
|
+
}),
|
|
185
|
+
showFooter && /* @__PURE__ */ jsxs("div", {
|
|
186
|
+
className: s.footer({ class: slots.footer }),
|
|
187
|
+
children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
188
|
+
pageIndex * size + 1,
|
|
189
|
+
"–",
|
|
190
|
+
Math.min((pageIndex + 1) * size, filteredTotal),
|
|
191
|
+
" of",
|
|
192
|
+
" ",
|
|
193
|
+
filteredTotal,
|
|
194
|
+
selectedCount > 0 && /* @__PURE__ */ jsxs("span", {
|
|
195
|
+
className: "text-foreground",
|
|
196
|
+
children: [
|
|
197
|
+
" · ",
|
|
198
|
+
selectedCount,
|
|
199
|
+
" selected"
|
|
200
|
+
]
|
|
201
|
+
})
|
|
202
|
+
] }), /* @__PURE__ */ jsxs("div", {
|
|
203
|
+
className: s.pager({ class: slots.pager }),
|
|
204
|
+
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
205
|
+
variant: "outline",
|
|
206
|
+
size: "sm",
|
|
207
|
+
icon: /* @__PURE__ */ jsx(ChevronLeftIcon, {}),
|
|
208
|
+
"aria-label": "Previous page",
|
|
209
|
+
disabled: !table.getCanPreviousPage(),
|
|
210
|
+
onClick: () => table.previousPage()
|
|
211
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
212
|
+
variant: "outline",
|
|
213
|
+
size: "sm",
|
|
214
|
+
icon: /* @__PURE__ */ jsx(ChevronRightIcon, {}),
|
|
215
|
+
"aria-label": "Next page",
|
|
216
|
+
disabled: !table.getCanNextPage(),
|
|
217
|
+
onClick: () => table.nextPage()
|
|
218
|
+
})]
|
|
219
|
+
})]
|
|
220
|
+
})
|
|
221
|
+
]
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { DataTable, createColumnHelper, dataTableStyles };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { E as tv, O as useComponentConfig, t as FieldContext } from "./field-context-B8cYheXz.js";
|
|
3
|
+
import { Label } from "radix-ui";
|
|
4
|
+
import { useId, useMemo } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/components/label/label.tsx
|
|
7
|
+
const labelStyles = tv({ slots: { base: "inline-flex select-none items-center gap-1 text-small font-medium text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-60" } });
|
|
8
|
+
function Label$1(inProps) {
|
|
9
|
+
const [{ className, ...rest }, slots] = useComponentConfig("Label", inProps);
|
|
10
|
+
return /* @__PURE__ */ jsx(Label.Root, {
|
|
11
|
+
"data-slot": "label",
|
|
12
|
+
className: labelStyles().base({ class: [slots.base, className] }),
|
|
13
|
+
...rest
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/components/field/field.styles.ts
|
|
18
|
+
const fieldStyles = tv({
|
|
19
|
+
slots: {
|
|
20
|
+
root: "grid gap-1.5",
|
|
21
|
+
label: "",
|
|
22
|
+
required: "text-danger",
|
|
23
|
+
text: "grid gap-0.5",
|
|
24
|
+
description: "text-small text-faint-foreground",
|
|
25
|
+
error: "text-small font-medium text-danger"
|
|
26
|
+
},
|
|
27
|
+
variants: { orientation: {
|
|
28
|
+
vertical: {},
|
|
29
|
+
horizontal: { root: "grid-cols-[auto_1fr] items-start gap-x-3 [&>[data-slot=field-text]]:col-start-2" }
|
|
30
|
+
} },
|
|
31
|
+
defaultVariants: { orientation: "vertical" }
|
|
32
|
+
});
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/components/field/field.tsx
|
|
35
|
+
/**
|
|
36
|
+
* Wraps one form control with its label, description and error, and wires the ARIA
|
|
37
|
+
* attributes between them. Controls inside (Input, Select, Checkbox, ...) pick this up.
|
|
38
|
+
*
|
|
39
|
+
* `orientation="horizontal"` puts the control first with text beside it, for checkboxes
|
|
40
|
+
* and switches.
|
|
41
|
+
*/
|
|
42
|
+
function Field(inProps) {
|
|
43
|
+
const [props, slots] = useComponentConfig("Field", inProps);
|
|
44
|
+
const { label, description, error, required = false, disabled = false, controlId, orientation, className, children, ...rest } = props;
|
|
45
|
+
const generated = useId();
|
|
46
|
+
const id = controlId ?? generated;
|
|
47
|
+
const invalid = Boolean(error);
|
|
48
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
49
|
+
const errorId = invalid ? `${id}-error` : void 0;
|
|
50
|
+
const s = fieldStyles({ orientation });
|
|
51
|
+
const context = useMemo(() => ({
|
|
52
|
+
id,
|
|
53
|
+
descriptionId,
|
|
54
|
+
errorId,
|
|
55
|
+
invalid,
|
|
56
|
+
required,
|
|
57
|
+
disabled
|
|
58
|
+
}), [
|
|
59
|
+
id,
|
|
60
|
+
descriptionId,
|
|
61
|
+
errorId,
|
|
62
|
+
invalid,
|
|
63
|
+
required,
|
|
64
|
+
disabled
|
|
65
|
+
]);
|
|
66
|
+
const labelNode = label ? /* @__PURE__ */ jsxs(Label$1, {
|
|
67
|
+
htmlFor: id,
|
|
68
|
+
className: s.label({ class: slots.label }),
|
|
69
|
+
children: [label, required && /* @__PURE__ */ jsx("span", {
|
|
70
|
+
className: s.required({ class: slots.required }),
|
|
71
|
+
"aria-hidden": "true",
|
|
72
|
+
children: "*"
|
|
73
|
+
})]
|
|
74
|
+
}) : null;
|
|
75
|
+
const messages = /* @__PURE__ */ jsxs(Fragment$1, { children: [description && /* @__PURE__ */ jsx("p", {
|
|
76
|
+
id: descriptionId,
|
|
77
|
+
"data-slot": "field-description",
|
|
78
|
+
className: s.description({ class: slots.description }),
|
|
79
|
+
children: description
|
|
80
|
+
}), invalid && /* @__PURE__ */ jsx("p", {
|
|
81
|
+
id: errorId,
|
|
82
|
+
"data-slot": "field-error",
|
|
83
|
+
className: s.error({ class: slots.error }),
|
|
84
|
+
children: error
|
|
85
|
+
})] });
|
|
86
|
+
return /* @__PURE__ */ jsx(FieldContext.Provider, {
|
|
87
|
+
value: context,
|
|
88
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
89
|
+
"data-slot": "field",
|
|
90
|
+
"data-invalid": invalid || void 0,
|
|
91
|
+
"data-disabled": disabled || void 0,
|
|
92
|
+
className: s.root({ class: [slots.root, className] }),
|
|
93
|
+
...rest,
|
|
94
|
+
children: orientation === "horizontal" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [children, /* @__PURE__ */ jsxs("div", {
|
|
95
|
+
"data-slot": "field-text",
|
|
96
|
+
className: s.text({ class: slots.text }),
|
|
97
|
+
children: [labelNode, messages]
|
|
98
|
+
})] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
99
|
+
labelNode,
|
|
100
|
+
children,
|
|
101
|
+
messages
|
|
102
|
+
] })
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { labelStyles as i, fieldStyles as n, Label$1 as r, Field as t };
|