@saptanshuwanjari/react-component-library 0.1.9 → 0.1.11

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/index.js CHANGED
@@ -1,21 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var React2 = require('react');
4
- var zod = require('@hookform/resolvers/zod');
5
- var reactHookForm = require('react-hook-form');
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var LabelPrimitive = require('@radix-ui/react-label');
8
3
  var clsx = require('clsx');
9
4
  var tailwindMerge = require('tailwind-merge');
5
+ var reactTable = require('@tanstack/react-table');
6
+ var React2 = require('react');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var SelectPrimitive = require('@radix-ui/react-select');
10
9
  var lucideReact = require('lucide-react');
11
10
  var classVarianceAuthority = require('class-variance-authority');
12
- var SelectPrimitive = require('@radix-ui/react-select');
13
- var CheckboxPrimitive = require('@radix-ui/react-checkbox');
14
- var PopoverPrimitive = require('@radix-ui/react-popover');
15
- var reactDayPicker = require('react-day-picker');
16
- var dateFns = require('date-fns');
17
- var AvatarPrimitive = require('@radix-ui/react-avatar');
18
- var reactTable = require('@tanstack/react-table');
19
11
 
20
12
  function _interopNamespace(e) {
21
13
  if (e && e.__esModule) return e;
@@ -36,111 +28,71 @@ function _interopNamespace(e) {
36
28
  }
37
29
 
38
30
  var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
39
- var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespace(LabelPrimitive);
40
31
  var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
41
- var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
42
- var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
43
- var AvatarPrimitive__namespace = /*#__PURE__*/_interopNamespace(AvatarPrimitive);
44
32
 
45
- // src/components/form/root.tsx
46
- var FormContext = React2.createContext(null);
47
- var DEFAULT_FORM_KEY = "__default_form__";
48
- var formRegistry = /* @__PURE__ */ new Map();
49
- function Root({
50
- schema,
51
- defaultValues,
52
- onSubmit,
53
- children,
54
- enableOptimistic = false,
55
- title,
56
- description,
57
- enableEditMode = false,
58
- formId
59
- }) {
60
- const resolver = schema ? zod.zodResolver(schema) : void 0;
61
- const [isPending, startTransition] = React2.useTransition();
62
- const [isEditing, setIsEditing] = React2.useState(!enableEditMode);
63
- const methods = reactHookForm.useForm({
64
- resolver,
65
- defaultValues
66
- });
67
- const handleFormSubmit = methods.handleSubmit((data) => {
68
- if (enableOptimistic) {
69
- startTransition(() => {
70
- void onSubmit(data);
71
- });
72
- return;
73
- }
74
- return onSubmit(data);
75
- });
76
- React2.useEffect(() => {
77
- const key = formId ?? DEFAULT_FORM_KEY;
78
- formRegistry.set(key, setIsEditing);
79
- return () => {
80
- formRegistry.delete(key);
81
- };
82
- }, [formId, setIsEditing]);
83
- return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: { ...methods, schema, isPending, isEditing, setIsEditing }, children: /* @__PURE__ */ jsxRuntime.jsxs(
84
- "form",
85
- {
86
- onSubmit: handleFormSubmit,
87
- className: "bg-card text-card-foreground rounded-xl border shadow-sm p-6 space-y-6",
88
- children: [
89
- (title || description) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
90
- title && /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold tracking-tight", children: title }),
91
- description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: description })
92
- ] }),
93
- children
94
- ]
95
- }
96
- ) });
97
- }
98
- var root_default = Root;
99
- function useFormCtx() {
100
- const ctx = React2.useContext(FormContext);
101
- if (!ctx) throw new Error("Form components must be used inside Form.Root");
102
- return ctx;
103
- }
33
+ // src/lib/utils.ts
104
34
  function cn(...inputs) {
105
35
  return tailwindMerge.twMerge(clsx.clsx(inputs));
106
36
  }
107
- function Label({
108
- className,
109
- ...props
37
+ var DataTableContext = React2.createContext(null);
38
+ function useDataTableContext() {
39
+ const context = React2.useContext(DataTableContext);
40
+ if (!context) {
41
+ throw new Error("useDataTableContext must be used within a DataTableRoot");
42
+ }
43
+ return context;
44
+ }
45
+ function useViewMode(defaultMode = "table") {
46
+ const [viewMode, setViewMode] = React2.useState(defaultMode);
47
+ return { viewMode, setViewMode };
48
+ }
49
+ function Root({
50
+ columns,
51
+ data,
52
+ filters = [],
53
+ defaultViewMode = "table",
54
+ showFilters = true,
55
+ children
110
56
  }) {
57
+ const [globalFilter, setGlobalFilter] = React2.useState("");
58
+ const [pagination, setPagination] = React2.useState({ pageIndex: 0, pageSize: 10 });
59
+ const [sorting, setSorting] = React2.useState([]);
60
+ const [columnFilters, setColumnFilters] = React2.useState([]);
61
+ const [viewMode, setViewMode] = React2.useState(defaultViewMode);
62
+ const table = reactTable.useReactTable({
63
+ data,
64
+ columns,
65
+ state: {
66
+ globalFilter,
67
+ pagination,
68
+ sorting,
69
+ columnFilters
70
+ },
71
+ onGlobalFilterChange: setGlobalFilter,
72
+ onPaginationChange: setPagination,
73
+ onSortingChange: setSorting,
74
+ onColumnFiltersChange: setColumnFilters,
75
+ getCoreRowModel: reactTable.getCoreRowModel(),
76
+ getFilteredRowModel: reactTable.getFilteredRowModel(),
77
+ getSortedRowModel: reactTable.getSortedRowModel(),
78
+ getPaginationRowModel: reactTable.getPaginationRowModel()
79
+ });
111
80
  return /* @__PURE__ */ jsxRuntime.jsx(
112
- LabelPrimitive__namespace.Root,
81
+ DataTableContext.Provider,
113
82
  {
114
- "data-slot": "label",
115
- className: cn(
116
- "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
117
- className
118
- ),
119
- ...props
83
+ value: {
84
+ table,
85
+ viewMode,
86
+ setViewMode,
87
+ filters,
88
+ showFilters,
89
+ globalFilter,
90
+ setGlobalFilter
91
+ },
92
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children })
120
93
  }
121
94
  );
122
95
  }
123
- function Field({
124
- name,
125
- label,
126
- children
127
- }) {
128
- const form = useFormCtx();
129
- const error = form.formState.errors[name];
130
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
131
- label ? /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: String(name), children: label }) : null,
132
- /* @__PURE__ */ jsxRuntime.jsx(
133
- reactHookForm.Controller,
134
- {
135
- control: form.control,
136
- name,
137
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children(field) })
138
- }
139
- ),
140
- error?.message && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-destructive", children: error.message })
141
- ] });
142
- }
143
- var field_default = Field;
144
96
  function Input({ className, type, ...props }) {
145
97
  return /* @__PURE__ */ jsxRuntime.jsx(
146
98
  "input",
@@ -157,258 +109,6 @@ function Input({ className, type, ...props }) {
157
109
  }
158
110
  );
159
111
  }
