@flanksource/clicky-ui 0.2.15 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat.cjs +16 -0
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.js +17 -1
- package/dist/chat.js.map +1 -1
- package/dist/components/Combobox.cjs +34 -11
- package/dist/components/Combobox.cjs.map +1 -1
- package/dist/components/Combobox.d.ts +8 -0
- package/dist/components/Combobox.d.ts.map +1 -1
- package/dist/components/Combobox.js +34 -11
- package/dist/components/Combobox.js.map +1 -1
- package/dist/components/DateTimePicker.cjs +3 -0
- package/dist/components/DateTimePicker.cjs.map +1 -1
- package/dist/components/DateTimePicker.d.ts +6 -2
- package/dist/components/DateTimePicker.d.ts.map +1 -1
- package/dist/components/DateTimePicker.js +3 -0
- package/dist/components/DateTimePicker.js.map +1 -1
- package/dist/components/Field.cjs +33 -0
- package/dist/components/Field.cjs.map +1 -0
- package/dist/components/Field.d.ts +27 -0
- package/dist/components/Field.d.ts.map +1 -0
- package/dist/components/Field.js +33 -0
- package/dist/components/Field.js.map +1 -0
- package/dist/components/FilterBar.cjs +81 -20
- package/dist/components/FilterBar.cjs.map +1 -1
- package/dist/components/FilterBar.d.ts +30 -0
- package/dist/components/FilterBar.d.ts.map +1 -1
- package/dist/components/FilterBar.js +83 -22
- package/dist/components/FilterBar.js.map +1 -1
- package/dist/components/JsonSchemaForm.cjs +26 -3
- package/dist/components/JsonSchemaForm.cjs.map +1 -1
- package/dist/components/JsonSchemaForm.d.ts.map +1 -1
- package/dist/components/JsonSchemaForm.js +26 -3
- package/dist/components/JsonSchemaForm.js.map +1 -1
- package/dist/components/MultiSelect.cjs +2 -1
- package/dist/components/MultiSelect.cjs.map +1 -1
- package/dist/components/MultiSelect.d.ts +5 -1
- package/dist/components/MultiSelect.d.ts.map +1 -1
- package/dist/components/MultiSelect.js +2 -1
- package/dist/components/MultiSelect.js.map +1 -1
- package/dist/components/json-schema-form-fields.cjs +15 -8
- package/dist/components/json-schema-form-fields.cjs.map +1 -1
- package/dist/components/json-schema-form-fields.d.ts.map +1 -1
- package/dist/components/json-schema-form-fields.js +15 -8
- package/dist/components/json-schema-form-fields.js.map +1 -1
- package/dist/components/json-schema-form-preferences.cjs +4 -0
- package/dist/components/json-schema-form-preferences.cjs.map +1 -1
- package/dist/components/json-schema-form-preferences.d.ts +2 -0
- package/dist/components/json-schema-form-preferences.d.ts.map +1 -1
- package/dist/components/json-schema-form-preferences.js +4 -0
- package/dist/components/json-schema-form-preferences.js.map +1 -1
- package/dist/components/json-schema-form-render.cjs +1 -1
- package/dist/components/json-schema-form-render.cjs.map +1 -1
- package/dist/components/json-schema-form-render.d.ts.map +1 -1
- package/dist/components/json-schema-form-render.js +2 -2
- package/dist/components/json-schema-form-render.js.map +1 -1
- package/dist/components/json-schema-form-types.d.ts +4 -2
- package/dist/components/json-schema-form-types.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.cjs +13 -0
- package/dist/components/json-schema-form-utils.cjs.map +1 -1
- package/dist/components/json-schema-form-utils.d.ts +2 -0
- package/dist/components/json-schema-form-utils.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.js +13 -0
- package/dist/components/json-schema-form-utils.js.map +1 -1
- package/dist/components/loading.cjs +21 -8
- package/dist/components/loading.cjs.map +1 -1
- package/dist/components/loading.d.ts +6 -4
- package/dist/components/loading.d.ts.map +1 -1
- package/dist/components/loading.js +21 -8
- package/dist/components/loading.js.map +1 -1
- package/dist/components/use-form.cjs +27 -0
- package/dist/components/use-form.cjs.map +1 -0
- package/dist/components/use-form.d.ts +30 -0
- package/dist/components/use-form.d.ts.map +1 -0
- package/dist/components/use-form.js +27 -0
- package/dist/components/use-form.js.map +1 -0
- package/dist/components.cjs +7 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.ts +4 -1
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +8 -1
- package/dist/components.js.map +1 -1
- package/dist/data/Markdown.cjs +14 -40
- package/dist/data/Markdown.cjs.map +1 -1
- package/dist/data/Markdown.d.ts +3 -0
- package/dist/data/Markdown.d.ts.map +1 -1
- package/dist/data/Markdown.js +14 -40
- package/dist/data/Markdown.js.map +1 -1
- package/dist/data/TaskProgress.cjs +22 -0
- package/dist/data/TaskProgress.cjs.map +1 -1
- package/dist/data/TaskProgress.js +22 -0
- package/dist/data/TaskProgress.js.map +1 -1
- package/dist/data/TaskSnapshot.cjs.map +1 -1
- package/dist/data/TaskSnapshot.d.ts +5 -0
- package/dist/data/TaskSnapshot.d.ts.map +1 -1
- package/dist/data/TaskSnapshot.js.map +1 -1
- package/dist/data/Tree.cjs +32 -1
- package/dist/data/Tree.cjs.map +1 -1
- package/dist/data/Tree.d.ts +9 -1
- package/dist/data/Tree.d.ts.map +1 -1
- package/dist/data/Tree.js +32 -1
- package/dist/data/Tree.js.map +1 -1
- package/dist/data/chat/Attachment.cjs +79 -0
- package/dist/data/chat/Attachment.cjs.map +1 -0
- package/dist/data/chat/Attachment.d.ts +18 -0
- package/dist/data/chat/Attachment.d.ts.map +1 -0
- package/dist/data/chat/Attachment.js +79 -0
- package/dist/data/chat/Attachment.js.map +1 -0
- package/dist/data/chat/Chat.cjs +71 -14
- package/dist/data/chat/Chat.cjs.map +1 -1
- package/dist/data/chat/Chat.d.ts +30 -12
- package/dist/data/chat/Chat.d.ts.map +1 -1
- package/dist/data/chat/Chat.fixtures.d.ts +9 -0
- package/dist/data/chat/Chat.fixtures.d.ts.map +1 -1
- package/dist/data/chat/Chat.js +73 -16
- package/dist/data/chat/Chat.js.map +1 -1
- package/dist/data/chat/Conversation.cjs +32 -14
- package/dist/data/chat/Conversation.cjs.map +1 -1
- package/dist/data/chat/Conversation.d.ts +5 -3
- package/dist/data/chat/Conversation.d.ts.map +1 -1
- package/dist/data/chat/Conversation.js +34 -16
- package/dist/data/chat/Conversation.js.map +1 -1
- package/dist/data/chat/Message.cjs +73 -14
- package/dist/data/chat/Message.cjs.map +1 -1
- package/dist/data/chat/Message.d.ts +11 -4
- package/dist/data/chat/Message.d.ts.map +1 -1
- package/dist/data/chat/Message.js +75 -16
- package/dist/data/chat/Message.js.map +1 -1
- package/dist/data/chat/MessageActions.cjs +54 -0
- package/dist/data/chat/MessageActions.cjs.map +1 -0
- package/dist/data/chat/MessageActions.d.ts +11 -0
- package/dist/data/chat/MessageActions.d.ts.map +1 -0
- package/dist/data/chat/MessageActions.js +54 -0
- package/dist/data/chat/MessageActions.js.map +1 -0
- package/dist/data/chat/ModelSelector.cjs +43 -0
- package/dist/data/chat/ModelSelector.cjs.map +1 -0
- package/dist/data/chat/ModelSelector.d.ts +22 -0
- package/dist/data/chat/ModelSelector.d.ts.map +1 -0
- package/dist/data/chat/ModelSelector.js +43 -0
- package/dist/data/chat/ModelSelector.js.map +1 -0
- package/dist/data/chat/PromptInput.cjs +28 -15
- package/dist/data/chat/PromptInput.cjs.map +1 -1
- package/dist/data/chat/PromptInput.d.ts +14 -8
- package/dist/data/chat/PromptInput.d.ts.map +1 -1
- package/dist/data/chat/PromptInput.js +28 -15
- package/dist/data/chat/PromptInput.js.map +1 -1
- package/dist/data/chat/Reasoning.cjs +37 -0
- package/dist/data/chat/Reasoning.cjs.map +1 -0
- package/dist/data/chat/Reasoning.d.ts +11 -0
- package/dist/data/chat/Reasoning.d.ts.map +1 -0
- package/dist/data/chat/Reasoning.js +37 -0
- package/dist/data/chat/Reasoning.js.map +1 -0
- package/dist/data/chat/Suggestion.cjs +20 -0
- package/dist/data/chat/Suggestion.cjs.map +1 -0
- package/dist/data/chat/Suggestion.d.ts +10 -0
- package/dist/data/chat/Suggestion.d.ts.map +1 -0
- package/dist/data/chat/Suggestion.js +20 -0
- package/dist/data/chat/Suggestion.js.map +1 -0
- package/dist/data/chat/ToolCall.cjs +26 -3
- package/dist/data/chat/ToolCall.cjs.map +1 -1
- package/dist/data/chat/ToolCall.d.ts +5 -1
- package/dist/data/chat/ToolCall.d.ts.map +1 -1
- package/dist/data/chat/ToolCall.js +26 -3
- package/dist/data/chat/ToolCall.js.map +1 -1
- package/dist/data/chat/index.d.ts +7 -2
- package/dist/data/chat/index.d.ts.map +1 -1
- package/dist/data/chat/types.cjs +16 -0
- package/dist/data/chat/types.cjs.map +1 -1
- package/dist/data/chat/types.d.ts +29 -2
- package/dist/data/chat/types.d.ts.map +1 -1
- package/dist/data/chat/types.js +16 -0
- package/dist/data/chat/types.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/hooks/use-task-run.cjs +33 -20
- package/dist/hooks/use-task-run.cjs.map +1 -1
- package/dist/hooks/use-task-run.d.ts.map +1 -1
- package/dist/hooks/use-task-run.js +33 -20
- package/dist/hooks/use-task-run.js.map +1 -1
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/overlay/Modal.cjs +27 -23
- package/dist/overlay/Modal.cjs.map +1 -1
- package/dist/overlay/Modal.d.ts +7 -1
- package/dist/overlay/Modal.d.ts.map +1 -1
- package/dist/overlay/Modal.js +27 -23
- package/dist/overlay/Modal.js.map +1 -1
- package/dist/rpc/FilterForm.cjs +4 -4
- package/dist/rpc/FilterForm.cjs.map +1 -1
- package/dist/rpc/FilterForm.js +4 -4
- package/dist/rpc/FilterForm.js.map +1 -1
- package/dist/rpc/OperationCatalog.cjs +17 -21
- package/dist/rpc/OperationCatalog.cjs.map +1 -1
- package/dist/rpc/OperationCatalog.d.ts +3 -3
- package/dist/rpc/OperationCatalog.d.ts.map +1 -1
- package/dist/rpc/OperationCatalog.js +18 -22
- package/dist/rpc/OperationCatalog.js.map +1 -1
- package/dist/rpc/formMetadata.cjs +5 -3
- package/dist/rpc/formMetadata.cjs.map +1 -1
- package/dist/rpc/formMetadata.d.ts.map +1 -1
- package/dist/rpc/formMetadata.js +5 -3
- package/dist/rpc/formMetadata.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","sources":["../../src/components/Combobox.tsx"],"sourcesContent":["import {\n Fragment,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { cn } from \"../lib/utils\";\nimport { Icon, LabelIcon, type LabelIconSpec } from \"../data/Icon\";\nimport { UiChevronDown, UiClose, UiCheck } from \"../icons\";\nimport { inputSizeClass, type FormSize } from \"./json-schema-form-size\";\n\n// Upper bound the open dropdown grows to in order to show full option labels\n// before they truncate. The menu's minimum is always the input's width.\nconst MENU_MAX_WIDTH_PX = 400;\n\nexport type ComboboxOption = {\n value: string;\n label: string;\n disabled?: boolean;\n /** Leading glyph for the option: a runtime icon name or a rendered node. */\n icon?: LabelIconSpec;\n /**\n * Optional section label. A non-interactive header renders above the first\n * option of each group (options are grouped by contiguous `group` value in\n * the order provided). Options without a `group` render no header.\n */\n group?: string;\n};\n\ntype ComboboxBaseProps = {\n /** Available options, rendered in the order provided. */\n options: ComboboxOption[];\n /** Ghost text when no value is set. */\n placeholder?: string;\n /** Optional label rendered inline inside the control, before the input. */\n label?: ReactNode;\n /** Disables the input. */\n disabled?: boolean;\n /** When true, the value cannot be cleared (the clear button is hidden). */\n required?: boolean;\n /**\n * Marks the control as invalid: renders a destructive border and sets\n * aria-invalid. Purely presentational — the consumer decides what invalid\n * means (e.g. a value absent from the options in a strict picker).\n */\n invalid?: boolean;\n /**\n * When false, the value is restricted to the provided options — typed text\n * that does not match an option is discarded instead of committed. Defaults\n * to true (freeform entry allowed).\n */\n allowCustomValue?: boolean;\n /** HTML id for the input element. */\n id?: string;\n /**\n * Overrides the input's height/padding/text size with an explicit size token\n * (xs–xl). When unset, the input uses the global density tokens.\n */\n size?: FormSize;\n /** Classes applied to the root wrapper. */\n className?: string;\n /** Shows a loading indicator when options are being fetched. */\n loading?: boolean;\n /**\n * Optional async search invoked (debounced ~250ms) as the user types. The\n * consumer fetches and feeds matching options back via the `options` prop\n * (setting `loading` while in flight). When set, the component renders the\n * provided `options` as-is instead of filtering them client-side — the\n * server has already filtered. When absent, typing filters `options`\n * client-side as before.\n */\n onSearch?: (query: string) => void;\n /** Called when a key is pressed in the input. */\n onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;\n /** Trailing in-field adornment, rendered left of the clear/chevron controls. */\n suffix?: ReactNode;\n};\n\nexport type ComboboxSingleProps = ComboboxBaseProps & {\n multiple?: false;\n /** Controlled selected value. */\n value: string;\n /** Called when the selected value changes (from list or freeform input). */\n onChange: (value: string) => void;\n};\n\nexport type ComboboxMultiProps = ComboboxBaseProps & {\n multiple: true;\n /** Controlled selected values. */\n value: string[];\n /** Called with the complete next value array after each toggle. */\n onChange: (value: string[]) => void;\n};\n\nexport type ComboboxProps = ComboboxSingleProps | ComboboxMultiProps;\n\nexport function Combobox(props: ComboboxProps) {\n const {\n options,\n placeholder,\n label,\n disabled,\n required,\n invalid,\n allowCustomValue = true,\n id,\n size,\n className,\n loading,\n onSearch,\n onKeyDown: onKeyDownProp,\n suffix,\n } = props;\n const multiple = props.multiple === true;\n const selectedValues = useMemo<string[]>(\n () => (multiple ? props.value : props.value ? [props.value] : []),\n [multiple, props.value],\n );\n\n const rootRef = useRef<HTMLDivElement>(null);\n const anchorRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n const [open, setOpen] = useState(false);\n // Fixed-position coordinates for the portaled listbox, measured from the\n // input row. `width` is the input width (the menu's minimum); `maxWidth` caps\n // content growth at 400px, further bounded by the viewport. Null until first\n // measured so we never render at (0,0).\n const [menuPos, setMenuPos] = useState<{\n top: number;\n left: number;\n width: number;\n maxWidth: number;\n } | null>(null);\n // `query` is the type-ahead filter text, kept separate from the committed\n // value. It is empty unless the user is actively typing, so opening the\n // dropdown shows every option rather than only the selected one.\n const [query, setQuery] = useState(\"\");\n const [highlighted, setHighlighted] = useState(-1);\n\n const isSelected = (optValue: string) => selectedValues.includes(optValue);\n\n // Closed-state input text. Single: the selected option's label (or its raw\n // value as a fallback). Multi: a summary mirroring MultiSelect.\n const closedLabel = useMemo(() => {\n if (multiple) {\n const labels = options\n .filter((o) => selectedValues.includes(o.value))\n .map((o) => o.label);\n if (labels.length === 0) return \"\";\n if (labels.length <= 2) return labels.join(\", \");\n return `${labels.length} selected`;\n }\n const single = selectedValues[0] ?? \"\";\n return options.find((o) => o.value === single)?.label ?? single;\n }, [multiple, options, selectedValues]);\n\n // While open the input mirrors the query; while closed it shows the\n // committed selection's label/summary.\n const displayValue = open ? query : closedLabel;\n\n const filtered = useMemo(() => {\n // With onSearch the server already filtered. The matches replace the list,\n // but any already-selected value not in the matches is pinned so the user's\n // selection stays visible and toggleable. Selected values carry no label\n // object here, so synthesize {value, label: value} (the typeahead's value is\n // its own human label).\n if (onSearch) return withSelectedOptions(options, selectedValues);\n const q = query.toLowerCase().trim();\n if (!q) return options;\n return options.filter(\n (o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q),\n );\n }, [onSearch, options, query, selectedValues]);\n\n // Debounced server-side search: fires onSearch ~250ms after the query settles\n // while the menu is open. The empty-query call lets the consumer reset its\n // result set. Only active when onSearch is provided.\n useEffect(() => {\n if (!onSearch || !open) return;\n const handle = setTimeout(() => onSearch(query.trim()), 250);\n return () => clearTimeout(handle);\n }, [onSearch, open, query]);\n\n useEffect(() => {\n setHighlighted(-1);\n }, [filtered.length]);\n\n useEffect(() => {\n if (!open) return;\n const onPointerDown = (e: MouseEvent) => {\n const target = e.target as Node;\n // The listbox is portaled out of rootRef, so a click inside it would\n // otherwise read as \"outside\" and close the menu before selection.\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n commitAndClose();\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n });\n\n // Position the portaled listbox with fixed coordinates measured from the\n // input row, so it escapes any overflow-hidden / scroll ancestor (e.g. a\n // Modal body) that would otherwise clip it. Mirrors HoverCard's approach.\n useLayoutEffect(() => {\n if (!open) {\n setMenuPos(null);\n return;\n }\n const update = () => {\n const anchor = anchorRef.current;\n if (!anchor) return;\n const rect = anchor.getBoundingClientRect();\n // The menu may grow rightward up to 400px, but not past the viewport edge\n // (leaving an 8px gutter). Never let the cap fall below the input width.\n const viewportCap = window.innerWidth - rect.left - 8;\n const maxWidth = Math.max(rect.width, Math.min(MENU_MAX_WIDTH_PX, viewportCap));\n setMenuPos({ top: rect.bottom + 4, left: rect.left, width: rect.width, maxWidth });\n };\n update();\n window.addEventListener(\"scroll\", update, true);\n window.addEventListener(\"resize\", update);\n return () => {\n window.removeEventListener(\"scroll\", update, true);\n window.removeEventListener(\"resize\", update);\n };\n }, [open]);\n\n function emit(next: string[]) {\n if (multiple) {\n props.onChange(next);\n } else {\n props.onChange(next[0] ?? \"\");\n }\n }\n\n function openMenu() {\n setQuery(\"\");\n setHighlighted(-1);\n setOpen(true);\n }\n\n function commitAndClose() {\n // Freeform commit (single, allowCustomValue only): a non-empty query that\n // doesn't match an option becomes the value. An empty query keeps the\n // existing selection. Multi and strict modes never commit freeform text.\n const trimmed = query.trim();\n if (!multiple && allowCustomValue && trimmed && trimmed !== selectedValues[0]) {\n emit([trimmed]);\n }\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n }\n\n function selectOption(opt: ComboboxOption) {\n if (multiple) {\n const next = isSelected(opt.value)\n ? selectedValues.filter((v) => v !== opt.value)\n : [...selectedValues, opt.value];\n emit(next);\n setQuery(\"\");\n setHighlighted(-1);\n inputRef.current?.focus();\n return;\n }\n emit([opt.value]);\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n inputRef.current?.focus();\n }\n\n function clear() {\n if (selectedValues.length > 0) emit([]);\n setQuery(\"\");\n setHighlighted(-1);\n inputRef.current?.focus();\n }\n\n function scrollToHighlighted(index: number) {\n const list = listRef.current;\n if (!list) return;\n // Query option rows by role rather than child index — interleaved group\n // header rows are direct children too, so children[index] would be offset.\n const item = list.querySelectorAll<HTMLElement>('[role=\"option\"]')[index];\n item?.scrollIntoView({ block: \"nearest\" });\n }\n\n function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n if (!open) {\n openMenu();\n return;\n }\n const next = highlighted < filtered.length - 1 ? highlighted + 1 : 0;\n setHighlighted(next);\n scrollToHighlighted(next);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n if (!open) return;\n const next = highlighted > 0 ? highlighted - 1 : filtered.length - 1;\n setHighlighted(next);\n scrollToHighlighted(next);\n } else if (e.key === \"Enter\") {\n if (open && highlighted >= 0 && filtered[highlighted] && !filtered[highlighted].disabled) {\n e.preventDefault();\n selectOption(filtered[highlighted]);\n return;\n }\n commitAndClose();\n onKeyDownProp?.(e);\n } else if (e.key === \"Escape\") {\n if (open) {\n e.preventDefault();\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n }\n } else {\n onKeyDownProp?.(e);\n }\n }\n\n const listId = id ? `${id}-listbox` : undefined;\n const ariaLabel = typeof label === \"string\" ? label : undefined;\n const showClear = !required && !loading && !disabled && selectedValues.length > 0;\n\n return (\n <div ref={rootRef} className={cn(\"relative\", className)}>\n <div ref={anchorRef} data-jsf-control className=\"relative flex items-center\">\n {label != null && (\n <span className=\"pointer-events-none absolute left-2 z-10 whitespace-nowrap font-medium uppercase tracking-wide text-muted-foreground text-[10px]\">\n {label}\n </span>\n )}\n <input\n ref={inputRef}\n id={id}\n type=\"text\"\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={listId}\n aria-activedescendant={highlighted >= 0 ? `${listId}-${highlighted}` : undefined}\n aria-label={ariaLabel}\n aria-invalid={invalid || undefined}\n autoComplete=\"off\"\n disabled={disabled}\n placeholder={placeholder}\n value={displayValue}\n onChange={(e) => {\n setQuery(e.target.value);\n if (!open) setOpen(true);\n }}\n onFocus={openMenu}\n onKeyDown={onKeyDown}\n className={cn(\n \"w-full rounded-md border border-input bg-background text-foreground\",\n size ? inputSizeClass[size] : \"h-control-h px-control-px text-sm\",\n suffix ? (showClear ? \"pr-[5.5rem]\" : \"pr-14\") : showClear ? \"pr-14\" : \"pr-8\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n invalid && \"border-destructive focus-visible:ring-destructive\",\n )}\n style={label != null ? labelPadding(label) : undefined}\n />\n {suffix && (\n <div className={cn(\"absolute flex h-full items-center\", showClear ? \"right-[3.75rem]\" : \"right-7\")}>\n {suffix}\n </div>\n )}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onClick={clear}\n className=\"absolute right-7 flex h-full items-center px-1 text-muted-foreground hover:text-foreground\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n {loading ? (\n <span className=\"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2\">\n <svg className=\"h-3.5 w-3.5 animate-spin text-muted-foreground\" viewBox=\"0 0 16 16\" fill=\"none\">\n <circle cx=\"8\" cy=\"8\" r=\"6.5\" stroke=\"currentColor\" strokeWidth=\"2\" opacity=\"0.25\" />\n <path d=\"M14.5 8a6.5 6.5 0 0 0-6.5-6.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n </span>\n ) : (\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={disabled}\n aria-label=\"Toggle options\"\n onClick={() => {\n if (open) {\n commitAndClose();\n } else {\n openMenu();\n inputRef.current?.focus();\n }\n }}\n className=\"pointer-events-auto absolute right-0 flex h-full items-center px-2 text-muted-foreground\"\n >\n <Icon icon={UiChevronDown} className=\"text-xs\" />\n </button>\n )}\n </div>\n {open && menuPos && typeof document !== \"undefined\" &&\n createPortal(\n <div\n id={listId}\n ref={listRef}\n role=\"listbox\"\n aria-multiselectable={multiple || undefined}\n style={{\n position: \"fixed\",\n top: menuPos.top,\n left: menuPos.left,\n // Grow to fit the widest option, but never narrower than the input\n // nor wider than 400px (beyond which option labels truncate). The\n // cap is also bounded by the viewport so the menu can't overflow.\n minWidth: menuPos.width,\n maxWidth: menuPos.maxWidth,\n }}\n className=\"z-[9999] max-h-64 w-max overflow-auto rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg shadow-black/5\"\n >\n {loading && filtered.length === 0 && (\n <div className=\"px-2 py-4 text-center text-sm text-muted-foreground\">Loading…</div>\n )}\n {!loading && filtered.length === 0 && (\n <div className=\"px-2 py-4 text-center text-sm text-muted-foreground\">No results</div>\n )}\n {filtered.map((opt, i) => {\n const selected = isSelected(opt.value);\n // A header renders above the first option of each group. Derived\n // from the surviving (filtered) options, so an empty group emits no\n // header. The option keeps `i` (its index in `filtered`) for\n // id/highlight/select — headers are role=\"presentation\", never\n // counted in the highlight/scroll index.\n const showHeader = opt.group != null && opt.group !== filtered[i - 1]?.group;\n return (\n <Fragment key={opt.value}>\n {showHeader && (\n <div\n role=\"presentation\"\n className=\"select-none px-2 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\"\n >\n {opt.group}\n </div>\n )}\n <div\n id={listId ? `${listId}-${i}` : undefined}\n role=\"option\"\n aria-selected={selected}\n aria-disabled={opt.disabled}\n onMouseDown={(e) => {\n e.preventDefault();\n if (!opt.disabled) selectOption(opt);\n }}\n onMouseEnter={() => setHighlighted(i)}\n className={cn(\n \"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm\",\n i === highlighted && \"bg-accent\",\n selected && \"font-medium\",\n opt.disabled && \"cursor-not-allowed opacity-50\",\n )}\n >\n <Icon\n icon={UiCheck}\n className={cn(\"text-xs shrink-0\", selected ? \"opacity-100\" : \"opacity-0\")}\n />\n <LabelIcon icon={opt.icon} className=\"text-sm text-muted-foreground\" />\n <span className=\"min-w-0 truncate\">{opt.label}</span>\n </div>\n </Fragment>\n );\n })}\n </div>,\n document.body,\n )}\n </div>\n );\n}\n\n// Reserve room on the left of the input for the inline label so typed text\n// does not overlap it. Roughly 0.6rem per character plus padding.\nfunction labelPadding(label: ReactNode) {\n const length = typeof label === \"string\" ? label.length : 6;\n return { paddingLeft: `${Math.min(length * 0.62 + 0.75, 9)}rem` };\n}\n\n// withSelectedOptions returns the option list plus any selected value that isn't\n// already present, synthesized as {value, label: value}. Used by the server\n// (onSearch) typeahead so an already-selected value missing from the current\n// matches still renders as a checked row. Selected-but-absent values come first\n// so they don't get scrolled past by a long match list.\nfunction withSelectedOptions(\n options: ComboboxOption[],\n selectedValues: string[],\n): ComboboxOption[] {\n const present = new Set(options.map((o) => o.value));\n const pinned = selectedValues\n .filter((v) => !present.has(v))\n .map((v) => ({ value: v, label: v }));\n return pinned.length === 0 ? options : [...pinned, ...options];\n}\n"],"names":[],"mappings":";;;;;;;;;AAkBA,MAAM,oBAAoB;AAmFnB,SAAS,SAAS,OAAsB;AAC7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,EAAA,IACE;AACJ,QAAM,WAAW,MAAM,aAAa;AACpC,QAAM,iBAAiB;AAAA,IACrB,MAAO,WAAW,MAAM,QAAQ,MAAM,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAA;AAAA,IAC9D,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAGxB,QAAM,UAAU,OAAuB,IAAI;AAC3C,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,UAAU,OAAuB,IAAI;AAC3C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AAKtC,QAAM,CAAC,SAAS,UAAU,IAAI,SAKpB,IAAI;AAId,QAA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ACA,MAAM,eAAe;AAAA,sBACrB,YAAY;AAAA,sBACZ,IAAI,YAAY;AAAA,oBAAA;AAAA,oBAGlB,UAAA;AAAA,sBAAA;AAAA,wBAAC;AAAA,wBAAA;AAAA,0BACC,MAAM;AAAA,0BACN,WAAW,GAAG,oBAAoB,WAAW,gBAAgB,WAAW;AAAA,wBAAA;AAAA,sBAAA;AAAA,0CAEzE,WAAA,EAAU,MAAM,IAAI,MAAM,WAAU,iCAAgC;AAAA,sBACrE,oBAAC,QAAA,EAAK,WAAU,oBAAoB,cAAI,MAAA,CAAM;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAAA;AAAA,cAChD,EAAA,GAhCa,IAAI,KAiCnB;AAAA,YAEJ,CAAC;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,MAED,SAAS;AAAA,IAAA;AAAA,EACX,GACJ;AAEJ;AAIA,SAAS,aAAa,OAAkB;AACtC,QAAM,SAAS,OAAO,UAAU,WAAW,MAAM,SAAS;AAC1D,SAAO,EAAE,aAAa,GAAG,KAAK,IAAI,SAAS,OAAO,MAAM,CAAC,CAAC,MAAA;AAC5D;AAOA,SAAS,oBACP,SACA,gBACkB;AAClB,QAAM,UAAU,IAAI,IAAI,QAAQ,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AACnD,QAAM,SAAS,eACZ,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,EAC7B,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;AACtC,SAAO,OAAO,WAAW,IAAI,UAAU,CAAC,GAAG,QAAQ,GAAG,OAAO;AAC/D;"}
|
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../src/components/Combobox.tsx"],"sourcesContent":["import {\n Fragment,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type KeyboardEvent,\n type ReactNode,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { cn } from \"../lib/utils\";\nimport { Icon, LabelIcon, type LabelIconSpec } from \"../data/Icon\";\nimport { UiChevronDown, UiClose, UiCheck } from \"../icons\";\nimport { inputSizeClass, type FormSize } from \"./json-schema-form-size\";\n\n// Upper bound the open dropdown grows to in order to show full option labels\n// before they truncate. The menu's minimum is always the input's width.\nconst MENU_MAX_WIDTH_PX = 400;\n\n// Matches the menu's `max-h-64` (16rem) cap; also the threshold below which the\n// menu flips above the input instead of opening downward off-screen.\nconst MENU_MAX_HEIGHT_PX = 256;\n\nexport type ComboboxOption = {\n value: string;\n label: string;\n disabled?: boolean;\n /** Leading glyph for the option: a runtime icon name or a rendered node. */\n icon?: LabelIconSpec;\n /**\n * Optional section label. A non-interactive header renders above the first\n * option of each group (options are grouped by contiguous `group` value in\n * the order provided). Options without a `group` render no header.\n */\n group?: string;\n};\n\ntype ComboboxBaseProps = {\n /** Available options, rendered in the order provided. */\n options: ComboboxOption[];\n /** Ghost text when no value is set. */\n placeholder?: string;\n /** Optional label rendered inline inside the control, before the input. */\n label?: ReactNode;\n /**\n * Accessible name for the input. Use when `label` is a non-string node (e.g.\n * an icon) so the control still has a text name for screen readers; defaults\n * to `label` when it is a string.\n */\n ariaLabel?: string;\n /** Disables the input. */\n disabled?: boolean;\n /** When true, the value cannot be cleared (the clear button is hidden). */\n required?: boolean;\n /**\n * Marks the control as invalid: renders a destructive border and sets\n * aria-invalid. Purely presentational — the consumer decides what invalid\n * means (e.g. a value absent from the options in a strict picker).\n */\n invalid?: boolean;\n /**\n * When false, the value is restricted to the provided options — typed text\n * that does not match an option is discarded instead of committed. Defaults\n * to true (freeform entry allowed).\n */\n allowCustomValue?: boolean;\n /** HTML id for the input element. */\n id?: string;\n /**\n * Overrides the input's height/padding/text size with an explicit size token\n * (xs–xl). When unset, the input uses the global density tokens.\n */\n size?: FormSize;\n /** Classes applied to the root wrapper. */\n className?: string;\n /** Shows a loading indicator when options are being fetched. */\n loading?: boolean;\n /**\n * Optional async search invoked (debounced ~250ms) as the user types. The\n * consumer fetches and feeds matching options back via the `options` prop\n * (setting `loading` while in flight). When set, the component renders the\n * provided `options` as-is instead of filtering them client-side — the\n * server has already filtered. When absent, typing filters `options`\n * client-side as before.\n */\n onSearch?: (query: string) => void;\n /** Called when a key is pressed in the input. */\n onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;\n /** Trailing in-field adornment, rendered left of the clear/chevron controls. */\n suffix?: ReactNode;\n /** Leading in-field adornment, rendered at the left edge of the input. */\n prefix?: ReactNode;\n};\n\nexport type ComboboxSingleProps = ComboboxBaseProps & {\n multiple?: false;\n /** Controlled selected value. */\n value: string;\n /** Called when the selected value changes (from list or freeform input). */\n onChange: (value: string) => void;\n};\n\nexport type ComboboxMultiProps = ComboboxBaseProps & {\n multiple: true;\n /** Controlled selected values. */\n value: string[];\n /** Called with the complete next value array after each toggle. */\n onChange: (value: string[]) => void;\n};\n\nexport type ComboboxProps = ComboboxSingleProps | ComboboxMultiProps;\n\nexport function Combobox(props: ComboboxProps) {\n const {\n options,\n placeholder,\n label,\n ariaLabel: ariaLabelProp,\n disabled,\n required,\n invalid,\n allowCustomValue = true,\n id,\n size,\n className,\n loading,\n onSearch,\n onKeyDown: onKeyDownProp,\n suffix,\n prefix,\n } = props;\n const multiple = props.multiple === true;\n const selectedValues = useMemo<string[]>(\n () => (multiple ? props.value : props.value ? [props.value] : []),\n [multiple, props.value],\n );\n\n const rootRef = useRef<HTMLDivElement>(null);\n const anchorRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n const [open, setOpen] = useState(false);\n // Fixed-position coordinates for the portaled listbox, measured from the\n // input row. `width` is the input width (the menu's minimum); `maxWidth` caps\n // content growth at 400px, further bounded by the viewport. Null until first\n // measured so we never render at (0,0).\n // Either `top` (opening downward) or `bottom` (flipped upward when space below\n // is tight, e.g. a control docked near the viewport bottom) is set, never both.\n const [menuPos, setMenuPos] = useState<{\n top?: number;\n bottom?: number;\n left: number;\n width: number;\n maxWidth: number;\n maxHeight: number;\n } | null>(null);\n // `query` is the type-ahead filter text, kept separate from the committed\n // value. It is empty unless the user is actively typing, so opening the\n // dropdown shows every option rather than only the selected one.\n const [query, setQuery] = useState(\"\");\n const [highlighted, setHighlighted] = useState(-1);\n\n const isSelected = (optValue: string) => selectedValues.includes(optValue);\n\n // Closed-state input text. Single: the selected option's label (or its raw\n // value as a fallback). Multi: a summary mirroring MultiSelect.\n const closedLabel = useMemo(() => {\n if (multiple) {\n const labels = options\n .filter((o) => selectedValues.includes(o.value))\n .map((o) => o.label);\n if (labels.length === 0) return \"\";\n if (labels.length <= 2) return labels.join(\", \");\n return `${labels.length} selected`;\n }\n const single = selectedValues[0] ?? \"\";\n return options.find((o) => o.value === single)?.label ?? single;\n }, [multiple, options, selectedValues]);\n\n // While open the input mirrors the query; while closed it shows the\n // committed selection's label/summary.\n const displayValue = open ? query : closedLabel;\n\n const filtered = useMemo(() => {\n // With onSearch the server already filtered. The matches replace the list,\n // but any already-selected value not in the matches is pinned so the user's\n // selection stays visible and toggleable. Selected values carry no label\n // object here, so synthesize {value, label: value} (the typeahead's value is\n // its own human label).\n if (onSearch) return withSelectedOptions(options, selectedValues);\n const q = query.toLowerCase().trim();\n if (!q) return options;\n return options.filter(\n (o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q),\n );\n }, [onSearch, options, query, selectedValues]);\n\n // Debounced server-side search: fires onSearch ~250ms after the query settles\n // while the menu is open. The empty-query call lets the consumer reset its\n // result set. Only active when onSearch is provided.\n useEffect(() => {\n if (!onSearch || !open) return;\n const handle = setTimeout(() => onSearch(query.trim()), 250);\n return () => clearTimeout(handle);\n }, [onSearch, open, query]);\n\n useEffect(() => {\n setHighlighted(-1);\n }, [filtered.length]);\n\n useEffect(() => {\n if (!open) return;\n // Dismiss when the pointer goes down, OR focus moves, anywhere outside the\n // control and its portaled listbox — so clicking elsewhere in a dialog (the\n // backdrop never intercepts a document-level listener) or tabbing to another\n // field both close the menu. The listbox is portaled out of rootRef, so a\n // click inside it would otherwise read as \"outside\" and close before select.\n const onAway = (e: Event) => {\n const target = e.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) {\n commitAndClose();\n }\n };\n document.addEventListener(\"mousedown\", onAway);\n document.addEventListener(\"focusin\", onAway);\n return () => {\n document.removeEventListener(\"mousedown\", onAway);\n document.removeEventListener(\"focusin\", onAway);\n };\n });\n\n // Position the portaled listbox with fixed coordinates measured from the\n // input row, so it escapes any overflow-hidden / scroll ancestor (e.g. a\n // Modal body) that would otherwise clip it. Mirrors HoverCard's approach.\n useLayoutEffect(() => {\n if (!open) {\n setMenuPos(null);\n return;\n }\n const update = () => {\n const anchor = anchorRef.current;\n if (!anchor) return;\n const rect = anchor.getBoundingClientRect();\n // The menu may grow rightward up to 400px, but not past the viewport edge\n // (leaving an 8px gutter). Never let the cap fall below the input width.\n const viewportCap = window.innerWidth - rect.left - 8;\n const maxWidth = Math.max(rect.width, Math.min(MENU_MAX_WIDTH_PX, viewportCap));\n // Flip upward when there isn't room below for the menu but there is above\n // (the input is docked near the viewport bottom). The available side bounds\n // the menu height so it never runs off-screen.\n const spaceBelow = window.innerHeight - rect.bottom - 8;\n const spaceAbove = rect.top - 8;\n const openUp = spaceBelow < MENU_MAX_HEIGHT_PX && spaceAbove > spaceBelow;\n const maxHeight = Math.min(MENU_MAX_HEIGHT_PX, openUp ? spaceAbove : spaceBelow);\n setMenuPos({\n ...(openUp\n ? { bottom: window.innerHeight - rect.top + 4 }\n : { top: rect.bottom + 4 }),\n left: rect.left,\n width: rect.width,\n maxWidth,\n maxHeight,\n });\n };\n update();\n window.addEventListener(\"scroll\", update, true);\n window.addEventListener(\"resize\", update);\n return () => {\n window.removeEventListener(\"scroll\", update, true);\n window.removeEventListener(\"resize\", update);\n };\n }, [open]);\n\n function emit(next: string[]) {\n if (multiple) {\n props.onChange(next);\n } else {\n props.onChange(next[0] ?? \"\");\n }\n }\n\n function openMenu() {\n setQuery(\"\");\n setHighlighted(-1);\n setOpen(true);\n }\n\n function commitAndClose() {\n // Freeform commit (single, allowCustomValue only): a non-empty query that\n // doesn't match an option becomes the value. An empty query keeps the\n // existing selection. Multi and strict modes never commit freeform text.\n const trimmed = query.trim();\n if (!multiple && allowCustomValue && trimmed && trimmed !== selectedValues[0]) {\n emit([trimmed]);\n }\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n }\n\n function selectOption(opt: ComboboxOption) {\n if (multiple) {\n const next = isSelected(opt.value)\n ? selectedValues.filter((v) => v !== opt.value)\n : [...selectedValues, opt.value];\n emit(next);\n setQuery(\"\");\n setHighlighted(-1);\n inputRef.current?.focus();\n return;\n }\n emit([opt.value]);\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n inputRef.current?.focus();\n }\n\n function clear() {\n if (selectedValues.length > 0) emit([]);\n setQuery(\"\");\n setHighlighted(-1);\n inputRef.current?.focus();\n }\n\n function scrollToHighlighted(index: number) {\n const list = listRef.current;\n if (!list) return;\n // Query option rows by role rather than child index — interleaved group\n // header rows are direct children too, so children[index] would be offset.\n const item = list.querySelectorAll<HTMLElement>('[role=\"option\"]')[index];\n item?.scrollIntoView({ block: \"nearest\" });\n }\n\n function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n if (!open) {\n openMenu();\n return;\n }\n const next = highlighted < filtered.length - 1 ? highlighted + 1 : 0;\n setHighlighted(next);\n scrollToHighlighted(next);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n if (!open) return;\n const next = highlighted > 0 ? highlighted - 1 : filtered.length - 1;\n setHighlighted(next);\n scrollToHighlighted(next);\n } else if (e.key === \"Enter\") {\n if (open && highlighted >= 0 && filtered[highlighted] && !filtered[highlighted].disabled) {\n e.preventDefault();\n selectOption(filtered[highlighted]);\n return;\n }\n commitAndClose();\n onKeyDownProp?.(e);\n } else if (e.key === \"Escape\") {\n if (open) {\n e.preventDefault();\n setQuery(\"\");\n setOpen(false);\n setHighlighted(-1);\n }\n } else {\n onKeyDownProp?.(e);\n }\n }\n\n const listId = id ? `${id}-listbox` : undefined;\n const ariaLabel = ariaLabelProp ?? (typeof label === \"string\" ? label : undefined);\n const showClear = !required && !loading && !disabled && selectedValues.length > 0;\n\n return (\n <div ref={rootRef} className={cn(\"relative\", className)}>\n <div ref={anchorRef} data-jsf-control className=\"relative flex items-center\">\n {label != null && (\n <span className=\"pointer-events-none absolute left-2 z-10 whitespace-nowrap font-medium uppercase tracking-wide text-muted-foreground text-[10px]\">\n {label}\n </span>\n )}\n <input\n ref={inputRef}\n id={id}\n type=\"text\"\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={listId}\n aria-activedescendant={highlighted >= 0 ? `${listId}-${highlighted}` : undefined}\n aria-label={ariaLabel}\n aria-invalid={invalid || undefined}\n autoComplete=\"off\"\n disabled={disabled}\n placeholder={placeholder}\n value={displayValue}\n onChange={(e) => {\n setQuery(e.target.value);\n if (!open) setOpen(true);\n }}\n onFocus={openMenu}\n // Reopen on click too: focus only fires on the first focus, so a click\n // on an already-focused-but-closed input (e.g. after selecting, or\n // after Escape) would otherwise do nothing.\n onClick={() => {\n if (!open) openMenu();\n }}\n onKeyDown={onKeyDown}\n className={cn(\n \"w-full rounded-md border border-input bg-background text-foreground\",\n size ? inputSizeClass[size] : \"h-control-h px-control-px text-sm\",\n prefix && \"pl-8\",\n suffix ? (showClear ? \"pr-[5.5rem]\" : \"pr-14\") : showClear ? \"pr-14\" : \"pr-8\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n invalid && \"border-destructive focus-visible:ring-destructive\",\n )}\n style={label != null ? labelPadding(label) : undefined}\n />\n {prefix && (\n <div className=\"absolute inset-y-0 left-1.5 flex items-center\">{prefix}</div>\n )}\n {suffix && (\n <div className={cn(\"absolute flex h-full items-center\", showClear ? \"right-[3.75rem]\" : \"right-7\")}>\n {suffix}\n </div>\n )}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onClick={clear}\n className=\"absolute right-7 flex h-full items-center px-1 text-muted-foreground hover:text-foreground\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n {loading ? (\n <span className=\"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2\">\n <svg className=\"h-3.5 w-3.5 animate-spin text-muted-foreground\" viewBox=\"0 0 16 16\" fill=\"none\">\n <circle cx=\"8\" cy=\"8\" r=\"6.5\" stroke=\"currentColor\" strokeWidth=\"2\" opacity=\"0.25\" />\n <path d=\"M14.5 8a6.5 6.5 0 0 0-6.5-6.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n </span>\n ) : (\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={disabled}\n aria-label=\"Toggle options\"\n onClick={() => {\n if (open) {\n commitAndClose();\n } else {\n openMenu();\n inputRef.current?.focus();\n }\n }}\n className=\"pointer-events-auto absolute right-0 flex h-full items-center px-2 text-muted-foreground\"\n >\n <Icon icon={UiChevronDown} className=\"text-xs\" />\n </button>\n )}\n </div>\n {open && menuPos && typeof document !== \"undefined\" &&\n createPortal(\n <div\n id={listId}\n ref={listRef}\n role=\"listbox\"\n aria-multiselectable={multiple || undefined}\n style={{\n position: \"fixed\",\n ...(menuPos.top != null ? { top: menuPos.top } : { bottom: menuPos.bottom }),\n left: menuPos.left,\n // Grow to fit the widest option, but never narrower than the input\n // nor wider than 400px (beyond which option labels truncate). The\n // cap is also bounded by the viewport so the menu can't overflow.\n minWidth: menuPos.width,\n maxWidth: menuPos.maxWidth,\n maxHeight: menuPos.maxHeight,\n }}\n className=\"z-[9999] w-max overflow-auto rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-lg shadow-black/5\"\n >\n {loading && filtered.length === 0 && (\n <div className=\"px-2 py-4 text-center text-sm text-muted-foreground\">Loading…</div>\n )}\n {!loading && filtered.length === 0 && (\n <div className=\"px-2 py-4 text-center text-sm text-muted-foreground\">No results</div>\n )}\n {filtered.map((opt, i) => {\n const selected = isSelected(opt.value);\n // A header renders above the first option of each group. Derived\n // from the surviving (filtered) options, so an empty group emits no\n // header. The option keeps `i` (its index in `filtered`) for\n // id/highlight/select — headers are role=\"presentation\", never\n // counted in the highlight/scroll index.\n const showHeader = opt.group != null && opt.group !== filtered[i - 1]?.group;\n return (\n <Fragment key={opt.value}>\n {showHeader && (\n <div\n role=\"presentation\"\n className=\"select-none px-2 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\"\n >\n {opt.group}\n </div>\n )}\n <div\n id={listId ? `${listId}-${i}` : undefined}\n role=\"option\"\n aria-selected={selected}\n aria-disabled={opt.disabled}\n onMouseDown={(e) => {\n e.preventDefault();\n if (!opt.disabled) selectOption(opt);\n }}\n onMouseEnter={() => setHighlighted(i)}\n className={cn(\n \"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm\",\n i === highlighted && \"bg-accent\",\n selected && \"font-medium\",\n opt.disabled && \"cursor-not-allowed opacity-50\",\n )}\n >\n <Icon\n icon={UiCheck}\n className={cn(\"text-xs shrink-0\", selected ? \"opacity-100\" : \"opacity-0\")}\n />\n <LabelIcon icon={opt.icon} className=\"text-sm text-muted-foreground\" />\n <span className=\"min-w-0 truncate\">{opt.label}</span>\n </div>\n </Fragment>\n );\n })}\n </div>,\n document.body,\n )}\n </div>\n );\n}\n\n// Reserve room on the left of the input for the inline label so typed text\n// does not overlap it. Node labels (an icon from comboboxLabelProps) are\n// compact, so reserve a fixed icon-sized inset; text labels scale with their\n// character count at roughly 0.6rem per character plus padding.\nfunction labelPadding(label: ReactNode) {\n if (typeof label !== \"string\") return { paddingLeft: \"1.75rem\" };\n return { paddingLeft: `${Math.min(label.length * 0.62 + 0.75, 9)}rem` };\n}\n\n// withSelectedOptions returns the option list plus any selected value that isn't\n// already present, synthesized as {value, label: value}. Used by the server\n// (onSearch) typeahead so an already-selected value missing from the current\n// matches still renders as a checked row. Selected-but-absent values come first\n// so they don't get scrolled past by a long match list.\nfunction withSelectedOptions(\n options: ComboboxOption[],\n selectedValues: string[],\n): ComboboxOption[] {\n const present = new Set(options.map((o) => o.value));\n const pinned = selectedValues\n .filter((v) => !present.has(v))\n .map((v) => ({ value: v, label: v }));\n return pinned.length === 0 ? options : [...pinned, ...options];\n}\n"],"names":[],"mappings":";;;;;;;;;AAkBA,MAAM,oBAAoB;AAI1B,MAAM,qBAAqB;AA2FpB,SAAS,SAAS,OAAsB;AAC7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EAAA,IACE;AACJ,QAAM,WAAW,MAAM,aAAa;AACpC,QAAM,iBAAiB;AAAA,IACrB,MAAO,WAAW,MAAM,QAAQ,MAAM,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAA;AAAA,IAC9D,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAGxB,QAAM,UAAU,OAAuB,IAAI;AAC3C,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,UAAU,OAAuB,IAAI;AAC3C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AAOtC,QAAM,CAAC,SAAS,UAAU,IAAI,SAOpB,IAAI;AAId,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,EAAE;AAEjD,QAAM,aAAa,CAAC,aAAqB,eAAe,SAAS,QAAQ;AAIzE,QAAM,cAAc,QAAQ,MAAM;;AAChC,QAAI,UAAU;AACZ,YAAM,SAAS,QACZ,OAAO,CAAC,MAAM,eAAe,S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,IAAI,CAAC,CAAC,EAC7B,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;AACtC,SAAO,OAAO,WAAW,IAAI,UAAU,CAAC,GAAG,QAAQ,GAAG,OAAO;AAC/D;"}
|
|
@@ -14,6 +14,7 @@ const DateTimePicker = react.forwardRef(
|
|
|
14
14
|
buttonClassName,
|
|
15
15
|
openButtonLabel = "Open time picker",
|
|
16
16
|
suffix,
|
|
17
|
+
prefix,
|
|
17
18
|
...props
|
|
18
19
|
}, ref) => {
|
|
19
20
|
const visibleRef = react.useRef(null);
|
|
@@ -27,6 +28,7 @@ const DateTimePicker = react.forwardRef(
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-jsf-control": true, className: utils.cn("relative", className), children: [
|
|
31
|
+
prefix && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-y-0 left-1.5 flex items-center", children: prefix }),
|
|
30
32
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
31
33
|
"input",
|
|
32
34
|
{
|
|
@@ -36,6 +38,7 @@ const DateTimePicker = react.forwardRef(
|
|
|
36
38
|
value,
|
|
37
39
|
className: utils.cn(
|
|
38
40
|
"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
41
|
+
prefix && "pl-8",
|
|
39
42
|
inputClassName
|
|
40
43
|
),
|
|
41
44
|
onChange: (event) => onChange == null ? void 0 : onChange(event.target.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimePicker.cjs","sources":["../../src/components/DateTimePicker.tsx"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiCalendar } from \"../icons\";\nimport { cn } from \"../lib/utils\";\n\nexport type DateTimePickerProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"value\" | \"onChange\"\n> & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n};\n\nexport const DateTimePicker = forwardRef<HTMLInputElement, DateTimePickerProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel = \"Open time picker\",\n suffix,\n ...props\n },\n ref,\n ) => {\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const pickerRef = useRef<HTMLInputElement | null>(null);\n\n function assignRef(node: HTMLInputElement | null) {\n visibleRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n\n return (\n <div data-jsf-control className={cn(\"relative\", className)}>\n <input\n {...props}\n ref={assignRef}\n type=\"text\"\n value={value}\n className={cn(\n \"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n inputClassName,\n )}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <input\n ref={pickerRef}\n type=\"datetime-local\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute left-0 top-0 h-0 w-0 opacity-0\"\n value={toDateTimeLocalValue(value)}\n onChange={(event) => onChange?.(event.target.value)}\n />\n {suffix && (\n <div className=\"absolute inset-y-0 right-7 flex items-center\">{suffix}</div>\n )}\n <button\n type=\"button\"\n aria-label={openButtonLabel}\n disabled={props.disabled}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n onClick={() => {\n visibleRef.current?.focus();\n pickerRef.current?.showPicker?.();\n }}\n >\n <Icon icon={UiCalendar} className=\"text-sm\" />\n </button>\n </div>\n );\n },\n);\n\nDateTimePicker.displayName = \"DateTimePicker\";\n\nfunction toDateTimeLocalValue(value: string) {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n if (trimmed === \"now\" || trimmed.startsWith(\"now\")) return \"\";\n\n const withTime = /^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed) ? `${trimmed}T00:00` : trimmed;\n\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/.test(withTime) ? withTime.slice(0, 16) : \"\";\n}\n"],"names":["forwardRef","useRef","jsxs","cn","jsx","Icon","UiCalendar"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"DateTimePicker.cjs","sources":["../../src/components/DateTimePicker.tsx"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiCalendar } from \"../icons\";\nimport { cn } from \"../lib/utils\";\n\nexport type DateTimePickerProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n // `prefix` is a global HTML attribute typed as string; omit it so our\n // ReactNode adornment prop below is not intersected down to `string & ReactNode`.\n \"type\" | \"value\" | \"onChange\" | \"prefix\"\n> & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n /** Leading in-field adornment, rendered at the left edge of the input. */\n prefix?: ReactNode;\n};\n\nexport const DateTimePicker = forwardRef<HTMLInputElement, DateTimePickerProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel = \"Open time picker\",\n suffix,\n prefix,\n ...props\n },\n ref,\n ) => {\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const pickerRef = useRef<HTMLInputElement | null>(null);\n\n function assignRef(node: HTMLInputElement | null) {\n visibleRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n\n return (\n <div data-jsf-control className={cn(\"relative\", className)}>\n {prefix && <div className=\"absolute inset-y-0 left-1.5 flex items-center\">{prefix}</div>}\n <input\n {...props}\n ref={assignRef}\n type=\"text\"\n value={value}\n className={cn(\n \"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n prefix && \"pl-8\",\n inputClassName,\n )}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <input\n ref={pickerRef}\n type=\"datetime-local\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute left-0 top-0 h-0 w-0 opacity-0\"\n value={toDateTimeLocalValue(value)}\n onChange={(event) => onChange?.(event.target.value)}\n />\n {suffix && (\n <div className=\"absolute inset-y-0 right-7 flex items-center\">{suffix}</div>\n )}\n <button\n type=\"button\"\n aria-label={openButtonLabel}\n disabled={props.disabled}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n onClick={() => {\n visibleRef.current?.focus();\n pickerRef.current?.showPicker?.();\n }}\n >\n <Icon icon={UiCalendar} className=\"text-sm\" />\n </button>\n </div>\n );\n },\n);\n\nDateTimePicker.displayName = \"DateTimePicker\";\n\nfunction toDateTimeLocalValue(value: string) {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n if (trimmed === \"now\" || trimmed.startsWith(\"now\")) return \"\";\n\n const withTime = /^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed) ? `${trimmed}T00:00` : trimmed;\n\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/.test(withTime) ? withTime.slice(0, 16) : \"\";\n}\n"],"names":["forwardRef","useRef","jsxs","cn","jsx","Icon","UiCalendar"],"mappings":";;;;;;;AAuBO,MAAM,iBAAiBA,MAAAA;AAAAA,EAC5B,CACE;AAAA,IACE,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,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S,MAAM;;AACb,6BAAW,YAAX,mBAAoB;AACpB,kCAAU,YAAV,mBAAmB,eAAnB;AAAA,UACF;AAAA,UAEA,UAAAC,2BAAAA,IAACC,WAAA,EAAK,MAAMC,WAAAA,YAAY,WAAU,UAAA,CAAU;AAAA,QAAA;AAAA,MAAA;AAAA,IAC9C,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAE7B,SAAS,qBAAqB,OAAe;AAC3C,QAAM,UAAU,MAAM,KAAA;AACtB,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,YAAY,SAAS,QAAQ,WAAW,KAAK,EAAG,QAAO;AAE3D,QAAM,WAAW,sBAAsB,KAAK,OAAO,IAAI,GAAG,OAAO,WAAW;AAE5E,SAAO,iCAAiC,KAAK,QAAQ,IAAI,SAAS,MAAM,GAAG,EAAE,IAAI;AACnF;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InputHTMLAttributes, ReactNode } from 'react';
|
|
2
|
-
export type DateTimePickerProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "onChange"> & {
|
|
2
|
+
export type DateTimePickerProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "onChange" | "prefix"> & {
|
|
3
3
|
value?: string;
|
|
4
4
|
onChange?: (value: string) => void;
|
|
5
5
|
className?: string;
|
|
@@ -8,8 +8,10 @@ export type DateTimePickerProps = Omit<InputHTMLAttributes<HTMLInputElement>, "t
|
|
|
8
8
|
openButtonLabel?: string;
|
|
9
9
|
/** Trailing in-field adornment, rendered left of the calendar button. */
|
|
10
10
|
suffix?: ReactNode;
|
|
11
|
+
/** Leading in-field adornment, rendered at the left edge of the input. */
|
|
12
|
+
prefix?: ReactNode;
|
|
11
13
|
};
|
|
12
|
-
export declare const DateTimePicker: import('react').ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "type" | "onChange"> & {
|
|
14
|
+
export declare const DateTimePicker: import('react').ForwardRefExoticComponent<Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "type" | "onChange" | "prefix"> & {
|
|
13
15
|
value?: string;
|
|
14
16
|
onChange?: (value: string) => void;
|
|
15
17
|
className?: string;
|
|
@@ -18,5 +20,7 @@ export declare const DateTimePicker: import('react').ForwardRefExoticComponent<O
|
|
|
18
20
|
openButtonLabel?: string;
|
|
19
21
|
/** Trailing in-field adornment, rendered left of the calendar button. */
|
|
20
22
|
suffix?: ReactNode;
|
|
23
|
+
/** Leading in-field adornment, rendered at the left edge of the input. */
|
|
24
|
+
prefix?: ReactNode;
|
|
21
25
|
} & import('react').RefAttributes<HTMLInputElement>>;
|
|
22
26
|
//# sourceMappingURL=DateTimePicker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimePicker.d.ts","sourceRoot":"","sources":["../../src/components/DateTimePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKrF,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,mBAAmB,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"DateTimePicker.d.ts","sourceRoot":"","sources":["../../src/components/DateTimePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKrF,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,mBAAmB,CAAC,gBAAgB,CAAC,EAGrC,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CACzC,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,cAAc;YAZjB,MAAM;eACH,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;gBACtB,MAAM;qBACD,MAAM;sBACL,MAAM;sBACN,MAAM;IACxB,yEAAyE;aAChE,SAAS;IAClB,0EAA0E;aACjE,SAAS;oDA2EnB,CAAC"}
|
|
@@ -12,6 +12,7 @@ const DateTimePicker = forwardRef(
|
|
|
12
12
|
buttonClassName,
|
|
13
13
|
openButtonLabel = "Open time picker",
|
|
14
14
|
suffix,
|
|
15
|
+
prefix,
|
|
15
16
|
...props
|
|
16
17
|
}, ref) => {
|
|
17
18
|
const visibleRef = useRef(null);
|
|
@@ -25,6 +26,7 @@ const DateTimePicker = forwardRef(
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
return /* @__PURE__ */ jsxs("div", { "data-jsf-control": true, className: cn("relative", className), children: [
|
|
29
|
+
prefix && /* @__PURE__ */ jsx("div", { className: "absolute inset-y-0 left-1.5 flex items-center", children: prefix }),
|
|
28
30
|
/* @__PURE__ */ jsx(
|
|
29
31
|
"input",
|
|
30
32
|
{
|
|
@@ -34,6 +36,7 @@ const DateTimePicker = forwardRef(
|
|
|
34
36
|
value,
|
|
35
37
|
className: cn(
|
|
36
38
|
"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
39
|
+
prefix && "pl-8",
|
|
37
40
|
inputClassName
|
|
38
41
|
),
|
|
39
42
|
onChange: (event) => onChange == null ? void 0 : onChange(event.target.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimePicker.js","sources":["../../src/components/DateTimePicker.tsx"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiCalendar } from \"../icons\";\nimport { cn } from \"../lib/utils\";\n\nexport type DateTimePickerProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"value\" | \"onChange\"\n> & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n};\n\nexport const DateTimePicker = forwardRef<HTMLInputElement, DateTimePickerProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel = \"Open time picker\",\n suffix,\n ...props\n },\n ref,\n ) => {\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const pickerRef = useRef<HTMLInputElement | null>(null);\n\n function assignRef(node: HTMLInputElement | null) {\n visibleRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n\n return (\n <div data-jsf-control className={cn(\"relative\", className)}>\n <input\n {...props}\n ref={assignRef}\n type=\"text\"\n value={value}\n className={cn(\n \"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n inputClassName,\n )}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <input\n ref={pickerRef}\n type=\"datetime-local\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute left-0 top-0 h-0 w-0 opacity-0\"\n value={toDateTimeLocalValue(value)}\n onChange={(event) => onChange?.(event.target.value)}\n />\n {suffix && (\n <div className=\"absolute inset-y-0 right-7 flex items-center\">{suffix}</div>\n )}\n <button\n type=\"button\"\n aria-label={openButtonLabel}\n disabled={props.disabled}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n onClick={() => {\n visibleRef.current?.focus();\n pickerRef.current?.showPicker?.();\n }}\n >\n <Icon icon={UiCalendar} className=\"text-sm\" />\n </button>\n </div>\n );\n },\n);\n\nDateTimePicker.displayName = \"DateTimePicker\";\n\nfunction toDateTimeLocalValue(value: string) {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n if (trimmed === \"now\" || trimmed.startsWith(\"now\")) return \"\";\n\n const withTime = /^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed) ? `${trimmed}T00:00` : trimmed;\n\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/.test(withTime) ? withTime.slice(0, 16) : \"\";\n}\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"DateTimePicker.js","sources":["../../src/components/DateTimePicker.tsx"],"sourcesContent":["import { forwardRef, useRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { Icon } from \"../data/Icon\";\nimport { UiCalendar } from \"../icons\";\nimport { cn } from \"../lib/utils\";\n\nexport type DateTimePickerProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n // `prefix` is a global HTML attribute typed as string; omit it so our\n // ReactNode adornment prop below is not intersected down to `string & ReactNode`.\n \"type\" | \"value\" | \"onChange\" | \"prefix\"\n> & {\n value?: string;\n onChange?: (value: string) => void;\n className?: string;\n inputClassName?: string;\n buttonClassName?: string;\n openButtonLabel?: string;\n /** Trailing in-field adornment, rendered left of the calendar button. */\n suffix?: ReactNode;\n /** Leading in-field adornment, rendered at the left edge of the input. */\n prefix?: ReactNode;\n};\n\nexport const DateTimePicker = forwardRef<HTMLInputElement, DateTimePickerProps>(\n (\n {\n value = \"\",\n onChange,\n className,\n inputClassName,\n buttonClassName,\n openButtonLabel = \"Open time picker\",\n suffix,\n prefix,\n ...props\n },\n ref,\n ) => {\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const pickerRef = useRef<HTMLInputElement | null>(null);\n\n function assignRef(node: HTMLInputElement | null) {\n visibleRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }\n\n return (\n <div data-jsf-control className={cn(\"relative\", className)}>\n {prefix && <div className=\"absolute inset-y-0 left-1.5 flex items-center\">{prefix}</div>}\n <input\n {...props}\n ref={assignRef}\n type=\"text\"\n value={value}\n className={cn(\n \"h-8 w-full rounded-md border border-input bg-background px-2 pr-8 text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50\",\n prefix && \"pl-8\",\n inputClassName,\n )}\n onChange={(event) => onChange?.(event.target.value)}\n />\n <input\n ref={pickerRef}\n type=\"datetime-local\"\n tabIndex={-1}\n aria-hidden=\"true\"\n className=\"pointer-events-none absolute left-0 top-0 h-0 w-0 opacity-0\"\n value={toDateTimeLocalValue(value)}\n onChange={(event) => onChange?.(event.target.value)}\n />\n {suffix && (\n <div className=\"absolute inset-y-0 right-7 flex items-center\">{suffix}</div>\n )}\n <button\n type=\"button\"\n aria-label={openButtonLabel}\n disabled={props.disabled}\n className={cn(\n \"absolute inset-y-0 right-1 inline-flex items-center text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n buttonClassName,\n )}\n onClick={() => {\n visibleRef.current?.focus();\n pickerRef.current?.showPicker?.();\n }}\n >\n <Icon icon={UiCalendar} className=\"text-sm\" />\n </button>\n </div>\n );\n },\n);\n\nDateTimePicker.displayName = \"DateTimePicker\";\n\nfunction toDateTimeLocalValue(value: string) {\n const trimmed = value.trim();\n if (!trimmed) return \"\";\n if (trimmed === \"now\" || trimmed.startsWith(\"now\")) return \"\";\n\n const withTime = /^\\d{4}-\\d{2}-\\d{2}$/.test(trimmed) ? `${trimmed}T00:00` : trimmed;\n\n return /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/.test(withTime) ? withTime.slice(0, 16) : \"\";\n}\n"],"names":[],"mappings":";;;;;AAuBO,MAAM,iBAAiB;AAAA,EAC5B,CACE;AAAA,IACE,QAAQ;AA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AmB,eAAnB;AAAA,UACF;AAAA,UAEA,UAAA,oBAAC,MAAA,EAAK,MAAM,YAAY,WAAU,UAAA,CAAU;AAAA,QAAA;AAAA,MAAA;AAAA,IAC9C,GACF;AAAA,EAEJ;AACF;AAEA,eAAe,cAAc;AAE7B,SAAS,qBAAqB,OAAe;AAC3C,QAAM,UAAU,MAAM,KAAA;AACtB,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,YAAY,SAAS,QAAQ,WAAW,KAAK,EAAG,QAAO;AAE3D,QAAM,WAAW,sBAAsB,KAAK,OAAO,IAAI,GAAG,OAAO,WAAW;AAE5E,SAAO,iCAAiC,KAAK,QAAQ,IAAI,SAAS,MAAM,GAAG,EAAE,IAAI;AACnF;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const utils = require("../lib/utils.cjs");
|
|
5
|
+
function Field({
|
|
6
|
+
label,
|
|
7
|
+
htmlFor,
|
|
8
|
+
required,
|
|
9
|
+
error,
|
|
10
|
+
helper,
|
|
11
|
+
className,
|
|
12
|
+
labelClassName,
|
|
13
|
+
onBlur,
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils.cn("flex w-full flex-col gap-1", className), onBlur, children: [
|
|
17
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
18
|
+
"label",
|
|
19
|
+
{
|
|
20
|
+
htmlFor,
|
|
21
|
+
className: utils.cn("flex min-w-0 items-center gap-1 text-sm font-medium", labelClassName),
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0", children: label }),
|
|
24
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-destructive", "aria-hidden": true, children: "*" })
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
),
|
|
28
|
+
children,
|
|
29
|
+
error ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-destructive", children: error }) : helper ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: helper }) : null
|
|
30
|
+
] });
|
|
31
|
+
}
|
|
32
|
+
exports.Field = Field;
|
|
33
|
+
//# sourceMappingURL=Field.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.cjs","sources":["../../src/components/Field.tsx"],"sourcesContent":["import type { FocusEventHandler, ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\n\nexport interface FieldProps {\n /** Field label text (or node). */\n label: ReactNode;\n /** Associates the label with a control by id (optional for non-input controls). */\n htmlFor?: string;\n /** Appends a destructive \"*\" after the label. */\n required?: boolean;\n /**\n * Inline validation message rendered under the control in destructive color.\n * When set it takes the place of `helper`.\n */\n error?: ReactNode;\n /** Muted helper/description text under the control (shown when there's no error). */\n helper?: ReactNode;\n className?: string;\n /** Overrides the label classes (e.g. an uppercase form style). */\n labelClassName?: string;\n /**\n * Fires when focus leaves the field (focusout bubbles), so a form can mark the\n * field touched and reveal its error on blur.\n */\n onBlur?: FocusEventHandler<HTMLDivElement>;\n children: ReactNode;\n}\n\n// Field is the generic label-over-control chrome: a label (with an optional\n// required \"*\"), the control, and an inline error or helper line beneath it.\n// Pair it with useForm for blur/submit-gated error display, or pass `error`\n// directly. The same primitive JsonSchemaForm renders internally, exposed for\n// hand-built forms.\nexport function Field({\n label,\n htmlFor,\n required,\n error,\n helper,\n className,\n labelClassName,\n onBlur,\n children,\n}: FieldProps) {\n return (\n <div className={cn(\"flex w-full flex-col gap-1\", className)} onBlur={onBlur}>\n <label\n htmlFor={htmlFor}\n className={cn(\"flex min-w-0 items-center gap-1 text-sm font-medium\", labelClassName)}\n >\n <span className=\"min-w-0\">{label}</span>\n {required && (\n <span className=\"shrink-0 text-destructive\" aria-hidden>\n *\n </span>\n )}\n </label>\n {children}\n {error ? (\n <p className=\"text-xs text-destructive\">{error}</p>\n ) : helper ? (\n <p className=\"text-xs text-muted-foreground\">{helper}</p>\n ) : null}\n </div>\n );\n}\n"],"names":["cn","jsxs","jsx"],"mappings":";;;;AAiCO,SAAS,MAAM;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAe;AACb,yCACG,OAAA,EAAI,WAAWA,MAAAA,GAAG,8BAA8B,SAAS,GAAG,QAC3D,UAAA;AAAA,IAAAC,2BAAAA;AAAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAWD,MAAAA,GAAG,uDAAuD,cAAc;AAAA,QAEnF,UAAA;AAAA,UAAAE,2BAAAA,IAAC,QAAA,EAAK,WAAU,WAAW,UAAA,OAAM;AAAA,UAChC,YACCA,2BAAAA,IAAC,QAAA,EAAK,WAAU,6BAA4B,eAAW,MAAC,UAAA,IAAA,CAExD;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,IAGH;AAAA,IACA,QACCA,2BAAAA,IAAC,KAAA,EAAE,WAAU,4BAA4B,UAAA,MAAA,CAAM,IAC7C,SACFA,2BAAAA,IAAC,KAAA,EAAE,WAAU,iCAAiC,kBAAO,IACnD;AAAA,EAAA,GACN;AAEJ;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FocusEventHandler, ReactNode } from 'react';
|
|
2
|
+
export interface FieldProps {
|
|
3
|
+
/** Field label text (or node). */
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
/** Associates the label with a control by id (optional for non-input controls). */
|
|
6
|
+
htmlFor?: string;
|
|
7
|
+
/** Appends a destructive "*" after the label. */
|
|
8
|
+
required?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Inline validation message rendered under the control in destructive color.
|
|
11
|
+
* When set it takes the place of `helper`.
|
|
12
|
+
*/
|
|
13
|
+
error?: ReactNode;
|
|
14
|
+
/** Muted helper/description text under the control (shown when there's no error). */
|
|
15
|
+
helper?: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
/** Overrides the label classes (e.g. an uppercase form style). */
|
|
18
|
+
labelClassName?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Fires when focus leaves the field (focusout bubbles), so a form can mark the
|
|
21
|
+
* field touched and reveal its error on blur.
|
|
22
|
+
*/
|
|
23
|
+
onBlur?: FocusEventHandler<HTMLDivElement>;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
export declare function Field({ label, htmlFor, required, error, helper, className, labelClassName, onBlur, children, }: FieldProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=Field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/components/Field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG1D,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,KAAK,EAAE,SAAS,CAAC;IACjB,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,qFAAqF;IACrF,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,SAAS,CAAC;CACrB;AAOD,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACN,SAAS,EACT,cAAc,EACd,MAAM,EACN,QAAQ,GACT,EAAE,UAAU,2CAsBZ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../lib/utils.js";
|
|
3
|
+
function Field({
|
|
4
|
+
label,
|
|
5
|
+
htmlFor,
|
|
6
|
+
required,
|
|
7
|
+
error,
|
|
8
|
+
helper,
|
|
9
|
+
className,
|
|
10
|
+
labelClassName,
|
|
11
|
+
onBlur,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex w-full flex-col gap-1", className), onBlur, children: [
|
|
15
|
+
/* @__PURE__ */ jsxs(
|
|
16
|
+
"label",
|
|
17
|
+
{
|
|
18
|
+
htmlFor,
|
|
19
|
+
className: cn("flex min-w-0 items-center gap-1 text-sm font-medium", labelClassName),
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0", children: label }),
|
|
22
|
+
required && /* @__PURE__ */ jsx("span", { className: "shrink-0 text-destructive", "aria-hidden": true, children: "*" })
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
children,
|
|
27
|
+
error ? /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error }) : helper ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: helper }) : null
|
|
28
|
+
] });
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
Field
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=Field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.js","sources":["../../src/components/Field.tsx"],"sourcesContent":["import type { FocusEventHandler, ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\n\nexport interface FieldProps {\n /** Field label text (or node). */\n label: ReactNode;\n /** Associates the label with a control by id (optional for non-input controls). */\n htmlFor?: string;\n /** Appends a destructive \"*\" after the label. */\n required?: boolean;\n /**\n * Inline validation message rendered under the control in destructive color.\n * When set it takes the place of `helper`.\n */\n error?: ReactNode;\n /** Muted helper/description text under the control (shown when there's no error). */\n helper?: ReactNode;\n className?: string;\n /** Overrides the label classes (e.g. an uppercase form style). */\n labelClassName?: string;\n /**\n * Fires when focus leaves the field (focusout bubbles), so a form can mark the\n * field touched and reveal its error on blur.\n */\n onBlur?: FocusEventHandler<HTMLDivElement>;\n children: ReactNode;\n}\n\n// Field is the generic label-over-control chrome: a label (with an optional\n// required \"*\"), the control, and an inline error or helper line beneath it.\n// Pair it with useForm for blur/submit-gated error display, or pass `error`\n// directly. The same primitive JsonSchemaForm renders internally, exposed for\n// hand-built forms.\nexport function Field({\n label,\n htmlFor,\n required,\n error,\n helper,\n className,\n labelClassName,\n onBlur,\n children,\n}: FieldProps) {\n return (\n <div className={cn(\"flex w-full flex-col gap-1\", className)} onBlur={onBlur}>\n <label\n htmlFor={htmlFor}\n className={cn(\"flex min-w-0 items-center gap-1 text-sm font-medium\", labelClassName)}\n >\n <span className=\"min-w-0\">{label}</span>\n {required && (\n <span className=\"shrink-0 text-destructive\" aria-hidden>\n *\n </span>\n )}\n </label>\n {children}\n {error ? (\n <p className=\"text-xs text-destructive\">{error}</p>\n ) : helper ? (\n <p className=\"text-xs text-muted-foreground\">{helper}</p>\n ) : null}\n </div>\n );\n}\n"],"names":[],"mappings":";;AAiCO,SAAS,MAAM;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAe;AACb,8BACG,OAAA,EAAI,WAAW,GAAG,8BAA8B,SAAS,GAAG,QAC3D,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,WAAW,GAAG,uDAAuD,cAAc;AAAA,QAEnF,UAAA;AAAA,UAAA,oBAAC,QAAA,EAAK,WAAU,WAAW,UAAA,OAAM;AAAA,UAChC,YACC,oBAAC,QAAA,EAAK,WAAU,6BAA4B,eAAW,MAAC,UAAA,IAAA,CAExD;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,IAGH;AAAA,IACA,QACC,oBAAC,KAAA,EAAE,WAAU,4BAA4B,UAAA,MAAA,CAAM,IAC7C,SACF,oBAAC,KAAA,EAAE,WAAU,iCAAiC,kBAAO,IACnD;AAAA,EAAA,GACN;AAEJ;"}
|