@betterinternship/components 3.2.2 → 3.2.4
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.
|
@@ -3,6 +3,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ChevronDown } from 'lucide-react';
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
|
+
import { interactiveSurfaceClassName } from '../lib/interaction-styles.js';
|
|
6
7
|
|
|
7
8
|
const CollapsibleContext = React.createContext(null);
|
|
8
9
|
function useCollapsible() {
|
|
@@ -20,7 +21,11 @@ function Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange,
|
|
|
20
21
|
setUncontrolledOpen(next);
|
|
21
22
|
onOpenChange?.(next);
|
|
22
23
|
};
|
|
23
|
-
return jsx(CollapsibleContext.Provider, { value: { open, toggle }, children: jsx("div", { className: cn("w-full overflow-hidden rounded-control-lg border border-input bg-background",
|
|
24
|
+
return jsx(CollapsibleContext.Provider, { value: { open, toggle }, children: jsx("div", { className: cn("w-full overflow-hidden rounded-control-lg border border-input bg-background",
|
|
25
|
+
// The ready-made panel, closed, answers like an interactive Card (lift,
|
|
26
|
+
// shadow, darker border). Open, it holds content being worked in, so it
|
|
27
|
+
// stays put and only the title row highlights.
|
|
28
|
+
title !== undefined && !open && cn(interactiveSurfaceClassName, "pointer-fine:hover:border-border-hover focus-within:border-border-hover"), className), "data-state": open ? "open" : "closed", ...props, children: title !== undefined ? jsxs(Fragment, { children: [jsxs(CollapsibleTrigger, { className: "flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue", children: [jsx("span", { children: title }), jsx(ChevronDown, { "aria-hidden": "true", className: cn("h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none", open && "rotate-180") })] }), jsx(CollapsibleContent, { divider: divider, children: jsx("div", { className: "px-4 pb-4 pt-4", children: children }) })] }) : children }) });
|
|
24
29
|
}
|
|
25
30
|
function CollapsibleTrigger({ asChild, className, children, onClick, ...props }) {
|
|
26
31
|
const { open, toggle } = useCollapsible();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collapsible.js","sources":["../../src/components/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/utils\";\n\ntype ContextValue = { open: boolean; toggle: () => void };\nconst CollapsibleContext = React.createContext<ContextValue | null>(null);\n\nfunction useCollapsible() {\n const context = React.useContext(CollapsibleContext);\n if (!context) throw new Error(\"Collapsible parts must be used inside Collapsible\");\n return context;\n}\n\nfunction Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange, className, children, title, divider = false, ...props }: {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n children: React.ReactNode;\n /** Optional heading for the ready-to-use collapsible panel. */\n title?: string;\n divider?: boolean;\n} & React.HTMLAttributes<HTMLDivElement>) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? uncontrolledOpen;\n const toggle = () => {\n const next = !open;\n if (controlledOpen === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n return <CollapsibleContext.Provider value={{ open, toggle }}>\n <div className={cn(\"w-full overflow-hidden rounded-control-lg border border-input bg-background\", className)} data-state={open ? \"open\" : \"closed\"} {...props}>\n {title !== undefined ? <>\n <CollapsibleTrigger className=\"flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue\">\n <span>{title}</span>\n <ChevronDown aria-hidden=\"true\" className={cn(\"h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none\", open && \"rotate-180\")} />\n </CollapsibleTrigger>\n <CollapsibleContent divider={divider}>\n <div className=\"px-4 pb-4 pt-4\">{children}</div>\n </CollapsibleContent>\n </> : children}\n </div>\n </CollapsibleContext.Provider>;\n}\n\nfunction CollapsibleTrigger({ asChild, className, children, onClick, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement> & { asChild?: boolean }) {\n const { open, toggle } = useCollapsible();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { onClick?.(event); if (!event.defaultPrevented) toggle(); };\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(children as React.ReactElement<any>, {\n ...props,\n 'aria-expanded': open,\n 'data-state': open ? 'open' : 'closed',\n onClick: handleClick,\n });\n }\n return <button type=\"button\" {...props} aria-expanded={open} data-state={open ? \"open\" : \"closed\"} className={className} onClick={handleClick}>{children}</button>;\n}\n\nfunction CollapsibleContent({ className, children, divider = false, style, ...props }: React.HTMLAttributes<HTMLDivElement> & { divider?: boolean }) {\n const { open } = useCollapsible();\n return <div className={cn(\"grid transition-[grid-template-rows] duration-state ease-landing-out motion-reduce:transition-none\", divider && open && \"border-t border-border\", className)} style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", ...style }} aria-hidden={!open} inert={!open} {...props}>\n <div className=\"min-h-0 overflow-hidden\">\n <div className={cn(\n \"origin-top transition-[opacity,transform,filter] duration-state ease-landing-out motion-reduce:transform-none motion-reduce:filter-none motion-reduce:transition-none\",\n open ? \"scale-100 opacity-100 blur-none\" : \"scale-[0.98] opacity-0 blur-sm\",\n )}>{children}</div>\n </div>\n </div>;\n}\n\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent };\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collapsible.js","sources":["../../src/components/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/utils\";\nimport { interactiveSurfaceClassName } from \"@/lib/interaction-styles\";\n\ntype ContextValue = { open: boolean; toggle: () => void };\nconst CollapsibleContext = React.createContext<ContextValue | null>(null);\n\nfunction useCollapsible() {\n const context = React.useContext(CollapsibleContext);\n if (!context) throw new Error(\"Collapsible parts must be used inside Collapsible\");\n return context;\n}\n\nfunction Collapsible({ open: controlledOpen, defaultOpen = false, onOpenChange, className, children, title, divider = false, ...props }: {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n children: React.ReactNode;\n /** Optional heading for the ready-to-use collapsible panel. */\n title?: string;\n divider?: boolean;\n} & React.HTMLAttributes<HTMLDivElement>) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);\n const open = controlledOpen ?? uncontrolledOpen;\n const toggle = () => {\n const next = !open;\n if (controlledOpen === undefined) setUncontrolledOpen(next);\n onOpenChange?.(next);\n };\n\n return <CollapsibleContext.Provider value={{ open, toggle }}>\n <div className={cn(\n \"w-full overflow-hidden rounded-control-lg border border-input bg-background\",\n // The ready-made panel, closed, answers like an interactive Card (lift,\n // shadow, darker border). Open, it holds content being worked in, so it\n // stays put and only the title row highlights.\n title !== undefined && !open && cn(interactiveSurfaceClassName, \"pointer-fine:hover:border-border-hover focus-within:border-border-hover\"),\n className,\n )} data-state={open ? \"open\" : \"closed\"} {...props}>\n {title !== undefined ? <>\n <CollapsibleTrigger className=\"flex w-full items-center justify-between gap-2 p-4 text-left text-sm font-semibold transition-colors duration-state hover:bg-muted motion-reduce:transition-none focus-visible:outline-3 focus-visible:-outline-offset-4 focus-visible:outline-landing-blue\">\n <span>{title}</span>\n <ChevronDown aria-hidden=\"true\" className={cn(\"h-5 w-5 shrink-0 transition-transform duration-state ease-landing-out motion-reduce:transition-none\", open && \"rotate-180\")} />\n </CollapsibleTrigger>\n <CollapsibleContent divider={divider}>\n <div className=\"px-4 pb-4 pt-4\">{children}</div>\n </CollapsibleContent>\n </> : children}\n </div>\n </CollapsibleContext.Provider>;\n}\n\nfunction CollapsibleTrigger({ asChild, className, children, onClick, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement> & { asChild?: boolean }) {\n const { open, toggle } = useCollapsible();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { onClick?.(event); if (!event.defaultPrevented) toggle(); };\n if (asChild && React.isValidElement(children)) {\n return React.cloneElement(children as React.ReactElement<any>, {\n ...props,\n 'aria-expanded': open,\n 'data-state': open ? 'open' : 'closed',\n onClick: handleClick,\n });\n }\n return <button type=\"button\" {...props} aria-expanded={open} data-state={open ? \"open\" : \"closed\"} className={className} onClick={handleClick}>{children}</button>;\n}\n\nfunction CollapsibleContent({ className, children, divider = false, style, ...props }: React.HTMLAttributes<HTMLDivElement> & { divider?: boolean }) {\n const { open } = useCollapsible();\n return <div className={cn(\"grid transition-[grid-template-rows] duration-state ease-landing-out motion-reduce:transition-none\", divider && open && \"border-t border-border\", className)} style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", ...style }} aria-hidden={!open} inert={!open} {...props}>\n <div className=\"min-h-0 overflow-hidden\">\n <div className={cn(\n \"origin-top transition-[opacity,transform,filter] duration-state ease-landing-out motion-reduce:transform-none motion-reduce:filter-none motion-reduce:transition-none\",\n open ? \"scale-100 opacity-100 blur-none\" : \"scale-[0.98] opacity-0 blur-sm\",\n )}>{children}</div>\n </div>\n </div>;\n}\n\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent };\n"],"names":[],"mappings":";;;;;;;AAQA;AAEA;;AAEE;AAAc;AACd;AACF;AAEA;AAUE;AACA;;AAEE;;;AAEA;AACF;AAEA;;;;AAMI;AAcN;AAEA;;AAEE;AAAqH;;AAEnH;AACE;AACA;;AAEA;AACD;;AAEH;AACF;AAEA;AACE;AACA;AAQF;;"}
|
|
@@ -72,7 +72,7 @@ function FilterMenu(props) {
|
|
|
72
72
|
return (jsxs(Fragment, { children: [trigger, jsx(Sheet, { open: open, onOpenChange: setOpen, children: jsxs(SheetContent, { side: "bottom", showCloseButton: false, overlayClassName: "z-[1090] bg-black/25 backdrop-blur-[1px]", "aria-describedby": undefined, onOpenAutoFocus: (event) => {
|
|
73
73
|
event.preventDefault();
|
|
74
74
|
closeRef.current?.focus();
|
|
75
|
-
}, className: "flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]", children: [jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { ref: closeRef, type: "button", "aria-label": "Close", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx("div", { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-2", children: list }), jsxs("div", { className: "flex shrink-0 gap-2 border-t border-border px-4 pt-3", children: [clearInSheet && (jsx(Button, { type: "button", variant: "
|
|
75
|
+
}, className: "flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]", children: [jsxs("div", { className: "flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: title }), jsx("button", { ref: closeRef, type: "button", "aria-label": "Close", className: "-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => setOpen(false), children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx("div", { className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-2", children: list }), jsxs("div", { className: "flex shrink-0 gap-2 border-t border-border px-4 pt-3", children: [clearInSheet && (jsx(Button, { type: "button", variant: "ghost", scheme: "neutral", className: "flex-1", onClick: clearInSheet, children: clearLabel })), jsx(Button, { type: "button", variant: "outline", className: "flex-1", onClick: () => setOpen(false), children: "Done" })] })] }) })] }));
|
|
76
76
|
return (jsxs(Popover, { open: open, onOpenChange: setOpen, children: [jsx(PopoverTrigger, { asChild: true, children: trigger }), jsxs(PopoverContent, { align: align, className: cn("w-56 p-0", contentClassName), children: [list, onClear && (jsx("div", { className: "border-t border-border p-option-inset", children: jsx(Button, { type: "button", variant: "link", scheme: "primary", size: "xs", onClick: onClear, children: clearLabel }) }))] })] }));
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-list.js","sources":["../../src/components/option-list.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown, X } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { Button } from \"./button\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\n\n/*\n * The shared look for every list of options (menus, selects, dropdowns,\n * autocomplete, filter menus): the list is inset from its container's edge,\n * and each row is its own rounded box with a little space between rows, so\n * hover and selection read as distinct pills rather than full-bleed stripes.\n */\n\n/** Padding + row gap for a list of options inside a popover or sheet. */\nexport const optionListClassName = \"flex flex-col gap-option-gap p-option-inset\";\n\n/** One option row. Pair with a hover/focus or selected state as needed. */\nexport const optionRowClassName =\n \"relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11\";\n\nexport type CheckboxListItem = {\n label: React.ReactNode;\n checked: boolean;\n onCheckedChange: (checked: boolean) => void;\n /** Indents the row under a group heading row. */\n indent?: boolean;\n /** Bolder label, e.g. a group's \"All …\" row. */\n strong?: boolean;\n disabled?: boolean;\n};\n\n/** A list of checkbox rows in the shared option style. */\nexport function CheckboxList({\n items,\n className,\n \"aria-label\": label,\n}: {\n items: CheckboxListItem[];\n className?: string;\n \"aria-label\"?: string;\n}) {\n return (\n <ul\n aria-label={label}\n className={cn(\"m-0 list-none\", optionListClassName, className)}\n >\n {items.map((item, index) => (\n <li key={index}>\n <label\n className={cn(\n optionRowClassName,\n item.indent && \"pl-8\",\n item.strong && \"font-medium\",\n item.disabled && \"pointer-events-none opacity-50\",\n )}\n >\n <Checkbox\n checked={item.checked}\n disabled={item.disabled}\n onCheckedChange={(checked) =>\n item.onCheckedChange(checked === true)\n }\n />\n <span className=\"min-w-0 flex-1\">{item.label}</span>\n </label>\n </li>\n ))}\n </ul>\n );\n}\n\nexport type FilterMenuOption = { label: React.ReactNode; value: string };\n\ntype FilterMenuCommon = {\n /** The chip's label (and the sheet title when it's text). */\n label?: React.ReactNode;\n /** Replaces the default chip, e.g. a labelled field button. */\n trigger?: React.ReactElement<React.HTMLAttributes<HTMLElement>>;\n /** Sheet title / list name when `label` isn't plain text. */\n title?: string;\n /** Shows a clear action (popover footer and sheet footer). */\n onClear?: () => void;\n clearLabel?: string;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n};\n\n/** Simple filters: options in, selected values out. */\ntype FilterMenuOptionsProps = FilterMenuCommon & {\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n items?: never;\n};\n\n/** Lists with their own rules (groups, indents): the rows themselves. */\ntype FilterMenuItemsProps = FilterMenuCommon & {\n items: CheckboxListItem[];\n options?: never;\n value?: never;\n onValueChange?: never;\n};\n\nexport type FilterMenuProps = FilterMenuOptionsProps | FilterMenuItemsProps;\n\n/**\n * A checklist behind a trigger: a dropdown on desktop and a bottom sheet\n * (with Clear and Done) on phones. Each tick applies immediately.\n *\n * Feed it either `options` + `value` + `onValueChange` (simple filters; the\n * default trigger is a FilterChip showing the count in the selected,\n * secondary style), or ready-made `items` with your own `trigger`.\n */\nexport function FilterMenu(props: FilterMenuProps) {\n const {\n label,\n trigger: customTrigger,\n title: titleProp,\n onClear,\n clearLabel = \"Clear\",\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n } = props;\n const isMobile = useMobile();\n const [open, setOpen] = React.useState(false);\n const closeRef = React.useRef<HTMLButtonElement>(null);\n\n // Both ways in become the same rows.\n const items: CheckboxListItem[] =\n props.items ??\n props.options.map((option) => ({\n label: option.label,\n checked: props.value.includes(option.value),\n onCheckedChange: (on) =>\n props.onValueChange(\n on\n ? [...props.value, option.value]\n : props.value.filter((item) => item !== option.value),\n ),\n }));\n const count = props.items\n ? props.items.filter((item) => item.checked).length\n : props.value.length;\n const title = titleProp ?? (typeof label === \"string\" ? label : \"Filter\");\n // The sheet always offers Clear while something's on; the popover only\n // when the caller asks for it.\n const clearInSheet =\n onClear ??\n (!props.items && count > 0 ? () => props.onValueChange([]) : undefined);\n\n const triggerProps = {\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": open,\n onClick: isMobile ? () => setOpen(true) : undefined,\n };\n const trigger = customTrigger ? (\n React.cloneElement(customTrigger, {\n ...triggerProps,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n customTrigger.props.onClick?.(event);\n triggerProps.onClick?.();\n },\n })\n ) : (\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n {...triggerProps}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n );\n\n const list = <CheckboxList aria-label={title} items={items} />;\n\n // Phones: a bottom sheet, like Autocomplete and Select.\n if (isMobile)\n return (\n <>\n {trigger}\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent\n side=\"bottom\"\n showCloseButton={false}\n overlayClassName=\"z-[1090] bg-black/25 backdrop-blur-[1px]\"\n aria-describedby={undefined}\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n closeRef.current?.focus();\n }}\n className=\"flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n >\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">\n {title}\n </SheetTitle>\n <button\n ref={closeRef}\n type=\"button\"\n aria-label=\"Close\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-2\">\n {list}\n </div>\n <div className=\"flex shrink-0 gap-2 border-t border-border px-4 pt-3\">\n {clearInSheet && (\n <Button\n type=\"button\"\n variant=\"
|
|
1
|
+
{"version":3,"file":"option-list.js","sources":["../../src/components/option-list.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronDown, X } from \"lucide-react\";\n\nimport { cn } from \"@/utils\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { Button } from \"./button\";\nimport { Checkbox } from \"./checkbox\";\nimport { FilterChip } from \"./filter-chip\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\n\n/*\n * The shared look for every list of options (menus, selects, dropdowns,\n * autocomplete, filter menus): the list is inset from its container's edge,\n * and each row is its own rounded box with a little space between rows, so\n * hover and selection read as distinct pills rather than full-bleed stripes.\n */\n\n/** Padding + row gap for a list of options inside a popover or sheet. */\nexport const optionListClassName = \"flex flex-col gap-option-gap p-option-inset\";\n\n/** One option row. Pair with a hover/focus or selected state as needed. */\nexport const optionRowClassName =\n \"relative flex min-h-option-row w-full cursor-pointer select-none items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-foreground outline-none transition-colors duration-state hover:bg-muted focus-visible:bg-muted motion-reduce:transition-none max-md:min-h-11\";\n\nexport type CheckboxListItem = {\n label: React.ReactNode;\n checked: boolean;\n onCheckedChange: (checked: boolean) => void;\n /** Indents the row under a group heading row. */\n indent?: boolean;\n /** Bolder label, e.g. a group's \"All …\" row. */\n strong?: boolean;\n disabled?: boolean;\n};\n\n/** A list of checkbox rows in the shared option style. */\nexport function CheckboxList({\n items,\n className,\n \"aria-label\": label,\n}: {\n items: CheckboxListItem[];\n className?: string;\n \"aria-label\"?: string;\n}) {\n return (\n <ul\n aria-label={label}\n className={cn(\"m-0 list-none\", optionListClassName, className)}\n >\n {items.map((item, index) => (\n <li key={index}>\n <label\n className={cn(\n optionRowClassName,\n item.indent && \"pl-8\",\n item.strong && \"font-medium\",\n item.disabled && \"pointer-events-none opacity-50\",\n )}\n >\n <Checkbox\n checked={item.checked}\n disabled={item.disabled}\n onCheckedChange={(checked) =>\n item.onCheckedChange(checked === true)\n }\n />\n <span className=\"min-w-0 flex-1\">{item.label}</span>\n </label>\n </li>\n ))}\n </ul>\n );\n}\n\nexport type FilterMenuOption = { label: React.ReactNode; value: string };\n\ntype FilterMenuCommon = {\n /** The chip's label (and the sheet title when it's text). */\n label?: React.ReactNode;\n /** Replaces the default chip, e.g. a labelled field button. */\n trigger?: React.ReactElement<React.HTMLAttributes<HTMLElement>>;\n /** Sheet title / list name when `label` isn't plain text. */\n title?: string;\n /** Shows a clear action (popover footer and sheet footer). */\n onClear?: () => void;\n clearLabel?: string;\n size?: \"xs\" | \"sm\" | \"md\";\n align?: \"start\" | \"center\" | \"end\";\n className?: string;\n contentClassName?: string;\n};\n\n/** Simple filters: options in, selected values out. */\ntype FilterMenuOptionsProps = FilterMenuCommon & {\n options: FilterMenuOption[];\n /** The selected option values. */\n value: string[];\n onValueChange: (value: string[]) => void;\n items?: never;\n};\n\n/** Lists with their own rules (groups, indents): the rows themselves. */\ntype FilterMenuItemsProps = FilterMenuCommon & {\n items: CheckboxListItem[];\n options?: never;\n value?: never;\n onValueChange?: never;\n};\n\nexport type FilterMenuProps = FilterMenuOptionsProps | FilterMenuItemsProps;\n\n/**\n * A checklist behind a trigger: a dropdown on desktop and a bottom sheet\n * (with Clear and Done) on phones. Each tick applies immediately.\n *\n * Feed it either `options` + `value` + `onValueChange` (simple filters; the\n * default trigger is a FilterChip showing the count in the selected,\n * secondary style), or ready-made `items` with your own `trigger`.\n */\nexport function FilterMenu(props: FilterMenuProps) {\n const {\n label,\n trigger: customTrigger,\n title: titleProp,\n onClear,\n clearLabel = \"Clear\",\n size = \"sm\",\n align = \"start\",\n className,\n contentClassName,\n } = props;\n const isMobile = useMobile();\n const [open, setOpen] = React.useState(false);\n const closeRef = React.useRef<HTMLButtonElement>(null);\n\n // Both ways in become the same rows.\n const items: CheckboxListItem[] =\n props.items ??\n props.options.map((option) => ({\n label: option.label,\n checked: props.value.includes(option.value),\n onCheckedChange: (on) =>\n props.onValueChange(\n on\n ? [...props.value, option.value]\n : props.value.filter((item) => item !== option.value),\n ),\n }));\n const count = props.items\n ? props.items.filter((item) => item.checked).length\n : props.value.length;\n const title = titleProp ?? (typeof label === \"string\" ? label : \"Filter\");\n // The sheet always offers Clear while something's on; the popover only\n // when the caller asks for it.\n const clearInSheet =\n onClear ??\n (!props.items && count > 0 ? () => props.onValueChange([]) : undefined);\n\n const triggerProps = {\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": open,\n onClick: isMobile ? () => setOpen(true) : undefined,\n };\n const trigger = customTrigger ? (\n React.cloneElement(customTrigger, {\n ...triggerProps,\n onClick: (event: React.MouseEvent<HTMLElement>) => {\n customTrigger.props.onClick?.(event);\n triggerProps.onClick?.();\n },\n })\n ) : (\n <FilterChip\n size={size}\n selected={count > 0}\n count={count || undefined}\n className={className}\n {...triggerProps}\n >\n {label}\n <ChevronDown size={14} aria-hidden=\"true\" className=\"-mr-1\" />\n </FilterChip>\n );\n\n const list = <CheckboxList aria-label={title} items={items} />;\n\n // Phones: a bottom sheet, like Autocomplete and Select.\n if (isMobile)\n return (\n <>\n {trigger}\n <Sheet open={open} onOpenChange={setOpen}>\n <SheetContent\n side=\"bottom\"\n showCloseButton={false}\n overlayClassName=\"z-[1090] bg-black/25 backdrop-blur-[1px]\"\n aria-describedby={undefined}\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n closeRef.current?.focus();\n }}\n className=\"flex flex-col gap-0 p-0 pb-[max(0.75rem,env(safe-area-inset-bottom))]\"\n >\n <div className=\"flex shrink-0 items-center justify-between gap-4 px-4 pb-1 pt-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">\n {title}\n </SheetTitle>\n <button\n ref={closeRef}\n type=\"button\"\n aria-label=\"Close\"\n className=\"-mr-3 flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\"\n onClick={() => setOpen(false)}\n >\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain px-2\">\n {list}\n </div>\n <div className=\"flex shrink-0 gap-2 border-t border-border px-4 pt-3\">\n {clearInSheet && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n scheme=\"neutral\"\n className=\"flex-1\"\n onClick={clearInSheet}\n >\n {clearLabel}\n </Button>\n )}\n {/* Outline, like Autocomplete's: ticks already applied, so\n Done only closes the sheet. */}\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"flex-1\"\n onClick={() => setOpen(false)}\n >\n Done\n </Button>\n </div>\n </SheetContent>\n </Sheet>\n </>\n );\n\n return (\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>{trigger}</PopoverTrigger>\n <PopoverContent\n align={align}\n className={cn(\"w-56 p-0\", contentClassName)}\n >\n {list}\n {onClear && (\n <div className=\"border-t border-border p-option-inset\">\n <Button\n type=\"button\"\n variant=\"link\"\n scheme=\"primary\"\n size=\"xs\"\n onClick={onClear}\n >\n {clearLabel}\n </Button>\n </div>\n )}\n </PopoverContent>\n </Popover>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAaA;;;;;AAKG;AAEH;AACO;AAEP;AACO;AAcP;AACM;;AAqCN;AAuCA;;;;;;;AAOG;AACG;AACJ;AAWA;AACA;;;AAIA;;;;;;AASU;AAEP;AACH;AACE;AACA;AACF;;;;;AAOA;AACE;AACA;AACA;;AAEF;AAEI;AACA;;AAEE;;;;;AAmBN;AACE;;AAWU;AACF;AAgDV;AAwBF;;"}
|