160
- var InputField = React2.memo(function InputField2({
161
- name,
162
- label,
163
- placeholder,
164
- type = "text",
165
- icon,
166
- iconAlign = "inline-start",
167
- startAddon,
168
- endAddon,
169
- useGroup
170
- }) {
171
- const { isEditing } = useFormCtx();
172
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => /* @__PURE__ */ jsxRuntime.jsx(
173
- Input,
174
- {
175
- id: String(name),
176
- type,
177
- ...field,
178
- value: field.value ?? "",
179
- placeholder,
180
- disabled: !isEditing
181
- }
182
- ) });
183
- });
184
- var input_field_default = InputField;
185
- function setRef(ref, value) {
186
- if (typeof ref === "function") {
187
- return ref(value);
188
- } else if (ref !== null && ref !== void 0) {
189
- ref.current = value;
190
- }
191
- }
192
- function composeRefs(...refs) {
193
- return (node) => {
194
- let hasCleanup = false;
195
- const cleanups = refs.map((ref) => {
196
- const cleanup = setRef(ref, node);
197
- if (!hasCleanup && typeof cleanup == "function") {
198
- hasCleanup = true;
199
- }
200
- return cleanup;
201
- });
202
- if (hasCleanup) {
203
- return () => {
204
- for (let i = 0; i < cleanups.length; i++) {
205
- const cleanup = cleanups[i];
206
- if (typeof cleanup == "function") {
207
- cleanup();
208
- } else {
209
- setRef(refs[i], null);
210
- }
211
- }
212
- };
213
- }
214
- };
215
- }
216
- // @__NO_SIDE_EFFECTS__
217
- function createSlot(ownerName) {
218
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
219
- const Slot2 = React2__namespace.forwardRef((props, forwardedRef) => {
220
- const { children, ...slotProps } = props;
221
- const childrenArray = React2__namespace.Children.toArray(children);
222
- const slottable = childrenArray.find(isSlottable);
223
- if (slottable) {
224
- const newElement = slottable.props.children;
225
- const newChildren = childrenArray.map((child) => {
226
- if (child === slottable) {
227
- if (React2__namespace.Children.count(newElement) > 1) return React2__namespace.Children.only(null);
228
- return React2__namespace.isValidElement(newElement) ? newElement.props.children : null;
229
- } else {
230
- return child;
231
- }
232
- });
233
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React2__namespace.isValidElement(newElement) ? React2__namespace.cloneElement(newElement, void 0, newChildren) : null });
234
- }
235
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
236
- });
237
- Slot2.displayName = `${ownerName}.Slot`;
238
- return Slot2;
239
- }
240
- var Slot = /* @__PURE__ */ createSlot("Slot");
241
- // @__NO_SIDE_EFFECTS__
242
- function createSlotClone(ownerName) {
243
- const SlotClone = React2__namespace.forwardRef((props, forwardedRef) => {
244
- const { children, ...slotProps } = props;
245
- if (React2__namespace.isValidElement(children)) {
246
- const childrenRef = getElementRef(children);
247
- const props2 = mergeProps(slotProps, children.props);
248
- if (children.type !== React2__namespace.Fragment) {
249
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
250
- }
251
- return React2__namespace.cloneElement(children, props2);
252
- }
253
- return React2__namespace.Children.count(children) > 1 ? React2__namespace.Children.only(null) : null;
254
- });
255
- SlotClone.displayName = `${ownerName}.SlotClone`;
256
- return SlotClone;
257
- }
258
- var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
259
- function isSlottable(child) {
260
- return React2__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
261
- }
262
- function mergeProps(slotProps, childProps) {
263
- const overrideProps = { ...childProps };
264
- for (const propName in childProps) {
265
- const slotPropValue = slotProps[propName];
266
- const childPropValue = childProps[propName];
267
- const isHandler = /^on[A-Z]/.test(propName);
268
- if (isHandler) {
269
- if (slotPropValue && childPropValue) {
270
- overrideProps[propName] = (...args) => {
271
- const result = childPropValue(...args);
272
- slotPropValue(...args);
273
- return result;
274
- };
275
- } else if (slotPropValue) {
276
- overrideProps[propName] = slotPropValue;
277
- }
278
- } else if (propName === "style") {
279
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
280
- } else if (propName === "className") {
281
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
282
- }
283
- }
284
- return { ...slotProps, ...overrideProps };
285
- }
286
- function getElementRef(element) {
287
- let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
288
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
289
- if (mayWarn) {
290
- return element.ref;
291
- }
292
- getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
293
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
294
- if (mayWarn) {
295
- return element.props.ref;
296
- }
297
- return element.props.ref || element.ref;
298
- }
299
- var buttonVariants = classVarianceAuthority.cva(
300
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
301
- {
302
- variants: {
303
- variant: {
304
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
305
- destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
306
- outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
307
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
308
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
309
- link: "text-primary underline-offset-4 hover:underline"
310
- },
311
- size: {
312
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
313
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
314
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
315
- icon: "size-9",
316
- "icon-sm": "size-8",
317
- "icon-lg": "size-10"
318
- }
319
- },
320
- defaultVariants: {
321
- variant: "default",
322
- size: "default"
323
- }
324
- }
325
- );
326
- function Button({
327
- className,
328
- variant = "default",
329
- size = "default",
330
- asChild = false,
331
- ...props
332
- }) {
333
- const Comp = asChild ? Slot : "button";
334
- return /* @__PURE__ */ jsxRuntime.jsx(
335
- Comp,
336
- {
337
- "data-slot": "button",
338
- "data-variant": variant,
339
- "data-size": size,
340
- className: cn(buttonVariants({ variant, size, className })),
341
- ...props
342
- }
343
- );
344
- }
345
- var PasswordField = React2.memo(function PasswordField2({
346
- name,
347
- label,
348
- placeholder
349
- }) {
350
- const [show, setShow] = React2.useState(false);
351
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
352
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none z-10", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Lock, { className: "h-4 w-4 text-muted-foreground" }) }),
353
- /* @__PURE__ */ jsxRuntime.jsx(
354
- Input,
355
- {
356
- id: String(name),
357
- type: show ? "text" : "password",
358
- ...field,
359
- value: field.value ?? "",
360
- placeholder,
361
- className: "pl-10 pr-10"
362
- }
363
- ),
364
- /* @__PURE__ */ jsxRuntime.jsx(
365
- Button,
366
- {
367
- variant: "ghost",
368
- size: "sm",
369
- type: "button",
370
- onClick: () => setShow(!show),
371
- className: "absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8 p-0 text-muted-foreground hover:text-foreground",
372
- children: show ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "h-4 w-4" })
373
- }
374
- )
375
- ] }) });
376
- });
377
- var password_field_default = PasswordField;
378
- function Textarea({ className, ...props }) {
379
- return /* @__PURE__ */ jsxRuntime.jsx(
380
- "textarea",
381
- {
382
- "data-slot": "textarea",
383
- className: cn(
384
- "border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
385
- className
386
- ),
387
- ...props
388
- }
389
- );
390
- }
391
- var TextareaField = React2.memo(function TextareaField2({
392
- name,
393
- label,
394
- placeholder,
395
- rows = 4
396
- }) {
397
- const { isEditing } = useFormCtx();
398
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => /* @__PURE__ */ jsxRuntime.jsx(
399
- Textarea,
400
- {
401
- id: String(name),
402
- ...field,
403
- value: field.value ?? "",
404
- placeholder,
405
- rows,
406
- disabled: !isEditing,
407
- className: !isEditing ? "bg-background/50 opacity-80" : ""
408
- }
409
- ) });
410
- });
411
- var textarea_field_default = TextareaField;
412
112
  function Select({
413
113
  ...props
414
114
  }) {
@@ -519,888 +219,89 @@ function SelectScrollUpButton({
519
219
  className
520
220
  ),
521
221
  ...props,
522
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { className: "size-4" })
523
- }
524
- );
525
- }
526
- function SelectScrollDownButton({
527
- className,
528
- ...props
529
- }) {
530
- return /* @__PURE__ */ jsxRuntime.jsx(
531
- SelectPrimitive__namespace.ScrollDownButton,
532
- {
533
- "data-slot": "select-scroll-down-button",
534
- className: cn(
535
- "flex cursor-default items-center justify-center py-1",
536
- className
537
- ),
538
- ...props,
539
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { className: "size-4" })
540
- }
541
- );
542
- }
543
- var SelectField = React2.memo(function SelectField2({
544
- name,
545
- label,
546
- placeholder = "Select an option",
547
- options
548
- }) {
549
- const { isEditing } = useFormCtx();
550
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => !isEditing ? /* @__PURE__ */ jsxRuntime.jsx(
551
- Input,
552
- {
553
- id: String(name),
554
- value: options.find((opt) => opt.value === field.value)?.label ?? "",
555
- placeholder,
556
- readOnly: true,
557
- disabled: true,
558
- className: "bg-background/50 opacity-80"
559
- }
560
- ) : /* @__PURE__ */ jsxRuntime.jsxs(Select, { onValueChange: field.onChange, value: field.value ?? "", children: [
561
- /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder }) }),
562
- /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: option.value, children: option.label }, option.value)) })
563
- ] }) });
564
- });
565
- var select_field_default = SelectField;
566
- function Checkbox({
567
- className,
568
- ...props
569
- }) {
570
- return /* @__PURE__ */ jsxRuntime.jsx(
571
- CheckboxPrimitive__namespace.Root,
572
- {
573
- "data-slot": "checkbox",
574
- className: cn(
575
- "peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
576
- className
577
- ),
578
- ...props,
579
- children: /* @__PURE__ */ jsxRuntime.jsx(
580
- CheckboxPrimitive__namespace.Indicator,
581
- {
582
- "data-slot": "checkbox-indicator",
583
- className: "grid place-content-center text-current transition-none",
584
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, { className: "size-3.5" })
585
- }
586
- )
587
- }
588
- );
589
- }
590
- var CheckboxField = React2.memo(function CheckboxField2({
591
- name,
592
- label,
593
- description
594
- }) {
595
- const form = useFormCtx();
596
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
597
- /* @__PURE__ */ jsxRuntime.jsx(
598
- reactHookForm.Controller,
599
- {
600
- control: form.control,
601
- name,
602
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-2", children: [
603
- /* @__PURE__ */ jsxRuntime.jsx(
604
- Checkbox,
605
- {
606
- id: String(name),
607
- checked: !!field.value,
608
- onCheckedChange: form.isEditing ? field.onChange : void 0,
609
- disabled: !form.isEditing
610
- }
611
- ),
612
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-1.5 leading-none", children: [
613
- label && /* @__PURE__ */ jsxRuntime.jsx(
614
- Label,
615
- {
616
- htmlFor: String(name),
617
- className: "cursor-pointer",
618
- children: label
619
- }
620
- ),
621
- description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: description })
622
- ] })
623
- ] })
624
- }
625
- ),
626
- form.formState.errors[name]?.message && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-destructive", children: form.formState.errors[name]?.message })
627
- ] });
628
- });
629
- var checkbox_field_default = CheckboxField;
630
- function Popover({
631
- ...props
632
- }) {
633
- return /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Root, { "data-slot": "popover", ...props });
634
- }
635
- function PopoverTrigger({
636
- ...props
637
- }) {
638
- return /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Trigger, { "data-slot": "popover-trigger", ...props });
639
- }
640
- function PopoverContent({
641
- className,
642
- align = "center",
643
- sideOffset = 4,
644
- ...props
645
- }) {
646
- return /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
647
- PopoverPrimitive__namespace.Content,
648
- {
649
- "data-slot": "popover-content",
650
- align,
651
- sideOffset,
652
- className: cn(
653
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
654
- className
655
- ),
656
- ...props
657
- }
658
- ) });
659
- }
660
- function Calendar({
661
- className,
662
- classNames,
663
- showOutsideDays = true,
664
- captionLayout = "label",
665
- buttonVariant = "ghost",
666
- formatters,
667
- components,
668
- ...props
669
- }) {
670
- const defaultClassNames = reactDayPicker.getDefaultClassNames();
671
- return /* @__PURE__ */ jsxRuntime.jsx(
672
- reactDayPicker.DayPicker,
673
- {
674
- showOutsideDays,
675
- className: cn(
676
- "bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
677
- String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
678
- String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
679
- className
680
- ),
681
- captionLayout,
682
- formatters: {
683
- formatMonthDropdown: (date) => date.toLocaleString("default", { month: "short" }),
684
- ...formatters
685
- },
686
- classNames: {
687
- root: cn("w-fit", defaultClassNames.root),
688
- months: cn(
689
- "flex gap-4 flex-col md:flex-row relative",
690
- defaultClassNames.months
691
- ),
692
- month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
693
- nav: cn(
694
- "flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
695
- defaultClassNames.nav
696
- ),
697
- button_previous: cn(
698
- buttonVariants({ variant: buttonVariant }),
699
- "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
700
- defaultClassNames.button_previous
701
- ),
702
- button_next: cn(
703
- buttonVariants({ variant: buttonVariant }),
704
- "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
705
- defaultClassNames.button_next
706
- ),
707
- month_caption: cn(
708
- "flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
709
- defaultClassNames.month_caption
710
- ),
711
- dropdowns: cn(
712
- "w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
713
- defaultClassNames.dropdowns
714
- ),
715
- dropdown_root: cn(
716
- "relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
717
- defaultClassNames.dropdown_root
718
- ),
719
- dropdown: cn(
720
- "absolute bg-popover inset-0 opacity-0",
721
- defaultClassNames.dropdown
722
- ),
723
- caption_label: cn(
724
- "select-none font-medium",
725
- captionLayout === "label" ? "text-sm" : "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
726
- defaultClassNames.caption_label
727
- ),
728
- table: "w-full border-collapse",
729
- weekdays: cn("flex", defaultClassNames.weekdays),
730
- weekday: cn(
731
- "text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
732
- defaultClassNames.weekday
733
- ),
734
- week: cn("flex w-full mt-2", defaultClassNames.week),
735
- week_number_header: cn(
736
- "select-none w-(--cell-size)",
737
- defaultClassNames.week_number_header
738
- ),
739
- week_number: cn(
740
- "text-[0.8rem] select-none text-muted-foreground",
741
- defaultClassNames.week_number
742
- ),
743
- day: cn(
744
- "relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
745
- props.showWeekNumber ? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-md" : "[&:first-child[data-selected=true]_button]:rounded-l-md",
746
- defaultClassNames.day
747
- ),
748
- range_start: cn(
749
- "rounded-l-md bg-accent",
750
- defaultClassNames.range_start
751
- ),
752
- range_middle: cn("rounded-none", defaultClassNames.range_middle),
753
- range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
754
- today: cn(
755
- "bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
756
- defaultClassNames.today
757
- ),
758
- outside: cn(
759
- "text-muted-foreground aria-selected:text-muted-foreground",
760
- defaultClassNames.outside
761
- ),
762
- disabled: cn(
763
- "text-muted-foreground opacity-50",
764
- defaultClassNames.disabled
765
- ),
766
- hidden: cn("invisible", defaultClassNames.hidden),
767
- ...classNames
768
- },
769
- components: {
770
- Root: ({ className: className2, rootRef, ...props2 }) => {
771
- return /* @__PURE__ */ jsxRuntime.jsx(
772
- "div",
773
- {
774
- "data-slot": "calendar",
775
- ref: rootRef,
776
- className: cn(className2),
777
- ...props2
778
- }
779
- );
780
- },
781
- Chevron: ({ className: className2, orientation, ...props2 }) => {
782
- if (orientation === "left") {
783
- return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, { className: cn("size-4", className2), ...props2 });
784
- }
785
- if (orientation === "right") {
786
- return /* @__PURE__ */ jsxRuntime.jsx(
787
- lucideReact.ChevronRightIcon,
788
- {
789
- className: cn("size-4", className2),
790
- ...props2
791
- }
792
- );
793
- }
794
- return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { className: cn("size-4", className2), ...props2 });
795
- },
796
- DayButton: CalendarDayButton,
797
- WeekNumber: ({ children, ...props2 }) => {
798
- return /* @__PURE__ */ jsxRuntime.jsx("td", { ...props2, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-(--cell-size) items-center justify-center text-center", children }) });
799
- },
800
- ...components
801
- },
802
- ...props
803
- }
804
- );
805
- }
806
- function CalendarDayButton({
807
- className,
808
- day,
809
- modifiers,
810
- ...props
811
- }) {
812
- const defaultClassNames = reactDayPicker.getDefaultClassNames();
813
- const ref = React2__namespace.useRef(null);
814
- React2__namespace.useEffect(() => {
815
- if (modifiers.focused) ref.current?.focus();
816
- }, [modifiers.focused]);
817
- return /* @__PURE__ */ jsxRuntime.jsx(
818
- Button,
819
- {
820
- ref,
821
- variant: "ghost",
822
- size: "icon",
823
- "data-day": day.date.toLocaleDateString(),
824
- "data-selected-single": modifiers.selected && !modifiers.range_start && !modifiers.range_end && !modifiers.range_middle,
825
- "data-range-start": modifiers.range_start,
826
- "data-range-end": modifiers.range_end,
827
- "data-range-middle": modifiers.range_middle,
828
- className: cn(
829
- "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",
830
- defaultClassNames.day,
831
- className
832
- ),
833
- ...props
834
- }
835
- );
836
- }
837
- var DateField = React2.memo(function DateField2({
838
- name,
839
- label,
840
- placeholder = "Pick a date"
841
- }) {
842
- const { isEditing } = useFormCtx();
843
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => !isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(
844
- Button,
845
- {
846
- type: "button",
847
- variant: "outline",
848
- className: cn(
849
- "w-full justify-start text-left font-normal bg-background/50",
850
- !field.value && "text-muted-foreground"
851
- ),
852
- disabled: true,
853
- children: [
854
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, { className: "mr-2 h-4 w-4" }),
855
- field.value ? dateFns.format(new Date(field.value), "PPP") : /* @__PURE__ */ jsxRuntime.jsx("span", { children: placeholder })
856
- ]
857
- }
858
- ) : /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
859
- /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
860
- Button,
861
- {
862
- variant: "outline",
863
- className: cn(
864
- "w-full justify-start text-left font-normal",
865
- !field.value && "text-muted-foreground"
866
- ),
867
- children: [
868
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, { className: "mr-2 h-4 w-4" }),
869
- field.value ? dateFns.format(new Date(field.value), "PPP") : /* @__PURE__ */ jsxRuntime.jsx("span", { children: placeholder })
870
- ]
871
- }
872
- ) }),
873
- /* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ jsxRuntime.jsx(
874
- Calendar,
875
- {
876
- mode: "single",
877
- selected: field.value ? new Date(field.value) : void 0,
878
- onSelect: field.onChange,
879
- initialFocus: true
880
- }
881
- ) })
882
- ] }) });
883
- });
884
- var date_field_default = DateField;
885
- var FileField = React2.memo(function FileField2({
886
- name,
887
- label,
888
- accept,
889
- multiple
890
- }) {
891
- const { isEditing } = useFormCtx();
892
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => {
893
- const files = field.value;
894
- const filename = files && files.length ? multiple ? `${files.length} files` : files[0].name : "";
895
- if (!isEditing) {
896
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center", children: [
897
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { className: "absolute left-3 text-muted-foreground h-4 w-4 z-10" }),
898
- /* @__PURE__ */ jsxRuntime.jsx(
899
- Input,
900
- {
901
- id: `${String(name)}_display`,
902
- type: "text",
903
- value: filename,
904
- placeholder: accept ? `Accepts ${accept}` : "No file selected",
905
- readOnly: true,
906
- disabled: true,
907
- className: "bg-background/50 opacity-80 pl-10"
908
- }
909
- )
910
- ] });
911
- }
912
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center", children: [
913
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { className: "absolute left-3 text-muted-foreground h-4 w-4 z-10 pointer-events-none" }),
914
- /* @__PURE__ */ jsxRuntime.jsx(
915
- Input,
916
- {
917
- id: String(name),
918
- type: "file",
919
- accept,
920
- multiple,
921
- onChange: (e) => field.onChange(e.target.files),
922
- onBlur: field.onBlur,
923
- name: field.name,
924
- ref: field.ref,
925
- className: "pl-10"
926
- }
927
- )
928
- ] });
929
- } });
930
- });
931
- var file_field_default = FileField;
932
- function Avatar({
933
- className,
934
- ...props
935
- }) {
936
- return /* @__PURE__ */ jsxRuntime.jsx(
937
- AvatarPrimitive__namespace.Root,
938
- {
939
- "data-slot": "avatar",
940
- className: cn(
941
- "relative flex size-8 shrink-0 overflow-hidden rounded-full",
942
- className
943
- ),
944
- ...props
945
- }
946
- );
947
- }
948
- function AvatarImage({
949
- className,
950
- ...props
951
- }) {
952
- return /* @__PURE__ */ jsxRuntime.jsx(
953
- AvatarPrimitive__namespace.Image,
954
- {
955
- "data-slot": "avatar-image",
956
- className: cn("aspect-square size-full", className),
957
- ...props
958
- }
959
- );
960
- }
961
- function AvatarFallback({
962
- className,
963
- ...props
964
- }) {
965
- return /* @__PURE__ */ jsxRuntime.jsx(
966
- AvatarPrimitive__namespace.Fallback,
967
- {
968
- "data-slot": "avatar-fallback",
969
- className: cn(
970
- "bg-muted flex size-full items-center justify-center rounded-full",
971
- className
972
- ),
973
- ...props
974
- }
975
- );
976
- }
977
- var ProfilePictureField = React2.memo(function ProfilePictureField2({
978
- name,
979
- label,
980
- className,
981
- avatarClassName,
982
- fallback = "User"
983
- }) {
984
- const { isEditing } = useFormCtx();
985
- const [preview, setPreview] = React2.useState(null);
986
- return /* @__PURE__ */ jsxRuntime.jsx(field_default, { name, label, children: (field) => {
987
- const currentValue = field.value;
988
- const displayUrl = preview || (typeof currentValue === "string" ? currentValue : null);
989
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col items-center gap-4", className), children: [
990
- /* @__PURE__ */ jsxRuntime.jsxs(Avatar, { className: cn("h-24 w-24", avatarClassName), children: [
991
- /* @__PURE__ */ jsxRuntime.jsx(AvatarImage, { src: displayUrl || "", alt: "Profile picture" }),
992
- /* @__PURE__ */ jsxRuntime.jsx(AvatarFallback, { children: fallback })
993
- ] }),
994
- isEditing && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
995
- /* @__PURE__ */ jsxRuntime.jsxs(
996
- Label,
997
- {
998
- htmlFor: String(name),
999
- className: "cursor-pointer inline-flex items-center gap-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground",
1000
- children: [
1001
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { className: "h-4 w-4" }),
1002
- "Upload Picture"
1003
- ]
1004
- }
1005
- ),
1006
- /* @__PURE__ */ jsxRuntime.jsx(
1007
- Input,
1008
- {
1009
- id: String(name),
1010
- type: "file",
1011
- accept: "image/*",
1012
- className: "hidden",
1013
- onChange: (e) => {
1014
- const file = e.target.files?.[0];
1015
- if (file) {
1016
- field.onChange(file);
1017
- const reader = new FileReader();
1018
- reader.onloadend = () => {
1019
- setPreview(reader.result);
1020
- };
1021
- reader.readAsDataURL(file);
1022
- }
1023
- },
1024
- onBlur: field.onBlur,
1025
- name: field.name,
1026
- ref: field.ref
1027
- }
1028
- ),
1029
- displayUrl && /* @__PURE__ */ jsxRuntime.jsx(
1030
- Button,
1031
- {
1032
- variant: "ghost",
1033
- size: "sm",
1034
- type: "button",
1035
- onClick: () => {
1036
- field.onChange(null);
1037
- setPreview(null);
1038
- },
1039
- children: "Remove"
1040
- }
1041
- )
1042
- ] })
1043
- ] });
1044
- } });
1045
- });
1046
- var profile_picture_field_default = ProfilePictureField;
1047
- var Button2 = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
1048
- "button",
1049
- {
1050
- className: "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2",
1051
- ...props,
1052
- children
1053
- }
1054
- );
1055
- function Submit({ children, ...props }) {
1056
- const form = useFormCtx();
1057
- const isPending = form.isPending || form.formState.isSubmitting;
1058
- const { isEditing } = form;
1059
- if (!isEditing) return null;
1060
- return /* @__PURE__ */ jsxRuntime.jsx(Button2, { type: "submit", disabled: isPending || props.disabled, ...props, children: isPending ? "Submitting..." : children });
1061
- }
1062
- var submit_default = Submit;
1063
- function EditButton({ children, formId, ...props }) {
1064
- const ctx = React2.useContext(FormContext);
1065
- if (ctx) {
1066
- const { isEditing, setIsEditing } = ctx;
1067
- if (isEditing) return null;
1068
- return /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: () => setIsEditing?.(true), ...props, children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1069
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4 mr-2" }),
1070
- "Edit Profile"
1071
- ] }) });
1072
- }
1073
- const handleClick = () => {
1074
- const key = formId ?? DEFAULT_FORM_KEY;
1075
- const immediate = formRegistry.get(key);
1076
- if (immediate) return immediate(true);
1077
- let attempts = 0;
1078
- const maxAttempts = 20;
1079
- const interval = setInterval(() => {
1080
- attempts += 1;
1081
- const setter = formRegistry.get(key);
1082
- if (setter) {
1083
- setter(true);
1084
- clearInterval(interval);
1085
- } else if (attempts >= maxAttempts) {
1086
- clearInterval(interval);
1087
- }
1088
- }, 100);
1089
- };
1090
- return /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: handleClick, ...props, children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1091
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4 mr-2" }),
1092
- "Edit Profile"
1093
- ] }) });
1094
- }
1095
- var edit_button_default = EditButton;
1096
- function CancelButton({ children, ...props }) {
1097
- const { isEditing, setIsEditing, reset } = useFormCtx();
1098
- if (!isEditing) return null;
1099
- return /* @__PURE__ */ jsxRuntime.jsx(
1100
- Button,
1101
- {
1102
- type: "button",
1103
- variant: "outline",
1104
- onClick: () => {
1105
- reset();
1106
- setIsEditing?.(false);
1107
- },
1108
- ...props,
1109
- children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1110
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4 mr-2" }),
1111
- "Cancel"
1112
- ] })
1113
- }
1114
- );
1115
- }
1116
- var cancel_button_default = CancelButton;
1117
- function LinkField({ label, link, LinkComponent, className }) {
1118
- const LinkTag = LinkComponent || "a";
1119
- const linkProps = { href: link };
1120
- return /* @__PURE__ */ jsxRuntime.jsx(
1121
- LinkTag,
1122
- {
1123
- ...linkProps,
1124
- className: cn("text-sm text-primary hover:underline", className),
1125
- children: label
1126
- }
1127
- );
1128
- }
1129
- var link_field_default = LinkField;
1130
- function FieldGroup({ children, className, title }) {
1131
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-4", className), children: [
1132
- title && /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-lg font-medium", children: title }),
1133
- children
1134
- ] });
1135
- }
1136
- var field_group_default = FieldGroup;
1137
-
1138
- // src/components/form/index.ts
1139
- var Form = Object.assign(root_default, {
1140
- Root: root_default,
1141
- Field: field_default,
1142
- InputField: input_field_default,
1143
- PasswordField: password_field_default,
1144
- TextareaField: textarea_field_default,
1145
- SelectField: select_field_default,
1146
- CheckboxField: checkbox_field_default,
1147
- DateField: date_field_default,
1148
- FileField: file_field_default,
1149
- ProfilePictureField: profile_picture_field_default,
1150
- Submit: submit_default,
1151
- EditButton: edit_button_default,
1152
- CancelButton: cancel_button_default,
1153
- Group: field_group_default,
1154
- LinkField: link_field_default
1155
- });
1156
- var form_default = Form;
1157
- var DataTableContext = React2.createContext(null);
1158
- function useDataTable() {
1159
- const context = React2.useContext(DataTableContext);
1160
- if (!context) {
1161
- throw new Error("DataTable components must be used within DataTable.Root");
1162
- }
1163
- return context;
1164
- }
1165
- function Root7({
1166
- columns,
1167
- data,
1168
- filters = [],
1169
- defaultViewMode = "table",
1170
- viewMode: controlledViewMode,
1171
- onViewModeChange: controlledOnViewModeChange,
1172
- defaultPageSize = 10,
1173
- children
1174
- }) {
1175
- const [internalViewMode, setInternalViewMode] = React2.useState(defaultViewMode);
1176
- const [sorting, setSorting] = React2.useState([]);
1177
- const [columnFilters, setColumnFilters] = React2.useState([]);
1178
- const [columnVisibility, setColumnVisibility] = React2.useState({});
1179
- const [globalFilter, setGlobalFilter] = React2.useState("");
1180
- const [pagination, setPagination] = React2.useState({ pageIndex: 0, pageSize: defaultPageSize });
1181
- const [activeFilters, setActiveFilters] = React2.useState({});
1182
- const isControlled = controlledViewMode !== void 0 && controlledOnViewModeChange !== void 0;
1183
- const viewMode = isControlled ? controlledViewMode : internalViewMode;
1184
- const setViewMode = isControlled ? controlledOnViewModeChange : setInternalViewMode;
1185
- const filteredData = React2.useMemo(() => {
1186
- if (Object.keys(activeFilters).length === 0) return data;
1187
- return data.filter((row) => {
1188
- return Object.entries(activeFilters).every(([filterId, filterValue]) => {
1189
- if (!filterValue || Array.isArray(filterValue) && filterValue.length === 0) {
1190
- return true;
1191
- }
1192
- const rowValue = row[filterId];
1193
- if (Array.isArray(filterValue)) {
1194
- return filterValue.includes(String(rowValue));
1195
- }
1196
- return String(rowValue) === String(filterValue);
1197
- });
1198
- });
1199
- }, [data, activeFilters]);
1200
- const table = reactTable.useReactTable({
1201
- data: filteredData,
1202
- columns,
1203
- state: {
1204
- sorting,
1205
- columnFilters,
1206
- columnVisibility,
1207
- globalFilter,
1208
- pagination
1209
- },
1210
- onSortingChange: setSorting,
1211
- onColumnFiltersChange: setColumnFilters,
1212
- onColumnVisibilityChange: setColumnVisibility,
1213
- onGlobalFilterChange: setGlobalFilter,
1214
- onPaginationChange: setPagination,
1215
- getCoreRowModel: reactTable.getCoreRowModel(),
1216
- getFilteredRowModel: reactTable.getFilteredRowModel(),
1217
- getSortedRowModel: reactTable.getSortedRowModel(),
1218
- getPaginationRowModel: reactTable.getPaginationRowModel()
1219
- });
222
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { className: "size-4" })
223
+ }
224
+ );
225
+ }
226
+ function SelectScrollDownButton({
227
+ className,
228
+ ...props
229
+ }) {
1220
230
  return /* @__PURE__ */ jsxRuntime.jsx(
1221
- DataTableContext.Provider,
231
+ SelectPrimitive__namespace.ScrollDownButton,
1222
232
  {
1223
- value: {
1224
- table,
1225
- viewMode,
1226
- setViewMode,
1227
- filters,
1228
- activeFilters,
1229
- setActiveFilters
1230
- },
1231
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children })
233
+ "data-slot": "select-scroll-down-button",
234
+ className: cn(
235
+ "flex cursor-default items-center justify-center py-1",
236
+ className
237
+ ),
238
+ ...props,
239
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDownIcon, { className: "size-4" })
1232
240
  }
