@foundrykit/components 2.2.0 → 2.2.3
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/dist/chunk-4WYKNDYY.js +91 -0
- package/dist/chunk-4WYKNDYY.js.map +1 -0
- package/dist/chunk-5CXNMTIN.js +84 -0
- package/dist/chunk-5CXNMTIN.js.map +1 -0
- package/dist/chunk-B5ZTF5MZ.js +203 -0
- package/dist/chunk-B5ZTF5MZ.js.map +1 -0
- package/dist/chunk-EDNWBEKV.js +51 -0
- package/dist/chunk-EDNWBEKV.js.map +1 -0
- package/dist/chunk-ID7BFTID.js +248 -0
- package/dist/chunk-ID7BFTID.js.map +1 -0
- package/dist/chunk-IYBHXVCH.js +181 -0
- package/dist/chunk-IYBHXVCH.js.map +1 -0
- package/dist/chunk-KQZEF7PS.js +71 -0
- package/dist/chunk-KQZEF7PS.js.map +1 -0
- package/dist/chunk-P3GSYR7O.js +889 -0
- package/dist/chunk-P3GSYR7O.js.map +1 -0
- package/dist/chunk-PKSRYDN4.js +168 -0
- package/dist/chunk-PKSRYDN4.js.map +1 -0
- package/dist/chunk-SFM7ZMG2.js +104 -0
- package/dist/chunk-SFM7ZMG2.js.map +1 -0
- package/dist/chunk-TLQQZJUR.js +126 -0
- package/dist/chunk-TLQQZJUR.js.map +1 -0
- package/dist/chunk-UE7CDYEN.js +59 -0
- package/dist/chunk-UE7CDYEN.js.map +1 -0
- package/dist/chunk-UG7YS3D5.js +198 -0
- package/dist/chunk-UG7YS3D5.js.map +1 -0
- package/dist/components/advanced-search-bar/index.d.ts +308 -0
- package/dist/components/advanced-search-bar/index.js +34 -0
- package/dist/components/advanced-search-bar/index.js.map +1 -0
- package/dist/components/calendar/index.d.ts +20 -0
- package/dist/components/calendar/index.js +11 -0
- package/dist/components/calendar/index.js.map +1 -0
- package/dist/components/carousel/index.d.ts +40 -0
- package/dist/components/carousel/index.js +17 -0
- package/dist/components/carousel/index.js.map +1 -0
- package/dist/components/chart/index.d.ts +59 -0
- package/dist/components/chart/index.js +21 -0
- package/dist/components/chart/index.js.map +1 -0
- package/dist/components/combobox/index.d.ts +33 -0
- package/dist/components/combobox/index.js +10 -0
- package/dist/components/combobox/index.js.map +1 -0
- package/dist/components/command/index.d.ts +33 -0
- package/dist/components/command/index.js +25 -0
- package/dist/components/command/index.js.map +1 -0
- package/dist/components/data-table/index.d.ts +17 -0
- package/dist/components/data-table/index.js +9 -0
- package/dist/components/data-table/index.js.map +1 -0
- package/dist/components/date-picker/index.d.ts +17 -0
- package/dist/components/date-picker/index.js +9 -0
- package/dist/components/date-picker/index.js.map +1 -0
- package/dist/components/form/index.d.ts +37 -0
- package/dist/components/form/index.js +23 -0
- package/dist/components/form/index.js.map +1 -0
- package/dist/components/input-otp/index.d.ts +30 -0
- package/dist/components/input-otp/index.js +15 -0
- package/dist/components/input-otp/index.js.map +1 -0
- package/dist/components/pagination/index.d.ts +26 -0
- package/dist/components/pagination/index.js +20 -0
- package/dist/components/pagination/index.js.map +1 -0
- package/dist/components/search-bar/index.d.ts +17 -0
- package/dist/components/search-bar/index.js +9 -0
- package/dist/components/search-bar/index.js.map +1 -0
- package/dist/components/sidebar/index.d.ts +70 -0
- package/dist/components/sidebar/index.js +652 -0
- package/dist/components/sidebar/index.js.map +1 -0
- package/dist/components/theme-toggle/index.d.ts +20 -0
- package/dist/components/theme-toggle/index.js +9 -0
- package/dist/components/theme-toggle/index.js.map +1 -0
- package/dist/index.d.ts +27 -605
- package/dist/index.js +73 -2337
- package/dist/index.js.map +1 -1
- package/package.json +17 -10
- package/CHANGELOG.md +0 -362
- package/src/components/advanced-search-bar/config.ts +0 -223
- package/src/components/advanced-search-bar/index.tsx +0 -1415
- package/src/components/calendar/config.ts +0 -51
- package/src/components/calendar/index.tsx +0 -225
- package/src/components/carousel/config.ts +0 -28
- package/src/components/carousel/index.tsx +0 -258
- package/src/components/chart/config.ts +0 -28
- package/src/components/chart/index.tsx +0 -365
- package/src/components/combobox/config.ts +0 -28
- package/src/components/combobox/index.tsx +0 -111
- package/src/components/command/config.ts +0 -804
- package/src/components/command/index.tsx +0 -195
- package/src/components/data-table/config.ts +0 -28
- package/src/components/data-table/index.tsx +0 -124
- package/src/components/date-picker/config.ts +0 -55
- package/src/components/date-picker/index.tsx +0 -207
- package/src/components/form/config.ts +0 -21
- package/src/components/form/index.tsx +0 -150
- package/src/components/input-otp/config.ts +0 -28
- package/src/components/input-otp/index.tsx +0 -92
- package/src/components/pagination/config.ts +0 -367
- package/src/components/pagination/index.tsx +0 -135
- package/src/components/search-bar/config.ts +0 -58
- package/src/components/search-bar/index.tsx +0 -70
- package/src/components/sidebar/config.ts +0 -29
- package/src/components/sidebar/index.tsx +0 -723
- package/src/components/theme-toggle/config.ts +0 -27
- package/src/components/theme-toggle/index.tsx +0 -63
- package/src/index.ts +0 -83
- package/tsconfig.json +0 -12
- package/tsconfig.lint.json +0 -8
- package/tsup.config.ts +0 -11
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Dialog,
|
|
5
|
-
DialogContent,
|
|
6
|
-
DialogDescription,
|
|
7
|
-
DialogHeader,
|
|
8
|
-
DialogTitle,
|
|
9
|
-
} from '@foundrykit/primitives';
|
|
10
|
-
import { cn } from '@foundrykit/utils';
|
|
11
|
-
import { Command as CommandPrimitive } from 'cmdk';
|
|
12
|
-
import { SearchIcon } from 'lucide-react';
|
|
13
|
-
import type * as React from 'react';
|
|
14
|
-
|
|
15
|
-
/** Styled `cmdk` command menu — the root container for a command palette. */
|
|
16
|
-
function Command({
|
|
17
|
-
className,
|
|
18
|
-
...props
|
|
19
|
-
}: React.ComponentProps<typeof CommandPrimitive>) {
|
|
20
|
-
return (
|
|
21
|
-
<CommandPrimitive
|
|
22
|
-
data-slot='command'
|
|
23
|
-
className={cn(
|
|
24
|
-
'bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md',
|
|
25
|
-
className
|
|
26
|
-
)}
|
|
27
|
-
{...props}
|
|
28
|
-
/>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Command menu rendered inside a modal dialog. `title` and `description` are
|
|
34
|
-
* visually hidden but read by assistive technology.
|
|
35
|
-
*/
|
|
36
|
-
function CommandDialog({
|
|
37
|
-
title = 'Command Palette',
|
|
38
|
-
description = 'Search for a command to run...',
|
|
39
|
-
children,
|
|
40
|
-
className,
|
|
41
|
-
showCloseButton = true,
|
|
42
|
-
...props
|
|
43
|
-
}: React.ComponentProps<typeof Dialog> & {
|
|
44
|
-
title?: string;
|
|
45
|
-
description?: string;
|
|
46
|
-
className?: string;
|
|
47
|
-
showCloseButton?: boolean;
|
|
48
|
-
}) {
|
|
49
|
-
return (
|
|
50
|
-
<Dialog {...props}>
|
|
51
|
-
<DialogHeader className='sr-only'>
|
|
52
|
-
<DialogTitle>{title}</DialogTitle>
|
|
53
|
-
<DialogDescription>{description}</DialogDescription>
|
|
54
|
-
</DialogHeader>
|
|
55
|
-
<DialogContent
|
|
56
|
-
className={cn('overflow-hidden p-0', className)}
|
|
57
|
-
showCloseButton={showCloseButton}
|
|
58
|
-
>
|
|
59
|
-
<Command className='[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5'>
|
|
60
|
-
{children}
|
|
61
|
-
</Command>
|
|
62
|
-
</DialogContent>
|
|
63
|
-
</Dialog>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Search input for a command menu, with a leading search icon. */
|
|
68
|
-
function CommandInput({
|
|
69
|
-
className,
|
|
70
|
-
...props
|
|
71
|
-
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
|
72
|
-
return (
|
|
73
|
-
<div
|
|
74
|
-
data-slot='command-input-wrapper'
|
|
75
|
-
className='flex h-9 items-center gap-2 border-b px-3'
|
|
76
|
-
>
|
|
77
|
-
<SearchIcon className='size-4 shrink-0 opacity-50' />
|
|
78
|
-
<CommandPrimitive.Input
|
|
79
|
-
data-slot='command-input'
|
|
80
|
-
className={cn(
|
|
81
|
-
'placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50',
|
|
82
|
-
className
|
|
83
|
-
)}
|
|
84
|
-
{...props}
|
|
85
|
-
/>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Scrollable list containing command groups and items. */
|
|
91
|
-
function CommandList({
|
|
92
|
-
className,
|
|
93
|
-
...props
|
|
94
|
-
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
|
95
|
-
return (
|
|
96
|
-
<CommandPrimitive.List
|
|
97
|
-
data-slot='command-list'
|
|
98
|
-
className={cn(
|
|
99
|
-
'max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto',
|
|
100
|
-
className
|
|
101
|
-
)}
|
|
102
|
-
{...props}
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Message shown when no command items match the current query. */
|
|
108
|
-
function CommandEmpty({
|
|
109
|
-
...props
|
|
110
|
-
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
|
111
|
-
return (
|
|
112
|
-
<CommandPrimitive.Empty
|
|
113
|
-
data-slot='command-empty'
|
|
114
|
-
className='py-6 text-center text-sm'
|
|
115
|
-
{...props}
|
|
116
|
-
/>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Labelled group of related command items. */
|
|
121
|
-
function CommandGroup({
|
|
122
|
-
className,
|
|
123
|
-
...props
|
|
124
|
-
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
|
125
|
-
return (
|
|
126
|
-
<CommandPrimitive.Group
|
|
127
|
-
data-slot='command-group'
|
|
128
|
-
className={cn(
|
|
129
|
-
'text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium',
|
|
130
|
-
className
|
|
131
|
-
)}
|
|
132
|
-
{...props}
|
|
133
|
-
/>
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Horizontal divider between command groups or items. */
|
|
138
|
-
function CommandSeparator({
|
|
139
|
-
className,
|
|
140
|
-
...props
|
|
141
|
-
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
|
142
|
-
return (
|
|
143
|
-
<CommandPrimitive.Separator
|
|
144
|
-
data-slot='command-separator'
|
|
145
|
-
className={cn('bg-border -mx-1 h-px', className)}
|
|
146
|
-
{...props}
|
|
147
|
-
/>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Selectable command item within a {@link CommandList} or {@link CommandGroup}. */
|
|
152
|
-
function CommandItem({
|
|
153
|
-
className,
|
|
154
|
-
...props
|
|
155
|
-
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
|
156
|
-
return (
|
|
157
|
-
<CommandPrimitive.Item
|
|
158
|
-
data-slot='command-item'
|
|
159
|
-
className={cn(
|
|
160
|
-
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
161
|
-
className
|
|
162
|
-
)}
|
|
163
|
-
{...props}
|
|
164
|
-
/>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Right-aligned keyboard-shortcut hint shown inside a command item. */
|
|
169
|
-
function CommandShortcut({
|
|
170
|
-
className,
|
|
171
|
-
...props
|
|
172
|
-
}: React.ComponentProps<'span'>) {
|
|
173
|
-
return (
|
|
174
|
-
<span
|
|
175
|
-
data-slot='command-shortcut'
|
|
176
|
-
className={cn(
|
|
177
|
-
'text-muted-foreground ml-auto text-xs tracking-widest',
|
|
178
|
-
className
|
|
179
|
-
)}
|
|
180
|
-
{...props}
|
|
181
|
-
/>
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export {
|
|
186
|
-
Command,
|
|
187
|
-
CommandDialog,
|
|
188
|
-
CommandEmpty,
|
|
189
|
-
CommandGroup,
|
|
190
|
-
CommandInput,
|
|
191
|
-
CommandItem,
|
|
192
|
-
CommandList,
|
|
193
|
-
CommandSeparator,
|
|
194
|
-
CommandShortcut,
|
|
195
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const DataTableConfig: ComponentConfig = {
|
|
4
|
-
name: 'Data Table',
|
|
5
|
-
description:
|
|
6
|
-
'A generic, paginated, and sortable table powered by TanStack Table and the Table primitives.',
|
|
7
|
-
category: 'components',
|
|
8
|
-
tags: ['table', 'data', 'tanstack', 'pagination', 'sorting'],
|
|
9
|
-
preview: {
|
|
10
|
-
type: 'static',
|
|
11
|
-
html: '<div class="w-full overflow-hidden rounded-md border border-gray-300 bg-white"><div class="flex border-b border-gray-300 bg-gray-100 px-3 py-2 text-xs font-medium text-gray-600"><span class="flex-1">Name</span><span class="flex-1">Status</span></div><div class="flex px-3 py-2 text-xs text-gray-600"><span class="flex-1">Row 1</span><span class="flex-1">Active</span></div></div>',
|
|
12
|
-
},
|
|
13
|
-
variants: [
|
|
14
|
-
{
|
|
15
|
-
name: 'Default',
|
|
16
|
-
description: 'Default data table with pagination',
|
|
17
|
-
code: '<DataTable columns={columns} data={data} />',
|
|
18
|
-
preview: {
|
|
19
|
-
type: 'component',
|
|
20
|
-
component: 'DataTable',
|
|
21
|
-
props: {},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
dependencies: ['utils', 'primitives'],
|
|
26
|
-
packageDependencies: ['@tanstack/react-table'],
|
|
27
|
-
files: ['components/data-table/index.tsx'],
|
|
28
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Button,
|
|
5
|
-
Table,
|
|
6
|
-
TableBody,
|
|
7
|
-
TableCell,
|
|
8
|
-
TableHead,
|
|
9
|
-
TableHeader,
|
|
10
|
-
TableRow,
|
|
11
|
-
} from '@foundrykit/primitives';
|
|
12
|
-
import {
|
|
13
|
-
type ColumnDef,
|
|
14
|
-
flexRender,
|
|
15
|
-
getCoreRowModel,
|
|
16
|
-
getPaginationRowModel,
|
|
17
|
-
getSortedRowModel,
|
|
18
|
-
type SortingState,
|
|
19
|
-
useReactTable,
|
|
20
|
-
} from '@tanstack/react-table';
|
|
21
|
-
import * as React from 'react';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Generic, paginated, sortable data table driven by TanStack Table column defs.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* <DataTable columns={columns} data={data} />
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
function DataTable<TData, TValue>({
|
|
32
|
-
columns,
|
|
33
|
-
data,
|
|
34
|
-
}: {
|
|
35
|
-
columns: ColumnDef<TData, TValue>[];
|
|
36
|
-
data: TData[];
|
|
37
|
-
}) {
|
|
38
|
-
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
39
|
-
|
|
40
|
-
const table = useReactTable({
|
|
41
|
-
data,
|
|
42
|
-
columns,
|
|
43
|
-
getCoreRowModel: getCoreRowModel(),
|
|
44
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
45
|
-
getSortedRowModel: getSortedRowModel(),
|
|
46
|
-
onSortingChange: setSorting,
|
|
47
|
-
state: {
|
|
48
|
-
sorting,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div data-slot='data-table' className='space-y-4'>
|
|
54
|
-
<div className='rounded-md border'>
|
|
55
|
-
<Table>
|
|
56
|
-
<TableHeader>
|
|
57
|
-
{table.getHeaderGroups().map(headerGroup => (
|
|
58
|
-
<TableRow key={headerGroup.id}>
|
|
59
|
-
{headerGroup.headers.map(header => (
|
|
60
|
-
<TableHead key={header.id}>
|
|
61
|
-
{header.isPlaceholder
|
|
62
|
-
? null
|
|
63
|
-
: flexRender(
|
|
64
|
-
header.column.columnDef.header,
|
|
65
|
-
header.getContext()
|
|
66
|
-
)}
|
|
67
|
-
</TableHead>
|
|
68
|
-
))}
|
|
69
|
-
</TableRow>
|
|
70
|
-
))}
|
|
71
|
-
</TableHeader>
|
|
72
|
-
<TableBody>
|
|
73
|
-
{table.getRowModel().rows?.length ? (
|
|
74
|
-
table.getRowModel().rows.map(row => (
|
|
75
|
-
<TableRow
|
|
76
|
-
key={row.id}
|
|
77
|
-
data-state={row.getIsSelected() && 'selected'}
|
|
78
|
-
>
|
|
79
|
-
{row.getVisibleCells().map(cell => (
|
|
80
|
-
<TableCell key={cell.id}>
|
|
81
|
-
{flexRender(
|
|
82
|
-
cell.column.columnDef.cell,
|
|
83
|
-
cell.getContext()
|
|
84
|
-
)}
|
|
85
|
-
</TableCell>
|
|
86
|
-
))}
|
|
87
|
-
</TableRow>
|
|
88
|
-
))
|
|
89
|
-
) : (
|
|
90
|
-
<TableRow>
|
|
91
|
-
<TableCell
|
|
92
|
-
colSpan={columns.length}
|
|
93
|
-
className='h-24 text-center'
|
|
94
|
-
>
|
|
95
|
-
No results.
|
|
96
|
-
</TableCell>
|
|
97
|
-
</TableRow>
|
|
98
|
-
)}
|
|
99
|
-
</TableBody>
|
|
100
|
-
</Table>
|
|
101
|
-
</div>
|
|
102
|
-
<div className='flex items-center justify-end gap-2'>
|
|
103
|
-
<Button
|
|
104
|
-
variant='outline'
|
|
105
|
-
size='sm'
|
|
106
|
-
onClick={() => table.previousPage()}
|
|
107
|
-
disabled={!table.getCanPreviousPage()}
|
|
108
|
-
>
|
|
109
|
-
Previous
|
|
110
|
-
</Button>
|
|
111
|
-
<Button
|
|
112
|
-
variant='outline'
|
|
113
|
-
size='sm'
|
|
114
|
-
onClick={() => table.nextPage()}
|
|
115
|
-
disabled={!table.getCanNextPage()}
|
|
116
|
-
>
|
|
117
|
-
Next
|
|
118
|
-
</Button>
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export { DataTable };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const datePickerConfig: ComponentConfig = {
|
|
4
|
-
name: 'Date Picker',
|
|
5
|
-
description: 'Date picker component with calendar popup',
|
|
6
|
-
category: 'components',
|
|
7
|
-
tags: ['date', 'picker', 'calendar', 'form'],
|
|
8
|
-
preview: {
|
|
9
|
-
type: 'static',
|
|
10
|
-
html: '<div class="flex h-12 w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3"><div class="h-2 w-16 rounded bg-gray-400"></div><div class="h-2 w-2 rotate-45 border border-gray-400"></div></div>',
|
|
11
|
-
},
|
|
12
|
-
variants: [
|
|
13
|
-
{
|
|
14
|
-
name: 'Default',
|
|
15
|
-
description: 'Default date picker',
|
|
16
|
-
code: '<DatePicker selected={date} onSelect={setDate} />',
|
|
17
|
-
preview: {
|
|
18
|
-
type: 'component',
|
|
19
|
-
component: 'DatePicker',
|
|
20
|
-
props: { selected: new Date(), onSelect: () => {} },
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'With Placeholder',
|
|
25
|
-
description: 'Date picker with custom placeholder',
|
|
26
|
-
code: '<DatePicker placeholder="Select date..." selected={date} onSelect={setDate} />',
|
|
27
|
-
preview: {
|
|
28
|
-
type: 'component',
|
|
29
|
-
component: 'DatePicker',
|
|
30
|
-
props: {
|
|
31
|
-
placeholder: 'Select date...',
|
|
32
|
-
selected: new Date(),
|
|
33
|
-
onSelect: () => {},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'Range',
|
|
39
|
-
description: 'Date range picker',
|
|
40
|
-
code: '<DatePicker mode="range" selected={dateRange} onSelect={setDateRange} />',
|
|
41
|
-
preview: {
|
|
42
|
-
type: 'component',
|
|
43
|
-
component: 'DatePicker',
|
|
44
|
-
props: {
|
|
45
|
-
mode: 'range',
|
|
46
|
-
selected: { from: new Date(), to: new Date() },
|
|
47
|
-
onSelect: () => {},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
dependencies: ['utils', 'button', 'input'],
|
|
53
|
-
packageDependencies: ['date-fns', 'lucide-react'],
|
|
54
|
-
files: ['components/date-picker/index.tsx'],
|
|
55
|
-
};
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Button, Input } from '@foundrykit/primitives';
|
|
4
|
-
import { cn } from '@foundrykit/utils';
|
|
5
|
-
import { format } from 'date-fns';
|
|
6
|
-
import { Calendar as CalendarIcon } from 'lucide-react';
|
|
7
|
-
import * as React from 'react';
|
|
8
|
-
|
|
9
|
-
export interface DatePickerProps {
|
|
10
|
-
value?: Date;
|
|
11
|
-
onValueChange?: (date: Date | undefined) => void;
|
|
12
|
-
placeholder?: string;
|
|
13
|
-
className?: string;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const WEEK_DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Date picker pairing a native date input with a pop-up month grid. Controlled
|
|
21
|
-
* via `value`/`onValueChange`; the calendar closes on selection, outside click,
|
|
22
|
-
* or Escape and returns focus to the toggle button.
|
|
23
|
-
*/
|
|
24
|
-
const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
|
25
|
-
(
|
|
26
|
-
{ value, onValueChange, placeholder = 'Pick a date', className, disabled },
|
|
27
|
-
ref
|
|
28
|
-
) => {
|
|
29
|
-
const [open, setOpen] = React.useState(false);
|
|
30
|
-
const [selectedDate, setSelectedDate] = React.useState<Date | undefined>(
|
|
31
|
-
value
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// Keep internal state in sync with the controlled `value` prop so a parent
|
|
35
|
-
// that changes `value` after mount is respected (previously ignored).
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
setSelectedDate(value);
|
|
38
|
-
}, [value]);
|
|
39
|
-
|
|
40
|
-
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
41
|
-
const toggleRef = React.useRef<HTMLButtonElement>(null);
|
|
42
|
-
// Merge the forwarded ref with our internal container ref.
|
|
43
|
-
React.useImperativeHandle(
|
|
44
|
-
ref,
|
|
45
|
-
() => containerRef.current as HTMLDivElement
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// Dismiss on outside click and on Escape; restore focus to the toggle when
|
|
49
|
-
// closing via keyboard.
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
if (!open) return;
|
|
52
|
-
|
|
53
|
-
const onPointerDown = (e: MouseEvent) => {
|
|
54
|
-
if (!containerRef.current?.contains(e.target as Node)) setOpen(false);
|
|
55
|
-
};
|
|
56
|
-
const onKeyDown = (e: KeyboardEvent) => {
|
|
57
|
-
if (e.key === 'Escape') {
|
|
58
|
-
setOpen(false);
|
|
59
|
-
toggleRef.current?.focus();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
document.addEventListener('mousedown', onPointerDown);
|
|
64
|
-
document.addEventListener('keydown', onKeyDown);
|
|
65
|
-
return () => {
|
|
66
|
-
document.removeEventListener('mousedown', onPointerDown);
|
|
67
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
68
|
-
};
|
|
69
|
-
}, [open]);
|
|
70
|
-
|
|
71
|
-
const handleDateSelect = (date: Date) => {
|
|
72
|
-
setSelectedDate(date);
|
|
73
|
-
onValueChange?.(date);
|
|
74
|
-
setOpen(false);
|
|
75
|
-
toggleRef.current?.focus();
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
79
|
-
const inputValue = e.target.value;
|
|
80
|
-
if (inputValue) {
|
|
81
|
-
const date = new Date(inputValue);
|
|
82
|
-
if (!isNaN(date.getTime())) {
|
|
83
|
-
setSelectedDate(date);
|
|
84
|
-
onValueChange?.(date);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
setSelectedDate(undefined);
|
|
88
|
-
onValueChange?.(undefined);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const viewDate = selectedDate ?? new Date();
|
|
93
|
-
const currentMonth = viewDate.getMonth();
|
|
94
|
-
const currentYear = viewDate.getFullYear();
|
|
95
|
-
const monthLabel = format(viewDate, 'MMMM yyyy');
|
|
96
|
-
|
|
97
|
-
const calendarDays = React.useMemo(() => {
|
|
98
|
-
const firstDay = new Date(currentYear, currentMonth, 1);
|
|
99
|
-
const daysInMonth = new Date(currentYear, currentMonth + 1, 0).getDate();
|
|
100
|
-
const startingDayOfWeek = firstDay.getDay();
|
|
101
|
-
|
|
102
|
-
const days: (Date | null)[] = [];
|
|
103
|
-
for (let i = 0; i < startingDayOfWeek; i++) days.push(null);
|
|
104
|
-
for (let day = 1; day <= daysInMonth; day++) {
|
|
105
|
-
days.push(new Date(currentYear, currentMonth, day));
|
|
106
|
-
}
|
|
107
|
-
return days;
|
|
108
|
-
}, [currentMonth, currentYear]);
|
|
109
|
-
|
|
110
|
-
const today = new Date();
|
|
111
|
-
const dialogId = React.useId();
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<div className={cn('relative', className)} ref={containerRef}>
|
|
115
|
-
<div className='flex gap-2'>
|
|
116
|
-
<Input
|
|
117
|
-
type='date'
|
|
118
|
-
value={selectedDate ? format(selectedDate, 'yyyy-MM-dd') : ''}
|
|
119
|
-
onChange={handleInputChange}
|
|
120
|
-
placeholder={placeholder}
|
|
121
|
-
disabled={disabled}
|
|
122
|
-
className='flex-1'
|
|
123
|
-
/>
|
|
124
|
-
<Button
|
|
125
|
-
ref={toggleRef}
|
|
126
|
-
type='button'
|
|
127
|
-
variant='outline'
|
|
128
|
-
onClick={() => setOpen(!open)}
|
|
129
|
-
disabled={disabled}
|
|
130
|
-
className='px-3'
|
|
131
|
-
aria-label={
|
|
132
|
-
selectedDate
|
|
133
|
-
? `Change date, currently ${format(selectedDate, 'PPP')}`
|
|
134
|
-
: 'Choose date'
|
|
135
|
-
}
|
|
136
|
-
aria-haspopup='dialog'
|
|
137
|
-
aria-expanded={open}
|
|
138
|
-
aria-controls={open ? dialogId : undefined}
|
|
139
|
-
>
|
|
140
|
-
<CalendarIcon className='h-4 w-4' />
|
|
141
|
-
</Button>
|
|
142
|
-
</div>
|
|
143
|
-
|
|
144
|
-
{open && (
|
|
145
|
-
<div
|
|
146
|
-
id={dialogId}
|
|
147
|
-
role='dialog'
|
|
148
|
-
aria-label={`Choose date, ${monthLabel}`}
|
|
149
|
-
className='bg-popover absolute top-full z-50 mt-1 w-80 rounded-md border p-3 shadow-md'
|
|
150
|
-
>
|
|
151
|
-
<div
|
|
152
|
-
aria-hidden='true'
|
|
153
|
-
className='text-foreground mb-2 text-center text-sm font-semibold'
|
|
154
|
-
>
|
|
155
|
-
{monthLabel}
|
|
156
|
-
</div>
|
|
157
|
-
<div
|
|
158
|
-
className='mb-2 grid grid-cols-7 gap-1 text-center text-sm font-medium'
|
|
159
|
-
aria-hidden='true'
|
|
160
|
-
>
|
|
161
|
-
{WEEK_DAYS.map(day => (
|
|
162
|
-
<div key={day} className='p-1'>
|
|
163
|
-
{day}
|
|
164
|
-
</div>
|
|
165
|
-
))}
|
|
166
|
-
</div>
|
|
167
|
-
<div role='grid' className='grid grid-cols-7 gap-1'>
|
|
168
|
-
{calendarDays.map((day, index) => {
|
|
169
|
-
if (!day) {
|
|
170
|
-
return <div key={`empty-${index}`} role='presentation' />;
|
|
171
|
-
}
|
|
172
|
-
const isSelected =
|
|
173
|
-
selectedDate &&
|
|
174
|
-
day.toDateString() === selectedDate.toDateString();
|
|
175
|
-
const isToday = day.toDateString() === today.toDateString();
|
|
176
|
-
return (
|
|
177
|
-
<button
|
|
178
|
-
key={day.toDateString()}
|
|
179
|
-
type='button'
|
|
180
|
-
aria-label={format(day, 'PPPP')}
|
|
181
|
-
aria-pressed={isSelected}
|
|
182
|
-
aria-current={isToday ? 'date' : undefined}
|
|
183
|
-
className={cn(
|
|
184
|
-
'hover:bg-accent hover:text-accent-foreground rounded p-2 text-sm',
|
|
185
|
-
isSelected
|
|
186
|
-
? 'bg-primary text-primary-foreground'
|
|
187
|
-
: isToday
|
|
188
|
-
? 'bg-muted'
|
|
189
|
-
: 'text-muted-foreground'
|
|
190
|
-
)}
|
|
191
|
-
onClick={() => handleDateSelect(day)}
|
|
192
|
-
>
|
|
193
|
-
{day.getDate()}
|
|
194
|
-
</button>
|
|
195
|
-
);
|
|
196
|
-
})}
|
|
197
|
-
</div>
|
|
198
|
-
</div>
|
|
199
|
-
)}
|
|
200
|
-
</div>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
DatePicker.displayName = 'DatePicker';
|
|
206
|
-
|
|
207
|
-
export { DatePicker };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const formConfig: ComponentConfig = {
|
|
4
|
-
name: 'Form',
|
|
5
|
-
description: 'Form component for collecting user input',
|
|
6
|
-
category: 'components',
|
|
7
|
-
tags: ['form', 'input', 'interactive'],
|
|
8
|
-
preview: {
|
|
9
|
-
type: 'static',
|
|
10
|
-
html: '<div class="flex h-12 w-full items-center justify-center rounded-md bg-gray-200"><div class="relative w-32"><div class="flex h-9 w-full items-center justify-between rounded-md border border-gray-300 bg-white px-3 py-2 text-sm"><span>Select option</span><div class="h-4 w-4 rotate-90 border border-gray-400"></div></div></div></div>',
|
|
11
|
-
},
|
|
12
|
-
variants: [],
|
|
13
|
-
files: ['components/form/index.tsx'],
|
|
14
|
-
dependencies: ['utils', 'hooks', 'label'],
|
|
15
|
-
packageDependencies: [
|
|
16
|
-
'react-hook-form',
|
|
17
|
-
'zod',
|
|
18
|
-
'@radix-ui/react-slot',
|
|
19
|
-
'@radix-ui/react-label',
|
|
20
|
-
],
|
|
21
|
-
};
|