@betterinternship/components 3.4.2 → 3.5.1
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/components/autocomplete.d.ts +1 -2
- package/dist/components/autocomplete.js +75 -64
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/checkbox-field.d.ts +18 -0
- package/dist/components/checkbox-field.js +25 -0
- package/dist/components/checkbox-field.js.map +1 -0
- package/dist/components/checkbox-group.d.ts +33 -0
- package/dist/components/checkbox-group.js +43 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +1 -1
- package/dist/components/checkbox.js +6 -2
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip-select.d.ts +11 -2
- package/dist/components/chip-select.js +9 -4
- package/dist/components/chip-select.js.map +1 -1
- package/dist/components/{form-date-picker.d.ts → date-picker.d.ts} +11 -8
- package/dist/components/date-picker.js +57 -0
- package/dist/components/date-picker.js.map +1 -0
- package/dist/components/dropdown.js +7 -2
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/form-field.d.ts +60 -5
- package/dist/components/form-field.js +55 -5
- package/dist/components/form-field.js.map +1 -1
- package/dist/components/input.js +3 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/label.js +1 -1
- package/dist/components/label.js.map +1 -1
- package/dist/components/{form-month-picker.d.ts → month-picker.d.ts} +6 -6
- package/dist/components/month-picker.js +57 -0
- package/dist/components/month-picker.js.map +1 -0
- package/dist/components/radio-group.d.ts +11 -1
- package/dist/components/radio-group.js +17 -4
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/select.js +38 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.d.ts +1 -1
- package/dist/components/switch.d.ts +1 -1
- package/dist/components/switch.js +4 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/table.js +5 -5
- package/dist/components/table.js.map +1 -1
- package/dist/components/textarea.d.ts +1 -1
- package/dist/components/textarea.js +3 -1
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/time-input.d.ts +9 -0
- package/dist/components/time-input.js +65 -0
- package/dist/components/time-input.js.map +1 -0
- package/dist/design-tokens.d.ts +1 -1
- package/dist/hooks/use-field-focus.d.ts +1 -1
- package/dist/hooks/use-field-focus.js +1 -1
- package/dist/hooks/use-field-focus.js.map +1 -1
- package/dist/index.d.ts +5 -9
- package/dist/index.js +7 -11
- package/dist/index.js.map +1 -1
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +54 -2
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -1
- package/dist/utils.js +11 -1
- package/dist/utils.js.map +1 -1
- package/package.json +28 -40
- package/theme.css +3 -1
- package/dist/components/form-checkbox-group.d.ts +0 -31
- package/dist/components/form-checkbox-group.js +0 -30
- package/dist/components/form-checkbox-group.js.map +0 -1
- package/dist/components/form-checkbox.d.ts +0 -15
- package/dist/components/form-checkbox.js +0 -15
- package/dist/components/form-checkbox.js.map +0 -1
- package/dist/components/form-date-picker.js +0 -56
- package/dist/components/form-date-picker.js.map +0 -1
- package/dist/components/form-input.d.ts +0 -11
- package/dist/components/form-input.js +0 -13
- package/dist/components/form-input.js.map +0 -1
- package/dist/components/form-month-picker.js +0 -56
- package/dist/components/form-month-picker.js.map +0 -1
- package/dist/components/form-radio.d.ts +0 -15
- package/dist/components/form-radio.js +0 -20
- package/dist/components/form-radio.js.map +0 -1
- package/dist/components/form-textarea.d.ts +0 -11
- package/dist/components/form-textarea.js +0 -12
- package/dist/components/form-textarea.js.map +0 -1
- package/dist/components/form.d.ts +0 -24
- package/dist/components/form.js +0 -71
- package/dist/components/form.js.map +0 -1
- package/dist/components/time-input-native.d.ts +0 -14
- package/dist/components/time-input-native.js +0 -62
- package/dist/components/time-input-native.js.map +0 -1
- package/dist/node_modules/react-hook-form/dist/index.esm.js +0 -706
- package/dist/node_modules/react-hook-form/dist/index.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label.js","sources":["../../src/components/label.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { MessageCircleQuestion } from 'lucide-react';\r\n\r\nimport { cn } from '@/utils';\r\nimport {\r\n Tooltip,\r\n TooltipContent,\r\n TooltipTrigger,\r\n} from '@/components/tooltip';\r\n\r\nexport interface LabelProps {\r\n label: React.ReactNode;\r\n required?: boolean;\r\n tooltip?: string;\r\n /** Kept so existing callers still type-check; the Radix tooltip needs no id. */\r\n tooltipId?: string;\r\n labelAddon?: React.ReactNode;\r\n labelProps?: React.ComponentPropsWithRef<'label'>;\r\n className?: string;\r\n}\r\n\r\n/** Shared label typography with native label association and ref support. */\r\nexport const FieldLabel = React.forwardRef<HTMLLabelElement, React.ComponentPropsWithoutRef<'label'>>(\r\n ({ className, ...props }, ref) => (\r\n <label\r\n ref={ref}\r\n className={cn('text-field-label font-field-label text-
|
|
1
|
+
{"version":3,"file":"label.js","sources":["../../src/components/label.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { MessageCircleQuestion } from 'lucide-react';\r\n\r\nimport { cn } from '@/utils';\r\nimport {\r\n Tooltip,\r\n TooltipContent,\r\n TooltipTrigger,\r\n} from '@/components/tooltip';\r\n\r\nexport interface LabelProps {\r\n label: React.ReactNode;\r\n required?: boolean;\r\n tooltip?: string;\r\n /** Kept so existing callers still type-check; the Radix tooltip needs no id. */\r\n tooltipId?: string;\r\n labelAddon?: React.ReactNode;\r\n labelProps?: React.ComponentPropsWithRef<'label'>;\r\n className?: string;\r\n}\r\n\r\n/** Shared label typography with native label association and ref support. */\r\nexport const FieldLabel = React.forwardRef<HTMLLabelElement, React.ComponentPropsWithoutRef<'label'>>(\r\n ({ className, ...props }, ref) => (\r\n <label\r\n ref={ref}\r\n className={cn('text-field-label font-field-label text-label-foreground', className)}\r\n {...props}\r\n />\r\n ),\r\n);\r\nFieldLabel.displayName = 'FieldLabel';\r\n\r\n/** The label row shared by every form field: label, help tooltip, addon. */\r\nexport function Label({\r\n label,\r\n required,\r\n tooltip,\r\n labelAddon,\r\n labelProps,\r\n className,\r\n}: LabelProps) {\r\n const hasTooltip = !!tooltip?.trim();\r\n\r\n return (\r\n <div className={cn('mb-field-label-gap flex w-full justify-between gap-2 md:items-center', className)}>\r\n <div className=\"flex gap-2 md:items-center\">\r\n <FieldLabel {...labelProps}>\r\n {label} {required && <span className=\"text-destructive\">*</span>}\r\n </FieldLabel>\r\n {hasTooltip ? (\r\n <Tooltip>\r\n <TooltipTrigger asChild>\r\n <button\r\n type=\"button\"\r\n aria-label=\"More information\"\r\n className=\"hover:cursor-help\"\r\n >\r\n <MessageCircleQuestion className=\"text-primary h-3.5 w-3.5\" />\r\n </button>\r\n </TooltipTrigger>\r\n <TooltipContent side=\"bottom\" className=\"z-(--z-tooltip) max-w-[80vw]\">\r\n {tooltip}\r\n </TooltipContent>\r\n </Tooltip>\r\n ) : (\r\n // Reserves the icon's space so labels line up with or without help.\r\n <div aria-hidden=\"true\">\r\n <MessageCircleQuestion className={cn('invisible h-3.5 w-3.5')} />\r\n </div>\r\n )}\r\n </div>\r\n {labelAddon && <div>{labelAddon}</div>}\r\n </div>\r\n );\r\n}\r\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;AAqBA;AACO,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CACxC,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,MAC3BA,eACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,yDAAyD,EAAE,SAAS,CAAC,EAAA,GAC/E,KAAK,EAAA,CACT,CACH;AAEH,UAAU,CAAC,WAAW,GAAG,YAAY;AAErC;AACM,SAAU,KAAK,CAAC,EACpB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS,GACE,EAAA;IACX,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE;AAEpC,IAAA,QACEC,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,EAAE,CAAC,sEAAsE,EAAE,SAAS,CAAC,aACnGA,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,4BAA4B,EAAA,QAAA,EAAA,CACzCA,KAAC,UAAU,EAAA,EAAA,GAAK,UAAU,EAAA,QAAA,EAAA,CACvB,KAAK,EAAA,GAAA,EAAG,QAAQ,IAAID,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,kBAAkB,EAAA,QAAA,EAAA,GAAA,EAAA,CAAS,CAAA,EAAA,CACrD,EACZ,UAAU,IACTC,IAAA,CAAC,OAAO,EAAA,EAAA,QAAA,EAAA,CACND,GAAA,CAAC,cAAc,EAAA,EAAC,OAAO,EAAA,IAAA,EAAA,QAAA,EACrBA,GAAA,CAAA,QAAA,EAAA,EACE,IAAI,EAAC,QAAQ,gBACF,kBAAkB,EAC7B,SAAS,EAAC,mBAAmB,EAAA,QAAA,EAE7BA,GAAA,CAAC,qBAAqB,EAAA,EAAC,SAAS,EAAC,0BAA0B,EAAA,CAAG,EAAA,CACvD,EAAA,CACM,EACjBA,GAAA,CAAC,cAAc,IAAC,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,8BAA8B,YACnE,OAAO,EAAA,CACO,IACT;;oBAGVA,GAAA,CAAA,KAAA,EAAA,EAAA,aAAA,EAAiB,MAAM,YACrBA,GAAA,CAAC,qBAAqB,IAAC,SAAS,EAAE,EAAE,CAAC,uBAAuB,CAAC,GAAI,EAAA,CAC7D,CACP,CAAA,EAAA,CACG,EACL,UAAU,IAAIA,uBAAM,UAAU,EAAA,CAAO,CAAA,EAAA,CAClC;AAEV;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/** Props the trigger takes from the caller or the surrounding FormField. */
|
|
3
|
+
type TriggerProps = Pick<React.ButtonHTMLAttributes<HTMLButtonElement>, 'id' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-required' | 'disabled'>;
|
|
4
|
+
/** A month picker. Unlabelled: put it in a `FormField` for a label. */
|
|
5
|
+
export interface MonthPickerProps extends TriggerProps {
|
|
4
6
|
/** ms since epoch; will be normalized to the first day of the month */
|
|
5
7
|
date?: number;
|
|
6
8
|
/** setter receives ms since epoch (first day of month at local midnight) or undefined when cleared */
|
|
@@ -10,9 +12,6 @@ export interface FormMonthPickerProps extends React.InputHTMLAttributes<HTMLInpu
|
|
|
10
12
|
align?: 'start' | 'center' | 'end';
|
|
11
13
|
sideOffset?: number;
|
|
12
14
|
contentClassName?: string;
|
|
13
|
-
tooltip?: string;
|
|
14
|
-
tooltipId?: string;
|
|
15
|
-
required?: boolean;
|
|
16
15
|
/** Placeholder text when no month selected */
|
|
17
16
|
placeholder?: string;
|
|
18
17
|
/** Format the button text */
|
|
@@ -23,4 +22,5 @@ export interface FormMonthPickerProps extends React.InputHTMLAttributes<HTMLInpu
|
|
|
23
22
|
/** Close popover automatically on select (default true) */
|
|
24
23
|
autoClose?: boolean;
|
|
25
24
|
}
|
|
26
|
-
export declare const
|
|
25
|
+
export declare const MonthPicker: ({ date, setter, className, side, align, sideOffset, contentClassName, placeholder, format, fromYear, toYear, autoClose, ...ownTriggerProps }: MonthPickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';
|
|
5
|
+
import { cn } from '../utils.js';
|
|
6
|
+
import { fieldTriggerClassName } from '../hooks/use-field-focus.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
8
|
+
import { Popover, PopoverTrigger, PopoverContent } from './popover.js';
|
|
9
|
+
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from './select.js';
|
|
10
|
+
import { useFormFieldControl, FormFieldReset } from './form-field.js';
|
|
11
|
+
|
|
12
|
+
const MonthPicker = ({ date, setter, className, side = 'bottom', align = 'start', sideOffset = 6, contentClassName, placeholder = 'Select month', format = (d) => d.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }), fromYear = new Date().getFullYear() - 5, toYear = new Date().getFullYear() + 5, autoClose = true, ...ownTriggerProps }) => {
|
|
13
|
+
const triggerProps = useFormFieldControl(ownTriggerProps);
|
|
14
|
+
const [open, setOpen] = React.useState(false);
|
|
15
|
+
// normalize incoming ms -> first day of month
|
|
16
|
+
const selected = React.useMemo(() => {
|
|
17
|
+
if (date == null)
|
|
18
|
+
return undefined;
|
|
19
|
+
const d = new Date(date);
|
|
20
|
+
return new Date(d.getFullYear(), d.getMonth(), 1, 0, 0, 0, 0);
|
|
21
|
+
}, [date]);
|
|
22
|
+
const [viewYear, setViewYear] = React.useState(selected?.getFullYear() ?? new Date().getFullYear());
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (selected)
|
|
25
|
+
setViewYear(selected.getFullYear());
|
|
26
|
+
}, [selected]);
|
|
27
|
+
const months = React.useMemo(() => Array.from({ length: 12 }, (_, m) => ({
|
|
28
|
+
m,
|
|
29
|
+
label: new Date(2000, m, 1).toLocaleString(undefined, {
|
|
30
|
+
month: 'short',
|
|
31
|
+
}),
|
|
32
|
+
})), []);
|
|
33
|
+
const clampYear = (y) => Math.min(Math.max(y, fromYear), toYear);
|
|
34
|
+
const selectMonth = (monthIndex) => {
|
|
35
|
+
const y = clampYear(viewYear);
|
|
36
|
+
const firstOfMonth = new Date(y, monthIndex, 1, 0, 0, 0, 0).getTime();
|
|
37
|
+
setter?.(firstOfMonth);
|
|
38
|
+
if (autoClose)
|
|
39
|
+
setOpen(false);
|
|
40
|
+
};
|
|
41
|
+
const prevYear = () => setViewYear((y) => clampYear(y - 1));
|
|
42
|
+
const nextYear = () => setViewYear((y) => clampYear(y + 1));
|
|
43
|
+
const isYearMin = viewYear <= fromYear;
|
|
44
|
+
const isYearMax = viewYear >= toYear;
|
|
45
|
+
return (jsx("div", { className: cn('flex flex-col', className), children: jsxs(Popover, { open: open, onOpenChange: setOpen, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button, { variant: "outline", ...triggerProps, className: cn("w-full justify-between px-field-padding-x py-0", fieldTriggerClassName), children: [selected ? format(selected) : jsx("span", { className: "text-muted-foreground/40", children: placeholder }), jsx(ChevronDown, { className: "h-4 w-4 text-muted-foreground" })] }) }), jsx(PopoverContent, { align: align, side: side, sideOffset: sideOffset, className: cn('w-72 p-3', contentClassName), children: jsxs(FormFieldReset, { children: [jsxs("div", { className: "mb-3 flex items-center justify-between", children: [jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "h-8 w-8 p-0", "aria-label": "Previous year", onClick: prevYear, disabled: isYearMin, children: jsx(ChevronLeft, { className: "h-4 w-4" }) }), jsxs(Select, { value: String(viewYear), onValueChange: (val) => setViewYear(clampYear(Number(val))), children: [jsx(SelectTrigger, { className: "w-fit text-sm", children: jsx(SelectValue, {}) }), jsx(SelectContent, { className: "h-fit", children: Array.from({ length: toYear - fromYear + 1 }, (_, i) => fromYear + i).map((y) => (jsx(SelectItem, { value: String(y), children: y }, y))) })] }), jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "h-8 w-8 p-0", "aria-label": "Next year", onClick: nextYear, disabled: isYearMax, children: jsx(ChevronRight, { className: "h-4 w-4" }) })] }), jsx("div", { className: "grid grid-cols-3 gap-2", children: months.map(({ m, label: monthLabel }) => {
|
|
46
|
+
const isActive = selected &&
|
|
47
|
+
selected.getFullYear() === viewYear &&
|
|
48
|
+
selected.getMonth() === m;
|
|
49
|
+
return (jsx(Button, { type: "button", variant: isActive ? 'solid' : 'outline', className: cn('h-9 justify-center rounded-control-lg', isActive ? '' : 'bg-background'), onClick: () => selectMonth(m), children: jsx("span", { className: "text-sm", children: monthLabel }) }, m));
|
|
50
|
+
}) }), jsx("div", { className: "mt-3 flex justify-end", children: jsx(Button, { type: "button", variant: "ghost", className: "h-8 px-2 text-xs", onClick: () => {
|
|
51
|
+
setter?.(undefined);
|
|
52
|
+
setOpen(false);
|
|
53
|
+
}, children: "Clear" }) })] }) })] }) }));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { MonthPicker };
|
|
57
|
+
//# sourceMappingURL=month-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"month-picker.js","sources":["../../src/components/month-picker.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\nimport { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';\r\n\r\nimport { cn } from '@/utils';\r\nimport { fieldTriggerClassName } from '@/hooks/use-field-focus';\r\nimport { Button } from '@/components/button';\r\nimport {\r\n Popover,\r\n PopoverContent,\r\n PopoverTrigger,\r\n} from '@/components/popover';\r\nimport {\r\n Select,\r\n SelectContent,\r\n SelectItem,\r\n SelectTrigger,\r\n SelectValue,\r\n} from '@/components/select';\r\nimport { FormFieldReset, useFormFieldControl } from './form-field';\r\n\r\n/** Props the trigger takes from the caller or the surrounding FormField. */\r\ntype TriggerProps = Pick<\r\n React.ButtonHTMLAttributes<HTMLButtonElement>,\r\n 'id' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-required' | 'disabled'\r\n>;\r\n\r\n/** A month picker. Unlabelled: put it in a `FormField` for a label. */\r\nexport interface MonthPickerProps extends TriggerProps {\r\n /** ms since epoch; will be normalized to the first day of the month */\r\n date?: number;\r\n /** setter receives ms since epoch (first day of month at local midnight) or undefined when cleared */\r\n setter?: (value?: number) => void;\r\n className?: string;\r\n side?: 'top' | 'right' | 'bottom' | 'left';\r\n align?: 'start' | 'center' | 'end';\r\n sideOffset?: number;\r\n contentClassName?: string;\r\n\r\n /** Placeholder text when no month selected */\r\n placeholder?: string;\r\n\r\n /** Format the button text */\r\n format?: (d: Date) => string;\r\n\r\n /** Year bounds for navigation (inclusive) */\r\n fromYear?: number;\r\n toYear?: number;\r\n\r\n /** Close popover automatically on select (default true) */\r\n autoClose?: boolean;\r\n}\r\n\r\nexport const MonthPicker = ({\r\n date,\r\n setter,\r\n className,\r\n side = 'bottom',\r\n align = 'start',\r\n sideOffset = 6,\r\n contentClassName,\r\n placeholder = 'Select month',\r\n format = (d) =>\r\n d.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }),\r\n fromYear = new Date().getFullYear() - 5,\r\n toYear = new Date().getFullYear() + 5,\r\n autoClose = true,\r\n ...ownTriggerProps\r\n}: MonthPickerProps) => {\r\n const triggerProps = useFormFieldControl(ownTriggerProps);\r\n const [open, setOpen] = React.useState(false);\r\n\r\n // normalize incoming ms -> first day of month\r\n const selected = React.useMemo(() => {\r\n if (date == null) return undefined;\r\n const d = new Date(date);\r\n return new Date(d.getFullYear(), d.getMonth(), 1, 0, 0, 0, 0);\r\n }, [date]);\r\n\r\n const [viewYear, setViewYear] = React.useState<number>(\r\n selected?.getFullYear() ?? new Date().getFullYear(),\r\n );\r\n\r\n React.useEffect(() => {\r\n if (selected) setViewYear(selected.getFullYear());\r\n }, [selected]);\r\n\r\n const months = React.useMemo(\r\n () =>\r\n Array.from({ length: 12 }, (_, m) => ({\r\n m,\r\n label: new Date(2000, m, 1).toLocaleString(undefined, {\r\n month: 'short',\r\n }),\r\n })),\r\n [],\r\n );\r\n\r\n const clampYear = (y: number) => Math.min(Math.max(y, fromYear), toYear);\r\n\r\n const selectMonth = (monthIndex: number) => {\r\n const y = clampYear(viewYear);\r\n const firstOfMonth = new Date(y, monthIndex, 1, 0, 0, 0, 0).getTime();\r\n setter?.(firstOfMonth);\r\n if (autoClose) setOpen(false);\r\n };\r\n\r\n const prevYear = () => setViewYear((y) => clampYear(y - 1));\r\n const nextYear = () => setViewYear((y) => clampYear(y + 1));\r\n\r\n const isYearMin = viewYear <= fromYear;\r\n const isYearMax = viewYear >= toYear;\r\n\r\n return (\r\n <div className={cn('flex flex-col', className)}>\r\n <Popover open={open} onOpenChange={setOpen}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n variant=\"outline\"\r\n {...triggerProps}\r\n className={cn(\"w-full justify-between px-field-padding-x py-0\", fieldTriggerClassName)}\r\n >\r\n {selected ? format(selected) : <span className=\"text-muted-foreground/40\">{placeholder}</span>}\r\n <ChevronDown className=\"h-4 w-4 text-muted-foreground\" />\r\n </Button>\r\n </PopoverTrigger>\r\n\r\n <PopoverContent\r\n align={align}\r\n side={side}\r\n sideOffset={sideOffset}\r\n className={cn('w-72 p-3', contentClassName)}\r\n >\r\n <FormFieldReset>\r\n {/* Header: year controls */}\r\n <div className=\"mb-3 flex items-center justify-between\">\r\n <Button\r\n type=\"button\"\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"h-8 w-8 p-0\"\r\n aria-label=\"Previous year\"\r\n onClick={prevYear}\r\n disabled={isYearMin}\r\n >\r\n <ChevronLeft className=\"h-4 w-4\" />\r\n </Button>\r\n\r\n <Select\r\n value={String(viewYear)}\r\n onValueChange={(val) => setViewYear(clampYear(Number(val)))}\r\n >\r\n <SelectTrigger className=\"w-fit text-sm\">\r\n <SelectValue />\r\n </SelectTrigger>\r\n <SelectContent className=\"h-fit\">\r\n {Array.from(\r\n { length: toYear - fromYear + 1 },\r\n (_, i) => fromYear + i,\r\n ).map((y) => (\r\n <SelectItem key={y} value={String(y)}>\r\n {y}\r\n </SelectItem>\r\n ))}\r\n </SelectContent>\r\n </Select>\r\n\r\n <Button\r\n type=\"button\"\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n className=\"h-8 w-8 p-0\"\r\n aria-label=\"Next year\"\r\n onClick={nextYear}\r\n disabled={isYearMax}\r\n >\r\n <ChevronRight className=\"h-4 w-4\" />\r\n </Button>\r\n </div>\r\n\r\n {/* Month grid */}\r\n <div className=\"grid grid-cols-3 gap-2\">\r\n {months.map(({ m, label: monthLabel }) => {\r\n const isActive =\r\n selected &&\r\n selected.getFullYear() === viewYear &&\r\n selected.getMonth() === m;\r\n\r\n return (\r\n <Button\r\n key={m}\r\n type=\"button\"\r\n variant={isActive ? 'solid' : 'outline'}\r\n className={cn(\r\n 'h-9 justify-center rounded-control-lg',\r\n isActive ? '' : 'bg-background',\r\n )}\r\n onClick={() => selectMonth(m)}\r\n >\r\n <span className=\"text-sm\">{monthLabel}</span>\r\n </Button>\r\n );\r\n })}\r\n </div>\r\n\r\n {/* Clear (optional) */}\r\n <div className=\"mt-3 flex justify-end\">\r\n <Button\r\n type=\"button\"\r\n variant=\"ghost\"\r\n className=\"h-8 px-2 text-xs\"\r\n onClick={() => {\r\n setter?.(undefined);\r\n setOpen(false);\r\n }}\r\n >\r\n Clear\r\n </Button>\r\n </div>\r\n </FormFieldReset>\r\n </PopoverContent>\r\n </Popover>\r\n </div>\r\n );\r\n};\r\n"],"names":[],"mappings":";;;;;;;;;;;AAsDO;AAgBL;AACA;;AAGA;;AACoB;AAClB;;AAEF;;AAMA;AACE;AAAc;AAChB;;;AAMM;AACE;;AAEH;;AAML;AACE;;AAEA;AACA;;AACF;AAEA;AACA;AAEA;AACA;AAEA;;AAwEc;AACA;;;AA0BA;;AAEF;AAUd;;"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
|
|
3
3
|
declare const RadioGroup: React.ForwardRefExoticComponent<Omit<RadioGroupPrimitive.RadioGroupProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
/**
|
|
5
|
+
* The radio circle shared by RadioGroup and ChipSelect: one fixed SVG whose
|
|
6
|
+
* colours change with the state, so nothing shifts when it is selected.
|
|
7
|
+
* Pass `checked`, or leave it out inside a `group` element with
|
|
8
|
+
* `data-state="checked"` (as a RadioGroupItem is).
|
|
9
|
+
*/
|
|
10
|
+
declare function RadioVisual({ checked, className }: {
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
4
14
|
declare const RadioGroupItem: React.ForwardRefExoticComponent<Omit<RadioGroupPrimitive.RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
-
export { RadioGroup, RadioGroupItem };
|
|
15
|
+
export { RadioGroup, RadioGroupItem, RadioVisual };
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
|
+
import { useFormFieldControl } from './form-field.js';
|
|
6
7
|
|
|
7
|
-
const RadioGroup = React.forwardRef(({ className, ...
|
|
8
|
+
const RadioGroup = React.forwardRef(({ className, ...ownProps }, ref) => {
|
|
9
|
+
// Inside a FormField the field's label names the whole group.
|
|
10
|
+
const props = useFormFieldControl(ownProps, "group");
|
|
8
11
|
return (jsx(RadioGroupPrimitive.Root, { className: cn("grid gap-2", className), ...props, ref: ref }));
|
|
9
12
|
});
|
|
10
13
|
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
|
|
14
|
+
/**
|
|
15
|
+
* The radio circle shared by RadioGroup and ChipSelect: one fixed SVG whose
|
|
16
|
+
* colours change with the state, so nothing shifts when it is selected.
|
|
17
|
+
* Pass `checked`, or leave it out inside a `group` element with
|
|
18
|
+
* `data-state="checked"` (as a RadioGroupItem is).
|
|
19
|
+
*/
|
|
20
|
+
function RadioVisual({ checked, className }) {
|
|
21
|
+
const state = checked === undefined ? undefined : checked ? "checked" : "unchecked";
|
|
22
|
+
return (jsxs("svg", { "aria-hidden": "true", "data-state": state, viewBox: "0 0 16 16", className: cn("group/radio size-4 shrink-0", className), children: [jsx("circle", { cx: "8", cy: "8", r: "7", strokeWidth: "1", className: cn("fill-muted stroke-input transition-colors duration-state motion-reduce:transition-none", "group-data-[state=checked]/radio:fill-primary group-data-[state=checked]/radio:stroke-primary", checked === undefined && "group-data-[state=checked]:fill-primary group-data-[state=checked]:stroke-primary group-hover:stroke-primary") }), jsx("circle", { cx: "8", cy: "8", r: "4", className: cn("fill-background opacity-0", "group-data-[state=checked]/radio:opacity-100", checked === undefined && "group-data-[state=checked]:opacity-100") })] }));
|
|
23
|
+
}
|
|
11
24
|
const RadioGroupItem = React.forwardRef(({ className, ...props }, ref) => {
|
|
12
|
-
return (jsx(RadioGroupPrimitive.Item, { ref: ref, className: cn("relative aspect-square
|
|
25
|
+
return (jsx(RadioGroupPrimitive.Item, { ref: ref, className: cn("group relative aspect-square size-4 shrink-0 rounded-full focus:outline-none focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue disabled:cursor-not-allowed disabled:opacity-50 after:absolute after:-inset-3 after:content-['']", className), ...props, children: jsx(RadioVisual, {}) }));
|
|
13
26
|
});
|
|
14
27
|
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
|
|
15
28
|
|
|
16
|
-
export { RadioGroup, RadioGroupItem };
|
|
29
|
+
export { RadioGroup, RadioGroupItem, RadioVisual };
|
|
17
30
|
//# sourceMappingURL=radio-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio-group.js","sources":["../../src/components/radio-group.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\r\n\r\nimport { cn } from \"@/utils\";\r\n\r\nconst RadioGroup = React.forwardRef<\r\n React.ElementRef<typeof RadioGroupPrimitive.Root>,\r\n React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>\r\n>(({ className, ...
|
|
1
|
+
{"version":3,"file":"radio-group.js","sources":["../../src/components/radio-group.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\r\n\r\nimport { cn } from \"@/utils\";\r\nimport { useFormFieldControl } from \"./form-field\";\r\n\r\nconst RadioGroup = React.forwardRef<\r\n React.ElementRef<typeof RadioGroupPrimitive.Root>,\r\n React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>\r\n>(({ className, ...ownProps }, ref) => {\r\n // Inside a FormField the field's label names the whole group.\r\n const props = useFormFieldControl(ownProps, \"group\");\r\n return (\r\n <RadioGroupPrimitive.Root\r\n className={cn(\"grid gap-2\", className)}\r\n {...props}\r\n ref={ref}\r\n />\r\n );\r\n});\r\nRadioGroup.displayName = RadioGroupPrimitive.Root.displayName;\r\n\r\n/**\r\n * The radio circle shared by RadioGroup and ChipSelect: one fixed SVG whose\r\n * colours change with the state, so nothing shifts when it is selected.\r\n * Pass `checked`, or leave it out inside a `group` element with\r\n * `data-state=\"checked\"` (as a RadioGroupItem is).\r\n */\r\nfunction RadioVisual({ checked, className }: { checked?: boolean; className?: string }) {\r\n const state = checked === undefined ? undefined : checked ? \"checked\" : \"unchecked\";\r\n return (\r\n <svg aria-hidden=\"true\" data-state={state} viewBox=\"0 0 16 16\" className={cn(\"group/radio size-4 shrink-0\", className)}>\r\n <circle\r\n cx=\"8\"\r\n cy=\"8\"\r\n r=\"7\"\r\n strokeWidth=\"1\"\r\n className={cn(\r\n \"fill-muted stroke-input transition-colors duration-state motion-reduce:transition-none\",\r\n \"group-data-[state=checked]/radio:fill-primary group-data-[state=checked]/radio:stroke-primary\",\r\n checked === undefined && \"group-data-[state=checked]:fill-primary group-data-[state=checked]:stroke-primary group-hover:stroke-primary\",\r\n )}\r\n />\r\n <circle\r\n cx=\"8\"\r\n cy=\"8\"\r\n r=\"4\"\r\n className={cn(\r\n \"fill-background opacity-0\",\r\n \"group-data-[state=checked]/radio:opacity-100\",\r\n checked === undefined && \"group-data-[state=checked]:opacity-100\",\r\n )}\r\n />\r\n </svg>\r\n );\r\n}\r\n\r\nconst RadioGroupItem = React.forwardRef<\r\n React.ElementRef<typeof RadioGroupPrimitive.Item>,\r\n React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>\r\n>(({ className, ...props }, ref) => {\r\n return (\r\n <RadioGroupPrimitive.Item\r\n ref={ref}\r\n className={cn(\r\n \"group relative aspect-square size-4 shrink-0 rounded-full focus:outline-none focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue disabled:cursor-not-allowed disabled:opacity-50 after:absolute after:-inset-3 after:content-['']\",\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <RadioVisual />\r\n </RadioGroupPrimitive.Item>\r\n );\r\n});\r\nRadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;\r\n\r\nexport { RadioGroup, RadioGroupItem, RadioVisual };\r\n"],"names":[],"mappings":";;;;;;;AAQA;;;;AAaA;AACA;AAEA;;;;;AAKG;AACH;;AAEE;AAyBF;AAEA;;AAgBA;AACA;;"}
|
|
@@ -7,6 +7,7 @@ import { cn } from '../utils.js';
|
|
|
7
7
|
import { fieldInteractionClassName } from '../hooks/use-field-focus.js';
|
|
8
8
|
import { useMobile } from '../hooks/use-mobile.js';
|
|
9
9
|
import { useMobileSheetViewport } from '../hooks/use-mobile-sheet-viewport.js';
|
|
10
|
+
import { useFormFieldControl, useFormField } from './form-field.js';
|
|
10
11
|
|
|
11
12
|
const SelectContext = React.createContext({ open: false, setOpen: (_open) => { } });
|
|
12
13
|
function Select({ open: controlledOpen, defaultOpen = false, onOpenChange, children, ...props }) {
|
|
@@ -21,14 +22,49 @@ function Select({ open: controlledOpen, defaultOpen = false, onOpenChange, child
|
|
|
21
22
|
}
|
|
22
23
|
const SelectGroup = SelectPrimitive.Group;
|
|
23
24
|
const SelectValue = SelectPrimitive.Value;
|
|
24
|
-
const SelectTrigger = React.forwardRef(({ className, children, ...
|
|
25
|
+
const SelectTrigger = React.forwardRef(({ className, children, onPointerDown, onClick, ...ownProps }, ref) => {
|
|
26
|
+
const props = useFormFieldControl(ownProps);
|
|
27
|
+
const { open, setOpen } = React.useContext(SelectContext);
|
|
28
|
+
// Radix opens on a mouse press on the trigger itself, so a click that arrives
|
|
29
|
+
// without one (from the field's label) would only focus it. Open it here.
|
|
30
|
+
// A press on the trigger stops counting once anything else is pressed: when
|
|
31
|
+
// Radix opens on the press, the release lands on the menu, not the trigger.
|
|
32
|
+
const pressedRef = React.useRef(false);
|
|
33
|
+
const triggerRef = React.useRef(null);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
const onPointerDownAnywhere = (event) => {
|
|
36
|
+
if (!(event.target instanceof Node) || !triggerRef.current?.contains(event.target))
|
|
37
|
+
pressedRef.current = false;
|
|
38
|
+
};
|
|
39
|
+
document.addEventListener('pointerdown', onPointerDownAnywhere, true);
|
|
40
|
+
return () => document.removeEventListener('pointerdown', onPointerDownAnywhere, true);
|
|
41
|
+
}, []);
|
|
42
|
+
return (jsxs(SelectPrimitive.Trigger, { ref: (node) => {
|
|
43
|
+
triggerRef.current = node;
|
|
44
|
+
if (typeof ref === 'function')
|
|
45
|
+
ref(node);
|
|
46
|
+
else if (ref)
|
|
47
|
+
ref.current = node;
|
|
48
|
+
}, onPointerDown: (event) => {
|
|
49
|
+
pressedRef.current = true;
|
|
50
|
+
onPointerDown?.(event);
|
|
51
|
+
}, onClick: (event) => {
|
|
52
|
+
onClick?.(event);
|
|
53
|
+
const fromLabel = !pressedRef.current;
|
|
54
|
+
pressedRef.current = false;
|
|
55
|
+
if (fromLabel && !event.defaultPrevented && !open && !props.disabled)
|
|
56
|
+
setOpen(true);
|
|
57
|
+
}, className: cn('group bg-background text-foreground placeholder:text-muted-foreground/40 data-[placeholder]:text-muted-foreground/40 border-input enabled:hover:border-input-hover flex h-form-control min-h-form-control max-h-form-control w-full cursor-pointer items-center justify-between gap-2 rounded-control-lg border px-field-padding-x py-0 text-base font-normal outline-none aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1', 'focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue', fieldInteractionClassName, className), ...props, children: [children, jsx(SelectPrimitive.Icon, { asChild: true, children: jsx(ChevronDown, { className: "h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-interactive ease-out-strong group-data-[state=open]:rotate-180 motion-reduce:transition-none" }) })] }));
|
|
58
|
+
});
|
|
25
59
|
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
26
60
|
const SelectScrollUpButton = React.forwardRef(({ className, ...props }, ref) => (jsx(SelectPrimitive.ScrollUpButton, { ref: ref, className: cn('flex cursor-default items-center justify-center py-1', className), ...props, children: jsx(ChevronUp, { className: "h-4 w-4" }) })));
|
|
27
61
|
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
|
28
62
|
const SelectScrollDownButton = React.forwardRef(({ className, ...props }, ref) => (jsx(SelectPrimitive.ScrollDownButton, { ref: ref, className: cn('flex cursor-default items-center justify-center py-1', className), ...props, children: jsx(ChevronDown, { className: "h-4 w-4" }) })));
|
|
29
63
|
SelectScrollDownButton.displayName =
|
|
30
64
|
SelectPrimitive.ScrollDownButton.displayName;
|
|
31
|
-
const SelectContent = React.forwardRef(({ className, children, position = 'popper', title
|
|
65
|
+
const SelectContent = React.forwardRef(({ className, children, position = 'popper', title: ownTitle, style, ...props }, ref) => {
|
|
66
|
+
// The phone sheet's title: an explicit title, else the field's label.
|
|
67
|
+
const title = ownTitle ?? useFormField()?.labelText ?? 'Choose an option';
|
|
32
68
|
const mobile = useMobile();
|
|
33
69
|
const { open, setOpen } = React.useContext(SelectContext);
|
|
34
70
|
const viewport = useMobileSheetViewport(open && mobile);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sources":["../../src/components/select.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\nimport * as SelectPrimitive from '@radix-ui/react-select';\r\nimport { Check, ChevronDown, ChevronUp, X } from 'lucide-react';\r\n\r\nimport { cn } from '@/utils';\r\nimport { fieldInteractionClassName } from '@/hooks/use-field-focus';\r\nimport { useMobile } from '@/hooks/use-mobile';\r\nimport { useMobileSheetViewport } from '@/hooks/use-mobile-sheet-viewport';\r\n\r\nconst SelectContext = React.createContext({ open: false, setOpen: (_open: boolean) => {} });\r\n\r\nfunction Select({ open: controlledOpen, defaultOpen = false, onOpenChange, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {\r\n const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\r\n const open = controlledOpen ?? internalOpen;\r\n const setOpen = (next: boolean) => {\r\n if (controlledOpen === undefined) setInternalOpen(next);\r\n onOpenChange?.(next);\r\n };\r\n\r\n return (\r\n <SelectContext.Provider value={{ open, setOpen }}>\r\n <SelectPrimitive.Root {...props} open={open} onOpenChange={setOpen}>\r\n {children}\r\n </SelectPrimitive.Root>\r\n </SelectContext.Provider>\r\n );\r\n}\r\n\r\nconst SelectGroup = SelectPrimitive.Group;\r\n\r\nconst SelectValue = SelectPrimitive.Value;\r\n\r\nconst SelectTrigger = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Trigger>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>\r\n>(({ className, children, ...props }, ref) => (\r\n <SelectPrimitive.Trigger\r\n ref={ref}\r\n className={cn(\r\n 'group bg-background text-foreground placeholder:text-muted-foreground/40 data-[placeholder]:text-muted-foreground/40 border-input enabled:hover:border-input-hover flex h-form-control min-h-form-control max-h-form-control w-full cursor-pointer items-center justify-between gap-2 rounded-control-lg border px-field-padding-x py-0 text-base font-normal outline-none aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',\r\n 'focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue',\r\n fieldInteractionClassName,\r\n className,\r\n )}\r\n {...props}\r\n >\r\n {children}\r\n <SelectPrimitive.Icon asChild>\r\n <ChevronDown className=\"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-interactive ease-out-strong group-data-[state=open]:rotate-180 motion-reduce:transition-none\" />\r\n </SelectPrimitive.Icon>\r\n </SelectPrimitive.Trigger>\r\n));\r\nSelectTrigger.displayName = SelectPrimitive.Trigger.displayName;\r\n\r\nconst SelectScrollUpButton = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.ScrollUpButton\r\n ref={ref}\r\n className={cn(\r\n 'flex cursor-default items-center justify-center py-1',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <ChevronUp className=\"h-4 w-4\" />\r\n </SelectPrimitive.ScrollUpButton>\r\n));\r\nSelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;\r\n\r\nconst SelectScrollDownButton = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.ScrollDownButton\r\n ref={ref}\r\n className={cn(\r\n 'flex cursor-default items-center justify-center py-1',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <ChevronDown className=\"h-4 w-4\" />\r\n </SelectPrimitive.ScrollDownButton>\r\n));\r\nSelectScrollDownButton.displayName =\r\n SelectPrimitive.ScrollDownButton.displayName;\r\n\r\nconst SelectContent = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Content>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & { title?: string }\r\n>(({ className, children, position = 'popper', title = 'Choose an option', style, ...props }, ref) => {\r\n const mobile = useMobile();\r\n const { open, setOpen } = React.useContext(SelectContext);\r\n const viewport = useMobileSheetViewport(open && mobile);\r\n\r\n return (\r\n <SelectPrimitive.Portal>\r\n <div\r\n className={mobile ? '[&>[data-radix-popper-content-wrapper]]:!fixed [&>[data-radix-popper-content-wrapper]]:!inset-x-0 [&>[data-radix-popper-content-wrapper]]:!top-auto [&>[data-radix-popper-content-wrapper]]:!bottom-[var(--select-sheet-bottom)] [&>[data-radix-popper-content-wrapper]]:!transform-none [&>[data-radix-popper-content-wrapper]]:!z-(--z-popover) [&>[data-radix-popper-content-wrapper]]:!min-w-0' : undefined}\r\n style={{ '--select-sheet-bottom': `${viewport?.bottom ?? 0}px` } as React.CSSProperties}\r\n >\r\n {mobile && open && (\r\n <div aria-hidden=\"true\" className=\"fixed inset-0 z-(--z-popover-overlay) bg-black/25 backdrop-blur-[1px]\" />\r\n )}\r\n <SelectPrimitive.Content\r\n ref={ref}\r\n className={cn(\r\n 'relative flex flex-col overflow-hidden border border-border bg-background text-sm text-foreground shadow-card duration-interactive ease-out-strong motion-reduce:animate-none',\r\n mobile\r\n ? 'w-full rounded-t-control-lg border-b-0 pb-[env(safe-area-inset-bottom)]'\r\n : 'z-(--z-popover) max-h-[400px] min-w-[8rem] rounded-control-lg 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',\r\n className,\r\n )}\r\n position={mobile ? 'popper' : position}\r\n sideOffset={4}\r\n style={{\r\n ...(mobile ? { maxHeight: viewport ? Math.min(viewport.height, 640) : '80dvh' } : {}),\r\n ...style,\r\n }}\r\n {...props}\r\n >\r\n {mobile && (\r\n <div role=\"presentation\" className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4\">\r\n <h2 className=\"text-base font-semibold text-foreground\">{title}</h2>\r\n <button\r\n type=\"button\"\r\n aria-label=\"Close options\"\r\n className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\r\n onPointerDown={(event) => event.stopPropagation()}\r\n onClick={() => setOpen(false)}\r\n >\r\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\r\n </button>\r\n </div>\r\n )}\r\n {!mobile && <SelectScrollUpButton />}\r\n <SelectPrimitive.Viewport\r\n className={cn(\r\n 'flex min-h-0 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset',\r\n mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]',\r\n )}\r\n >\r\n {children}\r\n </SelectPrimitive.Viewport>\r\n {!mobile && <SelectScrollDownButton />}\r\n </SelectPrimitive.Content>\r\n </div>\r\n </SelectPrimitive.Portal>\r\n );\r\n});\r\nSelectContent.displayName = SelectPrimitive.Content.displayName;\r\n\r\nconst SelectLabel = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Label>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.Label\r\n ref={ref}\r\n className={cn('px-option-x py-2 text-sm font-semibold text-foreground', className)}\r\n {...props}\r\n />\r\n));\r\nSelectLabel.displayName = SelectPrimitive.Label.displayName;\r\n\r\nconst SelectItem = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Item>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>\r\n>(({ className, children, ...props }, ref) => (\r\n <SelectPrimitive.Item\r\n ref={ref}\r\n className={cn(\r\n 'relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pr-9 text-sm text-muted-foreground outline-none select-none transition-colors duration-interactive ease-out-strong focus:bg-muted data-[state=checked]:bg-primary-tint data-[disabled]:pointer-events-none data-[disabled]:opacity-50 motion-reduce:transition-none max-md:min-h-12',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <span className=\"absolute right-option-x flex h-4 w-4 items-center justify-center\">\r\n <SelectPrimitive.ItemIndicator>\r\n <Check className=\"h-4 w-4\" />\r\n </SelectPrimitive.ItemIndicator>\r\n </span>\r\n\r\n <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>\r\n </SelectPrimitive.Item>\r\n));\r\nSelectItem.displayName = SelectPrimitive.Item.displayName;\r\n\r\nconst SelectSeparator = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Separator>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.Separator\r\n ref={ref}\r\n className={cn('bg-border h-px', className)}\r\n {...props}\r\n />\r\n));\r\nSelectSeparator.displayName = SelectPrimitive.Separator.displayName;\r\n\r\nexport {\r\n Select,\r\n SelectGroup,\r\n SelectValue,\r\n SelectTrigger,\r\n SelectContent,\r\n SelectLabel,\r\n SelectItem,\r\n SelectSeparator,\r\n SelectScrollUpButton,\r\n SelectScrollDownButton,\r\n};\r\n"],"names":[],"mappings":";;;;;;;;;;AAWA;AAEA;AACE;AACA;AACA;;;AAEE;AACF;AAEA;AAOF;AAEA;AAEA;AAEA;AAoBA;AAEA;AAeA;AAEA;AAeA;AACE;AAEF;AAIE;AACA;;AAGA;AAcQ;;AAOF;AACA;;AAgCR;AACA;AAEA;AAUA;AAEA;AAqBA;AAEA;AAUA;;"}
|
|
1
|
+
{"version":3,"file":"select.js","sources":["../../src/components/select.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\nimport * as SelectPrimitive from '@radix-ui/react-select';\r\nimport { Check, ChevronDown, ChevronUp, X } from 'lucide-react';\r\n\r\nimport { cn } from '@/utils';\r\nimport { fieldInteractionClassName } from '@/hooks/use-field-focus';\r\nimport { useMobile } from '@/hooks/use-mobile';\r\nimport { useMobileSheetViewport } from '@/hooks/use-mobile-sheet-viewport';\r\nimport { useFormField, useFormFieldControl } from './form-field';\r\n\r\nconst SelectContext = React.createContext({ open: false, setOpen: (_open: boolean) => {} });\r\n\r\nfunction Select({ open: controlledOpen, defaultOpen = false, onOpenChange, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {\r\n const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\r\n const open = controlledOpen ?? internalOpen;\r\n const setOpen = (next: boolean) => {\r\n if (controlledOpen === undefined) setInternalOpen(next);\r\n onOpenChange?.(next);\r\n };\r\n\r\n return (\r\n <SelectContext.Provider value={{ open, setOpen }}>\r\n <SelectPrimitive.Root {...props} open={open} onOpenChange={setOpen}>\r\n {children}\r\n </SelectPrimitive.Root>\r\n </SelectContext.Provider>\r\n );\r\n}\r\n\r\nconst SelectGroup = SelectPrimitive.Group;\r\n\r\nconst SelectValue = SelectPrimitive.Value;\r\n\r\nconst SelectTrigger = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Trigger>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>\r\n>(({ className, children, onPointerDown, onClick, ...ownProps }, ref) => {\r\n const props = useFormFieldControl(ownProps);\r\n const { open, setOpen } = React.useContext(SelectContext);\r\n // Radix opens on a mouse press on the trigger itself, so a click that arrives\r\n // without one (from the field's label) would only focus it. Open it here.\r\n // A press on the trigger stops counting once anything else is pressed: when\r\n // Radix opens on the press, the release lands on the menu, not the trigger.\r\n const pressedRef = React.useRef(false);\r\n const triggerRef = React.useRef<HTMLButtonElement | null>(null);\r\n React.useEffect(() => {\r\n const onPointerDownAnywhere = (event: PointerEvent) => {\r\n if (!(event.target instanceof Node) || !triggerRef.current?.contains(event.target)) pressedRef.current = false;\r\n };\r\n document.addEventListener('pointerdown', onPointerDownAnywhere, true);\r\n return () => document.removeEventListener('pointerdown', onPointerDownAnywhere, true);\r\n }, []);\r\n return (\r\n <SelectPrimitive.Trigger\r\n ref={(node) => {\r\n triggerRef.current = node;\r\n if (typeof ref === 'function') ref(node);\r\n else if (ref) ref.current = node;\r\n }}\r\n onPointerDown={(event) => {\r\n pressedRef.current = true;\r\n onPointerDown?.(event);\r\n }}\r\n onClick={(event) => {\r\n onClick?.(event);\r\n const fromLabel = !pressedRef.current;\r\n pressedRef.current = false;\r\n if (fromLabel && !event.defaultPrevented && !open && !props.disabled) setOpen(true);\r\n }}\r\n className={cn(\r\n 'group bg-background text-foreground placeholder:text-muted-foreground/40 data-[placeholder]:text-muted-foreground/40 border-input enabled:hover:border-input-hover flex h-form-control min-h-form-control max-h-form-control w-full cursor-pointer items-center justify-between gap-2 rounded-control-lg border px-field-padding-x py-0 text-base font-normal outline-none aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',\r\n 'focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue',\r\n fieldInteractionClassName,\r\n className,\r\n )}\r\n {...props}\r\n >\r\n {children}\r\n <SelectPrimitive.Icon asChild>\r\n <ChevronDown className=\"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-interactive ease-out-strong group-data-[state=open]:rotate-180 motion-reduce:transition-none\" />\r\n </SelectPrimitive.Icon>\r\n </SelectPrimitive.Trigger>\r\n );\r\n});\r\nSelectTrigger.displayName = SelectPrimitive.Trigger.displayName;\r\n\r\nconst SelectScrollUpButton = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.ScrollUpButton\r\n ref={ref}\r\n className={cn(\r\n 'flex cursor-default items-center justify-center py-1',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <ChevronUp className=\"h-4 w-4\" />\r\n </SelectPrimitive.ScrollUpButton>\r\n));\r\nSelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;\r\n\r\nconst SelectScrollDownButton = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.ScrollDownButton\r\n ref={ref}\r\n className={cn(\r\n 'flex cursor-default items-center justify-center py-1',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <ChevronDown className=\"h-4 w-4\" />\r\n </SelectPrimitive.ScrollDownButton>\r\n));\r\nSelectScrollDownButton.displayName =\r\n SelectPrimitive.ScrollDownButton.displayName;\r\n\r\nconst SelectContent = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Content>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & { title?: string }\r\n>(({ className, children, position = 'popper', title: ownTitle, style, ...props }, ref) => {\r\n // The phone sheet's title: an explicit title, else the field's label.\r\n const title = ownTitle ?? useFormField()?.labelText ?? 'Choose an option';\r\n const mobile = useMobile();\r\n const { open, setOpen } = React.useContext(SelectContext);\r\n const viewport = useMobileSheetViewport(open && mobile);\r\n\r\n return (\r\n <SelectPrimitive.Portal>\r\n <div\r\n className={mobile ? '[&>[data-radix-popper-content-wrapper]]:!fixed [&>[data-radix-popper-content-wrapper]]:!inset-x-0 [&>[data-radix-popper-content-wrapper]]:!top-auto [&>[data-radix-popper-content-wrapper]]:!bottom-[var(--select-sheet-bottom)] [&>[data-radix-popper-content-wrapper]]:!transform-none [&>[data-radix-popper-content-wrapper]]:!z-(--z-popover) [&>[data-radix-popper-content-wrapper]]:!min-w-0' : undefined}\r\n style={{ '--select-sheet-bottom': `${viewport?.bottom ?? 0}px` } as React.CSSProperties}\r\n >\r\n {mobile && open && (\r\n <div aria-hidden=\"true\" className=\"fixed inset-0 z-(--z-popover-overlay) bg-black/25 backdrop-blur-[1px]\" />\r\n )}\r\n <SelectPrimitive.Content\r\n ref={ref}\r\n className={cn(\r\n 'relative flex flex-col overflow-hidden border border-border bg-background text-sm text-foreground shadow-card duration-interactive ease-out-strong motion-reduce:animate-none',\r\n mobile\r\n ? 'w-full rounded-t-control-lg border-b-0 pb-[env(safe-area-inset-bottom)]'\r\n : 'z-(--z-popover) max-h-[400px] min-w-[8rem] rounded-control-lg 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',\r\n className,\r\n )}\r\n position={mobile ? 'popper' : position}\r\n sideOffset={4}\r\n style={{\r\n ...(mobile ? { maxHeight: viewport ? Math.min(viewport.height, 640) : '80dvh' } : {}),\r\n ...style,\r\n }}\r\n {...props}\r\n >\r\n {mobile && (\r\n <div role=\"presentation\" className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-3 pt-4\">\r\n <h2 className=\"text-base font-semibold text-foreground\">{title}</h2>\r\n <button\r\n type=\"button\"\r\n aria-label=\"Close options\"\r\n className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\r\n onPointerDown={(event) => event.stopPropagation()}\r\n onClick={() => setOpen(false)}\r\n >\r\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\r\n </button>\r\n </div>\r\n )}\r\n {!mobile && <SelectScrollUpButton />}\r\n <SelectPrimitive.Viewport\r\n className={cn(\r\n 'flex min-h-0 flex-col gap-option-gap overflow-y-auto overscroll-contain p-option-inset',\r\n mobile ? 'w-full flex-1' : position === 'popper' && 'w-full min-w-[var(--radix-select-trigger-width)]',\r\n )}\r\n >\r\n {children}\r\n </SelectPrimitive.Viewport>\r\n {!mobile && <SelectScrollDownButton />}\r\n </SelectPrimitive.Content>\r\n </div>\r\n </SelectPrimitive.Portal>\r\n );\r\n});\r\nSelectContent.displayName = SelectPrimitive.Content.displayName;\r\n\r\nconst SelectLabel = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Label>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.Label\r\n ref={ref}\r\n className={cn('px-option-x py-2 text-sm font-semibold text-foreground', className)}\r\n {...props}\r\n />\r\n));\r\nSelectLabel.displayName = SelectPrimitive.Label.displayName;\r\n\r\nconst SelectItem = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Item>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>\r\n>(({ className, children, ...props }, ref) => (\r\n <SelectPrimitive.Item\r\n ref={ref}\r\n className={cn(\r\n 'relative flex min-h-option-row w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 pr-9 text-sm text-muted-foreground outline-none select-none transition-colors duration-interactive ease-out-strong focus:bg-muted data-[state=checked]:bg-primary-tint data-[disabled]:pointer-events-none data-[disabled]:opacity-50 motion-reduce:transition-none max-md:min-h-12',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <span className=\"absolute right-option-x flex h-4 w-4 items-center justify-center\">\r\n <SelectPrimitive.ItemIndicator>\r\n <Check className=\"h-4 w-4\" />\r\n </SelectPrimitive.ItemIndicator>\r\n </span>\r\n\r\n <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>\r\n </SelectPrimitive.Item>\r\n));\r\nSelectItem.displayName = SelectPrimitive.Item.displayName;\r\n\r\nconst SelectSeparator = React.forwardRef<\r\n React.ElementRef<typeof SelectPrimitive.Separator>,\r\n React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>\r\n>(({ className, ...props }, ref) => (\r\n <SelectPrimitive.Separator\r\n ref={ref}\r\n className={cn('bg-border h-px', className)}\r\n {...props}\r\n />\r\n));\r\nSelectSeparator.displayName = SelectPrimitive.Separator.displayName;\r\n\r\nexport {\r\n Select,\r\n SelectGroup,\r\n SelectValue,\r\n SelectTrigger,\r\n SelectContent,\r\n SelectLabel,\r\n SelectItem,\r\n SelectSeparator,\r\n SelectScrollUpButton,\r\n SelectScrollDownButton,\r\n};\r\n"],"names":[],"mappings":";;;;;;;;;;;AAYA;AAEA;AACE;AACA;AACA;;;AAEE;AACF;AAEA;AAOF;AAEA;AAEA;AAEA;AAIE;AACA;;;;;;;AAOA;AACE;AACE;AAAoF;AACtF;;AAEA;;;AAKE;;;AAEK;AAAS;AAChB;AAEE;AACA;AACF;AAEE;AACA;AACA;AACA;;AACF;AAeJ;AACA;AAEA;AAeA;AAEA;AAeA;AACE;AAEF;;;AAME;AACA;;AAGA;AAcQ;;AAOF;AACA;;AAgCR;AACA;AAEA;AAUA;AAEA;AAqBA;AAEA;AAUA;;"}
|
|
@@ -7,7 +7,7 @@ declare const SheetClose: React.ForwardRefExoticComponent<SheetPrimitive.DialogC
|
|
|
7
7
|
declare const SheetPortal: React.FC<SheetPrimitive.DialogPortalProps>;
|
|
8
8
|
declare const SheetOverlay: React.ForwardRefExoticComponent<Omit<SheetPrimitive.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
9
|
declare const sheetVariants: (props?: ({
|
|
10
|
-
side?: "
|
|
10
|
+
side?: "bottom" | "left" | "right" | "top" | null | undefined;
|
|
11
11
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
12
12
|
interface SheetContentProps extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>, VariantProps<typeof sheetVariants> {
|
|
13
13
|
showCloseButton?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as SwitchPrimitive from '@radix-ui/react-switch';
|
|
3
|
-
declare function Switch({ className, ...
|
|
3
|
+
declare function Switch({ className, ...ownProps }: React.ComponentProps<typeof SwitchPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export { Switch };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from 'react/jsx-runtime';
|
|
2
3
|
import * as SwitchPrimitive from '@radix-ui/react-switch';
|
|
3
4
|
import { cn } from '../utils.js';
|
|
5
|
+
import { useFormFieldControl } from './form-field.js';
|
|
4
6
|
|
|
5
|
-
function Switch({ className, ...
|
|
7
|
+
function Switch({ className, ...ownProps }) {
|
|
8
|
+
const props = useFormFieldControl(ownProps);
|
|
6
9
|
return (jsx(SwitchPrimitive.Root, { "data-slot": "switch", className: cn('relative after:absolute after:-inset-y-3 after:-inset-x-2 after:content-[""] peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-[background-color,border-color,box-shadow] duration-state ease-out-strong outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none', className), ...props, children: jsx(SwitchPrimitive.Thumb, { "data-slot": "switch-thumb", className: cn('bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform duration-state ease-out-strong data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 motion-reduce:transition-none') }) }));
|
|
7
10
|
}
|
|
8
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","sources":["../../src/components/switch.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"switch.js","sources":["../../src/components/switch.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\nimport * as SwitchPrimitive from '@radix-ui/react-switch';\r\n\r\nimport { cn } from '@/utils';\r\nimport { useFormFieldControl } from './form-field';\r\n\r\nfunction Switch({\r\n className,\r\n ...ownProps\r\n}: React.ComponentProps<typeof SwitchPrimitive.Root>) {\r\n const props = useFormFieldControl(ownProps);\r\n return (\r\n <SwitchPrimitive.Root\r\n data-slot=\"switch\"\r\n className={cn(\r\n 'relative after:absolute after:-inset-y-3 after:-inset-x-2 after:content-[\"\"] peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-[background-color,border-color,box-shadow] duration-state ease-out-strong outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none',\r\n className,\r\n )}\r\n {...props}\r\n >\r\n <SwitchPrimitive.Thumb\r\n data-slot=\"switch-thumb\"\r\n className={cn(\r\n 'bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform duration-state ease-out-strong data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 motion-reduce:transition-none',\r\n )}\r\n />\r\n </SwitchPrimitive.Root>\r\n );\r\n}\r\n\r\nexport { Switch };\r\n"],"names":[],"mappings":";;;;;;AAQA;AAIE;AACA;AAiBF;;"}
|
package/dist/components/table.js
CHANGED
|
@@ -11,10 +11,10 @@ import { cn } from '../utils.js';
|
|
|
11
11
|
// REVIEW SNAPSHOT: bi-iom/IOM-Client/components/ui/resource-table.tsx
|
|
12
12
|
// Source SHA-256: 9772e5fbce1e3adc3af1e8bf8184c4ef3546a0608cce43154aeecad56ca58fd6
|
|
13
13
|
// Generated by playground/review/snapshot.mjs; import paths normalized for isolated review.
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
const SELECTION_CHECKBOX_CLASS = "
|
|
14
|
+
// The standard 16px checkbox, with a visible hover cue: these sit in a dense,
|
|
15
|
+
// easy-to-miss leading column. UnselectableMark matches the same size so a
|
|
16
|
+
// column of checkboxes stays aligned.
|
|
17
|
+
const SELECTION_CHECKBOX_CLASS = "hover:border-primary hover:ring-2 hover:ring-primary/15";
|
|
18
18
|
/**
|
|
19
19
|
* Stands in for the selection checkbox on rows the caller marked
|
|
20
20
|
* unselectable. A disabled Radix checkbox only fades — with no indicator
|
|
@@ -23,7 +23,7 @@ const SELECTION_CHECKBOX_CLASS = "size-5 border-gray-400 hover:border-primary ho
|
|
|
23
23
|
* subtle opacity change.
|
|
24
24
|
*/
|
|
25
25
|
function UnselectableMark({ className, reason = "Not selectable", }) {
|
|
26
|
-
return (jsxs(Tooltip, { children: [jsx(TooltipTrigger, { asChild: true, children: jsx("span", { className: cn("flex size-
|
|
26
|
+
return (jsxs(Tooltip, { children: [jsx(TooltipTrigger, { asChild: true, children: jsx("span", { className: cn("flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-gray-300 bg-gray-100", className), role: "img", tabIndex: 0, "aria-label": "Not selectable", children: jsx(X, { className: "size-3 text-gray-400", strokeWidth: 3, "aria-hidden": "true" }) }) }), jsx(TooltipContent, { side: "right", sideOffset: 6, children: reason })] }));
|
|
27
27
|
}
|
|
28
28
|
function ResourceFilterPanel({ groups, draftValue, draftActiveCount, toggleOption, toggleGroup, clearDraft, cancel, apply, }) {
|
|
29
29
|
return (jsxs(Fragment, { children: [jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2", children: [jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Filters" }), draftActiveCount > 0 && (jsx("button", { type: "button", onClick: clearDraft, className: "shrink-0 text-sm font-medium text-gray-600 hover:text-primary", children: "Clear all" }))] }), jsx("div", { className: "min-h-0 flex-1 space-y-3 overflow-y-auto p-3", children: groups.map((group) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sources":["../../src/components/table.tsx"],"sourcesContent":["// REVIEW SNAPSHOT: bi-iom/IOM-Client/components/ui/resource-table.tsx\r\n// Source SHA-256: 9772e5fbce1e3adc3af1e8bf8184c4ef3546a0608cce43154aeecad56ca58fd6\r\n// Generated by playground/review/snapshot.mjs; import paths normalized for isolated review.\r\n\"use client\";\r\n\r\nimport { type ReactNode } from \"react\";\r\nimport {\r\n ChevronDown,\r\n ChevronLeft,\r\n ChevronRight,\r\n ChevronUp,\r\n ChevronsUpDown,\r\n Filter,\r\n Search,\r\n X,\r\n} from \"lucide-react\";\r\n\r\nimport { Button } from \"@/components/button\";\r\nimport { Checkbox } from \"@/components/checkbox\";\r\nimport {\r\n Popover,\r\n PopoverContent,\r\n PopoverTrigger,\r\n} from \"@/components/popover\";\r\nimport {\r\n Select,\r\n SelectContent,\r\n SelectItem,\r\n SelectTrigger,\r\n SelectValue,\r\n} from \"@/components/select\";\r\nimport {\r\n Tooltip,\r\n TooltipContent,\r\n TooltipTrigger,\r\n} from \"@/components/tooltip\";\r\nimport { cn } from \"@/utils\";\r\nimport type {\r\n ResourceFilterGroup,\r\n ResourceTableColumn,\r\n ResourceTableState,\r\n} from \"@/hooks/use-resource-table\";\r\n\r\nexport type { ResourceTableColumn } from \"@/hooks/use-resource-table\";\r\n\r\ntype ResourceEmptyState = {\r\n title: string;\r\n description?: ReactNode;\r\n action?: ReactNode;\r\n};\r\n\r\n// Sized up from the Checkbox default (size-4) and given a visible hover cue\r\n// — these sit in a dense, easy-to-miss leading column. UnselectableMark\r\n// matches the same size so a column of checkboxes stays aligned.\r\nconst SELECTION_CHECKBOX_CLASS =\r\n \"size-5 border-gray-400 hover:border-primary hover:ring-2 hover:ring-primary/15\";\r\n\r\n/**\r\n * Stands in for the selection checkbox on rows the caller marked\r\n * unselectable. A disabled Radix checkbox only fades — with no indicator\r\n * shown, it reads as barely-there. This is always visibly crossed out\r\n * instead, so \"you can't pick this row\" doesn't depend on noticing a\r\n * subtle opacity change.\r\n */\r\nfunction UnselectableMark({\r\n className,\r\n reason = \"Not selectable\",\r\n}: {\r\n className?: string;\r\n reason?: ReactNode;\r\n}) {\r\n return (\r\n <Tooltip>\r\n <TooltipTrigger asChild>\r\n <span\r\n className={cn(\r\n \"flex size-5 shrink-0 items-center justify-center rounded-[4px] border border-gray-300 bg-gray-100\",\r\n className,\r\n )}\r\n role=\"img\"\r\n tabIndex={0}\r\n aria-label=\"Not selectable\"\r\n >\r\n <X\r\n className=\"size-3.5 text-gray-400\"\r\n strokeWidth={3}\r\n aria-hidden=\"true\"\r\n />\r\n </span>\r\n </TooltipTrigger>\r\n <TooltipContent side=\"right\" sideOffset={6}>\r\n {reason}\r\n </TooltipContent>\r\n </Tooltip>\r\n );\r\n}\r\n\r\n\r\n\r\nfunction ResourceFilterPanel({\r\n groups,\r\n draftValue,\r\n draftActiveCount,\r\n toggleOption,\r\n toggleGroup,\r\n clearDraft,\r\n cancel,\r\n apply,\r\n}: {\r\n groups: ResourceFilterGroup[];\r\n draftValue: Record<string, string[]>;\r\n draftActiveCount: number;\r\n toggleOption: (\r\n groupId: string,\r\n optionValue: string,\r\n checked: boolean,\r\n ) => void;\r\n toggleGroup: (groupId: string) => void;\r\n clearDraft: () => void;\r\n cancel: () => void;\r\n apply: () => void;\r\n}) {\r\n return (\r\n <>\r\n <div className=\"flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2\">\r\n <span className=\"text-sm font-semibold text-gray-900\">Filters</span>\r\n {draftActiveCount > 0 && (\r\n <button\r\n type=\"button\"\r\n onClick={clearDraft}\r\n className=\"shrink-0 text-sm font-medium text-gray-600 hover:text-primary\"\r\n >\r\n Clear all\r\n </button>\r\n )}\r\n </div>\r\n\r\n <div className=\"min-h-0 flex-1 space-y-3 overflow-y-auto p-3\">\r\n {groups.map((group) => {\r\n const activeValues = draftValue[group.id] ?? [];\r\n const allSelected = activeValues.length === group.options.length;\r\n\r\n return (\r\n <section\r\n key={group.id}\r\n className=\"overflow-hidden rounded-control-lg border border-border bg-background\"\r\n >\r\n <div className=\"flex items-center justify-between border-b border-border px-4 py-2.5\">\r\n <span className=\"text-sm font-semibold text-foreground\">\r\n {group.label}\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={() => toggleGroup(group.id)}\r\n className=\"text-sm font-medium text-muted-foreground hover:text-primary\"\r\n >\r\n {allSelected ? \"Clear\" : \"Select all\"}\r\n </button>\r\n </div>\r\n <div className=\"flex flex-col gap-option-gap p-option-inset\">\r\n {group.options.map((option) => (\r\n <label\r\n key={option.value}\r\n className=\"flex min-h-option-row cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted active:bg-muted\"\r\n >\r\n <span className=\"flex-1\">{option.label}</span>\r\n {typeof option.count === \"number\" && (\r\n <span className=\"text-muted-foreground\">\r\n {option.count}\r\n </span>\r\n )}\r\n <Checkbox\r\n checked={activeValues.includes(option.value)}\r\n onCheckedChange={(checked) =>\r\n toggleOption(group.id, option.value, checked === true)\r\n }\r\n />\r\n </label>\r\n ))}\r\n </div>\r\n </section>\r\n );\r\n })}\r\n </div>\r\n\r\n <div className=\"flex items-center justify-end gap-2 border-t bg-white px-3 py-2.5\">\r\n <Button variant=\"outline\" onClick={cancel}>\r\n Cancel\r\n </Button>\r\n <Button onClick={apply}>Apply</Button>\r\n </div>\r\n </>\r\n );\r\n}\r\n\r\nexport function ResourceTable<TData>({\r\n table,\r\n columns = table.columns,\r\n renderMobileRow,\r\n emptyState,\r\n noResultsState,\r\n rowLabelSingular,\r\n rowLabelPlural,\r\n className,\r\n contentClassName,\r\n listClassName,\r\n paginationClassName,\r\n toolbarStart,\r\n toolbarLeading,\r\n showSelectionRatio = true,\r\n selectionColumnClassName,\r\n rowSelectionCheckboxClassName,\r\n rowSelectionUnavailableClassName,\r\n getRowSelectionUnavailableReason,\r\n selectionIndicatorClassName,\r\n headerSelectionCheckboxClassName,\r\n onRowClick,\r\n getRowClassName,\r\n}: {\r\n table: ResourceTableState<TData>;\r\n columns?: Array<ResourceTableColumn<TData>>;\r\n renderMobileRow: (row: TData) => ReactNode;\r\n emptyState: ResourceEmptyState;\r\n noResultsState?: ResourceEmptyState;\r\n rowLabelSingular: string;\r\n rowLabelPlural: string;\r\n className?: string;\r\n contentClassName?: string;\r\n listClassName?: string;\r\n paginationClassName?: string;\r\n toolbarStart?: ReactNode;\r\n toolbarLeading?: ReactNode;\r\n showSelectionRatio?: boolean;\r\n selectionColumnClassName?: string;\r\n rowSelectionCheckboxClassName?: string;\r\n rowSelectionUnavailableClassName?: string;\r\n getRowSelectionUnavailableReason?: (row: TData) => ReactNode;\r\n selectionIndicatorClassName?: string;\r\n headerSelectionCheckboxClassName?: string;\r\n onRowClick?: (row: TData) => void;\r\n getRowClassName?: (row: TData) => string | undefined;\r\n}) {\r\n const hasToolbar =\r\n !!toolbarStart || !!toolbarLeading || !!table.search || !!table.filters;\r\n const hasRows = table.pagedRows.length > 0;\r\n const hasAnyData = table.dataCount > 0;\r\n const hasDesktopTable = !!columns?.length;\r\n const resolvedEmptyState = hasAnyData\r\n ? (noResultsState ?? emptyState)\r\n : emptyState;\r\n\r\n const selection = table.selection;\r\n const selectablePageRows = selection\r\n ? table.pagedRows.filter(selection.isRowSelectable)\r\n : [];\r\n const headerCheckedState = selection\r\n ? selection.isAllPageSelected\r\n ? true\r\n : selectablePageRows.some((row) => selection.isSelected(row))\r\n ? \"indeterminate\"\r\n : false\r\n : false;\r\n const showSelectAllMatchingBanner =\r\n !!selection &&\r\n hasRows &&\r\n selection.isAllPageSelected &&\r\n selection.selectableMatchingCount > selection.selectablePageCount;\r\n const showAllMatchingSelectedBanner =\r\n !!selection &&\r\n hasRows &&\r\n selection.isAllMatchingSelected &&\r\n selection.selectableMatchingCount > selection.selectablePageCount;\r\n\r\n const renderHeaderCell = (column: ResourceTableColumn<TData>) => {\r\n const sortColumn = table.sort?.columns.find(\r\n (item) => item.id === column.id,\r\n );\r\n const isSortable =\r\n !!table.sort && column.sortable !== false && !!sortColumn;\r\n const isActive = table.sort?.column === column.id;\r\n const isDesc = isActive && table.sort?.direction === \"desc\";\r\n\r\n return (\r\n <th\r\n key={column.id}\r\n className={cn(\r\n \"px-5 py-3 font-medium\",\r\n column.align === \"center\" && \"text-center\",\r\n column.align === \"right\" && \"text-right\",\r\n column.width,\r\n )}\r\n >\r\n {isSortable ? (\r\n <button\r\n type=\"button\"\r\n className={cn(\r\n \"inline-flex cursor-pointer items-center gap-1.5 text-left hover:text-gray-900\",\r\n column.align === \"center\" && \"justify-center\",\r\n column.align === \"right\" && \"justify-end\",\r\n isActive && \"text-primary\",\r\n )}\r\n onClick={() =>\r\n table.sort?.setSort(column.id, column.defaultSortDirection)\r\n }\r\n >\r\n {column.header}\r\n {isDesc ? (\r\n <ChevronDown className=\"h-3.5 w-3.5\" />\r\n ) : isActive ? (\r\n <ChevronUp className=\"h-3.5 w-3.5\" />\r\n ) : (\r\n <ChevronsUpDown className=\"text-muted-foreground/60 h-3.5 w-3.5\" />\r\n )}\r\n </button>\r\n ) : (\r\n column.header\r\n )}\r\n </th>\r\n );\r\n };\r\n\r\n return (\r\n <div className={cn(\"space-y-5\", className)}>\r\n {hasToolbar && (\r\n <div\r\n className={cn(\r\n \"flex flex-wrap items-center gap-2\",\r\n toolbarStart && \"min-w-0 lg:flex-nowrap\",\r\n )}\r\n >\r\n {toolbarStart && (\r\n <div className=\"min-w-0 max-w-full overflow-hidden\">\r\n {toolbarStart}\r\n </div>\r\n )}\r\n\r\n <div\r\n className={cn(\r\n \"flex min-w-0 flex-1 items-center gap-2\",\r\n toolbarStart && \"w-full justify-end lg:ml-auto lg:w-auto\",\r\n )}\r\n >\r\n {table.search && (\r\n <div\r\n className={cn(\r\n \"relative min-w-0 flex-1\",\r\n toolbarStart ? \"lg:w-80 lg:flex-none\" : \"w-full max-w-xl\",\r\n )}\r\n >\r\n <Search className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-4 z-20 h-4 w-4 -translate-y-1/2\" />\r\n <input\r\n type=\"search\"\r\n value={table.search.value}\r\n onChange={(event) =>\r\n table.search?.setValue(event.target.value)\r\n }\r\n placeholder={table.search.placeholder}\r\n aria-label={table.search.ariaLabel}\r\n className=\"placeholder:text-muted-foreground/60 focus:border-primary h-11 w-full rounded-[0.33em] border border-gray-200 bg-white pr-4 pl-11 text-sm outline-none transition-colors focus:ring-2 focus:ring-primary/10\"\r\n />\r\n </div>\r\n )}\r\n\r\n {table.filters && (\r\n <Popover\r\n open={table.filters.open}\r\n onOpenChange={table.filters.setOpen}\r\n >\r\n <PopoverTrigger asChild>\r\n <Button\r\n variant=\"outline\"\r\n size=\"sm\"\r\n className={cn(\r\n \"relative h-11 w-11 shrink-0 border-gray-200 bg-white text-gray-600 hover:text-primary\",\r\n table.filters.activeCount > 0 && \"text-primary\",\r\n )}\r\n aria-label=\"Filter results\"\r\n aria-expanded={table.filters.open}\r\n >\r\n <Filter />\r\n {table.filters.activeCount > 0 && (\r\n <span className=\"bg-primary text-primary-foreground absolute top-0 right-0 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[11px] font-semibold\">\r\n {table.filters.activeCount}\r\n </span>\r\n )}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent\r\n align=\"start\"\r\n sideOffset={6}\r\n className=\"flex max-h-[70vh] w-[calc(100vw-2rem)] flex-col overflow-hidden rounded-[0.33em] border border-gray-200 bg-white p-0 shadow-lg sm:w-[445px]\"\r\n >\r\n <ResourceFilterPanel\r\n groups={table.filters.groups}\r\n draftValue={table.filters.draftValue}\r\n draftActiveCount={table.filters.draftActiveCount}\r\n toggleOption={table.filters.toggleDraftOption}\r\n toggleGroup={table.filters.toggleDraftGroup}\r\n clearDraft={table.filters.clearDraft}\r\n cancel={table.filters.cancel}\r\n apply={table.filters.apply}\r\n />\r\n </PopoverContent>\r\n </Popover>\r\n )}\r\n\r\n {toolbarLeading}\r\n </div>\r\n </div>\r\n )}\r\n\r\n {hasRows ? (\r\n <div\r\n className={cn(\r\n \"overflow-hidden rounded-[0.33em] border border-gray-200 bg-white\",\r\n contentClassName,\r\n )}\r\n >\r\n {(showSelectAllMatchingBanner || showAllMatchingSelectedBanner) && (\r\n <div className=\"bg-primary/5 flex items-center justify-center gap-2 border-b border-gray-200 px-4 py-2 text-sm text-gray-700\">\r\n {showAllMatchingSelectedBanner ? (\r\n <>\r\n <span>\r\n All {selection!.selectableMatchingCount} matching rows are\r\n selected.\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={selection!.clear}\r\n className=\"text-primary cursor-pointer font-medium hover:underline\"\r\n >\r\n Clear selection\r\n </button>\r\n </>\r\n ) : (\r\n <>\r\n <span>\r\n All {selection!.selectablePageCount} on this page are\r\n selected.\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={selection!.selectAllMatching}\r\n className=\"text-primary cursor-pointer font-medium hover:underline\"\r\n >\r\n Select all {selection!.selectableMatchingCount} matching\r\n rows\r\n </button>\r\n </>\r\n )}\r\n </div>\r\n )}\r\n\r\n {hasDesktopTable && (\r\n <div className=\"hidden overflow-x-auto md:block\">\r\n <table className=\"w-full table-fixed border-collapse text-left\">\r\n <thead className=\"bg-gray-50 text-sm font-medium text-gray-700\">\r\n <tr className=\"border-b border-gray-200\">\r\n {selection && (\r\n <th\r\n className={cn(\r\n \"w-16 px-3 py-3\",\r\n selectionColumnClassName,\r\n )}\r\n >\r\n <div className=\"flex flex-col items-start gap-0.5\">\r\n <Checkbox\r\n checked={headerCheckedState}\r\n onCheckedChange={() =>\r\n selection.isAllPageSelected\r\n ? selection.deselectPage()\r\n : selection.selectPage()\r\n }\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n selectionIndicatorClassName,\r\n headerSelectionCheckboxClassName,\r\n )}\r\n aria-label=\"Select all rows on this page\"\r\n />\r\n {showSelectionRatio &&\r\n selection.selectablePageCount <\r\n table.pagedRows.length && (\r\n <span className=\"text-muted-foreground text-[10px] leading-tight font-normal\">\r\n {selection.selectablePageCount}/\r\n {table.pagedRows.length}\r\n </span>\r\n )}\r\n </div>\r\n </th>\r\n )}\r\n {columns.map(renderHeaderCell)}\r\n </tr>\r\n </thead>\r\n <tbody>\r\n {table.pagedRows.map((row) => {\r\n const rowSelectable =\r\n selection?.isRowSelectable(row) ?? true;\r\n return (\r\n <tr\r\n key={table.getRowId(row)}\r\n className={cn(\r\n \"group border-b border-gray-200 transition-colors last:border-b-0 hover:bg-primary/[0.035] focus-within:bg-primary/[0.035]\",\r\n onRowClick && \"cursor-pointer\",\r\n getRowClassName?.(row),\r\n )}\r\n onClick={onRowClick ? () => onRowClick(row) : undefined}\r\n >\r\n {selection && (\r\n <td\r\n className={cn(\r\n \"px-3 py-4\",\r\n selectionColumnClassName,\r\n )}\r\n onClick={(event) => event.stopPropagation()}\r\n >\r\n {rowSelectable ? (\r\n <span className=\"flex size-5 items-center justify-center\">\r\n <Checkbox\r\n checked={selection.isSelected(row)}\r\n onCheckedChange={() => selection.toggle(row)}\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n rowSelectionCheckboxClassName,\r\n selectionIndicatorClassName,\r\n )}\r\n aria-label=\"Select row\"\r\n />\r\n </span>\r\n ) : (\r\n <UnselectableMark\r\n reason={getRowSelectionUnavailableReason?.(row)}\r\n className={cn(\r\n selectionIndicatorClassName,\r\n rowSelectionUnavailableClassName,\r\n )}\r\n />\r\n )}\r\n </td>\r\n )}\r\n {columns.map((column) => (\r\n <td\r\n key={column.id}\r\n className={cn(\r\n \"px-5 py-4\",\r\n column.align === \"center\" && \"text-center\",\r\n column.align === \"right\" && \"text-right\",\r\n )}\r\n >\r\n {column.render(row)}\r\n </td>\r\n ))}\r\n </tr>\r\n );\r\n })}\r\n </tbody>\r\n </table>\r\n </div>\r\n )}\r\n\r\n <div\r\n className={cn(\r\n \"divide-y divide-gray-200\",\r\n hasDesktopTable && \"md:hidden\",\r\n listClassName,\r\n )}\r\n >\r\n {table.pagedRows.map((row) => {\r\n const rowSelectable = selection?.isRowSelectable(row) ?? true;\r\n return (\r\n <div key={table.getRowId(row)} className=\"flex items-start\">\r\n {selection && (\r\n <div\r\n className=\"flex shrink-0 items-center self-stretch pl-4\"\r\n onClick={(event) => event.stopPropagation()}\r\n >\r\n {rowSelectable ? (\r\n <span className=\"flex size-5 items-center justify-center\">\r\n <Checkbox\r\n checked={selection.isSelected(row)}\r\n onCheckedChange={() => selection.toggle(row)}\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n rowSelectionCheckboxClassName,\r\n selectionIndicatorClassName,\r\n )}\r\n aria-label=\"Select row\"\r\n />\r\n </span>\r\n ) : (\r\n <UnselectableMark\r\n reason={getRowSelectionUnavailableReason?.(row)}\r\n className={cn(\r\n selectionIndicatorClassName,\r\n rowSelectionUnavailableClassName,\r\n )}\r\n />\r\n )}\r\n </div>\r\n )}\r\n <div className=\"min-w-0 flex-1\">{renderMobileRow(row)}</div>\r\n </div>\r\n );\r\n })}\r\n </div>\r\n\r\n <div\r\n className={cn(\r\n \"flex flex-col items-center justify-between gap-3 border-t border-gray-200 px-5 py-4 sm:flex-row\",\r\n paginationClassName,\r\n )}\r\n >\r\n <p className=\"text-muted-foreground text-sm\">\r\n Showing {table.pageStart + 1} to {table.pageEnd} of{\" \"}\r\n {table.totalCount}{\" \"}\r\n {table.totalCount === 1 ? rowLabelSingular : rowLabelPlural}\r\n </p>\r\n <div className=\"flex flex-wrap items-center justify-center gap-3\">\r\n <label className=\"text-muted-foreground flex items-center gap-2 text-sm whitespace-nowrap\">\r\n Rows per page\r\n <Select\r\n value={String(table.pagination.pageSize)}\r\n onValueChange={(value) =>\r\n table.pagination.setPageSize(Number(value))\r\n }\r\n >\r\n <SelectTrigger className=\"w-20\" aria-label=\"Rows per page\">\r\n <SelectValue />\r\n </SelectTrigger>\r\n <SelectContent align=\"end\">\r\n {table.pagination.pageSizeOptions.map((pageSize) => (\r\n <SelectItem key={pageSize} value={String(pageSize)}>\r\n {pageSize}\r\n </SelectItem>\r\n ))}\r\n </SelectContent>\r\n </Select>\r\n </label>\r\n\r\n {table.pageCount > 1 && (\r\n <div\r\n className=\"flex items-center gap-1\"\r\n aria-label=\"Pagination\"\r\n >\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n disabled={table.page === 1}\r\n onClick={() => table.pagination.setPage(table.page - 1)}\r\n aria-label=\"Previous page\"\r\n >\r\n <ChevronLeft />\r\n </Button>\r\n {Array.from(\r\n { length: table.pageCount },\r\n (_, index) => index + 1,\r\n )\r\n .filter(\r\n (page) =>\r\n page === 1 ||\r\n page === table.pageCount ||\r\n Math.abs(page - table.page) <= 1,\r\n )\r\n .map((page, index, pages) => (\r\n <span key={page} className=\"flex items-center gap-1\">\r\n {index > 0 && page - pages[index - 1] > 1 && (\r\n <span className=\"text-muted-foreground px-1\">\r\n ...\r\n </span>\r\n )}\r\n <Button\r\n variant={page === table.page ? \"outline\" : \"ghost\"}\r\n scheme={page === table.page ? \"primary\" : undefined}\r\n size=\"sm\"\r\n className=\"h-9 w-9\"\r\n onClick={() => table.pagination.setPage(page)}\r\n aria-label={`Page ${page}`}\r\n aria-current={\r\n page === table.page ? \"page\" : undefined\r\n }\r\n >\r\n {page}\r\n </Button>\r\n </span>\r\n ))}\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n disabled={table.page === table.pageCount}\r\n onClick={() => table.pagination.setPage(table.page + 1)}\r\n aria-label=\"Next page\"\r\n >\r\n <ChevronRight />\r\n </Button>\r\n </div>\r\n )}\r\n </div>\r\n </div>\r\n </div>\r\n ) : (\r\n <div className=\"rounded-[0.33em] border border-dashed border-gray-300 bg-white px-6 py-12 text-center\">\r\n <p className=\"text-sm font-medium text-gray-700\">\r\n {resolvedEmptyState.title}\r\n </p>\r\n {resolvedEmptyState.description && (\r\n <p className=\"text-muted-foreground mt-1 text-sm\">\r\n {resolvedEmptyState.description}\r\n </p>\r\n )}\r\n {resolvedEmptyState.action && (\r\n <div className=\"mt-4\">{resolvedEmptyState.action}</div>\r\n )}\r\n </div>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport const Table = ResourceTable;\r\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAiDA;AACA;AACA;AACA;AAGA;;;;;;AAMG;AACH;AAOE;AAwBF;AAIA;;;;AA2CU;AAwCF;AAWR;AAEM;;;AAkDJ;AACA;;AAEE;;AAGF;;;;;;AAMI;AACA;AACE;AACA;;AAEN;;AAGE;AACA;AACF;;AAGE;AACA;AAEF;;AAIE;;;AAKA;AAqCF;;AAuJ8B;;AAWJ;;;;AAyEV;;;;;;;;AAkKlB;AAEO;;"}
|
|
1
|
+
{"version":3,"file":"table.js","sources":["../../src/components/table.tsx"],"sourcesContent":["// REVIEW SNAPSHOT: bi-iom/IOM-Client/components/ui/resource-table.tsx\r\n// Source SHA-256: 9772e5fbce1e3adc3af1e8bf8184c4ef3546a0608cce43154aeecad56ca58fd6\r\n// Generated by playground/review/snapshot.mjs; import paths normalized for isolated review.\r\n\"use client\";\r\n\r\nimport { type ReactNode } from \"react\";\r\nimport {\r\n ChevronDown,\r\n ChevronLeft,\r\n ChevronRight,\r\n ChevronUp,\r\n ChevronsUpDown,\r\n Filter,\r\n Search,\r\n X,\r\n} from \"lucide-react\";\r\n\r\nimport { Button } from \"@/components/button\";\r\nimport { Checkbox } from \"@/components/checkbox\";\r\nimport {\r\n Popover,\r\n PopoverContent,\r\n PopoverTrigger,\r\n} from \"@/components/popover\";\r\nimport {\r\n Select,\r\n SelectContent,\r\n SelectItem,\r\n SelectTrigger,\r\n SelectValue,\r\n} from \"@/components/select\";\r\nimport {\r\n Tooltip,\r\n TooltipContent,\r\n TooltipTrigger,\r\n} from \"@/components/tooltip\";\r\nimport { cn } from \"@/utils\";\r\nimport type {\r\n ResourceFilterGroup,\r\n ResourceTableColumn,\r\n ResourceTableState,\r\n} from \"@/hooks/use-resource-table\";\r\n\r\nexport type { ResourceTableColumn } from \"@/hooks/use-resource-table\";\r\n\r\ntype ResourceEmptyState = {\r\n title: string;\r\n description?: ReactNode;\r\n action?: ReactNode;\r\n};\r\n\r\n// The standard 16px checkbox, with a visible hover cue: these sit in a dense,\r\n// easy-to-miss leading column. UnselectableMark matches the same size so a\r\n// column of checkboxes stays aligned.\r\nconst SELECTION_CHECKBOX_CLASS =\r\n \"hover:border-primary hover:ring-2 hover:ring-primary/15\";\r\n\r\n/**\r\n * Stands in for the selection checkbox on rows the caller marked\r\n * unselectable. A disabled Radix checkbox only fades — with no indicator\r\n * shown, it reads as barely-there. This is always visibly crossed out\r\n * instead, so \"you can't pick this row\" doesn't depend on noticing a\r\n * subtle opacity change.\r\n */\r\nfunction UnselectableMark({\r\n className,\r\n reason = \"Not selectable\",\r\n}: {\r\n className?: string;\r\n reason?: ReactNode;\r\n}) {\r\n return (\r\n <Tooltip>\r\n <TooltipTrigger asChild>\r\n <span\r\n className={cn(\r\n \"flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-gray-300 bg-gray-100\",\r\n className,\r\n )}\r\n role=\"img\"\r\n tabIndex={0}\r\n aria-label=\"Not selectable\"\r\n >\r\n <X\r\n className=\"size-3 text-gray-400\"\r\n strokeWidth={3}\r\n aria-hidden=\"true\"\r\n />\r\n </span>\r\n </TooltipTrigger>\r\n <TooltipContent side=\"right\" sideOffset={6}>\r\n {reason}\r\n </TooltipContent>\r\n </Tooltip>\r\n );\r\n}\r\n\r\n\r\n\r\nfunction ResourceFilterPanel({\r\n groups,\r\n draftValue,\r\n draftActiveCount,\r\n toggleOption,\r\n toggleGroup,\r\n clearDraft,\r\n cancel,\r\n apply,\r\n}: {\r\n groups: ResourceFilterGroup[];\r\n draftValue: Record<string, string[]>;\r\n draftActiveCount: number;\r\n toggleOption: (\r\n groupId: string,\r\n optionValue: string,\r\n checked: boolean,\r\n ) => void;\r\n toggleGroup: (groupId: string) => void;\r\n clearDraft: () => void;\r\n cancel: () => void;\r\n apply: () => void;\r\n}) {\r\n return (\r\n <>\r\n <div className=\"flex items-center justify-between gap-3 border-b border-gray-200 px-3 py-2\">\r\n <span className=\"text-sm font-semibold text-gray-900\">Filters</span>\r\n {draftActiveCount > 0 && (\r\n <button\r\n type=\"button\"\r\n onClick={clearDraft}\r\n className=\"shrink-0 text-sm font-medium text-gray-600 hover:text-primary\"\r\n >\r\n Clear all\r\n </button>\r\n )}\r\n </div>\r\n\r\n <div className=\"min-h-0 flex-1 space-y-3 overflow-y-auto p-3\">\r\n {groups.map((group) => {\r\n const activeValues = draftValue[group.id] ?? [];\r\n const allSelected = activeValues.length === group.options.length;\r\n\r\n return (\r\n <section\r\n key={group.id}\r\n className=\"overflow-hidden rounded-control-lg border border-border bg-background\"\r\n >\r\n <div className=\"flex items-center justify-between border-b border-border px-4 py-2.5\">\r\n <span className=\"text-sm font-semibold text-foreground\">\r\n {group.label}\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={() => toggleGroup(group.id)}\r\n className=\"text-sm font-medium text-muted-foreground hover:text-primary\"\r\n >\r\n {allSelected ? \"Clear\" : \"Select all\"}\r\n </button>\r\n </div>\r\n <div className=\"flex flex-col gap-option-gap p-option-inset\">\r\n {group.options.map((option) => (\r\n <label\r\n key={option.value}\r\n className=\"flex min-h-option-row cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-sm text-foreground transition-colors hover:bg-muted active:bg-muted\"\r\n >\r\n <span className=\"flex-1\">{option.label}</span>\r\n {typeof option.count === \"number\" && (\r\n <span className=\"text-muted-foreground\">\r\n {option.count}\r\n </span>\r\n )}\r\n <Checkbox\r\n checked={activeValues.includes(option.value)}\r\n onCheckedChange={(checked) =>\r\n toggleOption(group.id, option.value, checked === true)\r\n }\r\n />\r\n </label>\r\n ))}\r\n </div>\r\n </section>\r\n );\r\n })}\r\n </div>\r\n\r\n <div className=\"flex items-center justify-end gap-2 border-t bg-white px-3 py-2.5\">\r\n <Button variant=\"outline\" onClick={cancel}>\r\n Cancel\r\n </Button>\r\n <Button onClick={apply}>Apply</Button>\r\n </div>\r\n </>\r\n );\r\n}\r\n\r\nexport function ResourceTable<TData>({\r\n table,\r\n columns = table.columns,\r\n renderMobileRow,\r\n emptyState,\r\n noResultsState,\r\n rowLabelSingular,\r\n rowLabelPlural,\r\n className,\r\n contentClassName,\r\n listClassName,\r\n paginationClassName,\r\n toolbarStart,\r\n toolbarLeading,\r\n showSelectionRatio = true,\r\n selectionColumnClassName,\r\n rowSelectionCheckboxClassName,\r\n rowSelectionUnavailableClassName,\r\n getRowSelectionUnavailableReason,\r\n selectionIndicatorClassName,\r\n headerSelectionCheckboxClassName,\r\n onRowClick,\r\n getRowClassName,\r\n}: {\r\n table: ResourceTableState<TData>;\r\n columns?: Array<ResourceTableColumn<TData>>;\r\n renderMobileRow: (row: TData) => ReactNode;\r\n emptyState: ResourceEmptyState;\r\n noResultsState?: ResourceEmptyState;\r\n rowLabelSingular: string;\r\n rowLabelPlural: string;\r\n className?: string;\r\n contentClassName?: string;\r\n listClassName?: string;\r\n paginationClassName?: string;\r\n toolbarStart?: ReactNode;\r\n toolbarLeading?: ReactNode;\r\n showSelectionRatio?: boolean;\r\n selectionColumnClassName?: string;\r\n rowSelectionCheckboxClassName?: string;\r\n rowSelectionUnavailableClassName?: string;\r\n getRowSelectionUnavailableReason?: (row: TData) => ReactNode;\r\n selectionIndicatorClassName?: string;\r\n headerSelectionCheckboxClassName?: string;\r\n onRowClick?: (row: TData) => void;\r\n getRowClassName?: (row: TData) => string | undefined;\r\n}) {\r\n const hasToolbar =\r\n !!toolbarStart || !!toolbarLeading || !!table.search || !!table.filters;\r\n const hasRows = table.pagedRows.length > 0;\r\n const hasAnyData = table.dataCount > 0;\r\n const hasDesktopTable = !!columns?.length;\r\n const resolvedEmptyState = hasAnyData\r\n ? (noResultsState ?? emptyState)\r\n : emptyState;\r\n\r\n const selection = table.selection;\r\n const selectablePageRows = selection\r\n ? table.pagedRows.filter(selection.isRowSelectable)\r\n : [];\r\n const headerCheckedState = selection\r\n ? selection.isAllPageSelected\r\n ? true\r\n : selectablePageRows.some((row) => selection.isSelected(row))\r\n ? \"indeterminate\"\r\n : false\r\n : false;\r\n const showSelectAllMatchingBanner =\r\n !!selection &&\r\n hasRows &&\r\n selection.isAllPageSelected &&\r\n selection.selectableMatchingCount > selection.selectablePageCount;\r\n const showAllMatchingSelectedBanner =\r\n !!selection &&\r\n hasRows &&\r\n selection.isAllMatchingSelected &&\r\n selection.selectableMatchingCount > selection.selectablePageCount;\r\n\r\n const renderHeaderCell = (column: ResourceTableColumn<TData>) => {\r\n const sortColumn = table.sort?.columns.find(\r\n (item) => item.id === column.id,\r\n );\r\n const isSortable =\r\n !!table.sort && column.sortable !== false && !!sortColumn;\r\n const isActive = table.sort?.column === column.id;\r\n const isDesc = isActive && table.sort?.direction === \"desc\";\r\n\r\n return (\r\n <th\r\n key={column.id}\r\n className={cn(\r\n \"px-5 py-3 font-medium\",\r\n column.align === \"center\" && \"text-center\",\r\n column.align === \"right\" && \"text-right\",\r\n column.width,\r\n )}\r\n >\r\n {isSortable ? (\r\n <button\r\n type=\"button\"\r\n className={cn(\r\n \"inline-flex cursor-pointer items-center gap-1.5 text-left hover:text-gray-900\",\r\n column.align === \"center\" && \"justify-center\",\r\n column.align === \"right\" && \"justify-end\",\r\n isActive && \"text-primary\",\r\n )}\r\n onClick={() =>\r\n table.sort?.setSort(column.id, column.defaultSortDirection)\r\n }\r\n >\r\n {column.header}\r\n {isDesc ? (\r\n <ChevronDown className=\"h-3.5 w-3.5\" />\r\n ) : isActive ? (\r\n <ChevronUp className=\"h-3.5 w-3.5\" />\r\n ) : (\r\n <ChevronsUpDown className=\"text-muted-foreground/60 h-3.5 w-3.5\" />\r\n )}\r\n </button>\r\n ) : (\r\n column.header\r\n )}\r\n </th>\r\n );\r\n };\r\n\r\n return (\r\n <div className={cn(\"space-y-5\", className)}>\r\n {hasToolbar && (\r\n <div\r\n className={cn(\r\n \"flex flex-wrap items-center gap-2\",\r\n toolbarStart && \"min-w-0 lg:flex-nowrap\",\r\n )}\r\n >\r\n {toolbarStart && (\r\n <div className=\"min-w-0 max-w-full overflow-hidden\">\r\n {toolbarStart}\r\n </div>\r\n )}\r\n\r\n <div\r\n className={cn(\r\n \"flex min-w-0 flex-1 items-center gap-2\",\r\n toolbarStart && \"w-full justify-end lg:ml-auto lg:w-auto\",\r\n )}\r\n >\r\n {table.search && (\r\n <div\r\n className={cn(\r\n \"relative min-w-0 flex-1\",\r\n toolbarStart ? \"lg:w-80 lg:flex-none\" : \"w-full max-w-xl\",\r\n )}\r\n >\r\n <Search className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-4 z-20 h-4 w-4 -translate-y-1/2\" />\r\n <input\r\n type=\"search\"\r\n value={table.search.value}\r\n onChange={(event) =>\r\n table.search?.setValue(event.target.value)\r\n }\r\n placeholder={table.search.placeholder}\r\n aria-label={table.search.ariaLabel}\r\n className=\"placeholder:text-muted-foreground/60 focus:border-primary h-11 w-full rounded-[0.33em] border border-gray-200 bg-white pr-4 pl-11 text-sm outline-none transition-colors focus:ring-2 focus:ring-primary/10\"\r\n />\r\n </div>\r\n )}\r\n\r\n {table.filters && (\r\n <Popover\r\n open={table.filters.open}\r\n onOpenChange={table.filters.setOpen}\r\n >\r\n <PopoverTrigger asChild>\r\n <Button\r\n variant=\"outline\"\r\n size=\"sm\"\r\n className={cn(\r\n \"relative h-11 w-11 shrink-0 border-gray-200 bg-white text-gray-600 hover:text-primary\",\r\n table.filters.activeCount > 0 && \"text-primary\",\r\n )}\r\n aria-label=\"Filter results\"\r\n aria-expanded={table.filters.open}\r\n >\r\n <Filter />\r\n {table.filters.activeCount > 0 && (\r\n <span className=\"bg-primary text-primary-foreground absolute top-0 right-0 inline-flex h-5 min-w-5 items-center justify-center rounded-full px-1 text-[11px] font-semibold\">\r\n {table.filters.activeCount}\r\n </span>\r\n )}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent\r\n align=\"start\"\r\n sideOffset={6}\r\n className=\"flex max-h-[70vh] w-[calc(100vw-2rem)] flex-col overflow-hidden rounded-[0.33em] border border-gray-200 bg-white p-0 shadow-lg sm:w-[445px]\"\r\n >\r\n <ResourceFilterPanel\r\n groups={table.filters.groups}\r\n draftValue={table.filters.draftValue}\r\n draftActiveCount={table.filters.draftActiveCount}\r\n toggleOption={table.filters.toggleDraftOption}\r\n toggleGroup={table.filters.toggleDraftGroup}\r\n clearDraft={table.filters.clearDraft}\r\n cancel={table.filters.cancel}\r\n apply={table.filters.apply}\r\n />\r\n </PopoverContent>\r\n </Popover>\r\n )}\r\n\r\n {toolbarLeading}\r\n </div>\r\n </div>\r\n )}\r\n\r\n {hasRows ? (\r\n <div\r\n className={cn(\r\n \"overflow-hidden rounded-[0.33em] border border-gray-200 bg-white\",\r\n contentClassName,\r\n )}\r\n >\r\n {(showSelectAllMatchingBanner || showAllMatchingSelectedBanner) && (\r\n <div className=\"bg-primary/5 flex items-center justify-center gap-2 border-b border-gray-200 px-4 py-2 text-sm text-gray-700\">\r\n {showAllMatchingSelectedBanner ? (\r\n <>\r\n <span>\r\n All {selection!.selectableMatchingCount} matching rows are\r\n selected.\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={selection!.clear}\r\n className=\"text-primary cursor-pointer font-medium hover:underline\"\r\n >\r\n Clear selection\r\n </button>\r\n </>\r\n ) : (\r\n <>\r\n <span>\r\n All {selection!.selectablePageCount} on this page are\r\n selected.\r\n </span>\r\n <button\r\n type=\"button\"\r\n onClick={selection!.selectAllMatching}\r\n className=\"text-primary cursor-pointer font-medium hover:underline\"\r\n >\r\n Select all {selection!.selectableMatchingCount} matching\r\n rows\r\n </button>\r\n </>\r\n )}\r\n </div>\r\n )}\r\n\r\n {hasDesktopTable && (\r\n <div className=\"hidden overflow-x-auto md:block\">\r\n <table className=\"w-full table-fixed border-collapse text-left\">\r\n <thead className=\"bg-gray-50 text-sm font-medium text-gray-700\">\r\n <tr className=\"border-b border-gray-200\">\r\n {selection && (\r\n <th\r\n className={cn(\r\n \"w-16 px-3 py-3\",\r\n selectionColumnClassName,\r\n )}\r\n >\r\n <div className=\"flex flex-col items-start gap-0.5\">\r\n <Checkbox\r\n checked={headerCheckedState}\r\n onCheckedChange={() =>\r\n selection.isAllPageSelected\r\n ? selection.deselectPage()\r\n : selection.selectPage()\r\n }\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n selectionIndicatorClassName,\r\n headerSelectionCheckboxClassName,\r\n )}\r\n aria-label=\"Select all rows on this page\"\r\n />\r\n {showSelectionRatio &&\r\n selection.selectablePageCount <\r\n table.pagedRows.length && (\r\n <span className=\"text-muted-foreground text-[10px] leading-tight font-normal\">\r\n {selection.selectablePageCount}/\r\n {table.pagedRows.length}\r\n </span>\r\n )}\r\n </div>\r\n </th>\r\n )}\r\n {columns.map(renderHeaderCell)}\r\n </tr>\r\n </thead>\r\n <tbody>\r\n {table.pagedRows.map((row) => {\r\n const rowSelectable =\r\n selection?.isRowSelectable(row) ?? true;\r\n return (\r\n <tr\r\n key={table.getRowId(row)}\r\n className={cn(\r\n \"group border-b border-gray-200 transition-colors last:border-b-0 hover:bg-primary/[0.035] focus-within:bg-primary/[0.035]\",\r\n onRowClick && \"cursor-pointer\",\r\n getRowClassName?.(row),\r\n )}\r\n onClick={onRowClick ? () => onRowClick(row) : undefined}\r\n >\r\n {selection && (\r\n <td\r\n className={cn(\r\n \"px-3 py-4\",\r\n selectionColumnClassName,\r\n )}\r\n onClick={(event) => event.stopPropagation()}\r\n >\r\n {rowSelectable ? (\r\n <span className=\"flex size-5 items-center justify-center\">\r\n <Checkbox\r\n checked={selection.isSelected(row)}\r\n onCheckedChange={() => selection.toggle(row)}\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n rowSelectionCheckboxClassName,\r\n selectionIndicatorClassName,\r\n )}\r\n aria-label=\"Select row\"\r\n />\r\n </span>\r\n ) : (\r\n <UnselectableMark\r\n reason={getRowSelectionUnavailableReason?.(row)}\r\n className={cn(\r\n selectionIndicatorClassName,\r\n rowSelectionUnavailableClassName,\r\n )}\r\n />\r\n )}\r\n </td>\r\n )}\r\n {columns.map((column) => (\r\n <td\r\n key={column.id}\r\n className={cn(\r\n \"px-5 py-4\",\r\n column.align === \"center\" && \"text-center\",\r\n column.align === \"right\" && \"text-right\",\r\n )}\r\n >\r\n {column.render(row)}\r\n </td>\r\n ))}\r\n </tr>\r\n );\r\n })}\r\n </tbody>\r\n </table>\r\n </div>\r\n )}\r\n\r\n <div\r\n className={cn(\r\n \"divide-y divide-gray-200\",\r\n hasDesktopTable && \"md:hidden\",\r\n listClassName,\r\n )}\r\n >\r\n {table.pagedRows.map((row) => {\r\n const rowSelectable = selection?.isRowSelectable(row) ?? true;\r\n return (\r\n <div key={table.getRowId(row)} className=\"flex items-start\">\r\n {selection && (\r\n <div\r\n className=\"flex shrink-0 items-center self-stretch pl-4\"\r\n onClick={(event) => event.stopPropagation()}\r\n >\r\n {rowSelectable ? (\r\n <span className=\"flex size-5 items-center justify-center\">\r\n <Checkbox\r\n checked={selection.isSelected(row)}\r\n onCheckedChange={() => selection.toggle(row)}\r\n className={cn(\r\n SELECTION_CHECKBOX_CLASS,\r\n rowSelectionCheckboxClassName,\r\n selectionIndicatorClassName,\r\n )}\r\n aria-label=\"Select row\"\r\n />\r\n </span>\r\n ) : (\r\n <UnselectableMark\r\n reason={getRowSelectionUnavailableReason?.(row)}\r\n className={cn(\r\n selectionIndicatorClassName,\r\n rowSelectionUnavailableClassName,\r\n )}\r\n />\r\n )}\r\n </div>\r\n )}\r\n <div className=\"min-w-0 flex-1\">{renderMobileRow(row)}</div>\r\n </div>\r\n );\r\n })}\r\n </div>\r\n\r\n <div\r\n className={cn(\r\n \"flex flex-col items-center justify-between gap-3 border-t border-gray-200 px-5 py-4 sm:flex-row\",\r\n paginationClassName,\r\n )}\r\n >\r\n <p className=\"text-muted-foreground text-sm\">\r\n Showing {table.pageStart + 1} to {table.pageEnd} of{\" \"}\r\n {table.totalCount}{\" \"}\r\n {table.totalCount === 1 ? rowLabelSingular : rowLabelPlural}\r\n </p>\r\n <div className=\"flex flex-wrap items-center justify-center gap-3\">\r\n <label className=\"text-muted-foreground flex items-center gap-2 text-sm whitespace-nowrap\">\r\n Rows per page\r\n <Select\r\n value={String(table.pagination.pageSize)}\r\n onValueChange={(value) =>\r\n table.pagination.setPageSize(Number(value))\r\n }\r\n >\r\n <SelectTrigger className=\"w-20\" aria-label=\"Rows per page\">\r\n <SelectValue />\r\n </SelectTrigger>\r\n <SelectContent align=\"end\">\r\n {table.pagination.pageSizeOptions.map((pageSize) => (\r\n <SelectItem key={pageSize} value={String(pageSize)}>\r\n {pageSize}\r\n </SelectItem>\r\n ))}\r\n </SelectContent>\r\n </Select>\r\n </label>\r\n\r\n {table.pageCount > 1 && (\r\n <div\r\n className=\"flex items-center gap-1\"\r\n aria-label=\"Pagination\"\r\n >\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n disabled={table.page === 1}\r\n onClick={() => table.pagination.setPage(table.page - 1)}\r\n aria-label=\"Previous page\"\r\n >\r\n <ChevronLeft />\r\n </Button>\r\n {Array.from(\r\n { length: table.pageCount },\r\n (_, index) => index + 1,\r\n )\r\n .filter(\r\n (page) =>\r\n page === 1 ||\r\n page === table.pageCount ||\r\n Math.abs(page - table.page) <= 1,\r\n )\r\n .map((page, index, pages) => (\r\n <span key={page} className=\"flex items-center gap-1\">\r\n {index > 0 && page - pages[index - 1] > 1 && (\r\n <span className=\"text-muted-foreground px-1\">\r\n ...\r\n </span>\r\n )}\r\n <Button\r\n variant={page === table.page ? \"outline\" : \"ghost\"}\r\n scheme={page === table.page ? \"primary\" : undefined}\r\n size=\"sm\"\r\n className=\"h-9 w-9\"\r\n onClick={() => table.pagination.setPage(page)}\r\n aria-label={`Page ${page}`}\r\n aria-current={\r\n page === table.page ? \"page\" : undefined\r\n }\r\n >\r\n {page}\r\n </Button>\r\n </span>\r\n ))}\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n disabled={table.page === table.pageCount}\r\n onClick={() => table.pagination.setPage(table.page + 1)}\r\n aria-label=\"Next page\"\r\n >\r\n <ChevronRight />\r\n </Button>\r\n </div>\r\n )}\r\n </div>\r\n </div>\r\n </div>\r\n ) : (\r\n <div className=\"rounded-[0.33em] border border-dashed border-gray-300 bg-white px-6 py-12 text-center\">\r\n <p className=\"text-sm font-medium text-gray-700\">\r\n {resolvedEmptyState.title}\r\n </p>\r\n {resolvedEmptyState.description && (\r\n <p className=\"text-muted-foreground mt-1 text-sm\">\r\n {resolvedEmptyState.description}\r\n </p>\r\n )}\r\n {resolvedEmptyState.action && (\r\n <div className=\"mt-4\">{resolvedEmptyState.action}</div>\r\n )}\r\n </div>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport const Table = ResourceTable;\r\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AAiDA;AACA;AACA;AACA;AAGA;;;;;;AAMG;AACH;AAOE;AAwBF;AAIA;;;;AA2CU;AAwCF;AAWR;AAEM;;;AAkDJ;AACA;;AAEE;;AAGF;;;;;;AAMI;AACA;AACE;AACA;;AAEN;;AAGE;AACA;AACF;;AAGE;AACA;AAEF;;AAIE;;;AAKA;AAqCF;;AAuJ8B;;AAWJ;;;;AAyEV;;;;;;;;AAkKlB;AAEO;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
declare function Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...
|
|
2
|
+
declare function Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...ownProps }: React.ComponentProps<'textarea'>): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export { Textarea };
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { cn } from '../utils.js';
|
|
4
4
|
import { useFieldFocus, chain, fieldFocusOutlineClassName, fieldInteractionClassName } from '../hooks/use-field-focus.js';
|
|
5
|
+
import { useFormFieldControl } from './form-field.js';
|
|
5
6
|
|
|
6
|
-
function Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...
|
|
7
|
+
function Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...ownProps }) {
|
|
8
|
+
const props = useFormFieldControl(ownProps);
|
|
7
9
|
const { keyboardFocus, focusProps } = useFieldFocus();
|
|
8
10
|
return (jsx("textarea", { "data-slot": "textarea", className: cn('placeholder:text-muted-foreground/40 aria-invalid:border-destructive flex field-sizing-content min-h-24 w-full rounded-control-lg border border-input hover:border-input-hover bg-background px-3 py-2 text-base text-foreground ring-0 outline-none disabled:cursor-not-allowed disabled:opacity-50', !disabled && fieldInteractionClassName, keyboardFocus && fieldFocusOutlineClassName, className), disabled: disabled, onPointerDown: chain(onPointerDown, focusProps.onPointerDown), onFocus: chain(onFocus, focusProps.onFocus), onBlur: chain(onBlur, focusProps.onBlur), ...props }));
|
|
9
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.js","sources":["../../src/components/textarea.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\n\r\nimport { cn } from '@/utils';\r\nimport {\r\n chain,\r\n fieldFocusOutlineClassName,\r\n fieldInteractionClassName,\r\n useFieldFocus,\r\n} from '@/hooks/use-field-focus';\r\n\r\nfunction Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...
|
|
1
|
+
{"version":3,"file":"textarea.js","sources":["../../src/components/textarea.tsx"],"sourcesContent":["'use client';\r\n\r\nimport * as React from 'react';\r\n\r\nimport { cn } from '@/utils';\r\nimport {\r\n chain,\r\n fieldFocusOutlineClassName,\r\n fieldInteractionClassName,\r\n useFieldFocus,\r\n} from '@/hooks/use-field-focus';\r\nimport { useFormFieldControl } from './form-field';\r\n\r\nfunction Textarea({ className, disabled, onPointerDown, onFocus, onBlur, ...ownProps }: React.ComponentProps<'textarea'>) {\r\n const props = useFormFieldControl(ownProps);\r\n const { keyboardFocus, focusProps } = useFieldFocus();\r\n\r\n return (\r\n <textarea\r\n data-slot=\"textarea\"\r\n className={cn(\r\n 'placeholder:text-muted-foreground/40 aria-invalid:border-destructive flex field-sizing-content min-h-24 w-full rounded-control-lg border border-input hover:border-input-hover bg-background px-3 py-2 text-base text-foreground ring-0 outline-none disabled:cursor-not-allowed disabled:opacity-50',\r\n !disabled && fieldInteractionClassName,\r\n keyboardFocus && fieldFocusOutlineClassName,\r\n className,\r\n )}\r\n disabled={disabled}\r\n onPointerDown={chain(onPointerDown, focusProps.onPointerDown)}\r\n onFocus={chain(onFocus, focusProps.onFocus)}\r\n onBlur={chain(onBlur, focusProps.onBlur)}\r\n {...props}\r\n />\r\n );\r\n}\r\n\r\nexport { Textarea };\r\n"],"names":[],"mappings":";;;;;;AAaA;AACE;;AAGA;AAgBF;;"}
|