1233
241
  );
1234
242
  }
1235
- var root_default2 = Root7;
1236
- function ViewOptions({ viewMode: propViewMode, onViewModeChange: propOnViewModeChange }) {
1237
- let contextStr;
1238
- try {
1239
- contextStr = useDataTable();
1240
- } catch (e) {
1241
- }
1242
- const mode = propViewMode ?? contextStr?.viewMode ?? "table";
1243
- const setMode = propOnViewModeChange ?? contextStr?.setViewMode ?? (() => {
1244
- });
1245
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center border rounded-md bg-background", children: [
1246
- /* @__PURE__ */ jsxRuntime.jsx(
1247
- Button,
1248
- {
1249
- variant: mode === "table" ? "secondary" : "ghost",
1250
- size: "sm",
1251
- onClick: () => setMode("table"),
1252
- className: "rounded-r-none h-8 px-2 lg:px-3",
1253
- "aria-label": "Switch to table view",
1254
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Table, { className: "h-4 w-4" })
1255
- }
1256
- ),
1257
- /* @__PURE__ */ jsxRuntime.jsx(
1258
- Button,
1259
- {
1260
- variant: mode === "grid" ? "secondary" : "ghost",
1261
- size: "sm",
1262
- onClick: () => setMode("grid"),
1263
- className: "rounded-l-none h-8 px-2 lg:px-3",
1264
- "aria-label": "Switch to grid view",
1265
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.LayoutGrid, { className: "h-4 w-4" })
1266
- }
1267
- )
1268
- ] });
1269
- }
1270
- var view_options_default = ViewOptions;
1271
- function Toolbar({ viewOptions } = {}) {
1272
- const { table, filters, activeFilters, setActiveFilters } = useDataTable();
243
+ function Toolbar() {
244
+ const { filters, showFilters, globalFilter, setGlobalFilter, table } = useDataTableContext();
245
+ const [activeFilters, setActiveFilters] = React2.useState({});
1273
246
  const handleFilterChange = (filterId, value) => {
1274
- setActiveFilters((prev) => ({
1275
- ...prev,
1276
- [filterId]: value === "all" ? "" : value
1277
- }));
1278
- };
1279
- const handleMultiFilterToggle = (filterId, value) => {
1280
- setActiveFilters((prev) => {
1281
- const current = prev[filterId];
1282
- if (!current || !Array.isArray(current)) {
1283
- return { ...prev, [filterId]: [value] };
1284
- }
1285
- const newValues = current.includes(value) ? current.filter((v) => v !== value) : [...current, value];
1286
- return { ...prev, [filterId]: newValues };
1287
- });
247
+ setActiveFilters((prev) => ({ ...prev, [filterId]: value }));
248
+ if (value === "all" || value === "") {
249
+ table.getColumn(filterId)?.setFilterValue(void 0);
250
+ } else {
251
+ table.getColumn(filterId)?.setFilterValue(value);
252
+ }
1288
253
  };
1289
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 py-4", children: [
1290
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
1291
- Input,
1292
- {
1293
- placeholder: "Search...",
1294
- value: table.getState().globalFilter ?? "",
1295
- onChange: (e) => table.setGlobalFilter(e.target.value),
1296
- className: "w-full max-w-sm"
1297
- }
1298
- ) }),
1299
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4", children: [
1300
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-wrap flex-1", children: [
1301
- filters.map((filter) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: filter.multiSelect ? /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
1302
- /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", className: "h-8 border-dashed", children: [
1303
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SlidersHorizontal, { className: "h-4 w-4 mr-2" }),
1304
- filter.label,
1305
- activeFilters[filter.id] && (Array.isArray(activeFilters[filter.id]) ? activeFilters[filter.id].length > 0 : true) && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1 rounded-sm bg-primary px-1 text-xs text-primary-foreground", children: Array.isArray(activeFilters[filter.id]) ? activeFilters[filter.id].length : 1 })
1306
- ] }) }),
1307
- /* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-[200px] p-0", align: "start", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-1", children: [
1308
- filter.options.map((option) => /* @__PURE__ */ jsxRuntime.jsxs(
1309
- "div",
1310
- {
1311
- className: "flex items-center space-x-2 rounded-sm px-2 py-1.5 hover:bg-accent cursor-pointer",
1312
- onClick: () => handleMultiFilterToggle(filter.id, option.value),
1313
- children: [
1314
- /* @__PURE__ */ jsxRuntime.jsx(
1315
- Checkbox,
1316
- {
1317
- id: `${filter.id}-${option.value}`,
1318
- checked: Array.isArray(activeFilters[filter.id]) && activeFilters[filter.id].includes(option.value)
1319
- }
1320
- ),
1321
- /* @__PURE__ */ jsxRuntime.jsx(
1322
- "label",
1323
- {
1324
- htmlFor: `${filter.id}-${option.value}`,
1325
- className: "text-sm cursor-pointer flex-1",
1326
- children: option.label
1327
- }
1328
- )
1329
- ]
1330
- },
1331
- option.value
1332
- )),
1333
- activeFilters[filter.id] && (Array.isArray(activeFilters[filter.id]) ? activeFilters[filter.id].length > 0 : false) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1334
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-px bg-border my-1" }),
1335
- /* @__PURE__ */ jsxRuntime.jsx(
1336
- "div",
1337
- {
1338
- className: "px-2 py-1.5 text-center text-sm cursor-pointer hover:bg-accent rounded-sm",
1339
- onClick: () => setActiveFilters((prev) => ({ ...prev, [filter.id]: [] })),
1340
- children: "Clear filters"
1341
- }
1342
- )
254
+ const hasFilters = filters && filters.length > 0;
255
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2", children: [
256
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-1 flex-wrap", children: [
257
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-sm w-full sm:w-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
258
+ Input,
259
+ {
260
+ placeholder: "Search...",
261
+ value: globalFilter ?? "",
262
+ onChange: (e) => setGlobalFilter(e.target.value),
263
+ className: "w-full"
264
+ }
265
+ ) }),
266
+ hasFilters && showFilters && filters.map((filter) => /* @__PURE__ */ jsxRuntime.jsxs(
267
+ Select,
268
+ {
269
+ onValueChange: (val) => handleFilterChange(filter.id, val),
270
+ children: [
271
+ /* @__PURE__ */ jsxRuntime.jsxs(SelectTrigger, { className: "h-9 cursor-pointer w-[140px] rounded-md border border-input bg-background px-2 text-sm", children: [
272
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Filter, { className: "h-4 w-4 mr-2 text-muted-foreground" }),
273
+ /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: filter.label })
274
+ ] }),
275
+ /* @__PURE__ */ jsxRuntime.jsxs(SelectContent, { children: [
276
+ /* @__PURE__ */ jsxRuntime.jsxs(SelectItem, { value: "all", children: [
277
+ "All ",
278
+ filter.label
279
+ ] }),
280
+ filter.options.map((opt) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))
1343
281
  ] })
