@namroodinc/liquid-editorial 0.13.1 → 0.13.3
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/UPGRADING.md +4 -0
- package/dist/chunks/{Board-DfVQSb_L.cjs → Board-CQ1GTuRB.cjs} +2 -2
- package/dist/chunks/{Board-DfVQSb_L.cjs.map → Board-CQ1GTuRB.cjs.map} +1 -1
- package/dist/chunks/{Board-6fXt1YFp.js → Board-DUX76d2R.js} +2 -2
- package/dist/chunks/{Board-6fXt1YFp.js.map → Board-DUX76d2R.js.map} +1 -1
- package/dist/chunks/{ColourField-YaCEWiPA.js → ColourField-BG5oGj9f.js} +2 -2
- package/dist/chunks/{ColourField-YaCEWiPA.js.map → ColourField-BG5oGj9f.js.map} +1 -1
- package/dist/chunks/{ColourField-bgi6TLOM.cjs → ColourField-DFvRASVe.cjs} +2 -2
- package/dist/chunks/{ColourField-bgi6TLOM.cjs.map → ColourField-DFvRASVe.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-CCygKPuy.cjs → DatePicker-ClOqS6oH.cjs} +2 -2
- package/dist/chunks/{DatePicker-CCygKPuy.cjs.map → DatePicker-ClOqS6oH.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-CHJYSaLU.js → DatePicker-LqaePc57.js} +2 -2
- package/dist/chunks/{DatePicker-CHJYSaLU.js.map → DatePicker-LqaePc57.js.map} +1 -1
- package/dist/chunks/{EntryPicker-DmiAnu9l.cjs → EntryPicker-B4dAsObz.cjs} +2 -2
- package/dist/chunks/{EntryPicker-DmiAnu9l.cjs.map → EntryPicker-B4dAsObz.cjs.map} +1 -1
- package/dist/chunks/{EntryPicker-WERMwe0h.js → EntryPicker-DDXHytMN.js} +2 -2
- package/dist/chunks/{EntryPicker-WERMwe0h.js.map → EntryPicker-DDXHytMN.js.map} +1 -1
- package/dist/chunks/{FormEditor-B8USzAky.cjs → FormEditor-BGzE-rqk.cjs} +2 -2
- package/dist/chunks/{FormEditor-B8USzAky.cjs.map → FormEditor-BGzE-rqk.cjs.map} +1 -1
- package/dist/chunks/{FormEditor-BG2RhC71.js → FormEditor-ChH4e5sB.js} +6 -6
- package/dist/chunks/{FormEditor-BG2RhC71.js.map → FormEditor-ChH4e5sB.js.map} +1 -1
- package/dist/chunks/{Icon-C12r4frL.cjs → Icon-3ucBRgrd.cjs} +2 -2
- package/dist/chunks/Icon-3ucBRgrd.cjs.map +1 -0
- package/dist/chunks/{Icon-Peb0houB.js → Icon-dPXyBYe5.js} +13 -12
- package/dist/chunks/Icon-dPXyBYe5.js.map +1 -0
- package/dist/chunks/{Message-qguX0uZk.cjs → Message-Ce2zjtfz.cjs} +2 -2
- package/dist/chunks/{Message-qguX0uZk.cjs.map → Message-Ce2zjtfz.cjs.map} +1 -1
- package/dist/chunks/{Message-CMoH7jcg.js → Message-DNaudg1u.js} +2 -2
- package/dist/chunks/{Message-CMoH7jcg.js.map → Message-DNaudg1u.js.map} +1 -1
- package/dist/chunks/{RichTextEditor-D8VQAM5h.js → RichTextEditor-BFblqw8m.js} +3 -3
- package/dist/chunks/{RichTextEditor-D8VQAM5h.js.map → RichTextEditor-BFblqw8m.js.map} +1 -1
- package/dist/chunks/{RichTextEditor-BSA4uzKm.cjs → RichTextEditor-DU9CVeRD.cjs} +2 -2
- package/dist/chunks/{RichTextEditor-BSA4uzKm.cjs.map → RichTextEditor-DU9CVeRD.cjs.map} +1 -1
- package/dist/chunks/{use-picker-session-GCDShVBy.js → use-picker-session-BSpOwnQ-.js} +2 -2
- package/dist/chunks/{use-picker-session-GCDShVBy.js.map → use-picker-session-BSpOwnQ-.js.map} +1 -1
- package/dist/chunks/{use-picker-session-CM0zcEbf.cjs → use-picker-session-ouqHBmVA.cjs} +2 -2
- package/dist/chunks/{use-picker-session-CM0zcEbf.cjs.map → use-picker-session-ouqHBmVA.cjs.map} +1 -1
- package/dist/components/AssetCard/index.cjs +1 -1
- package/dist/components/AssetCard/index.js +1 -1
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.js +1 -1
- package/dist/components/Avatar/style.css +1 -1
- package/dist/components/Banner/index.cjs +1 -1
- package/dist/components/Banner/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.js +1 -1
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/Icon/icons.d.cts +1 -0
- package/dist/components/Icon/icons.d.cts.map +1 -1
- package/dist/components/Icon/icons.d.ts +1 -0
- package/dist/components/Icon/icons.d.ts.map +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SubNav/index.cjs +1 -1
- package/dist/components/SubNav/index.js +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.cjs.map +1 -1
- package/dist/components/Time/index.js +4 -1
- package/dist/components/Time/index.js.map +1 -1
- package/dist/components/Time/style.css +1 -0
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/package.json +1 -1
- package/dist/chunks/Icon-C12r4frL.cjs.map +0 -1
- package/dist/chunks/Icon-Peb0houB.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColourField-bgi6TLOM.cjs","names":["useRef","useState","colourState","normaliseColour","colourHex","forwardRef","useRef","useState","useSyncExternalStore","useId","normaliseColour","colourHex","useMemo","parseColour","colourState","_Fragment","Button","Slider","Icon","forwardRef","useState","useOverlayOpen","useRef","useId","normaliseColour","parseColour","tabbableControls","FieldAffix","Button","TextField","mergeRefs","Popover","require_colour","require_Icon","require_components_Button_index","require_mergeRefs","require_overlayLayer","require_components_TextField_index","require_components_Popover_index","require_components_FieldAffix_index","require_Slider","react","react_jsx_runtime","clamp","value","ColourSquare","dragging","update","rect","event","onChange","colour","isDisabled","step","change","useColourValue","internal","setInternal","defaultValue","current","selection","setSelection","hex","next","onValueChange","useColourDraft","draft","setDraft","isValid","eyeDropperConstructor","subscribe","noPresets","presetColumns","presetTarget","column","index","lastInColumn","count","key","ColourPanel","rest","ColourPanelContent","commit","inputRef","active","disabledRef","isPicking","setPicking","pickerError","setPickerError","hasEyeDropper","presetsId","rgb","swatches","unique","preset","presets","normalised","selectedIndex","swatch","pickFromScreen","EyeDropper","result","onColourChange","error","className","style","picker","delta","input","a","showPresets","radios","selected","ColourField","ariaInvalid","open","setOpen","isOpen","rootRef","openerRef","panelRef","panelId","fieldId","id","invalid","text","effectiveDisabled","disabled","readOnly","visible","onValidityChange","outside","target","toggle","opener","close","triggerProps","controls","ref","isInvalid","valid","type","discard","onBlur","onKeyDown"],"sources":["../../src/components/ColourField/square.tsx","../../src/components/ColourField/value.ts","../../src/components/ColourField/panel.tsx","../../src/components/ColourField/index.tsx"],"sourcesContent":["import { useRef, type KeyboardEvent, type PointerEvent } from \"react\";\nimport type { Colour } from \"./colour\";\n\ninterface ColourSquareProps {\n colour: Colour;\n isDisabled: boolean;\n onChange: (colour: Colour) => void;\n}\n\nfunction clamp(value: number) {\n return Math.max(0, Math.min(100, value));\n}\n\nexport function ColourSquare({ colour, isDisabled, onChange }: ColourSquareProps) {\n const dragging = useRef<number | null>(null);\n const update = (event: PointerEvent<HTMLDivElement>) => {\n const rect = event.currentTarget.getBoundingClientRect();\n if (!rect.width || !rect.height) {\n return;\n }\n onChange({\n ...colour,\n s: clamp(((event.clientX - rect.left) / rect.width) * 100),\n v: clamp((1 - (event.clientY - rect.top) / rect.height) * 100),\n });\n };\n const handleKey = (event: KeyboardEvent) => {\n if (isDisabled) {\n return;\n }\n const step = event.shiftKey ? 10 : 1;\n const changes: Record<string, Partial<Colour>> = {\n ArrowLeft: { s: clamp(colour.s - step) },\n ArrowRight: { s: clamp(colour.s + step) },\n ArrowDown: { v: clamp(colour.v - step) },\n ArrowUp: { v: clamp(colour.v + step) },\n Home: { s: 0 },\n End: { s: 100 },\n };\n const change = changes[event.key];\n if (!change) {\n return;\n }\n event.preventDefault();\n onChange({ ...colour, ...change });\n };\n return (\n <div\n className=\"ds-colour-panel__square\"\n role=\"slider\"\n tabIndex={isDisabled ? -1 : 0}\n aria-label=\"Saturation and brightness\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={Math.round(colour.s)}\n aria-valuetext={`Saturation ${Math.round(colour.s)}%, brightness ${Math.round(colour.v)}%`}\n aria-disabled={isDisabled || undefined}\n onKeyDown={handleKey}\n onPointerDown={(event) => {\n if (isDisabled || event.button !== 0) {\n return;\n }\n event.preventDefault();\n event.currentTarget.focus();\n dragging.current = event.pointerId;\n event.currentTarget.setPointerCapture(event.pointerId);\n update(event);\n }}\n onPointerMove={(event) => {\n if (!isDisabled && dragging.current === event.pointerId) {\n update(event);\n }\n }}\n onPointerUp={(event) => {\n if (dragging.current !== event.pointerId) {\n return;\n }\n dragging.current = null;\n event.currentTarget.releasePointerCapture(event.pointerId);\n }}\n onPointerCancel={() => {\n dragging.current = null;\n }}\n onLostPointerCapture={() => {\n dragging.current = null;\n }}\n >\n <span\n className=\"ds-colour-panel__thumb\"\n style={{ left: `${colour.s}%`, top: `${100 - colour.v}%` }}\n />\n </div>\n );\n}\n","import { useState } from \"react\";\nimport { colourHex, colourState, normaliseColour, type Colour } from \"./colour\";\n\nexport interface ColourValueProps {\n value?: string;\n defaultValue?: string;\n /** Uppercase hex (including alpha when needed), or an empty string when cleared. */\n onValueChange?: (value: string) => void;\n}\n\nexport function useColourValue({ value, defaultValue = \"\", onValueChange }: ColourValueProps) {\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n const [selection, setSelection] = useState(() => ({\n source: current,\n colour: colourState(current),\n }));\n let colour = selection.colour;\n if (selection.source !== current) {\n colour = colourState(current, colour);\n setSelection({ source: current, colour });\n }\n\n const commit = (next: string | Colour) => {\n const hex = typeof next === \"string\" ? normaliseColour(next) : colourHex(next);\n setSelection({\n source: hex,\n colour: typeof next === \"string\" ? colourState(next, colour) : next,\n });\n if (value === undefined) {\n setInternal(hex);\n }\n onValueChange?.(hex);\n };\n\n return { current, colour, commit };\n}\n\n/** Typed text the field shows until it is committed, blurred, or replaced. */\nexport function useColourDraft(current: string, hex: string) {\n const [draft, setDraft] = useState<{ source: string; text: string } | null>(null);\n // A draft belongs to the value it was typed over. A parent that stores the invalid\n // text (FormEditor does) takes it over, so restoring the earlier value then wins.\n if (draft && draft.source !== current && draft.text === current) {\n setDraft({ source: current, text: current });\n }\n const text = draft?.source === current ? draft.text : hex || current;\n /** Valid text becomes the committed hex; invalid text stays over the current value. */\n const type = (next: string, isValid: boolean) =>\n setDraft({ source: isValid ? normaliseColour(next) : current, text: next });\n return { text, type, discard: () => setDraft(null) };\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n type CSSProperties,\n type HTMLAttributes,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Slider } from \"../Slider\";\nimport { colourHex, colourState, normaliseColour, parseColour, type Colour } from \"./colour\";\nimport { ColourSquare } from \"./square\";\nimport { useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport interface ColourPickerOptions {\n presets?: string[];\n showPresets?: boolean;\n picker?: \"custom\" | \"native\";\n isDisabled?: boolean;\n}\n\nexport interface ColourPanelProps\n extends\n Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\">,\n ColourValueProps,\n ColourPickerOptions {}\n\ninterface EyeDropperInstance {\n open: () => Promise<{ sRGBHex: string }>;\n}\nfunction eyeDropperConstructor() {\n return (window as Window & { EyeDropper?: new () => EyeDropperInstance }).EyeDropper;\n}\nconst subscribe = () => () => {};\nconst noPresets: string[] = [];\nconst presetColumns = 8;\n\n/** Where a key moves within the preset grid; rows wrap within their column. */\nfunction presetTarget(key: string, index: number, count: number) {\n const column = index % presetColumns;\n const lastInColumn = column + Math.floor((count - 1 - column) / presetColumns) * presetColumns;\n switch (key) {\n case \"Home\":\n return 0;\n case \"End\":\n return count - 1;\n case \"ArrowRight\":\n return (index + 1) % count;\n case \"ArrowLeft\":\n return (index - 1 + count) % count;\n case \"ArrowDown\":\n return index + presetColumns < count ? index + presetColumns : column;\n case \"ArrowUp\":\n return index >= presetColumns ? index - presetColumns : lastInColumn;\n default:\n return undefined;\n }\n}\n\n/** A standalone colour selection surface, also composed by ColourField. */\nexport const ColourPanel = forwardRef<HTMLDivElement, ColourPanelProps>(function ColourPanel(\n { value, defaultValue, onValueChange, ...rest },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n return (\n <ColourPanelContent\n {...rest}\n ref={ref}\n colour={colour}\n current={current}\n onColourChange={commit}\n />\n );\n});\n\ninterface ColourPanelContentProps extends Omit<\n ColourPanelProps,\n \"value\" | \"defaultValue\" | \"onValueChange\"\n> {\n colour: Colour;\n current: string;\n onColourChange: (colour: Colour | string) => void;\n}\n\nexport const ColourPanelContent = forwardRef<HTMLDivElement, ColourPanelContentProps>(\n function ColourPanelContent(\n {\n colour,\n current,\n onColourChange,\n presets = noPresets,\n showPresets = true,\n picker = \"custom\",\n isDisabled = false,\n className,\n style,\n ...rest\n },\n ref,\n ) {\n const inputRef = useRef<HTMLInputElement>(null);\n const active = useRef(true);\n const disabledRef = useRef(isDisabled);\n const [isPicking, setPicking] = useState(false);\n const [pickerError, setPickerError] = useState(\"\");\n const hasEyeDropper = useSyncExternalStore(\n subscribe,\n () => Boolean(eyeDropperConstructor()),\n () => false,\n );\n const presetsId = useId();\n const hex = normaliseColour(current);\n const rgb = colourHex({ ...colour, a: 1 });\n // Equivalent spellings collapse onto the first; each preset is parsed once.\n const swatches = useMemo(() => {\n const unique = new Map<string, string>();\n for (const preset of presets) {\n const normalised = normaliseColour(preset);\n if (normalised && !unique.has(normalised)) {\n unique.set(normalised, preset);\n }\n }\n return [...unique].map(([normalised, preset]) => ({ normalised, preset }));\n }, [presets]);\n const selectedIndex = swatches.findIndex((swatch) => swatch.normalised === hex);\n useEffect(() => {\n disabledRef.current = isDisabled;\n }, [isDisabled]);\n useEffect(() => {\n active.current = true;\n return () => {\n active.current = false;\n };\n }, []);\n\n const pickFromScreen = async () => {\n const EyeDropper = eyeDropperConstructor();\n if (!EyeDropper || isDisabled || isPicking) {\n return;\n }\n setPicking(true);\n setPickerError(\"\");\n try {\n const result = await new EyeDropper().open();\n if (active.current && !disabledRef.current) {\n if (parseColour(result.sRGBHex)) {\n onColourChange({ ...colourState(result.sRGBHex, colour), a: colour.a });\n }\n }\n } catch (error) {\n if (active.current && !(error instanceof DOMException && error.name === \"AbortError\")) {\n setPickerError(\"Unable to pick a colour from the screen. Try again.\");\n }\n } finally {\n if (active.current) {\n setPicking(false);\n }\n }\n };\n\n return (\n <div\n {...rest}\n ref={ref}\n className={[\"ds-colour-panel\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n data-disabled={isDisabled || undefined}\n style={\n {\n ...style,\n \"--colour-hue\": `hsl(${colour.h} 100% 50%)`,\n \"--colour-rgb\": rgb,\n \"--colour-rgba\": colourHex(colour),\n } as CSSProperties\n }\n >\n <div className=\"ds-colour-panel__head ds-field-surface\">\n <span>Colour</span>\n <span className=\"ds-colour-panel__value\">{hex || \"No colour\"}</span>\n </div>\n {picker === \"custom\" ? (\n <>\n <ColourSquare\n colour={colour}\n isDisabled={isDisabled}\n onChange={onColourChange}\n />\n <div className=\"ds-colour-panel__hue-row\">\n {hasEyeDropper && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"pipette\"\n aria-label=\"Pick from screen\"\n isDisabled={isDisabled}\n // Busy, not pending: a pending Button disables itself and drops focus.\n aria-busy={isPicking || undefined}\n onClick={() => void pickFromScreen()}\n />\n )}\n <Slider\n className=\"ds-colour-panel__hue\"\n value={colour.h}\n min={0}\n max={360}\n step={1}\n hasValueLabel={false}\n aria-label=\"Hue\"\n aria-valuetext={`${Math.round(colour.h)} degrees`}\n isDisabled={isDisabled}\n onValueChange={(h) => onColourChange({ ...colour, h })}\n onKeyDown={(event) => {\n if (\n !event.shiftKey ||\n ![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)\n ) {\n return;\n }\n event.preventDefault();\n const delta = event.key === \"ArrowRight\" || event.key === \"ArrowUp\" ? 15 : -15;\n onColourChange({ ...colour, h: Math.max(0, Math.min(360, colour.h + delta)) });\n }}\n />\n </div>\n </>\n ) : (\n <div className=\"ds-colour-panel__native\">\n <input\n ref={inputRef}\n type=\"color\"\n value={rgb}\n tabIndex={-1}\n aria-hidden=\"true\"\n disabled={isDisabled}\n onChange={(event) => {\n if (parseColour(event.target.value)) {\n onColourChange({ ...colourState(event.target.value, colour), a: colour.a });\n }\n }}\n />\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"pipette\"\n isDisabled={isDisabled}\n onClick={() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n try {\n if (input.showPicker) {\n input.showPicker();\n } else {\n input.click();\n }\n } catch {\n input.click();\n }\n }}\n >\n Custom colour…\n </Button>\n </div>\n )}\n <div className=\"ds-colour-panel__opacity\">\n <label htmlFor={`${presetsId}-opacity`}>Opacity</label>\n <Slider\n id={`${presetsId}-opacity`}\n className=\"ds-colour-panel__alpha\"\n value={Math.round(colour.a * 100)}\n min={0}\n max={100}\n step={1}\n suffix=\"%\"\n isDisabled={isDisabled}\n onValueChange={(a) => onColourChange({ ...colour, a: a / 100 })}\n />\n </div>\n {showPresets && swatches.length > 0 && (\n <div className=\"ds-colour-panel__presets\">\n <span\n id={presetsId}\n className=\"ds-colour-panel__presets-label\"\n >\n Presets\n </span>\n <div\n className=\"ds-colour-panel__grid\"\n role=\"radiogroup\"\n aria-labelledby={presetsId}\n style={{ \"--colour-preset-columns\": presetColumns } as CSSProperties}\n onKeyDown={(event) => {\n const radios = Array.from(\n event.currentTarget.querySelectorAll<HTMLButtonElement>(\"[role='radio']\"),\n );\n const index = radios.indexOf(event.target as HTMLButtonElement);\n const next = index < 0 ? undefined : presetTarget(event.key, index, radios.length);\n if (next === undefined) {\n return;\n }\n event.preventDefault();\n radios[next]?.focus();\n radios[next]?.click();\n }}\n >\n {swatches.map(({ normalised, preset }, index) => {\n const selected = index === selectedIndex;\n return (\n <Button\n key={normalised}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n role=\"radio\"\n aria-checked={selected}\n aria-label={preset}\n title={preset}\n tabIndex={index === Math.max(0, selectedIndex) ? 0 : -1}\n isDisabled={isDisabled}\n className=\"ds-colour-panel__preset\"\n onClick={() => onColourChange(preset)}\n >\n <span\n className=\"ds-colour-swatch\"\n style={{ \"--colour-swatch\": normalised } as CSSProperties}\n >\n {selected && (\n <Icon\n name=\"check\"\n size={16}\n strokeWidth={3}\n />\n )}\n </span>\n </Button>\n );\n })}\n </div>\n </div>\n )}\n {pickerError && (\n <span\n className=\"ds-colour-panel__error\"\n role=\"status\"\n >\n {pickerError}\n </span>\n )}\n </div>\n );\n },\n);\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type CSSProperties } from \"react\";\nimport { Button } from \"../Button\";\nimport { FieldAffix } from \"../FieldAffix\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { TextField, type TextFieldProps } from \"../TextField\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { normaliseColour, parseColour } from \"./colour\";\nimport { focusAfterField, tabbableControls } from \"../../internal/dialogFocus\";\nimport { ColourPanelContent, type ColourPickerOptions } from \"./panel\";\nimport { useColourDraft, useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport { ColourPanel } from \"./panel\";\nexport type { ColourPanelProps } from \"./panel\";\n\nexport interface ColourFieldProps\n extends\n Omit<TextFieldProps, \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"children\">,\n ColourValueProps,\n ColourPickerOptions {\n isInvalid?: boolean;\n placement?: PopoverPlacement;\n /** Parsing validity; an empty value is valid and native required validation remains separate. */\n onValidityChange?: (isValid: boolean) => void;\n}\n\n/** A typed colour value and a visual picker, bound to the shared Field frame. */\nexport const ColourField = forwardRef<HTMLInputElement, ColourFieldProps>(function ColourField(\n {\n value,\n defaultValue,\n onValueChange,\n onValidityChange,\n presets,\n showPresets,\n picker,\n placement,\n isDisabled = false,\n disabled,\n readOnly,\n isInvalid,\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n onBlur,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const openerRef = useRef<HTMLElement | null>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const panelId = useId();\n const fieldId = id ?? `${panelId}-input`;\n const hex = normaliseColour(current);\n const { text, type, discard } = useColourDraft(current, hex);\n const invalid = Boolean(text.trim() && !parseColour(text));\n const effectiveDisabled = isDisabled || disabled;\n if (isOpen && (effectiveDisabled || readOnly)) {\n setOpen(false);\n }\n const visible = isOpen && !effectiveDisabled && !readOnly;\n\n useEffect(() => {\n onValidityChange?.(!invalid);\n inputRef.current?.setCustomValidity(\n invalid ? \"Enter a colour, such as #0052CC or rebeccapurple.\" : \"\",\n );\n }, [invalid, onValidityChange]);\n\n useEffect(() => {\n if (!visible) {\n return;\n }\n if (panelRef.current) {\n tabbableControls(panelRef.current)[0]?.focus({ preventScroll: true });\n }\n const outside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", outside);\n return () => document.removeEventListener(\"mousedown\", outside);\n }, [visible]);\n\n const toggle = (opener: HTMLElement) => {\n openerRef.current = opener;\n setOpen(!visible);\n };\n const close = () => {\n setOpen(false);\n openerRef.current?.focus({ preventScroll: true });\n };\n const triggerProps = {\n \"aria-label\": visible ? \"Close colour picker\" : \"Open colour picker\",\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": visible,\n \"aria-controls\": visible ? panelId : undefined,\n isDisabled: effectiveDisabled || readOnly,\n };\n\n return (\n <div\n className=\"ds-colour-field\"\n ref={rootRef}\n onBlur={(event) => {\n const target = event.relatedTarget as Node | null;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n }}\n onKeyDown={(event) => {\n if (visible && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n close();\n }\n if (!visible || event.key !== \"Tab\" || !panelRef.current?.contains(event.target as Node)) {\n return;\n }\n const controls = tabbableControls(panelRef.current);\n const atBoundary = event.shiftKey\n ? event.target === controls[0]\n : event.target === controls.at(-1);\n if (!atBoundary) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n if (event.shiftKey) {\n openerRef.current?.focus({ preventScroll: true });\n } else if (rootRef.current) {\n focusAfterField(rootRef.current);\n }\n }}\n >\n <FieldAffix\n isLeadInteractive\n isTrailInteractive\n lead={\n // A pointer shortcut only: the chevron is the one keyboard and screen\n // reader trigger. The swatch never takes focus; the input gets it back.\n <Button\n aria-hidden=\"true\"\n tabIndex={-1}\n isDisabled={triggerProps.isDisabled}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n openerRef.current = inputRef.current;\n if (visible) {\n close();\n } else {\n setOpen(true);\n }\n }}\n >\n <span\n className=\"ds-colour-swatch ds-colour-field__swatch\"\n style={{ \"--colour-swatch\": hex || \"transparent\" } as CSSProperties}\n />\n </Button>\n }\n trail={\n <Button\n {...triggerProps}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n iconStart=\"chevron-down\"\n onClick={(event) => toggle(event.currentTarget)}\n />\n }\n >\n <TextField\n {...rest}\n ref={mergeRefs(inputRef, ref)}\n id={fieldId}\n disabled={effectiveDisabled}\n readOnly={readOnly}\n spellCheck={false}\n autoComplete=\"off\"\n value={text}\n aria-invalid={invalid || isInvalid || ariaInvalid || undefined}\n aria-haspopup=\"dialog\"\n aria-controls={visible ? panelId : undefined}\n className={[\"ds-colour-field__input\", className].filter(Boolean).join(\" \")}\n onChange={(event) => {\n const next = event.target.value;\n const valid = !next.trim() || Boolean(parseColour(next));\n type(next, valid);\n if (valid) {\n commit(next);\n }\n }}\n onBlur={(event) => {\n if (!invalid) {\n discard();\n }\n onBlur?.(event);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) {\n return;\n }\n if (event.key === \"Enter\" && !invalid) {\n event.preventDefault();\n discard();\n }\n if (event.key === \"ArrowDown\" && !effectiveDisabled && !readOnly) {\n event.preventDefault();\n openerRef.current = event.currentTarget;\n setOpen(true);\n }\n }}\n />\n </FieldAffix>\n <Popover\n anchorRef={inputRef}\n anchorId={fieldId}\n isOpen={visible}\n align=\"start\"\n placement={placement}\n panelRef={panelRef}\n id={panelId}\n role=\"dialog\"\n aria-label=\"Choose a colour\"\n // A click on the padding or a label focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n className=\"ds-colour-field__popover\"\n >\n <ColourPanelContent\n colour={colour}\n current={hex}\n presets={presets}\n showPresets={showPresets}\n picker={picker}\n onColourChange={(next) => {\n discard();\n commit(next);\n }}\n />\n </Popover>\n </div>\n );\n});\n"],"mappings":"A,0aASA,SAAS2C,EAAM,EAAe,CAC5B,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,IAAKC,CAAK,CAAC,CACzC,CAEA,SAAgBC,EAAa,CAAE,SAAQ,aAAY,YAA+B,CAChF,IAAMC,GAAA,EAAW9C,EAAAA,OAAAA,CAAsB,IAAI,EACrC+C,EAAU,GAAwC,CACtD,IAAMC,EAAOC,EAAM,cAAc,sBAAsB,EAClDD,EAAK,OAAUA,EAAK,QAGzBE,EAAS,CACP,GAAGC,EACH,EAAGR,GAAQM,EAAM,QAAUD,EAAK,MAAQA,EAAK,MAAS,GAAG,EACzD,EAAGL,GAAO,GAAKM,EAAM,QAAUD,EAAK,KAAOA,EAAK,QAAU,GAAG,CAC/D,CAAC,CACH,EAqBA,OACE,EAAAN,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,0BACV,KAAK,SACL,SAAUU,EAAa,GAAK,EAC5B,aAAW,4BACX,gBAAe,EACf,gBAAe,IACf,gBAAe,KAAK,MAAMD,EAAO,CAAC,EAClC,iBAAgB,cAAc,KAAK,MAAMA,EAAO,CAAC,EAAE,gBAAgB,KAAK,MAAMA,EAAO,CAAC,EAAE,GACxF,gBAAeC,GAAc,IAAA,GAC7B,UA/Be,GAAyB,CAC1C,GAAIA,EACF,OAEF,IAAMC,EAAOJ,EAAM,SAAW,GAAK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ACA,OAAS,GAAU,CACZ8D,GACHkB,EAAQ,EAEVC,IAAS/F,CAAK,CAChB,EACA,UAAY,GAAU,CACpBgG,IAAYhG,CAAK,EACb,GAAM,mBAGNA,EAAM,MAAQ,SAAW,CAAC4E,IAC5B5E,EAAM,eAAe,EACrB8F,EAAQ,GAEN9F,EAAM,MAAQ,aAAe,CAAC8E,GAAqB,CAACE,IACtDhF,EAAM,eAAe,EACrB,EAAU,QAAUA,EAAM,cAC1BoE,EAAQ,EAAI,GAEhB,CACD,CAAA,CACS,CAAA,GACZ,EAAA3E,EAAA,IAAA,CAACX,EAAAA,QAAD,CACE,UAAWoD,EACX,SAAUwC,EACV,OAAQO,EACR,MAAM,QACK,YACD,WACV,GAAIR,EACJ,KAAK,SACL,aAAW,kBAGX,SAAU,GACV,UAAU,2BAEV,UAAA,EAAAhF,EAAA,IAAA,CAACuC,EAAD,CACU,SACR,QAASnB,EACA,UACI,cACL,SACR,eAAiB,GAAS,CACxBiF,EAAQ,EACR7D,EAAOnB,CAAI,CACb,CACD,CAAA,CACM,CAAA,CACN,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"ColourField-DFvRASVe.cjs","names":["useRef","useState","colourState","normaliseColour","colourHex","forwardRef","useRef","useState","useSyncExternalStore","useId","normaliseColour","colourHex","useMemo","parseColour","colourState","_Fragment","Button","Slider","Icon","forwardRef","useState","useOverlayOpen","useRef","useId","normaliseColour","parseColour","tabbableControls","FieldAffix","Button","TextField","mergeRefs","Popover","require_colour","require_Icon","require_components_Button_index","require_mergeRefs","require_overlayLayer","require_components_TextField_index","require_components_Popover_index","require_components_FieldAffix_index","require_Slider","react","react_jsx_runtime","clamp","value","ColourSquare","dragging","update","rect","event","onChange","colour","isDisabled","step","change","useColourValue","internal","setInternal","defaultValue","current","selection","setSelection","hex","next","onValueChange","useColourDraft","draft","setDraft","isValid","eyeDropperConstructor","subscribe","noPresets","presetColumns","presetTarget","column","index","lastInColumn","count","key","ColourPanel","rest","ColourPanelContent","commit","inputRef","active","disabledRef","isPicking","setPicking","pickerError","setPickerError","hasEyeDropper","presetsId","rgb","swatches","unique","preset","presets","normalised","selectedIndex","swatch","pickFromScreen","EyeDropper","result","onColourChange","error","className","style","picker","delta","input","a","showPresets","radios","selected","ColourField","ariaInvalid","open","setOpen","isOpen","rootRef","openerRef","panelRef","panelId","fieldId","id","invalid","text","effectiveDisabled","disabled","readOnly","visible","onValidityChange","outside","target","toggle","opener","close","triggerProps","controls","ref","isInvalid","valid","type","discard","onBlur","onKeyDown"],"sources":["../../src/components/ColourField/square.tsx","../../src/components/ColourField/value.ts","../../src/components/ColourField/panel.tsx","../../src/components/ColourField/index.tsx"],"sourcesContent":["import { useRef, type KeyboardEvent, type PointerEvent } from \"react\";\nimport type { Colour } from \"./colour\";\n\ninterface ColourSquareProps {\n colour: Colour;\n isDisabled: boolean;\n onChange: (colour: Colour) => void;\n}\n\nfunction clamp(value: number) {\n return Math.max(0, Math.min(100, value));\n}\n\nexport function ColourSquare({ colour, isDisabled, onChange }: ColourSquareProps) {\n const dragging = useRef<number | null>(null);\n const update = (event: PointerEvent<HTMLDivElement>) => {\n const rect = event.currentTarget.getBoundingClientRect();\n if (!rect.width || !rect.height) {\n return;\n }\n onChange({\n ...colour,\n s: clamp(((event.clientX - rect.left) / rect.width) * 100),\n v: clamp((1 - (event.clientY - rect.top) / rect.height) * 100),\n });\n };\n const handleKey = (event: KeyboardEvent) => {\n if (isDisabled) {\n return;\n }\n const step = event.shiftKey ? 10 : 1;\n const changes: Record<string, Partial<Colour>> = {\n ArrowLeft: { s: clamp(colour.s - step) },\n ArrowRight: { s: clamp(colour.s + step) },\n ArrowDown: { v: clamp(colour.v - step) },\n ArrowUp: { v: clamp(colour.v + step) },\n Home: { s: 0 },\n End: { s: 100 },\n };\n const change = changes[event.key];\n if (!change) {\n return;\n }\n event.preventDefault();\n onChange({ ...colour, ...change });\n };\n return (\n <div\n className=\"ds-colour-panel__square\"\n role=\"slider\"\n tabIndex={isDisabled ? -1 : 0}\n aria-label=\"Saturation and brightness\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={Math.round(colour.s)}\n aria-valuetext={`Saturation ${Math.round(colour.s)}%, brightness ${Math.round(colour.v)}%`}\n aria-disabled={isDisabled || undefined}\n onKeyDown={handleKey}\n onPointerDown={(event) => {\n if (isDisabled || event.button !== 0) {\n return;\n }\n event.preventDefault();\n event.currentTarget.focus();\n dragging.current = event.pointerId;\n event.currentTarget.setPointerCapture(event.pointerId);\n update(event);\n }}\n onPointerMove={(event) => {\n if (!isDisabled && dragging.current === event.pointerId) {\n update(event);\n }\n }}\n onPointerUp={(event) => {\n if (dragging.current !== event.pointerId) {\n return;\n }\n dragging.current = null;\n event.currentTarget.releasePointerCapture(event.pointerId);\n }}\n onPointerCancel={() => {\n dragging.current = null;\n }}\n onLostPointerCapture={() => {\n dragging.current = null;\n }}\n >\n <span\n className=\"ds-colour-panel__thumb\"\n style={{ left: `${colour.s}%`, top: `${100 - colour.v}%` }}\n />\n </div>\n );\n}\n","import { useState } from \"react\";\nimport { colourHex, colourState, normaliseColour, type Colour } from \"./colour\";\n\nexport interface ColourValueProps {\n value?: string;\n defaultValue?: string;\n /** Uppercase hex (including alpha when needed), or an empty string when cleared. */\n onValueChange?: (value: string) => void;\n}\n\nexport function useColourValue({ value, defaultValue = \"\", onValueChange }: ColourValueProps) {\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n const [selection, setSelection] = useState(() => ({\n source: current,\n colour: colourState(current),\n }));\n let colour = selection.colour;\n if (selection.source !== current) {\n colour = colourState(current, colour);\n setSelection({ source: current, colour });\n }\n\n const commit = (next: string | Colour) => {\n const hex = typeof next === \"string\" ? normaliseColour(next) : colourHex(next);\n setSelection({\n source: hex,\n colour: typeof next === \"string\" ? colourState(next, colour) : next,\n });\n if (value === undefined) {\n setInternal(hex);\n }\n onValueChange?.(hex);\n };\n\n return { current, colour, commit };\n}\n\n/** Typed text the field shows until it is committed, blurred, or replaced. */\nexport function useColourDraft(current: string, hex: string) {\n const [draft, setDraft] = useState<{ source: string; text: string } | null>(null);\n // A draft belongs to the value it was typed over. A parent that stores the invalid\n // text (FormEditor does) takes it over, so restoring the earlier value then wins.\n if (draft && draft.source !== current && draft.text === current) {\n setDraft({ source: current, text: current });\n }\n const text = draft?.source === current ? draft.text : hex || current;\n /** Valid text becomes the committed hex; invalid text stays over the current value. */\n const type = (next: string, isValid: boolean) =>\n setDraft({ source: isValid ? normaliseColour(next) : current, text: next });\n return { text, type, discard: () => setDraft(null) };\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n type CSSProperties,\n type HTMLAttributes,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Slider } from \"../Slider\";\nimport { colourHex, colourState, normaliseColour, parseColour, type Colour } from \"./colour\";\nimport { ColourSquare } from \"./square\";\nimport { useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport interface ColourPickerOptions {\n presets?: string[];\n showPresets?: boolean;\n picker?: \"custom\" | \"native\";\n isDisabled?: boolean;\n}\n\nexport interface ColourPanelProps\n extends\n Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\">,\n ColourValueProps,\n ColourPickerOptions {}\n\ninterface EyeDropperInstance {\n open: () => Promise<{ sRGBHex: string }>;\n}\nfunction eyeDropperConstructor() {\n return (window as Window & { EyeDropper?: new () => EyeDropperInstance }).EyeDropper;\n}\nconst subscribe = () => () => {};\nconst noPresets: string[] = [];\nconst presetColumns = 8;\n\n/** Where a key moves within the preset grid; rows wrap within their column. */\nfunction presetTarget(key: string, index: number, count: number) {\n const column = index % presetColumns;\n const lastInColumn = column + Math.floor((count - 1 - column) / presetColumns) * presetColumns;\n switch (key) {\n case \"Home\":\n return 0;\n case \"End\":\n return count - 1;\n case \"ArrowRight\":\n return (index + 1) % count;\n case \"ArrowLeft\":\n return (index - 1 + count) % count;\n case \"ArrowDown\":\n return index + presetColumns < count ? index + presetColumns : column;\n case \"ArrowUp\":\n return index >= presetColumns ? index - presetColumns : lastInColumn;\n default:\n return undefined;\n }\n}\n\n/** A standalone colour selection surface, also composed by ColourField. */\nexport const ColourPanel = forwardRef<HTMLDivElement, ColourPanelProps>(function ColourPanel(\n { value, defaultValue, onValueChange, ...rest },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n return (\n <ColourPanelContent\n {...rest}\n ref={ref}\n colour={colour}\n current={current}\n onColourChange={commit}\n />\n );\n});\n\ninterface ColourPanelContentProps extends Omit<\n ColourPanelProps,\n \"value\" | \"defaultValue\" | \"onValueChange\"\n> {\n colour: Colour;\n current: string;\n onColourChange: (colour: Colour | string) => void;\n}\n\nexport const ColourPanelContent = forwardRef<HTMLDivElement, ColourPanelContentProps>(\n function ColourPanelContent(\n {\n colour,\n current,\n onColourChange,\n presets = noPresets,\n showPresets = true,\n picker = \"custom\",\n isDisabled = false,\n className,\n style,\n ...rest\n },\n ref,\n ) {\n const inputRef = useRef<HTMLInputElement>(null);\n const active = useRef(true);\n const disabledRef = useRef(isDisabled);\n const [isPicking, setPicking] = useState(false);\n const [pickerError, setPickerError] = useState(\"\");\n const hasEyeDropper = useSyncExternalStore(\n subscribe,\n () => Boolean(eyeDropperConstructor()),\n () => false,\n );\n const presetsId = useId();\n const hex = normaliseColour(current);\n const rgb = colourHex({ ...colour, a: 1 });\n // Equivalent spellings collapse onto the first; each preset is parsed once.\n const swatches = useMemo(() => {\n const unique = new Map<string, string>();\n for (const preset of presets) {\n const normalised = normaliseColour(preset);\n if (normalised && !unique.has(normalised)) {\n unique.set(normalised, preset);\n }\n }\n return [...unique].map(([normalised, preset]) => ({ normalised, preset }));\n }, [presets]);\n const selectedIndex = swatches.findIndex((swatch) => swatch.normalised === hex);\n useEffect(() => {\n disabledRef.current = isDisabled;\n }, [isDisabled]);\n useEffect(() => {\n active.current = true;\n return () => {\n active.current = false;\n };\n }, []);\n\n const pickFromScreen = async () => {\n const EyeDropper = eyeDropperConstructor();\n if (!EyeDropper || isDisabled || isPicking) {\n return;\n }\n setPicking(true);\n setPickerError(\"\");\n try {\n const result = await new EyeDropper().open();\n if (active.current && !disabledRef.current) {\n if (parseColour(result.sRGBHex)) {\n onColourChange({ ...colourState(result.sRGBHex, colour), a: colour.a });\n }\n }\n } catch (error) {\n if (active.current && !(error instanceof DOMException && error.name === \"AbortError\")) {\n setPickerError(\"Unable to pick a colour from the screen. Try again.\");\n }\n } finally {\n if (active.current) {\n setPicking(false);\n }\n }\n };\n\n return (\n <div\n {...rest}\n ref={ref}\n className={[\"ds-colour-panel\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n data-disabled={isDisabled || undefined}\n style={\n {\n ...style,\n \"--colour-hue\": `hsl(${colour.h} 100% 50%)`,\n \"--colour-rgb\": rgb,\n \"--colour-rgba\": colourHex(colour),\n } as CSSProperties\n }\n >\n <div className=\"ds-colour-panel__head ds-field-surface\">\n <span>Colour</span>\n <span className=\"ds-colour-panel__value\">{hex || \"No colour\"}</span>\n </div>\n {picker === \"custom\" ? (\n <>\n <ColourSquare\n colour={colour}\n isDisabled={isDisabled}\n onChange={onColourChange}\n />\n <div className=\"ds-colour-panel__hue-row\">\n {hasEyeDropper && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"pipette\"\n aria-label=\"Pick from screen\"\n isDisabled={isDisabled}\n // Busy, not pending: a pending Button disables itself and drops focus.\n aria-busy={isPicking || undefined}\n onClick={() => void pickFromScreen()}\n />\n )}\n <Slider\n className=\"ds-colour-panel__hue\"\n value={colour.h}\n min={0}\n max={360}\n step={1}\n hasValueLabel={false}\n aria-label=\"Hue\"\n aria-valuetext={`${Math.round(colour.h)} degrees`}\n isDisabled={isDisabled}\n onValueChange={(h) => onColourChange({ ...colour, h })}\n onKeyDown={(event) => {\n if (\n !event.shiftKey ||\n ![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)\n ) {\n return;\n }\n event.preventDefault();\n const delta = event.key === \"ArrowRight\" || event.key === \"ArrowUp\" ? 15 : -15;\n onColourChange({ ...colour, h: Math.max(0, Math.min(360, colour.h + delta)) });\n }}\n />\n </div>\n </>\n ) : (\n <div className=\"ds-colour-panel__native\">\n <input\n ref={inputRef}\n type=\"color\"\n value={rgb}\n tabIndex={-1}\n aria-hidden=\"true\"\n disabled={isDisabled}\n onChange={(event) => {\n if (parseColour(event.target.value)) {\n onColourChange({ ...colourState(event.target.value, colour), a: colour.a });\n }\n }}\n />\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"pipette\"\n isDisabled={isDisabled}\n onClick={() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n try {\n if (input.showPicker) {\n input.showPicker();\n } else {\n input.click();\n }\n } catch {\n input.click();\n }\n }}\n >\n Custom colour…\n </Button>\n </div>\n )}\n <div className=\"ds-colour-panel__opacity\">\n <label htmlFor={`${presetsId}-opacity`}>Opacity</label>\n <Slider\n id={`${presetsId}-opacity`}\n className=\"ds-colour-panel__alpha\"\n value={Math.round(colour.a * 100)}\n min={0}\n max={100}\n step={1}\n suffix=\"%\"\n isDisabled={isDisabled}\n onValueChange={(a) => onColourChange({ ...colour, a: a / 100 })}\n />\n </div>\n {showPresets && swatches.length > 0 && (\n <div className=\"ds-colour-panel__presets\">\n <span\n id={presetsId}\n className=\"ds-colour-panel__presets-label\"\n >\n Presets\n </span>\n <div\n className=\"ds-colour-panel__grid\"\n role=\"radiogroup\"\n aria-labelledby={presetsId}\n style={{ \"--colour-preset-columns\": presetColumns } as CSSProperties}\n onKeyDown={(event) => {\n const radios = Array.from(\n event.currentTarget.querySelectorAll<HTMLButtonElement>(\"[role='radio']\"),\n );\n const index = radios.indexOf(event.target as HTMLButtonElement);\n const next = index < 0 ? undefined : presetTarget(event.key, index, radios.length);\n if (next === undefined) {\n return;\n }\n event.preventDefault();\n radios[next]?.focus();\n radios[next]?.click();\n }}\n >\n {swatches.map(({ normalised, preset }, index) => {\n const selected = index === selectedIndex;\n return (\n <Button\n key={normalised}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n role=\"radio\"\n aria-checked={selected}\n aria-label={preset}\n title={preset}\n tabIndex={index === Math.max(0, selectedIndex) ? 0 : -1}\n isDisabled={isDisabled}\n className=\"ds-colour-panel__preset\"\n onClick={() => onColourChange(preset)}\n >\n <span\n className=\"ds-colour-swatch\"\n style={{ \"--colour-swatch\": normalised } as CSSProperties}\n >\n {selected && (\n <Icon\n name=\"check\"\n size={16}\n strokeWidth={3}\n />\n )}\n </span>\n </Button>\n );\n })}\n </div>\n </div>\n )}\n {pickerError && (\n <span\n className=\"ds-colour-panel__error\"\n role=\"status\"\n >\n {pickerError}\n </span>\n )}\n </div>\n );\n },\n);\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type CSSProperties } from \"react\";\nimport { Button } from \"../Button\";\nimport { FieldAffix } from \"../FieldAffix\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { TextField, type TextFieldProps } from \"../TextField\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { normaliseColour, parseColour } from \"./colour\";\nimport { focusAfterField, tabbableControls } from \"../../internal/dialogFocus\";\nimport { ColourPanelContent, type ColourPickerOptions } from \"./panel\";\nimport { useColourDraft, useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport { ColourPanel } from \"./panel\";\nexport type { ColourPanelProps } from \"./panel\";\n\nexport interface ColourFieldProps\n extends\n Omit<TextFieldProps, \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"children\">,\n ColourValueProps,\n ColourPickerOptions {\n isInvalid?: boolean;\n placement?: PopoverPlacement;\n /** Parsing validity; an empty value is valid and native required validation remains separate. */\n onValidityChange?: (isValid: boolean) => void;\n}\n\n/** A typed colour value and a visual picker, bound to the shared Field frame. */\nexport const ColourField = forwardRef<HTMLInputElement, ColourFieldProps>(function ColourField(\n {\n value,\n defaultValue,\n onValueChange,\n onValidityChange,\n presets,\n showPresets,\n picker,\n placement,\n isDisabled = false,\n disabled,\n readOnly,\n isInvalid,\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n onBlur,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const openerRef = useRef<HTMLElement | null>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const panelId = useId();\n const fieldId = id ?? `${panelId}-input`;\n const hex = normaliseColour(current);\n const { text, type, discard } = useColourDraft(current, hex);\n const invalid = Boolean(text.trim() && !parseColour(text));\n const effectiveDisabled = isDisabled || disabled;\n if (isOpen && (effectiveDisabled || readOnly)) {\n setOpen(false);\n }\n const visible = isOpen && !effectiveDisabled && !readOnly;\n\n useEffect(() => {\n onValidityChange?.(!invalid);\n inputRef.current?.setCustomValidity(\n invalid ? \"Enter a colour, such as #0052CC or rebeccapurple.\" : \"\",\n );\n }, [invalid, onValidityChange]);\n\n useEffect(() => {\n if (!visible) {\n return;\n }\n if (panelRef.current) {\n tabbableControls(panelRef.current)[0]?.focus({ preventScroll: true });\n }\n const outside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", outside);\n return () => document.removeEventListener(\"mousedown\", outside);\n }, [visible]);\n\n const toggle = (opener: HTMLElement) => {\n openerRef.current = opener;\n setOpen(!visible);\n };\n const close = () => {\n setOpen(false);\n openerRef.current?.focus({ preventScroll: true });\n };\n const triggerProps = {\n \"aria-label\": visible ? \"Close colour picker\" : \"Open colour picker\",\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": visible,\n \"aria-controls\": visible ? panelId : undefined,\n isDisabled: effectiveDisabled || readOnly,\n };\n\n return (\n <div\n className=\"ds-colour-field\"\n ref={rootRef}\n onBlur={(event) => {\n const target = event.relatedTarget as Node | null;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n }}\n onKeyDown={(event) => {\n if (visible && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n close();\n }\n if (!visible || event.key !== \"Tab\" || !panelRef.current?.contains(event.target as Node)) {\n return;\n }\n const controls = tabbableControls(panelRef.current);\n const atBoundary = event.shiftKey\n ? event.target === controls[0]\n : event.target === controls.at(-1);\n if (!atBoundary) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n if (event.shiftKey) {\n openerRef.current?.focus({ preventScroll: true });\n } else if (rootRef.current) {\n focusAfterField(rootRef.current);\n }\n }}\n >\n <FieldAffix\n isLeadInteractive\n isTrailInteractive\n lead={\n // A pointer shortcut only: the chevron is the one keyboard and screen\n // reader trigger. The swatch never takes focus; the input gets it back.\n <Button\n aria-hidden=\"true\"\n tabIndex={-1}\n isDisabled={triggerProps.isDisabled}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n openerRef.current = inputRef.current;\n if (visible) {\n close();\n } else {\n setOpen(true);\n }\n }}\n >\n <span\n className=\"ds-colour-swatch ds-colour-field__swatch\"\n style={{ \"--colour-swatch\": hex || \"transparent\" } as CSSProperties}\n />\n </Button>\n }\n trail={\n <Button\n {...triggerProps}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n iconStart=\"chevron-down\"\n onClick={(event) => toggle(event.currentTarget)}\n />\n }\n >\n <TextField\n {...rest}\n ref={mergeRefs(inputRef, ref)}\n id={fieldId}\n disabled={effectiveDisabled}\n readOnly={readOnly}\n spellCheck={false}\n autoComplete=\"off\"\n value={text}\n aria-invalid={invalid || isInvalid || ariaInvalid || undefined}\n aria-haspopup=\"dialog\"\n aria-controls={visible ? panelId : undefined}\n className={[\"ds-colour-field__input\", className].filter(Boolean).join(\" \")}\n onChange={(event) => {\n const next = event.target.value;\n const valid = !next.trim() || Boolean(parseColour(next));\n type(next, valid);\n if (valid) {\n commit(next);\n }\n }}\n onBlur={(event) => {\n if (!invalid) {\n discard();\n }\n onBlur?.(event);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) {\n return;\n }\n if (event.key === \"Enter\" && !invalid) {\n event.preventDefault();\n discard();\n }\n if (event.key === \"ArrowDown\" && !effectiveDisabled && !readOnly) {\n event.preventDefault();\n openerRef.current = event.currentTarget;\n setOpen(true);\n }\n }}\n />\n </FieldAffix>\n <Popover\n anchorRef={inputRef}\n anchorId={fieldId}\n isOpen={visible}\n align=\"start\"\n placement={placement}\n panelRef={panelRef}\n id={panelId}\n role=\"dialog\"\n aria-label=\"Choose a colour\"\n // A click on the padding or a label focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n className=\"ds-colour-field__popover\"\n >\n <ColourPanelContent\n colour={colour}\n current={hex}\n presets={presets}\n showPresets={showPresets}\n picker={picker}\n onColourChange={(next) => {\n discard();\n commit(next);\n }}\n />\n </Popover>\n </div>\n );\n});\n"],"mappings":"A,0aASA,SAAS2C,EAAM,EAAe,CAC5B,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,IAAKC,CAAK,CAAC,CACzC,CAEA,SAAgBC,EAAa,CAAE,SAAQ,aAAY,YAA+B,CAChF,IAAMC,GAAA,EAAW9C,EAAAA,OAAAA,CAAsB,IAAI,EACrC+C,EAAU,GAAwC,CACtD,IAAMC,EAAOC,EAAM,cAAc,sBAAsB,EAClDD,EAAK,OAAUA,EAAK,QAGzBE,EAAS,CACP,GAAGC,EACH,EAAGR,GAAQM,EAAM,QAAUD,EAAK,MAAQA,EAAK,MAAS,GAAG,EACzD,EAAGL,GAAO,GAAKM,EAAM,QAAUD,EAAK,KAAOA,EA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,EACA,WACV,WAAY,GACZ,aAAa,MACb,MAAOD,EACP,eAAcD,GAAWe,GAAazB,GAAe,IAAA,GACrD,gBAAc,SACd,gBAAee,EAAUR,EAAU,IAAA,GACnC,UAAW,CAAC,yBAA0BjB,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EACzE,SAAW,GAAU,CACnB,IAAM1C,EAAOd,EAAM,OAAO,MACpB4F,EAAQ,CAAC9E,EAAK,KAAK,GAAK,EAAQtC,EAAAA,EAAYsC,CAAI,EACtD+E,EAAK/E,EAAM8E,CAAK,EACZA,GACF3D,EAAOnB,CAAI,CAEf,EACA,OAAS,GAAU,CACZ8D,GACHkB,EAAQ,EAEVC,IAAS/F,CAAK,CAChB,EACA,UAAY,GAAU,CACpBgG,IAAYhG,CAAK,EACb,GAAM,mBAGNA,EAAM,MAAQ,SAAW,CAAC4E,IAC5B5E,EAAM,eAAe,EACrB8F,EAAQ,GAEN9F,EAAM,MAAQ,aAAe,CAAC8E,GAAqB,CAACE,IACtDhF,EAAM,eAAe,EACrB,EAAU,QAAUA,EAAM,cAC1BoE,EAAQ,EAAI,GAEhB,CACD,CAAA,CACS,CAAA,GACZ,EAAA3E,EAAA,IAAA,CAACX,EAAAA,QAAD,CACE,UAAWoD,EACX,SAAUwC,EACV,OAAQO,EACR,MAAM,QACK,YACD,WACV,GAAIR,EACJ,KAAK,SACL,aAAW,kBAGX,SAAU,GACV,UAAU,2BAEV,UAAA,EAAAhF,EAAA,IAAA,CAACuC,EAAD,CACU,SACR,QAASnB,EACA,UACI,cACL,SACR,eAAiB,GAAS,CACxBiF,EAAQ,EACR7D,EAAOnB,CAAI,CACb,CACD,CAAA,CACM,CAAA,CACN,C,EAET,CAAC,E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./Icon-
|
|
2
|
-
//# sourceMappingURL=DatePicker-
|
|
1
|
+
const e=require("./Icon-3ucBRgrd.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-iGhuAByk.cjs");;/* empty css */const r=require("../components/Popover/index.cjs"),i=require("./binding-tMjrUzkU.cjs");let a=require("react"),o=require("react/jsx-runtime");function s(e){let t=`${e.getMonth()+1}`.padStart(2,`0`),n=`${e.getDate()}`.padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function c(e){if(!e||!/^\d{4}-\d{2}-\d{2}$/.test(e))return null;let[t,n,r]=e.split(`-`).map(Number);if(!t||!n||!r)return null;let i=new Date(t,n-1,r);return Number.isNaN(i.getTime())||s(i)!==e?null:i}function l(e){return c(e)!==null}function u(e){let t=c(e);return t?t.toLocaleDateString(`en-GB`,{day:`numeric`,month:`long`,year:`numeric`}):``}function d(...e){return e.filter(Boolean).join(` `)}var f=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function p(e,t,n){let r=c(e)?e:s(new Date);return t&&r<t?t:n&&r>n?n:r}function m(e){return e.toLocaleDateString(`en-GB`,{month:`long`,year:`numeric`})}function h(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7;return new Date(t.getFullYear(),t.getMonth(),1-n)}function g(e,t,n){return e?`primary`:t?`active`:n?`neutral`:`simple`}var _=(0,a.forwardRef)(function({value:e,endValue:n,onSelect:r,min:l,max:_,className:v,...y},b){let[x,S]=(0,a.useState)(()=>p(e,l,_)),[C,w]=(0,a.useState)(()=>c(x)??new Date),T=(0,a.useRef)(null),E=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(!c(e))return;let t=p(e,l,_),n=c(t)??new Date;S(t),w(new Date(n.getFullYear(),n.getMonth(),1))},[e,l,_]),(0,a.useEffect)(()=>{E.current&&(E.current=!1,T.current?.querySelector(`[data-focused]`)?.focus())},[x]);let D=Array.from({length:42},(e,t)=>{let n=h(C);return new Date(n.getFullYear(),n.getMonth(),n.getDate()+t)}),O=s(new Date),k=e=>{let t=new Date(C.getFullYear(),C.getMonth()+e,1);w(t),S(s(t))},A=e=>{let t=c(x)??new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()+e);E.current=!0,S(s(n)),w(new Date(n.getFullYear(),n.getMonth(),1))},j=e=>{let t={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7,PageUp:-28,PageDown:28}[e.key];t!==void 0&&(e.preventDefault(),A(t))};return(0,o.jsxs)(`div`,{ref:b,className:d(`ds-calendar`,`ds-field-surface`,v),...i.n(y),children:[(0,o.jsxs)(`div`,{className:`ds-calendar__head ds-field-surface`,children:[(0,o.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`chevron-left`,"aria-label":`Previous month`,onClick:()=>k(-1)}),(0,o.jsx)(`span`,{className:`ds-calendar__month`,children:m(C)}),(0,o.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`chevron-right`,"aria-label":`Next month`,onClick:()=>k(1)})]}),(0,o.jsx)(`div`,{className:`ds-calendar__weekdays`,"aria-hidden":`true`,children:f.map(e=>(0,o.jsx)(`span`,{children:e.slice(0,2)},e))}),(0,o.jsx)(`div`,{ref:T,className:`ds-calendar__grid`,role:`grid`,onKeyDown:j,children:Array.from({length:6},(i,a)=>(0,o.jsx)(`div`,{role:`row`,className:`ds-calendar__row`,children:D.slice(a*7,a*7+7).map(i=>{let a=s(i),c=i.getMonth()!==C.getMonth(),d=l&&a<l||_&&a>_,f=!!(e&&n&&a>e&&a<n),p=a===e||a===n;return(0,o.jsx)(t.Button,{variant:g(p,f,a===O),size:`sm`,isIconOnly:!0,role:`gridcell`,"aria-label":u(a),tabIndex:a===x?0:-1,isDisabled:!!d,"aria-selected":p||void 0,"data-outside":c||void 0,"data-today":a===O||void 0,"data-in-range":f||void 0,"data-focused":a===x||void 0,className:`ds-calendar__day`,onClick:()=>{S(a),r?.(a)},children:i.getDate()},a)})},a))})]})});function v({value:s,defaultValue:c=``,onValueChange:l,size:f=`md`,placeholder:p=`Pick a date`,placement:m,min:h,max:g,isDisabled:v=!1,isInvalid:y=!1,isClearable:b=!1,clearLabel:x=`Clear date`,"aria-invalid":S,id:C,className:w,...T}){let[E,D]=(0,a.useState)(c),O=s??E,[k,A]=(0,a.useState)(!1),j=n.o(k),M=(0,a.useRef)(null),N=(0,a.useRef)(null),P=(0,a.useRef)(null),F=(0,a.useId)(),I=C??F;return j&&v&&A(!1),(0,a.useEffect)(()=>{if(!j)return;let e=P.current;(e?.querySelector(`[data-focused]:not(:disabled)`)??e)?.focus();let t=e=>{let t=e.target;!M.current?.contains(t)&&!P.current?.contains(t)&&A(!1)};return document.addEventListener(`mousedown`,t),()=>document.removeEventListener(`mousedown`,t)},[j]),(0,o.jsxs)(`div`,{className:d(`ds-datefield`,w),ref:M,onKeyDown:e=>{j&&e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),A(!1),N.current?.focus())},children:[(0,o.jsxs)(t.Button,{...i.n(T),ref:N,id:I,size:f,"aria-haspopup":`dialog`,"aria-expanded":j,"aria-invalid":y||S||void 0,isDisabled:v,"data-placeholder":O?void 0:``,className:`ds-field-skin ds-datefield__control`,onClick:()=>A(e=>!e),children:[(0,o.jsx)(`span`,{className:`ds-datefield__value`,children:O?u(O):p}),(0,o.jsx)(e.t,{name:`calendar`,size:16,className:`ds-datefield__glyph`})]}),b&&O&&(0,o.jsx)(t.Button,{variant:`simple`,size:f,isIconOnly:!0,iconStart:`x`,"aria-label":x,isDisabled:v,onClick:()=>{s===void 0&&D(``),l?.(``),A(!1),N.current?.focus()}}),(0,o.jsx)(r.Popover,{anchorRef:N,placement:m,anchorId:I,isOpen:j,align:`start`,panelRef:P,className:`ds-datefield__popover`,role:`dialog`,"aria-label":`Choose a date`,tabIndex:-1,children:(0,o.jsx)(_,{value:O,min:h,max:g,onSelect:e=>{s===void 0&&D(e),l?.(e),A(!1),N.current?.focus()}})})]})}function y(e,t,n){return c(e)?t?n===`min`?e>t?e:t:e<t?e:t:e:t}function b({value:e,defaultValue:t={start:``,end:``},onValueChange:n,size:r=`md`,min:s,max:c,isDisabled:l=!1,isClearable:u=!1,startLabel:f=`Start date`,endLabel:p=`End date`,placement:m,className:h,...g}){let[_,b]=(0,a.useState)(t),x=e??_,S=t=>{e===void 0&&b(t),n?.(t)},{attributes:C}=i.r(g);return(0,o.jsxs)(`div`,{...C,className:d(`ds-daterange`,h),children:[(0,o.jsx)(v,{"aria-invalid":g[`aria-invalid`],"aria-label":f,placement:m,size:r,value:x.start,min:s,max:y(x.end,c,`max`),isDisabled:l,isClearable:u,clearLabel:`Clear ${f}`,placeholder:f,onValueChange:e=>S({...x,start:e})}),(0,o.jsx)(`span`,{className:`ds-daterange__dash`,"aria-hidden":`true`,children:`–`}),(0,o.jsx)(v,{"aria-invalid":g[`aria-invalid`],"aria-label":p,placement:m,size:r,value:x.end,min:y(x.start,s,`min`),max:c,isDisabled:l,isClearable:u,clearLabel:`Clear ${p}`,placeholder:p,onValueChange:e=>S({...x,end:e})})]})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return _}});
|
|
2
|
+
//# sourceMappingURL=DatePicker-ClOqS6oH.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker-CCygKPuy.cjs","names":["forwardRef","useState","useRef","omitRequired","Button","useOverlayOpen","useId","Icon","Popover","useGroupBinding","require_Icon","require_components_Button_index","require_overlayLayer","require_components_Popover_index","require_binding","react","react_jsx_runtime","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","rest","focused","setFocused","setMonth","gridRef","shouldFocus","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":"A,ySAGA,SAAgBiB,EAAM,EAAqB,CACzC,IAAMC,EAAQ,GAAGC,EAAK,SAAS,EAAI,IAAI,SAAS,EAAG,GAAG,EAChDC,EAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,EAAG,GAAG,EAC/C,MAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE,GAC3C,CAEA,SAAgBC,EAAQ,EAAwC,CAC9D,GAAI,CAACC,GAAS,CAAC,sBAAsB,KAAKA,CAAK,EAC7C,OAAO,KAET,GAAM,CAACC,EAAML,EAAOE,GAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,EACtD,GAAI,CAACC,GAAQ,CAACL,GAAS,CAACE,EACtB,OAAO,KAET,IAAMD,EAAO,IAAI,KAAKI,EAAML,EAAQ,EAAGE,CAAG,EAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CAAC,GAAKF,EAAME,CAAI,IAAMG,EAAQ,KAAOH,CACxE,CAGA,SAAgBK,EA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jD,GAAS8C,EAEnB2B,EAAU,GAAyB,CACnCzE,IAAU,IAAA,IACZ+C,EAAYtB,CAAI,EAElByC,IAAgBzC,CAAI,CACtB,EACM,CAAE,cAAetC,EAAAA,EAAgBqF,CAAO,EAE9C,OACE,EAAA9E,EAAA,KAAA,CAAC,MAAD,CACE,GAAIgF,EACJ,UAAWtE,EAAG,eAAgBiC,CAAS,EAFzC,SAAA,EAIE,EAAA3C,EAAA,IAAA,CAACkD,EAAD,CACE,eAAc4B,EAAQ,gBACtB,aAAYG,EACD,YACL,OACN,MAAO1B,EAAQ,MACV,MACL,IAAKkB,EAAWlB,EAAQ,IAAKxC,EAAK,KAAK,EAC3B,aACC,cACb,WAAY,SAASkE,IACrB,YAAaA,EACb,cAAgB,GAASF,EAAO,CAAE,GAAGxB,EAAS,MAAOxB,CAAK,CAAC,CAC5D,CAAA,GACD,EAAA/B,EAAA,IAAA,CAAC,OAAD,CACE,UAAU,qBACV,cAAY,OACb,SAAA,GAEK,CAAA,GACN,EAAAA,EAAA,IAAA,CAACkD,EAAD,CACE,eAAc4B,EAAQ,gBACtB,aAAYI,EACD,YACL,OACN,MAAO3B,EAAQ,IACf,IAAKkB,EAAWlB,EAAQ,MAAOzC,EAAK,KAAK,EACpC,MACO,aACC,cACb,WAAY,SAASoE,IACrB,YAAaA,EACb,cAAgB,GAASH,EAAO,CAAE,GAAGxB,EAAS,IAAKxB,CAAK,CAAC,CAC1D,CAAA,CACE,C,EAET,C"}
|
|
1
|
+
{"version":3,"file":"DatePicker-ClOqS6oH.cjs","names":["forwardRef","useState","useRef","omitRequired","Button","useOverlayOpen","useId","Icon","Popover","useGroupBinding","require_Icon","require_components_Button_index","require_overlayLayer","require_components_Popover_index","require_binding","react","react_jsx_runtime","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","rest","focused","setFocused","setMonth","gridRef","shouldFocus","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":"A,ySAGA,SAAgBiB,EAAM,EAAqB,CACzC,IAAMC,EAAQ,GAAGC,EAAK,SAAS,EAAI,IAAI,SAAS,EAAG,GAAG,EAChDC,EAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,EAAG,GAAG,EAC/C,MAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE,GAC3C,CAEA,SAAgBC,EAAQ,EAAwC,CAC9D,GAAI,CAACC,GAAS,CAAC,sBAAsB,KAAKA,CAAK,EAC7C,OAAO,KAET,GAAM,CAACC,EAAML,EAAOE,GAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,EACtD,GAAI,CAACC,GAAQ,CAACL,GAAS,CAACE,EACtB,OAAO,KAET,IAAMD,EAAO,IAAI,KAAKI,EAAML,EAAQ,EAAGE,CAAG,EAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CA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1B,EAAUC,IAAA,EAAepE,EAAAA,SAAAA,CAAyBqE,CAAY,EAC/DC,EAAUjD,GAAS8C,EAEnB2B,EAAU,GAAyB,CACnCzE,IAAU,IAAA,IACZ+C,EAAYtB,CAAI,EAElByC,IAAgBzC,CAAI,CACtB,EACM,CAAE,cAAetC,EAAAA,EAAgBqF,CAAO,EAE9C,OACE,EAAA9E,EAAA,KAAA,CAAC,MAAD,CACE,GAAIgF,EACJ,UAAWtE,EAAG,eAAgBiC,CAAS,EAFzC,SAAA,EAIE,EAAA3C,EAAA,IAAA,CAACkD,EAAD,CACE,eAAc4B,EAAQ,gBACtB,aAAYG,EACD,YACL,OACN,MAAO1B,EAAQ,MACV,MACL,IAAKkB,EAAWlB,EAAQ,IAAKxC,EAAK,KAAK,EAC3B,aACC,cACb,WAAY,SAASkE,IACrB,YAAaA,EACb,cAAgB,GAASF,EAAO,CAAE,GAAGxB,EAAS,MAAOxB,CAAK,CAAC,CAC5D,CAAA,GACD,EAAA/B,EAAA,IAAA,CAAC,OAAD,CACE,UAAU,qBACV,cAAY,OACb,SAAA,GAEK,CAAA,GACN,EAAAA,EAAA,IAAA,CAACkD,EAAD,CACE,eAAc4B,EAAQ,gBACtB,aAAYI,EACD,YACL,OACN,MAAO3B,EAAQ,IACf,IAAKkB,EAAWlB,EAAQ,MAAOzC,EAAK,KAAK,EACpC,MACO,aACC,cACb,WAAY,SAASoE,IACrB,YAAaA,EACb,cAAgB,GAASH,EAAO,CAAE,GAAGxB,EAAS,IAAKxB,CAAK,CAAC,CAC1D,CAAA,CACE,C,EAET,C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "./Icon-
|
|
1
|
+
import { t as e } from "./Icon-dPXyBYe5.js";
|
|
2
2
|
import { Button as t } from "../components/Button/index.js";
|
|
3
3
|
import { o as n } from "./overlayLayer-lU4iWSjO.js";
|
|
4
4
|
/* empty css */
|
|
@@ -295,4 +295,4 @@ function E({ value: e, defaultValue: t = {
|
|
|
295
295
|
//#endregion
|
|
296
296
|
export { h as a, g as i, w as n, E as r, C as t };
|
|
297
297
|
|
|
298
|
-
//# sourceMappingURL=DatePicker-
|
|
298
|
+
//# sourceMappingURL=DatePicker-LqaePc57.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker-CHJYSaLU.js","names":["Icon","useOverlayOpen","omitRequired","useGroupBinding","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","forwardRef","rest","focused","setFocused","useState","setMonth","gridRef","useRef","shouldFocus","useEffect","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","Button","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","useId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","Popover","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAGA,SAAgBI,EAAM,GAAqB;CACzC,IAAMC,IAAQ,GAAGC,EAAK,SAAS,IAAI,IAAI,SAAS,GAAG,GAAG,GAChDC,IAAM,GAAGD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B,CAAI,GAElB2C,IAAgB3C,CAAI;CACtB,GACM,EAAE,kBAAenC,EAAgBqF,CAAO;CAE9C,OACE,kBAAC,OAAD;EACE,GAAIE;EACJ,WAAW7E,EAAG,gBAAgBqC,CAAS;EAFzC,UAAA;GAIE,kBAACQ,GAAD;IACE,gBAAc8B,EAAQ;IACtB,cAAYG;IACD;IACL;IACN,OAAO5B,EAAQ;IACV;IACL,KAAKoB,EAAWpB,EAAQ,KAAK7C,GAAK,KAAK;IAC3B;IACC;IACb,YAAY,SAASyE;IACrB,aAAaA;IACb,gBAAgB,MAASF,EAAO;KAAE,GAAG1B;KAAS,OAAOzB;IAAK,CAAC;GAC5D,CAAA;GACD,kBAAC,QAAD;IACE,WAAU;IACV,eAAY;IACb,UAAA;GAEK,CAAA;GACN,kBAACoB,GAAD;IACE,gBAAc8B,EAAQ;IACtB,cAAYI;IACD;IACL;IACN,OAAO7B,EAAQ;IACf,KAAKoB,EAAWpB,EAAQ,OAAO9C,GAAK,KAAK;IACpC;IACO;IACC;IACb,YAAY,SAAS2E;IACrB,aAAaA;IACb,gBAAgB,MAASH,EAAO;KAAE,GAAG1B;KAAS,KAAKzB;IAAK,CAAC;GAC1D,CAAA;EACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"DatePicker-LqaePc57.js","names":["Icon","useOverlayOpen","omitRequired","useGroupBinding","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","forwardRef","rest","focused","setFocused","useState","setMonth","gridRef","useRef","shouldFocus","useEffect","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","Button","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","useId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","Popover","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAGA,SAAgBI,EAAM,GAAqB;CACzC,IAAMC,IAAQ,GAAGC,EAAK,SAAS,IAAI,IAAI,SAAS,GAAG,GAAG,GAChDC,IAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,GAAG,GAAG;CAC/C,OAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE;AAC3C;AAEA,SAAgBC,EAAQ,GAAwC;CAC9D,IAAI,CAACC,KAAS,CAAC,sBAAsB,KAAKA,CAAK,GAC7C,OAAO;CAET,IAAM,CAACC,GAAML,GAAOE,KAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CACtD,IAAI,CAACC,KAAQ,CAACL,KAAS,CAACE,GACtB,OAAO;CAET,IAAMD,IAAO,IAAI,KAAKI,GAAML,IAAQ,GAAGE,CAAG;CAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CAAC,KAAKF,EAAME,CAAI,MAAMG,IAAQ,OAAOH;AACxE;AAGA,SAAgBK,EAAU,GAAe;CACvC,OAAOH,EAAQC,CAAK,MAAM;AAC5B;AAGA,SAAgBG,EAAc,GAAmC;CAC/D,IAAMN,IAAOE,EAAQC,CAAK;CAI1B,OAHKH,IAGEA,EAAK,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AAY,SAAS2E;IACrB,aAAaA;IACb,gBAAgB,MAASH,EAAO;KAAE,GAAG1B;KAAS,KAAKzB;IAAK,CAAC;GAC1D,CAAA;EACE;;AAET"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../components/Button/index.cjs"),t=require("./use-picker-session-
|
|
2
|
-
//# sourceMappingURL=EntryPicker-
|
|
1
|
+
const e=require("../components/Button/index.cjs"),t=require("./use-picker-session-ouqHBmVA.cjs"),n=require("./style-nulIa2_8.cjs"),r=require("../components/SortableList/index.cjs");let i=require("react"),a=require("react/jsx-runtime");function o({items:n,selected:o,onChange:s,onEdit:c,isDisabled:l,canReorder:u,emptyLabel:d}){let f=(0,i.useId)(),p=(e,n)=>t.f(e)?`${f}-reason-${n}`:void 0,m=(n,r)=>(0,a.jsxs)(`span`,{className:`ds-entry-picker__item-actions`,children:[(0,a.jsx)(t.u,{item:n}),(0,a.jsx)(t.c,{item:n,onEdit:n.tone===`removed`?void 0:c,isDisabled:l}),(0,a.jsx)(e.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${n.title}`,"aria-describedby":r,isDisabled:l,onClick:()=>s(o.filter(e=>e!==n.id))})]});return n.length===0?(0,a.jsx)(`p`,{className:`ds-entry-picker__empty`,children:d}):u?(0,a.jsx)(r.SortableList,{items:o,onReorder:s,isDisabled:l,children:n.map((e,n)=>(0,a.jsx)(r.SortableListItem,{id:e.id,label:e.title,"data-tone":e.tone,handleDescribedBy:p(e,n),action:m(e,p(e,n)),children:(0,a.jsx)(`div`,{className:`ds-entry`,children:(0,a.jsx)(t.d,{item:e,reasonId:p(e,n)})})},e.id))}):(0,a.jsx)(`ul`,{className:`ds-entry-picker__list`,children:n.map((e,n)=>(0,a.jsxs)(`li`,{className:`ds-entry-picker__row ds-field-surface`,"data-tone":e.tone,children:[(0,a.jsx)(`div`,{className:`ds-entry`,children:(0,a.jsx)(t.d,{item:e,reasonId:p(e,n)})}),m(e,p(e,n))]},e.id))})}var s=[];function c({items:r=s,value:c,defaultValue:l=[],onValueChange:u,mode:d=`multiple`,max:f,label:p=`Entries`,emptyLabel:m=`Nothing selected yet.`,addLabel:h=`Choose entries`,itemLabel:g=`entry`,itemsLabel:_=`entries`,isReorderable:v=!0,isDisabled:y=!1,loadPage:b,pageSize:x=10,resolveItem:S,onEditItem:C,onCreate:w,isCreating:T=!1,refreshKey:E,dialogTitle:D,dialogDescription:O,isDialogHidden:k=!1,className:A,...j}){let[M,N]=(0,i.useState)(l),P=c??M,[F,I]=(0,i.useState)(!1),L=t.t(P,r,{resolveItem:S,refreshKey:E,loadPage:b,pageSize:x,mode:d,max:f,onEditItem:C},{isOpen:F,isDisabled:y,itemLabel:g,itemsLabel:_,close:()=>I(!1)}),{selection:R,remote:z,cap:B,editItem:V}=L,H=t.a(`Couldn't load selected ${_}`,R.status,R.error,R.retry),U=e=>{y||(c===void 0&&N(e),u?.(e))},W=(e,t)=>{R.remember([t],L.revision,e),U(e)},G=e=>{let t=L.choice(e);t&&(d===`single`?(W(P[0]===e?[]:[e],t),I(!1)):P.includes(e)?U(P.filter(t=>t!==e)):W([...P,e],t))},{known:K,failures:q}=R,J=!!S,Y=(0,i.useMemo)(()=>t.s({selected:P,items:r,pageItems:z.items,known:K,failures:q,hasResolver:J,itemLabel:g}),[P,r,z.items,K,q,J,g]);return(0,a.jsxs)(n.t,{...j,className:[`ds-entry-picker`,A].filter(Boolean).join(` `),label:p,count:t.n(d,P.length,f),limit:j.limit===void 0?B.limit:j.limit,children:[(0,a.jsx)(o,{items:Y,selected:P,onChange:U,onEdit:V,isDisabled:y,canReorder:v&&d===`multiple`&&Y.length>1,emptyLabel:m}),H,(0,a.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,a.jsx)(e.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:y,onClick:()=>I(!0),children:h}),P.length>0&&(0,a.jsx)(e.Button,{variant:`simple`,size:`sm`,isDisabled:y,onClick:()=>U([]),children:`Clear`})]}),(0,a.jsx)(t.i,{...L.dialog,isOpen:F,onClose:()=>I(!1),onToggle:G,addLabel:h,onCreate:w,isCreating:T,dialogTitle:D,dialogDescription:O,isDialogHidden:k})]})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}});
|
|
2
|
+
//# sourceMappingURL=EntryPicker-B4dAsObz.cjs.map
|