@betterinternship/components 3.3.4 → 3.3.6

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.
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useState, useRef, useId, useMemo, useEffect, Fragment } from 'react';
3
+ import { useState, useRef, useId, useMemo, useLayoutEffect, useEffect, Fragment } from 'react';
4
4
  import { Input } from './input.js';
5
5
  import { useDetectClickOutside } from '../hooks/use-detect-click-outside.js';
6
6
  import { cn } from '../utils.js';
@@ -104,6 +104,35 @@ function AutocompleteBase({ required, options, value = [], setter, placeholder,
104
104
  const singleDisplay = !multiple && (selectedLabels[0] ?? "");
105
105
  const useMobileSheet = isMobile && mobileDropdownMode === "sheet";
106
106
  const sheetViewport = useMobileSheetViewport(isOpen && useMobileSheet);
107
+ // Desktop list: sized to the screen so it never runs off it. It opens
108
+ // below the field, as tall as fits above the screen's bottom edge (16px
109
+ // margin, at most 400px). With little room below (under 200px) and more
110
+ // above, it opens upwards instead, sized to the space above. Re-measured
111
+ // on scroll and resize while open.
112
+ const [listFit, setListFit] = useState(null);
113
+ useLayoutEffect(() => {
114
+ if (!isOpen || useMobileSheet)
115
+ return;
116
+ const measure = () => {
117
+ const field = inputRef.current?.getBoundingClientRect();
118
+ if (!field)
119
+ return;
120
+ const below = window.innerHeight - field.bottom - 16;
121
+ const above = field.top - 16;
122
+ const openAbove = below < 200 && above > below;
123
+ setListFit({
124
+ above: openAbove,
125
+ maxHeight: Math.max(120, Math.min(400, openAbove ? above : below)),
126
+ });
127
+ };
128
+ measure();
129
+ window.addEventListener("resize", measure);
130
+ window.addEventListener("scroll", measure, true);
131
+ return () => {
132
+ window.removeEventListener("resize", measure);
133
+ window.removeEventListener("scroll", measure, true);
134
+ };
135
+ }, [isOpen, useMobileSheet]);
107
136
  const useInlineMobileDropdown = isMobile && mobileDropdownMode === "inline";
108
137
  useEffect(() => {
109
138
  if (!isOpen || !useInlineMobileDropdown) {
@@ -264,7 +293,17 @@ function AutocompleteBase({ required, options, value = [], setter, placeholder,
264
293
  bottom: sheetViewport?.bottom ?? 0,
265
294
  maxHeight: sheetViewport ? Math.min(sheetViewport.height, 640) : "80dvh",
266
295
  }
267
- : undefined, children: [useMobileSheet && (jsxs("div", { className: "shrink-0 px-4 pb-3 pt-4", children: [jsxs("div", { className: "mb-3 flex items-center justify-between gap-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: label || "Choose options" }), jsx("button", { ref: sheetCloseRef, type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => { setQuery(""); setIsOpen(false); }, children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx(Input, { ref: sheetInputRef, "aria-label": typeof label === "string" ? `Search ${label}` : "Search options", value: query, placeholder: placeholder ?? "Search", className: "h-10 min-h-10 max-h-none text-base", onChange: (e) => {
296
+ : listFit
297
+ ? {
298
+ maxHeight: listFit.maxHeight,
299
+ ...(listFit.above && {
300
+ top: "auto",
301
+ bottom: "100%",
302
+ marginTop: 0,
303
+ marginBottom: 4,
304
+ }),
305
+ }
306
+ : undefined, children: [useMobileSheet && (jsxs("div", { className: "shrink-0 px-4 pb-3 pt-4", children: [jsxs("div", { className: "mb-3 flex items-center justify-between gap-4", children: [jsx(SheetTitle, { className: "text-base font-semibold text-foreground", children: label || "Choose options" }), jsx("button", { ref: sheetCloseRef, type: "button", "aria-label": "Close options", className: "-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted", onClick: () => { setQuery(""); setIsOpen(false); }, children: jsx(X, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), jsx(Input, { ref: sheetInputRef, "aria-label": typeof label === "string" ? `Search ${label}` : "Search options", value: query, placeholder: placeholder ?? "Search", className: "h-10 min-h-10 max-h-none text-base", onChange: (e) => {
268
307
  setQuery(e.target.value);
269
308
  setIsOpen(true);
270
309
  if ((value?.length ?? 0) > 0 && !multiple) {
@@ -1 +1 @@
1
- {"version":3,"file":"autocomplete.js","sources":["../../src/components/autocomplete.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { Input } from \"./input\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\nimport { cn } from \"@/utils\";\nimport { ChevronDown, PlusCircleIcon, Search, X } from \"lucide-react\";\nimport { Label } from \"./label\";\nimport { Button } from \"./button\";\nimport { CheckboxVisual } from \"./checkbox\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport {\n FieldChromeContext,\n fieldFocusOutlineClassName,\n fieldInteractionClassName,\n useFieldFocus,\n} from \"@/hooks/use-field-focus\";\n\nexport interface IAutocompleteOption<ID extends number | string> {\n id: ID;\n name: string;\n keywords?: string[];\n /** Child options; in multiple mode the group can select all its children. */\n children?: IAutocompleteOption<ID>[];\n}\n\ntype MobileDropdownMode = \"sheet\" | \"inline\";\ntype InputIcons = boolean | \"search\" | \"dropdown\";\n\n/* -------------------------------------------------------\n * Base component (array-based). Single uses length 0..1.\n * -----------------------------------------------------*/\nfunction AutocompleteBase<ID extends number | string>({\n required,\n options,\n value = [],\n setter,\n placeholder,\n className,\n multiple = true,\n label,\n labelAddon,\n allowCustomValue = false,\n preserveOptionOrder = false,\n emptyText = \"No matching options\",\n mobileDropdownMode = \"sheet\",\n inputIcons = false,\n ...props\n}: {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n value?: ID[]; // single => 0..1 items, multi => any length\n setter: (next: ID[]) => void; // set the whole selection\n placeholder?: string;\n className?: string;\n multiple?: boolean;\n label?: React.ReactNode;\n labelAddon?: React.ReactNode;\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n}) {\n const [query, setQuery] = useState(\"\");\n const [isOpen, setIsOpen] = useState(false);\n const [dropdownMaxHeight, setDropdownMaxHeight] = useState<number>();\n const isMobile = useMobile();\n const clickOutsideRef = useDetectClickOutside({\n onTriggered: () => {\n // Radix owns outside dismissal for the portalled modal sheet.\n if (isMobile && mobileDropdownMode === 'sheet') return;\n setIsOpen(false);\n },\n });\n const rootRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const sheetInputRef = useRef<HTMLInputElement | null>(null);\n const sheetRef = useRef<HTMLDivElement | null>(null);\n const sheetCloseRef = useRef<HTMLButtonElement | null>(null);\n const lastSelectionRef = useRef(0);\n // Show the Button focus outline only for keyboard focus, not clicks.\n const { keyboardFocus, focusProps: fieldFocusProps } = useFieldFocus();\n\n const inputId = useId();\n const flatOptions = useMemo(\n () => options.flatMap((option) => option.children?.length ? option.children : [option]),\n [options],\n );\n\n const findExactOption = (value: string) => {\n const normalizedValue = value.trim().toLowerCase();\n return flatOptions.find(\n (o) =>\n o.name?.trim().toLowerCase() === normalizedValue ||\n o.keywords?.some((k) => k === normalizedValue),\n );\n };\n\n const resolveQuerySelection = (nextQuery: string, matchKeywords = true) => {\n const text = nextQuery.trim();\n if (!text) return false;\n\n const exact = matchKeywords\n ? findExactOption(text)\n : flatOptions.find(\n (o) => o.name?.trim().toLowerCase() === text.toLowerCase(),\n );\n if (exact) {\n setter([exact.id]);\n setQuery(\"\");\n return true;\n }\n\n if (allowCustomValue) {\n setter([text as unknown as ID]);\n setQuery(\"\");\n return true;\n }\n\n return false;\n };\n\n const selectedSet = useMemo(() => new Set(value ?? []), [value]);\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n const base = q\n ? flatOptions.filter(\n (o) =>\n o.name?.toLowerCase().includes(q) ||\n options.some((group) => group.children?.some((child) => child.id === o.id) && group.name.toLowerCase().includes(q)) ||\n o.keywords?.some((k) => k.includes(q)),\n )\n : flatOptions;\n return preserveOptionOrder || options.some((option) => option.children?.length)\n ? base\n : base.slice().sort((a, b) => a.name.localeCompare(b.name));\n }, [query, flatOptions, options, preserveOptionOrder]);\n\n const toggle = (id: ID) => {\n lastSelectionRef.current = Date.now();\n if (!multiple) {\n setter([id]); // single-select\n setIsOpen(false);\n setQuery(\"\");\n return;\n }\n const set = new Set(value ?? []);\n if (set.has(id)) set.delete(id);\n else set.add(id);\n setter(Array.from(set));\n };\n\n const removeAt = (id: ID) => {\n const set = new Set(value ?? []);\n set.delete(id);\n setter(Array.from(set));\n };\n\n const selectedLabels = useMemo(\n () =>\n (value ?? [])\n .map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name;\n return label ?? (allowCustomValue ? String(id) : undefined);\n })\n .filter(Boolean) as string[],\n [value, flatOptions, allowCustomValue],\n );\n\n const singleDisplay = !multiple && (selectedLabels[0] ?? \"\");\n const useMobileSheet = isMobile && mobileDropdownMode === \"sheet\";\n const sheetViewport = useMobileSheetViewport(isOpen && useMobileSheet);\n const useInlineMobileDropdown = isMobile && mobileDropdownMode === \"inline\";\n\n\n useEffect(() => {\n if (!isOpen || !useInlineMobileDropdown) {\n setDropdownMaxHeight(undefined);\n return;\n }\n\n const updateDropdownMaxHeight = () => {\n const rootRect = rootRef.current?.getBoundingClientRect();\n if (!rootRect) return;\n\n const viewportHeight =\n window.visualViewport?.height ?? window.innerHeight;\n const gap = 8;\n const availableHeight = viewportHeight - rootRect.bottom - gap;\n setDropdownMaxHeight(Math.max(0, Math.min(400, availableHeight)));\n };\n\n updateDropdownMaxHeight();\n window.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"scroll\", updateDropdownMaxHeight);\n\n return () => {\n window.removeEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.removeEventListener(\n \"resize\",\n updateDropdownMaxHeight,\n );\n window.visualViewport?.removeEventListener(\n \"scroll\",\n updateDropdownMaxHeight,\n );\n };\n }, [isOpen, useInlineMobileDropdown]);\n\n const suppressMobileKeyboard =\n isMobile && (useMobileSheet || (mobileDropdownMode === \"inline\" && !allowCustomValue));\n\n // --- keyboard helpers for multi\n const onMultiKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!multiple) return;\n if (allowCustomValue && e.key === \"Enter\" && query.trim().length > 0 && !findExactOption(query)) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n const set = new Set(value ?? []);\n set.add(nextId);\n setter(Array.from(set));\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n return;\n }\n if (\n e.key === \"Backspace\" &&\n query.length === 0 &&\n (value?.length ?? 0) > 0\n ) {\n const last = value[value.length - 1];\n removeAt(last);\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n const first = filtered[0];\n if (first) {\n toggle(first.id);\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n }\n }\n if (e.key === \"ArrowDown\") setIsOpen(true);\n if (e.key === \"Escape\") setIsOpen(false);\n };\n\n // Same hover lift and press feedback as the Dropdown trigger.\n const fieldClassName = cn(\n fieldInteractionClassName,\n keyboardFocus && fieldFocusOutlineClassName,\n );\n\n const decorateSingleInput = (input: React.ReactNode) =>\n inputIcons ? (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n {inputIcons !== \"search\" && inputIcons !== \"dropdown\" && (\n <Search\n className=\"pointer-events-none absolute left-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n )}\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n {inputIcons === \"search\" ? (\n <Search\n className=\"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n ) : (\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n )}\n </div>\n ) : (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n </div>\n );\n\n const OptionsSurface = useMobileSheet ? SheetContent : 'div';\n const sheetProps = useMobileSheet ? {\n side: 'bottom' as const,\n showCloseButton: false,\n overlayClassName: 'z-(--z-popover-overlay) bg-black/25 backdrop-blur-[1px]',\n 'aria-describedby': undefined,\n onOpenAutoFocus: (event: Event) => { event.preventDefault(); sheetCloseRef.current?.focus(); },\n onCloseAutoFocus: (event: Event) => { event.preventDefault(); inputRef.current?.focus(); },\n } : {};\n return (\n <div\n className={cn(\"relative w-full overflow-visible\", className)}\n ref={(node) => {\n rootRef.current = node;\n (\n clickOutsideRef as React.MutableRefObject<HTMLDivElement | null>\n ).current = node;\n }}\n >\n {label ? (\n <Label\n label={label}\n required={required}\n labelAddon={labelAddon}\n />\n ) : null}\n\n {multiple ? (\n // ---------- MULTI: chips inline inside the box ----------\n <div\n className={cn(\n \"relative flex min-h-form-control w-full flex-wrap items-center gap-1 rounded-control-lg border border-input bg-background px-[0.75em] pr-10 hover:border-input-hover\",\n fieldClassName,\n )}\n {...fieldFocusProps}\n onClick={() => {\n setIsOpen(true);\n if (!suppressMobileKeyboard) {\n inputRef.current?.focus();\n }\n }}\n >\n {(value ?? []).map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name ?? String(id);\n return (\n <span\n key={String(id)}\n className=\"my-0.5 flex items-center gap-1 rounded-control-sm border border-input bg-muted px-2 text-xs\"\n >\n {label}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n className=\"ml-1 h-5 min-h-0 w-5 p-0 hover:bg-muted\"\n onClick={(event) => { event.stopPropagation(); removeAt(id); }}\n aria-label={`Remove ${label}`}\n >\n <X className=\"h-3.5 w-3.5\" />\n </Button>\n </span>\n );\n })}\n <input\n id={inputId}\n ref={inputRef}\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // Delay slightly to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (allowCustomValue && query.trim().length > 0) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n setter(Array.from(new Set([...(value ?? []), nextId])));\n setQuery(\"\");\n }\n }, 150);\n }}\n onKeyDown={onMultiKeyDown}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n readOnly={suppressMobileKeyboard}\n placeholder={(value?.length ?? 0) === 0 ? placeholder : \"\"}\n className={cn(\n \"h-[calc(var(--spacing-form-control)-2px)] min-w-[8ch] flex-1 border-none bg-transparent p-0 text-base outline-none focus:ring-0\",\n \"placeholder:text-muted-foreground/40\",\n )}\n {...props}\n />\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n </div>\n ) : (\n // ---------- SINGLE: regular input ----------\n decorateSingleInput(\n <Input\n id={inputId}\n value={singleDisplay || query}\n className={cn(\n \"border-input\",\n inputIcons === \"search\" || inputIcons === \"dropdown\" ? \"pr-10\" : inputIcons && \"px-10\",\n )}\n placeholder={placeholder}\n readOnly={suppressMobileKeyboard}\n onChange={(e) => {\n const nextQuery = e.target.value;\n\n if ((value?.length ?? 0) > 0) {\n setter([]);\n }\n\n const exact = findExactOption(nextQuery);\n // Only auto-fill on an exact NAME match; keyword/acronym matches\n // (e.g. \"dlsu\") require an explicit Enter, blur, or click.\n if (\n exact &&\n exact.name.trim().toLowerCase() ===\n nextQuery.trim().toLowerCase()\n ) {\n setter([exact.id]);\n setQuery(\"\");\n } else {\n setQuery(nextQuery);\n }\n\n setIsOpen(true);\n }}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n onClick={(e) => {\n setIsOpen(true);\n if (suppressMobileKeyboard) {\n e.currentTarget.blur();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && resolveQuerySelection(query, true)) {\n setIsOpen(false);\n e.preventDefault();\n }\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // slight delay to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (!resolveQuerySelection(query, false)) setQuery(\"\");\n }, 150);\n }}\n />,\n )\n )}\n\n {isOpen && (\n <Sheet open={useMobileSheet && isOpen} onOpenChange={next => { if (!next) { setQuery(''); setIsOpen(false); } }}>\n <OptionsSurface\n {...sheetProps}\n ref={useMobileSheet ? sheetRef : undefined}\n role={useMobileSheet ? \"dialog\" : undefined}\n aria-modal={useMobileSheet ? true : undefined}\n aria-label={useMobileSheet ? (typeof label === \"string\" ? label : \"Choose options\") : undefined}\n className={cn(\n \"bg-background text-sm shadow-card border border-border\",\n useMobileSheet\n ? \"fixed left-0 right-0 z-(--z-popover) flex flex-col gap-0 overflow-hidden rounded-t-control-lg border-b-0 p-0\"\n : \"absolute left-0 right-0 z-50 mt-1 max-h-[400px] overflow-y-auto overscroll-contain rounded-control-lg\",\n )}\n style={\n useMobileSheet\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport ? Math.min(sheetViewport.height, 640) : \"80dvh\",\n }\n : undefined\n }\n >\n {useMobileSheet && (\n <div className=\"shrink-0 px-4 pb-3 pt-4\">\n <div className=\"mb-3 flex items-center justify-between gap-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">{label || \"Choose options\"}</SheetTitle>\n <button ref={sheetCloseRef} type=\"button\" aria-label=\"Close options\" className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\" onClick={() => { setQuery(\"\"); setIsOpen(false); }}>\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <Input\n ref={sheetInputRef}\n aria-label={typeof label === \"string\" ? `Search ${label}` : \"Search options\"}\n value={query}\n placeholder={placeholder ?? \"Search\"}\n className=\"h-10 min-h-10 max-h-none text-base\"\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n if ((value?.length ?? 0) > 0 && !multiple) {\n setter([]);\n }\n }}\n onKeyDown={(e) => {\n if (multiple) {\n onMultiKeyDown(e);\n return;\n }\n\n if (e.key === \"Enter\" && resolveQuerySelection(query)) {\n setIsOpen(false);\n e.preventDefault();\n }\n\n if (e.key === \"Escape\") {\n setIsOpen(false);\n }\n }}\n />\n </div>\n )}\n <ul className={cn(\"flex flex-col gap-option-gap p-option-inset\", useMobileSheet && \"min-h-0 flex-1 overflow-y-auto overscroll-contain\")}>\n {allowCustomValue && (\n <li className=\"pointer-events-none px-option-x pb-1 pt-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground\">\n Suggestions\n </li>\n )}\n {filtered.length ? (\n filtered.map((option, index) => {\n const active = selectedSet.has(option.id);\n const group = options.find((item) => item.children?.some((child) => child.id === option.id));\n const firstInGroup = group && !filtered.slice(0, index).some((item) => group.children?.some((child) => child.id === item.id));\n return (\n <Fragment key={String(option.id)}>\n {firstInGroup && group && (\n <li>\n {multiple ? (\n <button type=\"button\" aria-pressed={group.children!.every((child) => selectedSet.has(child.id))} className=\"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm font-medium text-foreground transition-colors hover:bg-muted max-md:min-h-11\" onClick={() => {\n const ids = group.children!.map((child) => child.id);\n const next = new Set(value ?? []);\n const allSelected = ids.every((id) => next.has(id));\n ids.forEach((id) => allSelected ? next.delete(id) : next.add(id));\n setter(Array.from(next));\n }}>\n <CheckboxVisual checked={group.children!.every((child) => selectedSet.has(child.id)) ? true : group.children!.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false} />\n {group.name}\n </button>\n ) : <div className=\"px-option-x py-2 text-sm font-medium text-foreground\">{group.name}</div>}\n </li>\n )}\n <li>\n <button\n type=\"button\"\n aria-pressed={multiple ? active : undefined}\n onClick={() => {\n toggle(option.id);\n if (multiple) {\n // keep open for rapid multi-pick\n setQuery(\"\");\n if (!useMobileSheet) {\n inputRef.current?.focus();\n }\n } else {\n setQuery(\"\");\n setIsOpen(false);\n }\n }}\n className={cn(\n \"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-muted\",\n useMobileSheet && \"min-h-12\",\n group && \"pl-8\",\n active && \"bg-primary-tint\",\n )}\n >\n {multiple ? (\n <CheckboxVisual checked={active} />\n ) : null}\n {option.name}\n </button>\n </li>\n </Fragment>\n );\n })\n ) : (\n !allowCustomValue || !query.trim() ? (\n <li className=\"px-option-x py-2 text-sm text-muted-foreground\">\n {emptyText}\n </li>\n ) : null\n )}\n {allowCustomValue && query.trim() && !findExactOption(query) && (\n <li>\n <button\n type=\"button\"\n className=\"flex min-h-11 w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-sm text-primary transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-primary\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n const text = query.trim();\n if (multiple) {\n setter(Array.from(new Set([...(value ?? []), text as unknown as ID])));\n setQuery(\"\");\n } else {\n resolveQuerySelection(text);\n setIsOpen(false);\n }\n }}\n >\n <PlusCircleIcon className=\"h-4 w-4\" aria-hidden=\"true\" />\n Add “{query.trim()}”\n </button>\n </li>\n )}\n </ul>\n {useMobileSheet && multiple && (\n <div className=\"shrink-0 border-t border-border bg-background px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]\">\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"min-h-11 w-full\"\n onClick={() => {\n setQuery(\"\");\n setIsOpen(false);\n }}\n >\n Done\n </Button>\n </div>\n )}\n </OptionsSurface>\n </Sheet>\n )}\n </div>\n );\n}\n\ntype AutocompleteCommonProps<ID extends number | string> = {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n placeholder?: string;\n className?: string;\n label?: React.ReactNode;\n props?: any[];\n /** Allow a user to add their own text. Custom values are strings. */\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n};\n\nexport type AutocompleteProps<ID extends number | string> = AutocompleteCommonProps<ID> & (\n | { multiple?: false; value?: ID | null; setter: (value?: ID | null) => void }\n | { multiple: true; value?: ID[]; setter: (value: ID[]) => void }\n);\n\nexport const Autocomplete = <ID extends number | string>(config: AutocompleteProps<ID>) => {\n const { required, options, placeholder, className, label, props, allowCustomValue = false,\n preserveOptionOrder = false, emptyText, mobileDropdownMode, inputIcons } = config;\n return (\n <AutocompleteBase<ID>\n required={required}\n options={options}\n multiple={config.multiple === true}\n value={config.multiple === true ? config.value ?? [] : config.value != null ? [config.value] : []}\n setter={(arr) => {\n if (config.multiple === true) config.setter(arr);\n else config.setter(arr[0] ?? null);\n }}\n placeholder={placeholder}\n className={className}\n label={label}\n allowCustomValue={allowCustomValue}\n preserveOptionOrder={preserveOptionOrder}\n emptyText={emptyText}\n mobileDropdownMode={mobileDropdownMode}\n inputIcons={inputIcons}\n {...props}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+BA;;AAE0D;AAC1D;;;;AAmCE;;;;AAII;;;;AAGH;AACD;AACA;AACA;AACA;AACA;AACA;;;AAIA;AACA;AAKA;;AAEE;AAGI;AAEN;;AAGE;AACA;AAAW;;AAGT;;;AAKA;;AAEA;;;AAIA;;AAEA;;AAGF;AACF;AAEA;AAEA;;;;AAMY;AACA;;AAGV;AACE;;;AAIJ;AACE;;AAEE;;;;;;AAMF;AAAiB;;AACZ;;AAEP;AAEA;;AAEE;;AAEF;;AAKO;AACC;AACA;AACF;AACC;AAIP;AACA;;AAEA;;AAIE;;;;;;AAOE;;;;;AAMA;AACF;AAEA;AACA;;;AAIA;AACE;;;AASF;AACF;AAEA;;AAIA;AACE;;;AAEE;AACA;AACA;;AAEA;;;;;;;AAOF;;;;;;;AASA;AACE;;AAEE;;;;;;AAMJ;;AACA;;AACF;;;;;AAwCA;AACE;AACA;AACA;AACA;;;;AAIF;AAIM;AAEE;AAEJ;;AAYE;;;AASM;;AAEJ;;AAIE;;AAwBE;;AAEF;AAEE;;;;;;;;AAOI;AACA;AACA;;;;;AAKN;AAEsC;;;AA8BpC;;;;AAMA;;;AAGA;AAEE;AACE;AAEF;;;;;;;;AAQkC;;;AAIlC;;AAEJ;AAEE;;;;AAIF;AAEE;;;;;;;AAME;;;;;;AAQoG;AAUnG;AACA;AAID;AACI;AACA;AACD;;AAmBC;;AAEA;;;AAGF;;;;;;;;;AAYE;;;AAGF;;AAaF;AACA;;AAOU;;AAEA;AACA;;;AAcJ;;;;;AAKI;;;;;;;;AAsBZ;AAeM;;;;;;;;;;;;;AAoCpB;AAsBO;AACL;AAEA;AAOM;AAA8B;;;AAEhC;AAYN;;"}
1
+ {"version":3,"file":"autocomplete.js","sources":["../../src/components/autocomplete.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport { Input } from \"./input\";\nimport { useDetectClickOutside } from '@/hooks/use-detect-click-outside';\nimport { cn } from \"@/utils\";\nimport { ChevronDown, PlusCircleIcon, Search, X } from \"lucide-react\";\nimport { Label } from \"./label\";\nimport { Button } from \"./button\";\nimport { CheckboxVisual } from \"./checkbox\";\nimport { Sheet, SheetContent, SheetTitle } from \"./sheet\";\nimport { useMobile } from \"@/hooks/use-mobile\";\nimport { useMobileSheetViewport } from \"@/hooks/use-mobile-sheet-viewport\";\nimport {\n FieldChromeContext,\n fieldFocusOutlineClassName,\n fieldInteractionClassName,\n useFieldFocus,\n} from \"@/hooks/use-field-focus\";\n\nexport interface IAutocompleteOption<ID extends number | string> {\n id: ID;\n name: string;\n keywords?: string[];\n /** Child options; in multiple mode the group can select all its children. */\n children?: IAutocompleteOption<ID>[];\n}\n\ntype MobileDropdownMode = \"sheet\" | \"inline\";\ntype InputIcons = boolean | \"search\" | \"dropdown\";\n\n/* -------------------------------------------------------\n * Base component (array-based). Single uses length 0..1.\n * -----------------------------------------------------*/\nfunction AutocompleteBase<ID extends number | string>({\n required,\n options,\n value = [],\n setter,\n placeholder,\n className,\n multiple = true,\n label,\n labelAddon,\n allowCustomValue = false,\n preserveOptionOrder = false,\n emptyText = \"No matching options\",\n mobileDropdownMode = \"sheet\",\n inputIcons = false,\n ...props\n}: {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n value?: ID[]; // single => 0..1 items, multi => any length\n setter: (next: ID[]) => void; // set the whole selection\n placeholder?: string;\n className?: string;\n multiple?: boolean;\n label?: React.ReactNode;\n labelAddon?: React.ReactNode;\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n}) {\n const [query, setQuery] = useState(\"\");\n const [isOpen, setIsOpen] = useState(false);\n const [dropdownMaxHeight, setDropdownMaxHeight] = useState<number>();\n const isMobile = useMobile();\n const clickOutsideRef = useDetectClickOutside({\n onTriggered: () => {\n // Radix owns outside dismissal for the portalled modal sheet.\n if (isMobile && mobileDropdownMode === 'sheet') return;\n setIsOpen(false);\n },\n });\n const rootRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const sheetInputRef = useRef<HTMLInputElement | null>(null);\n const sheetRef = useRef<HTMLDivElement | null>(null);\n const sheetCloseRef = useRef<HTMLButtonElement | null>(null);\n const lastSelectionRef = useRef(0);\n // Show the Button focus outline only for keyboard focus, not clicks.\n const { keyboardFocus, focusProps: fieldFocusProps } = useFieldFocus();\n\n const inputId = useId();\n const flatOptions = useMemo(\n () => options.flatMap((option) => option.children?.length ? option.children : [option]),\n [options],\n );\n\n const findExactOption = (value: string) => {\n const normalizedValue = value.trim().toLowerCase();\n return flatOptions.find(\n (o) =>\n o.name?.trim().toLowerCase() === normalizedValue ||\n o.keywords?.some((k) => k === normalizedValue),\n );\n };\n\n const resolveQuerySelection = (nextQuery: string, matchKeywords = true) => {\n const text = nextQuery.trim();\n if (!text) return false;\n\n const exact = matchKeywords\n ? findExactOption(text)\n : flatOptions.find(\n (o) => o.name?.trim().toLowerCase() === text.toLowerCase(),\n );\n if (exact) {\n setter([exact.id]);\n setQuery(\"\");\n return true;\n }\n\n if (allowCustomValue) {\n setter([text as unknown as ID]);\n setQuery(\"\");\n return true;\n }\n\n return false;\n };\n\n const selectedSet = useMemo(() => new Set(value ?? []), [value]);\n\n const filtered = useMemo(() => {\n const q = query.trim().toLowerCase();\n const base = q\n ? flatOptions.filter(\n (o) =>\n o.name?.toLowerCase().includes(q) ||\n options.some((group) => group.children?.some((child) => child.id === o.id) && group.name.toLowerCase().includes(q)) ||\n o.keywords?.some((k) => k.includes(q)),\n )\n : flatOptions;\n return preserveOptionOrder || options.some((option) => option.children?.length)\n ? base\n : base.slice().sort((a, b) => a.name.localeCompare(b.name));\n }, [query, flatOptions, options, preserveOptionOrder]);\n\n const toggle = (id: ID) => {\n lastSelectionRef.current = Date.now();\n if (!multiple) {\n setter([id]); // single-select\n setIsOpen(false);\n setQuery(\"\");\n return;\n }\n const set = new Set(value ?? []);\n if (set.has(id)) set.delete(id);\n else set.add(id);\n setter(Array.from(set));\n };\n\n const removeAt = (id: ID) => {\n const set = new Set(value ?? []);\n set.delete(id);\n setter(Array.from(set));\n };\n\n const selectedLabels = useMemo(\n () =>\n (value ?? [])\n .map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name;\n return label ?? (allowCustomValue ? String(id) : undefined);\n })\n .filter(Boolean) as string[],\n [value, flatOptions, allowCustomValue],\n );\n\n const singleDisplay = !multiple && (selectedLabels[0] ?? \"\");\n const useMobileSheet = isMobile && mobileDropdownMode === \"sheet\";\n const sheetViewport = useMobileSheetViewport(isOpen && useMobileSheet);\n // Desktop list: sized to the screen so it never runs off it. It opens\n // below the field, as tall as fits above the screen's bottom edge (16px\n // margin, at most 400px). With little room below (under 200px) and more\n // above, it opens upwards instead, sized to the space above. Re-measured\n // on scroll and resize while open.\n const [listFit, setListFit] = useState<{ maxHeight: number; above: boolean } | null>(null);\n useLayoutEffect(() => {\n if (!isOpen || useMobileSheet) return;\n const measure = () => {\n const field = inputRef.current?.getBoundingClientRect();\n if (!field) return;\n const below = window.innerHeight - field.bottom - 16;\n const above = field.top - 16;\n const openAbove = below < 200 && above > below;\n setListFit({\n above: openAbove,\n maxHeight: Math.max(120, Math.min(400, openAbove ? above : below)),\n });\n };\n measure();\n window.addEventListener(\"resize\", measure);\n window.addEventListener(\"scroll\", measure, true);\n return () => {\n window.removeEventListener(\"resize\", measure);\n window.removeEventListener(\"scroll\", measure, true);\n };\n }, [isOpen, useMobileSheet]);\n const useInlineMobileDropdown = isMobile && mobileDropdownMode === \"inline\";\n\n\n useEffect(() => {\n if (!isOpen || !useInlineMobileDropdown) {\n setDropdownMaxHeight(undefined);\n return;\n }\n\n const updateDropdownMaxHeight = () => {\n const rootRect = rootRef.current?.getBoundingClientRect();\n if (!rootRect) return;\n\n const viewportHeight =\n window.visualViewport?.height ?? window.innerHeight;\n const gap = 8;\n const availableHeight = viewportHeight - rootRect.bottom - gap;\n setDropdownMaxHeight(Math.max(0, Math.min(400, availableHeight)));\n };\n\n updateDropdownMaxHeight();\n window.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.addEventListener(\"scroll\", updateDropdownMaxHeight);\n\n return () => {\n window.removeEventListener(\"resize\", updateDropdownMaxHeight);\n window.visualViewport?.removeEventListener(\n \"resize\",\n updateDropdownMaxHeight,\n );\n window.visualViewport?.removeEventListener(\n \"scroll\",\n updateDropdownMaxHeight,\n );\n };\n }, [isOpen, useInlineMobileDropdown]);\n\n const suppressMobileKeyboard =\n isMobile && (useMobileSheet || (mobileDropdownMode === \"inline\" && !allowCustomValue));\n\n // --- keyboard helpers for multi\n const onMultiKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!multiple) return;\n if (allowCustomValue && e.key === \"Enter\" && query.trim().length > 0 && !findExactOption(query)) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n const set = new Set(value ?? []);\n set.add(nextId);\n setter(Array.from(set));\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n return;\n }\n if (\n e.key === \"Backspace\" &&\n query.length === 0 &&\n (value?.length ?? 0) > 0\n ) {\n const last = value[value.length - 1];\n removeAt(last);\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n const first = filtered[0];\n if (first) {\n toggle(first.id);\n setQuery(\"\");\n setIsOpen(true);\n e.preventDefault();\n }\n }\n if (e.key === \"ArrowDown\") setIsOpen(true);\n if (e.key === \"Escape\") setIsOpen(false);\n };\n\n // Same hover lift and press feedback as the Dropdown trigger.\n const fieldClassName = cn(\n fieldInteractionClassName,\n keyboardFocus && fieldFocusOutlineClassName,\n );\n\n const decorateSingleInput = (input: React.ReactNode) =>\n inputIcons ? (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n {inputIcons !== \"search\" && inputIcons !== \"dropdown\" && (\n <Search\n className=\"pointer-events-none absolute left-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n )}\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n {inputIcons === \"search\" ? (\n <Search\n className=\"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n ) : (\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 z-20 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n )}\n </div>\n ) : (\n <div className={cn(\"relative min-w-0 flex-1\", fieldClassName)} {...fieldFocusProps}>\n <FieldChromeContext value={true}>{input}</FieldChromeContext>\n </div>\n );\n\n const OptionsSurface = useMobileSheet ? SheetContent : 'div';\n const sheetProps = useMobileSheet ? {\n side: 'bottom' as const,\n showCloseButton: false,\n overlayClassName: 'z-(--z-popover-overlay) bg-black/25 backdrop-blur-[1px]',\n 'aria-describedby': undefined,\n onOpenAutoFocus: (event: Event) => { event.preventDefault(); sheetCloseRef.current?.focus(); },\n onCloseAutoFocus: (event: Event) => { event.preventDefault(); inputRef.current?.focus(); },\n } : {};\n return (\n <div\n className={cn(\"relative w-full overflow-visible\", className)}\n ref={(node) => {\n rootRef.current = node;\n (\n clickOutsideRef as React.MutableRefObject<HTMLDivElement | null>\n ).current = node;\n }}\n >\n {label ? (\n <Label\n label={label}\n required={required}\n labelAddon={labelAddon}\n />\n ) : null}\n\n {multiple ? (\n // ---------- MULTI: chips inline inside the box ----------\n <div\n className={cn(\n \"relative flex min-h-form-control w-full flex-wrap items-center gap-1 rounded-control-lg border border-input bg-background px-[0.75em] pr-10 hover:border-input-hover\",\n fieldClassName,\n )}\n {...fieldFocusProps}\n onClick={() => {\n setIsOpen(true);\n if (!suppressMobileKeyboard) {\n inputRef.current?.focus();\n }\n }}\n >\n {(value ?? []).map((id) => {\n const label = flatOptions.find((o) => o.id === id)?.name ?? String(id);\n return (\n <span\n key={String(id)}\n className=\"my-0.5 flex items-center gap-1 rounded-control-sm border border-input bg-muted px-2 text-xs\"\n >\n {label}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n className=\"ml-1 h-5 min-h-0 w-5 p-0 hover:bg-muted\"\n onClick={(event) => { event.stopPropagation(); removeAt(id); }}\n aria-label={`Remove ${label}`}\n >\n <X className=\"h-3.5 w-3.5\" />\n </Button>\n </span>\n );\n })}\n <input\n id={inputId}\n ref={inputRef}\n value={query}\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // Delay slightly to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (allowCustomValue && query.trim().length > 0) {\n const text = query.trim();\n const exact = findExactOption(text);\n const nextId = exact ? exact.id : (text as unknown as ID);\n setter(Array.from(new Set([...(value ?? []), nextId])));\n setQuery(\"\");\n }\n }, 150);\n }}\n onKeyDown={onMultiKeyDown}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n readOnly={suppressMobileKeyboard}\n placeholder={(value?.length ?? 0) === 0 ? placeholder : \"\"}\n className={cn(\n \"h-[calc(var(--spacing-form-control)-2px)] min-w-[8ch] flex-1 border-none bg-transparent p-0 text-base outline-none focus:ring-0\",\n \"placeholder:text-muted-foreground/40\",\n )}\n {...props}\n />\n <ChevronDown\n className={cn(\n \"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground transition-transform duration-interactive ease-out-strong motion-reduce:transition-none\",\n isOpen && \"rotate-180\",\n )}\n aria-hidden=\"true\"\n />\n </div>\n ) : (\n // ---------- SINGLE: regular input ----------\n decorateSingleInput(\n <Input\n id={inputId}\n value={singleDisplay || query}\n className={cn(\n \"border-input\",\n inputIcons === \"search\" || inputIcons === \"dropdown\" ? \"pr-10\" : inputIcons && \"px-10\",\n )}\n placeholder={placeholder}\n readOnly={suppressMobileKeyboard}\n onChange={(e) => {\n const nextQuery = e.target.value;\n\n if ((value?.length ?? 0) > 0) {\n setter([]);\n }\n\n const exact = findExactOption(nextQuery);\n // Only auto-fill on an exact NAME match; keyword/acronym matches\n // (e.g. \"dlsu\") require an explicit Enter, blur, or click.\n if (\n exact &&\n exact.name.trim().toLowerCase() ===\n nextQuery.trim().toLowerCase()\n ) {\n setter([exact.id]);\n setQuery(\"\");\n } else {\n setQuery(nextQuery);\n }\n\n setIsOpen(true);\n }}\n onFocus={() => { if (!useMobileSheet) setIsOpen(true); }}\n onClick={(e) => {\n setIsOpen(true);\n if (suppressMobileKeyboard) {\n e.currentTarget.blur();\n }\n }}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && resolveQuerySelection(query, true)) {\n setIsOpen(false);\n e.preventDefault();\n }\n }}\n onBlur={() => {\n if (useMobileSheet) return;\n // slight delay to let dropdown option clicks register first\n setTimeout(() => {\n if (Date.now() - lastSelectionRef.current < 250) {\n return;\n }\n if (!resolveQuerySelection(query, false)) setQuery(\"\");\n }, 150);\n }}\n />,\n )\n )}\n\n {isOpen && (\n <Sheet open={useMobileSheet && isOpen} onOpenChange={next => { if (!next) { setQuery(''); setIsOpen(false); } }}>\n <OptionsSurface\n {...sheetProps}\n ref={useMobileSheet ? sheetRef : undefined}\n role={useMobileSheet ? \"dialog\" : undefined}\n aria-modal={useMobileSheet ? true : undefined}\n aria-label={useMobileSheet ? (typeof label === \"string\" ? label : \"Choose options\") : undefined}\n className={cn(\n \"bg-background text-sm shadow-card border border-border\",\n useMobileSheet\n ? \"fixed left-0 right-0 z-(--z-popover) flex flex-col gap-0 overflow-hidden rounded-t-control-lg border-b-0 p-0\"\n : \"absolute left-0 right-0 z-50 mt-1 max-h-[400px] overflow-y-auto overscroll-contain rounded-control-lg\",\n )}\n style={\n useMobileSheet\n ? {\n bottom: sheetViewport?.bottom ?? 0,\n maxHeight: sheetViewport ? Math.min(sheetViewport.height, 640) : \"80dvh\",\n }\n : listFit\n ? {\n maxHeight: listFit.maxHeight,\n ...(listFit.above && {\n top: \"auto\",\n bottom: \"100%\",\n marginTop: 0,\n marginBottom: 4,\n }),\n }\n : undefined\n }\n >\n {useMobileSheet && (\n <div className=\"shrink-0 px-4 pb-3 pt-4\">\n <div className=\"mb-3 flex items-center justify-between gap-4\">\n <SheetTitle className=\"text-base font-semibold text-foreground\">{label || \"Choose options\"}</SheetTitle>\n <button ref={sheetCloseRef} type=\"button\" aria-label=\"Close options\" className=\"-mr-3 flex h-11 w-11 shrink-0 items-center justify-center rounded-control-lg text-muted-foreground hover:bg-muted\" onClick={() => { setQuery(\"\"); setIsOpen(false); }}>\n <X className=\"h-5 w-5\" aria-hidden=\"true\" />\n </button>\n </div>\n <Input\n ref={sheetInputRef}\n aria-label={typeof label === \"string\" ? `Search ${label}` : \"Search options\"}\n value={query}\n placeholder={placeholder ?? \"Search\"}\n className=\"h-10 min-h-10 max-h-none text-base\"\n onChange={(e) => {\n setQuery(e.target.value);\n setIsOpen(true);\n if ((value?.length ?? 0) > 0 && !multiple) {\n setter([]);\n }\n }}\n onKeyDown={(e) => {\n if (multiple) {\n onMultiKeyDown(e);\n return;\n }\n\n if (e.key === \"Enter\" && resolveQuerySelection(query)) {\n setIsOpen(false);\n e.preventDefault();\n }\n\n if (e.key === \"Escape\") {\n setIsOpen(false);\n }\n }}\n />\n </div>\n )}\n <ul className={cn(\"flex flex-col gap-option-gap p-option-inset\", useMobileSheet && \"min-h-0 flex-1 overflow-y-auto overscroll-contain\")}>\n {allowCustomValue && (\n <li className=\"pointer-events-none px-option-x pb-1 pt-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground\">\n Suggestions\n </li>\n )}\n {filtered.length ? (\n filtered.map((option, index) => {\n const active = selectedSet.has(option.id);\n const group = options.find((item) => item.children?.some((child) => child.id === option.id));\n const firstInGroup = group && !filtered.slice(0, index).some((item) => group.children?.some((child) => child.id === item.id));\n return (\n <Fragment key={String(option.id)}>\n {firstInGroup && group && (\n <li>\n {multiple ? (\n <button type=\"button\" aria-pressed={group.children!.every((child) => selectedSet.has(child.id))} className=\"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm font-medium text-foreground transition-colors hover:bg-muted max-md:min-h-11\" onClick={() => {\n const ids = group.children!.map((child) => child.id);\n const next = new Set(value ?? []);\n const allSelected = ids.every((id) => next.has(id));\n ids.forEach((id) => allSelected ? next.delete(id) : next.add(id));\n setter(Array.from(next));\n }}>\n <CheckboxVisual checked={group.children!.every((child) => selectedSet.has(child.id)) ? true : group.children!.some((child) => selectedSet.has(child.id)) ? 'indeterminate' : false} />\n {group.name}\n </button>\n ) : <div className=\"px-option-x py-2 text-sm font-medium text-foreground\">{group.name}</div>}\n </li>\n )}\n <li>\n <button\n type=\"button\"\n aria-pressed={multiple ? active : undefined}\n onClick={() => {\n toggle(option.id);\n if (multiple) {\n // keep open for rapid multi-pick\n setQuery(\"\");\n if (!useMobileSheet) {\n inputRef.current?.focus();\n }\n } else {\n setQuery(\"\");\n setIsOpen(false);\n }\n }}\n className={cn(\n \"flex min-h-option-row w-full cursor-pointer items-center gap-3 rounded-control-sm px-option-x py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-muted\",\n useMobileSheet && \"min-h-12\",\n group && \"pl-8\",\n active && \"bg-primary-tint\",\n )}\n >\n {multiple ? (\n <CheckboxVisual checked={active} />\n ) : null}\n {option.name}\n </button>\n </li>\n </Fragment>\n );\n })\n ) : (\n !allowCustomValue || !query.trim() ? (\n <li className=\"px-option-x py-2 text-sm text-muted-foreground\">\n {emptyText}\n </li>\n ) : null\n )}\n {allowCustomValue && query.trim() && !findExactOption(query) && (\n <li>\n <button\n type=\"button\"\n className=\"flex min-h-11 w-full cursor-pointer items-center gap-2 rounded-control-sm px-option-x py-2 text-left text-sm text-primary transition-colors hover:bg-muted focus-visible:outline-2 focus-visible:outline-primary\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n const text = query.trim();\n if (multiple) {\n setter(Array.from(new Set([...(value ?? []), text as unknown as ID])));\n setQuery(\"\");\n } else {\n resolveQuerySelection(text);\n setIsOpen(false);\n }\n }}\n >\n <PlusCircleIcon className=\"h-4 w-4\" aria-hidden=\"true\" />\n Add “{query.trim()}”\n </button>\n </li>\n )}\n </ul>\n {useMobileSheet && multiple && (\n <div className=\"shrink-0 border-t border-border bg-background px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]\">\n <Button\n type=\"button\"\n variant=\"outline\"\n className=\"min-h-11 w-full\"\n onClick={() => {\n setQuery(\"\");\n setIsOpen(false);\n }}\n >\n Done\n </Button>\n </div>\n )}\n </OptionsSurface>\n </Sheet>\n )}\n </div>\n );\n}\n\ntype AutocompleteCommonProps<ID extends number | string> = {\n required?: boolean;\n options: IAutocompleteOption<ID>[];\n placeholder?: string;\n className?: string;\n label?: React.ReactNode;\n props?: any[];\n /** Allow a user to add their own text. Custom values are strings. */\n allowCustomValue?: boolean;\n preserveOptionOrder?: boolean;\n emptyText?: string;\n mobileDropdownMode?: MobileDropdownMode;\n inputIcons?: InputIcons;\n};\n\nexport type AutocompleteProps<ID extends number | string> = AutocompleteCommonProps<ID> & (\n | { multiple?: false; value?: ID | null; setter: (value?: ID | null) => void }\n | { multiple: true; value?: ID[]; setter: (value: ID[]) => void }\n);\n\nexport const Autocomplete = <ID extends number | string>(config: AutocompleteProps<ID>) => {\n const { required, options, placeholder, className, label, props, allowCustomValue = false,\n preserveOptionOrder = false, emptyText, mobileDropdownMode, inputIcons } = config;\n return (\n <AutocompleteBase<ID>\n required={required}\n options={options}\n multiple={config.multiple === true}\n value={config.multiple === true ? config.value ?? [] : config.value != null ? [config.value] : []}\n setter={(arr) => {\n if (config.multiple === true) config.setter(arr);\n else config.setter(arr[0] ?? null);\n }}\n placeholder={placeholder}\n className={className}\n label={label}\n allowCustomValue={allowCustomValue}\n preserveOptionOrder={preserveOptionOrder}\n emptyText={emptyText}\n mobileDropdownMode={mobileDropdownMode}\n inputIcons={inputIcons}\n {...props}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA+BA;;AAE0D;AAC1D;;;;AAmCE;;;;AAII;;;;AAGH;AACD;AACA;AACA;AACA;AACA;AACA;;;AAIA;AACA;AAKA;;AAEE;AAGI;AAEN;;AAGE;AACA;AAAW;;AAGT;;;AAKA;;AAEA;;;AAIA;;AAEA;;AAGF;AACF;AAEA;AAEA;;;;AAMY;AACA;;AAGV;AACE;;;AAIJ;AACE;;AAEE;;;;;;AAMF;AAAiB;;AACZ;;AAEP;AAEA;;AAEE;;AAEF;;AAKO;AACC;AACA;AACF;AACC;AAIP;AACA;;;;;;;;;;;;;AAYI;;;AAEA;;AAEA;AACE;;AAED;AACH;AACA;AACA;;AAEA;AACE;;AAEF;AACF;AACA;;AAIE;;;;;;AAOE;;;;;AAMA;AACF;AAEA;AACA;;;AAIA;AACE;;;AASF;AACF;AAEA;;AAIA;AACE;;;AAEE;AACA;AACA;;AAEA;;;;;;;AAOF;;;;;;;AASA;AACE;;AAEE;;;;;;AAMJ;;AACA;;AACF;;;;;AAwCA;AACE;AACA;AACA;AACA;;;;AAIF;AAIM;AAEE;AAEJ;;AAYE;;;AASM;;AAEJ;;AAIE;;AAwBE;;AAEF;AAEE;;;;;;;;AAOI;AACA;AACA;;;;;AAKN;AAEsC;;;AA8BpC;;;;AAMA;;;AAGA;AAEE;AACE;AAEF;;;;;;;;AAQkC;;;AAIlC;;AAEJ;AAEE;;;;AAIF;AAEE;;;;;;;AAME;;;;;;AAQoG;AAUnG;AACA;AAID;AACI;AACA;AACD;AACH;AACE;;AAEI;AACE;AACA;AACA;AACA;;AAEH;;AAmBD;;AAEA;;;AAGF;;;;;;;;;AAYE;;;AAGF;;AAaF;AACA;;AAOU;;AAEA;AACA;;;AAcJ;;;;;AAKI;;;;;;;;AAsBZ;AAeM;;;;;;;;;;;;;AAoCpB;AAsBO;AACL;AAEA;AAOM;AAA8B;;;AAEhC;AAYN;;"}
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import Link from 'next/link';
3
3
  import { cn } from '../utils.js';
4
4
  import { Spinner } from './loader.js';
@@ -37,16 +37,18 @@ function Button({ variant = 'solid', scheme, size = 'md', shape, className, icon
37
37
  return jsx(Link, { ...linkProps, className: classes, children: content });
38
38
  }
39
39
  const { type = 'button', disabled, loading = false, href: _href, ...buttonProps } = props;
40
- return jsxs("button", { ...buttonProps, type: type, className: classes, disabled: disabled || loading, "aria-busy": loading || buttonProps['aria-busy'], children: [loading && jsx(Spinner, { decorative: true }), (!iconOnly || !loading) && content] });
40
+ // Loading: only a centred spinner. The content stays in place, transparent,
41
+ // so the button keeps its size and its accessible name.
42
+ return jsx("button", { ...buttonProps, type: type, className: cn(classes, loading && 'relative'), disabled: disabled || loading, "aria-busy": loading || buttonProps['aria-busy'], children: loading ? jsxs(Fragment, { children: [jsx("span", { className: "inline-flex items-center gap-[inherit] opacity-0", children: content }), jsx(Spinner, { decorative: true, className: "absolute inset-0" })] }) : content });
41
43
  }
42
44
  const iconSizes = {
43
45
  xs: 'size-8', sm: 'size-9', md: 'size-11', lg: 'size-12', xl: 'size-13', '2xl': 'size-14',
44
46
  };
45
47
  function ExpandingButton({ icon, label, size = 'md', loading, ...props }) {
46
- return jsxs(Button, { "aria-label": label, ...props, size: size, loading: loading, className: cn('gap-0 px-3', props.className), children: [!loading && jsx("span", { "aria-hidden": "true", className: "inline-flex", children: icon }), jsx("span", { className: "ml-0 max-w-0 overflow-hidden whitespace-nowrap opacity-0 pointer-fine:group-hover/button:ml-2 pointer-fine:group-hover/button:max-w-40 pointer-fine:group-hover/button:opacity-100 group-focus-visible/button:ml-2 group-focus-visible/button:max-w-40 group-focus-visible/button:opacity-100 group-aria-busy/button:ml-2 group-aria-busy/button:max-w-40 group-aria-busy/button:opacity-100 motion-safe:transition-[max-width,margin,opacity] motion-safe:duration-interactive motion-safe:ease-out-strong motion-reduce:transition-none", children: label })] });
48
+ return jsxs(Button, { "aria-label": label, ...props, size: size, loading: loading, className: cn('gap-0 px-3', props.className), children: [jsx("span", { "aria-hidden": "true", className: "inline-flex", children: icon }), jsx("span", { className: "ml-0 max-w-0 overflow-hidden whitespace-nowrap opacity-0 pointer-fine:group-hover/button:ml-2 pointer-fine:group-hover/button:max-w-40 pointer-fine:group-hover/button:opacity-100 group-focus-visible/button:ml-2 group-focus-visible/button:max-w-40 group-focus-visible/button:opacity-100 motion-safe:transition-[max-width,margin,opacity] motion-safe:duration-interactive motion-safe:ease-out-strong motion-reduce:transition-none", children: label })] });
47
49
  }
48
50
  function FilterChip({ selected = false, icon, children, loading, ...props }) {
49
- return jsxs(Button, { ...props, variant: "outline", scheme: selected ? 'secondary' : 'neutral', size: "md", shape: "pill", "aria-pressed": selected, loading: loading, className: cn('w-max max-w-full gap-2.5 px-5 py-3 text-base leading-[1.4]', selected && 'font-semibold'), children: [!loading && icon, children] });
51
+ return jsxs(Button, { ...props, variant: "outline", scheme: selected ? 'secondary' : 'neutral', size: "md", shape: "pill", "aria-pressed": selected, loading: loading, className: cn('w-max max-w-full gap-2.5 px-5 py-3 text-base leading-[1.4]', selected && 'font-semibold'), children: [icon, children] });
50
52
  }
51
53
 
52
54
  export { Button, ExpandingButton, FilterChip, buttonClassName };
@@ -1 +1 @@
1
- {"version":3,"file":"button.js","sources":["../../src/components/button.tsx"],"sourcesContent":["import Link from 'next/link';\nimport type { ComponentPropsWithRef, ReactNode } from 'react';\nimport { cn } from '@/utils';\nimport { Spinner } from './loader';\nimport { interactiveControlClassName, interactiveControlTransitionClassName } from '@/lib/interaction-styles';\n\nexport type ButtonVariant = 'solid' | 'outline' | 'ghost' | 'link';\nexport type ButtonScheme = 'primary' | 'secondary' | 'neutral' | 'destructive' | 'success';\nexport type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\nexport type ButtonShape = 'rounded' | 'pill';\n\ntype ButtonAppearance = {\n /** Visual treatment. */\n variant?: ButtonVariant;\n /** Semantic color, independent of the fill treatment. Defaults to primary, or neutral for outline/ghost. */\n scheme?: ButtonScheme;\n /** Standard control size: 32px, 36px, 44px, 48px, 52px, or 56px minimum height. */\n size?: ButtonSize;\n /** Corner treatment. Landing presets keep their original shape when omitted. */\n shape?: ButtonShape;\n /** Additional classes, merged after the component's appearance classes. */\n className?: string;\n};\n\nconst schemes: Record<ButtonScheme, string> = {\n primary: '[--btn-fill:var(--color-landing-blue)] [--btn-on:white] [--btn-hover:var(--color-landing-blue-hover)] [--btn-ink:var(--color-landing-blue-hover)] [--btn-soft:var(--color-landing-tint)] [--btn-border:var(--color-landing-blue)]',\n secondary: '[--btn-fill:var(--color-landing-secondary-tint)] [--btn-on:var(--color-landing-secondary-deep)] [--btn-hover:var(--color-brand-secondary-hover)] [--btn-ink:var(--color-landing-secondary-deep)] [--btn-soft:var(--color-landing-secondary-tint)] [--btn-border:var(--color-landing-secondary-border)]',\n neutral: '[--btn-fill:var(--color-v2-surface-subtle)] [--btn-on:var(--color-landing-nav)] [--btn-hover:var(--color-landing-border)] [--btn-ink:var(--color-landing-nav)] [--btn-soft:rgb(55_65_81_/_6%)] [--btn-border:var(--color-landing-control)]',\n destructive: '[--btn-fill:var(--color-v2-destructive)] [--btn-on:white] [--btn-hover:var(--color-brand-destructive-hover)] [--btn-ink:var(--color-brand-destructive-hover)] [--btn-soft:var(--color-brand-destructive-soft)] [--btn-border:var(--color-v2-destructive)]',\n success: '[--btn-fill:var(--color-brand-success)] [--btn-on:white] [--btn-hover:var(--color-brand-success-hover)] [--btn-ink:var(--color-brand-success)] [--btn-soft:var(--color-brand-success-soft)] [--btn-border:var(--color-brand-success)]',\n};\nconst treatments: Record<ButtonVariant, string> = {\n solid: cn('border border-[var(--btn-border)] bg-[var(--btn-fill)] font-semibold text-[var(--btn-on)] enabled:pointer-fine:hover:border-[var(--btn-hover)] enabled:pointer-fine:hover:bg-[var(--btn-hover)] [&:is(a):hover]:bg-[var(--btn-hover)]', interactiveControlClassName),\n outline: cn('border border-[var(--btn-border)] bg-transparent text-[var(--btn-ink)] enabled:hover:bg-[var(--btn-soft)] [&:is(a):hover]:bg-[var(--btn-soft)]', interactiveControlClassName),\n ghost: 'border border-transparent bg-transparent text-[var(--btn-ink)] enabled:hover:bg-[var(--btn-soft)] [&:is(a):hover]:bg-[var(--btn-soft)]',\n link: 'border-0 bg-transparent text-[var(--btn-ink)] underline-offset-4 enabled:hover:underline [&:is(a):hover]:underline',\n};\nconst sizes: Record<ButtonSize, string> = {\n xs: 'min-h-8 px-2 text-xs leading-[1.5]',\n sm: 'min-h-9 px-3 text-sm leading-[1.5]',\n md: 'min-h-11 px-5 text-sm leading-[1.5]',\n lg: 'min-h-12 px-6 text-base leading-[1.5]',\n xl: 'min-h-13 px-7 text-base leading-[1.5]',\n '2xl': 'min-h-14 px-8 text-lg leading-[1.5]',\n};\n\n/** Shared styling for action and navigation controls. Colors never change the fill treatment. */\nexport function buttonClassName({variant = 'solid', scheme, size = 'md', shape, className}: ButtonAppearance = {}) {\n return cn(\n 'group group/button inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control-lg font-[550] focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue disabled:pointer-events-none disabled:opacity-50 aria-disabled:cursor-default aria-busy:cursor-wait [&_svg]:shrink-0',\n interactiveControlTransitionClassName,\n schemes[scheme ?? (['outline', 'ghost'].includes(variant) ? 'neutral' : 'primary')],\n treatments[variant], sizes[size],\n variant === 'outline' && (scheme === undefined || scheme === 'neutral') && 'enabled:hover:border-landing-control-hover enabled:hover:text-landing-nav-hover [&:is(a):hover]:border-landing-control-hover',\n variant === 'outline' && scheme === 'secondary' && 'bg-[var(--btn-soft)]',\n shape === 'pill' && 'rounded-full', shape === 'rounded' && 'rounded-control-lg', className,\n );\n}\n\ntype IconOnlyProps = { iconOnly?: false } | { iconOnly: true; 'aria-label': string };\ntype ActionButtonProps = ComponentPropsWithRef<'button'> & ButtonAppearance & {\n href?: never;\n /** Shows a progress indicator, exposes aria-busy, and disables the action while work is pending. */\n loading?: boolean;\n};\ntype NavigationButtonProps = Omit<ComponentPropsWithRef<typeof Link>, 'className'> & ButtonAppearance & {\n loading?: never;\n disabled?: never;\n};\nexport type ButtonProps = ActionButtonProps;\nexport type UnifiedButtonProps = (ActionButtonProps | NavigationButtonProps) & IconOnlyProps;\n\nexport function Button({variant = 'solid', scheme, size = 'md', shape, className, iconOnly = false, children, ...props}: UnifiedButtonProps) {\n const classes = buttonClassName({variant, scheme, size, shape, className: cn(iconOnly && [iconSizes[size], 'gap-0 p-0'], className)});\n const content = iconOnly ? <span aria-hidden=\"true\" className=\"inline-flex\">{children}</span> : children;\n if (props.href !== undefined) {\n const { loading: _loading, disabled: _disabled, ...linkProps } = props as NavigationButtonProps;\n return <Link {...linkProps} className={classes}>{content}</Link>;\n }\n const {type = 'button', disabled, loading = false, href: _href, ...buttonProps} = props as ActionButtonProps;\n return <button {...buttonProps} type={type} className={classes} disabled={disabled || loading} aria-busy={loading || buttonProps['aria-busy']}>\n {loading && <Spinner decorative />}{(!iconOnly || !loading) && content}\n </button>;\n}\n\n\ntype IconSize = ButtonSize;\nconst iconSizes: Record<IconSize, string> = {\n xs: 'size-8', sm: 'size-9', md: 'size-11', lg: 'size-12', xl: 'size-13', '2xl': 'size-14',\n};\n\nexport type ExpandingButtonProps = Omit<ActionButtonProps, 'children' | 'size'> & {\n /** Leading icon. */\n icon: ReactNode;\n /** Action label, revealed on hover/focus and always visible on touch screens. */\n label: string;\n /** Standard control size. */\n size?: IconSize;\n};\nexport function ExpandingButton({icon, label, size = 'md', loading, ...props}: ExpandingButtonProps) {\n return <Button aria-label={label} {...props} size={size} loading={loading} className={cn('gap-0 px-3', props.className)}>\n {!loading && <span aria-hidden=\"true\" className=\"inline-flex\">{icon}</span>}\n {/* Icon only at rest. With a mouse the label slides out on hover; on\n touch there's no hover, so it stays an icon button. Keyboard focus and\n loading show the label on any device (loading hides the icon). */}\n <span className=\"ml-0 max-w-0 overflow-hidden whitespace-nowrap opacity-0 pointer-fine:group-hover/button:ml-2 pointer-fine:group-hover/button:max-w-40 pointer-fine:group-hover/button:opacity-100 group-focus-visible/button:ml-2 group-focus-visible/button:max-w-40 group-focus-visible/button:opacity-100 group-aria-busy/button:ml-2 group-aria-busy/button:max-w-40 group-aria-busy/button:opacity-100 motion-safe:transition-[max-width,margin,opacity] motion-safe:duration-interactive motion-safe:ease-out-strong motion-reduce:transition-none\">{label}</span>\n </Button>;\n}\n\nexport type FilterChipProps = Omit<ActionButtonProps, 'variant' | 'scheme' | 'size' | 'shape' | 'aria-pressed'> & {\n /** Controlled selection state; onClick belongs to the caller. */\n selected?: boolean;\n /** Optional leading icon. */\n icon?: ReactNode;\n};\nexport function FilterChip({selected = false, icon, children, loading, ...props}: FilterChipProps) {\n return <Button {...props} variant=\"outline\" scheme={selected ? 'secondary' : 'neutral'} size=\"md\" shape=\"pill\" aria-pressed={selected} loading={loading} className={cn('w-max max-w-full gap-2.5 px-5 py-3 text-base leading-[1.4]', selected && 'font-semibold')}>\n {!loading && icon}{children}\n </Button>;\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;AAwBA,MAAM,OAAO,GAAiC;AAC5C,IAAA,OAAO,EAAE,mOAAmO;AAC5O,IAAA,SAAS,EAAE,wSAAwS;AACnT,IAAA,OAAO,EAAE,4OAA4O;AACrP,IAAA,WAAW,EAAE,2PAA2P;AACxQ,IAAA,OAAO,EAAE,uOAAuO;CACjP;AACD,MAAM,UAAU,GAAkC;AAChD,IAAA,KAAK,EAAE,EAAE,CAAC,uOAAuO,EAAE,2BAA2B,CAAC;AAC/Q,IAAA,OAAO,EAAE,EAAE,CAAC,gJAAgJ,EAAE,2BAA2B,CAAC;AAC1L,IAAA,KAAK,EAAE,wIAAwI;AAC/I,IAAA,IAAI,EAAE,oHAAoH;CAC3H;AACD,MAAM,KAAK,GAA+B;AACxC,IAAA,EAAE,EAAE,oCAAoC;AACxC,IAAA,EAAE,EAAE,oCAAoC;AACxC,IAAA,EAAE,EAAE,qCAAqC;AACzC,IAAA,EAAE,EAAE,uCAAuC;AAC3C,IAAA,EAAE,EAAE,uCAAuC;AAC3C,IAAA,KAAK,EAAE,qC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EAAA,CAAQ,EAI3EA,cAAM,SAAS,EAAC,2gBAA2gB,EAAA,QAAA,EAAE,KAAK,EAAA,CAAQ,CAAA,EAAA,CACniB;AACX;SAQgB,UAAU,CAAC,EAAC,QAAQ,GAAG,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,EAAkB,EAAA;IAC/F,OAAOC,IAAA,CAAC,MAAM,EAAA,EAAA,GAAK,KAAK,EAAE,OAAO,EAAC,SAAS,EAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,EAAE,IAAI,EAAC,IAAI,EAAC,KAAK,EAAC,MAAM,EAAA,cAAA,EAAe,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,4DAA4D,EAAE,QAAQ,IAAI,eAAe,CAAC,EAAA,QAAA,EAAA,CAC9P,CAAC,OAAO,IAAI,IAAI,EAAE,QAAQ,CAAA,EAAA,CACpB;AACX;;;;"}
1
+ {"version":3,"file":"button.js","sources":["../../src/components/button.tsx"],"sourcesContent":["import Link from 'next/link';\nimport type { ComponentPropsWithRef, ReactNode } from 'react';\nimport { cn } from '@/utils';\nimport { Spinner } from './loader';\nimport { interactiveControlClassName, interactiveControlTransitionClassName } from '@/lib/interaction-styles';\n\nexport type ButtonVariant = 'solid' | 'outline' | 'ghost' | 'link';\nexport type ButtonScheme = 'primary' | 'secondary' | 'neutral' | 'destructive' | 'success';\nexport type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\nexport type ButtonShape = 'rounded' | 'pill';\n\ntype ButtonAppearance = {\n /** Visual treatment. */\n variant?: ButtonVariant;\n /** Semantic color, independent of the fill treatment. Defaults to primary, or neutral for outline/ghost. */\n scheme?: ButtonScheme;\n /** Standard control size: 32px, 36px, 44px, 48px, 52px, or 56px minimum height. */\n size?: ButtonSize;\n /** Corner treatment. Landing presets keep their original shape when omitted. */\n shape?: ButtonShape;\n /** Additional classes, merged after the component's appearance classes. */\n className?: string;\n};\n\nconst schemes: Record<ButtonScheme, string> = {\n primary: '[--btn-fill:var(--color-landing-blue)] [--btn-on:white] [--btn-hover:var(--color-landing-blue-hover)] [--btn-ink:var(--color-landing-blue-hover)] [--btn-soft:var(--color-landing-tint)] [--btn-border:var(--color-landing-blue)]',\n secondary: '[--btn-fill:var(--color-landing-secondary-tint)] [--btn-on:var(--color-landing-secondary-deep)] [--btn-hover:var(--color-brand-secondary-hover)] [--btn-ink:var(--color-landing-secondary-deep)] [--btn-soft:var(--color-landing-secondary-tint)] [--btn-border:var(--color-landing-secondary-border)]',\n neutral: '[--btn-fill:var(--color-v2-surface-subtle)] [--btn-on:var(--color-landing-nav)] [--btn-hover:var(--color-landing-border)] [--btn-ink:var(--color-landing-nav)] [--btn-soft:rgb(55_65_81_/_6%)] [--btn-border:var(--color-landing-control)]',\n destructive: '[--btn-fill:var(--color-v2-destructive)] [--btn-on:white] [--btn-hover:var(--color-brand-destructive-hover)] [--btn-ink:var(--color-brand-destructive-hover)] [--btn-soft:var(--color-brand-destructive-soft)] [--btn-border:var(--color-v2-destructive)]',\n success: '[--btn-fill:var(--color-brand-success)] [--btn-on:white] [--btn-hover:var(--color-brand-success-hover)] [--btn-ink:var(--color-brand-success)] [--btn-soft:var(--color-brand-success-soft)] [--btn-border:var(--color-brand-success)]',\n};\nconst treatments: Record<ButtonVariant, string> = {\n solid: cn('border border-[var(--btn-border)] bg-[var(--btn-fill)] font-semibold text-[var(--btn-on)] enabled:pointer-fine:hover:border-[var(--btn-hover)] enabled:pointer-fine:hover:bg-[var(--btn-hover)] [&:is(a):hover]:bg-[var(--btn-hover)]', interactiveControlClassName),\n outline: cn('border border-[var(--btn-border)] bg-transparent text-[var(--btn-ink)] enabled:hover:bg-[var(--btn-soft)] [&:is(a):hover]:bg-[var(--btn-soft)]', interactiveControlClassName),\n ghost: 'border border-transparent bg-transparent text-[var(--btn-ink)] enabled:hover:bg-[var(--btn-soft)] [&:is(a):hover]:bg-[var(--btn-soft)]',\n link: 'border-0 bg-transparent text-[var(--btn-ink)] underline-offset-4 enabled:hover:underline [&:is(a):hover]:underline',\n};\nconst sizes: Record<ButtonSize, string> = {\n xs: 'min-h-8 px-2 text-xs leading-[1.5]',\n sm: 'min-h-9 px-3 text-sm leading-[1.5]',\n md: 'min-h-11 px-5 text-sm leading-[1.5]',\n lg: 'min-h-12 px-6 text-base leading-[1.5]',\n xl: 'min-h-13 px-7 text-base leading-[1.5]',\n '2xl': 'min-h-14 px-8 text-lg leading-[1.5]',\n};\n\n/** Shared styling for action and navigation controls. Colors never change the fill treatment. */\nexport function buttonClassName({variant = 'solid', scheme, size = 'md', shape, className}: ButtonAppearance = {}) {\n return cn(\n 'group group/button inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control-lg font-[550] focus-visible:outline-3 focus-visible:outline-offset-4 focus-visible:outline-landing-blue disabled:pointer-events-none disabled:opacity-50 aria-disabled:cursor-default aria-busy:cursor-wait [&_svg]:shrink-0',\n interactiveControlTransitionClassName,\n schemes[scheme ?? (['outline', 'ghost'].includes(variant) ? 'neutral' : 'primary')],\n treatments[variant], sizes[size],\n variant === 'outline' && (scheme === undefined || scheme === 'neutral') && 'enabled:hover:border-landing-control-hover enabled:hover:text-landing-nav-hover [&:is(a):hover]:border-landing-control-hover',\n variant === 'outline' && scheme === 'secondary' && 'bg-[var(--btn-soft)]',\n shape === 'pill' && 'rounded-full', shape === 'rounded' && 'rounded-control-lg', className,\n );\n}\n\ntype IconOnlyProps = { iconOnly?: false } | { iconOnly: true; 'aria-label': string };\ntype ActionButtonProps = ComponentPropsWithRef<'button'> & ButtonAppearance & {\n href?: never;\n /** Shows a progress indicator, exposes aria-busy, and disables the action while work is pending. */\n loading?: boolean;\n};\ntype NavigationButtonProps = Omit<ComponentPropsWithRef<typeof Link>, 'className'> & ButtonAppearance & {\n loading?: never;\n disabled?: never;\n};\nexport type ButtonProps = ActionButtonProps;\nexport type UnifiedButtonProps = (ActionButtonProps | NavigationButtonProps) & IconOnlyProps;\n\nexport function Button({variant = 'solid', scheme, size = 'md', shape, className, iconOnly = false, children, ...props}: UnifiedButtonProps) {\n const classes = buttonClassName({variant, scheme, size, shape, className: cn(iconOnly && [iconSizes[size], 'gap-0 p-0'], className)});\n const content = iconOnly ? <span aria-hidden=\"true\" className=\"inline-flex\">{children}</span> : children;\n if (props.href !== undefined) {\n const { loading: _loading, disabled: _disabled, ...linkProps } = props as NavigationButtonProps;\n return <Link {...linkProps} className={classes}>{content}</Link>;\n }\n const {type = 'button', disabled, loading = false, href: _href, ...buttonProps} = props as ActionButtonProps;\n // Loading: only a centred spinner. The content stays in place, transparent,\n // so the button keeps its size and its accessible name.\n return <button {...buttonProps} type={type} className={cn(classes, loading && 'relative')} disabled={disabled || loading} aria-busy={loading || buttonProps['aria-busy']}>\n {loading ? <>\n <span className=\"inline-flex items-center gap-[inherit] opacity-0\">{content}</span>\n <Spinner decorative className=\"absolute inset-0\" />\n </> : content}\n </button>;\n}\n\n\ntype IconSize = ButtonSize;\nconst iconSizes: Record<IconSize, string> = {\n xs: 'size-8', sm: 'size-9', md: 'size-11', lg: 'size-12', xl: 'size-13', '2xl': 'size-14',\n};\n\nexport type ExpandingButtonProps = Omit<ActionButtonProps, 'children' | 'size'> & {\n /** Leading icon. */\n icon: ReactNode;\n /** Action label, revealed on hover/focus and always visible on touch screens. */\n label: string;\n /** Standard control size. */\n size?: IconSize;\n};\nexport function ExpandingButton({icon, label, size = 'md', loading, ...props}: ExpandingButtonProps) {\n return <Button aria-label={label} {...props} size={size} loading={loading} className={cn('gap-0 px-3', props.className)}>\n <span aria-hidden=\"true\" className=\"inline-flex\">{icon}</span>\n {/* Icon only at rest. With a mouse the label slides out on hover; on\n touch there's no hover, so it stays an icon button. Keyboard focus\n shows the label on any device. Loading shows Button's spinner. */}\n <span className=\"ml-0 max-w-0 overflow-hidden whitespace-nowrap opacity-0 pointer-fine:group-hover/button:ml-2 pointer-fine:group-hover/button:max-w-40 pointer-fine:group-hover/button:opacity-100 group-focus-visible/button:ml-2 group-focus-visible/button:max-w-40 group-focus-visible/button:opacity-100 motion-safe:transition-[max-width,margin,opacity] motion-safe:duration-interactive motion-safe:ease-out-strong motion-reduce:transition-none\">{label}</span>\n </Button>;\n}\n\nexport type FilterChipProps = Omit<ActionButtonProps, 'variant' | 'scheme' | 'size' | 'shape' | 'aria-pressed'> & {\n /** Controlled selection state; onClick belongs to the caller. */\n selected?: boolean;\n /** Optional leading icon. */\n icon?: ReactNode;\n};\nexport function FilterChip({selected = false, icon, children, loading, ...props}: FilterChipProps) {\n return <Button {...props} variant=\"outline\" scheme={selected ? 'secondary' : 'neutral'} size=\"md\" shape=\"pill\" aria-pressed={selected} loading={loading} className={cn('w-max max-w-full gap-2.5 px-5 py-3 text-base leading-[1.4]', selected && 'font-semibold')}>\n {icon}{children}\n </Button>;\n}\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;AAwBA,MAAM,OAAO,GAAiC;AAC5C,IAAA,OAAO,EAAE,mOAAmO;AAC5O,IAAA,SAAS,EAAE,wSAAwS;AACnT,IAAA,OAAO,EAAE,4OAA4O;AACrP,IAAA,WAAW,EAAE,2PAA2P;AACxQ,IAAA,OAAO,EAAE,uOAAuO;CACjP;AACD,MAAM,UAAU,GAAkC;AAChD,IAAA,KAAK,EAAE,EAAE,CAAC,uOAAuO,EAAE,2BAA2B,CAAC;AAC/Q,IAAA,OAAO,EAAE,EAAE,CAAC,gJAAgJ,EAAE,2BAA2B,CAAC;AAC1L,IAAA,KAAK,EAAE,wIAAwI;AAC/I,IAAA,IAAI,EAAE,oHAAoH;CAC3H;AACD,MAAM,KAAK,GAA+B;AACxC,IAAA,EAAE,EAAE,oCAAoC;AACxC,IAAA,EAAE,EAAE,oCAAoC;AACxC,IAAA,EAAE,EAAE,qCAAqC;AACzC,IAAA,EAAE,EAAE,uCAAuC;AAC3C,IAAA,EAAE,EAAE,uCAAuC;AAC3C,IAAA,KAAK,E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