1344
- ] }) })
1345
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(
1346
- Select,
1347
- {
1348
- value: activeFilters[filter.id] || "all",
1349
- onValueChange: (value) => handleFilterChange(filter.id, value),
1350
- children: [
1351
- /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 w-[150px] border-dashed", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, { placeholder: filter.placeholder || filter.label }) }),
1352
- /* @__PURE__ */ jsxRuntime.jsxs(SelectContent, { children: [
1353
- /* @__PURE__ */ jsxRuntime.jsxs(SelectItem, { value: "all", children: [
1354
- "All ",
1355
- filter.label
1356
- ] }),
1357
- filter.options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: option.value, children: option.label }, option.value))
1358
- ] })
1359
- ]
1360
- }
1361
- ) }, filter.id)),
1362
- /* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
1363
- /* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(Button, { variant: "outline", size: "sm", className: "h-8 ml-auto sm:ml-0", children: [
1364
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "h-4 w-4 mr-2" }),
1365
- "Columns"
1366
- ] }) }),
1367
- /* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-56", align: "end", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
1368
- /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "font-medium text-sm", children: "Toggle Columns" }),
1369
- table.getAllColumns().filter((column) => column.getCanHide()).map((column) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center space-x-2", children: [
1370
- /* @__PURE__ */ jsxRuntime.jsx(
1371
- Checkbox,
1372
- {
1373
- id: column.id,
1374
- checked: column.getIsVisible(),
1375
- onCheckedChange: (value) => column.toggleVisibility(!!value)
1376
- }
1377
- ),
1378
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: column.id, className: "text-sm cursor-pointer", children: column.id })
1379
- ] }, column.id))
1380
- ] }) })
1381
- ] })
1382
- ] }),
1383
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
1384
- viewOptions ? viewOptions : /* @__PURE__ */ jsxRuntime.jsx(ViewOptions, {}),
1385
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
1386
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-sm text-muted-foreground whitespace-nowrap hidden sm:inline-block", children: "Rows" }),
1387
- /* @__PURE__ */ jsxRuntime.jsxs(
1388
- Select,
1389
- {
1390
- value: String(table.getState().pagination.pageSize),
1391
- onValueChange: (value) => table.setPageSize(Number(value)),
1392
- children: [
1393
- /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "w-16 h-8", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {}) }),
1394
- /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: [10, 20, 30, 40, 50].map((size) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: String(size), children: size }, size)) })
1395
- ]
1396
- }
1397
- )
1398
- ] })
1399
- ] })
282
+ ]
283
+ },
284
+ filter.id
285
+ ))
286
+ ] }),
287
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
288
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "text-sm text-muted-foreground hidden sm:block", children: "Rows" }),
289
+ /* @__PURE__ */ jsxRuntime.jsxs(
290
+ Select,
291
+ {
292
+ value: String(table.getState().pagination.pageSize),
293
+ onValueChange: (val) => {
294
+ table.setPageSize(Number(val));
295
+ },
296
+ children: [
297
+ /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "h-8 cursor-pointer rounded-md border border-input bg-background px-2 text-sm w-[70px]", children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {}) }),
298
+ /* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: [10, 20, 30, 40, 50].map((s) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: String(s), children: s }, s)) })
299
+ ]
300
+ }
301
+ )
1400
302
  ] })
1401
303
  ] });
1402
304
  }
1403
- var toolbar_default = Toolbar;
1404
305
  function Table({ className, ...props }) {
1405
306
  return /* @__PURE__ */ jsxRuntime.jsx(
1406
307
  "div",
@@ -1477,8 +378,15 @@ function TableCell({ className, ...props }) {
1477
378
  }
1478
379
  );
