@sereno-ds/ui 0.42.1 → 0.44.0
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/README.md +16 -3
- package/dist/core/ActionCard.d.ts +1 -1
- package/dist/core/ActionCard.js +9 -8
- package/dist/core/ActionCard.js.map +1 -1
- package/dist/core/Button.d.ts +1 -9
- package/dist/core/Button.js +1 -22
- package/dist/core/Button.js.map +1 -1
- package/dist/forms/Autocomplete.js +3 -4
- package/dist/forms/Autocomplete.js.map +1 -1
- package/dist/forms/AvatarUpload.js +1 -4
- package/dist/forms/AvatarUpload.js.map +1 -1
- package/dist/forms/Checkbox.js +6 -5
- package/dist/forms/Checkbox.js.map +1 -1
- package/dist/forms/DatePicker.js +2 -1
- package/dist/forms/DatePicker.js.map +1 -1
- package/dist/forms/Input.js +5 -15
- package/dist/forms/Input.js.map +1 -1
- package/dist/forms/Radio.js +6 -5
- package/dist/forms/Radio.js.map +1 -1
- package/dist/forms/SearchInput.js.map +1 -1
- package/dist/forms/Select.js +3 -1
- package/dist/forms/Select.js.map +1 -1
- package/dist/forms/Textarea.js +6 -17
- package/dist/forms/Textarea.js.map +1 -1
- package/dist/forms/_internal/choiceVars.d.ts +9 -0
- package/dist/forms/_internal/choiceVars.js +7 -0
- package/dist/forms/_internal/choiceVars.js.map +1 -0
- package/dist/forms/_internal/fieldBoxStyle.d.ts +6 -2
- package/dist/forms/_internal/fieldBoxStyle.js +6 -4
- package/dist/forms/_internal/fieldBoxStyle.js.map +1 -1
- package/dist/forms/_internal/fieldFrame.d.ts +26 -0
- package/dist/forms/_internal/fieldFrame.js +11 -0
- package/dist/forms/_internal/fieldFrame.js.map +1 -0
- package/dist/navigation/SidebarNav.js +10 -3
- package/dist/navigation/SidebarNav.js.map +1 -1
- package/dist/navigation/_internal/SidebarNavItems.js +14 -31
- package/dist/navigation/_internal/SidebarNavItems.js.map +1 -1
- package/dist/styles.css +77 -3
- package/package.json +1 -1
package/dist/forms/Select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/Select.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { acquireScrollLock } from '../_internal/scrollLock';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface SelectOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/**\n * Single-choice select - a hand-rolled listbox (token-styled, full keyboard\n * support) so it looks and behaves the same in every browser. On a mouse it's\n * an anchored dropdown; on touch it opens as a bottom sheet with finger-sized\n * rows.\n *\n * Value contract: `value` / `defaultValue` + `onValueChange(value)` - a plain\n * string, not a DOM event.\n */\nexport interface SelectProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n options?: SelectOption[];\n /** Shown in muted text on the trigger when nothing is selected. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value. */\n value?: string;\n /** Uncontrolled initial value. */\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /** Form field name - mirrored to a hidden input so the value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the trigger. Only needed when there's no visible\n * `label` (e.g. a compact row where the context is already clear visually,\n * a day name next to a \"start time\" / \"end time\" pair): `Field` only\n * renders a `<label>` when `label` is set, so without either the trigger\n * has no accessible name at all. Takes precedence over `label` if both are\n * set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n}\n\n// ── Custom listbox ──────────────────────────────────────────────────────────\nfunction CustomSelect({\n rid,\n label,\n ariaLabel,\n options,\n value,\n placeholder,\n size,\n error,\n disabled,\n coarse,\n fieldAria,\n onCommit,\n}: {\n rid: string;\n /** The field label - shown as the sheet header on touch so the picker has context. */\n label?: string;\n /** Falls back to `label` when there's no visible one at all. */\n ariaLabel?: string;\n options: SelectOption[];\n value: string;\n placeholder?: string;\n size: NonNullable<SelectProps['size']>;\n error: boolean;\n disabled?: boolean;\n /** Touch: open as a bottom sheet with finger-sized rows instead of a dropdown. */\n coarse: boolean;\n /** `aria-invalid` / `aria-describedby` tying the trigger to the field's hint / error line. */\n fieldAria: ReturnType<typeof fieldA11y>;\n onCommit: (v: string) => void;\n}) {\n const listboxId = `${rid}-listbox`;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const panelRef = React.useRef<HTMLUListElement>(null);\n const typeahead = React.useRef<{ str: string; timer: number }>({ str: '', timer: 0 });\n // A <label htmlFor> forwards a fully-trusted click to this button (detail:1),\n // indistinguishable from a direct one - but its *pointerdown* landed on the\n // label, not here. So only toggle when the press actually started on the box.\n const pressedAt = React.useRef(0);\n\n const [open, setOpen] = React.useState(false);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n // Where the dropdown sits (inline under the field, or portalled to the body inside a Dialog): see\n // `useMenuPlacement`. The touch sheet needs no anchoring.\n const place = useMenuPlacement({\n open,\n disabled: coarse,\n anchorRef: triggerRef,\n panelRef,\n itemCount: options.length,\n onDismiss: () => setOpen(false),\n });\n\n const selectedIndex = options.findIndex((o) => o.value === value);\n const selected = selectedIndex >= 0 ? options[selectedIndex] : undefined;\n\n const firstEnabled = () => options.findIndex((o) => !o.disabled);\n const lastEnabled = () => {\n for (let i = options.length - 1; i >= 0; i--) if (!options[i].disabled) return i;\n return -1;\n };\n const nextEnabled = (from: number, dir: 1 | -1) => {\n let i = from;\n for (let step = 0; step < options.length; step++) {\n i += dir;\n if (i < 0 || i >= options.length) return from;\n if (!options[i].disabled) return i;\n }\n return from;\n };\n\n // Close on outside pointerdown (the touch sheet uses its own scrim instead).\n useOutsidePress(open && !coarse, [triggerRef, panelRef], () => setOpen(false));\n\n // The touch sheet is a modal surface - lock the page scroll behind it. Through the shared lock,\n // so a Select inside a Dialog (two held at once) frees the page whichever lets go first.\n React.useEffect(() => {\n if (!open || !coarse) return;\n return acquireScrollLock();\n }, [open, coarse]);\n\n // Keep the active option in view, the first time the list opens too (SS-568): see `useRevealActive`.\n useRevealActive(open, activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null, place);\n\n const openMenu = () => {\n if (disabled) return;\n setActiveIndex(selectedIndex >= 0 ? selectedIndex : firstEnabled());\n setOpen(true);\n };\n const closeMenu = (refocus = true) => {\n setOpen(false);\n if (refocus) triggerRef.current?.focus({ preventScroll: true });\n };\n const choose = (i: number) => {\n const o = options[i];\n if (!o || o.disabled) return;\n onCommit(o.value);\n closeMenu();\n };\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (disabled) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) return openMenu();\n setActiveIndex((i) => nextEnabled(i < 0 ? -1 : i, 1));\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) return openMenu();\n setActiveIndex((i) => nextEnabled(i < 0 ? options.length : i, -1));\n return;\n case 'Home':\n if (open) {\n e.preventDefault();\n setActiveIndex(firstEnabled());\n }\n return;\n case 'End':\n if (open) {\n e.preventDefault();\n setActiveIndex(lastEnabled());\n }\n return;\n case 'Enter':\n case ' ':\n e.preventDefault();\n if (!open) return openMenu();\n choose(activeIndex);\n return;\n case 'Escape':\n if (open) {\n e.preventDefault();\n // Only the list closes: a Dialog around the field keeps its own Esc for the next press.\n // (`stopImmediate...` too: React may listen on `document`, where the Dialog listens as well.)\n e.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n closeMenu();\n }\n return;\n case 'Tab':\n if (open) setOpen(false);\n return;\n default:\n if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {\n const ta = typeahead.current;\n ta.str += e.key.toLowerCase();\n window.clearTimeout(ta.timer);\n ta.timer = window.setTimeout(() => (ta.str = ''), 500);\n const match = options.findIndex((o) => !o.disabled && o.label.toLowerCase().startsWith(ta.str));\n if (match >= 0) {\n if (!open) openMenu();\n setActiveIndex(match);\n }\n }\n }\n };\n\n const hasValue = !!selected;\n const rowPadY = menuRowPadY(coarse, size);\n\n const listStyleBase: React.CSSProperties = { ...menuSurfaceStyle(size), ...menuListStyle };\n const optionRows = options.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === value}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n onPointerEnter={() => !o.disabled && setActiveIndex(i)}\n onClick={() => choose(i)}\n />\n ));\n\n return (\n <div style={sx({ position: 'relative', width: '100%' })}>\n <button\n ref={triggerRef}\n type=\"button\"\n id={rid}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n aria-disabled={disabled || undefined}\n disabled={disabled}\n onPointerDown={() => {\n pressedAt.current = Date.now();\n }}\n onMouseDown={(e) => {\n // Take focus without the browser scrolling us into view.\n e.preventDefault();\n triggerRef.current?.focus({ preventScroll: true });\n }}\n onClick={() => {\n // Only toggle when the press started on this button - a click forwarded\n // from the field <label>, or synthesised by the keyboard, never set\n // pressedAt (keyboard is handled in onKeyDown).\n if (Date.now() - pressedAt.current > 500) return;\n pressedAt.current = 0;\n if (open) closeMenu(false);\n else openMenu();\n }}\n onKeyDown={onKeyDown}\n style={fieldBoxStyle(size, error, open, !!disabled)}\n >\n <span\n style={sx({\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: hasValue ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {hasValue ? selected!.label : placeholder ?? 'Select…'}\n </span>\n <span\n aria-hidden=\"true\"\n style={sx({\n display: 'flex',\n flex: '0 0 auto',\n color: 'var(--text-muted)',\n transition: 'transform var(--duration-fast) var(--ease-standard)',\n transform: open ? 'rotate(180deg)' : 'none',\n })}\n >\n <ChevronDown size={16} strokeWidth={1.75} />\n </span>\n </button>\n\n {open && mounted && coarse &&\n createPortal(\n <div\n role=\"presentation\"\n onClick={() => closeMenu()}\n style={sx({\n position: 'fixed',\n inset: 0,\n zIndex: 1100,\n display: 'flex',\n alignItems: 'flex-end',\n background: 'var(--bg-overlay)',\n backdropFilter: 'blur(2px)',\n animation: 'sereno-fade-in var(--duration-fast) var(--ease-standard)',\n })}\n >\n <div\n onClick={(e) => e.stopPropagation()}\n style={sx({\n width: '100%',\n maxHeight: '70dvh',\n display: 'flex',\n flexDirection: 'column',\n background: 'var(--bg-surface)',\n borderRadius: 'var(--radius-sheet) var(--radius-sheet) 0 0',\n boxShadow: 'var(--shadow-sheet)',\n paddingBottom: 'env(safe-area-inset-bottom)',\n animation: 'sereno-slide-up var(--duration-sheet) var(--ease-gentle)',\n })}\n >\n {label && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-base)',\n fontWeight: 'var(--weight-semibold)',\n letterSpacing: 'var(--tracking-snug)',\n color: 'var(--text-primary)',\n })}\n >\n {label}\n </div>\n )}\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={label}\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n flex: '1 1 auto',\n minHeight: 0,\n border: 'none',\n borderRadius: 0,\n boxShadow: 'none',\n background: 'transparent',\n padding: 'var(--space-2)',\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {optionRows}\n </ul>\n </div>\n </div>,\n document.body,\n )}\n {open && !coarse && place && place.strategy === 'inline' && (\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n maxHeight: place.maxH,\n zIndex: 100,\n })}\n >\n {optionRows}\n </ul>\n )}\n {open && !coarse && mounted && place && place.strategy === 'fixed' &&\n createPortal(\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n maxHeight: place.maxH,\n zIndex: 1100,\n })}\n >\n {optionRows}\n </ul>,\n document.body,\n )}\n </div>\n );\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the selected\n * value (rendered only when `name` is set - pass it, as `register()` does).\n * Enough for `getValues()` / `trigger()` / `setFocus()`, but a plain\n * `{...register(name)}` spread still won't validate on change: this hidden\n * input never dispatches a native `input`/`change` event, and `onValueChange`\n * hands back a plain string, not a `ChangeEvent` - wire it through\n * `Controller`, or call the registered `onChange` yourself from\n * `onValueChange`.\n */\nexport const Select = React.forwardRef<HTMLInputElement, SelectProps>(function Select({\n label,\n hint,\n error,\n required,\n options = [],\n placeholder,\n size = 'md',\n disabled,\n value: valueProp,\n defaultValue,\n onValueChange,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n}: SelectProps, ref) {\n const reactId = React.useId();\n const rid = id || reactId;\n const isControlled = valueProp !== undefined;\n const [internalValue, setInternalValue] = React.useState(defaultValue ?? '');\n const value = isControlled ? valueProp! : internalValue;\n const coarse = useCoarsePointer();\n\n const commit = React.useCallback(\n (v: string) => {\n if (!isControlled) setInternalValue(v);\n onValueChange?.(v);\n },\n [isControlled, onValueChange],\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <CustomSelect\n rid={rid}\n label={label}\n ariaLabel={ariaLabel}\n options={options}\n value={value}\n placeholder={placeholder}\n size={size}\n error={!!error}\n disabled={disabled}\n coarse={coarse}\n fieldAria={fieldA11y(rid, { hint, error, required })}\n onCommit={commit}\n />\n {name && <input ref={ref} type=\"hidden\" name={name} value={value} />}\n </Field>\n );\n});\n\nSelect.displayName = 'Select';\n"],"mappings":";AAyOI,cAgBE,YAhBF;AAvOJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,YAAY,eAAe,aAAa,wBAAwB;AACzE,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAoD9B,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAiBG;AACD,QAAM,YAAY,GAAG,GAAG;AACxB,QAAM,aAAa,MAAM,OAA0B,IAAI;AACvD,QAAM,WAAW,MAAM,OAAyB,IAAI;AACpD,QAAM,YAAY,MAAM,OAAuC,EAAE,KAAK,IAAI,OAAO,EAAE,CAAC;AAIpF,QAAM,YAAY,MAAM,OAAO,CAAC;AAEhC,QAAM,CAAC,MAAM,OAA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iBAAiB;AAEhC,QAAM,SAAS,MAAM;AAAA,IACnB,CAAC,MAAc;AACb,UAAI,CAAC,aAAc,kBAAiB,CAAC;AACrC,sBAAgB,CAAC;AAAA,IACnB;AAAA,IACA,CAAC,cAAc,aAAa;AAAA,EAC9B;AAEA,SACE,qBAAC,SAAM,OAAc,MAAY,OAAc,UAAoB,iBAAe,MAAC,SAAS,KAAK,OAAO,gBAAgB,qBACtH;AAAA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,CAAC,CAAC;AAAA,QACT;AAAA,QACA;AAAA,QACA,WAAW,UAAU,KAAK,EAAE,MAAM,OAAO,SAAS,CAAC;AAAA,QACnD,UAAU;AAAA;AAAA,IACZ;AAAA,IACC,QAAQ,oBAAC,WAAM,KAAU,MAAK,UAAS,MAAY,OAAc;AAAA,KACpE;AAEJ,CAAC;AAED,OAAO,cAAc;","names":["Select"]}
|
|
1
|
+
{"version":3,"sources":["../../src/forms/Select.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { acquireScrollLock } from '../_internal/scrollLock';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\nimport { fieldBoxProps } from './_internal/fieldFrame';\n\nexport interface SelectOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/**\n * Single-choice select - a hand-rolled listbox (token-styled, full keyboard\n * support) so it looks and behaves the same in every browser. On a mouse it's\n * an anchored dropdown; on touch it opens as a bottom sheet with finger-sized\n * rows.\n *\n * Value contract: `value` / `defaultValue` + `onValueChange(value)` - a plain\n * string, not a DOM event.\n */\nexport interface SelectProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n options?: SelectOption[];\n /** Shown in muted text on the trigger when nothing is selected. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value. */\n value?: string;\n /** Uncontrolled initial value. */\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /** Form field name - mirrored to a hidden input so the value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the trigger. Only needed when there's no visible\n * `label` (e.g. a compact row where the context is already clear visually,\n * a day name next to a \"start time\" / \"end time\" pair): `Field` only\n * renders a `<label>` when `label` is set, so without either the trigger\n * has no accessible name at all. Takes precedence over `label` if both are\n * set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n}\n\n// ── Custom listbox ──────────────────────────────────────────────────────────\nfunction CustomSelect({\n rid,\n label,\n ariaLabel,\n options,\n value,\n placeholder,\n size,\n error,\n disabled,\n coarse,\n fieldAria,\n onCommit,\n}: {\n rid: string;\n /** The field label - shown as the sheet header on touch so the picker has context. */\n label?: string;\n /** Falls back to `label` when there's no visible one at all. */\n ariaLabel?: string;\n options: SelectOption[];\n value: string;\n placeholder?: string;\n size: NonNullable<SelectProps['size']>;\n error: boolean;\n disabled?: boolean;\n /** Touch: open as a bottom sheet with finger-sized rows instead of a dropdown. */\n coarse: boolean;\n /** `aria-invalid` / `aria-describedby` tying the trigger to the field's hint / error line. */\n fieldAria: ReturnType<typeof fieldA11y>;\n onCommit: (v: string) => void;\n}) {\n const listboxId = `${rid}-listbox`;\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const panelRef = React.useRef<HTMLUListElement>(null);\n const typeahead = React.useRef<{ str: string; timer: number }>({ str: '', timer: 0 });\n // A <label htmlFor> forwards a fully-trusted click to this button (detail:1),\n // indistinguishable from a direct one - but its *pointerdown* landed on the\n // label, not here. So only toggle when the press actually started on the box.\n const pressedAt = React.useRef(0);\n\n const [open, setOpen] = React.useState(false);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n // Where the dropdown sits (inline under the field, or portalled to the body inside a Dialog): see\n // `useMenuPlacement`. The touch sheet needs no anchoring.\n const place = useMenuPlacement({\n open,\n disabled: coarse,\n anchorRef: triggerRef,\n panelRef,\n itemCount: options.length,\n onDismiss: () => setOpen(false),\n });\n\n const selectedIndex = options.findIndex((o) => o.value === value);\n const selected = selectedIndex >= 0 ? options[selectedIndex] : undefined;\n\n const firstEnabled = () => options.findIndex((o) => !o.disabled);\n const lastEnabled = () => {\n for (let i = options.length - 1; i >= 0; i--) if (!options[i].disabled) return i;\n return -1;\n };\n const nextEnabled = (from: number, dir: 1 | -1) => {\n let i = from;\n for (let step = 0; step < options.length; step++) {\n i += dir;\n if (i < 0 || i >= options.length) return from;\n if (!options[i].disabled) return i;\n }\n return from;\n };\n\n // Close on outside pointerdown (the touch sheet uses its own scrim instead).\n useOutsidePress(open && !coarse, [triggerRef, panelRef], () => setOpen(false));\n\n // The touch sheet is a modal surface - lock the page scroll behind it. Through the shared lock,\n // so a Select inside a Dialog (two held at once) frees the page whichever lets go first.\n React.useEffect(() => {\n if (!open || !coarse) return;\n return acquireScrollLock();\n }, [open, coarse]);\n\n // Keep the active option in view, the first time the list opens too (SS-568): see `useRevealActive`.\n useRevealActive(open, activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null, place);\n\n const openMenu = () => {\n if (disabled) return;\n setActiveIndex(selectedIndex >= 0 ? selectedIndex : firstEnabled());\n setOpen(true);\n };\n const closeMenu = (refocus = true) => {\n setOpen(false);\n if (refocus) triggerRef.current?.focus({ preventScroll: true });\n };\n const choose = (i: number) => {\n const o = options[i];\n if (!o || o.disabled) return;\n onCommit(o.value);\n closeMenu();\n };\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (disabled) return;\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) return openMenu();\n setActiveIndex((i) => nextEnabled(i < 0 ? -1 : i, 1));\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) return openMenu();\n setActiveIndex((i) => nextEnabled(i < 0 ? options.length : i, -1));\n return;\n case 'Home':\n if (open) {\n e.preventDefault();\n setActiveIndex(firstEnabled());\n }\n return;\n case 'End':\n if (open) {\n e.preventDefault();\n setActiveIndex(lastEnabled());\n }\n return;\n case 'Enter':\n case ' ':\n e.preventDefault();\n if (!open) return openMenu();\n choose(activeIndex);\n return;\n case 'Escape':\n if (open) {\n e.preventDefault();\n // Only the list closes: a Dialog around the field keeps its own Esc for the next press.\n // (`stopImmediate...` too: React may listen on `document`, where the Dialog listens as well.)\n e.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n closeMenu();\n }\n return;\n case 'Tab':\n if (open) setOpen(false);\n return;\n default:\n if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {\n const ta = typeahead.current;\n ta.str += e.key.toLowerCase();\n window.clearTimeout(ta.timer);\n ta.timer = window.setTimeout(() => (ta.str = ''), 500);\n const match = options.findIndex((o) => !o.disabled && o.label.toLowerCase().startsWith(ta.str));\n if (match >= 0) {\n if (!open) openMenu();\n setActiveIndex(match);\n }\n }\n }\n };\n\n const hasValue = !!selected;\n const rowPadY = menuRowPadY(coarse, size);\n\n const listStyleBase: React.CSSProperties = { ...menuSurfaceStyle(size), ...menuListStyle };\n const optionRows = options.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === value}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n onPointerEnter={() => !o.disabled && setActiveIndex(i)}\n onClick={() => choose(i)}\n />\n ));\n\n return (\n <div style={sx({ position: 'relative', width: '100%' })}>\n <button\n ref={triggerRef}\n type=\"button\"\n id={rid}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n aria-disabled={disabled || undefined}\n disabled={disabled}\n onPointerDown={() => {\n pressedAt.current = Date.now();\n }}\n onMouseDown={(e) => {\n // Take focus without the browser scrolling us into view.\n e.preventDefault();\n triggerRef.current?.focus({ preventScroll: true });\n }}\n onClick={() => {\n // Only toggle when the press started on this button - a click forwarded\n // from the field <label>, or synthesised by the keyboard, never set\n // pressedAt (keyboard is handled in onKeyDown).\n if (Date.now() - pressedAt.current > 500) return;\n pressedAt.current = 0;\n if (open) closeMenu(false);\n else openMenu();\n }}\n onKeyDown={onKeyDown}\n {...fieldBoxProps(open)}\n style={fieldBoxStyle(size, error, !!disabled)}\n >\n <span\n style={sx({\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: hasValue ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {hasValue ? selected!.label : placeholder ?? 'Select…'}\n </span>\n <span\n aria-hidden=\"true\"\n style={sx({\n display: 'flex',\n flex: '0 0 auto',\n color: 'var(--text-muted)',\n transition: 'transform var(--duration-fast) var(--ease-standard)',\n transform: open ? 'rotate(180deg)' : 'none',\n })}\n >\n <ChevronDown size={16} strokeWidth={1.75} />\n </span>\n </button>\n\n {open && mounted && coarse &&\n createPortal(\n <div\n role=\"presentation\"\n onClick={() => closeMenu()}\n style={sx({\n position: 'fixed',\n inset: 0,\n zIndex: 1100,\n display: 'flex',\n alignItems: 'flex-end',\n background: 'var(--bg-overlay)',\n backdropFilter: 'blur(2px)',\n animation: 'sereno-fade-in var(--duration-fast) var(--ease-standard)',\n })}\n >\n <div\n onClick={(e) => e.stopPropagation()}\n style={sx({\n width: '100%',\n maxHeight: '70dvh',\n display: 'flex',\n flexDirection: 'column',\n background: 'var(--bg-surface)',\n borderRadius: 'var(--radius-sheet) var(--radius-sheet) 0 0',\n boxShadow: 'var(--shadow-sheet)',\n paddingBottom: 'env(safe-area-inset-bottom)',\n animation: 'sereno-slide-up var(--duration-sheet) var(--ease-gentle)',\n })}\n >\n {label && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-base)',\n fontWeight: 'var(--weight-semibold)',\n letterSpacing: 'var(--tracking-snug)',\n color: 'var(--text-primary)',\n })}\n >\n {label}\n </div>\n )}\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={label}\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n flex: '1 1 auto',\n minHeight: 0,\n border: 'none',\n borderRadius: 0,\n boxShadow: 'none',\n background: 'transparent',\n padding: 'var(--space-2)',\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {optionRows}\n </ul>\n </div>\n </div>,\n document.body,\n )}\n {open && !coarse && place && place.strategy === 'inline' && (\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n maxHeight: place.maxH,\n zIndex: 100,\n })}\n >\n {optionRows}\n </ul>\n )}\n {open && !coarse && mounted && place && place.strategy === 'fixed' &&\n createPortal(\n <ul\n ref={panelRef}\n id={listboxId}\n role=\"listbox\"\n tabIndex={-1}\n style={sx({\n ...listStyleBase,\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n maxHeight: place.maxH,\n zIndex: 1100,\n })}\n >\n {optionRows}\n </ul>,\n document.body,\n )}\n </div>\n );\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the selected\n * value (rendered only when `name` is set - pass it, as `register()` does).\n * Enough for `getValues()` / `trigger()` / `setFocus()`, but a plain\n * `{...register(name)}` spread still won't validate on change: this hidden\n * input never dispatches a native `input`/`change` event, and `onValueChange`\n * hands back a plain string, not a `ChangeEvent` - wire it through\n * `Controller`, or call the registered `onChange` yourself from\n * `onValueChange`.\n */\nexport const Select = React.forwardRef<HTMLInputElement, SelectProps>(function Select({\n label,\n hint,\n error,\n required,\n options = [],\n placeholder,\n size = 'md',\n disabled,\n value: valueProp,\n defaultValue,\n onValueChange,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n}: SelectProps, ref) {\n const reactId = React.useId();\n const rid = id || reactId;\n const isControlled = valueProp !== undefined;\n const [internalValue, setInternalValue] = React.useState(defaultValue ?? '');\n const value = isControlled ? valueProp! : internalValue;\n const coarse = useCoarsePointer();\n\n const commit = React.useCallback(\n (v: string) => {\n if (!isControlled) setInternalValue(v);\n onValueChange?.(v);\n },\n [isControlled, onValueChange],\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <CustomSelect\n rid={rid}\n label={label}\n ariaLabel={ariaLabel}\n options={options}\n value={value}\n placeholder={placeholder}\n size={size}\n error={!!error}\n disabled={disabled}\n coarse={coarse}\n fieldAria={fieldA11y(rid, { hint, error, required })}\n onCommit={commit}\n />\n {name && <input ref={ref} type=\"hidden\" name={name} value={value} />}\n </Field>\n );\n});\n\nSelect.displayName = 'Select';\n"],"mappings":";AA0OI,cAgBE,YAhBF;AAxOJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AA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AU,MAAK,UAAS,MAAY,OAAc;AAAA,KACpE;AAEJ,CAAC;AAED,OAAO,cAAc;","names":["Select"]}
|
package/dist/forms/Textarea.js
CHANGED
|
@@ -7,6 +7,7 @@ import { fieldA11y } from "../_internal/fieldA11y.js";
|
|
|
7
7
|
import { CharCount } from "../_internal/CharCount.js";
|
|
8
8
|
import { mergeRefs } from "../_internal/mergeRefs.js";
|
|
9
9
|
import { useValueLength } from "../_internal/useValueLength.js";
|
|
10
|
+
import { fieldFrameVars } from "./_internal/fieldFrame.js";
|
|
10
11
|
const Textarea = React.forwardRef(function Textarea2({
|
|
11
12
|
label,
|
|
12
13
|
hint,
|
|
@@ -19,15 +20,12 @@ const Textarea = React.forwardRef(function Textarea2({
|
|
|
19
20
|
id,
|
|
20
21
|
style,
|
|
21
22
|
containerStyle,
|
|
22
|
-
|
|
23
|
-
onFocus,
|
|
24
|
-
onBlur,
|
|
23
|
+
className,
|
|
25
24
|
"aria-describedby": describedBy,
|
|
26
25
|
"aria-invalid": invalid,
|
|
27
26
|
"aria-required": ariaRequired,
|
|
28
27
|
...rest
|
|
29
28
|
}, ref) {
|
|
30
|
-
const [focus, setFocus] = React.useState(false);
|
|
31
29
|
const textareaRef = React.useRef(null);
|
|
32
30
|
const setRefs = React.useMemo(() => mergeRefs(textareaRef, ref), [ref]);
|
|
33
31
|
const autoId = React.useId();
|
|
@@ -41,14 +39,6 @@ const Textarea = React.forwardRef(function Textarea2({
|
|
|
41
39
|
typeof rest.defaultValue === "string" || typeof rest.defaultValue === "number" ? String(rest.defaultValue).length : 0
|
|
42
40
|
);
|
|
43
41
|
const count = rest.value !== void 0 ? String(rest.value ?? "").length : uncount;
|
|
44
|
-
const handleFocus = (e) => {
|
|
45
|
-
setFocus(true);
|
|
46
|
-
onFocus?.(e);
|
|
47
|
-
};
|
|
48
|
-
const handleBlur = (e) => {
|
|
49
|
-
setFocus(false);
|
|
50
|
-
onBlur?.(e);
|
|
51
|
-
};
|
|
52
42
|
return /* @__PURE__ */ jsx(
|
|
53
43
|
Field,
|
|
54
44
|
{
|
|
@@ -70,17 +60,16 @@ const Textarea = React.forwardRef(function Textarea2({
|
|
|
70
60
|
disabled,
|
|
71
61
|
...rest,
|
|
72
62
|
...a11y,
|
|
73
|
-
|
|
74
|
-
onBlur: handleBlur,
|
|
75
|
-
onChange,
|
|
63
|
+
className: ["sereno-field", className].filter(Boolean).join(" "),
|
|
76
64
|
style: sx({
|
|
65
|
+
...fieldFrameVars(!!error),
|
|
77
66
|
width: "100%",
|
|
78
67
|
padding: "var(--space-3)",
|
|
79
68
|
resize: "vertical",
|
|
80
69
|
borderRadius: "var(--radius-control)",
|
|
81
70
|
background: disabled ? "var(--interactive-disabled-bg)" : "var(--bg-surface)",
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
borderWidth: "var(--border-width-hairline)",
|
|
72
|
+
borderStyle: "solid",
|
|
84
73
|
outline: "none",
|
|
85
74
|
fontFamily: "var(--font-body)",
|
|
86
75
|
fontSize: "var(--text-base)",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/Textarea.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { CharCount } from '../_internal/CharCount';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { useValueLength } from '../_internal/useValueLength';\n\n/** Multi-line field for booking notes and service descriptions. */\nexport interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n rows?: number;\n /**\n * Show a `n / max` character counter on the hint row. Implied when `maxLength`\n * is set; pass `showCount` on its own for a bare count with no ceiling.\n */\n showCount?: boolean;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n}\n\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(function Textarea(\n {\n label,\n hint,\n error,\n required,\n rows = 4,\n showCount,\n preserveHelperSpace,\n disabled,\n id,\n style,\n containerStyle,\n
|
|
1
|
+
{"version":3,"sources":["../../src/forms/Textarea.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { CharCount } from '../_internal/CharCount';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { useValueLength } from '../_internal/useValueLength';\nimport { fieldFrameVars } from './_internal/fieldFrame';\n\n/** Multi-line field for booking notes and service descriptions. */\nexport interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n rows?: number;\n /**\n * Show a `n / max` character counter on the hint row. Implied when `maxLength`\n * is set; pass `showCount` on its own for a bare count with no ceiling.\n */\n showCount?: boolean;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n}\n\nexport const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(function Textarea(\n {\n label,\n hint,\n error,\n required,\n rows = 4,\n showCount,\n preserveHelperSpace,\n disabled,\n id,\n style,\n containerStyle,\n className,\n 'aria-describedby': describedBy,\n 'aria-invalid': invalid,\n 'aria-required': ariaRequired,\n ...rest\n },\n ref,\n) {\n const textareaRef = React.useRef<HTMLTextAreaElement>(null);\n // Stable across renders, so a form library's ref callback isn't detached and re-attached each time.\n const setRefs = React.useMemo(() => mergeRefs(textareaRef, ref), [ref]);\n // SSR-stable id (the DS source used Math.random(), which breaks hydration).\n const autoId = React.useId();\n const rid = id || autoId;\n // Names the hint / error line and flags the error, so a screen reader reads both with the field.\n const a11y = fieldA11y(rid, { hint, error, describedBy, invalid, required, ariaRequired });\n\n const max = typeof rest.maxLength === 'number' ? rest.maxLength : undefined;\n const showCounter = Boolean(showCount) || max != null;\n // Controlled: the count comes from `value`. Uncontrolled: from the element itself, so a\n // value written by code (react-hook-form's `reset()` / `setValue()`, `el.value = …`) counts too.\n const uncount = useValueLength(\n textareaRef,\n showCounter && rest.value === undefined,\n typeof rest.defaultValue === 'string' || typeof rest.defaultValue === 'number' ? String(rest.defaultValue).length : 0,\n );\n const count = rest.value !== undefined ? String(rest.value ?? '').length : uncount;\n\n return (\n <Field\n label={label}\n hint={hint}\n error={error}\n required={required}\n requiredExposed\n htmlFor={rid}\n style={containerStyle}\n counter={showCounter ? <CharCount count={count} max={max} /> : undefined}\n preserveHelperSpace={preserveHelperSpace}\n >\n <textarea\n id={rid}\n ref={setRefs}\n rows={rows}\n disabled={disabled}\n {...rest}\n {...a11y}\n // The border colour and the focus ring are CSS (`.sereno-field:focus` in styles.css, SS-582): the field\n // keeps no focus state, and a caller's `onFocus` / `onBlur` (react-hook-form's `register()` injects\n // one) stays in `...rest`, untouched.\n className={['sereno-field', className].filter(Boolean).join(' ')}\n style={sx({\n ...fieldFrameVars(!!error),\n width: '100%',\n padding: 'var(--space-3)',\n resize: 'vertical',\n borderRadius: 'var(--radius-control)',\n background: disabled ? 'var(--interactive-disabled-bg)' : 'var(--bg-surface)',\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n outline: 'none',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-base)',\n lineHeight: 'var(--leading-normal)',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n transition: 'var(--transition-control)',\n ...style,\n })}\n />\n </Field>\n );\n});\n\nTextarea.displayName = 'Textarea';"],"mappings":";AA+E6B;AA7E7B,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAoBxB,MAAM,WAAW,MAAM,WAA+C,SAASA,U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AAG;AAAA,YACR,GAAG,eAAe,CAAC,CAAC,KAAK;AAAA,YACzB,OAAO;AAAA,YACP,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,cAAc;AAAA,YACd,YAAY,WAAW,mCAAmC;AAAA,YAC1D,aAAa;AAAA,YACb,aAAa;AAAA,YACb,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,UAAU;AAAA,YACV,YAAY;AAAA,YACZ,OAAO,WAAW,yBAAyB;AAAA,YAC3C,YAAY;AAAA,YACZ,GAAG;AAAA,UACL,CAAC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ,CAAC;AAED,SAAS,cAAc;","names":["Textarea"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The border colours of the box of a `Checkbox` or `Radio`, as the custom properties `.sereno-check` and
|
|
3
|
+
* `.sereno-radio` (styles.css) read: `--sd-bd` at rest and `--sd-bd-hover` while the pointer is on the row. An error
|
|
4
|
+
* keeps its own colour in both, so a hover does not hide it. Nothing is set without an error: the stylesheet's
|
|
5
|
+
* fallbacks (the strong border, then the brand one) are the idle and hover colours.
|
|
6
|
+
*/
|
|
7
|
+
declare function choiceVars(error: string | undefined): Record<string, string>;
|
|
8
|
+
|
|
9
|
+
export { choiceVars };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/_internal/choiceVars.ts"],"sourcesContent":["/**\n * The border colours of the box of a `Checkbox` or `Radio`, as the custom properties `.sereno-check` and\n * `.sereno-radio` (styles.css) read: `--sd-bd` at rest and `--sd-bd-hover` while the pointer is on the row. An error\n * keeps its own colour in both, so a hover does not hide it. Nothing is set without an error: the stylesheet's\n * fallbacks (the strong border, then the brand one) are the idle and hover colours.\n */\nexport function choiceVars(error: string | undefined): Record<string, string> {\n return error ? { '--sd-bd': 'var(--interactive-error)', '--sd-bd-hover': 'var(--interactive-error)' } : {};\n}\n"],"mappings":"AAMO,SAAS,WAAW,OAAmD;AAC5E,SAAO,QAAQ,EAAE,WAAW,4BAA4B,iBAAiB,2BAA2B,IAAI,CAAC;AAC3G;","names":[]}
|
|
@@ -5,10 +5,14 @@ declare const CONTROL_HEIGHT: Record<FieldBoxSize, string>;
|
|
|
5
5
|
/**
|
|
6
6
|
* The bordered field-box chrome shared by any control whose trigger looks
|
|
7
7
|
* like a text field but opens something else on click - `Select`'s
|
|
8
|
-
* `<button role="combobox">`, `DatePicker`'s calendar trigger (SS-243)
|
|
8
|
+
* `<button role="combobox">`, `DatePicker`'s calendar trigger (SS-243),
|
|
9
|
+
* `Autocomplete`'s text box.
|
|
9
10
|
* Not for `Input`/`Textarea` themselves - those style their own `<input>`/
|
|
10
11
|
* `<textarea>` directly, with no separate "trigger vs. panel" split.
|
|
12
|
+
*
|
|
13
|
+
* The border colour and the focus ring are not here: the caller spreads `fieldBoxProps(open)` for the class
|
|
14
|
+
* and the open flag, and `styles.css` draws them from the `--sd-*` values this sets (see `fieldFrame.ts`).
|
|
11
15
|
*/
|
|
12
|
-
declare function fieldBoxStyle(size: FieldBoxSize, error: boolean,
|
|
16
|
+
declare function fieldBoxStyle(size: FieldBoxSize, error: boolean, disabled: boolean): CSSProperties;
|
|
13
17
|
|
|
14
18
|
export { CONTROL_HEIGHT, type FieldBoxSize, fieldBoxStyle };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { sx } from "../../_internal/style.js";
|
|
2
|
+
import { fieldFrameVars } from "./fieldFrame.js";
|
|
2
3
|
const CONTROL_HEIGHT = {
|
|
3
4
|
sm: "var(--control-height-sm)",
|
|
4
5
|
md: "var(--control-height-md)",
|
|
5
6
|
lg: "var(--control-height-lg)"
|
|
6
7
|
};
|
|
7
|
-
function fieldBoxStyle(size, error,
|
|
8
|
-
const active = open && !error;
|
|
8
|
+
function fieldBoxStyle(size, error, disabled) {
|
|
9
9
|
return sx({
|
|
10
|
+
...fieldFrameVars(error),
|
|
10
11
|
display: "flex",
|
|
11
12
|
alignItems: "center",
|
|
12
13
|
gap: "var(--space-2)",
|
|
@@ -20,8 +21,9 @@ function fieldBoxStyle(size, error, open, disabled) {
|
|
|
20
21
|
paddingLeft: "var(--space-3)",
|
|
21
22
|
borderRadius: "var(--radius-control)",
|
|
22
23
|
background: disabled ? "var(--interactive-disabled-bg)" : "var(--bg-surface)",
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
// Width and style only: the colour is `border-color: var(--sd-bd)` in styles.css, so a state can change it.
|
|
25
|
+
borderWidth: "var(--border-width-hairline)",
|
|
26
|
+
borderStyle: "solid",
|
|
25
27
|
fontFamily: "var(--font-body)",
|
|
26
28
|
fontSize: size === "sm" ? "var(--text-sm)" : "var(--text-base)",
|
|
27
29
|
color: disabled ? "var(--text-disabled)" : "var(--text-primary)",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/forms/_internal/fieldBoxStyle.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport { sx } from '../../_internal/style';\n\nexport type FieldBoxSize = 'sm' | 'md' | 'lg';\n\nexport const CONTROL_HEIGHT: Record<FieldBoxSize, string> = {\n sm: 'var(--control-height-sm)',\n md: 'var(--control-height-md)',\n lg: 'var(--control-height-lg)',\n};\n\n/**\n * The bordered field-box chrome shared by any control whose trigger looks\n * like a text field but opens something else on click - `Select`'s\n * `<button role=\"combobox\">`, `DatePicker`'s calendar trigger (SS-243).\n * Not for `Input`/`Textarea` themselves - those style their own `<input>`/\n * `<textarea>` directly, with no separate \"trigger vs. panel\" split.\n */\nexport function fieldBoxStyle(size: FieldBoxSize, error: boolean,
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/_internal/fieldBoxStyle.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nimport { sx } from '../../_internal/style';\nimport { fieldFrameVars } from './fieldFrame';\n\nexport type FieldBoxSize = 'sm' | 'md' | 'lg';\n\nexport const CONTROL_HEIGHT: Record<FieldBoxSize, string> = {\n sm: 'var(--control-height-sm)',\n md: 'var(--control-height-md)',\n lg: 'var(--control-height-lg)',\n};\n\n/**\n * The bordered field-box chrome shared by any control whose trigger looks\n * like a text field but opens something else on click - `Select`'s\n * `<button role=\"combobox\">`, `DatePicker`'s calendar trigger (SS-243),\n * `Autocomplete`'s text box.\n * Not for `Input`/`Textarea` themselves - those style their own `<input>`/\n * `<textarea>` directly, with no separate \"trigger vs. panel\" split.\n *\n * The border colour and the focus ring are not here: the caller spreads `fieldBoxProps(open)` for the class\n * and the open flag, and `styles.css` draws them from the `--sd-*` values this sets (see `fieldFrame.ts`).\n */\nexport function fieldBoxStyle(size: FieldBoxSize, error: boolean, disabled: boolean): CSSProperties {\n return sx({\n ...fieldFrameVars(error),\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n height: CONTROL_HEIGHT[size],\n // Longhand (not the `padding` shorthand) so callers can override one side,\n // e.g. NativeSelect's right pad - without React leaving the others blank.\n paddingTop: 0,\n paddingRight: 'var(--space-3)',\n paddingBottom: 0,\n paddingLeft: 'var(--space-3)',\n borderRadius: 'var(--radius-control)',\n background: disabled ? 'var(--interactive-disabled-bg)' : 'var(--bg-surface)',\n // Width and style only: the colour is `border-color: var(--sd-bd)` in styles.css, so a state can change it.\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n fontFamily: 'var(--font-body)',\n fontSize: size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n cursor: disabled ? 'not-allowed' : 'pointer',\n transition: 'var(--transition-control)',\n textAlign: 'left',\n });\n}\n"],"mappings":"AACA,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAIxB,MAAM,iBAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAaO,SAAS,cAAc,MAAoB,OAAgB,UAAkC;AAClG,SAAO,GAAG;AAAA,IACR,GAAG,eAAe,KAAK;AAAA,IACvB,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,QAAQ,eAAe,IAAI;AAAA;AAAA;AAAA,IAG3B,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,eAAe;AAAA,IACf,aAAa;AAAA,IACb,cAAc;AAAA,IACd,YAAY,WAAW,mCAAmC;AAAA;AAAA,IAE1D,aAAa;AAAA,IACb,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,UAAU,SAAS,OAAO,mBAAmB;AAAA,IAC7C,OAAO,WAAW,yBAAyB;AAAA,IAC3C,QAAQ,WAAW,gBAAgB;AAAA,IACnC,YAAY;AAAA,IACZ,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame of a text-like field (the row of `Input`, the `Textarea`, the box of `Select`, `DatePicker` and
|
|
3
|
+
* `Autocomplete`): its border colour and its focus ring are CSS, not component state (SS-582).
|
|
4
|
+
*
|
|
5
|
+
* The component declares the colours as custom properties on the element and the `.sereno-field` rules of
|
|
6
|
+
* `styles.css` switch between them, so a field holds no `focus` state (before: a `useState` and an
|
|
7
|
+
* `onFocus` / `onBlur` pair per instance, re-rendering the field on every focus and blur):
|
|
8
|
+
*
|
|
9
|
+
* - `--sd-bd`: the border colour at rest.
|
|
10
|
+
* - `--sd-bd-active`: the border colour while the field is active (focused, or its popup is open).
|
|
11
|
+
* - `--sd-ring-active`: the `box-shadow` while active.
|
|
12
|
+
*
|
|
13
|
+
* An error keeps its border in both states and has no ring.
|
|
14
|
+
*/
|
|
15
|
+
declare function fieldFrameVars(error: boolean): Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* For a box that is active because something is open (a `Select` or `DatePicker` popup, an `Autocomplete`
|
|
18
|
+
* list), not because it has the focus: the class that carries the frame rules, plus `data-active` while open.
|
|
19
|
+
* The focus itself needs nothing from the component, `styles.css` reads it from the `:focus` of the field.
|
|
20
|
+
*/
|
|
21
|
+
declare function fieldBoxProps(open: boolean): {
|
|
22
|
+
className: string;
|
|
23
|
+
'data-active'?: '';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { fieldBoxProps, fieldFrameVars };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function fieldFrameVars(error) {
|
|
2
|
+
return error ? { "--sd-bd": "var(--interactive-error)", "--sd-bd-active": "var(--interactive-error)", "--sd-ring-active": "none" } : { "--sd-bd": "var(--border-default)", "--sd-bd-active": "var(--border-focus)", "--sd-ring-active": "var(--focus-ring)" };
|
|
3
|
+
}
|
|
4
|
+
function fieldBoxProps(open) {
|
|
5
|
+
return open ? { className: "sereno-field", "data-active": "" } : { className: "sereno-field" };
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
fieldBoxProps,
|
|
9
|
+
fieldFrameVars
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=fieldFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/forms/_internal/fieldFrame.ts"],"sourcesContent":["/**\n * The frame of a text-like field (the row of `Input`, the `Textarea`, the box of `Select`, `DatePicker` and\n * `Autocomplete`): its border colour and its focus ring are CSS, not component state (SS-582).\n *\n * The component declares the colours as custom properties on the element and the `.sereno-field` rules of\n * `styles.css` switch between them, so a field holds no `focus` state (before: a `useState` and an\n * `onFocus` / `onBlur` pair per instance, re-rendering the field on every focus and blur):\n *\n * - `--sd-bd`: the border colour at rest.\n * - `--sd-bd-active`: the border colour while the field is active (focused, or its popup is open).\n * - `--sd-ring-active`: the `box-shadow` while active.\n *\n * An error keeps its border in both states and has no ring.\n */\nexport function fieldFrameVars(error: boolean): Record<string, string> {\n return error\n ? { '--sd-bd': 'var(--interactive-error)', '--sd-bd-active': 'var(--interactive-error)', '--sd-ring-active': 'none' }\n : { '--sd-bd': 'var(--border-default)', '--sd-bd-active': 'var(--border-focus)', '--sd-ring-active': 'var(--focus-ring)' };\n}\n\n/**\n * For a box that is active because something is open (a `Select` or `DatePicker` popup, an `Autocomplete`\n * list), not because it has the focus: the class that carries the frame rules, plus `data-active` while open.\n * The focus itself needs nothing from the component, `styles.css` reads it from the `:focus` of the field.\n */\nexport function fieldBoxProps(open: boolean): { className: string; 'data-active'?: '' } {\n return open ? { className: 'sereno-field', 'data-active': '' } : { className: 'sereno-field' };\n}\n"],"mappings":"AAcO,SAAS,eAAe,OAAwC;AACrE,SAAO,QACH,EAAE,WAAW,4BAA4B,kBAAkB,4BAA4B,oBAAoB,OAAO,IAClH,EAAE,WAAW,yBAAyB,kBAAkB,uBAAuB,oBAAoB,oBAAoB;AAC7H;AAOO,SAAS,cAAc,MAA0D;AACtF,SAAO,OAAO,EAAE,WAAW,gBAAgB,eAAe,GAAG,IAAI,EAAE,WAAW,eAAe;AAC/F;","names":[]}
|
|
@@ -83,9 +83,16 @@ function SidebarNavRoot({
|
|
|
83
83
|
width: 26,
|
|
84
84
|
height: 26,
|
|
85
85
|
borderRadius: "999px",
|
|
86
|
-
border
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
// Fill, ink and border come from the `--sd-*` values (the hover is the `:hover` rule of
|
|
87
|
+
// `.sereno-sidenav-toggle`); set inline they would beat that rule and the hover would never show.
|
|
88
|
+
"--sd-bg": "var(--bg-surface)",
|
|
89
|
+
"--sd-bg-hover": "var(--interactive-secondary-hover)",
|
|
90
|
+
"--sd-fg": "var(--text-secondary)",
|
|
91
|
+
"--sd-fg-hover": "var(--text-primary)",
|
|
92
|
+
"--sd-bd": "var(--border-default)",
|
|
93
|
+
"--sd-bd-hover": "var(--border-strong)",
|
|
94
|
+
borderWidth: "var(--border-width-hairline)",
|
|
95
|
+
borderStyle: "solid",
|
|
89
96
|
boxShadow: "var(--shadow-sm)",
|
|
90
97
|
cursor: "pointer",
|
|
91
98
|
transition: "var(--transition-control)"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/navigation/SidebarNav.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronLeft } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { SidebarNavContext, type SidebarNavContextValue } from './_internal/sidebarNavContext';\nimport { Item, Section, SubItem } from './_internal/SidebarNavItems';\n\nexport type { SidebarNavItemProps, SidebarNavSectionProps, SidebarNavSubItemProps } from './_internal/SidebarNavItems';\n\n/**\n * Desktop primary navigation - a **compound component**, the counterpart to\n * `BottomNav`. Grouped sections with dividers, an optional second level per\n * item, and a collapse toggle that drops it to a 72px icon rail.\n *\n * ```tsx\n * <SidebarNav value={view} onChange={setView} header={<Wordmark />}>\n * <SidebarNav.Section label=\"Workspace\">\n * <SidebarNav.Item value=\"agenda\" label=\"Calendar\" icon={<Calendar size={18} />} />\n * <SidebarNav.Item value=\"finance\" label=\"Finance\" icon={<Wallet size={18} />}>\n * <SidebarNav.SubItem value=\"finance:incoming\" label=\"Incoming\" />\n * <SidebarNav.SubItem value=\"finance:payouts\" label=\"Payouts\" count={3} />\n * </SidebarNav.Item>\n * </SidebarNav.Section>\n * </SidebarNav>\n * ```\n *\n * `Item` is not a destination once it has `SubItem` children - it toggles\n * them instead (an inline accordion when expanded, a hover flyout on the\n * collapsed rail).\n */\nexport interface SidebarNavProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {\n value?: string;\n onChange?: (value: string) => void;\n /** Controlled collapse (icon-only rail). */\n collapsed?: boolean;\n defaultCollapsed?: boolean;\n onCollapsedChange?: (collapsed: boolean) => void;\n /** Show the collapse toggle in the footer. */\n collapsible?: boolean;\n /** Brand / logo slot at the top. */\n header?: React.ReactNode;\n /** Persistent slot pinned to the bottom (user card, plan nudge). Hidden while collapsed. */\n footer?: React.ReactNode;\n labels?: { expand?: string; collapse?: string };\n /** Component used to render items that carry `href` (e.g. Next's `Link`). Defaults to `'a'`. */\n linkComponent?: React.ElementType;\n /**\n * Disables every `Item` / `SubItem` at once - a gated area, an account that\n * isn't active yet. An item can still opt back in with its own\n * `disabled={false}` (e.g. a \"Help\" link that must stay reachable). Only the\n * destinations are affected: the collapse toggle, `header` and `footer` stay\n * live, since they aren't navigation.\n */\n disabled?: boolean;\n children: React.ReactNode;\n}\n\nconst EXPANDED = 248;\nconst COLLAPSED = 72;\n\nfunction SidebarNavRoot({\n value,\n onChange,\n collapsed: collapsedProp,\n defaultCollapsed = false,\n onCollapsedChange,\n collapsible = true,\n header,\n footer,\n labels,\n linkComponent,\n disabled = false,\n children,\n style,\n ...rest\n}: SidebarNavProps) {\n const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);\n const collapsed = collapsedProp ?? internalCollapsed;\n const setCollapsed = (c: boolean) => {\n if (collapsedProp === undefined) setInternalCollapsed(c);\n onCollapsedChange?.(c);\n };\n\n // Custom hover tooltip for the collapsed rail - portalled so the rail's own\n // overflow clipping can't hide it.\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n const [tip, setTip] = React.useState<{ label: string; top: number; left: number } | null>(null);\n React.useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- drop a stale tip when the rail expands\n if (!collapsed) setTip(null);\n }, [collapsed]);\n const showTip = (label: string, r: DOMRect) => setTip({ label, top: r.top + r.height / 2, left: r.right + 10 });\n const hideTip = () => setTip(null);\n\n // Single cross-item flyout for the collapsed rail (only one open at a time).\n const [flyoutValue, setFlyoutValue] = React.useState<string | null>(null);\n const flyoutTimer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const openFlyout = (v: string) => {\n clearTimeout(flyoutTimer.current);\n setFlyoutValue(v);\n };\n const closeFlyoutSoon = () => {\n clearTimeout(flyoutTimer.current);\n flyoutTimer.current = setTimeout(() => setFlyoutValue(null), 140);\n };\n const closeFlyoutNow = () => {\n clearTimeout(flyoutTimer.current);\n setFlyoutValue(null);\n };\n React.useEffect(() => () => clearTimeout(flyoutTimer.current), []);\n React.useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- drop a stale flyout when the rail expands\n if (!collapsed) setFlyoutValue(null);\n }, [collapsed]);\n\n const select = (v: string) => {\n closeFlyoutNow();\n onChange?.(v);\n };\n\n const ctx: SidebarNavContextValue = { value, disabled, select, collapsed, linkComponent, flyoutValue, openFlyout, closeFlyoutSoon, closeFlyoutNow, showTip, hideTip };\n\n // The collapse control straddles the sidebar's right edge, level with the logo.\n const toggleLabel = collapsed ? labels?.expand ?? 'Expand' : labels?.collapse ?? 'Collapse';\n const toggleBtn = collapsible ? (\n <button\n type=\"button\"\n className=\"sereno-sidenav-btn sereno-sidenav-toggle\"\n aria-label={toggleLabel}\n aria-pressed={collapsed}\n title={toggleLabel}\n onClick={() => setCollapsed(!collapsed)}\n style={sx({\n position: 'absolute',\n top: 'calc(var(--sidenav-header-h, 56px) / 2)',\n right: -13,\n transform: 'translateY(-50%)',\n zIndex: 5,\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: 26,\n height: 26,\n borderRadius: '999px',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n background: 'var(--bg-surface)',\n color: 'var(--text-secondary)',\n boxShadow: 'var(--shadow-sm)',\n cursor: 'pointer',\n transition: 'var(--transition-control)',\n })}\n >\n <ChevronLeft\n size={15}\n strokeWidth={2}\n style={{ transition: 'transform var(--duration-normal) var(--ease-out)', transform: collapsed ? 'rotate(180deg)' : 'none' }}\n />\n </button>\n ) : null;\n\n return (\n <SidebarNavContext.Provider value={ctx}>\n <nav\n {...rest}\n className={['sereno-sidenav-root', rest.className].filter(Boolean).join(' ')}\n data-collapsed={collapsed ? '' : undefined}\n style={sx({\n position: 'relative',\n display: 'flex',\n flexDirection: 'column',\n flex: '0 0 auto',\n width: collapsed ? COLLAPSED : EXPANDED,\n height: '100%',\n background: 'var(--bg-surface)',\n borderRight: 'var(--border-width-hairline) solid var(--border-default)',\n transition: 'width var(--duration-normal) var(--ease-out)',\n ...style,\n })}\n >\n {toggleBtn}\n\n {header !== undefined && (\n <div\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n height: 'var(--sidenav-header-h, 56px)',\n padding: collapsed ? '0' : '0 var(--space-4)',\n })}\n >\n <div style={sx({ minWidth: 0, overflow: 'hidden', display: 'flex', alignItems: 'center' })}>{header}</div>\n </div>\n )}\n\n <div\n className=\"sereno-sidenav\"\n style={sx({\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n padding: 'var(--space-2) var(--space-3)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n {children}\n </div>\n\n {footer && !collapsed && (\n <div\n style={sx({\n borderTop: 'var(--border-width-hairline) solid var(--border-subtle)',\n padding: 'var(--space-3)',\n display: 'flex',\n flexDirection: 'column',\n gap: 'var(--space-2)',\n })}\n >\n {footer}\n </div>\n )}\n\n {mounted &&\n tip &&\n createPortal(\n <div\n role=\"tooltip\"\n style={sx({\n position: 'fixed',\n top: tip.top,\n left: tip.left,\n transform: 'translateY(-50%)',\n padding: '5px 9px',\n borderRadius: 'var(--radius-sm)',\n background: 'var(--bg-inverse)',\n color: 'var(--text-inverse)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n fontWeight: 'var(--weight-medium)',\n lineHeight: 1,\n whiteSpace: 'nowrap',\n boxShadow: 'var(--shadow-md)',\n pointerEvents: 'none',\n zIndex: 1000,\n animation: 'sereno-fade-in var(--duration-fast) var(--ease-out)',\n })}\n >\n <span\n aria-hidden\n style={sx({\n position: 'absolute',\n left: -3,\n top: '50%',\n width: 6,\n height: 6,\n background: 'var(--bg-inverse)',\n transform: 'translateY(-50%) rotate(45deg)',\n borderRadius: 1,\n })}\n />\n {tip.label}\n </div>,\n document.body,\n )}\n </nav>\n </SidebarNavContext.Provider>\n );\n}\n\nexport const SidebarNav = Object.assign(SidebarNavRoot, { Section, Item, SubItem });\n"],"mappings":";AA4JM,cA2EM,YA3EN;AA1JN,YAAY,WAAW;AAC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ACC,MAAK;AAAA,cACL,OAAO,GAAG;AAAA,gBACR,UAAU;AAAA,gBACV,KAAK,IAAI;AAAA,gBACT,MAAM,IAAI;AAAA,gBACV,WAAW;AAAA,gBACX,SAAS;AAAA,gBACT,cAAc;AAAA,gBACd,YAAY;AAAA,gBACZ,OAAO;AAAA,gBACP,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,YAAY;AAAA,gBACZ,YAAY;AAAA,gBACZ,YAAY;AAAA,gBACZ,WAAW;AAAA,gBACX,eAAe;AAAA,gBACf,QAAQ;AAAA,gBACR,WAAW;AAAA,cACb,CAAC;AAAA,cAED;AAAA;AAAA,kBAAC;AAAA;AAAA,oBACC,eAAW;AAAA,oBACX,OAAO,GAAG;AAAA,sBACR,UAAU;AAAA,sBACV,MAAM;AAAA,sBACN,KAAK;AAAA,sBACL,OAAO;AAAA,sBACP,QAAQ;AAAA,sBACR,YAAY;AAAA,sBACZ,WAAW;AAAA,sBACX,cAAc;AAAA,oBAChB,CAAC;AAAA;AAAA,gBACH;AAAA,gBACC,IAAI;AAAA;AAAA;AAAA,UACP;AAAA,UACA,SAAS;AAAA,QACX;AAAA;AAAA;AAAA,EACJ,GACF;AAEJ;AAEO,MAAM,aAAa,OAAO,OAAO,gBAAgB,EAAE,SAAS,MAAM,QAAQ,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/navigation/SidebarNav.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronLeft } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { SidebarNavContext, type SidebarNavContextValue } from './_internal/sidebarNavContext';\nimport { Item, Section, SubItem } from './_internal/SidebarNavItems';\n\nexport type { SidebarNavItemProps, SidebarNavSectionProps, SidebarNavSubItemProps } from './_internal/SidebarNavItems';\n\n/**\n * Desktop primary navigation - a **compound component**, the counterpart to\n * `BottomNav`. Grouped sections with dividers, an optional second level per\n * item, and a collapse toggle that drops it to a 72px icon rail.\n *\n * ```tsx\n * <SidebarNav value={view} onChange={setView} header={<Wordmark />}>\n * <SidebarNav.Section label=\"Workspace\">\n * <SidebarNav.Item value=\"agenda\" label=\"Calendar\" icon={<Calendar size={18} />} />\n * <SidebarNav.Item value=\"finance\" label=\"Finance\" icon={<Wallet size={18} />}>\n * <SidebarNav.SubItem value=\"finance:incoming\" label=\"Incoming\" />\n * <SidebarNav.SubItem value=\"finance:payouts\" label=\"Payouts\" count={3} />\n * </SidebarNav.Item>\n * </SidebarNav.Section>\n * </SidebarNav>\n * ```\n *\n * `Item` is not a destination once it has `SubItem` children - it toggles\n * them instead (an inline accordion when expanded, a hover flyout on the\n * collapsed rail).\n */\nexport interface SidebarNavProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {\n value?: string;\n onChange?: (value: string) => void;\n /** Controlled collapse (icon-only rail). */\n collapsed?: boolean;\n defaultCollapsed?: boolean;\n onCollapsedChange?: (collapsed: boolean) => void;\n /** Show the collapse toggle in the footer. */\n collapsible?: boolean;\n /** Brand / logo slot at the top. */\n header?: React.ReactNode;\n /** Persistent slot pinned to the bottom (user card, plan nudge). Hidden while collapsed. */\n footer?: React.ReactNode;\n labels?: { expand?: string; collapse?: string };\n /** Component used to render items that carry `href` (e.g. Next's `Link`). Defaults to `'a'`. */\n linkComponent?: React.ElementType;\n /**\n * Disables every `Item` / `SubItem` at once - a gated area, an account that\n * isn't active yet. An item can still opt back in with its own\n * `disabled={false}` (e.g. a \"Help\" link that must stay reachable). Only the\n * destinations are affected: the collapse toggle, `header` and `footer` stay\n * live, since they aren't navigation.\n */\n disabled?: boolean;\n children: React.ReactNode;\n}\n\nconst EXPANDED = 248;\nconst COLLAPSED = 72;\n\nfunction SidebarNavRoot({\n value,\n onChange,\n collapsed: collapsedProp,\n defaultCollapsed = false,\n onCollapsedChange,\n collapsible = true,\n header,\n footer,\n labels,\n linkComponent,\n disabled = false,\n children,\n style,\n ...rest\n}: SidebarNavProps) {\n const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);\n const collapsed = collapsedProp ?? internalCollapsed;\n const setCollapsed = (c: boolean) => {\n if (collapsedProp === undefined) setInternalCollapsed(c);\n onCollapsedChange?.(c);\n };\n\n // Custom hover tooltip for the collapsed rail - portalled so the rail's own\n // overflow clipping can't hide it.\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n const [tip, setTip] = React.useState<{ label: string; top: number; left: number } | null>(null);\n React.useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- drop a stale tip when the rail expands\n if (!collapsed) setTip(null);\n }, [collapsed]);\n const showTip = (label: string, r: DOMRect) => setTip({ label, top: r.top + r.height / 2, left: r.right + 10 });\n const hideTip = () => setTip(null);\n\n // Single cross-item flyout for the collapsed rail (only one open at a time).\n const [flyoutValue, setFlyoutValue] = React.useState<string | null>(null);\n const flyoutTimer = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const openFlyout = (v: string) => {\n clearTimeout(flyoutTimer.current);\n setFlyoutValue(v);\n };\n const closeFlyoutSoon = () => {\n clearTimeout(flyoutTimer.current);\n flyoutTimer.current = setTimeout(() => setFlyoutValue(null), 140);\n };\n const closeFlyoutNow = () => {\n clearTimeout(flyoutTimer.current);\n setFlyoutValue(null);\n };\n React.useEffect(() => () => clearTimeout(flyoutTimer.current), []);\n React.useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- drop a stale flyout when the rail expands\n if (!collapsed) setFlyoutValue(null);\n }, [collapsed]);\n\n const select = (v: string) => {\n closeFlyoutNow();\n onChange?.(v);\n };\n\n const ctx: SidebarNavContextValue = { value, disabled, select, collapsed, linkComponent, flyoutValue, openFlyout, closeFlyoutSoon, closeFlyoutNow, showTip, hideTip };\n\n // The collapse control straddles the sidebar's right edge, level with the logo.\n const toggleLabel = collapsed ? labels?.expand ?? 'Expand' : labels?.collapse ?? 'Collapse';\n const toggleBtn = collapsible ? (\n <button\n type=\"button\"\n className=\"sereno-sidenav-btn sereno-sidenav-toggle\"\n aria-label={toggleLabel}\n aria-pressed={collapsed}\n title={toggleLabel}\n onClick={() => setCollapsed(!collapsed)}\n style={sx({\n position: 'absolute',\n top: 'calc(var(--sidenav-header-h, 56px) / 2)',\n right: -13,\n transform: 'translateY(-50%)',\n zIndex: 5,\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: 26,\n height: 26,\n borderRadius: '999px',\n // Fill, ink and border come from the `--sd-*` values (the hover is the `:hover` rule of\n // `.sereno-sidenav-toggle`); set inline they would beat that rule and the hover would never show.\n '--sd-bg': 'var(--bg-surface)',\n '--sd-bg-hover': 'var(--interactive-secondary-hover)',\n '--sd-fg': 'var(--text-secondary)',\n '--sd-fg-hover': 'var(--text-primary)',\n '--sd-bd': 'var(--border-default)',\n '--sd-bd-hover': 'var(--border-strong)',\n borderWidth: 'var(--border-width-hairline)',\n borderStyle: 'solid',\n boxShadow: 'var(--shadow-sm)',\n cursor: 'pointer',\n transition: 'var(--transition-control)',\n })}\n >\n <ChevronLeft\n size={15}\n strokeWidth={2}\n style={{ transition: 'transform var(--duration-normal) var(--ease-out)', transform: collapsed ? 'rotate(180deg)' : 'none' }}\n />\n </button>\n ) : null;\n\n return (\n <SidebarNavContext.Provider value={ctx}>\n <nav\n {...rest}\n className={['sereno-sidenav-root', rest.className].filter(Boolean).join(' ')}\n data-collapsed={collapsed ? '' : undefined}\n style={sx({\n position: 'relative',\n display: 'flex',\n flexDirection: 'column',\n flex: '0 0 auto',\n width: collapsed ? COLLAPSED : EXPANDED,\n height: '100%',\n background: 'var(--bg-surface)',\n borderRight: 'var(--border-width-hairline) solid var(--border-default)',\n transition: 'width var(--duration-normal) var(--ease-out)',\n ...style,\n })}\n >\n {toggleBtn}\n\n {header !== undefined && (\n <div\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n height: 'var(--sidenav-header-h, 56px)',\n padding: collapsed ? '0' : '0 var(--space-4)',\n })}\n >\n <div style={sx({ minWidth: 0, overflow: 'hidden', display: 'flex', alignItems: 'center' })}>{header}</div>\n </div>\n )}\n\n <div\n className=\"sereno-sidenav\"\n style={sx({\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n padding: 'var(--space-2) var(--space-3)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n {children}\n </div>\n\n {footer && !collapsed && (\n <div\n style={sx({\n borderTop: 'var(--border-width-hairline) solid var(--border-subtle)',\n padding: 'var(--space-3)',\n display: 'flex',\n flexDirection: 'column',\n gap: 'var(--space-2)',\n })}\n >\n {footer}\n </div>\n )}\n\n {mounted &&\n tip &&\n createPortal(\n <div\n role=\"tooltip\"\n style={sx({\n position: 'fixed',\n top: tip.top,\n left: tip.left,\n transform: 'translateY(-50%)',\n padding: '5px 9px',\n borderRadius: 'var(--radius-sm)',\n background: 'var(--bg-inverse)',\n color: 'var(--text-inverse)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-xs)',\n fontWeight: 'var(--weight-medium)',\n lineHeight: 1,\n whiteSpace: 'nowrap',\n boxShadow: 'var(--shadow-md)',\n pointerEvents: 'none',\n zIndex: 1000,\n animation: 'sereno-fade-in var(--duration-fast) var(--ease-out)',\n })}\n >\n <span\n aria-hidden\n style={sx({\n position: 'absolute',\n left: -3,\n top: '50%',\n width: 6,\n height: 6,\n background: 'var(--bg-inverse)',\n transform: 'translateY(-50%) rotate(45deg)',\n borderRadius: 1,\n })}\n />\n {tip.label}\n </div>,\n document.body,\n )}\n </nav>\n </SidebarNavContext.Provider>\n );\n}\n\nexport const SidebarNav = Object.assign(SidebarNavRoot, { Section, Item, SubItem });\n"],"mappings":";AAmKM,cA2EM,YA3EN;AAjKN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB,SAAS,yBAAsD;AAC/D,SAAS,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AAAA;AAAA,cACC,MAAK;AAAA,cACL,OAAO,GAAG;AAAA,gBACR,UAAU;AAAA,gBACV,KAAK,IAAI;AAAA,gBACT,MAAM,IAAI;AAAA,gBACV,WAAW;AAAA,gBACX,SAAS;AAAA,gBACT,cAAc;AAAA,gBACd,YAAY;AAAA,gBACZ,OAAO;AAAA,gBACP,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,YAAY;AAAA,gBACZ,YAAY;AAAA,gBACZ,YAAY;AAAA,gBACZ,WAAW;AAAA,gBACX,eAAe;AAAA,gBACf,QAAQ;AAAA,gBACR,WAAW;AAAA,cACb,CAAC;AAAA,cAED;AAAA;AAAA,kBAAC;AAAA;AAAA,oBACC,eAAW;AAAA,oBACX,OAAO,GAAG;AAAA,sBACR,UAAU;AAAA,sBACV,MAAM;AAAA,sBACN,KAAK;AAAA,sBACL,OAAO;AAAA,sBACP,QAAQ;AAAA,sBACR,YAAY;AAAA,sBACZ,WAAW;AAAA,sBACX,cAAc;AAAA,oBAChB,CAAC;AAAA;AAAA,gBACH;AAAA,gBACC,IAAI;AAAA;AAAA;AAAA,UACP;AAAA,UACA,SAAS;AAAA,QACX;AAAA;AAAA;AAAA,EACJ,GACF;AAEJ;AAEO,MAAM,aAAa,OAAO,OAAO,gBAAgB,EAAE,SAAS,MAAM,QAAQ,CAAC;","names":[]}
|
|
@@ -3,7 +3,6 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { ChevronDown } from "lucide-react";
|
|
5
5
|
import { sx } from "../../_internal/style.js";
|
|
6
|
-
import { useInteract } from "../../core/Button.js";
|
|
7
6
|
import { ParentDisabledContext, useSidebarNavContext } from "./sidebarNavContext.js";
|
|
8
7
|
import { SubmenuPopover } from "./SidebarSubmenuPopover.js";
|
|
9
8
|
const groupHead = sx({
|
|
@@ -69,7 +68,6 @@ function Item({ value, label, icon, count, href, disabled: disabledProp, childre
|
|
|
69
68
|
hideTip
|
|
70
69
|
} = useSidebarNavContext("Item");
|
|
71
70
|
const disabled = disabledProp ?? rootDisabled;
|
|
72
|
-
const st = useInteract(disabled);
|
|
73
71
|
const btnRef = React.useRef(null);
|
|
74
72
|
const labelRef = React.useRef(null);
|
|
75
73
|
const hasChildren = React.Children.count(children) > 0;
|
|
@@ -107,7 +105,10 @@ function Item({ value, label, icon, count, href, disabled: disabledProp, childre
|
|
|
107
105
|
fontFamily: "var(--font-body)",
|
|
108
106
|
fontSize: "var(--text-base)",
|
|
109
107
|
fontWeight: highlight || childActive ? "var(--weight-semibold)" : "var(--weight-medium)",
|
|
110
|
-
|
|
108
|
+
// The fill and its hover value, as custom properties `.sereno-sidenav-btn` (styles.css) switches between on `:hover`
|
|
109
|
+
// (SS-577). The current page keeps its own fill under the pointer, and a disabled row has no hover value.
|
|
110
|
+
"--sd-bg": highlight ? "var(--bg-brand-soft)" : open ? "var(--interactive-ghost-hover)" : "transparent",
|
|
111
|
+
"--sd-bg-hover": highlight || disabled ? void 0 : "var(--interactive-ghost-hover)",
|
|
111
112
|
color: disabled ? "var(--text-disabled)" : highlight || childActive ? "var(--text-brand)" : "var(--text-secondary)",
|
|
112
113
|
transition: "var(--transition-control)"
|
|
113
114
|
});
|
|
@@ -142,26 +143,19 @@ function Item({ value, label, icon, count, href, disabled: disabledProp, childre
|
|
|
142
143
|
] })
|
|
143
144
|
] });
|
|
144
145
|
const hoverHandlers = {
|
|
145
|
-
...st.handlers,
|
|
146
146
|
onMouseEnter: (e) => {
|
|
147
|
-
st.handlers.onMouseEnter?.(e);
|
|
148
147
|
if (railFlyout) openFlyout(value);
|
|
149
148
|
else showLabelTip(e.currentTarget, labelRef.current, label, showTip);
|
|
150
149
|
},
|
|
151
|
-
onMouseLeave: (
|
|
152
|
-
st.handlers.onMouseLeave?.(e);
|
|
150
|
+
onMouseLeave: () => {
|
|
153
151
|
if (railFlyout) closeFlyoutSoon();
|
|
154
152
|
else hideTip();
|
|
155
153
|
},
|
|
156
154
|
// Keyboard parity with hover - on the rail a Tab stop is otherwise just an unlabelled icon.
|
|
157
155
|
onFocus: (e) => {
|
|
158
|
-
st.handlers.onFocus?.(e);
|
|
159
156
|
if (isKeyboardFocus(e.currentTarget)) showLabelTip(e.currentTarget, labelRef.current, label, showTip);
|
|
160
157
|
},
|
|
161
|
-
onBlur: (
|
|
162
|
-
st.handlers.onBlur?.(e);
|
|
163
|
-
hideTip();
|
|
164
|
-
},
|
|
158
|
+
onBlur: () => hideTip(),
|
|
165
159
|
// Dismissible without moving the pointer or focus (WCAG 1.4.13).
|
|
166
160
|
onKeyDown: (e) => {
|
|
167
161
|
if (e.key === "Escape") hideTip();
|
|
@@ -176,7 +170,7 @@ function Item({ value, label, icon, count, href, disabled: disabledProp, childre
|
|
|
176
170
|
Link,
|
|
177
171
|
{
|
|
178
172
|
href,
|
|
179
|
-
className: "sereno-sidenav-btn",
|
|
173
|
+
className: "sereno-sidenav-btn sereno-sidenav-row",
|
|
180
174
|
"aria-label": collapsed ? label : void 0,
|
|
181
175
|
"aria-current": selfActive ? "page" : void 0,
|
|
182
176
|
onClick: () => {
|
|
@@ -192,7 +186,7 @@ function Item({ value, label, icon, count, href, disabled: disabledProp, childre
|
|
|
192
186
|
{
|
|
193
187
|
ref: btnRef,
|
|
194
188
|
type: "button",
|
|
195
|
-
className: "sereno-sidenav-btn",
|
|
189
|
+
className: "sereno-sidenav-btn sereno-sidenav-row",
|
|
196
190
|
"aria-label": collapsed ? label : void 0,
|
|
197
191
|
"aria-current": selfActive ? "page" : void 0,
|
|
198
192
|
"aria-disabled": disabled || void 0,
|
|
@@ -233,12 +227,11 @@ function SubItem({ value, label, count, disabled: disabledProp, compact = false
|
|
|
233
227
|
const labelRef = React.useRef(null);
|
|
234
228
|
const disabled = disabledProp ?? parentDisabled ?? rootDisabled;
|
|
235
229
|
const active = activeValue === value;
|
|
236
|
-
const st = useInteract(disabled);
|
|
237
230
|
return /* @__PURE__ */ jsxs(
|
|
238
231
|
"button",
|
|
239
232
|
{
|
|
240
233
|
type: "button",
|
|
241
|
-
className: "sereno-sidenav-btn",
|
|
234
|
+
className: "sereno-sidenav-btn sereno-sidenav-row",
|
|
242
235
|
"aria-current": active ? "page" : void 0,
|
|
243
236
|
"aria-disabled": disabled || void 0,
|
|
244
237
|
tabIndex: disabled ? -1 : void 0,
|
|
@@ -246,23 +239,12 @@ function SubItem({ value, label, count, disabled: disabledProp, compact = false
|
|
|
246
239
|
hideTip();
|
|
247
240
|
if (!disabled) select(value);
|
|
248
241
|
},
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
st.handlers.onMouseEnter?.(e);
|
|
252
|
-
showLabelTip(e.currentTarget, labelRef.current, label, showTip);
|
|
253
|
-
},
|
|
254
|
-
onMouseLeave: (e) => {
|
|
255
|
-
st.handlers.onMouseLeave?.(e);
|
|
256
|
-
hideTip();
|
|
257
|
-
},
|
|
242
|
+
onMouseEnter: (e) => showLabelTip(e.currentTarget, labelRef.current, label, showTip),
|
|
243
|
+
onMouseLeave: () => hideTip(),
|
|
258
244
|
onFocus: (e) => {
|
|
259
|
-
st.handlers.onFocus?.(e);
|
|
260
245
|
if (isKeyboardFocus(e.currentTarget)) showLabelTip(e.currentTarget, labelRef.current, label, showTip);
|
|
261
246
|
},
|
|
262
|
-
onBlur: (
|
|
263
|
-
st.handlers.onBlur?.(e);
|
|
264
|
-
hideTip();
|
|
265
|
-
},
|
|
247
|
+
onBlur: () => hideTip(),
|
|
266
248
|
onKeyDown: (e) => {
|
|
267
249
|
if (e.key === "Escape") hideTip();
|
|
268
250
|
},
|
|
@@ -280,7 +262,8 @@ function SubItem({ value, label, count, disabled: disabledProp, compact = false
|
|
|
280
262
|
fontFamily: "var(--font-body)",
|
|
281
263
|
fontSize: "var(--text-sm)",
|
|
282
264
|
fontWeight: active ? "var(--weight-semibold)" : "var(--weight-medium)",
|
|
283
|
-
|
|
265
|
+
"--sd-bg": active ? "var(--bg-brand-soft)" : "transparent",
|
|
266
|
+
"--sd-bg-hover": active || disabled ? void 0 : "var(--interactive-ghost-hover)",
|
|
284
267
|
color: disabled ? "var(--text-disabled)" : active ? "var(--text-brand)" : "var(--text-secondary)",
|
|
285
268
|
transition: "var(--transition-control)"
|
|
286
269
|
}),
|