@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/components/data-table/index.tsx
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Table,
|
|
7
|
+
TableBody,
|
|
8
|
+
TableCell,
|
|
9
|
+
TableHead,
|
|
10
|
+
TableHeader,
|
|
11
|
+
TableRow
|
|
12
|
+
} from "@foundrykit/primitives";
|
|
13
|
+
import {
|
|
14
|
+
flexRender,
|
|
15
|
+
getCoreRowModel,
|
|
16
|
+
getPaginationRowModel,
|
|
17
|
+
getSortedRowModel,
|
|
18
|
+
useReactTable
|
|
19
|
+
} from "@tanstack/react-table";
|
|
20
|
+
import * as React from "react";
|
|
21
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
+
function DataTable({
|
|
23
|
+
columns,
|
|
24
|
+
data
|
|
25
|
+
}) {
|
|
26
|
+
const [sorting, setSorting] = React.useState([]);
|
|
27
|
+
const table = useReactTable({
|
|
28
|
+
data,
|
|
29
|
+
columns,
|
|
30
|
+
getCoreRowModel: getCoreRowModel(),
|
|
31
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
32
|
+
getSortedRowModel: getSortedRowModel(),
|
|
33
|
+
onSortingChange: setSorting,
|
|
34
|
+
state: {
|
|
35
|
+
sorting
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsxs("div", { "data-slot": "data-table", className: "space-y-4", children: [
|
|
39
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-md border", children: /* @__PURE__ */ jsxs(Table, { children: [
|
|
40
|
+
/* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx(TableHead, { children: header.isPlaceholder ? null : flexRender(
|
|
41
|
+
header.column.columnDef.header,
|
|
42
|
+
header.getContext()
|
|
43
|
+
) }, header.id)) }, headerGroup.id)) }),
|
|
44
|
+
/* @__PURE__ */ jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(
|
|
45
|
+
TableRow,
|
|
46
|
+
{
|
|
47
|
+
"data-state": row.getIsSelected() && "selected",
|
|
48
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, { children: flexRender(
|
|
49
|
+
cell.column.columnDef.cell,
|
|
50
|
+
cell.getContext()
|
|
51
|
+
) }, cell.id))
|
|
52
|
+
},
|
|
53
|
+
row.id
|
|
54
|
+
)) : /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(
|
|
55
|
+
TableCell,
|
|
56
|
+
{
|
|
57
|
+
colSpan: columns.length,
|
|
58
|
+
className: "h-24 text-center",
|
|
59
|
+
children: "No results."
|
|
60
|
+
}
|
|
61
|
+
) }) })
|
|
62
|
+
] }) }),
|
|
63
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
Button,
|
|
66
|
+
{
|
|
67
|
+
variant: "outline",
|
|
68
|
+
size: "sm",
|
|
69
|
+
onClick: () => table.previousPage(),
|
|
70
|
+
disabled: !table.getCanPreviousPage(),
|
|
71
|
+
children: "Previous"
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
Button,
|
|
76
|
+
{
|
|
77
|
+
variant: "outline",
|
|
78
|
+
size: "sm",
|
|
79
|
+
onClick: () => table.nextPage(),
|
|
80
|
+
disabled: !table.getCanNextPage(),
|
|
81
|
+
children: "Next"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
] })
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
DataTable
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=chunk-4WYKNDYY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/data-table/index.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from '@foundrykit/primitives';\nimport {\n type ColumnDef,\n flexRender,\n getCoreRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n type SortingState,\n useReactTable,\n} from '@tanstack/react-table';\nimport * as React from 'react';\n\n/**\n * Generic, paginated, sortable data table driven by TanStack Table column defs.\n *\n * @example\n * ```tsx\n * <DataTable columns={columns} data={data} />\n * ```\n */\nfunction DataTable<TData, TValue>({\n columns,\n data,\n}: {\n columns: ColumnDef<TData, TValue>[];\n data: TData[];\n}) {\n const [sorting, setSorting] = React.useState<SortingState>([]);\n\n const table = useReactTable({\n data,\n columns,\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getSortedRowModel: getSortedRowModel(),\n onSortingChange: setSorting,\n state: {\n sorting,\n },\n });\n\n return (\n <div data-slot='data-table' className='space-y-4'>\n <div className='rounded-md border'>\n <Table>\n <TableHeader>\n {table.getHeaderGroups().map(headerGroup => (\n <TableRow key={headerGroup.id}>\n {headerGroup.headers.map(header => (\n <TableHead key={header.id}>\n {header.isPlaceholder\n ? null\n : flexRender(\n header.column.columnDef.header,\n header.getContext()\n )}\n </TableHead>\n ))}\n </TableRow>\n ))}\n </TableHeader>\n <TableBody>\n {table.getRowModel().rows?.length ? (\n table.getRowModel().rows.map(row => (\n <TableRow\n key={row.id}\n data-state={row.getIsSelected() && 'selected'}\n >\n {row.getVisibleCells().map(cell => (\n <TableCell key={cell.id}>\n {flexRender(\n cell.column.columnDef.cell,\n cell.getContext()\n )}\n </TableCell>\n ))}\n </TableRow>\n ))\n ) : (\n <TableRow>\n <TableCell\n colSpan={columns.length}\n className='h-24 text-center'\n >\n No results.\n </TableCell>\n </TableRow>\n )}\n </TableBody>\n </Table>\n </div>\n <div className='flex items-center justify-end gap-2'>\n <Button\n variant='outline'\n size='sm'\n onClick={() => table.previousPage()}\n disabled={!table.getCanPreviousPage()}\n >\n Previous\n </Button>\n <Button\n variant='outline'\n size='sm'\n onClick={() => table.nextPage()}\n disabled={!table.getCanNextPage()}\n >\n Next\n </Button>\n </div>\n </div>\n );\n}\n\nexport { DataTable };\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,YAAY,WAAW;AAkCf,SAKU,KALV;AAxBR,SAAS,UAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AACD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAuB,CAAC,CAAC;AAE7D,QAAM,QAAQ,cAAc;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,iBAAiB,gBAAgB;AAAA,IACjC,uBAAuB,sBAAsB;AAAA,IAC7C,mBAAmB,kBAAkB;A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;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
CommandEmpty,
|
|
5
|
+
CommandGroup,
|
|
6
|
+
CommandInput,
|
|
7
|
+
CommandItem,
|
|
8
|
+
CommandList
|
|
9
|
+
} from "./chunk-IYBHXVCH.js";
|
|
10
|
+
|
|
11
|
+
// src/components/combobox/index.tsx
|
|
12
|
+
import {
|
|
13
|
+
Button,
|
|
14
|
+
Popover,
|
|
15
|
+
PopoverContent,
|
|
16
|
+
PopoverTrigger
|
|
17
|
+
} from "@foundrykit/primitives";
|
|
18
|
+
import { cn } from "@foundrykit/utils";
|
|
19
|
+
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
|
20
|
+
import * as React from "react";
|
|
21
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
+
function Combobox({
|
|
23
|
+
options,
|
|
24
|
+
value,
|
|
25
|
+
onValueChange,
|
|
26
|
+
placeholder = "Select an option...",
|
|
27
|
+
id,
|
|
28
|
+
"aria-label": ariaLabel
|
|
29
|
+
}) {
|
|
30
|
+
const [open, setOpen] = React.useState(false);
|
|
31
|
+
const selected = options.find((option) => option.value === value);
|
|
32
|
+
return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
33
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
34
|
+
Button,
|
|
35
|
+
{
|
|
36
|
+
"data-slot": "combobox-trigger",
|
|
37
|
+
variant: "outline",
|
|
38
|
+
role: "combobox",
|
|
39
|
+
id,
|
|
40
|
+
"aria-label": ariaLabel,
|
|
41
|
+
"aria-expanded": open,
|
|
42
|
+
className: "w-[200px] justify-between",
|
|
43
|
+
children: [
|
|
44
|
+
selected ? selected.label : placeholder,
|
|
45
|
+
/* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "ml-2 size-4 shrink-0 opacity-50" })
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
) }),
|
|
49
|
+
/* @__PURE__ */ jsx(PopoverContent, { "data-slot": "combobox-content", className: "w-[200px] p-0", children: /* @__PURE__ */ jsxs(Command, { children: [
|
|
50
|
+
/* @__PURE__ */ jsx(CommandInput, { placeholder, className: "h-9" }),
|
|
51
|
+
/* @__PURE__ */ jsxs(CommandList, { children: [
|
|
52
|
+
/* @__PURE__ */ jsx(CommandEmpty, { children: "No option found." }),
|
|
53
|
+
/* @__PURE__ */ jsx(CommandGroup, { children: options.map((option) => /* @__PURE__ */ jsxs(
|
|
54
|
+
CommandItem,
|
|
55
|
+
{
|
|
56
|
+
value: option.value,
|
|
57
|
+
onSelect: (currentValue) => {
|
|
58
|
+
onValueChange?.(currentValue === value ? "" : currentValue);
|
|
59
|
+
setOpen(false);
|
|
60
|
+
},
|
|
61
|
+
children: [
|
|
62
|
+
option.label,
|
|
63
|
+
/* @__PURE__ */ jsx(
|
|
64
|
+
CheckIcon,
|
|
65
|
+
{
|
|
66
|
+
className: cn(
|
|
67
|
+
"ml-auto size-4",
|
|
68
|
+
value === option.value ? "opacity-100" : "opacity-0"
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
option.value
|
|
75
|
+
)) })
|
|
76
|
+
] })
|
|
77
|
+
] }) })
|
|
78
|
+
] });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
Combobox
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=chunk-5CXNMTIN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/combobox/index.tsx"],"sourcesContent":["'use client';\n\nimport {\n Button,\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from '@foundrykit/primitives';\nimport { cn } from '@foundrykit/utils';\nimport { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';\nimport * as React from 'react';\n\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '../command/index.js';\n\ntype ComboboxOption = {\n value: string;\n label: string;\n};\n\n/**\n * Searchable single-select combobox composed from `Popover` and `Command`.\n * `role=\"combobox\"` takes no name from its text, so give it a label: `aria-label`\n * or an `id` paired with `<Label htmlFor>`.\n *\n * @example\n * ```tsx\n * <Combobox\n * options={[{ value: 'next', label: 'Next.js' }]}\n * value={value}\n * onValueChange={setValue}\n * placeholder='Select framework...'\n * />\n * ```\n */\nfunction Combobox({\n options,\n value,\n onValueChange,\n placeholder = 'Select an option...',\n id,\n 'aria-label': ariaLabel,\n}: {\n options: ComboboxOption[];\n value?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n /** Lets a `<Label htmlFor>` name the trigger. */\n id?: string;\n /** Names the trigger when there is no visible label. */\n 'aria-label'?: string;\n}) {\n const [open, setOpen] = React.useState(false);\n\n const selected = options.find(option => option.value === value);\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <Button\n data-slot='combobox-trigger'\n variant='outline'\n role='combobox'\n id={id}\n aria-label={ariaLabel}\n aria-expanded={open}\n className='w-[200px] justify-between'\n >\n {selected ? selected.label : placeholder}\n <ChevronsUpDownIcon className='ml-2 size-4 shrink-0 opacity-50' />\n </Button>\n </PopoverTrigger>\n <PopoverContent data-slot='combobox-content' className='w-[200px] p-0'>\n <Command>\n <CommandInput placeholder={placeholder} className='h-9' />\n <CommandList>\n <CommandEmpty>No option found.</CommandEmpty>\n <CommandGroup>\n {options.map(option => (\n <CommandItem\n key={option.value}\n value={option.value}\n onSelect={currentValue => {\n onValueChange?.(currentValue === value ? '' : currentValue);\n setOpen(false);\n }}\n >\n {option.label}\n <CheckIcon\n className={cn(\n 'ml-auto size-4',\n value === option.value ? 'opacity-100' : 'opacity-0'\n )}\n />\n </CommandItem>\n ))}\n </CommandGroup>\n </CommandList>\n </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;AAAA,cACF;AAAA;AAAA;AAAA,UAbK,OAAO;AAAA,QAcd,CACD,GACH;AAAA,SACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/components/carousel/index.tsx
|
|
4
|
+
import { Button } from "@foundrykit/primitives";
|
|
5
|
+
import { cn } from "@foundrykit/utils";
|
|
6
|
+
import useEmblaCarousel from "embla-carousel-react";
|
|
7
|
+
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var CarouselContext = React.createContext(null);
|
|
11
|
+
function useCarousel() {
|
|
12
|
+
const context = React.useContext(CarouselContext);
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error("useCarousel must be used within a <Carousel />");
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
function Carousel({
|
|
19
|
+
orientation = "horizontal",
|
|
20
|
+
opts,
|
|
21
|
+
setApi,
|
|
22
|
+
plugins,
|
|
23
|
+
className,
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
26
|
+
}) {
|
|
27
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
28
|
+
{
|
|
29
|
+
...opts,
|
|
30
|
+
axis: orientation === "horizontal" ? "x" : "y"
|
|
31
|
+
},
|
|
32
|
+
plugins
|
|
33
|
+
);
|
|
34
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
35
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
36
|
+
const onSelect = React.useCallback((api2) => {
|
|
37
|
+
if (!api2) return;
|
|
38
|
+
setCanScrollPrev(api2.canScrollPrev());
|
|
39
|
+
setCanScrollNext(api2.canScrollNext());
|
|
40
|
+
}, []);
|
|
41
|
+
const scrollPrev = React.useCallback(() => {
|
|
42
|
+
api?.scrollPrev();
|
|
43
|
+
}, [api]);
|
|
44
|
+
const scrollNext = React.useCallback(() => {
|
|
45
|
+
api?.scrollNext();
|
|
46
|
+
}, [api]);
|
|
47
|
+
const handleKeyDown = React.useCallback(
|
|
48
|
+
(event) => {
|
|
49
|
+
if (event.key === "ArrowLeft") {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
scrollPrev();
|
|
52
|
+
} else if (event.key === "ArrowRight") {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
scrollNext();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[scrollPrev, scrollNext]
|
|
58
|
+
);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
if (!api || !setApi) return;
|
|
61
|
+
setApi(api);
|
|
62
|
+
}, [api, setApi]);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
if (!api) return;
|
|
65
|
+
onSelect(api);
|
|
66
|
+
api.on("reInit", onSelect);
|
|
67
|
+
api.on("select", onSelect);
|
|
68
|
+
return () => {
|
|
69
|
+
api?.off("select", onSelect);
|
|
70
|
+
};
|
|
71
|
+
}, [api, onSelect]);
|
|
72
|
+
return /* @__PURE__ */ jsx(
|
|
73
|
+
CarouselContext.Provider,
|
|
74
|
+
{
|
|
75
|
+
value: {
|
|
76
|
+
carouselRef,
|
|
77
|
+
api,
|
|
78
|
+
opts,
|
|
79
|
+
orientation: orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
80
|
+
scrollPrev,
|
|
81
|
+
scrollNext,
|
|
82
|
+
canScrollPrev,
|
|
83
|
+
canScrollNext
|
|
84
|
+
},
|
|
85
|
+
children: /* @__PURE__ */ jsx(
|
|
86
|
+
"div",
|
|
87
|
+
{
|
|
88
|
+
"data-slot": "carousel",
|
|
89
|
+
onKeyDownCapture: handleKeyDown,
|
|
90
|
+
className: cn("relative", className),
|
|
91
|
+
role: "region",
|
|
92
|
+
"aria-roledescription": "carousel",
|
|
93
|
+
...props,
|
|
94
|
+
children
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function CarouselContent({ className, ...props }) {
|
|
101
|
+
const { carouselRef, orientation } = useCarousel();
|
|
102
|
+
return /* @__PURE__ */ jsx(
|
|
103
|
+
"div",
|
|
104
|
+
{
|
|
105
|
+
ref: carouselRef,
|
|
106
|
+
"data-slot": "carousel-content",
|
|
107
|
+
className: "overflow-hidden",
|
|
108
|
+
children: /* @__PURE__ */ jsx(
|
|
109
|
+
"div",
|
|
110
|
+
{
|
|
111
|
+
className: cn(
|
|
112
|
+
"flex",
|
|
113
|
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
114
|
+
className
|
|
115
|
+
),
|
|
116
|
+
...props
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function CarouselItem({ className, ...props }) {
|
|
123
|
+
const { orientation } = useCarousel();
|
|
124
|
+
return /* @__PURE__ */ jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
"data-slot": "carousel-item",
|
|
128
|
+
role: "group",
|
|
129
|
+
"aria-roledescription": "slide",
|
|
130
|
+
className: cn(
|
|
131
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
132
|
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
133
|
+
className
|
|
134
|
+
),
|
|
135
|
+
...props
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function CarouselPrevious({
|
|
140
|
+
className,
|
|
141
|
+
variant = "outline",
|
|
142
|
+
size = "icon",
|
|
143
|
+
...props
|
|
144
|
+
}) {
|
|
145
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
146
|
+
return /* @__PURE__ */ jsxs(
|
|
147
|
+
Button,
|
|
148
|
+
{
|
|
149
|
+
"data-slot": "carousel-previous",
|
|
150
|
+
variant,
|
|
151
|
+
size,
|
|
152
|
+
className: cn(
|
|
153
|
+
"absolute size-8 rounded-full",
|
|
154
|
+
orientation === "horizontal" ? "top-1/2 -left-12 -translate-y-1/2" : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
155
|
+
className
|
|
156
|
+
),
|
|
157
|
+
disabled: !canScrollPrev,
|
|
158
|
+
onClick: scrollPrev,
|
|
159
|
+
...props,
|
|
160
|
+
children: [
|
|
161
|
+
/* @__PURE__ */ jsx(ArrowLeftIcon, {}),
|
|
162
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Previous slide" })
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function CarouselNext({
|
|
168
|
+
className,
|
|
169
|
+
variant = "outline",
|
|
170
|
+
size = "icon",
|
|
171
|
+
...props
|
|
172
|
+
}) {
|
|
173
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
174
|
+
return /* @__PURE__ */ jsxs(
|
|
175
|
+
Button,
|
|
176
|
+
{
|
|
177
|
+
"data-slot": "carousel-next",
|
|
178
|
+
variant,
|
|
179
|
+
size,
|
|
180
|
+
className: cn(
|
|
181
|
+
"absolute size-8 rounded-full",
|
|
182
|
+
orientation === "horizontal" ? "top-1/2 -right-12 -translate-y-1/2" : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
183
|
+
className
|
|
184
|
+
),
|
|
185
|
+
disabled: !canScrollNext,
|
|
186
|
+
onClick: scrollNext,
|
|
187
|
+
...props,
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ jsx(ArrowRightIcon, {}),
|
|
190
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Next slide" })
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export {
|
|
197
|
+
Carousel,
|
|
198
|
+
CarouselContent,
|
|
199
|
+
CarouselItem,
|
|
200
|
+
CarouselPrevious,
|
|
201
|
+
CarouselNext
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=chunk-B5ZTF5MZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/carousel/index.tsx"],"sourcesContent":["'use client';\n\nimport { Button } from '@foundrykit/primitives';\nimport { cn } from '@foundrykit/utils';\nimport useEmblaCarousel, {\n type UseEmblaCarouselType,\n} from 'embla-carousel-react';\nimport { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react';\nimport * as React from 'react';\n\ntype CarouselApi = UseEmblaCarouselType[1];\ntype UseCarouselParameters = Parameters<typeof useEmblaCarousel>;\ntype CarouselOptions = UseCarouselParameters[0];\ntype CarouselPlugin = UseCarouselParameters[1];\n\ntype CarouselProps = {\n opts?: CarouselOptions;\n plugins?: CarouselPlugin;\n orientation?: 'horizontal' | 'vertical';\n setApi?: (api: CarouselApi) => void;\n};\n\ntype CarouselContextProps = {\n carouselRef: ReturnType<typeof useEmblaCarousel>[0];\n api: ReturnType<typeof useEmblaCarousel>[1];\n scrollPrev: () => void;\n scrollNext: () => void;\n canScrollPrev: boolean;\n canScrollNext: boolean;\n} & CarouselProps;\n\nconst CarouselContext = React.createContext<CarouselContextProps | null>(null);\n\nfunction useCarousel() {\n const context = React.useContext(CarouselContext);\n\n if (!context) {\n throw new Error('useCarousel must be used within a <Carousel />');\n }\n\n return context;\n}\n\n/**\n * Carousel root that provides Embla state to its parts.\n *\n * @example\n * ```tsx\n * <Carousel>\n * <CarouselContent>\n * <CarouselItem>Slide 1</CarouselItem>\n * </CarouselContent>\n * <CarouselPrevious />\n * <CarouselNext />\n * </Carousel>\n * ```\n */\nfunction Carousel({\n orientation = 'horizontal',\n opts,\n setApi,\n plugins,\n className,\n children,\n ...props\n}: React.ComponentProps<'div'> & CarouselProps) {\n const [carouselRef, api] = useEmblaCarousel(\n {\n ...opts,\n axis: orientation === 'horizontal' ? 'x' : 'y',\n },\n plugins\n );\n const [canScrollPrev, setCanScrollPrev] = React.useState(false);\n const [canScrollNext, setCanScrollNext] = React.useState(false);\n\n const onSelect = React.useCallback((api: CarouselApi) => {\n if (!api) return;\n setCanScrollPrev(api.canScrollPrev());\n setCanScrollNext(api.canScrollNext());\n }, []);\n\n const scrollPrev = React.useCallback(() => {\n api?.scrollPrev();\n }, [api]);\n\n const scrollNext = React.useCallback(() => {\n api?.scrollNext();\n }, [api]);\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'ArrowLeft') {\n event.preventDefault();\n scrollPrev();\n } else if (event.key === 'ArrowRight') {\n event.preventDefault();\n scrollNext();\n }\n },\n [scrollPrev, scrollNext]\n );\n\n React.useEffect(() => {\n if (!api || !setApi) return;\n setApi(api);\n }, [api, setApi]);\n\n React.useEffect(() => {\n if (!api) return;\n onSelect(api);\n api.on('reInit', onSelect);\n api.on('select', onSelect);\n\n return () => {\n api?.off('select', onSelect);\n };\n }, [api, onSelect]);\n\n return (\n <CarouselContext.Provider\n value={{\n carouselRef,\n api,\n opts,\n orientation:\n orientation || (opts?.axis === 'y' ? 'vertical' : 'horizontal'),\n scrollPrev,\n scrollNext,\n canScrollPrev,\n canScrollNext,\n }}\n >\n <div\n data-slot='carousel'\n onKeyDownCapture={handleKeyDown}\n className={cn('relative', className)}\n role='region'\n aria-roledescription='carousel'\n {...props}\n >\n {children}\n </div>\n </CarouselContext.Provider>\n );\n}\n\n/** Scrollable track that holds the carousel items. */\nfunction CarouselContent({ className, ...props }: React.ComponentProps<'div'>) {\n const { carouselRef, orientation } = useCarousel();\n\n return (\n <div\n ref={carouselRef}\n data-slot='carousel-content'\n className='overflow-hidden'\n >\n <div\n className={cn(\n 'flex',\n orientation === 'horizontal' ? '-ml-4' : '-mt-4 flex-col',\n className\n )}\n {...props}\n />\n </div>\n );\n}\n\n/** A single slide within a {@link CarouselContent}. */\nfunction CarouselItem({ className, ...props }: React.ComponentProps<'div'>) {\n const { orientation } = useCarousel();\n\n return (\n <div\n data-slot='carousel-item'\n role='group'\n aria-roledescription='slide'\n className={cn(\n 'min-w-0 shrink-0 grow-0 basis-full',\n orientation === 'horizontal' ? 'pl-4' : 'pt-4',\n className\n )}\n {...props}\n />\n );\n}\n\n/** Button that scrolls the carousel to the previous slide. */\nfunction CarouselPrevious({\n className,\n variant = 'outline',\n size = 'icon',\n ...props\n}: React.ComponentProps<typeof Button>) {\n const { orientation, scrollPrev, canScrollPrev } = useCarousel();\n\n return (\n <Button\n data-slot='carousel-previous'\n variant={variant}\n size={size}\n className={cn(\n 'absolute size-8 rounded-full',\n orientation === 'horizontal'\n ? 'top-1/2 -left-12 -translate-y-1/2'\n : '-top-12 left-1/2 -translate-x-1/2 rotate-90',\n className\n )}\n disabled={!canScrollPrev}\n onClick={scrollPrev}\n {...props}\n >\n <ArrowLeftIcon />\n <span className='sr-only'>Previous slide</span>\n </Button>\n );\n}\n\n/** Button that scrolls the carousel to the next slide. */\nfunction CarouselNext({\n className,\n variant = 'outline',\n size = 'icon',\n ...props\n}: React.ComponentProps<typeof Button>) {\n const { orientation, scrollNext, canScrollNext } = useCarousel();\n\n return (\n <Button\n data-slot='carousel-next'\n variant={variant}\n size={size}\n className={cn(\n 'absolute size-8 rounded-full',\n orientation === 'horizontal'\n ? 'top-1/2 -right-12 -translate-y-1/2'\n : '-bottom-12 left-1/2 -translate-x-1/2 rotate-90',\n className\n )}\n disabled={!canScrollNext}\n onClick={scrollNext}\n {...props}\n >\n <ArrowRightIcon />\n <span className='sr-only'>Next slide</span>\n </Button>\n );\n}\n\nexport {\n Carousel,\n type CarouselApi,\n CarouselContent,\n CarouselItem,\n CarouselNext,\n CarouselPrevious,\n};\n"],"mappings":";;;AAEA,SAAS,cAAc;AACvB,SAAS,UAAU;AACnB,OAAO,sBAEA;AACP,SAAS,eAAe,sBAAsB;AAC9C,YAAY,WAAW;AA6HjB,cAiEF,YAjEE;AAtGN,IAAM,kBAAwB,oBAA2C,IAAI;AAE7E,SAAS,cAAc;AAC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S,iBAAiB;AAAA,EACxB;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,GAAG;AACL,GAAwC;AACtC,QAAM,EAAE,aAAa,YAAY,cAAc,IAAI,YAAY;AAE/D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA,gBAAgB,eACZ,sCACA;AAAA,QACJ;AAAA,MACF;AAAA,MACA,UAAU,CAAC;AAAA,MACX,SAAS;AAAA,MACR,GAAG;AAAA,MAEJ;AAAA,4BAAC,iBAAc;AAAA,QACf,oBAAC,UAAK,WAAU,WAAU,4BAAc;AAAA;AAAA;AAAA,EAC1C;AAEJ;AAGA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,GAAG;AACL,GAAwC;AACtC,QAAM,EAAE,aAAa,YAAY,cAAc,IAAI,YAAY;AAE/D,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA,gBAAgB,eACZ,uCACA;AAAA,QACJ;AAAA,MACF;AAAA,MACA,UAAU,CAAC;AAAA,MACX,SAAS;AAAA,MACR,GAAG;AAAA,MAEJ;AAAA,4BAAC,kBAAe;AAAA,QAChB,oBAAC,UAAK,WAAU,WAAU,wBAAU;AAAA;AAAA;AAAA,EACtC;AAEJ;","names":["api"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/components/search-bar/index.tsx
|
|
4
|
+
import { Input } from "@foundrykit/primitives";
|
|
5
|
+
import { cn } from "@foundrykit/utils";
|
|
6
|
+
import { Search } from "lucide-react";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var SearchBar = React.forwardRef(
|
|
10
|
+
({
|
|
11
|
+
className,
|
|
12
|
+
onSearch,
|
|
13
|
+
placeholder = "Search...",
|
|
14
|
+
value: externalValue,
|
|
15
|
+
onChange: externalOnChange,
|
|
16
|
+
...props
|
|
17
|
+
}, ref) => {
|
|
18
|
+
const [internalQuery, setInternalQuery] = React.useState("");
|
|
19
|
+
const query = externalValue !== void 0 ? externalValue : internalQuery;
|
|
20
|
+
const isControlled = externalValue !== void 0;
|
|
21
|
+
const handleChange = (e) => {
|
|
22
|
+
const value = e.target.value;
|
|
23
|
+
if (!isControlled) {
|
|
24
|
+
setInternalQuery(value);
|
|
25
|
+
}
|
|
26
|
+
onSearch?.(value);
|
|
27
|
+
externalOnChange?.(e);
|
|
28
|
+
};
|
|
29
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
|
|
30
|
+
/* @__PURE__ */ jsx(Search, { className: "text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2" }),
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
Input,
|
|
33
|
+
{
|
|
34
|
+
ref,
|
|
35
|
+
type: "search",
|
|
36
|
+
placeholder,
|
|
37
|
+
value: query,
|
|
38
|
+
onChange: handleChange,
|
|
39
|
+
className: "pl-10",
|
|
40
|
+
...props
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
] });
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
SearchBar.displayName = "SearchBar";
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
SearchBar
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=chunk-EDNWBEKV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/search-bar/index.tsx"],"sourcesContent":["'use client';\n\nimport { Input } from '@foundrykit/primitives';\nimport { cn } from '@foundrykit/utils';\nimport { Search } from 'lucide-react';\nimport * as React from 'react';\n\nexport interface SearchBarProps\n extends React.InputHTMLAttributes<HTMLInputElement> {\n onSearch?: (query: string) => void;\n placeholder?: string;\n className?: string;\n value?: string;\n onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;\n}\n\n/**\n * Search input with a leading search icon. Works uncontrolled or controlled\n * (pass `value`/`onChange`); `onSearch` is called with the current query text on\n * every change.\n */\nconst SearchBar = React.forwardRef<HTMLInputElement, SearchBarProps>(\n (\n {\n className,\n onSearch,\n placeholder = 'Search...',\n value: externalValue,\n onChange: externalOnChange,\n ...props\n },\n ref\n ) => {\n const [internalQuery, setInternalQuery] = React.useState('');\n\n // Use external value if provided, otherwise use internal state\n const query = externalValue !== undefined ? externalValue : internalQuery;\n const isControlled = externalValue !== undefined;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const value = e.target.value;\n\n if (!isControlled) {\n setInternalQuery(value);\n }\n\n onSearch?.(value);\n externalOnChange?.(e);\n };\n\n return (\n <div className={cn('relative', className)}>\n <Search className='text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2' />\n <Input\n ref={ref}\n type='search'\n placeholder={placeholder}\n value={query}\n onChange={handleChange}\n className='pl-10'\n {...props}\n />\n </div>\n );\n }\n);\n\nSearchBar.displayName = 'SearchBar';\n\nexport { SearchBar };\n"],"mappings":";;;AAEA,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,YAAY,WAAW;AA8CjB,SACE,KADF;AA9BN,IAAM,YAAkB;AAAA,EACtB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,OAAO;AAAA,IACP,UAAU;AAAA,IACV,GAAG;AAAA,EACL,GACA,QACG;AACH,UAAM,CAAC,eAAe,gBAAgB,IAAU,eAAS,EAAE;AAG3D,UAAM,QAAQ,kBAAkB,SAAY,gBAAgB;AAC5D,UAAM,eAAe,kBAAkB;AAEvC,UAAM,eAAe,CAAC,MAA2C;AAC/D,YAAM,QAAQ,EAAE,OAAO;AAEvB,UAAI,CAAC,cAAc;AACjB,yBAAiB,KAAK;AAAA,MACxB;AAEA,iBAAW,KAAK;AAChB,yBAAmB,CAAC;AAAA,IACtB;AAEA,WACE,qBAAC,SAAI,WAAW,GAAG,YAAY,SAAS,GACtC;AAAA,0BAAC,UAAO,WAAU,0EAAyE;AAAA,MAC3F;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,MAAK;AAAA,UACL;AAAA,UACA,OAAO;AAAA,UACP,UAAU;AAAA,UACV,WAAU;AAAA,UACT,GAAG;AAAA;AAAA,MACN;AAAA,OACF;AAAA,EAEJ;AACF;AAEA,UAAU,cAAc;","names":[]}
|