1479
380
  }
1480
- function TableView() {
1481
- const { table } = useDataTable();
381
+ function Content2({ renderCard }) {
382
+ const { table, viewMode } = useDataTableContext();
383
+ const columns = table.getAllColumns();
384
+ if (viewMode === "grid") {
385
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4", children: [
386
+ table.getRowModel().rows.map((row, index) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderCard ? renderCard(row.original, index) : JSON.stringify(row.original) }, row.id)),
387
+ table.getRowModel().rows.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-full text-center py-8 text-muted-foreground", children: "No results." })
388
+ ] });
389
+ }
1482
390
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { children: [
1483
391
  /* @__PURE__ */ jsxRuntime.jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { children: headerGroup.headers.map((header) => {
1484
392
  const canSort = header.column.getCanSort();
@@ -1487,66 +395,207 @@ function TableView() {
1487
395
  "button",
1488
396
  {
1489
397
  className: "flex items-center gap-2",
1490
- onClick: () => canSort && header.column.toggleSorting(),
398
+ onClick: header.column.getToggleSortingHandler(),
399
+ disabled: !canSort,
1491
400
  children: [
1492
- reactTable.flexRender(header.column.columnDef.header, header.getContext()),
401
+ reactTable.flexRender(
402
+ header.column.columnDef.header,
403
+ header.getContext()
404
+ ),
1493
405
  canSort && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-2", children: sortState === "asc" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "h-3 w-3" }) : sortState === "desc" ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowDown, { className: "h-3 w-3" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUpDown, { className: "h-3 w-3 opacity-50" }) })
1494
406
  ]
1495
407
  }
1496
408
  ) }, header.id);
1497
409
  }) }, headerGroup.id)) }),
