@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,51 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const calendarConfig: ComponentConfig = {
|
|
4
|
-
name: 'Calendar',
|
|
5
|
-
description: 'Date picker calendar component',
|
|
6
|
-
category: 'components',
|
|
7
|
-
tags: ['calendar', 'date', 'picker'],
|
|
8
|
-
preview: {
|
|
9
|
-
type: 'static',
|
|
10
|
-
html: '<div class="flex h-12 w-full flex-col justify-center rounded-md border border-gray-300 bg-white p-2"><div class="mb-1 flex items-center justify-between"><div class="h-2 w-2 rotate-45 border border-gray-400"></div><div class="h-2 w-2 -rotate-45 border border-gray-400"></div></div><div class="grid grid-cols-7 gap-1"><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div><div class="h-1.5 w-1.5 rounded bg-gray-200"></div></div></div>',
|
|
11
|
-
},
|
|
12
|
-
variants: [
|
|
13
|
-
{
|
|
14
|
-
name: 'Default',
|
|
15
|
-
description: 'Default calendar view',
|
|
16
|
-
code: '<Calendar mode="single" selected={date} onSelect={setDate} />',
|
|
17
|
-
preview: {
|
|
18
|
-
type: 'component',
|
|
19
|
-
component: 'Calendar',
|
|
20
|
-
props: { mode: 'single', selected: new Date(), onSelect: () => {} },
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'Range',
|
|
25
|
-
description: 'Calendar with date range selection',
|
|
26
|
-
code: '<Calendar mode="range" selected={dateRange} onSelect={setDateRange} />',
|
|
27
|
-
preview: {
|
|
28
|
-
type: 'component',
|
|
29
|
-
component: 'Calendar',
|
|
30
|
-
props: {
|
|
31
|
-
mode: 'range',
|
|
32
|
-
selected: { from: new Date(), to: new Date() },
|
|
33
|
-
onSelect: () => {},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'Multiple',
|
|
39
|
-
description: 'Calendar with multiple date selection',
|
|
40
|
-
code: '<Calendar mode="multiple" selected={dates} onSelect={setDates} />',
|
|
41
|
-
preview: {
|
|
42
|
-
type: 'component',
|
|
43
|
-
component: 'Calendar',
|
|
44
|
-
props: { mode: 'multiple', selected: [new Date()], onSelect: () => {} },
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
dependencies: ['button', 'utils'],
|
|
49
|
-
packageDependencies: ['react-day-picker'],
|
|
50
|
-
files: ['components/calendar/index.tsx'],
|
|
51
|
-
};
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Button, buttonVariants } from '@foundrykit/primitives';
|
|
4
|
-
import { cn } from '@foundrykit/utils';
|
|
5
|
-
import {
|
|
6
|
-
ChevronDownIcon,
|
|
7
|
-
ChevronLeftIcon,
|
|
8
|
-
ChevronRightIcon,
|
|
9
|
-
} from 'lucide-react';
|
|
10
|
-
import * as React from 'react';
|
|
11
|
-
import {
|
|
12
|
-
type DayButton,
|
|
13
|
-
DayPicker,
|
|
14
|
-
getDefaultClassNames,
|
|
15
|
-
} from 'react-day-picker';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Themed wrapper around `react-day-picker`'s `DayPicker`, styled with FoundryKit
|
|
19
|
-
* design tokens. Accepts all `DayPicker` props (`mode`, `selected`, `onSelect`,
|
|
20
|
-
* etc.) plus `buttonVariant` to control the nav button style.
|
|
21
|
-
*/
|
|
22
|
-
function Calendar({
|
|
23
|
-
className,
|
|
24
|
-
classNames,
|
|
25
|
-
showOutsideDays = true,
|
|
26
|
-
captionLayout = 'label',
|
|
27
|
-
buttonVariant = 'ghost',
|
|
28
|
-
formatters,
|
|
29
|
-
components,
|
|
30
|
-
...props
|
|
31
|
-
}: React.ComponentProps<typeof DayPicker> & {
|
|
32
|
-
buttonVariant?: React.ComponentProps<typeof Button>['variant'];
|
|
33
|
-
}) {
|
|
34
|
-
const defaultClassNames = getDefaultClassNames();
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<DayPicker
|
|
38
|
-
showOutsideDays={showOutsideDays}
|
|
39
|
-
className={cn(
|
|
40
|
-
'bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent',
|
|
41
|
-
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
|
42
|
-
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
|
43
|
-
className
|
|
44
|
-
)}
|
|
45
|
-
captionLayout={captionLayout}
|
|
46
|
-
formatters={{
|
|
47
|
-
formatMonthDropdown: date =>
|
|
48
|
-
date.toLocaleString('default', { month: 'short' }),
|
|
49
|
-
...formatters,
|
|
50
|
-
}}
|
|
51
|
-
classNames={{
|
|
52
|
-
root: cn('w-fit', defaultClassNames.root),
|
|
53
|
-
months: cn(
|
|
54
|
-
'relative flex flex-col gap-4 md:flex-row',
|
|
55
|
-
defaultClassNames.months
|
|
56
|
-
),
|
|
57
|
-
month: cn('flex w-full flex-col gap-4', defaultClassNames.month),
|
|
58
|
-
nav: cn(
|
|
59
|
-
'absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1',
|
|
60
|
-
defaultClassNames.nav
|
|
61
|
-
),
|
|
62
|
-
button_previous: cn(
|
|
63
|
-
buttonVariants({ variant: buttonVariant }),
|
|
64
|
-
'size-(--cell-size) p-0 select-none aria-disabled:opacity-50',
|
|
65
|
-
defaultClassNames.button_previous
|
|
66
|
-
),
|
|
67
|
-
button_next: cn(
|
|
68
|
-
buttonVariants({ variant: buttonVariant }),
|
|
69
|
-
'size-(--cell-size) p-0 select-none aria-disabled:opacity-50',
|
|
70
|
-
defaultClassNames.button_next
|
|
71
|
-
),
|
|
72
|
-
month_caption: cn(
|
|
73
|
-
'flex h-(--cell-size) w-full items-center justify-center px-(--cell-size)',
|
|
74
|
-
defaultClassNames.month_caption
|
|
75
|
-
),
|
|
76
|
-
dropdowns: cn(
|
|
77
|
-
'flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium',
|
|
78
|
-
defaultClassNames.dropdowns
|
|
79
|
-
),
|
|
80
|
-
dropdown_root: cn(
|
|
81
|
-
'has-focus:border-ring border-input has-focus:ring-ring/50 relative rounded-md border shadow-xs has-focus:ring-[3px]',
|
|
82
|
-
defaultClassNames.dropdown_root
|
|
83
|
-
),
|
|
84
|
-
dropdown: cn(
|
|
85
|
-
'bg-popover absolute inset-0 opacity-0',
|
|
86
|
-
defaultClassNames.dropdown
|
|
87
|
-
),
|
|
88
|
-
caption_label: cn(
|
|
89
|
-
'font-medium select-none',
|
|
90
|
-
captionLayout === 'label'
|
|
91
|
-
? 'text-sm'
|
|
92
|
-
: '[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pr-1 pl-2 text-sm [&>svg]:size-3.5',
|
|
93
|
-
defaultClassNames.caption_label
|
|
94
|
-
),
|
|
95
|
-
table: 'w-full border-collapse',
|
|
96
|
-
weekdays: cn('flex', defaultClassNames.weekdays),
|
|
97
|
-
weekday: cn(
|
|
98
|
-
'text-muted-foreground flex-1 rounded-md text-[0.8rem] font-normal select-none',
|
|
99
|
-
defaultClassNames.weekday
|
|
100
|
-
),
|
|
101
|
-
week: cn('mt-2 flex w-full', defaultClassNames.week),
|
|
102
|
-
week_number_header: cn(
|
|
103
|
-
'w-(--cell-size) select-none',
|
|
104
|
-
defaultClassNames.week_number_header
|
|
105
|
-
),
|
|
106
|
-
week_number: cn(
|
|
107
|
-
'text-muted-foreground text-[0.8rem] select-none',
|
|
108
|
-
defaultClassNames.week_number
|
|
109
|
-
),
|
|
110
|
-
day: cn(
|
|
111
|
-
'group/day relative aspect-square h-full w-full p-0 text-center select-none [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md',
|
|
112
|
-
defaultClassNames.day
|
|
113
|
-
),
|
|
114
|
-
range_start: cn(
|
|
115
|
-
'bg-accent rounded-l-md',
|
|
116
|
-
defaultClassNames.range_start
|
|
117
|
-
),
|
|
118
|
-
range_middle: cn('rounded-none', defaultClassNames.range_middle),
|
|
119
|
-
range_end: cn('bg-accent rounded-r-md', defaultClassNames.range_end),
|
|
120
|
-
today: cn(
|
|
121
|
-
'bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none',
|
|
122
|
-
defaultClassNames.today
|
|
123
|
-
),
|
|
124
|
-
outside: cn(
|
|
125
|
-
'text-muted-foreground aria-selected:text-muted-foreground',
|
|
126
|
-
defaultClassNames.outside
|
|
127
|
-
),
|
|
128
|
-
disabled: cn(
|
|
129
|
-
'text-muted-foreground opacity-50',
|
|
130
|
-
defaultClassNames.disabled
|
|
131
|
-
),
|
|
132
|
-
hidden: cn('invisible', defaultClassNames.hidden),
|
|
133
|
-
...classNames,
|
|
134
|
-
}}
|
|
135
|
-
components={{
|
|
136
|
-
Root: ({ className, rootRef, ...props }) => {
|
|
137
|
-
return (
|
|
138
|
-
<div
|
|
139
|
-
data-slot='calendar'
|
|
140
|
-
ref={rootRef}
|
|
141
|
-
className={cn(className)}
|
|
142
|
-
{...props}
|
|
143
|
-
/>
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
Chevron: ({ className, orientation, ...props }) => {
|
|
147
|
-
if (orientation === 'left') {
|
|
148
|
-
return (
|
|
149
|
-
<ChevronLeftIcon className={cn('size-4', className)} {...props} />
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (orientation === 'right') {
|
|
154
|
-
return (
|
|
155
|
-
<ChevronRightIcon
|
|
156
|
-
className={cn('size-4', className)}
|
|
157
|
-
{...props}
|
|
158
|
-
/>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<ChevronDownIcon className={cn('size-4', className)} {...props} />
|
|
164
|
-
);
|
|
165
|
-
},
|
|
166
|
-
DayButton: CalendarDayButton,
|
|
167
|
-
WeekNumber: ({ children, ...props }) => {
|
|
168
|
-
return (
|
|
169
|
-
<td {...props}>
|
|
170
|
-
<div className='flex size-(--cell-size) items-center justify-center text-center'>
|
|
171
|
-
{children}
|
|
172
|
-
</div>
|
|
173
|
-
</td>
|
|
174
|
-
);
|
|
175
|
-
},
|
|
176
|
-
...components,
|
|
177
|
-
}}
|
|
178
|
-
{...props}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Individual day cell button used by {@link Calendar}. Applies selected/range
|
|
185
|
-
* data attributes for styling and auto-focuses when the day is focused.
|
|
186
|
-
*/
|
|
187
|
-
function CalendarDayButton({
|
|
188
|
-
className,
|
|
189
|
-
day,
|
|
190
|
-
modifiers,
|
|
191
|
-
...props
|
|
192
|
-
}: React.ComponentProps<typeof DayButton>) {
|
|
193
|
-
const defaultClassNames = getDefaultClassNames();
|
|
194
|
-
|
|
195
|
-
const ref = React.useRef<HTMLButtonElement>(null);
|
|
196
|
-
React.useEffect(() => {
|
|
197
|
-
if (modifiers.focused) ref.current?.focus();
|
|
198
|
-
}, [modifiers.focused]);
|
|
199
|
-
|
|
200
|
-
return (
|
|
201
|
-
<Button
|
|
202
|
-
ref={ref}
|
|
203
|
-
variant='ghost'
|
|
204
|
-
size='icon'
|
|
205
|
-
data-day={day.date.toLocaleDateString()}
|
|
206
|
-
data-selected-single={
|
|
207
|
-
modifiers.selected &&
|
|
208
|
-
!modifiers.range_start &&
|
|
209
|
-
!modifiers.range_end &&
|
|
210
|
-
!modifiers.range_middle
|
|
211
|
-
}
|
|
212
|
-
data-range-start={modifiers.range_start}
|
|
213
|
-
data-range-end={modifiers.range_end}
|
|
214
|
-
data-range-middle={modifiers.range_middle}
|
|
215
|
-
className={cn(
|
|
216
|
-
'data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70',
|
|
217
|
-
defaultClassNames.day,
|
|
218
|
-
className
|
|
219
|
-
)}
|
|
220
|
-
{...props}
|
|
221
|
-
/>
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export { Calendar, CalendarDayButton };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const CarouselConfig: ComponentConfig = {
|
|
4
|
-
name: 'Carousel',
|
|
5
|
-
description:
|
|
6
|
-
'A slideshow component for cycling through elements, built on Embla Carousel.',
|
|
7
|
-
category: 'components',
|
|
8
|
-
tags: ['carousel', 'slider', 'gallery', 'interactive', 'embla'],
|
|
9
|
-
preview: {
|
|
10
|
-
type: 'static',
|
|
11
|
-
html: '<div class="flex h-24 w-full items-center justify-center gap-2 rounded-md border border-gray-300 bg-gray-100"><div class="flex h-8 w-8 items-center justify-center rounded-full border border-gray-300 bg-white text-gray-600">‹</div><div class="flex h-16 w-32 items-center justify-center rounded-md border border-gray-300 bg-white text-sm text-gray-600">Slide</div><div class="flex h-8 w-8 items-center justify-center rounded-full border border-gray-300 bg-white text-gray-600">›</div></div>',
|
|
12
|
-
},
|
|
13
|
-
variants: [
|
|
14
|
-
{
|
|
15
|
-
name: 'Default',
|
|
16
|
-
description: 'Default horizontal carousel',
|
|
17
|
-
code: '<Carousel><CarouselContent><CarouselItem>...</CarouselItem></CarouselContent><CarouselPrevious /><CarouselNext /></Carousel>',
|
|
18
|
-
preview: {
|
|
19
|
-
type: 'component',
|
|
20
|
-
component: 'Carousel',
|
|
21
|
-
props: {},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
dependencies: ['utils', 'primitives'],
|
|
26
|
-
packageDependencies: ['embla-carousel-react', 'lucide-react'],
|
|
27
|
-
files: ['components/carousel/index.tsx'],
|
|
28
|
-
};
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Button } from '@foundrykit/primitives';
|
|
4
|
-
import { cn } from '@foundrykit/utils';
|
|
5
|
-
import useEmblaCarousel, {
|
|
6
|
-
type UseEmblaCarouselType,
|
|
7
|
-
} from 'embla-carousel-react';
|
|
8
|
-
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react';
|
|
9
|
-
import * as React from 'react';
|
|
10
|
-
|
|
11
|
-
type CarouselApi = UseEmblaCarouselType[1];
|
|
12
|
-
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
13
|
-
type CarouselOptions = UseCarouselParameters[0];
|
|
14
|
-
type CarouselPlugin = UseCarouselParameters[1];
|
|
15
|
-
|
|
16
|
-
type CarouselProps = {
|
|
17
|
-
opts?: CarouselOptions;
|
|
18
|
-
plugins?: CarouselPlugin;
|
|
19
|
-
orientation?: 'horizontal' | 'vertical';
|
|
20
|
-
setApi?: (api: CarouselApi) => void;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type CarouselContextProps = {
|
|
24
|
-
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
25
|
-
api: ReturnType<typeof useEmblaCarousel>[1];
|
|
26
|
-
scrollPrev: () => void;
|
|
27
|
-
scrollNext: () => void;
|
|
28
|
-
canScrollPrev: boolean;
|
|
29
|
-
canScrollNext: boolean;
|
|
30
|
-
} & CarouselProps;
|
|
31
|
-
|
|
32
|
-
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
33
|
-
|
|
34
|
-
function useCarousel() {
|
|
35
|
-
const context = React.useContext(CarouselContext);
|
|
36
|
-
|
|
37
|
-
if (!context) {
|
|
38
|
-
throw new Error('useCarousel must be used within a <Carousel />');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return context;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Carousel root that provides Embla state to its parts.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```tsx
|
|
49
|
-
* <Carousel>
|
|
50
|
-
* <CarouselContent>
|
|
51
|
-
* <CarouselItem>Slide 1</CarouselItem>
|
|
52
|
-
* </CarouselContent>
|
|
53
|
-
* <CarouselPrevious />
|
|
54
|
-
* <CarouselNext />
|
|
55
|
-
* </Carousel>
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
function Carousel({
|
|
59
|
-
orientation = 'horizontal',
|
|
60
|
-
opts,
|
|
61
|
-
setApi,
|
|
62
|
-
plugins,
|
|
63
|
-
className,
|
|
64
|
-
children,
|
|
65
|
-
...props
|
|
66
|
-
}: React.ComponentProps<'div'> & CarouselProps) {
|
|
67
|
-
const [carouselRef, api] = useEmblaCarousel(
|
|
68
|
-
{
|
|
69
|
-
...opts,
|
|
70
|
-
axis: orientation === 'horizontal' ? 'x' : 'y',
|
|
71
|
-
},
|
|
72
|
-
plugins
|
|
73
|
-
);
|
|
74
|
-
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
75
|
-
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
76
|
-
|
|
77
|
-
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
78
|
-
if (!api) return;
|
|
79
|
-
setCanScrollPrev(api.canScrollPrev());
|
|
80
|
-
setCanScrollNext(api.canScrollNext());
|
|
81
|
-
}, []);
|
|
82
|
-
|
|
83
|
-
const scrollPrev = React.useCallback(() => {
|
|
84
|
-
api?.scrollPrev();
|
|
85
|
-
}, [api]);
|
|
86
|
-
|
|
87
|
-
const scrollNext = React.useCallback(() => {
|
|
88
|
-
api?.scrollNext();
|
|
89
|
-
}, [api]);
|
|
90
|
-
|
|
91
|
-
const handleKeyDown = React.useCallback(
|
|
92
|
-
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
93
|
-
if (event.key === 'ArrowLeft') {
|
|
94
|
-
event.preventDefault();
|
|
95
|
-
scrollPrev();
|
|
96
|
-
} else if (event.key === 'ArrowRight') {
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
scrollNext();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
[scrollPrev, scrollNext]
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
if (!api || !setApi) return;
|
|
106
|
-
setApi(api);
|
|
107
|
-
}, [api, setApi]);
|
|
108
|
-
|
|
109
|
-
React.useEffect(() => {
|
|
110
|
-
if (!api) return;
|
|
111
|
-
onSelect(api);
|
|
112
|
-
api.on('reInit', onSelect);
|
|
113
|
-
api.on('select', onSelect);
|
|
114
|
-
|
|
115
|
-
return () => {
|
|
116
|
-
api?.off('select', onSelect);
|
|
117
|
-
};
|
|
118
|
-
}, [api, onSelect]);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<CarouselContext.Provider
|
|
122
|
-
value={{
|
|
123
|
-
carouselRef,
|
|
124
|
-
api,
|
|
125
|
-
opts,
|
|
126
|
-
orientation:
|
|
127
|
-
orientation || (opts?.axis === 'y' ? 'vertical' : 'horizontal'),
|
|
128
|
-
scrollPrev,
|
|
129
|
-
scrollNext,
|
|
130
|
-
canScrollPrev,
|
|
131
|
-
canScrollNext,
|
|
132
|
-
}}
|
|
133
|
-
>
|
|
134
|
-
<div
|
|
135
|
-
data-slot='carousel'
|
|
136
|
-
onKeyDownCapture={handleKeyDown}
|
|
137
|
-
className={cn('relative', className)}
|
|
138
|
-
role='region'
|
|
139
|
-
aria-roledescription='carousel'
|
|
140
|
-
{...props}
|
|
141
|
-
>
|
|
142
|
-
{children}
|
|
143
|
-
</div>
|
|
144
|
-
</CarouselContext.Provider>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** Scrollable track that holds the carousel items. */
|
|
149
|
-
function CarouselContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
150
|
-
const { carouselRef, orientation } = useCarousel();
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<div
|
|
154
|
-
ref={carouselRef}
|
|
155
|
-
data-slot='carousel-content'
|
|
156
|
-
className='overflow-hidden'
|
|
157
|
-
>
|
|
158
|
-
<div
|
|
159
|
-
className={cn(
|
|
160
|
-
'flex',
|
|
161
|
-
orientation === 'horizontal' ? '-ml-4' : '-mt-4 flex-col',
|
|
162
|
-
className
|
|
163
|
-
)}
|
|
164
|
-
{...props}
|
|
165
|
-
/>
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** A single slide within a {@link CarouselContent}. */
|
|
171
|
-
function CarouselItem({ className, ...props }: React.ComponentProps<'div'>) {
|
|
172
|
-
const { orientation } = useCarousel();
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
<div
|
|
176
|
-
data-slot='carousel-item'
|
|
177
|
-
role='group'
|
|
178
|
-
aria-roledescription='slide'
|
|
179
|
-
className={cn(
|
|
180
|
-
'min-w-0 shrink-0 grow-0 basis-full',
|
|
181
|
-
orientation === 'horizontal' ? 'pl-4' : 'pt-4',
|
|
182
|
-
className
|
|
183
|
-
)}
|
|
184
|
-
{...props}
|
|
185
|
-
/>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** Button that scrolls the carousel to the previous slide. */
|
|
190
|
-
function CarouselPrevious({
|
|
191
|
-
className,
|
|
192
|
-
variant = 'outline',
|
|
193
|
-
size = 'icon',
|
|
194
|
-
...props
|
|
195
|
-
}: React.ComponentProps<typeof Button>) {
|
|
196
|
-
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<Button
|
|
200
|
-
data-slot='carousel-previous'
|
|
201
|
-
variant={variant}
|
|
202
|
-
size={size}
|
|
203
|
-
className={cn(
|
|
204
|
-
'absolute size-8 rounded-full',
|
|
205
|
-
orientation === 'horizontal'
|
|
206
|
-
? 'top-1/2 -left-12 -translate-y-1/2'
|
|
207
|
-
: '-top-12 left-1/2 -translate-x-1/2 rotate-90',
|
|
208
|
-
className
|
|
209
|
-
)}
|
|
210
|
-
disabled={!canScrollPrev}
|
|
211
|
-
onClick={scrollPrev}
|
|
212
|
-
{...props}
|
|
213
|
-
>
|
|
214
|
-
<ArrowLeftIcon />
|
|
215
|
-
<span className='sr-only'>Previous slide</span>
|
|
216
|
-
</Button>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Button that scrolls the carousel to the next slide. */
|
|
221
|
-
function CarouselNext({
|
|
222
|
-
className,
|
|
223
|
-
variant = 'outline',
|
|
224
|
-
size = 'icon',
|
|
225
|
-
...props
|
|
226
|
-
}: React.ComponentProps<typeof Button>) {
|
|
227
|
-
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
228
|
-
|
|
229
|
-
return (
|
|
230
|
-
<Button
|
|
231
|
-
data-slot='carousel-next'
|
|
232
|
-
variant={variant}
|
|
233
|
-
size={size}
|
|
234
|
-
className={cn(
|
|
235
|
-
'absolute size-8 rounded-full',
|
|
236
|
-
orientation === 'horizontal'
|
|
237
|
-
? 'top-1/2 -right-12 -translate-y-1/2'
|
|
238
|
-
: '-bottom-12 left-1/2 -translate-x-1/2 rotate-90',
|
|
239
|
-
className
|
|
240
|
-
)}
|
|
241
|
-
disabled={!canScrollNext}
|
|
242
|
-
onClick={scrollNext}
|
|
243
|
-
{...props}
|
|
244
|
-
>
|
|
245
|
-
<ArrowRightIcon />
|
|
246
|
-
<span className='sr-only'>Next slide</span>
|
|
247
|
-
</Button>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export {
|
|
252
|
-
Carousel,
|
|
253
|
-
type CarouselApi,
|
|
254
|
-
CarouselContent,
|
|
255
|
-
CarouselItem,
|
|
256
|
-
CarouselNext,
|
|
257
|
-
CarouselPrevious,
|
|
258
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ComponentConfig } from '@foundrykit/types';
|
|
2
|
-
|
|
3
|
-
export const ChartConfig: ComponentConfig = {
|
|
4
|
-
name: 'Chart',
|
|
5
|
-
description:
|
|
6
|
-
'A set of composable chart primitives built on Recharts with themeable colors, tooltips, and legends.',
|
|
7
|
-
category: 'components',
|
|
8
|
-
tags: ['chart', 'graph', 'recharts', 'data', 'visualization'],
|
|
9
|
-
preview: {
|
|
10
|
-
type: 'static',
|
|
11
|
-
html: '<div class="flex h-24 w-full items-end justify-center gap-2 rounded-md border border-gray-300 bg-gray-100 p-3"><div class="h-8 w-4 rounded-sm bg-gray-400"></div><div class="h-16 w-4 rounded-sm bg-gray-500"></div><div class="h-12 w-4 rounded-sm bg-gray-400"></div><div class="h-20 w-4 rounded-sm bg-gray-600"></div></div>',
|
|
12
|
-
},
|
|
13
|
-
variants: [
|
|
14
|
-
{
|
|
15
|
-
name: 'Default',
|
|
16
|
-
description: 'A bar chart rendered inside a ChartContainer',
|
|
17
|
-
code: '<ChartContainer config={config}><BarChart data={data}><Bar dataKey="total" /></BarChart></ChartContainer>',
|
|
18
|
-
preview: {
|
|
19
|
-
type: 'component',
|
|
20
|
-
component: 'ChartContainer',
|
|
21
|
-
props: {},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
dependencies: ['utils'],
|
|
26
|
-
packageDependencies: ['recharts'],
|
|
27
|
-
files: ['components/chart/index.tsx'],
|
|
28
|
-
};
|