1498
- /* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsxRuntime.jsx(TableRow, { "data-state": row.getIsSelected() && "selected", children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id)) }, row.id)) : /* @__PURE__ */ jsxRuntime.jsx(TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(TableCell, { colSpan: table.getAllColumns().length, className: "h-24 text-center", children: "No results." }) }) })
410
+ /* @__PURE__ */ jsxRuntime.jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsxRuntime.jsx(
411
+ TableRow,
412
+ {
413
+ "data-state": row.getIsSelected() && "selected",
414
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsxRuntime.jsx(TableCell, { children: reactTable.flexRender(
415
+ cell.column.columnDef.cell,
416
+ cell.getContext()
417
+ ) }, cell.id))
418
+ },
419
+ row.id
420
+ )) : /* @__PURE__ */ jsxRuntime.jsx(TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(
421
+ TableCell,
422
+ {
423
+ colSpan: columns.length,
424
+ className: "h-24 text-center",
425
+ children: "No results."
426
+ }
427
+ ) }) })
1499
428
  ] }) });
1500
429
  }
1501
- var table_view_default = TableView;
1502
- function GridView({ renderCard, columns = 3, gap = 16 }) {
1503
- const { table } = useDataTable();
1504
- const rows = table.getRowModel().rows;
1505
- if (!rows.length) {
1506
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center h-64 text-muted-foreground", children: "No results." });
430
+ function setRef(ref, value) {
431
+ if (typeof ref === "function") {
432
+ return ref(value);
433
+ } else if (ref !== null && ref !== void 0) {
434
+ ref.current = value;
1507
435
  }
1508
- return /* @__PURE__ */ jsxRuntime.jsx(
1509
- "div",
1510
- {
1511
- className: "grid",
1512
- style: {
1513
- gridTemplateColumns: `repeat(${columns}, 1fr)`,
1514
- gap: `${gap}px`
1515
- },
1516
- children: rows.map((row, index) => {
1517
- const item = row.original;
1518
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border bg-card p-4 shadow-sm", children: renderCard ? renderCard(item, index) : /* @__PURE__ */ jsxRuntime.jsx(DefaultCard, { item }) }, row.id);
1519
- })
436
+ }
437
+ function composeRefs(...refs) {
438
+ return (node) => {
439
+ let hasCleanup = false;
440
+ const cleanups = refs.map((ref) => {
441
+ const cleanup = setRef(ref, node);
442
+ if (!hasCleanup && typeof cleanup == "function") {
443
+ hasCleanup = true;
444
+ }
445
+ return cleanup;
446
+ });
447
+ if (hasCleanup) {
448
+ return () => {
449
+ for (let i = 0; i < cleanups.length; i++) {
450
+ const cleanup = cleanups[i];
451
+ if (typeof cleanup == "function") {
452
+ cleanup();
453
+ } else {
454
+ setRef(refs[i], null);
455
+ }
456
+ }
457
+ };
1520
458
  }
1521
- );
459
+ };
1522
460
  }
1523
- function DefaultCard({ item }) {
1524
- if (typeof item !== "object" || item === null) return null;
1525
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: Object.entries(item).map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1526
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm font-medium", children: [
1527
- key,
1528
- ": "
1529
- ] }),
1530
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: String(value) })
1531
- ] }, key)) });
461
+ // @__NO_SIDE_EFFECTS__
462
+ function createSlot(ownerName) {
463
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
464
+ const Slot2 = React2__namespace.forwardRef((props, forwardedRef) => {
465
+ const { children, ...slotProps } = props;
466
+ const childrenArray = React2__namespace.Children.toArray(children);
467
+ const slottable = childrenArray.find(isSlottable);
468
+ if (slottable) {
469
+ const newElement = slottable.props.children;
470
+ const newChildren = childrenArray.map((child) => {
471
+ if (child === slottable) {
472
+ if (React2__namespace.Children.count(newElement) > 1) return React2__namespace.Children.only(null);
473
+ return React2__namespace.isValidElement(newElement) ? newElement.props.children : null;
474
+ } else {
475
+ return child;
476
+ }
477
+ });
478
+ return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React2__namespace.isValidElement(newElement) ? React2__namespace.cloneElement(newElement, void 0, newChildren) : null });
479
+ }
480
+ return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
481
+ });
482
+ Slot2.displayName = `${ownerName}.Slot`;
483
+ return Slot2;
1532
484
  }
1533
- var grid_view_default = GridView;
1534
- function Content3({ renderCard, gridColumns, gridGap }) {
1535
- const { viewMode } = useDataTable();
1536
- if (viewMode === "grid") {
1537
- return /* @__PURE__ */ jsxRuntime.jsx(grid_view_default, { renderCard, columns: gridColumns, gap: gridGap });
485
+ var Slot = /* @__PURE__ */ createSlot("Slot");
486
+ // @__NO_SIDE_EFFECTS__
487
+ function createSlotClone(ownerName) {
488
+ const SlotClone = React2__namespace.forwardRef((props, forwardedRef) => {
489
+ const { children, ...slotProps } = props;
490
+ if (React2__namespace.isValidElement(children)) {
491
+ const childrenRef = getElementRef(children);
492
+ const props2 = mergeProps(slotProps, children.props);
493
+ if (children.type !== React2__namespace.Fragment) {
494
+ props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
495
+ }
496
+ return React2__namespace.cloneElement(children, props2);
497
+ }
498
+ return React2__namespace.Children.count(children) > 1 ? React2__namespace.Children.only(null) : null;
499
+ });
500
+ SlotClone.displayName = `${ownerName}.SlotClone`;
501
+ return SlotClone;
502
+ }
503
+ var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
504
+ function isSlottable(child) {
505
+ return React2__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
506
+ }
507
+ function mergeProps(slotProps, childProps) {
508
+ const overrideProps = { ...childProps };
509
+ for (const propName in childProps) {
510
+ const slotPropValue = slotProps[propName];
511
+ const childPropValue = childProps[propName];
512
+ const isHandler = /^on[A-Z]/.test(propName);
513
+ if (isHandler) {
514
+ if (slotPropValue && childPropValue) {
515
+ overrideProps[propName] = (...args) => {
516
+ const result = childPropValue(...args);
517
+ slotPropValue(...args);
518
+ return result;
519
+ };
520
+ } else if (slotPropValue) {
521
+ overrideProps[propName] = slotPropValue;
522
+ }
523
+ } else if (propName === "style") {
524
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
525
+ } else if (propName === "className") {
526
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
527
+ }
528
+ }
529
+ return { ...slotProps, ...overrideProps };
530
+ }
531
+ function getElementRef(element) {
532
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
533
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
534
+ if (mayWarn) {
535
+ return element.ref;
536
+ }
537
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
538
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
539
+ if (mayWarn) {
540
+ return element.props.ref;
541
+ }
542
+ return element.props.ref || element.ref;
543
+ }
544
+ var buttonVariants = classVarianceAuthority.cva(
545
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
546
+ {
547
+ variants: {
548
+ variant: {
549
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
550
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
551
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
552
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
553
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
554
+ link: "text-primary underline-offset-4 hover:underline"
555
+ },
556
+ size: {
557
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
558
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
559
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
560
+ icon: "size-9",
561
+ "icon-sm": "size-8",
562
+ "icon-lg": "size-10"
563
+ }
564
+ },
565
+ defaultVariants: {
566
+ variant: "default",
567
+ size: "default"
568
+ }
1538
569
  }
1539
- return /* @__PURE__ */ jsxRuntime.jsx(table_view_default, {});
570
+ );
571
+ function Button({
572
+ className,
573
+ variant = "default",
574
+ size = "default",
575
+ asChild = false,
576
+ ...props
577
+ }) {
578
+ const Comp = asChild ? Slot : "button";
579
+ return /* @__PURE__ */ jsxRuntime.jsx(
580
+ Comp,
581
+ {
582
+ "data-slot": "button",
583
+ "data-variant": variant,
584
+ "data-size": size,
585
+ className: cn(buttonVariants({ variant, size, className })),
586
+ ...props
587
+ }
588
+ );
1540
589
  }
1541
- var content_default = Content3;
1542
590
  function Pagination() {
1543
- const { table } = useDataTable();
591
+ const { table } = useDataTableContext();
1544
592
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between py-4", children: [
1545
593
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm text-muted-foreground", children: [
1546
594
  "Showing",
1547
595
  " ",
1548
596
  table.getState().pagination.pageIndex * table.getState().pagination.pageSize + 1,
1549
- " -",
597
+ " ",
598
+ "-",
1550
599
  " ",
1551
600
  Math.min(
1552
601
  (table.getState().pagination.pageIndex + 1) * table.getState().pagination.pageSize,
@@ -1570,7 +619,8 @@ function Pagination() {
1570
619
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 text-sm", children: [
1571
620
  "Page ",
1572
621
  table.getState().pagination.pageIndex + 1,
1573
- " of ",
622
+ " of",
623
+ " ",
1574
624
  table.getPageCount()
1575
625
  ] }),
1576
626
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1586,22 +636,46 @@ function Pagination() {
1586
636
  ] })
1587
637
  ] });
1588
638
  }
1589
- var pagination_default = Pagination;
1590
-
1591
- // src/components/data-table/index.tsx
1592
- var DataTable = Object.assign(root_default2, {
1593
- Root: root_default2,
1594
- Toolbar: toolbar_default,
1595
- Content: content_default,
1596
- TableView: table_view_default,
1597
- GridView: grid_view_default,
1598
- Pagination: pagination_default,
1599
- ViewOptions: view_options_default
1600
- });
1601
- var data_table_default = DataTable;
639
+ function ViewOptions({
640
+ viewMode: propViewMode,
641
+ onViewModeChange: propOnViewModeChange
642
+ }) {
643
+ const context = useDataTableContext();
644
+ const mode = propViewMode ?? context?.viewMode ?? "table";
645
+ const onChange = propOnViewModeChange ?? context?.setViewMode;
646
+ if (!onChange) return null;
647
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center border rounded-md", children: [
648
+ /* @__PURE__ */ jsxRuntime.jsx(
649
+ Button,
650
+ {
651
+ variant: mode === "table" ? "secondary" : "ghost",
652
+ size: "sm",
653
+ className: "rounded-r-none px-3",
654
+ onClick: () => onChange("table"),
655
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.TableIcon, { className: "h-4 w-4" })
656
+ }
657
+ ),
658
+ /* @__PURE__ */ jsxRuntime.jsx(
659
+ Button,
660
+ {
661
+ variant: mode === "grid" ? "secondary" : "ghost",
662
+ size: "sm",
663
+ className: "rounded-l-none px-3",
664
+ onClick: () => onChange("grid"),
665
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.LayoutGrid, { className: "h-4 w-4" })
666
+ }
667
+ )
668
+ ] });
669
+ }
1602
670
 
1603
- exports.DataTable = data_table_default;
1604
- exports.Form = form_default;
671
+ exports.Content = Content2;
672
+ exports.DataTableContext = DataTableContext;
673
+ exports.Pagination = Pagination;
674
+ exports.Root = Root;
675
+ exports.Toolbar = Toolbar;
676
+ exports.ViewOptions = ViewOptions;
1605
677
  exports.cn = cn;
678
+ exports.useDataTableContext = useDataTableContext;
679
+ exports.useViewMode = useViewMode;
1606
680
  //# sourceMappingURL=index.js.map
1607
681
  //# sourceMappingURL=index.js.map