@sereno-ds/ui 0.41.2 → 0.41.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.
@@ -2,6 +2,6 @@ import * as React from 'react';
2
2
 
3
3
  /** `useLayoutEffect` in the browser, `useEffect` on the server (React 18 warns
4
4
  * about the former during SSR). */
5
- declare const useIsoLayoutEffect: typeof React.useEffect;
5
+ declare const useIsoLayoutEffect: typeof React.useLayoutEffect;
6
6
 
7
7
  export { useIsoLayoutEffect };
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Calls `onOutside` when a pointer goes down anywhere outside every element in `refs`, while `enabled`.
5
+ * What `Select`, `Menu`, `Autocomplete`, `DatePicker` and the month / year popover of the calendar all do
6
+ * to close their popup on a press elsewhere (SS-575): one place, one behavior.
7
+ *
8
+ * It listens on `document` in the **capture** phase, so a component that stops the event on its way down
9
+ * cannot hide a press from it. `refs` and `onOutside` are read when the event arrives, so passing a new
10
+ * array or a new callback every render does not re-subscribe. A ref that is `null` (not mounted) counts
11
+ * as "nothing there", so a press is outside of it.
12
+ */
13
+ declare function useOutsidePress(enabled: boolean, refs: ReadonlyArray<React.RefObject<Element | null>>, onOutside: (event: PointerEvent) => void): void;
14
+
15
+ export { useOutsidePress };
@@ -0,0 +1,20 @@
1
+ import * as React from "react";
2
+ import { useLatest } from "./useLatest.js";
3
+ function useOutsidePress(enabled, refs, onOutside) {
4
+ const refsRef = useLatest(refs);
5
+ const onOutsideRef = useLatest(onOutside);
6
+ React.useEffect(() => {
7
+ if (!enabled) return;
8
+ const onDown = (e) => {
9
+ const target = e.target;
10
+ if (refsRef.current.some((r) => r.current?.contains(target))) return;
11
+ onOutsideRef.current(e);
12
+ };
13
+ document.addEventListener("pointerdown", onDown, true);
14
+ return () => document.removeEventListener("pointerdown", onDown, true);
15
+ }, [enabled, refsRef, onOutsideRef]);
16
+ }
17
+ export {
18
+ useOutsidePress
19
+ };
20
+ //# sourceMappingURL=useOutsidePress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/_internal/useOutsidePress.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLatest } from './useLatest';\n\n/**\n * Calls `onOutside` when a pointer goes down anywhere outside every element in `refs`, while `enabled`.\n * What `Select`, `Menu`, `Autocomplete`, `DatePicker` and the month / year popover of the calendar all do\n * to close their popup on a press elsewhere (SS-575): one place, one behavior.\n *\n * It listens on `document` in the **capture** phase, so a component that stops the event on its way down\n * cannot hide a press from it. `refs` and `onOutside` are read when the event arrives, so passing a new\n * array or a new callback every render does not re-subscribe. A ref that is `null` (not mounted) counts\n * as \"nothing there\", so a press is outside of it.\n */\nexport function useOutsidePress(\n enabled: boolean,\n refs: ReadonlyArray<React.RefObject<Element | null>>,\n onOutside: (event: PointerEvent) => void,\n): void {\n const refsRef = useLatest(refs);\n const onOutsideRef = useLatest(onOutside);\n React.useEffect(() => {\n if (!enabled) return;\n const onDown = (e: PointerEvent) => {\n const target = e.target as Node;\n if (refsRef.current.some((r) => r.current?.contains(target))) return;\n onOutsideRef.current(e);\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [enabled, refsRef, onOutsideRef]);\n}\n"],"mappings":"AAAA,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAYnB,SAAS,gBACd,SACA,MACA,WACM;AACN,QAAM,UAAU,UAAU,IAAI;AAC9B,QAAM,eAAe,UAAU,SAAS;AACxC,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,QAAS;AACd,UAAM,SAAS,CAAC,MAAoB;AAClC,YAAM,SAAS,EAAE;AACjB,UAAI,QAAQ,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS,MAAM,CAAC,EAAG;AAC9D,mBAAa,QAAQ,CAAC;AAAA,IACxB;AACA,aAAS,iBAAiB,eAAe,QAAQ,IAAI;AACrD,WAAO,MAAM,SAAS,oBAAoB,eAAe,QAAQ,IAAI;AAAA,EACvE,GAAG,CAAC,SAAS,SAAS,YAAY,CAAC;AACrC;","names":[]}
package/dist/core/Menu.js CHANGED
@@ -3,6 +3,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { createPortal } from "react-dom";
5
5
  import { sx } from "../_internal/style.js";
6
+ import { useOutsidePress } from "../_internal/useOutsidePress.js";
6
7
  const isItem = (e) => !("separator" in e) && !("heading" in e);
7
8
  const GAP = 6;
8
9
  const GUTTER = 12;
@@ -83,16 +84,7 @@ function Menu({ trigger, adornment, items, children, header, label, align = "end
83
84
  window.removeEventListener("resize", onResize);
84
85
  };
85
86
  }, [open, mounted, align, width, close]);
86
- React.useEffect(() => {
87
- if (!open) return;
88
- const onDown = (e) => {
89
- const t = e.target;
90
- if (anchorRef.current?.contains(t) || panelRef.current?.contains(t)) return;
91
- close(false);
92
- };
93
- document.addEventListener("pointerdown", onDown, true);
94
- return () => document.removeEventListener("pointerdown", onDown, true);
95
- }, [open, close]);
87
+ useOutsidePress(open, [anchorRef, panelRef], () => close(false));
96
88
  const placed = place !== null;
97
89
  React.useEffect(() => {
98
90
  const panel = panelRef.current;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/Menu.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { sx } from '../_internal/style';\n\n/**\n * Action menu / dropdown - a `trigger` you supply plus a portalled panel of\n * items. Same mechanics as `Select`: `position: fixed` panel measured off the\n * trigger, flips up when there's no room, closes on outside pointerdown / `Escape`\n * / selection, and returns focus to the trigger. `role=\"menu\"` with arrow-key\n * roving. Needs the `sereno-pop` keyframe from `@sereno-ds/ui/styles.css`.\n *\n * Opened with a click or tap, no row is highlighted until the pointer enters one\n * or the user arrows. Opened from the keyboard (Enter, Space or ArrowDown on the\n * trigger; ArrowUp for the last row) the first enabled row is active, with a\n * focus ring, so Enter acts straight away.\n *\n * ```tsx\n * <Menu\n * trigger={<IconButton label=\"Conta\"><User /></IconButton>}\n * items={[\n * { label: 'Configurações', icon: <Settings />, onClick: openSettings },\n * { separator: true },\n * { label: 'Sair', icon: <LogOut />, tone: 'danger', onClick: signOut },\n * ]}\n * />\n * ```\n *\n * For a rich popover (a notifications list, say) pass a render function instead\n * of `items` - it receives `close`:\n * `<Menu trigger={…}>{(close) => <NotificationList onDone={close} />}</Menu>`\n */\n\nexport interface MenuItem {\n label: string;\n icon?: React.ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n /** `danger` paints the row in the error colour (destructive action). */\n tone?: 'default' | 'danger';\n /** Keep the menu open after activating (e.g. a toggle row). Default `false`. */\n keepOpen?: boolean;\n}\n/** A hairline rule between groups. */\nexport interface MenuSeparator {\n separator: true;\n}\n/** A non-interactive group caption. */\nexport interface MenuHeading {\n heading: string;\n}\nexport type MenuEntry = MenuItem | MenuSeparator | MenuHeading;\n\nconst isItem = (e: MenuEntry): e is MenuItem => !('separator' in e) && !('heading' in e);\n\nexport interface MenuProps {\n /** The clickable element that opens the menu (an `IconButton`, `Button`, avatar button…). */\n trigger: React.ReactElement;\n /** Overlaid on the trigger - a notification count, a status dot. Sits in a\n * `pointer-events: none` layer so a click still opens the menu. */\n adornment?: React.ReactNode;\n /** Structured rows. Omit when using the `children` render function. */\n items?: MenuEntry[];\n /** Rich panel content - receives `close`. Mutually exclusive with `items`. */\n children?: (close: () => void) => React.ReactNode;\n /** A block above the `items` - a name + email, a title. Not part of the keyboard roving. */\n header?: React.ReactNode;\n /** Accessible name for the panel, and a heading row when `items` is used. */\n label?: string;\n /** Which trigger edge the panel lines up with. Default `end` (right). */\n align?: 'start' | 'end';\n /** Panel width. Number → px; string → any CSS length. Default: fits the content (min 180). */\n width?: number | string;\n disabled?: boolean;\n /** Controlled open state. Omit for uncontrolled. */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nconst GAP = 6;\nconst GUTTER = 12;\n\n/** `left` is clamped so the panel is always fully on screen; `above` picks the\n * vertical edge. On a narrow (phone) viewport `right` is set too - the panel\n * spans the gutters (centred, full-width) instead of hanging off the trigger. */\ntype Place = { top?: number; bottom?: number; left: number; right?: number; above: boolean; maxH: number };\n\n/** Phone-width viewport (`--bp-sm`). Width only - not `pointer: coarse`, which a\n * trackpad / touch laptop reports on a full-size screen. */\nconst PHONE_W = 560;\n\nexport function Menu({ trigger, adornment, items, children, header, label, align = 'end', width, disabled, open: openProp, onOpenChange }: MenuProps) {\n const rid = React.useId();\n const menuId = `${rid}-menu`;\n const anchorRef = React.useRef<HTMLSpanElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n\n const isControlled = openProp !== undefined;\n const [openState, setOpenState] = React.useState(false);\n const open = isControlled ? openProp! : openState;\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (!isControlled) setOpenState(next);\n onOpenChange?.(next);\n },\n [isControlled, onOpenChange],\n );\n\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\n const [place, setPlace] = React.useState<Place | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n // How the user is driving the menu. `pointer` (opened by a click or tap, or the mouse\n // entered a row): nothing is highlighted until a row is hovered or arrowed to. `keyboard`\n // (anything else): the first row is active so Enter works straight away, and the active\n // row gets a focus ring. Unknown opens (a screen reader, the parent forcing `open`) take\n // the keyboard side, the one that stays operable without a pointer.\n const [inputMode, setInputMode] = React.useState<'pointer' | 'keyboard'>('keyboard');\n\n // A fresh open never inherits the last session's row or mode, whichever way it closed\n // (Escape, outside click, the trigger, the parent). Adjusted during render, not in an effect.\n const [wasOpen, setWasOpen] = React.useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (!open) {\n setActiveIndex(-1);\n setInputMode('keyboard');\n }\n }\n\n const itemIndexes = React.useMemo(() => (items ?? []).map((e, i) => (isItem(e) && !e.disabled ? i : -1)).filter((i) => i >= 0), [items]);\n\n const close = React.useCallback(\n (refocus = true) => {\n setOpen(false);\n if (refocus) {\n const btn = anchorRef.current?.querySelector<HTMLElement>('button, [role=\"button\"], a, [tabindex]');\n btn?.focus({ preventScroll: true });\n }\n },\n [setOpen],\n );\n\n // Measure + place the panel while open. `left` is clamped to keep the whole\n // panel on screen (it can't just right-anchor - on a phone a 360px panel off a\n // trigger 300px from the left would run off the edge). Re-runs on scroll/resize;\n // closes if the trigger scrolls away (mirrors Select's fixed strategy). A\n // microtask re-measure picks up the real panel box once it's in the DOM.\n React.useLayoutEffect(() => {\n if (!open || !mounted) return;\n const anchor = anchorRef.current;\n if (!anchor) return;\n\n const measure = (): Place => {\n const r = anchor.getBoundingClientRect();\n // Fall back to a *desktop* width when unmeasurable - never full-width a\n // menu just because a reading came back 0 (a real phone always reports).\n const vw = window.innerWidth || document.documentElement.clientWidth || 1024;\n const vh = window.innerHeight || document.documentElement.clientHeight || 768;\n const roomBelow = vh - r.bottom - GUTTER;\n const roomAbove = r.top - GUTTER;\n const panelH = panelRef.current?.scrollHeight ?? 240;\n const above = roomBelow < Math.min(panelH, 200) && roomAbove > roomBelow;\n const maxH = Math.max(120, Math.round((above ? roomAbove : roomBelow) - GAP));\n const vert: Pick<Place, 'top' | 'bottom'> = above ? { bottom: Math.max(GUTTER, vh - r.top + GAP) } : { top: r.bottom + GAP };\n\n // Phone-width: span the gutters - centred, full-width - rather than hang off the trigger.\n if (vw <= PHONE_W) return { left: GUTTER, right: GUTTER, ...vert, above, maxH };\n\n const panelW = Math.min(panelRef.current?.offsetWidth || (typeof width === 'number' ? width : 240), vw - GUTTER * 2);\n const wanted = align === 'end' ? r.right - panelW : r.left;\n const left = Math.min(Math.max(GUTTER, wanted), vw - GUTTER - panelW);\n return { left, ...vert, above, maxH };\n };\n\n setPlace(measure());\n const raf = window.setTimeout(() => setPlace(measure()), 0); // real height now that the panel is in the DOM\n const anchorTop = anchor.getBoundingClientRect().top;\n const onScroll = (e: Event) => {\n if (e.target instanceof Node && panelRef.current?.contains(e.target)) return;\n if (Math.abs(anchor.getBoundingClientRect().top - anchorTop) > 1) close(false);\n else setPlace(measure());\n };\n const onResize = () => setPlace(measure());\n window.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onResize);\n return () => {\n window.clearTimeout(raf);\n window.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onResize);\n };\n }, [open, mounted, align, width, close]);\n\n // Outside pointerdown closes.\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n const t = e.target as Node;\n if (anchorRef.current?.contains(t) || panelRef.current?.contains(t)) return;\n close(false);\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [open, close]);\n\n // Move focus into the panel on open. Which row starts active depends on how it\n // was opened (see `effectiveActive`). The panel only mounts once `place` is measured,\n // so on the first open of an instance this has to wait for it (`placed`), or the\n // focus stays on the trigger and the arrow keys / Enter never reach the panel.\n // Leave it be if something inside already took focus (an `autoFocus` field in a rich panel).\n const placed = place !== null;\n React.useEffect(() => {\n const panel = panelRef.current;\n if (open && mounted && placed && panel && !panel.contains(document.activeElement)) panel.focus({ preventScroll: true });\n }, [open, mounted, placed]);\n\n // Opened by a pointer, no row is active until one is hovered or arrowed to, so the\n // panel never looks hovered under a cursor that is still on the trigger.\n const effectiveActive = activeIndex >= 0 ? activeIndex : inputMode === 'pointer' ? -1 : itemIndexes[0] ?? -1;\n\n const activate = (i: number) => {\n const e = (items ?? [])[i];\n if (!e || !isItem(e) || e.disabled) return;\n e.onClick?.();\n if (!e.keepOpen) close();\n };\n\n const roverKeyDown = (ev: React.KeyboardEvent) => {\n if (ev.key === 'Escape') {\n ev.preventDefault();\n close();\n return;\n }\n if (ev.key === 'Tab') {\n close(false);\n return;\n }\n if (!items) return;\n const pos = itemIndexes.indexOf(effectiveActive);\n const last = itemIndexes[itemIndexes.length - 1];\n let next: number | undefined;\n if (ev.key === 'ArrowDown') next = itemIndexes[Math.min(pos + 1, itemIndexes.length - 1)];\n // From \"nothing active\" (pointer open) ArrowUp goes to the last row, like on the trigger.\n else if (ev.key === 'ArrowUp') next = pos < 0 ? last : itemIndexes[Math.max(pos - 1, 0)];\n else if (ev.key === 'Home') next = itemIndexes[0];\n else if (ev.key === 'End') next = last;\n else if (ev.key === 'Enter' || ev.key === ' ') {\n ev.preventDefault();\n activate(effectiveActive);\n return;\n } else return;\n ev.preventDefault();\n setInputMode('keyboard');\n if (next !== undefined) setActiveIndex(next);\n };\n\n // `viaPointer` picks the starting state (see `inputMode`).\n const toggle = (viaPointer: boolean) => {\n if (disabled) return;\n if (!open) setInputMode(viaPointer ? 'pointer' : 'keyboard');\n setOpen(!open);\n };\n\n const triggerEl = React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n onClick: (e: React.MouseEvent) => {\n (trigger.props as { onClick?: (e: React.MouseEvent) => void }).onClick?.(e);\n // A real click or tap carries a click count (`detail` >= 1). Enter / Space on the\n // trigger, a screen reader and `element.click()` all report 0.\n toggle((e?.detail ?? 0) > 0);\n },\n // Menu button pattern: ArrowDown opens on the first row, ArrowUp on the last.\n onKeyDown: (e: React.KeyboardEvent) => {\n (trigger.props as { onKeyDown?: (e: React.KeyboardEvent) => void }).onKeyDown?.(e);\n if (e.defaultPrevented || disabled || open || !items) return;\n if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;\n e.preventDefault();\n setInputMode('keyboard');\n setActiveIndex(e.key === 'ArrowUp' ? itemIndexes[itemIndexes.length - 1] ?? -1 : -1);\n setOpen(true);\n },\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n 'aria-controls': open ? menuId : undefined,\n 'data-menu-open': open || undefined,\n });\n\n const panelStyle = (p: Place): React.CSSProperties => {\n const full = p.right != null; // phone: left+right span the gutters, width is implied\n return sx({\n position: 'fixed',\n top: p.top,\n bottom: p.bottom,\n left: p.left,\n right: p.right,\n width: full ? undefined : width ?? 'max-content',\n minWidth: full ? undefined : width ?? 180,\n maxWidth: full ? undefined : `calc(100vw - ${GUTTER * 2}px)`,\n maxHeight: p.maxH,\n zIndex: 1200,\n display: 'flex',\n flexDirection: 'column',\n overflowY: 'auto',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: items ? 'var(--space-1)' : 0,\n outline: 'none',\n transformOrigin: p.above ? 'bottom' : 'top',\n animation: 'sereno-pop var(--duration-fast) var(--ease-out)',\n });\n };\n\n /* eslint-disable react-hooks/refs -- the `children` render function receives `close`, a stable\n useCallback that reads the anchor ref only when a consumer invokes it from an event handler -\n never during this render. */\n return (\n <span ref={anchorRef} style={sx({ display: 'inline-flex', position: 'relative' })}>\n {triggerEl}\n {adornment != null && <span style={sx({ position: 'absolute', inset: 0, pointerEvents: 'none' })}>{adornment}</span>}\n {open &&\n mounted &&\n place &&\n createPortal(\n <div\n ref={panelRef}\n id={menuId}\n role={items ? 'menu' : 'dialog'}\n aria-label={label}\n aria-modal={items ? undefined : true}\n tabIndex={-1}\n onKeyDown={roverKeyDown}\n style={panelStyle(place)}\n >\n {header && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n margin: items ? 'calc(var(--space-1) * -1) calc(var(--space-1) * -1) var(--space-1)' : 0,\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n })}\n >\n {header}\n </div>\n )}\n {items ? (\n <>\n {label && (\n <div\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {label}\n </div>\n )}\n {items.map((entry, i) => {\n if ('separator' in entry) {\n return <div key={i} role=\"separator\" style={sx({ height: 1, margin: 'var(--space-1) 0', background: 'var(--border-subtle)' })} />;\n }\n if ('heading' in entry) {\n return (\n <div\n key={i}\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {entry.heading}\n </div>\n );\n }\n const danger = entry.tone === 'danger';\n const active = i === effectiveActive && !entry.disabled;\n return (\n <button\n key={i}\n type=\"button\"\n role=\"menuitem\"\n disabled={entry.disabled}\n data-active={active || undefined}\n onMouseEnter={() => {\n if (entry.disabled) return;\n setActiveIndex(i);\n setInputMode('pointer');\n }}\n // Hover ends with the pointer, so the fill must not stay behind on the last\n // row it crossed. A row the keyboard moved to is left alone.\n onMouseLeave={() => {\n if (inputMode === 'pointer') setActiveIndex((a) => (a === i ? -1 : a));\n }}\n onClick={() => activate(i)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-3)',\n width: '100%',\n padding: 'var(--space-2) var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: active ? 'var(--bg-subtle)' : 'transparent',\n // The active row is not the DOM-focused element (the panel is), so mark it for keyboard users.\n boxShadow: active && inputMode === 'keyboard' ? 'var(--focus-ring)' : 'none',\n color: entry.disabled\n ? 'var(--text-disabled)'\n : danger\n ? 'var(--status-error-fg)'\n : 'var(--text-secondary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n textAlign: 'left',\n cursor: entry.disabled ? 'not-allowed' : 'pointer',\n })}\n >\n {entry.icon && <span style={sx({ display: 'flex', flex: '0 0 auto' })}>{entry.icon}</span>}\n <span style={sx({ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' })}>{entry.label}</span>\n </button>\n );\n })}\n </>\n ) : (\n children?.(close)\n )}\n </div>,\n document.body,\n )}\n </span>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"m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gBAAM,MAAK;AAAA,sBACnF,oBAAC,UAAK,OAAO,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,UAAU,cAAc,YAAY,YAAY,SAAS,CAAC,GAAI,gBAAM,OAAM;AAAA;AAAA;AAAA,kBAvCvH;AAAA,gBAwCP;AAAA,cAEJ,CAAC;AAAA,eACH,IAEA,WAAW,KAAK;AAAA;AAAA;AAAA,MAEpB;AAAA,MACA,SAAS;AAAA,IACX;AAAA,KACJ;AAGJ;","names":[]}
1
+ {"version":3,"sources":["../../src/core/Menu.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { sx } from '../_internal/style';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\n\n/**\n * Action menu / dropdown - a `trigger` you supply plus a portalled panel of\n * items. Same mechanics as `Select`: `position: fixed` panel measured off the\n * trigger, flips up when there's no room, closes on outside pointerdown / `Escape`\n * / selection, and returns focus to the trigger. `role=\"menu\"` with arrow-key\n * roving. Needs the `sereno-pop` keyframe from `@sereno-ds/ui/styles.css`.\n *\n * Opened with a click or tap, no row is highlighted until the pointer enters one\n * or the user arrows. Opened from the keyboard (Enter, Space or ArrowDown on the\n * trigger; ArrowUp for the last row) the first enabled row is active, with a\n * focus ring, so Enter acts straight away.\n *\n * ```tsx\n * <Menu\n * trigger={<IconButton label=\"Conta\"><User /></IconButton>}\n * items={[\n * { label: 'Configurações', icon: <Settings />, onClick: openSettings },\n * { separator: true },\n * { label: 'Sair', icon: <LogOut />, tone: 'danger', onClick: signOut },\n * ]}\n * />\n * ```\n *\n * For a rich popover (a notifications list, say) pass a render function instead\n * of `items` - it receives `close`:\n * `<Menu trigger={…}>{(close) => <NotificationList onDone={close} />}</Menu>`\n */\n\nexport interface MenuItem {\n label: string;\n icon?: React.ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n /** `danger` paints the row in the error colour (destructive action). */\n tone?: 'default' | 'danger';\n /** Keep the menu open after activating (e.g. a toggle row). Default `false`. */\n keepOpen?: boolean;\n}\n/** A hairline rule between groups. */\nexport interface MenuSeparator {\n separator: true;\n}\n/** A non-interactive group caption. */\nexport interface MenuHeading {\n heading: string;\n}\nexport type MenuEntry = MenuItem | MenuSeparator | MenuHeading;\n\nconst isItem = (e: MenuEntry): e is MenuItem => !('separator' in e) && !('heading' in e);\n\nexport interface MenuProps {\n /** The clickable element that opens the menu (an `IconButton`, `Button`, avatar button…). */\n trigger: React.ReactElement;\n /** Overlaid on the trigger - a notification count, a status dot. Sits in a\n * `pointer-events: none` layer so a click still opens the menu. */\n adornment?: React.ReactNode;\n /** Structured rows. Omit when using the `children` render function. */\n items?: MenuEntry[];\n /** Rich panel content - receives `close`. Mutually exclusive with `items`. */\n children?: (close: () => void) => React.ReactNode;\n /** A block above the `items` - a name + email, a title. Not part of the keyboard roving. */\n header?: React.ReactNode;\n /** Accessible name for the panel, and a heading row when `items` is used. */\n label?: string;\n /** Which trigger edge the panel lines up with. Default `end` (right). */\n align?: 'start' | 'end';\n /** Panel width. Number → px; string → any CSS length. Default: fits the content (min 180). */\n width?: number | string;\n disabled?: boolean;\n /** Controlled open state. Omit for uncontrolled. */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nconst GAP = 6;\nconst GUTTER = 12;\n\n/** `left` is clamped so the panel is always fully on screen; `above` picks the\n * vertical edge. On a narrow (phone) viewport `right` is set too - the panel\n * spans the gutters (centred, full-width) instead of hanging off the trigger. */\ntype Place = { top?: number; bottom?: number; left: number; right?: number; above: boolean; maxH: number };\n\n/** Phone-width viewport (`--bp-sm`). Width only - not `pointer: coarse`, which a\n * trackpad / touch laptop reports on a full-size screen. */\nconst PHONE_W = 560;\n\nexport function Menu({ trigger, adornment, items, children, header, label, align = 'end', width, disabled, open: openProp, onOpenChange }: MenuProps) {\n const rid = React.useId();\n const menuId = `${rid}-menu`;\n const anchorRef = React.useRef<HTMLSpanElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n\n const isControlled = openProp !== undefined;\n const [openState, setOpenState] = React.useState(false);\n const open = isControlled ? openProp! : openState;\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (!isControlled) setOpenState(next);\n onOpenChange?.(next);\n },\n [isControlled, onOpenChange],\n );\n\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\n const [place, setPlace] = React.useState<Place | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n // How the user is driving the menu. `pointer` (opened by a click or tap, or the mouse\n // entered a row): nothing is highlighted until a row is hovered or arrowed to. `keyboard`\n // (anything else): the first row is active so Enter works straight away, and the active\n // row gets a focus ring. Unknown opens (a screen reader, the parent forcing `open`) take\n // the keyboard side, the one that stays operable without a pointer.\n const [inputMode, setInputMode] = React.useState<'pointer' | 'keyboard'>('keyboard');\n\n // A fresh open never inherits the last session's row or mode, whichever way it closed\n // (Escape, outside click, the trigger, the parent). Adjusted during render, not in an effect.\n const [wasOpen, setWasOpen] = React.useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (!open) {\n setActiveIndex(-1);\n setInputMode('keyboard');\n }\n }\n\n const itemIndexes = React.useMemo(() => (items ?? []).map((e, i) => (isItem(e) && !e.disabled ? i : -1)).filter((i) => i >= 0), [items]);\n\n const close = React.useCallback(\n (refocus = true) => {\n setOpen(false);\n if (refocus) {\n const btn = anchorRef.current?.querySelector<HTMLElement>('button, [role=\"button\"], a, [tabindex]');\n btn?.focus({ preventScroll: true });\n }\n },\n [setOpen],\n );\n\n // Measure + place the panel while open. `left` is clamped to keep the whole\n // panel on screen (it can't just right-anchor - on a phone a 360px panel off a\n // trigger 300px from the left would run off the edge). Re-runs on scroll/resize;\n // closes if the trigger scrolls away (mirrors Select's fixed strategy). A\n // microtask re-measure picks up the real panel box once it's in the DOM.\n React.useLayoutEffect(() => {\n if (!open || !mounted) return;\n const anchor = anchorRef.current;\n if (!anchor) return;\n\n const measure = (): Place => {\n const r = anchor.getBoundingClientRect();\n // Fall back to a *desktop* width when unmeasurable - never full-width a\n // menu just because a reading came back 0 (a real phone always reports).\n const vw = window.innerWidth || document.documentElement.clientWidth || 1024;\n const vh = window.innerHeight || document.documentElement.clientHeight || 768;\n const roomBelow = vh - r.bottom - GUTTER;\n const roomAbove = r.top - GUTTER;\n const panelH = panelRef.current?.scrollHeight ?? 240;\n const above = roomBelow < Math.min(panelH, 200) && roomAbove > roomBelow;\n const maxH = Math.max(120, Math.round((above ? roomAbove : roomBelow) - GAP));\n const vert: Pick<Place, 'top' | 'bottom'> = above ? { bottom: Math.max(GUTTER, vh - r.top + GAP) } : { top: r.bottom + GAP };\n\n // Phone-width: span the gutters - centred, full-width - rather than hang off the trigger.\n if (vw <= PHONE_W) return { left: GUTTER, right: GUTTER, ...vert, above, maxH };\n\n const panelW = Math.min(panelRef.current?.offsetWidth || (typeof width === 'number' ? width : 240), vw - GUTTER * 2);\n const wanted = align === 'end' ? r.right - panelW : r.left;\n const left = Math.min(Math.max(GUTTER, wanted), vw - GUTTER - panelW);\n return { left, ...vert, above, maxH };\n };\n\n setPlace(measure());\n const raf = window.setTimeout(() => setPlace(measure()), 0); // real height now that the panel is in the DOM\n const anchorTop = anchor.getBoundingClientRect().top;\n const onScroll = (e: Event) => {\n if (e.target instanceof Node && panelRef.current?.contains(e.target)) return;\n if (Math.abs(anchor.getBoundingClientRect().top - anchorTop) > 1) close(false);\n else setPlace(measure());\n };\n const onResize = () => setPlace(measure());\n window.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onResize);\n return () => {\n window.clearTimeout(raf);\n window.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onResize);\n };\n }, [open, mounted, align, width, close]);\n\n // Outside pointerdown closes.\n useOutsidePress(open, [anchorRef, panelRef], () => close(false));\n\n // Move focus into the panel on open. Which row starts active depends on how it\n // was opened (see `effectiveActive`). The panel only mounts once `place` is measured,\n // so on the first open of an instance this has to wait for it (`placed`), or the\n // focus stays on the trigger and the arrow keys / Enter never reach the panel.\n // Leave it be if something inside already took focus (an `autoFocus` field in a rich panel).\n const placed = place !== null;\n React.useEffect(() => {\n const panel = panelRef.current;\n if (open && mounted && placed && panel && !panel.contains(document.activeElement)) panel.focus({ preventScroll: true });\n }, [open, mounted, placed]);\n\n // Opened by a pointer, no row is active until one is hovered or arrowed to, so the\n // panel never looks hovered under a cursor that is still on the trigger.\n const effectiveActive = activeIndex >= 0 ? activeIndex : inputMode === 'pointer' ? -1 : itemIndexes[0] ?? -1;\n\n const activate = (i: number) => {\n const e = (items ?? [])[i];\n if (!e || !isItem(e) || e.disabled) return;\n e.onClick?.();\n if (!e.keepOpen) close();\n };\n\n const roverKeyDown = (ev: React.KeyboardEvent) => {\n if (ev.key === 'Escape') {\n ev.preventDefault();\n close();\n return;\n }\n if (ev.key === 'Tab') {\n close(false);\n return;\n }\n if (!items) return;\n const pos = itemIndexes.indexOf(effectiveActive);\n const last = itemIndexes[itemIndexes.length - 1];\n let next: number | undefined;\n if (ev.key === 'ArrowDown') next = itemIndexes[Math.min(pos + 1, itemIndexes.length - 1)];\n // From \"nothing active\" (pointer open) ArrowUp goes to the last row, like on the trigger.\n else if (ev.key === 'ArrowUp') next = pos < 0 ? last : itemIndexes[Math.max(pos - 1, 0)];\n else if (ev.key === 'Home') next = itemIndexes[0];\n else if (ev.key === 'End') next = last;\n else if (ev.key === 'Enter' || ev.key === ' ') {\n ev.preventDefault();\n activate(effectiveActive);\n return;\n } else return;\n ev.preventDefault();\n setInputMode('keyboard');\n if (next !== undefined) setActiveIndex(next);\n };\n\n // `viaPointer` picks the starting state (see `inputMode`).\n const toggle = (viaPointer: boolean) => {\n if (disabled) return;\n if (!open) setInputMode(viaPointer ? 'pointer' : 'keyboard');\n setOpen(!open);\n };\n\n const triggerEl = React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n onClick: (e: React.MouseEvent) => {\n (trigger.props as { onClick?: (e: React.MouseEvent) => void }).onClick?.(e);\n // A real click or tap carries a click count (`detail` >= 1). Enter / Space on the\n // trigger, a screen reader and `element.click()` all report 0.\n toggle((e?.detail ?? 0) > 0);\n },\n // Menu button pattern: ArrowDown opens on the first row, ArrowUp on the last.\n onKeyDown: (e: React.KeyboardEvent) => {\n (trigger.props as { onKeyDown?: (e: React.KeyboardEvent) => void }).onKeyDown?.(e);\n if (e.defaultPrevented || disabled || open || !items) return;\n if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;\n e.preventDefault();\n setInputMode('keyboard');\n setActiveIndex(e.key === 'ArrowUp' ? itemIndexes[itemIndexes.length - 1] ?? -1 : -1);\n setOpen(true);\n },\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n 'aria-controls': open ? menuId : undefined,\n 'data-menu-open': open || undefined,\n });\n\n const panelStyle = (p: Place): React.CSSProperties => {\n const full = p.right != null; // phone: left+right span the gutters, width is implied\n return sx({\n position: 'fixed',\n top: p.top,\n bottom: p.bottom,\n left: p.left,\n right: p.right,\n width: full ? undefined : width ?? 'max-content',\n minWidth: full ? undefined : width ?? 180,\n maxWidth: full ? undefined : `calc(100vw - ${GUTTER * 2}px)`,\n maxHeight: p.maxH,\n zIndex: 1200,\n display: 'flex',\n flexDirection: 'column',\n overflowY: 'auto',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: items ? 'var(--space-1)' : 0,\n outline: 'none',\n transformOrigin: p.above ? 'bottom' : 'top',\n animation: 'sereno-pop var(--duration-fast) var(--ease-out)',\n });\n };\n\n /* eslint-disable react-hooks/refs -- the `children` render function receives `close`, a stable\n useCallback that reads the anchor ref only when a consumer invokes it from an event handler -\n never during this render. */\n return (\n <span ref={anchorRef} style={sx({ display: 'inline-flex', position: 'relative' })}>\n {triggerEl}\n {adornment != null && <span style={sx({ position: 'absolute', inset: 0, pointerEvents: 'none' })}>{adornment}</span>}\n {open &&\n mounted &&\n place &&\n createPortal(\n <div\n ref={panelRef}\n id={menuId}\n role={items ? 'menu' : 'dialog'}\n aria-label={label}\n aria-modal={items ? undefined : true}\n tabIndex={-1}\n onKeyDown={roverKeyDown}\n style={panelStyle(place)}\n >\n {header && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n margin: items ? 'calc(var(--space-1) * -1) calc(var(--space-1) * -1) var(--space-1)' : 0,\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n })}\n >\n {header}\n </div>\n )}\n {items ? (\n <>\n {label && (\n <div\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {label}\n </div>\n )}\n {items.map((entry, i) => {\n if ('separator' in entry) {\n return <div key={i} role=\"separator\" style={sx({ height: 1, margin: 'var(--space-1) 0', background: 'var(--border-subtle)' })} />;\n }\n if ('heading' in entry) {\n return (\n <div\n key={i}\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {entry.heading}\n </div>\n );\n }\n const danger = entry.tone === 'danger';\n const active = i === effectiveActive && !entry.disabled;\n return (\n <button\n key={i}\n type=\"button\"\n role=\"menuitem\"\n disabled={entry.disabled}\n data-active={active || undefined}\n onMouseEnter={() => {\n if (entry.disabled) return;\n setActiveIndex(i);\n setInputMode('pointer');\n }}\n // Hover ends with the pointer, so the fill must not stay behind on the last\n // row it crossed. A row the keyboard moved to is left alone.\n onMouseLeave={() => {\n if (inputMode === 'pointer') setActiveIndex((a) => (a === i ? -1 : a));\n }}\n onClick={() => activate(i)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-3)',\n width: '100%',\n padding: 'var(--space-2) var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: active ? 'var(--bg-subtle)' : 'transparent',\n // The active row is not the DOM-focused element (the panel is), so mark it for keyboard users.\n boxShadow: active && inputMode === 'keyboard' ? 'var(--focus-ring)' : 'none',\n color: entry.disabled\n ? 'var(--text-disabled)'\n : danger\n ? 'var(--status-error-fg)'\n : 'var(--text-secondary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n textAlign: 'left',\n cursor: entry.disabled ? 'not-allowed' : 'pointer',\n })}\n >\n {entry.icon && <span style={sx({ display: 'flex', flex: '0 0 auto' })}>{entry.icon}</span>}\n <span style={sx({ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' })}>{entry.label}</span>\n </button>\n );\n })}\n </>\n ) : (\n children?.(close)\n )}\n </div>,\n document.body,\n )}\n </span>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AA0T4B,SA6Bd,UA7Bc,KAsER,YAtEQ;AAxT5B,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAkDhC,MAAM,SAAS,CAAC,MAAgC,EAAE,eAAe,MAAM,EAAE,aAAa;AA0BtF,MAAM,MAAM;AACZ,MAAM,SAAS;AASf,MAAM,UAAU;AAET,SAAS,KAAK,EAAE,SAAS,WAAW,OAAO,UAAU,QAAQ,OAAO,QAAQ,OAAO,OAAO,UAAU,MAAM,UAAU,aAAa,GAAc;AACpJ,QAAM,MAAM,MAAM,MAAM;AACxB,QAAM,SAAS,GAAG,GAAG;AACrB,QAAM,YAAY,MAAM,OAAwB,IAAI;AACpD,QAAM,WAAW,MAAM,OAAuB,IAAI;AAElD,QAAM,eAAe,aAAa;AAClC,QAAM,CAAC,WAAW,YAA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Y;AAAA,sBACZ,KAAK;AAAA,sBACL,OAAO;AAAA,sBACP,SAAS;AAAA,sBACT,QAAQ;AAAA,sBACR,cAAc;AAAA,sBACd,YAAY,SAAS,qBAAqB;AAAA;AAAA,sBAE1C,WAAW,UAAU,cAAc,aAAa,sBAAsB;AAAA,sBACtE,OAAO,MAAM,WACT,yBACA,SACE,2BACA;AAAA,sBACN,YAAY;AAAA,sBACZ,UAAU;AAAA,sBACV,WAAW;AAAA,sBACX,QAAQ,MAAM,WAAW,gBAAgB;AAAA,oBAC3C,CAAC;AAAA,oBAEA;AAAA,4BAAM,QAAQ,oBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,MAAM,WAAW,CAAC,GAAI,gBAAM,MAAK;AAAA,sBACnF,oBAAC,UAAK,OAAO,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,UAAU,cAAc,YAAY,YAAY,SAAS,CAAC,GAAI,gBAAM,OAAM;AAAA;AAAA;AAAA,kBAvCvH;AAAA,gBAwCP;AAAA,cAEJ,CAAC;AAAA,eACH,IAEA,WAAW,KAAK;AAAA;AAAA;AAAA,MAEpB;AAAA,MACA,SAAS;AAAA,IACX;AAAA,KACJ;AAGJ;","names":[]}
@@ -11,6 +11,7 @@ import { useIsoLayoutEffect } from "../_internal/useIsoLayoutEffect.js";
11
11
  import { useLatest } from "../_internal/useLatest.js";
12
12
  import { useCoarsePointer } from "../_internal/useCoarsePointer.js";
13
13
  import { useMenuPlacement } from "../_internal/useMenuPlacement.js";
14
+ import { useOutsidePress } from "../_internal/useOutsidePress.js";
14
15
  import { revealInList, useRevealActive } from "../_internal/useRevealActive.js";
15
16
  import { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from "../_internal/MenuOption.js";
16
17
  import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
@@ -160,17 +161,7 @@ const Autocomplete = React.forwardRef(function Autocomplete2({
160
161
  useIsoLayoutEffect(() => {
161
162
  if (draft !== null && listRef.current) listRef.current.scrollTop = 0;
162
163
  }, [draft, firstValue]);
163
- const settleRef = useLatest(settle);
164
- React.useEffect(() => {
165
- if (!open) return;
166
- const onDown = (e) => {
167
- const target = e.target;
168
- if (boxRef.current?.contains(target) || panelRef.current?.contains(target)) return;
169
- settleRef.current();
170
- };
171
- document.addEventListener("pointerdown", onDown, true);
172
- return () => document.removeEventListener("pointerdown", onDown, true);
173
- }, [open, settleRef]);
164
+ useOutsidePress(open, [boxRef, panelRef], () => settle());
174
165
  const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;
175
166
  const lastEnabledKey = () => {
176
167
  for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { srOnlyStyle } from '../_internal/srOnly';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useLatest } from '../_internal/useLatest';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { revealInList, useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface AutocompleteOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/** Every string the component says. Defaults come from `locale`; pass `labels` to change some. */\nexport interface AutocompleteLabels {\n /** Placeholder of the text box while nothing is chosen. */\n placeholder: string;\n /** aria-label of the clear (×) button. */\n clear: string;\n /** aria-label of the chevron button while the list is closed. */\n open: string;\n /** aria-label of the chevron button while the list is open. */\n close: string;\n /** What a screen reader hears while `loading` (the list itself shows only a spinner). */\n loading: string;\n /** The row shown when no option is left to show. */\n empty: string;\n /** What a screen reader hears when the list changes size. */\n results: (count: number) => string;\n}\n\nconst TEXT: Record<'pt-BR' | 'en', AutocompleteLabels> = {\n 'pt-BR': {\n placeholder: 'Buscar…',\n clear: 'Limpar seleção',\n open: 'Abrir lista',\n close: 'Fechar lista',\n loading: 'Carregando…',\n empty: 'Nenhum resultado',\n results: (n) => (n === 1 ? '1 resultado' : n + ' resultados'),\n },\n en: {\n placeholder: 'Search…',\n clear: 'Clear selection',\n open: 'Open list',\n close: 'Close list',\n loading: 'Loading…',\n empty: 'No results',\n results: (n) => (n === 1 ? '1 result' : n + ' results'),\n },\n};\n\n/**\n * Single choice from a list you search by typing. Like `Select`, but the box is a text field: type\n * to narrow the list, pick one row, and the value is that row. For a list too long to scroll\n * (past ~12 options), or one the server searches and pages (a thousand clients, fifty at a time).\n *\n * The value is the chosen option itself, `{ value, label }`, and it carries its own label. The\n * box shows `value.label` whether or not that option is in `options` right now, which is what\n * keeps the label when the page it came from is no longer loaded. `options` is only what the list\n * shows. `onValueChange` gives the option (or `null` when cleared), not a string.\n *\n * Two kinds of search, one prop apart:\n * - the default filters `options` itself, as you type (case and accents ignored);\n * - `filter={false}` leaves the list alone and tells you what was typed (`onSearch`, debounced),\n * for a list the server already filtered.\n *\n * It is a text box, not free text: what is typed never becomes the value. Leaving the box puts the\n * chosen label back.\n */\nexport interface AutocompleteProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n /** What the list shows now. Appending rows while it is open is fine: the list keeps its scroll. */\n options?: AutocompleteOption[];\n /** Controlled value: the chosen option, or `null` for none. */\n value?: AutocompleteOption | null;\n /** Uncontrolled initial value. */\n defaultValue?: AutocompleteOption | null;\n /** The chosen option, or `null` when the value is cleared. */\n onValueChange?: (option: AutocompleteOption | null) => void;\n /**\n * How typing narrows `options`. `true` (default): keep the rows whose label contains the text,\n * ignoring case and accents. `false`: show `options` as they are (the server did the filtering).\n * A function decides per row.\n */\n filter?: boolean | ((option: AutocompleteOption, query: string) => boolean);\n /**\n * The text to search for changed: fired as the user types (after `debounce`) and with `''` once\n * the box goes back to showing the chosen label (pick, clear, leave, Esc). Never with the label\n * itself, so it is safe to run the query here. Use it with `filter={false}`.\n */\n onSearch?: (query: string) => void;\n /** Debounce for `onSearch` while typing, in ms. */\n debounce?: number;\n /** The list is waiting for rows: a spinner under them (or alone), the list marked busy, and a screen reader told. */\n loading?: boolean;\n /**\n * The list was scrolled to within about five rows of its end. Fires once per list size, never\n * while `loading`. Pass it only while there is a next page, so a list that is complete asks for nothing.\n */\n onReachEnd?: () => void;\n /** The list opened or closed. For a list that loads when it opens. */\n onOpenChange?: (open: boolean) => void;\n /** A × button, and an emptied box clears the value. */\n clearable?: boolean;\n /** Shown in muted text while nothing is chosen. Defaults to the `locale` text. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Form field name - mirrored to a hidden input so the chosen value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the text box. Only needed when there's no visible `label`. Takes\n * precedence over `label` if both are set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the field from growing\n * the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /** Language of the built-in texts. */\n locale?: 'pt-BR' | 'en';\n /** Override any built-in text. */\n labels?: Partial<AutocompleteLabels>;\n}\n\n/** How close to the end of the list, in rows, `onReachEnd` fires. */\nconst REACH_ROWS = 5;\n\nconst MARKS = /[̀-ͯ]/g;\nconst plain = (s: string) => s.normalize('NFD').replace(MARKS, '').toLowerCase();\n\nfunction narrow(\n options: AutocompleteOption[],\n filter: AutocompleteProps['filter'],\n query: string,\n): AutocompleteOption[] {\n if (filter === false) return options;\n const q = query.trim();\n if (!q) return options;\n if (typeof filter === 'function') return options.filter((o) => filter(o, query));\n const needle = plain(q);\n return options.filter((o) => plain(o.label).includes(needle));\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the chosen value (rendered only\n * when `name` is set - pass it, as `register()` does), the same as `Select`. A plain\n * `{...register(name)}` spread still won't validate on change: wire it through `Controller`, or\n * call the registered `onChange` yourself from `onValueChange`.\n */\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(function Autocomplete(\n {\n label,\n hint,\n error,\n required,\n options = [],\n value: valueProp,\n defaultValue,\n onValueChange,\n filter = true,\n onSearch,\n debounce = 250,\n loading = false,\n onReachEnd,\n onOpenChange,\n clearable = true,\n placeholder,\n size = 'md',\n disabled,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n locale = 'pt-BR',\n labels,\n },\n ref,\n) {\n const reactId = React.useId();\n const rid = id || reactId;\n const listboxId = `${rid}-listbox`;\n const copy: AutocompleteLabels = { ...TEXT[locale], ...labels };\n const coarse = useCoarsePointer();\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n\n // ── value: the chosen option, with its own label ──\n const isControlled = valueProp !== undefined;\n const [inner, setInner] = React.useState<AutocompleteOption | null>(defaultValue ?? null);\n const value = isControlled ? valueProp : inner;\n const valueLabel = value?.label ?? '';\n\n // ── the text box: the chosen label, until the user types (`draft`) ──\n const [draft, setDraft] = React.useState<string | null>(null);\n const text = draft ?? valueLabel;\n const query = draft ?? '';\n\n const [open, setOpen] = React.useState(false);\n const [focused, setFocused] = React.useState(false);\n const [activeKey, setActiveKey] = React.useState<string | null>(null);\n // The active row is the chosen one only because the list opened on it, not because the user went\n // there: set by opening, cleared by the first thing the user does to the highlight.\n const activeFromOpen = React.useRef(false);\n const pick = (key: string | null) => {\n activeFromOpen.current = false;\n setActiveKey(key);\n };\n\n const visible = React.useMemo(() => narrow(options, filter, query), [options, filter, query]);\n const activeIndex = activeKey === null ? -1 : visible.findIndex((o) => o.value === activeKey && !o.disabled);\n const activeId = activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null;\n\n const rows = visible.length;\n const status = loading ? copy.loading : rows === 0 ? copy.empty : null;\n\n // ── open / close, told to the app once per change ──\n const onOpenChangeRef = useLatest(onOpenChange);\n const toldOpen = React.useRef(false);\n React.useEffect(() => {\n if (toldOpen.current === open) return;\n toldOpen.current = open;\n onOpenChangeRef.current?.(open);\n }, [open, onOpenChangeRef]);\n\n // ── search: told to the app when the query changes, debounced while typing ──\n const onSearchRef = useLatest(onSearch);\n const searchTimer = React.useRef<number | undefined>(undefined);\n const toldQuery = React.useRef('');\n React.useEffect(() => () => window.clearTimeout(searchTimer.current), []);\n const search = (q: string, immediate: boolean) => {\n window.clearTimeout(searchTimer.current);\n const run = () => {\n if (q === toldQuery.current) return;\n toldQuery.current = q;\n onSearchRef.current?.(q);\n };\n if (immediate) run();\n else searchTimer.current = window.setTimeout(run, debounce);\n };\n\n /** The box goes back to the chosen label: closes the list, drops what was typed, resets the query. */\n const settle = () => {\n setOpen(false);\n setDraft(null);\n search('', true);\n };\n\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef,\n itemCount: rows + (status ? 1 : 0),\n onDismiss: () => settle(),\n });\n // The chosen row can arrive after the list opened (a list that loads when it opens, on the page around\n // the chosen row). It is brought into view then, unless the user has already scrolled the list away\n // from the top: a user paging down for the next page is not carried off to a row that just landed.\n useRevealActive(open, activeId, place, revealInList, (el) => !activeFromOpen.current || (el.parentElement?.scrollTop ?? 0) === 0);\n\n // ── pagination: ask for more once the list is near its end ──\n const onReachEndRef = useLatest(onReachEnd);\n const askedFor = React.useRef<string | null>(null);\n // What the list is, for \"once per size\": a new search that happens to return as many rows is a new list.\n const shape = options.length + '|' + (options[0]?.value ?? '') + '|' + (options[options.length - 1]?.value ?? '');\n useIsoLayoutEffect(() => {\n if (!open) {\n askedFor.current = null;\n return;\n }\n const list = listRef.current;\n if (!list || rows === 0) return;\n const check = () => {\n if (loading || !onReachEndRef.current || askedFor.current === shape) return;\n const remaining = list.scrollHeight - list.scrollTop - list.clientHeight;\n if (remaining > (list.scrollHeight / rows) * REACH_ROWS) return;\n askedFor.current = shape;\n onReachEndRef.current();\n };\n check();\n list.addEventListener('scroll', check, { passive: true });\n return () => list.removeEventListener('scroll', check);\n }, [open, loading, shape, place, rows, onReachEndRef]);\n\n // A new search starts at the top.\n const firstValue = options[0]?.value;\n useIsoLayoutEffect(() => {\n if (draft !== null && listRef.current) listRef.current.scrollTop = 0;\n }, [draft, firstValue]);\n\n // iOS keeps the keyboard (and the field) up when you tap on plain page: close on any press outside.\n const settleRef = useLatest(settle);\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n const target = e.target as Node;\n if (boxRef.current?.contains(target) || panelRef.current?.contains(target)) return;\n settleRef.current();\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [open, settleRef]);\n\n // ── choosing ──\n const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;\n const lastEnabledKey = () => {\n for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;\n return null;\n };\n const move = (dir: 1 | -1) => {\n let i = activeIndex < 0 ? (dir === 1 ? -1 : rows) : activeIndex;\n for (let step = 0; step < rows; step++) {\n i += dir;\n if (i < 0 || i >= rows) return; // the ends are walls, not a loop: a paged list has no \"wrap\"\n if (!visible[i].disabled) {\n pick(visible[i].value);\n return;\n }\n }\n };\n\n const choose = (o: AutocompleteOption) => {\n if (o.disabled) return;\n if (!isControlled) setInner(o);\n onValueChange?.(o);\n setOpen(false);\n setDraft(null);\n search('', true);\n // On a phone the keyboard goes with the choice.\n if (coarse) inputRef.current?.blur();\n };\n const clear = () => {\n if (value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n setDraft(''); // empty at once, even if the app takes a moment to take the value away\n search('', true);\n inputRef.current?.focus();\n };\n\n const selectedKey = value?.value;\n // Opening starts on the chosen row. If it is not in the list *yet* because the list is empty (it\n // loads when it opens), it stays the active one so it is revealed when it arrives. With rows on screen\n // that do not include it, it is not chased: the list is not moved under the user later.\n const startKey = (fallback: string | null) =>\n selectedKey !== undefined && (rows === 0 || visible.some((o) => o.value === selectedKey)) ? selectedKey : fallback;\n const openFromPointer = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(null));\n setOpen(true);\n };\n const openFromKey = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(firstEnabledKey()));\n setOpen(true);\n };\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const next = e.currentTarget.value;\n setDraft(next);\n // Filtering here, the first match is ready for Enter. A server search has not answered yet:\n // an Enter now would pick a row of the old answer, so nothing is active until the user moves.\n pick(filter === false ? null : narrow(options, filter, next).find((o) => !o.disabled)?.value ?? null);\n setOpen(true);\n if (next === '' && clearable && value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n search(next, false);\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled || e.nativeEvent.isComposing) return; // an IME is still composing the text\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) openFromKey();\n else move(1);\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) openFromKey();\n else move(-1);\n return;\n case 'Home':\n case 'End':\n if (open) {\n e.preventDefault();\n pick(e.key === 'Home' ? firstEnabledKey() : lastEnabledKey());\n }\n return;\n case 'Enter':\n // Closed: let the form have its Enter. Open: it is for the list, never a submit.\n if (open) {\n e.preventDefault();\n if (activeIndex >= 0) choose(visible[activeIndex]);\n }\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 settle();\n }\n return;\n default:\n }\n };\n\n // Select the text on the way in, so typing replaces the label instead of appending to it. The click\n // that gave the focus would put the caret back, hence the second select.\n const selectOnClick = React.useRef(false);\n\n const fieldAria = fieldA11y(rid, { hint, error, required });\n const rowPadY = menuRowPadY(coarse, size);\n const fontSize = size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)';\n const showClear = clearable && !disabled && text !== '';\n\n const list = (\n <div\n ref={panelRef}\n // Keeps the focus in the text box: pressing the list (or its scrollbar) must not blur it.\n onMouseDown={(e) => e.preventDefault()}\n style={sx({\n ...menuSurfaceStyle(size),\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n maxHeight: place?.maxH,\n ...(place?.strategy === 'fixed'\n ? {\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n zIndex: 1100,\n }\n : {\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place?.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n zIndex: 100,\n }),\n })}\n >\n <ul\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={ariaLabel ?? label}\n aria-busy={loading || undefined}\n tabIndex={-1}\n style={sx({\n ...menuListStyle,\n position: 'relative', // so an option's offsetTop is measured from the list\n flex: '1 1 auto',\n minHeight: 0,\n padding: rows ? 'var(--space-1)' : 0,\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {visible.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === selectedKey}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n // Pointer *move*, not enter: a list that scrolls under a still mouse (the keyboard\n // revealing a row) must not hand the highlight to whatever slid beneath it.\n onPointerMove={() => !o.disabled && pick(o.value)}\n onClick={() => choose(o)}\n />\n ))}\n </ul>\n {status && (\n // Loading is a lone spinner, no text and no rule above it: a screen reader gets the words from the\n // live region below, and this is for the eye. \"No results\" is the same row with words.\n <div\n aria-hidden=\"true\"\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: coarse ? 44 : undefined,\n padding: 'var(--space-3)',\n color: 'var(--text-muted)',\n fontSize: coarse ? 'var(--text-base)' : 'var(--text-sm)',\n })}\n >\n {loading ? (\n <span\n style={sx({\n flex: '0 0 auto',\n width: 18,\n height: 18,\n borderRadius: '999px',\n border: '2px solid var(--border-default)',\n borderTopColor: 'var(--text-brand)',\n animation: 'sereno-spin .7s linear infinite',\n })}\n />\n ) : (\n status\n )}\n </div>\n )}\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div style={sx({ position: 'relative', width: '100%' })}>\n <div\n ref={boxRef}\n // The padding around the text is part of the field: pressing it puts the caret in the box.\n onMouseDown={(e) => {\n if (e.target === inputRef.current || disabled) return;\n e.preventDefault();\n inputRef.current?.focus();\n }}\n style={sx({ ...fieldBoxStyle(size, !!error, focused || open, !!disabled), cursor: disabled ? 'not-allowed' : 'text' })}\n >\n <input\n ref={inputRef}\n id={rid}\n type=\"text\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeId ? activeId : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n // A text box that looks like a name or an address draws the browser's autofill and the\n // password managers. Best effort: Chrome ignores `autoComplete=\"off\"`, and Bitwarden only\n // honors its attribute when the user turned that option on.\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n enterKeyHint=\"done\"\n data-1p-ignore\n data-lpignore=\"true\"\n data-bwignore=\"true\"\n data-form-type=\"other\"\n disabled={disabled}\n placeholder={placeholder ?? copy.placeholder}\n value={text}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onFocus={(e) => {\n setFocused(true);\n selectOnClick.current = true;\n e.currentTarget.select();\n }}\n onBlur={(e) => {\n setFocused(false);\n if (boxRef.current?.contains(e.relatedTarget as Node | null)) return;\n settle();\n }}\n onClick={(e) => {\n const el = e.currentTarget;\n if (selectOnClick.current && el.selectionStart === el.selectionEnd) el.select();\n selectOnClick.current = false;\n if (!open) openFromPointer();\n }}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the box's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize,\n lineHeight: 1.2,\n textOverflow: 'ellipsis',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n })}\n />\n {showClear && (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n aria-label={copy.clear}\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n >\n <X size={16} strokeWidth={2} />\n </button>\n )}\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n disabled={disabled}\n aria-label={open ? copy.close : copy.open}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n inputRef.current?.focus({ preventScroll: true });\n if (open) settle();\n else openFromPointer();\n }}\n style={sx({\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 </button>\n </div>\n\n {open && place && place.strategy === 'inline' && list}\n {open && place && place.strategy === 'fixed' && createPortal(list, document.body)}\n\n {/* Always rendered, so the change of its text is what a screen reader announces. */}\n <div role=\"status\" aria-live=\"polite\" style={srOnlyStyle}>\n {open ? (loading ? copy.loading : rows === 0 ? copy.empty : copy.results(rows)) : ''}\n </div>\n </div>\n {name && <input ref={ref} type=\"hidden\" name={name} value={value?.value ?? ''} />}\n </Field>\n );\n});\n\nAutocomplete.displayName = 'Autocomplete';\n"],"mappings":";AA2bI,SA6CM,KA7CN;AAzbJ,YAAY,WAAW;AACvB,SAAS,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IAAI;AAAA,KACjF;AAEJ,CAAC;AAED,aAAa,cAAc;","names":["Autocomplete","list"]}
1
+ {"version":3,"sources":["../../src/forms/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { srOnlyStyle } from '../_internal/srOnly';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useLatest } from '../_internal/useLatest';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { revealInList, useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface AutocompleteOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/** Every string the component says. Defaults come from `locale`; pass `labels` to change some. */\nexport interface AutocompleteLabels {\n /** Placeholder of the text box while nothing is chosen. */\n placeholder: string;\n /** aria-label of the clear (×) button. */\n clear: string;\n /** aria-label of the chevron button while the list is closed. */\n open: string;\n /** aria-label of the chevron button while the list is open. */\n close: string;\n /** What a screen reader hears while `loading` (the list itself shows only a spinner). */\n loading: string;\n /** The row shown when no option is left to show. */\n empty: string;\n /** What a screen reader hears when the list changes size. */\n results: (count: number) => string;\n}\n\nconst TEXT: Record<'pt-BR' | 'en', AutocompleteLabels> = {\n 'pt-BR': {\n placeholder: 'Buscar…',\n clear: 'Limpar seleção',\n open: 'Abrir lista',\n close: 'Fechar lista',\n loading: 'Carregando…',\n empty: 'Nenhum resultado',\n results: (n) => (n === 1 ? '1 resultado' : n + ' resultados'),\n },\n en: {\n placeholder: 'Search…',\n clear: 'Clear selection',\n open: 'Open list',\n close: 'Close list',\n loading: 'Loading…',\n empty: 'No results',\n results: (n) => (n === 1 ? '1 result' : n + ' results'),\n },\n};\n\n/**\n * Single choice from a list you search by typing. Like `Select`, but the box is a text field: type\n * to narrow the list, pick one row, and the value is that row. For a list too long to scroll\n * (past ~12 options), or one the server searches and pages (a thousand clients, fifty at a time).\n *\n * The value is the chosen option itself, `{ value, label }`, and it carries its own label. The\n * box shows `value.label` whether or not that option is in `options` right now, which is what\n * keeps the label when the page it came from is no longer loaded. `options` is only what the list\n * shows. `onValueChange` gives the option (or `null` when cleared), not a string.\n *\n * Two kinds of search, one prop apart:\n * - the default filters `options` itself, as you type (case and accents ignored);\n * - `filter={false}` leaves the list alone and tells you what was typed (`onSearch`, debounced),\n * for a list the server already filtered.\n *\n * It is a text box, not free text: what is typed never becomes the value. Leaving the box puts the\n * chosen label back.\n */\nexport interface AutocompleteProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n /** What the list shows now. Appending rows while it is open is fine: the list keeps its scroll. */\n options?: AutocompleteOption[];\n /** Controlled value: the chosen option, or `null` for none. */\n value?: AutocompleteOption | null;\n /** Uncontrolled initial value. */\n defaultValue?: AutocompleteOption | null;\n /** The chosen option, or `null` when the value is cleared. */\n onValueChange?: (option: AutocompleteOption | null) => void;\n /**\n * How typing narrows `options`. `true` (default): keep the rows whose label contains the text,\n * ignoring case and accents. `false`: show `options` as they are (the server did the filtering).\n * A function decides per row.\n */\n filter?: boolean | ((option: AutocompleteOption, query: string) => boolean);\n /**\n * The text to search for changed: fired as the user types (after `debounce`) and with `''` once\n * the box goes back to showing the chosen label (pick, clear, leave, Esc). Never with the label\n * itself, so it is safe to run the query here. Use it with `filter={false}`.\n */\n onSearch?: (query: string) => void;\n /** Debounce for `onSearch` while typing, in ms. */\n debounce?: number;\n /** The list is waiting for rows: a spinner under them (or alone), the list marked busy, and a screen reader told. */\n loading?: boolean;\n /**\n * The list was scrolled to within about five rows of its end. Fires once per list size, never\n * while `loading`. Pass it only while there is a next page, so a list that is complete asks for nothing.\n */\n onReachEnd?: () => void;\n /** The list opened or closed. For a list that loads when it opens. */\n onOpenChange?: (open: boolean) => void;\n /** A × button, and an emptied box clears the value. */\n clearable?: boolean;\n /** Shown in muted text while nothing is chosen. Defaults to the `locale` text. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Form field name - mirrored to a hidden input so the chosen value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the text box. Only needed when there's no visible `label`. Takes\n * precedence over `label` if both are set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the field from growing\n * the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /** Language of the built-in texts. */\n locale?: 'pt-BR' | 'en';\n /** Override any built-in text. */\n labels?: Partial<AutocompleteLabels>;\n}\n\n/** How close to the end of the list, in rows, `onReachEnd` fires. */\nconst REACH_ROWS = 5;\n\nconst MARKS = /[̀-ͯ]/g;\nconst plain = (s: string) => s.normalize('NFD').replace(MARKS, '').toLowerCase();\n\nfunction narrow(\n options: AutocompleteOption[],\n filter: AutocompleteProps['filter'],\n query: string,\n): AutocompleteOption[] {\n if (filter === false) return options;\n const q = query.trim();\n if (!q) return options;\n if (typeof filter === 'function') return options.filter((o) => filter(o, query));\n const needle = plain(q);\n return options.filter((o) => plain(o.label).includes(needle));\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the chosen value (rendered only\n * when `name` is set - pass it, as `register()` does), the same as `Select`. A plain\n * `{...register(name)}` spread still won't validate on change: wire it through `Controller`, or\n * call the registered `onChange` yourself from `onValueChange`.\n */\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(function Autocomplete(\n {\n label,\n hint,\n error,\n required,\n options = [],\n value: valueProp,\n defaultValue,\n onValueChange,\n filter = true,\n onSearch,\n debounce = 250,\n loading = false,\n onReachEnd,\n onOpenChange,\n clearable = true,\n placeholder,\n size = 'md',\n disabled,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n locale = 'pt-BR',\n labels,\n },\n ref,\n) {\n const reactId = React.useId();\n const rid = id || reactId;\n const listboxId = `${rid}-listbox`;\n const copy: AutocompleteLabels = { ...TEXT[locale], ...labels };\n const coarse = useCoarsePointer();\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n\n // ── value: the chosen option, with its own label ──\n const isControlled = valueProp !== undefined;\n const [inner, setInner] = React.useState<AutocompleteOption | null>(defaultValue ?? null);\n const value = isControlled ? valueProp : inner;\n const valueLabel = value?.label ?? '';\n\n // ── the text box: the chosen label, until the user types (`draft`) ──\n const [draft, setDraft] = React.useState<string | null>(null);\n const text = draft ?? valueLabel;\n const query = draft ?? '';\n\n const [open, setOpen] = React.useState(false);\n const [focused, setFocused] = React.useState(false);\n const [activeKey, setActiveKey] = React.useState<string | null>(null);\n // The active row is the chosen one only because the list opened on it, not because the user went\n // there: set by opening, cleared by the first thing the user does to the highlight.\n const activeFromOpen = React.useRef(false);\n const pick = (key: string | null) => {\n activeFromOpen.current = false;\n setActiveKey(key);\n };\n\n const visible = React.useMemo(() => narrow(options, filter, query), [options, filter, query]);\n const activeIndex = activeKey === null ? -1 : visible.findIndex((o) => o.value === activeKey && !o.disabled);\n const activeId = activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null;\n\n const rows = visible.length;\n const status = loading ? copy.loading : rows === 0 ? copy.empty : null;\n\n // ── open / close, told to the app once per change ──\n const onOpenChangeRef = useLatest(onOpenChange);\n const toldOpen = React.useRef(false);\n React.useEffect(() => {\n if (toldOpen.current === open) return;\n toldOpen.current = open;\n onOpenChangeRef.current?.(open);\n }, [open, onOpenChangeRef]);\n\n // ── search: told to the app when the query changes, debounced while typing ──\n const onSearchRef = useLatest(onSearch);\n const searchTimer = React.useRef<number | undefined>(undefined);\n const toldQuery = React.useRef('');\n React.useEffect(() => () => window.clearTimeout(searchTimer.current), []);\n const search = (q: string, immediate: boolean) => {\n window.clearTimeout(searchTimer.current);\n const run = () => {\n if (q === toldQuery.current) return;\n toldQuery.current = q;\n onSearchRef.current?.(q);\n };\n if (immediate) run();\n else searchTimer.current = window.setTimeout(run, debounce);\n };\n\n /** The box goes back to the chosen label: closes the list, drops what was typed, resets the query. */\n const settle = () => {\n setOpen(false);\n setDraft(null);\n search('', true);\n };\n\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef,\n itemCount: rows + (status ? 1 : 0),\n onDismiss: () => settle(),\n });\n // The chosen row can arrive after the list opened (a list that loads when it opens, on the page around\n // the chosen row). It is brought into view then, unless the user has already scrolled the list away\n // from the top: a user paging down for the next page is not carried off to a row that just landed.\n useRevealActive(open, activeId, place, revealInList, (el) => !activeFromOpen.current || (el.parentElement?.scrollTop ?? 0) === 0);\n\n // ── pagination: ask for more once the list is near its end ──\n const onReachEndRef = useLatest(onReachEnd);\n const askedFor = React.useRef<string | null>(null);\n // What the list is, for \"once per size\": a new search that happens to return as many rows is a new list.\n const shape = options.length + '|' + (options[0]?.value ?? '') + '|' + (options[options.length - 1]?.value ?? '');\n useIsoLayoutEffect(() => {\n if (!open) {\n askedFor.current = null;\n return;\n }\n const list = listRef.current;\n if (!list || rows === 0) return;\n const check = () => {\n if (loading || !onReachEndRef.current || askedFor.current === shape) return;\n const remaining = list.scrollHeight - list.scrollTop - list.clientHeight;\n if (remaining > (list.scrollHeight / rows) * REACH_ROWS) return;\n askedFor.current = shape;\n onReachEndRef.current();\n };\n check();\n list.addEventListener('scroll', check, { passive: true });\n return () => list.removeEventListener('scroll', check);\n }, [open, loading, shape, place, rows, onReachEndRef]);\n\n // A new search starts at the top.\n const firstValue = options[0]?.value;\n useIsoLayoutEffect(() => {\n if (draft !== null && listRef.current) listRef.current.scrollTop = 0;\n }, [draft, firstValue]);\n\n // iOS keeps the keyboard (and the field) up when you tap on plain page: close on any press outside.\n useOutsidePress(open, [boxRef, panelRef], () => settle());\n\n // ── choosing ──\n const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;\n const lastEnabledKey = () => {\n for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;\n return null;\n };\n const move = (dir: 1 | -1) => {\n let i = activeIndex < 0 ? (dir === 1 ? -1 : rows) : activeIndex;\n for (let step = 0; step < rows; step++) {\n i += dir;\n if (i < 0 || i >= rows) return; // the ends are walls, not a loop: a paged list has no \"wrap\"\n if (!visible[i].disabled) {\n pick(visible[i].value);\n return;\n }\n }\n };\n\n const choose = (o: AutocompleteOption) => {\n if (o.disabled) return;\n if (!isControlled) setInner(o);\n onValueChange?.(o);\n setOpen(false);\n setDraft(null);\n search('', true);\n // On a phone the keyboard goes with the choice.\n if (coarse) inputRef.current?.blur();\n };\n const clear = () => {\n if (value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n setDraft(''); // empty at once, even if the app takes a moment to take the value away\n search('', true);\n inputRef.current?.focus();\n };\n\n const selectedKey = value?.value;\n // Opening starts on the chosen row. If it is not in the list *yet* because the list is empty (it\n // loads when it opens), it stays the active one so it is revealed when it arrives. With rows on screen\n // that do not include it, it is not chased: the list is not moved under the user later.\n const startKey = (fallback: string | null) =>\n selectedKey !== undefined && (rows === 0 || visible.some((o) => o.value === selectedKey)) ? selectedKey : fallback;\n const openFromPointer = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(null));\n setOpen(true);\n };\n const openFromKey = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(firstEnabledKey()));\n setOpen(true);\n };\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const next = e.currentTarget.value;\n setDraft(next);\n // Filtering here, the first match is ready for Enter. A server search has not answered yet:\n // an Enter now would pick a row of the old answer, so nothing is active until the user moves.\n pick(filter === false ? null : narrow(options, filter, next).find((o) => !o.disabled)?.value ?? null);\n setOpen(true);\n if (next === '' && clearable && value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n search(next, false);\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled || e.nativeEvent.isComposing) return; // an IME is still composing the text\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) openFromKey();\n else move(1);\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) openFromKey();\n else move(-1);\n return;\n case 'Home':\n case 'End':\n if (open) {\n e.preventDefault();\n pick(e.key === 'Home' ? firstEnabledKey() : lastEnabledKey());\n }\n return;\n case 'Enter':\n // Closed: let the form have its Enter. Open: it is for the list, never a submit.\n if (open) {\n e.preventDefault();\n if (activeIndex >= 0) choose(visible[activeIndex]);\n }\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 settle();\n }\n return;\n default:\n }\n };\n\n // Select the text on the way in, so typing replaces the label instead of appending to it. The click\n // that gave the focus would put the caret back, hence the second select.\n const selectOnClick = React.useRef(false);\n\n const fieldAria = fieldA11y(rid, { hint, error, required });\n const rowPadY = menuRowPadY(coarse, size);\n const fontSize = size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)';\n const showClear = clearable && !disabled && text !== '';\n\n const list = (\n <div\n ref={panelRef}\n // Keeps the focus in the text box: pressing the list (or its scrollbar) must not blur it.\n onMouseDown={(e) => e.preventDefault()}\n style={sx({\n ...menuSurfaceStyle(size),\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n maxHeight: place?.maxH,\n ...(place?.strategy === 'fixed'\n ? {\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n zIndex: 1100,\n }\n : {\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place?.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n zIndex: 100,\n }),\n })}\n >\n <ul\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={ariaLabel ?? label}\n aria-busy={loading || undefined}\n tabIndex={-1}\n style={sx({\n ...menuListStyle,\n position: 'relative', // so an option's offsetTop is measured from the list\n flex: '1 1 auto',\n minHeight: 0,\n padding: rows ? 'var(--space-1)' : 0,\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {visible.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === selectedKey}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n // Pointer *move*, not enter: a list that scrolls under a still mouse (the keyboard\n // revealing a row) must not hand the highlight to whatever slid beneath it.\n onPointerMove={() => !o.disabled && pick(o.value)}\n onClick={() => choose(o)}\n />\n ))}\n </ul>\n {status && (\n // Loading is a lone spinner, no text and no rule above it: a screen reader gets the words from the\n // live region below, and this is for the eye. \"No results\" is the same row with words.\n <div\n aria-hidden=\"true\"\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: coarse ? 44 : undefined,\n padding: 'var(--space-3)',\n color: 'var(--text-muted)',\n fontSize: coarse ? 'var(--text-base)' : 'var(--text-sm)',\n })}\n >\n {loading ? (\n <span\n style={sx({\n flex: '0 0 auto',\n width: 18,\n height: 18,\n borderRadius: '999px',\n border: '2px solid var(--border-default)',\n borderTopColor: 'var(--text-brand)',\n animation: 'sereno-spin .7s linear infinite',\n })}\n />\n ) : (\n status\n )}\n </div>\n )}\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div style={sx({ position: 'relative', width: '100%' })}>\n <div\n ref={boxRef}\n // The padding around the text is part of the field: pressing it puts the caret in the box.\n onMouseDown={(e) => {\n if (e.target === inputRef.current || disabled) return;\n e.preventDefault();\n inputRef.current?.focus();\n }}\n style={sx({ ...fieldBoxStyle(size, !!error, focused || open, !!disabled), cursor: disabled ? 'not-allowed' : 'text' })}\n >\n <input\n ref={inputRef}\n id={rid}\n type=\"text\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeId ? activeId : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n // A text box that looks like a name or an address draws the browser's autofill and the\n // password managers. Best effort: Chrome ignores `autoComplete=\"off\"`, and Bitwarden only\n // honors its attribute when the user turned that option on.\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n enterKeyHint=\"done\"\n data-1p-ignore\n data-lpignore=\"true\"\n data-bwignore=\"true\"\n data-form-type=\"other\"\n disabled={disabled}\n placeholder={placeholder ?? copy.placeholder}\n value={text}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onFocus={(e) => {\n setFocused(true);\n selectOnClick.current = true;\n e.currentTarget.select();\n }}\n onBlur={(e) => {\n setFocused(false);\n if (boxRef.current?.contains(e.relatedTarget as Node | null)) return;\n settle();\n }}\n onClick={(e) => {\n const el = e.currentTarget;\n if (selectOnClick.current && el.selectionStart === el.selectionEnd) el.select();\n selectOnClick.current = false;\n if (!open) openFromPointer();\n }}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the box's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize,\n lineHeight: 1.2,\n textOverflow: 'ellipsis',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n })}\n />\n {showClear && (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n aria-label={copy.clear}\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n >\n <X size={16} strokeWidth={2} />\n </button>\n )}\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n disabled={disabled}\n aria-label={open ? copy.close : copy.open}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n inputRef.current?.focus({ preventScroll: true });\n if (open) settle();\n else openFromPointer();\n }}\n style={sx({\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 </button>\n </div>\n\n {open && place && place.strategy === 'inline' && list}\n {open && place && place.strategy === 'fixed' && createPortal(list, document.body)}\n\n {/* Always rendered, so the change of its text is what a screen reader announces. */}\n <div role=\"status\" aria-live=\"polite\" style={srOnlyStyle}>\n {open ? (loading ? copy.loading : rows === 0 ? copy.empty : copy.results(rows)) : ''}\n </div>\n </div>\n {name && <input ref={ref} type=\"hidden\" name={name} value={value?.value ?? ''} />}\n </Field>\n );\n});\n\nAutocomplete.displayName = 'Autocomplete';\n"],"mappings":";AAkbI,SA6CM,KA7CN;AAhbJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAAa,SAAS;AAC/B,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,cAAc,uBAAuB;AAC9C,SAAS,YAAY,eAAe,aAAa,wBAAwB;AACzE,SAAS,qBAAqB;AA0B9B,MAAM,OAAmD;AAAA,EACvD,SAAS;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO;AAAA,IACP,SAAS,CAAC,MAAO,MAAM,IAAI,gBAAgB,IAAI;AAAA,EACjD;AAAA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A,gBAED,8BAAC,eAAY,MAAM,IAAI,aAAa,MAAM;AAAA;AAAA,YAC5C;AAAA;AAAA;AAAA,MACF;AAAA,MAEC,QAAQ,SAAS,MAAM,aAAa,YAAY;AAAA,MAChD,QAAQ,SAAS,MAAM,aAAa,WAAW,aAAa,MAAM,SAAS,IAAI;AAAA,MAGhF,oBAAC,SAAI,MAAK,UAAS,aAAU,UAAS,OAAO,aAC1C,iBAAQ,UAAU,KAAK,UAAU,SAAS,IAAI,KAAK,QAAQ,KAAK,QAAQ,IAAI,IAAK,IACpF;AAAA,OACF;AAAA,IACC,QAAQ,oBAAC,WAAM,KAAU,MAAK,UAAS,MAAY,OAAO,OAAO,SAAS,IAAI;AAAA,KACjF;AAEJ,CAAC;AAED,aAAa,cAAc;","names":["Autocomplete","list"]}
@@ -8,6 +8,7 @@ import { Field } from "../_internal/Field.js";
8
8
  import { fieldA11y } from "../_internal/fieldA11y.js";
9
9
  import { useIsoLayoutEffect } from "../_internal/useIsoLayoutEffect.js";
10
10
  import { useMenuPlacement } from "../_internal/useMenuPlacement.js";
11
+ import { useOutsidePress } from "../_internal/useOutsidePress.js";
11
12
  import { CalendarGrid } from "./_internal/CalendarGrid.js";
12
13
  import { parseISODate as parseISO, toISODate as toISO } from "./_internal/calendarRange.js";
13
14
  import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
@@ -87,14 +88,9 @@ const DatePicker = React.forwardRef(function DatePicker2({
87
88
  const above = field.top - GAP - height;
88
89
  setFitTop(below + height <= viewport - EDGE ? below : above >= EDGE ? above : Math.max(EDGE, viewport - EDGE - height));
89
90
  }, [portalled, place, viewYear, viewMonth]);
91
+ useOutsidePress(open, [rootRef, popoverRef], () => setOpen(false));
90
92
  React.useEffect(() => {
91
93
  if (!open) return;
92
- const onDown = (e) => {
93
- const target = e.target;
94
- if (rootRef.current && !rootRef.current.contains(target) && !popoverRef.current?.contains(target)) {
95
- setOpen(false);
96
- }
97
- };
98
94
  const onKey = (e) => {
99
95
  if (e.key === "Escape") {
100
96
  e.preventDefault();
@@ -102,12 +98,8 @@ const DatePicker = React.forwardRef(function DatePicker2({
102
98
  triggerRef.current?.focus();
103
99
  }
104
100
  };
105
- document.addEventListener("pointerdown", onDown, true);
106
101
  document.addEventListener("keydown", onKey, true);
107
- return () => {
108
- document.removeEventListener("pointerdown", onDown, true);
109
- document.removeEventListener("keydown", onKey, true);
110
- };
102
+ return () => document.removeEventListener("keydown", onKey, true);
111
103
  }, [open]);
112
104
  const openPopover = () => {
113
105
  if (disabled) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/DatePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Calendar as CalendarIcon, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nconst TEXT = {\n 'pt-BR': { placeholder: 'Selecionar data', dialogLabel: 'Escolher data', clearLabel: 'Limpar data' },\n en: { placeholder: 'Pick a date', dialogLabel: 'Choose a date', clearLabel: 'Clear date' },\n} as const;\n\n/**\n * The widest a calendar gets once it leaves the field's own width, i.e. when portalled out of a Dialog. Its\n * cells are square, so it is as tall as it is wide: at the width of a wide dialog field it would be a\n * 450px-tall slab that covers the field and half the window. Inline it is untouched (still the field's width).\n */\nconst PORTALLED_MAX_WIDTH = 320;\n\n/** What a keyboard can reach inside `root`, in tab order (the calendar's roving day has `tabindex=\"0\"`, the others `-1`). */\nfunction tabbables(root: HTMLElement | null): HTMLElement[] {\n if (!root) return [];\n return Array.from(root.querySelectorAll<HTMLElement>('button:not(:disabled), [tabindex]')).filter((el) => el.tabIndex >= 0);\n}\n\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n /** Defaults to the `locale`-appropriate text (\"Selecionar data\" / \"Pick a date\"). */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value, ISO \"YYYY-MM-DD\". */\n value?: string;\n /** Uncontrolled initial value, ISO \"YYYY-MM-DD\". */\n defaultValue?: string;\n onChange?: (value: string) => void;\n /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** Latest selectable date, ISO \"YYYY-MM-DD\". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */\n max?: string;\n /**\n * Fires when the month on screen changes (the arrows, or the month / year popover), with the\n * new year and the 0-indexed month. Not when the popover opens: it opens on the month of the\n * value, or on the current one. Refresh `dayDots` / `renderDay` here.\n */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second\n * argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells\n * grow taller to hold it.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers\n * (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of\n * the month on screen, so refresh them in `onMonthChange`.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */\n clearLabel?: string;\n /**\n * The real Sereno product always renders pt-BR - this only exists so the\n * docs showcase can demo an English-speaking consumer without forking the\n * component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\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\nfunction formatDisplay(iso: string, locale: 'pt-BR' | 'en'): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat(locale === 'en' ? 'en-US' : 'pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(\n new Date(d.year, d.month, d.day),\n );\n}\n\n/**\n * Field for picking a single date - no time, no slots (`DateTimePicker`'s\n * job). A text-field-styled trigger showing the selected date opens a\n * popover with the same calendar grid `DateTimePicker` uses (roving\n * tabindex, month/year jump - see `./_internal/CalendarGrid`), so the two\n * share every bit of calendar behavior (SS-243).\n *\n * Value contract matches the rest of the forms package: `value` /\n * `defaultValue` + `onChange(value)`, a plain ISO \"YYYY-MM-DD\" string -\n * drops in wherever `<input type=\"date\">` would go, but themed instead of\n * the browser's own, and in pt-BR by default (the real Sereno product\n * always uses it; `locale=\"en\"` exists only for docs/demo purposes). A\n * clear (×) button appears once a value is set.\n */\nexport const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\n label,\n hint,\n error,\n required,\n placeholder,\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n preserveHelperSpace,\n },\n ref,\n) {\n const copy = TEXT[locale];\n const [inner, setInner] = React.useState(defaultValue ?? '');\n const iso = value !== undefined ? value : inner;\n const parsed = parseISO(iso);\n const now = React.useMemo(() => new Date(), []);\n\n const [open, setOpen] = React.useState(false);\n // The month currently shown in the popover - resets to the value's month\n // (or today's) every time the popover opens, via the conditional mount\n // below; CalendarGrid itself only takes year/month as its *initial* view.\n const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());\n const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const popoverRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const generatedId = React.useId();\n const rid = id || generatedId;\n\n React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\n\n // Where the calendar sits. Normally a plain `position: absolute` child of\n // `rootRef` (itself `position: relative`) - the same \"inline\" strategy\n // Select's panel uses for its common case, and the same one DateTimePicker's\n // own month/year popover already uses. The browser glues it to the trigger\n // through *any* scroll (page or a nested overflow container) for free - no JS\n // measuring position, no listening for scroll/resize, and critically, it\n // never has to close on scroll the way a `position: fixed` popover computed\n // once would (that was tried first here and didn't hold up - see PR history).\n //\n // The one place that fails is inside a `position: fixed` container (a\n // Dialog): its body scrolls and clips an inline child, cutting the calendar\n // off. There `useMenuPlacement` answers 'fixed' (what Select and\n // Autocomplete already do) and the calendar is portalled to <body> at the\n // field's viewport rect, closing if the field moves. Outside a dialog nothing\n // changes: still inline, still below the field, never flipped (the hook's\n // `above` / `maxH` are not used at all: see `fitTop` for the portalled case).\n // `itemCount` is just the hook's height estimate; a calendar is not a list.\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef: popoverRef,\n itemCount: 8,\n onDismiss: () => setOpen(false),\n });\n const portalled = open && place?.strategy === 'fixed';\n\n // The hook picks \"below\" or \"above\" from a rough guess at the height, which suits a list capped at 288px but not\n // a calendar (about as tall as it is wide). So once the portalled calendar is on screen it is measured and kept\n // inside the window: under the field if it fits, else above it, else as far up as it needs (over the field rather\n // than cut off). The month changes the row count, hence the dependencies. Runs before paint: no visible jump.\n const [fitTop, setFitTop] = React.useState<number | null>(null);\n useIsoLayoutEffect(() => {\n const popover = popoverRef.current;\n const box = boxRef.current;\n if (!portalled || !popover || !box) return;\n const GAP = 6;\n const EDGE = 8;\n const field = box.getBoundingClientRect();\n const height = popover.offsetHeight;\n const viewport = window.innerHeight || document.documentElement.clientHeight || 900;\n const below = field.bottom + GAP;\n const above = field.top - GAP - height;\n setFitTop(below + height <= viewport - EDGE ? below : above >= EDGE ? above : Math.max(EDGE, viewport - EDGE - height));\n }, [portalled, place, viewYear, viewMonth]);\n\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n // The portalled calendar is outside `rootRef` in the DOM but still part of the field.\n const target = e.target as Node;\n if (rootRef.current && !rootRef.current.contains(target) && !popoverRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault(); // handled: a Dialog around the field keeps its own Esc for the next press\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener('pointerdown', onDown, true);\n document.addEventListener('keydown', onKey, true);\n return () => {\n document.removeEventListener('pointerdown', onDown, true);\n document.removeEventListener('keydown', onKey, true);\n };\n }, [open]);\n\n const openPopover = () => {\n if (disabled) return;\n setViewYear(parsed?.year ?? now.getFullYear());\n setViewMonth(parsed?.month ?? now.getMonth());\n setOpen(true);\n };\n\n const commit = (day: number) => {\n const next = toISO(viewYear, viewMonth, day);\n if (value === undefined) setInner(next);\n onChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n };\n\n const clear = () => {\n if (value === undefined) setInner('');\n onChange?.('');\n triggerRef.current?.focus();\n };\n\n // Inline, the calendar follows the field in the DOM, so Tab walks field -> calendar -> next field on its\n // own. Portalled to the end of <body> it does not, so the focus is handed over by hand to keep that order.\n const onBoxKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab' || e.shiftKey || !portalled) return;\n const controls = tabbables(e.currentTarget);\n if (e.target !== controls[controls.length - 1]) return; // not the control the calendar follows\n const first = tabbables(popoverRef.current)[0];\n if (!first) return;\n e.preventDefault();\n first.focus();\n };\n\n const onPopoverKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab') return;\n const controls = tabbables(boxRef.current);\n const field = controls[controls.length - 1]; // the control the calendar follows in the DOM\n const inside = tabbables(e.currentTarget);\n if (e.shiftKey && e.target === inside[0]) {\n e.preventDefault();\n field?.focus();\n } else if (!e.shiftKey && e.target === inside[inside.length - 1]) {\n // Not prevented on purpose: with the focus back on the field the Tab goes on to whatever follows it.\n setOpen(false);\n field?.focus();\n }\n };\n\n // One popover, two positions (see `useMenuPlacement` above): the calendar and its look are the same.\n const renderPopover = (position: React.CSSProperties) => (\n <div\n ref={popoverRef}\n role=\"dialog\"\n aria-label={label || copy.dialogLabel}\n tabIndex={-1}\n onKeyDown={portalled ? onPopoverKeyDown : undefined}\n style={sx({\n ...position,\n // The 7-column grid needs some floor width to stay readable -\n // a narrow field (e.g. a compact \"Data\" next to \"Motivo\")\n // would otherwise squeeze it. `left`/`right: 0` already\n // matches the trigger's own width for anything wider.\n minWidth: 272,\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <CalendarGrid\n year={viewYear}\n month={viewMonth}\n selectedDate={parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : undefined}\n min={min}\n max={max}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n onMonthChange?.(y, m);\n }}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div ref={rootRef} style={{ position: 'relative', width: '100%' }}>\n {/* The bordered box lives on this wrapper `div`, not on a `<button>`\n - the open-trigger and the clear (×) button are real, independent\n sibling buttons inside it, since a button can't nest another. */}\n <div ref={boxRef} onKeyDown={onBoxKeyDown} style={fieldBoxStyle(size, !!error, open, disabled)}>\n <button\n ref={triggerRef}\n id={rid}\n type=\"button\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\n onClick={() => (open ? setOpen(false) : openPopover())}\n style={sx({\n flex: 1,\n minWidth: 0,\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n border: 'none',\n background: 'transparent',\n padding: 0,\n font: 'inherit',\n color: 'inherit',\n cursor: 'inherit',\n textAlign: 'left',\n })}\n >\n <CalendarIcon size={16} strokeWidth={1.75} style={{ flex: '0 0 auto', opacity: 0.7 }} />\n <span\n style={sx({\n flex: 1,\n textAlign: 'left',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: iso ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {iso ? formatDisplay(iso, locale) : (placeholder ?? copy.placeholder)}\n </span>\n </button>\n {iso && !disabled && (\n <button\n type=\"button\"\n aria-label={clearLabel ?? copy.clearLabel}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n marginRight: -4,\n padding: 4,\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'var(--text-muted)',\n cursor: 'pointer',\n })}\n >\n <X size={14} strokeWidth={2} />\n </button>\n )}\n </div>\n\n {open && place?.strategy === 'inline' &&\n renderPopover({ position: 'absolute', top: 'calc(100% + 6px)', left: 0, right: 0, zIndex: 20 })}\n {open && place?.strategy === 'fixed' &&\n createPortal(\n renderPopover({\n position: 'fixed',\n top: fitTop ?? place.top, // `fitTop` is measured (see above); the hook's guess only holds the first, unpainted render\n left: place.left,\n width: Math.min(place.width, PORTALLED_MAX_WIDTH),\n boxSizing: 'border-box',\n zIndex: 1100, // above the Dialog (1000), level with Select / Autocomplete's portalled lists\n }),\n document.body,\n )}\n </div>\n </Field>\n );\n});\n\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AA0TM,cA6BI,YA7BJ;AAxTN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB,UAAU,aAAa,aAAa;AAC7D,SAAS,qBAAqB;AAE9B,MAAM,OAAO;AAAA,EACX,SAAS,EAAE,aAAa,mBAAmB,aAAa,iBAAiB,YAAY,cAAc;AAAA,EACnG,IAAI,EAAE,aAAa,eAAe,aAAa,iBAAiB,YAAY,aAAa;AAC3F;AAOA,MAAM,sBAAsB;AAG5B,SAAS,UAAU,MAAyC;AAC1D,MAAI,CAAC,KAAM,QAAO,CAAC;AACnB,SAAO,MAAM,KAAK,KAAK,iBAA8B,mCAAmC,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC;AAC5H;AAyEA,SAAS,cAAc,KAAa,QAAgC;AAClE,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,WAAW,OAAO,UAAU,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE;AAAA,IACzH,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;A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,KAAK,UAAU,MAAM;AAAA;AAAA,QACrB,MAAM,MAAM;AAAA,QACZ,OAAO,KAAK,IAAI,MAAM,OAAO,mBAAmB;AAAA,QAChD,WAAW;AAAA,QACX,QAAQ;AAAA;AAAA,MACV,CAAC;AAAA,MACD,SAAS;AAAA,IACX;AAAA,KACJ,GACF;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
1
+ {"version":3,"sources":["../../src/forms/DatePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Calendar as CalendarIcon, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { CalendarGrid } from './_internal/CalendarGrid';\nimport type { CalendarDayContext, CalendarDayDots } from './_internal/calendarDots';\nimport { parseISODate as parseISO, toISODate as toISO } from './_internal/calendarRange';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nconst TEXT = {\n 'pt-BR': { placeholder: 'Selecionar data', dialogLabel: 'Escolher data', clearLabel: 'Limpar data' },\n en: { placeholder: 'Pick a date', dialogLabel: 'Choose a date', clearLabel: 'Clear date' },\n} as const;\n\n/**\n * The widest a calendar gets once it leaves the field's own width, i.e. when portalled out of a Dialog. Its\n * cells are square, so it is as tall as it is wide: at the width of a wide dialog field it would be a\n * 450px-tall slab that covers the field and half the window. Inline it is untouched (still the field's width).\n */\nconst PORTALLED_MAX_WIDTH = 320;\n\n/** What a keyboard can reach inside `root`, in tab order (the calendar's roving day has `tabindex=\"0\"`, the others `-1`). */\nfunction tabbables(root: HTMLElement | null): HTMLElement[] {\n if (!root) return [];\n return Array.from(root.querySelectorAll<HTMLElement>('button:not(:disabled), [tabindex]')).filter((el) => el.tabIndex >= 0);\n}\n\n/**\n * Imperative handle exposed via `ref` - there's no single native element\n * underneath (the trigger is a `<button>`, the value a plain ISO string in\n * React state), so `ref` can't hand back something `.value`-readable the way\n * a real `<input>` would. `focus()` is real and covers `setFocus()`-on-error;\n * reading the current value still means the `value`/`onChange` props, not the\n * ref. `onChange(value: string)` also isn't a `ChangeEvent`, so a plain\n * `{...register(name)}` spread won't work regardless - use `Controller`.\n */\nexport interface DatePickerHandle {\n focus: () => void;\n}\n\nexport interface DatePickerProps {\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n /** Defaults to the `locale`-appropriate text (\"Selecionar data\" / \"Pick a date\"). */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Controlled value, ISO \"YYYY-MM-DD\". */\n value?: string;\n /** Uncontrolled initial value, ISO \"YYYY-MM-DD\". */\n defaultValue?: string;\n onChange?: (value: string) => void;\n /**\n * Earliest selectable date, ISO \"YYYY-MM-DD\". Every day before it is struck through, and the\n * calendar cannot be navigated to an earlier month or year (the previous-month arrow disables,\n * PageUp and the arrow keys stop at the edge, the month / year popover disables what is out of\n * range). An initial value or month before it opens on `min`'s month.\n */\n min?: string;\n /** Latest selectable date, ISO \"YYYY-MM-DD\". The mirror image of `min`: later days are struck through and later months and years cannot be reached. */\n max?: string;\n /**\n * Fires when the month on screen changes (the arrows, or the month / year popover), with the\n * new year and the 0-indexed month. Not when the popover opens: it opens on the month of the\n * value, or on the current one. Refresh `dayDots` / `renderDay` here.\n */\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number (a count, a note), the same as `DateTimePicker`'s. The second\n * argument says whether the day is `selected`, `today` or `unavailable`. When set, the day cells\n * grow taller to hold it.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /**\n * The days that get a dot under their number, the same as `DateTimePicker`'s: day numbers\n * (`[3, 17]`), or an object keyed by day number for a per-dot `tone` or `label`. Day numbers of\n * the month on screen, so refresh them in `onMonthChange`.\n */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot with no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** aria-label for the clear (×) button. Defaults to the `locale`-appropriate text. */\n clearLabel?: string;\n /**\n * The real Sereno product always renders pt-BR - this only exists so the\n * docs showcase can demo an English-speaking consumer without forking the\n * component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\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\nfunction formatDisplay(iso: string, locale: 'pt-BR' | 'en'): string {\n const d = parseISO(iso);\n if (!d) return iso;\n return new Intl.DateTimeFormat(locale === 'en' ? 'en-US' : 'pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' }).format(\n new Date(d.year, d.month, d.day),\n );\n}\n\n/**\n * Field for picking a single date - no time, no slots (`DateTimePicker`'s\n * job). A text-field-styled trigger showing the selected date opens a\n * popover with the same calendar grid `DateTimePicker` uses (roving\n * tabindex, month/year jump - see `./_internal/CalendarGrid`), so the two\n * share every bit of calendar behavior (SS-243).\n *\n * Value contract matches the rest of the forms package: `value` /\n * `defaultValue` + `onChange(value)`, a plain ISO \"YYYY-MM-DD\" string -\n * drops in wherever `<input type=\"date\">` would go, but themed instead of\n * the browser's own, and in pt-BR by default (the real Sereno product\n * always uses it; `locale=\"en\"` exists only for docs/demo purposes). A\n * clear (×) button appears once a value is set.\n */\nexport const DatePicker = React.forwardRef<DatePickerHandle, DatePickerProps>(function DatePicker(\n {\n label,\n hint,\n error,\n required,\n placeholder,\n size = 'md',\n disabled = false,\n value,\n defaultValue,\n onChange,\n min,\n max,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n id,\n containerStyle,\n clearLabel,\n locale = 'pt-BR',\n preserveHelperSpace,\n },\n ref,\n) {\n const copy = TEXT[locale];\n const [inner, setInner] = React.useState(defaultValue ?? '');\n const iso = value !== undefined ? value : inner;\n const parsed = parseISO(iso);\n const now = React.useMemo(() => new Date(), []);\n\n const [open, setOpen] = React.useState(false);\n // The month currently shown in the popover - resets to the value's month\n // (or today's) every time the popover opens, via the conditional mount\n // below; CalendarGrid itself only takes year/month as its *initial* view.\n const [viewYear, setViewYear] = React.useState(parsed?.year ?? now.getFullYear());\n const [viewMonth, setViewMonth] = React.useState(parsed?.month ?? now.getMonth());\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const popoverRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const generatedId = React.useId();\n const rid = id || generatedId;\n\n React.useImperativeHandle(ref, () => ({ focus: () => triggerRef.current?.focus() }), []);\n\n // Where the calendar sits. Normally a plain `position: absolute` child of\n // `rootRef` (itself `position: relative`) - the same \"inline\" strategy\n // Select's panel uses for its common case, and the same one DateTimePicker's\n // own month/year popover already uses. The browser glues it to the trigger\n // through *any* scroll (page or a nested overflow container) for free - no JS\n // measuring position, no listening for scroll/resize, and critically, it\n // never has to close on scroll the way a `position: fixed` popover computed\n // once would (that was tried first here and didn't hold up - see PR history).\n //\n // The one place that fails is inside a `position: fixed` container (a\n // Dialog): its body scrolls and clips an inline child, cutting the calendar\n // off. There `useMenuPlacement` answers 'fixed' (what Select and\n // Autocomplete already do) and the calendar is portalled to <body> at the\n // field's viewport rect, closing if the field moves. Outside a dialog nothing\n // changes: still inline, still below the field, never flipped (the hook's\n // `above` / `maxH` are not used at all: see `fitTop` for the portalled case).\n // `itemCount` is just the hook's height estimate; a calendar is not a list.\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef: popoverRef,\n itemCount: 8,\n onDismiss: () => setOpen(false),\n });\n const portalled = open && place?.strategy === 'fixed';\n\n // The hook picks \"below\" or \"above\" from a rough guess at the height, which suits a list capped at 288px but not\n // a calendar (about as tall as it is wide). So once the portalled calendar is on screen it is measured and kept\n // inside the window: under the field if it fits, else above it, else as far up as it needs (over the field rather\n // than cut off). The month changes the row count, hence the dependencies. Runs before paint: no visible jump.\n const [fitTop, setFitTop] = React.useState<number | null>(null);\n useIsoLayoutEffect(() => {\n const popover = popoverRef.current;\n const box = boxRef.current;\n if (!portalled || !popover || !box) return;\n const GAP = 6;\n const EDGE = 8;\n const field = box.getBoundingClientRect();\n const height = popover.offsetHeight;\n const viewport = window.innerHeight || document.documentElement.clientHeight || 900;\n const below = field.bottom + GAP;\n const above = field.top - GAP - height;\n setFitTop(below + height <= viewport - EDGE ? below : above >= EDGE ? above : Math.max(EDGE, viewport - EDGE - height));\n }, [portalled, place, viewYear, viewMonth]);\n\n // A press outside the field closes the calendar. The portalled calendar is outside `rootRef` in the DOM but\n // still part of the field, so both count as inside.\n useOutsidePress(open, [rootRef, popoverRef], () => setOpen(false));\n React.useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault(); // handled: a Dialog around the field keeps its own Esc for the next press\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener('keydown', onKey, true);\n return () => document.removeEventListener('keydown', onKey, true);\n }, [open]);\n\n const openPopover = () => {\n if (disabled) return;\n setViewYear(parsed?.year ?? now.getFullYear());\n setViewMonth(parsed?.month ?? now.getMonth());\n setOpen(true);\n };\n\n const commit = (day: number) => {\n const next = toISO(viewYear, viewMonth, day);\n if (value === undefined) setInner(next);\n onChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n };\n\n const clear = () => {\n if (value === undefined) setInner('');\n onChange?.('');\n triggerRef.current?.focus();\n };\n\n // Inline, the calendar follows the field in the DOM, so Tab walks field -> calendar -> next field on its\n // own. Portalled to the end of <body> it does not, so the focus is handed over by hand to keep that order.\n const onBoxKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab' || e.shiftKey || !portalled) return;\n const controls = tabbables(e.currentTarget);\n if (e.target !== controls[controls.length - 1]) return; // not the control the calendar follows\n const first = tabbables(popoverRef.current)[0];\n if (!first) return;\n e.preventDefault();\n first.focus();\n };\n\n const onPopoverKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n if (e.key !== 'Tab') return;\n const controls = tabbables(boxRef.current);\n const field = controls[controls.length - 1]; // the control the calendar follows in the DOM\n const inside = tabbables(e.currentTarget);\n if (e.shiftKey && e.target === inside[0]) {\n e.preventDefault();\n field?.focus();\n } else if (!e.shiftKey && e.target === inside[inside.length - 1]) {\n // Not prevented on purpose: with the focus back on the field the Tab goes on to whatever follows it.\n setOpen(false);\n field?.focus();\n }\n };\n\n // One popover, two positions (see `useMenuPlacement` above): the calendar and its look are the same.\n const renderPopover = (position: React.CSSProperties) => (\n <div\n ref={popoverRef}\n role=\"dialog\"\n aria-label={label || copy.dialogLabel}\n tabIndex={-1}\n onKeyDown={portalled ? onPopoverKeyDown : undefined}\n style={sx({\n ...position,\n // The 7-column grid needs some floor width to stay readable -\n // a narrow field (e.g. a compact \"Data\" next to \"Motivo\")\n // would otherwise squeeze it. `left`/`right: 0` already\n // matches the trigger's own width for anything wider.\n minWidth: 272,\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <CalendarGrid\n year={viewYear}\n month={viewMonth}\n selectedDate={parsed && parsed.year === viewYear && parsed.month === viewMonth ? parsed.day : undefined}\n min={min}\n max={max}\n onMonthChange={(y, m) => {\n setViewYear(y);\n setViewMonth(m);\n onMonthChange?.(y, m);\n }}\n renderDay={renderDay}\n dayDots={dayDots}\n dayDotLabel={dayDotLabel}\n onSelectDate={commit}\n squareCells\n trimEmptyRows\n locale={locale}\n />\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div ref={rootRef} style={{ position: 'relative', width: '100%' }}>\n {/* The bordered box lives on this wrapper `div`, not on a `<button>`\n - the open-trigger and the clear (×) button are real, independent\n sibling buttons inside it, since a button can't nest another. */}\n <div ref={boxRef} onKeyDown={onBoxKeyDown} style={fieldBoxStyle(size, !!error, open, disabled)}>\n <button\n ref={triggerRef}\n id={rid}\n type=\"button\"\n disabled={disabled}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n // Ties the trigger to the hint / error line below, so they are read when it takes focus.\n {...fieldA11y(rid, { hint, error })}\n onClick={() => (open ? setOpen(false) : openPopover())}\n style={sx({\n flex: 1,\n minWidth: 0,\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n border: 'none',\n background: 'transparent',\n padding: 0,\n font: 'inherit',\n color: 'inherit',\n cursor: 'inherit',\n textAlign: 'left',\n })}\n >\n <CalendarIcon size={16} strokeWidth={1.75} style={{ flex: '0 0 auto', opacity: 0.7 }} />\n <span\n style={sx({\n flex: 1,\n textAlign: 'left',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n color: iso ? 'inherit' : 'var(--text-muted)',\n })}\n >\n {iso ? formatDisplay(iso, locale) : (placeholder ?? copy.placeholder)}\n </span>\n </button>\n {iso && !disabled && (\n <button\n type=\"button\"\n aria-label={clearLabel ?? copy.clearLabel}\n onClick={(e) => {\n e.stopPropagation();\n clear();\n }}\n style={sx({\n flex: '0 0 auto',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n marginRight: -4,\n padding: 4,\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n color: 'var(--text-muted)',\n cursor: 'pointer',\n })}\n >\n <X size={14} strokeWidth={2} />\n </button>\n )}\n </div>\n\n {open && place?.strategy === 'inline' &&\n renderPopover({ position: 'absolute', top: 'calc(100% + 6px)', left: 0, right: 0, zIndex: 20 })}\n {open && place?.strategy === 'fixed' &&\n createPortal(\n renderPopover({\n position: 'fixed',\n top: fitTop ?? place.top, // `fitTop` is measured (see above); the hook's guess only holds the first, unpainted render\n left: place.left,\n width: Math.min(place.width, PORTALLED_MAX_WIDTH),\n boxSizing: 'border-box',\n zIndex: 1100, // above the Dialog (1000), level with Select / Autocomplete's portalled lists\n }),\n document.body,\n )}\n </div>\n </Field>\n );\n});\n\nDatePicker.displayName = 'DatePicker';\n"],"mappings":";AAmTM,cA6BI,YA7BJ;AAjTN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,YAAY,cAAc,SAAS;AAC5C,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB,UAAU,aAAa,aAAa;AAC7D,SAAS,qBAAqB;AAE9B,MAAM,OAAO;AAAA,EACX,SAAS,EAAE,aAAa,mBAAmB,aAAa,iBAAiB,YAAY,cAAc;AAAA,EACnG,IAAI,EAAE,aAAa,eAAe,aAAa,iBAAiB,YAAY,aAAa;AAC3F;AAOA,MAAM,sBAAsB;AAG5B,SAAS,UAAU,MAAyC;AAC1D,MAAI,CAAC,KAAM,QAAO,CAAC;AACnB,SAAO,MAAM,KAAK,KAAK,iBAA8B,mCAAmC,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC;AAC5H;AAyEA,SAAS,cAAc,KAAa,QAAgC;AAClE,QAAM,IAAI,SAAS,GAAG;AACtB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO,IAAI,KAAK,eAAe,WAAW,OAAO,UAAU,SAAS,EAAE,KAAK,WAAW,OAAO,WAAW,MAAM,UAAU,CAAC,EAAE;AAAA,IACzH,IAAI,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;AAAA,EACjC;AACF;AAgBO,MAAM,aAAa,MAAM,WAA8C,SAASA,YACrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EAC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AAAA,kBACV,cAAc;AAAA,kBACd,YAAY;AAAA,kBACZ,OAAO,MAAM,YAAY;AAAA,gBAC3B,CAAC;AAAA,gBAEA,gBAAM,cAAc,KAAK,MAAM,IAAK,eAAe,KAAK;AAAA;AAAA,YAC3D;AAAA;AAAA;AAAA,MACF;AAAA,MACC,OAAO,CAAC,YACP;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,cAAY,cAAc,KAAK;AAAA,UAC/B,SAAS,CAAC,MAAM;AACd,cAAE,gBAAgB;AAClB,kBAAM;AAAA,UACR;AAAA,UACA,OAAO,GAAG;AAAA,YACR,MAAM;AAAA,YACN,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa;AAAA,YACb,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,cAAc;AAAA,YACd,YAAY;AAAA,YACZ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV,CAAC;AAAA,UAED,8BAAC,KAAE,MAAM,IAAI,aAAa,GAAG;AAAA;AAAA,MAC/B;AAAA,OAEJ;AAAA,IAEC,QAAQ,OAAO,aAAa,YAC3B,cAAc,EAAE,UAAU,YAAY,KAAK,oBAAoB,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,CAAC;AAAA,IAC/F,QAAQ,OAAO,aAAa,WAC3B;AAAA,MACE,cAAc;AAAA,QACZ,UAAU;AAAA,QACV,KAAK,UAAU,MAAM;AAAA;AAAA,QACrB,MAAM,MAAM;AAAA,QACZ,OAAO,KAAK,IAAI,MAAM,OAAO,mBAAmB;AAAA,QAChD,WAAW;AAAA,QACX,QAAQ;AAAA;AAAA,MACV,CAAC;AAAA,MACD,SAAS;AAAA,IACX;AAAA,KACJ,GACF;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["DatePicker"]}
@@ -7,6 +7,7 @@ import { sx } from "../_internal/style.js";
7
7
  import { acquireScrollLock } from "../_internal/scrollLock.js";
8
8
  import { useCoarsePointer } from "../_internal/useCoarsePointer.js";
9
9
  import { useMenuPlacement } from "../_internal/useMenuPlacement.js";
10
+ import { useOutsidePress } from "../_internal/useOutsidePress.js";
10
11
  import { useRevealActive } from "../_internal/useRevealActive.js";
11
12
  import { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from "../_internal/MenuOption.js";
12
13
  import { Field } from "../_internal/Field.js";
@@ -59,16 +60,7 @@ function CustomSelect({
59
60
  }
60
61
  return from;
61
62
  };
62
- React.useEffect(() => {
63
- if (!open || coarse) return;
64
- const onDown = (e) => {
65
- const target = e.target;
66
- if (triggerRef.current?.contains(target) || panelRef.current?.contains(target)) return;
67
- setOpen(false);
68
- };
69
- document.addEventListener("pointerdown", onDown, true);
70
- return () => document.removeEventListener("pointerdown", onDown, true);
71
- }, [open, coarse]);
63
+ useOutsidePress(open && !coarse, [triggerRef, panelRef], () => setOpen(false));
72
64
  React.useEffect(() => {
73
65
  if (!open || !coarse) return;
74
66
  return acquireScrollLock();
@@ -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 { 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 React.useEffect(() => {\n if (!open || coarse) return;\n const onDown = (e: PointerEvent) => {\n const target = e.target as Node;\n if (triggerRef.current?.contains(target) || panelRef.current?.contains(target)) return;\n setOpen(false);\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [open, coarse]);\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":";AAiPI,cAgBE,YAhBF;A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A;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';\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,E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AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd;AACF,GAAgB,KAAK;AACnB,QAAM,UAAU,MAAM,MAAM;AAC5B,QAAM,MAAM,MAAM;AAClB,QAAM,eAAe,cAAc;AACnC,QAAM,CAAC,eAAe,gBAAgB,IAAI,MAAM,SAAS,gBAAgB,EAAE;AAC3E,QAAM,QAAQ,eAAe,YAAa;AAC1C,QAAM,SAAS,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"]}
@@ -4,6 +4,7 @@ import * as React from "react";
4
4
  import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
5
5
  import { sx } from "../../_internal/style.js";
6
6
  import { srOnlyStyle } from "../../_internal/srOnly.js";
7
+ import { useOutsidePress } from "../../_internal/useOutsidePress.js";
7
8
  import { IconButton } from "../../core/IconButton.js";
8
9
  import { calendarRange, clampIndex, isDayOutside, yearWindowStart } from "./calendarRange.js";
9
10
  import { dotFor, dotStyle, TODAY_RING } from "./calendarDots.js";
@@ -95,20 +96,14 @@ function CalendarGrid({
95
96
  }
96
97
  onMonthChangeRef.current?.(Math.floor(viewIndex / 12), viewIndex % 12);
97
98
  }, [viewIndex]);
99
+ useOutsidePress(open, [rootRef], () => {
100
+ setOpen(false);
101
+ setPicker("month");
102
+ });
98
103
  React.useEffect(() => {
99
104
  if (!open) return;
100
- const onDown = (e) => {
101
- if (rootRef.current && !rootRef.current.contains(e.target)) {
102
- setOpen(false);
103
- setPicker("month");
104
- }
105
- };
106
- document.addEventListener("pointerdown", onDown, true);
107
105
  const id = requestAnimationFrame(() => popRef.current?.focus());
108
- return () => {
109
- document.removeEventListener("pointerdown", onDown, true);
110
- cancelAnimationFrame(id);
111
- };
106
+ return () => cancelAnimationFrame(id);
112
107
  }, [open]);
113
108
  const closePopover = React.useCallback(() => {
114
109
  setOpen(false);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/forms/_internal/CalendarGrid.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';\nimport { sx } from '../../_internal/style';\nimport { srOnlyStyle } from '../../_internal/srOnly';\nimport { IconButton } from '../../core/IconButton';\nimport { calendarRange, clampIndex, isDayOutside, yearWindowStart } from './calendarRange';\nimport { dotFor, dotStyle, TODAY_RING, type CalendarDayContext, type CalendarDayDots } from './calendarDots';\n\n/**\n * The month calendar body - header (‹ / › month nav + a month/year jump\n * popover) and the day grid with roving-tabindex keyboard navigation\n * (SS-228). Shared by `DateTimePicker` (rendered inline, with an optional\n * time-slot list under it) and `DatePicker` (rendered inside its own\n * trigger+popover shell) - extracted so neither has to duplicate the\n * keyboard-grid math (SS-243). See `DateTimePicker`'s own doc comment for\n * the full behavior description; this component owns exactly the same\n * state and logic it always has, just without the outer card chrome or\n * the time-slot section, neither of which any of this depends on.\n */\nexport interface CalendarGridProps {\n year?: number;\n month?: number;\n selectedDate?: number;\n unavailable?: number[];\n /**\n * Earliest date, ISO \"YYYY-MM-DD\". The calendar cannot be navigated to an earlier month or\n * year (the previous-month arrow disables, PageUp and the arrow keys stop at the edge, and\n * the month / year popover disables what is out of range), and every earlier day is struck\n * through, with no need to list it in `unavailable`. A value that is not a valid date is ignored.\n */\n min?: string;\n /** Latest date, ISO \"YYYY-MM-DD\". The mirror image of `min`. */\n max?: string;\n onSelectDate?: (day: number) => void;\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number. The second argument says what the calendar knows about the\n * day (selected, today, unavailable), so the content can follow it without redoing the logic.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /** The days that get a dot under their number (see `CalendarDayDots`). Shares the slot under the number with `renderDay`. */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot that has no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n /**\n * Day cells are perfect squares (`aspect-ratio`) instead of a fixed pixel\n * height - `DatePicker` (SS-243) opts into this since its popover can be\n * narrower than `DateTimePicker`'s own card, where a fixed height was\n * already tuned and shipped. Ignored when `renderDay` or `dayDots` is set -\n * that case always needs the extra fixed height for its own content.\n */\n squareCells?: boolean;\n /**\n * Drop wholly-blank trailing rows instead of always padding to 6 (SS-243)\n * `DateTimePicker` needs the fixed 6 rows so its *always-visible* card\n * never jumps height as you navigate months; `DatePicker`'s popover opens\n * and closes anyway, so a variable height per month reads better than a\n * dead empty row (e.g. a 30-day month starting on Sunday only needs 5).\n */\n trimEmptyRows?: boolean;\n /**\n * The product itself (Sereno's real booking app) always renders pt-BR -\n * this only exists so the docs showcase can demo an English-speaking\n * consumer without forking the component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\n}\n\nconst I18N = {\n 'pt-BR': {\n dow: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],\n months: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'],\n monthsShort: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'],\n prevMonth: 'Mês anterior',\n nextMonth: 'Próximo mês',\n prevYear: 'Ano anterior',\n prevYears: 'Anos anteriores',\n nextYear: 'Próximo ano',\n nextYears: 'Próximos anos',\n pickerLabel: 'Escolher mês e ano',\n marked: 'com marcador',\n },\n en: {\n dow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],\n months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],\n monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n prevMonth: 'Previous month',\n nextMonth: 'Next month',\n prevYear: 'Previous year',\n prevYears: 'Previous years',\n nextYear: 'Next year',\n nextYears: 'Next years',\n pickerLabel: 'Choose month and year',\n marked: 'marked',\n },\n} as const;\n\nfunction daysIn(y: number, m: number): number {\n return new Date(y, m + 1, 0).getDate();\n}\n\nexport function CalendarGrid({\n year,\n month,\n selectedDate,\n unavailable = [],\n min,\n max,\n onSelectDate,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n squareCells = false,\n trimEmptyRows = false,\n locale = 'pt-BR',\n}: CalendarGridProps) {\n const t = I18N[locale];\n const now = React.useMemo(() => new Date(), []);\n // One integer for the visible month - `year*12 + month`. Keeps ‹ / › arithmetic\n // (and rapid clicks) correct across year boundaries with no Date() juggling.\n // `year` / `month` are the *initial* view; the component then owns it. A\n // consumer that needs to reset the view (DatePicker, on reopen) remounts\n // this component instead - see its own comment.\n const range = React.useMemo(() => calendarRange(min, max), [min, max]);\n // `year` / `month` outside `min` .. `max` start on the nearest month inside it.\n const requestedIndex = (year ?? now.getFullYear()) * 12 + (month ?? now.getMonth());\n const initialIndex = clampIndex(requestedIndex, range);\n const [viewIndex, setViewIndex] = React.useState(initialIndex);\n // `min` / `max` can change after mount (a \"today\" that moves on, a bound that depends on a\n // choice made elsewhere): keep the visible month inside them. Adjusted while rendering, not in\n // an effect, so a month outside the range is never painted, not even for a frame.\n if (viewIndex !== clampIndex(viewIndex, range)) setViewIndex(clampIndex(viewIndex, range));\n const viewYear = Math.floor(viewIndex / 12);\n const viewMonth = viewIndex % 12;\n // `selectedDate` is only a day number, so remember which month that pick was\n // made in - the highlight shows only there, never on the same day of another\n // month you navigate to.\n const [selectionIndex, setSelectionIndex] = React.useState(initialIndex);\n const [open, setOpen] = React.useState(false);\n const [picker, setPicker] = React.useState<'month' | 'year'>('month');\n // Unbounded, the block is `year - 5` exactly as it always was; with a range it is based on the month\n // actually shown (the one the range moved it to).\n const bounded = Number.isFinite(range.minIndex) || Number.isFinite(range.maxIndex);\n const [yearBase, setYearBase] = React.useState(() => yearWindowStart(bounded ? Math.floor(initialIndex / 12) : (year ?? now.getFullYear()), range));\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const titleRef = React.useRef<HTMLButtonElement>(null);\n const popRef = React.useRef<HTMLDivElement>(null);\n const gridRef = React.useRef<HTMLDivElement>(null);\n\n // Roving tabindex for the day grid: only one cell is ever in the Tab\n // order (below), so Tab enters/leaves the whole grid in one stop instead\n // of one per day. `activeDay` is the day-of-month that cell represents -\n // clamped to the visible month's length at render (below), since it\n // persists across a month change (‹ / › or an arrow-key crossing) where\n // the same day number may no longer exist (e.g. the 31st, into February).\n const [activeDay, setActiveDay] = React.useState(() => {\n if (selectedDate) return selectedDate;\n const todayIndex = now.getFullYear() * 12 + now.getMonth();\n let day = todayIndex === initialIndex ? now.getDate() : 1;\n // On the first / last month of the range, start on a day that can be picked, not a struck one.\n if (range.min && initialIndex === range.minIndex) day = Math.max(day, range.min.day);\n if (range.max && initialIndex === range.maxIndex) day = Math.min(day, range.max.day);\n return day;\n });\n // Set right before a keyboard move changes activeDay/viewIndex; consumed\n // by the layout effect below to focus the new cell once it's in the DOM -\n // never on an unrelated render (a prop change, a re-render from the\n // parent) or the initial mount.\n const shouldFocusDayRef = React.useRef(false);\n\n // Notify on navigation - never on mount, always with the settled value.\n const onMonthChangeRef = React.useRef(onMonthChange);\n React.useEffect(() => {\n onMonthChangeRef.current = onMonthChange;\n });\n // The one time it does fire on mount: the month asked for was outside `min` .. `max` and was\n // moved inside it. A consumer that tracks the month (`DatePicker` does, to build the picked\n // date) must not be left believing in the one it asked for.\n const adjustedAtMount = React.useRef(requestedIndex !== initialIndex);\n const didMount = React.useRef(false);\n React.useEffect(() => {\n if (!didMount.current) {\n didMount.current = true;\n if (adjustedAtMount.current) onMonthChangeRef.current?.(Math.floor(viewIndex / 12), viewIndex % 12);\n return;\n }\n onMonthChangeRef.current?.(Math.floor(viewIndex / 12), viewIndex % 12);\n }, [viewIndex]);\n\n // close on outside pointer; move focus into the popover on open\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n setOpen(false);\n setPicker('month');\n }\n };\n document.addEventListener('pointerdown', onDown, true);\n const id = requestAnimationFrame(() => popRef.current?.focus());\n return () => {\n document.removeEventListener('pointerdown', onDown, true);\n cancelAnimationFrame(id);\n };\n }, [open]);\n\n const closePopover = React.useCallback(() => {\n setOpen(false);\n setPicker('month');\n titleRef.current?.focus();\n }, []);\n const toggleOpen = React.useCallback(() => {\n setOpen((v) => {\n if (v) setPicker('month');\n return !v;\n });\n }, []);\n\n const first = new Date(viewYear, viewMonth, 1).getDay();\n const total = daysIn(viewYear, viewMonth);\n // Always 6 rows (42 cells) so the calendar's height never shifts between\n // months - trailing blanks pad it out and carry the cell height too.\n const cells: (number | null)[] = [...Array(first).fill(null), ...Array.from({ length: total }, (_, i) => i + 1)];\n while (cells.length < 42) cells.push(null);\n if (trimEmptyRows) {\n while (cells.length > 7 && cells.slice(-7).every((c) => c === null)) cells.length -= 7;\n }\n // A plain day cell is a perfect square via aspect-ratio when `squareCells`\n // is set - its height then tracks the grid's actual column width (SS-243:\n // DatePicker's popover can be narrower than DateTimePicker's own card)\n // instead of a fixed guess that only looks square at one particular width.\n // `renderDay` needs literal extra height for its own content underneath\n // the day number regardless, so that case always keeps a fixed height.\n const hasSlot = !!renderDay || dayDots !== undefined;\n const cellSizing: React.CSSProperties = hasSlot ? { height: 48 } : squareCells ? { aspectRatio: '1' } : { height: 38 };\n const todayIndex = now.getFullYear() * 12 + now.getMonth();\n const years = Array.from({ length: 12 }, (_, i) => yearBase + i);\n const rovingDay = Math.min(Math.max(1, activeDay), total);\n\n // Arrow keys move the roving cursor by real calendar days - crossing into\n // the adjacent month's grid when they overflow the visible one, rather\n // than stopping dead at the edge. Home/End stay within the current week\n // row; PageUp/PageDown step the month (reusing the same ‹ / › state\n // change, so onMonthChange fires identically either way).\n const onGridKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n let delta = 0;\n switch (e.key) {\n case 'ArrowRight':\n delta = 1;\n break;\n case 'ArrowLeft':\n delta = -1;\n break;\n case 'ArrowDown':\n delta = 7;\n break;\n case 'ArrowUp':\n delta = -7;\n break;\n case 'Home': {\n e.preventDefault();\n const row = Math.floor((first + rovingDay - 1) / 7);\n shouldFocusDayRef.current = true;\n setActiveDay(Math.max(1, row * 7 - first + 1));\n return;\n }\n case 'End': {\n e.preventDefault();\n const row = Math.floor((first + rovingDay - 1) / 7);\n shouldFocusDayRef.current = true;\n setActiveDay(Math.min(total, row * 7 + 7 - first));\n return;\n }\n case 'PageUp':\n e.preventDefault();\n // At the first month nothing moves, and the focus flag stays down so it cannot go off later.\n if (viewIndex - 1 < range.minIndex) return;\n shouldFocusDayRef.current = true;\n setViewIndex((i) => clampIndex(i - 1, range));\n return;\n case 'PageDown':\n e.preventDefault();\n if (viewIndex + 1 > range.maxIndex) return;\n shouldFocusDayRef.current = true;\n setViewIndex((i) => clampIndex(i + 1, range));\n return;\n default:\n return;\n }\n e.preventDefault();\n const next = new Date(viewYear, viewMonth, rovingDay + delta);\n const nextViewIndex = next.getFullYear() * 12 + next.getMonth();\n // An arrow that would cross into a month outside `min` .. `max` is refused: the cursor stays put.\n if (nextViewIndex < range.minIndex || nextViewIndex > range.maxIndex) return;\n shouldFocusDayRef.current = true;\n if (nextViewIndex !== viewIndex) setViewIndex(nextViewIndex);\n setActiveDay(next.getDate());\n };\n\n // Runs after the grid above (keyed on viewIndex, so a month change remounts\n // it) has committed the DOM for the new activeDay/viewIndex - only then\n // does the target cell actually exist to focus.\n React.useLayoutEffect(() => {\n if (!shouldFocusDayRef.current) return;\n shouldFocusDayRef.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(`[data-day=\"${rovingDay}\"]`)?.focus();\n }, [viewIndex, rovingDay]);\n\n const canPrevMonth = viewIndex > range.minIndex;\n const canNextMonth = viewIndex < range.maxIndex;\n // One month with the header arrows, never outside the range. A press that lands on the first /\n // last month is about to disable the very button that has focus, and a disabled button drops\n // focus to the page: so the title button takes it first.\n const goMonth = (dir: 1 | -1) => {\n const next = clampIndex(viewIndex + dir, range);\n if (next === viewIndex) return;\n setViewIndex((i) => clampIndex(i + dir, range));\n if (clampIndex(next + dir, range) === next) titleRef.current?.focus();\n };\n // The popover's year arrows. In the month view they move the visible month by a year (clamped);\n // in the year view they page a block of 12 years. Same focus hand-off, to the popover itself.\n const canPrevYear = picker === 'month' ? viewYear > range.minYear : yearBase > range.minYear;\n const canNextYear = picker === 'month' ? viewYear < range.maxYear : yearBase + 12 <= range.maxYear;\n const goYear = (dir: 1 | -1) => {\n if (picker === 'month') {\n const next = clampIndex(viewIndex + dir * 12, range);\n if (next === viewIndex) return;\n setViewIndex((i) => clampIndex(i + dir * 12, range));\n const nextYear = Math.floor(next / 12);\n if (dir < 0 ? nextYear <= range.minYear : nextYear >= range.maxYear) popRef.current?.focus();\n } else {\n const next = yearBase + dir * 12;\n setYearBase((b) => b + dir * 12);\n if (dir < 0 ? next <= range.minYear : next + 12 > range.maxYear) popRef.current?.focus();\n }\n };\n\n return (\n <div ref={rootRef}>\n <div\n style={sx({\n position: 'relative',\n display: 'grid',\n gridTemplateColumns: 'auto 1fr auto',\n alignItems: 'center',\n gap: 'var(--space-1)',\n marginBottom: 'var(--space-3)',\n })}\n >\n <IconButton label={t.prevMonth} size=\"sm\" disabled={!canPrevMonth} onClick={() => goMonth(-1)}>\n <ChevronLeft size={18} strokeWidth={1.75} />\n </IconButton>\n\n <button\n ref={titleRef}\n type=\"button\"\n className=\"sereno-dtp-title\"\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={toggleOpen}\n style={sx({\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 4,\n margin: '0 auto',\n padding: '4px 8px',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-display)',\n fontSize: 'var(--text-base)',\n fontWeight: 'var(--weight-bold)',\n color: 'var(--text-primary)',\n textTransform: 'capitalize',\n })}\n >\n {t.months[viewMonth]} {viewYear}\n <ChevronDown size={15} strokeWidth={2} style={{ opacity: 0.6 }} />\n </button>\n\n <IconButton label={t.nextMonth} size=\"sm\" disabled={!canNextMonth} onClick={() => goMonth(1)}>\n <ChevronRight size={18} strokeWidth={1.75} />\n </IconButton>\n\n {open && (\n <div\n ref={popRef}\n role=\"dialog\"\n aria-label={t.pickerLabel}\n tabIndex={-1}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n closePopover();\n }\n }}\n className=\"sereno-dtp-pop\"\n style={sx({\n position: 'absolute',\n top: 'calc(100% + 6px)',\n left: '50%',\n transform: 'translateX(-50%)',\n zIndex: 20,\n width: 248,\n maxWidth: 'calc(100vw - 24px)',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <div\n style={sx({\n display: 'grid',\n gridTemplateColumns: 'auto 1fr auto',\n alignItems: 'center',\n marginBottom: 'var(--space-2)',\n })}\n >\n <IconButton label={picker === 'month' ? t.prevYear : t.prevYears} size=\"sm\" disabled={!canPrevYear} onClick={() => goYear(-1)}>\n <ChevronLeft size={18} strokeWidth={1.75} />\n </IconButton>\n\n {picker === 'month' ? (\n <button\n type=\"button\"\n className=\"sereno-dtp-title\"\n onClick={() => {\n setYearBase(yearWindowStart(viewYear, range));\n setPicker('year');\n }}\n style={sx({\n margin: '0 auto',\n padding: '4px 8px',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-display)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-bold)',\n color: 'var(--text-primary)',\n })}\n >\n {viewYear}\n </button>\n ) : (\n <span\n style={sx({\n textAlign: 'center',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-secondary)',\n })}\n >\n {years[0]}–{years[11]}\n </span>\n )}\n\n <IconButton label={picker === 'month' ? t.nextYear : t.nextYears} size=\"sm\" disabled={!canNextYear} onClick={() => goYear(1)}>\n <ChevronRight size={18} strokeWidth={1.75} />\n </IconButton>\n </div>\n\n <div className=\"sereno-dtp-grid\" style={sx({ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'var(--space-1)' })}>\n {picker === 'month'\n ? t.monthsShort.map((mo, i) => (\n <button\n key={mo}\n type=\"button\"\n data-current={i === viewMonth || undefined}\n aria-current={i === viewMonth ? 'true' : undefined}\n disabled={viewYear * 12 + i < range.minIndex || viewYear * 12 + i > range.maxIndex}\n onClick={() => {\n setViewIndex(clampIndex(viewYear * 12 + i, range));\n closePopover();\n }}\n >\n {mo}\n </button>\n ))\n : years.map((y) => (\n <button\n key={y}\n type=\"button\"\n data-current={y === viewYear || undefined}\n aria-current={y === viewYear ? 'true' : undefined}\n disabled={y < range.minYear || y > range.maxYear}\n onClick={() => {\n // Picking the first / last year with a month earlier / later than the range\n // allows lands on the nearest month inside it.\n setViewIndex(clampIndex(y * 12 + viewMonth, range));\n setPicker('month');\n }}\n >\n {y}\n </button>\n ))}\n </div>\n </div>\n )}\n </div>\n\n <div style={sx({ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', gap: 'var(--space-1)', marginBottom: 'var(--space-1)' })}>\n {t.dow.map((d, i) => (\n <span\n key={i}\n style={sx({\n textAlign: 'center',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-muted)',\n letterSpacing: 'var(--tracking-caps)',\n })}\n >\n {d}\n </span>\n ))}\n </div>\n {/* keyed on the month so cells remount cleanly - no bg transition when a\n slot morphs from one day to another on navigation. */}\n <div\n key={viewIndex}\n ref={gridRef}\n onKeyDown={onGridKeyDown}\n className=\"sereno-dtp-days\"\n style={sx({ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', gap: 'var(--space-1)' })}\n >\n {cells.map((d, i) => {\n // Blank cells still take the row height so the 6-row grid can't collapse.\n if (d === null) return <span key={i} aria-hidden style={cellSizing} />;\n const off = unavailable.includes(d) || isDayOutside(range, viewIndex, d);\n const sel = selectedDate === d && viewIndex === selectionIndex;\n const today = viewIndex === todayIndex && d === now.getDate();\n const extra = renderDay?.(d, { selected: sel, today, unavailable: off });\n const dot = dotFor(dayDots, d);\n return (\n <button\n key={i}\n type=\"button\"\n data-day={d}\n // Not the native `disabled` - an unavailable day stays a real,\n // focusable stop on the roving cursor (aria-disabled only) so\n // arrow-key navigation can still land on it and the user can\n // tell it exists, matching the WAI-ARIA date-grid pattern. A\n // truly `disabled` button can't receive focus at all, which\n // would make the roving tabindex below silently break.\n aria-disabled={off || undefined}\n aria-current={today ? 'date' : undefined}\n tabIndex={d === rovingDay ? 0 : -1}\n aria-pressed={sel}\n onClick={() => {\n if (off) return;\n setSelectionIndex(viewIndex);\n // Keep the roving cursor in sync with a mouse pick too - a\n // click already moves real DOM focus onto this button\n // natively, so without this the *next* arrow press would\n // jump from wherever the keyboard cursor was left instead\n // of from the day the user can see is focused/selected.\n setActiveDay(d);\n onSelectDate?.(d);\n }}\n style={sx({\n ...cellSizing,\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 1,\n borderRadius: 'var(--radius-sm)',\n border: 'none',\n padding: 0,\n cursor: off ? 'not-allowed' : 'pointer',\n background: sel ? 'var(--interactive-primary)' : 'transparent',\n color: sel ? 'var(--interactive-primary-fg)' : off ? 'var(--text-disabled)' : 'var(--text-primary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: sel ? 'var(--weight-bold)' : 'var(--weight-medium)',\n textDecoration: off ? 'line-through' : 'none',\n // Today is told apart by a thin inset ring (also `aria-current` above). Not when it\n // is the selected day: the primary fill already says which day it is.\n boxShadow: today && !sel ? TODAY_RING : undefined,\n transition: 'var(--transition-control)',\n // Not inline outline:none - that would always beat the\n // .sereno-dtp-days:focus-visible rule below no matter what\n // it says (inline style always outranks a class selector).\n // Suppressed as a class rule instead, same specificity as\n // the :focus-visible override that re-enables it.\n })}\n >\n <span>{d}</span>\n {hasSlot ? (\n <span style={sx({ display: 'flex', gap: 4, minHeight: 12, lineHeight: 1 })}>\n {extra}\n {dot ? <span aria-hidden style={sx({ ...dotStyle(dot.tone, { selected: sel, unavailable: off }), alignSelf: 'center' })} /> : null}\n </span>\n ) : null}\n {dot ? <span style={srOnlyStyle}>{dot.label ?? dayDotLabel ?? t.marked}</span> : null}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":";AAkWU,cAGF,YAHE;AAhWV,YAAY,WAAW;AACvB,SAAS,aAAa,aAAa,oBAAoB;AACvD,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,YAAY,cAAc,uBAAuB;AACzE,SAAS,QAAQ,UAAU,kBAAiE;AA8D5F,MAAM,OAAO;AAAA,EACX,SAAS;AAAA,IACP,KAAK,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,IACvC,QA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A;AAAA;AAAA;AAAA;AAAA,cAMd,CAAC;AAAA,cAED;AAAA,oCAAC,UAAM,aAAE;AAAA,gBACR,UACC,qBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,KAAK,GAAG,WAAW,IAAI,YAAY,EAAE,CAAC,GACtE;AAAA;AAAA,kBACA,MAAM,oBAAC,UAAK,eAAW,MAAC,OAAO,GAAG,EAAE,GAAG,SAAS,IAAI,MAAM,EAAE,UAAU,KAAK,aAAa,IAAI,CAAC,GAAG,WAAW,SAAS,CAAC,GAAG,IAAK;AAAA,mBAChI,IACE;AAAA,gBACH,MAAM,oBAAC,UAAK,OAAO,aAAc,cAAI,SAAS,eAAe,EAAE,QAAO,IAAU;AAAA;AAAA;AAAA,YA3D5E;AAAA,UA4DP;AAAA,QAEJ,CAAC;AAAA;AAAA,MA9EI;AAAA,IA+EP;AAAA,KACF;AAEJ;","names":["todayIndex"]}
1
+ {"version":3,"sources":["../../../src/forms/_internal/CalendarGrid.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ChevronDown, ChevronLeft, ChevronRight } from 'lucide-react';\nimport { sx } from '../../_internal/style';\nimport { srOnlyStyle } from '../../_internal/srOnly';\nimport { useOutsidePress } from '../../_internal/useOutsidePress';\nimport { IconButton } from '../../core/IconButton';\nimport { calendarRange, clampIndex, isDayOutside, yearWindowStart } from './calendarRange';\nimport { dotFor, dotStyle, TODAY_RING, type CalendarDayContext, type CalendarDayDots } from './calendarDots';\n\n/**\n * The month calendar body - header (‹ / › month nav + a month/year jump\n * popover) and the day grid with roving-tabindex keyboard navigation\n * (SS-228). Shared by `DateTimePicker` (rendered inline, with an optional\n * time-slot list under it) and `DatePicker` (rendered inside its own\n * trigger+popover shell) - extracted so neither has to duplicate the\n * keyboard-grid math (SS-243). See `DateTimePicker`'s own doc comment for\n * the full behavior description; this component owns exactly the same\n * state and logic it always has, just without the outer card chrome or\n * the time-slot section, neither of which any of this depends on.\n */\nexport interface CalendarGridProps {\n year?: number;\n month?: number;\n selectedDate?: number;\n unavailable?: number[];\n /**\n * Earliest date, ISO \"YYYY-MM-DD\". The calendar cannot be navigated to an earlier month or\n * year (the previous-month arrow disables, PageUp and the arrow keys stop at the edge, and\n * the month / year popover disables what is out of range), and every earlier day is struck\n * through, with no need to list it in `unavailable`. A value that is not a valid date is ignored.\n */\n min?: string;\n /** Latest date, ISO \"YYYY-MM-DD\". The mirror image of `min`. */\n max?: string;\n onSelectDate?: (day: number) => void;\n onMonthChange?: (year: number, month: number) => void;\n /**\n * Content under each day number. The second argument says what the calendar knows about the\n * day (selected, today, unavailable), so the content can follow it without redoing the logic.\n */\n renderDay?: (day: number, context: CalendarDayContext) => React.ReactNode;\n /** The days that get a dot under their number (see `CalendarDayDots`). Shares the slot under the number with `renderDay`. */\n dayDots?: CalendarDayDots;\n /** What a screen reader says for a dot that has no `label` of its own. Defaults to the `locale`-appropriate text. */\n dayDotLabel?: string;\n /**\n * Day cells are perfect squares (`aspect-ratio`) instead of a fixed pixel\n * height - `DatePicker` (SS-243) opts into this since its popover can be\n * narrower than `DateTimePicker`'s own card, where a fixed height was\n * already tuned and shipped. Ignored when `renderDay` or `dayDots` is set -\n * that case always needs the extra fixed height for its own content.\n */\n squareCells?: boolean;\n /**\n * Drop wholly-blank trailing rows instead of always padding to 6 (SS-243)\n * `DateTimePicker` needs the fixed 6 rows so its *always-visible* card\n * never jumps height as you navigate months; `DatePicker`'s popover opens\n * and closes anyway, so a variable height per month reads better than a\n * dead empty row (e.g. a 30-day month starting on Sunday only needs 5).\n */\n trimEmptyRows?: boolean;\n /**\n * The product itself (Sereno's real booking app) always renders pt-BR -\n * this only exists so the docs showcase can demo an English-speaking\n * consumer without forking the component. Default stays `'pt-BR'`.\n */\n locale?: 'pt-BR' | 'en';\n}\n\nconst I18N = {\n 'pt-BR': {\n dow: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],\n months: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'],\n monthsShort: ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'],\n prevMonth: 'Mês anterior',\n nextMonth: 'Próximo mês',\n prevYear: 'Ano anterior',\n prevYears: 'Anos anteriores',\n nextYear: 'Próximo ano',\n nextYears: 'Próximos anos',\n pickerLabel: 'Escolher mês e ano',\n marked: 'com marcador',\n },\n en: {\n dow: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],\n months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],\n monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n prevMonth: 'Previous month',\n nextMonth: 'Next month',\n prevYear: 'Previous year',\n prevYears: 'Previous years',\n nextYear: 'Next year',\n nextYears: 'Next years',\n pickerLabel: 'Choose month and year',\n marked: 'marked',\n },\n} as const;\n\nfunction daysIn(y: number, m: number): number {\n return new Date(y, m + 1, 0).getDate();\n}\n\nexport function CalendarGrid({\n year,\n month,\n selectedDate,\n unavailable = [],\n min,\n max,\n onSelectDate,\n onMonthChange,\n renderDay,\n dayDots,\n dayDotLabel,\n squareCells = false,\n trimEmptyRows = false,\n locale = 'pt-BR',\n}: CalendarGridProps) {\n const t = I18N[locale];\n const now = React.useMemo(() => new Date(), []);\n // One integer for the visible month - `year*12 + month`. Keeps ‹ / › arithmetic\n // (and rapid clicks) correct across year boundaries with no Date() juggling.\n // `year` / `month` are the *initial* view; the component then owns it. A\n // consumer that needs to reset the view (DatePicker, on reopen) remounts\n // this component instead - see its own comment.\n const range = React.useMemo(() => calendarRange(min, max), [min, max]);\n // `year` / `month` outside `min` .. `max` start on the nearest month inside it.\n const requestedIndex = (year ?? now.getFullYear()) * 12 + (month ?? now.getMonth());\n const initialIndex = clampIndex(requestedIndex, range);\n const [viewIndex, setViewIndex] = React.useState(initialIndex);\n // `min` / `max` can change after mount (a \"today\" that moves on, a bound that depends on a\n // choice made elsewhere): keep the visible month inside them. Adjusted while rendering, not in\n // an effect, so a month outside the range is never painted, not even for a frame.\n if (viewIndex !== clampIndex(viewIndex, range)) setViewIndex(clampIndex(viewIndex, range));\n const viewYear = Math.floor(viewIndex / 12);\n const viewMonth = viewIndex % 12;\n // `selectedDate` is only a day number, so remember which month that pick was\n // made in - the highlight shows only there, never on the same day of another\n // month you navigate to.\n const [selectionIndex, setSelectionIndex] = React.useState(initialIndex);\n const [open, setOpen] = React.useState(false);\n const [picker, setPicker] = React.useState<'month' | 'year'>('month');\n // Unbounded, the block is `year - 5` exactly as it always was; with a range it is based on the month\n // actually shown (the one the range moved it to).\n const bounded = Number.isFinite(range.minIndex) || Number.isFinite(range.maxIndex);\n const [yearBase, setYearBase] = React.useState(() => yearWindowStart(bounded ? Math.floor(initialIndex / 12) : (year ?? now.getFullYear()), range));\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const titleRef = React.useRef<HTMLButtonElement>(null);\n const popRef = React.useRef<HTMLDivElement>(null);\n const gridRef = React.useRef<HTMLDivElement>(null);\n\n // Roving tabindex for the day grid: only one cell is ever in the Tab\n // order (below), so Tab enters/leaves the whole grid in one stop instead\n // of one per day. `activeDay` is the day-of-month that cell represents -\n // clamped to the visible month's length at render (below), since it\n // persists across a month change (‹ / › or an arrow-key crossing) where\n // the same day number may no longer exist (e.g. the 31st, into February).\n const [activeDay, setActiveDay] = React.useState(() => {\n if (selectedDate) return selectedDate;\n const todayIndex = now.getFullYear() * 12 + now.getMonth();\n let day = todayIndex === initialIndex ? now.getDate() : 1;\n // On the first / last month of the range, start on a day that can be picked, not a struck one.\n if (range.min && initialIndex === range.minIndex) day = Math.max(day, range.min.day);\n if (range.max && initialIndex === range.maxIndex) day = Math.min(day, range.max.day);\n return day;\n });\n // Set right before a keyboard move changes activeDay/viewIndex; consumed\n // by the layout effect below to focus the new cell once it's in the DOM -\n // never on an unrelated render (a prop change, a re-render from the\n // parent) or the initial mount.\n const shouldFocusDayRef = React.useRef(false);\n\n // Notify on navigation - never on mount, always with the settled value.\n const onMonthChangeRef = React.useRef(onMonthChange);\n React.useEffect(() => {\n onMonthChangeRef.current = onMonthChange;\n });\n // The one time it does fire on mount: the month asked for was outside `min` .. `max` and was\n // moved inside it. A consumer that tracks the month (`DatePicker` does, to build the picked\n // date) must not be left believing in the one it asked for.\n const adjustedAtMount = React.useRef(requestedIndex !== initialIndex);\n const didMount = React.useRef(false);\n React.useEffect(() => {\n if (!didMount.current) {\n didMount.current = true;\n if (adjustedAtMount.current) onMonthChangeRef.current?.(Math.floor(viewIndex / 12), viewIndex % 12);\n return;\n }\n onMonthChangeRef.current?.(Math.floor(viewIndex / 12), viewIndex % 12);\n }, [viewIndex]);\n\n // close on outside pointer; move focus into the popover on open\n useOutsidePress(open, [rootRef], () => {\n setOpen(false);\n setPicker('month');\n });\n React.useEffect(() => {\n if (!open) return;\n const id = requestAnimationFrame(() => popRef.current?.focus());\n return () => cancelAnimationFrame(id);\n }, [open]);\n\n const closePopover = React.useCallback(() => {\n setOpen(false);\n setPicker('month');\n titleRef.current?.focus();\n }, []);\n const toggleOpen = React.useCallback(() => {\n setOpen((v) => {\n if (v) setPicker('month');\n return !v;\n });\n }, []);\n\n const first = new Date(viewYear, viewMonth, 1).getDay();\n const total = daysIn(viewYear, viewMonth);\n // Always 6 rows (42 cells) so the calendar's height never shifts between\n // months - trailing blanks pad it out and carry the cell height too.\n const cells: (number | null)[] = [...Array(first).fill(null), ...Array.from({ length: total }, (_, i) => i + 1)];\n while (cells.length < 42) cells.push(null);\n if (trimEmptyRows) {\n while (cells.length > 7 && cells.slice(-7).every((c) => c === null)) cells.length -= 7;\n }\n // A plain day cell is a perfect square via aspect-ratio when `squareCells`\n // is set - its height then tracks the grid's actual column width (SS-243:\n // DatePicker's popover can be narrower than DateTimePicker's own card)\n // instead of a fixed guess that only looks square at one particular width.\n // `renderDay` needs literal extra height for its own content underneath\n // the day number regardless, so that case always keeps a fixed height.\n const hasSlot = !!renderDay || dayDots !== undefined;\n const cellSizing: React.CSSProperties = hasSlot ? { height: 48 } : squareCells ? { aspectRatio: '1' } : { height: 38 };\n const todayIndex = now.getFullYear() * 12 + now.getMonth();\n const years = Array.from({ length: 12 }, (_, i) => yearBase + i);\n const rovingDay = Math.min(Math.max(1, activeDay), total);\n\n // Arrow keys move the roving cursor by real calendar days - crossing into\n // the adjacent month's grid when they overflow the visible one, rather\n // than stopping dead at the edge. Home/End stay within the current week\n // row; PageUp/PageDown step the month (reusing the same ‹ / › state\n // change, so onMonthChange fires identically either way).\n const onGridKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n let delta = 0;\n switch (e.key) {\n case 'ArrowRight':\n delta = 1;\n break;\n case 'ArrowLeft':\n delta = -1;\n break;\n case 'ArrowDown':\n delta = 7;\n break;\n case 'ArrowUp':\n delta = -7;\n break;\n case 'Home': {\n e.preventDefault();\n const row = Math.floor((first + rovingDay - 1) / 7);\n shouldFocusDayRef.current = true;\n setActiveDay(Math.max(1, row * 7 - first + 1));\n return;\n }\n case 'End': {\n e.preventDefault();\n const row = Math.floor((first + rovingDay - 1) / 7);\n shouldFocusDayRef.current = true;\n setActiveDay(Math.min(total, row * 7 + 7 - first));\n return;\n }\n case 'PageUp':\n e.preventDefault();\n // At the first month nothing moves, and the focus flag stays down so it cannot go off later.\n if (viewIndex - 1 < range.minIndex) return;\n shouldFocusDayRef.current = true;\n setViewIndex((i) => clampIndex(i - 1, range));\n return;\n case 'PageDown':\n e.preventDefault();\n if (viewIndex + 1 > range.maxIndex) return;\n shouldFocusDayRef.current = true;\n setViewIndex((i) => clampIndex(i + 1, range));\n return;\n default:\n return;\n }\n e.preventDefault();\n const next = new Date(viewYear, viewMonth, rovingDay + delta);\n const nextViewIndex = next.getFullYear() * 12 + next.getMonth();\n // An arrow that would cross into a month outside `min` .. `max` is refused: the cursor stays put.\n if (nextViewIndex < range.minIndex || nextViewIndex > range.maxIndex) return;\n shouldFocusDayRef.current = true;\n if (nextViewIndex !== viewIndex) setViewIndex(nextViewIndex);\n setActiveDay(next.getDate());\n };\n\n // Runs after the grid above (keyed on viewIndex, so a month change remounts\n // it) has committed the DOM for the new activeDay/viewIndex - only then\n // does the target cell actually exist to focus.\n React.useLayoutEffect(() => {\n if (!shouldFocusDayRef.current) return;\n shouldFocusDayRef.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(`[data-day=\"${rovingDay}\"]`)?.focus();\n }, [viewIndex, rovingDay]);\n\n const canPrevMonth = viewIndex > range.minIndex;\n const canNextMonth = viewIndex < range.maxIndex;\n // One month with the header arrows, never outside the range. A press that lands on the first /\n // last month is about to disable the very button that has focus, and a disabled button drops\n // focus to the page: so the title button takes it first.\n const goMonth = (dir: 1 | -1) => {\n const next = clampIndex(viewIndex + dir, range);\n if (next === viewIndex) return;\n setViewIndex((i) => clampIndex(i + dir, range));\n if (clampIndex(next + dir, range) === next) titleRef.current?.focus();\n };\n // The popover's year arrows. In the month view they move the visible month by a year (clamped);\n // in the year view they page a block of 12 years. Same focus hand-off, to the popover itself.\n const canPrevYear = picker === 'month' ? viewYear > range.minYear : yearBase > range.minYear;\n const canNextYear = picker === 'month' ? viewYear < range.maxYear : yearBase + 12 <= range.maxYear;\n const goYear = (dir: 1 | -1) => {\n if (picker === 'month') {\n const next = clampIndex(viewIndex + dir * 12, range);\n if (next === viewIndex) return;\n setViewIndex((i) => clampIndex(i + dir * 12, range));\n const nextYear = Math.floor(next / 12);\n if (dir < 0 ? nextYear <= range.minYear : nextYear >= range.maxYear) popRef.current?.focus();\n } else {\n const next = yearBase + dir * 12;\n setYearBase((b) => b + dir * 12);\n if (dir < 0 ? next <= range.minYear : next + 12 > range.maxYear) popRef.current?.focus();\n }\n };\n\n return (\n <div ref={rootRef}>\n <div\n style={sx({\n position: 'relative',\n display: 'grid',\n gridTemplateColumns: 'auto 1fr auto',\n alignItems: 'center',\n gap: 'var(--space-1)',\n marginBottom: 'var(--space-3)',\n })}\n >\n <IconButton label={t.prevMonth} size=\"sm\" disabled={!canPrevMonth} onClick={() => goMonth(-1)}>\n <ChevronLeft size={18} strokeWidth={1.75} />\n </IconButton>\n\n <button\n ref={titleRef}\n type=\"button\"\n className=\"sereno-dtp-title\"\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={toggleOpen}\n style={sx({\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 4,\n margin: '0 auto',\n padding: '4px 8px',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-display)',\n fontSize: 'var(--text-base)',\n fontWeight: 'var(--weight-bold)',\n color: 'var(--text-primary)',\n textTransform: 'capitalize',\n })}\n >\n {t.months[viewMonth]} {viewYear}\n <ChevronDown size={15} strokeWidth={2} style={{ opacity: 0.6 }} />\n </button>\n\n <IconButton label={t.nextMonth} size=\"sm\" disabled={!canNextMonth} onClick={() => goMonth(1)}>\n <ChevronRight size={18} strokeWidth={1.75} />\n </IconButton>\n\n {open && (\n <div\n ref={popRef}\n role=\"dialog\"\n aria-label={t.pickerLabel}\n tabIndex={-1}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n closePopover();\n }\n }}\n className=\"sereno-dtp-pop\"\n style={sx({\n position: 'absolute',\n top: 'calc(100% + 6px)',\n left: '50%',\n transform: 'translateX(-50%)',\n zIndex: 20,\n width: 248,\n maxWidth: 'calc(100vw - 24px)',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: 'var(--space-3)',\n outline: 'none',\n })}\n >\n <div\n style={sx({\n display: 'grid',\n gridTemplateColumns: 'auto 1fr auto',\n alignItems: 'center',\n marginBottom: 'var(--space-2)',\n })}\n >\n <IconButton label={picker === 'month' ? t.prevYear : t.prevYears} size=\"sm\" disabled={!canPrevYear} onClick={() => goYear(-1)}>\n <ChevronLeft size={18} strokeWidth={1.75} />\n </IconButton>\n\n {picker === 'month' ? (\n <button\n type=\"button\"\n className=\"sereno-dtp-title\"\n onClick={() => {\n setYearBase(yearWindowStart(viewYear, range));\n setPicker('year');\n }}\n style={sx({\n margin: '0 auto',\n padding: '4px 8px',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-display)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-bold)',\n color: 'var(--text-primary)',\n })}\n >\n {viewYear}\n </button>\n ) : (\n <span\n style={sx({\n textAlign: 'center',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-secondary)',\n })}\n >\n {years[0]}–{years[11]}\n </span>\n )}\n\n <IconButton label={picker === 'month' ? t.nextYear : t.nextYears} size=\"sm\" disabled={!canNextYear} onClick={() => goYear(1)}>\n <ChevronRight size={18} strokeWidth={1.75} />\n </IconButton>\n </div>\n\n <div className=\"sereno-dtp-grid\" style={sx({ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 'var(--space-1)' })}>\n {picker === 'month'\n ? t.monthsShort.map((mo, i) => (\n <button\n key={mo}\n type=\"button\"\n data-current={i === viewMonth || undefined}\n aria-current={i === viewMonth ? 'true' : undefined}\n disabled={viewYear * 12 + i < range.minIndex || viewYear * 12 + i > range.maxIndex}\n onClick={() => {\n setViewIndex(clampIndex(viewYear * 12 + i, range));\n closePopover();\n }}\n >\n {mo}\n </button>\n ))\n : years.map((y) => (\n <button\n key={y}\n type=\"button\"\n data-current={y === viewYear || undefined}\n aria-current={y === viewYear ? 'true' : undefined}\n disabled={y < range.minYear || y > range.maxYear}\n onClick={() => {\n // Picking the first / last year with a month earlier / later than the range\n // allows lands on the nearest month inside it.\n setViewIndex(clampIndex(y * 12 + viewMonth, range));\n setPicker('month');\n }}\n >\n {y}\n </button>\n ))}\n </div>\n </div>\n )}\n </div>\n\n <div style={sx({ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', gap: 'var(--space-1)', marginBottom: 'var(--space-1)' })}>\n {t.dow.map((d, i) => (\n <span\n key={i}\n style={sx({\n textAlign: 'center',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-semibold)',\n color: 'var(--text-muted)',\n letterSpacing: 'var(--tracking-caps)',\n })}\n >\n {d}\n </span>\n ))}\n </div>\n {/* keyed on the month so cells remount cleanly - no bg transition when a\n slot morphs from one day to another on navigation. */}\n <div\n key={viewIndex}\n ref={gridRef}\n onKeyDown={onGridKeyDown}\n className=\"sereno-dtp-days\"\n style={sx({ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', gap: 'var(--space-1)' })}\n >\n {cells.map((d, i) => {\n // Blank cells still take the row height so the 6-row grid can't collapse.\n if (d === null) return <span key={i} aria-hidden style={cellSizing} />;\n const off = unavailable.includes(d) || isDayOutside(range, viewIndex, d);\n const sel = selectedDate === d && viewIndex === selectionIndex;\n const today = viewIndex === todayIndex && d === now.getDate();\n const extra = renderDay?.(d, { selected: sel, today, unavailable: off });\n const dot = dotFor(dayDots, d);\n return (\n <button\n key={i}\n type=\"button\"\n data-day={d}\n // Not the native `disabled` - an unavailable day stays a real,\n // focusable stop on the roving cursor (aria-disabled only) so\n // arrow-key navigation can still land on it and the user can\n // tell it exists, matching the WAI-ARIA date-grid pattern. A\n // truly `disabled` button can't receive focus at all, which\n // would make the roving tabindex below silently break.\n aria-disabled={off || undefined}\n aria-current={today ? 'date' : undefined}\n tabIndex={d === rovingDay ? 0 : -1}\n aria-pressed={sel}\n onClick={() => {\n if (off) return;\n setSelectionIndex(viewIndex);\n // Keep the roving cursor in sync with a mouse pick too - a\n // click already moves real DOM focus onto this button\n // natively, so without this the *next* arrow press would\n // jump from wherever the keyboard cursor was left instead\n // of from the day the user can see is focused/selected.\n setActiveDay(d);\n onSelectDate?.(d);\n }}\n style={sx({\n ...cellSizing,\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: 1,\n borderRadius: 'var(--radius-sm)',\n border: 'none',\n padding: 0,\n cursor: off ? 'not-allowed' : 'pointer',\n background: sel ? 'var(--interactive-primary)' : 'transparent',\n color: sel ? 'var(--interactive-primary-fg)' : off ? 'var(--text-disabled)' : 'var(--text-primary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n fontWeight: sel ? 'var(--weight-bold)' : 'var(--weight-medium)',\n textDecoration: off ? 'line-through' : 'none',\n // Today is told apart by a thin inset ring (also `aria-current` above). Not when it\n // is the selected day: the primary fill already says which day it is.\n boxShadow: today && !sel ? TODAY_RING : undefined,\n transition: 'var(--transition-control)',\n // Not inline outline:none - that would always beat the\n // .sereno-dtp-days:focus-visible rule below no matter what\n // it says (inline style always outranks a class selector).\n // Suppressed as a class rule instead, same specificity as\n // the :focus-visible override that re-enables it.\n })}\n >\n <span>{d}</span>\n {hasSlot ? (\n <span style={sx({ display: 'flex', gap: 4, minHeight: 12, lineHeight: 1 })}>\n {extra}\n {dot ? <span aria-hidden style={sx({ ...dotStyle(dot.tone, { selected: sel, unavailable: off }), alignSelf: 'center' })} /> : null}\n </span>\n ) : null}\n {dot ? <span style={srOnlyStyle}>{dot.label ?? dayDotLabel ?? t.marked}</span> : null}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n"],"mappings":";AA6VU,cAGF,YAHE;AA3VV,YAAY,WAAW;AACvB,SAAS,aAAa,aAAa,oBAAoB;AACvD,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,eAAe,YAAY,cAAc,uBAAuB;AACzE,SAAS,QAAQ,UAAU,kBAAiE;AA8D5F,MAAM,OAAO;AAAA,EACX,SAAS;AAAA,IACP,KAAK,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AA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,WAAW,IAAI,YAAY,EAAE,CAAC,GACtE;AAAA;AAAA,kBACA,MAAM,oBAAC,UAAK,eAAW,MAAC,OAAO,GAAG,EAAE,GAAG,SAAS,IAAI,MAAM,EAAE,UAAU,KAAK,aAAa,IAAI,CAAC,GAAG,WAAW,SAAS,CAAC,GAAG,IAAK;AAAA,mBAChI,IACE;AAAA,gBACH,MAAM,oBAAC,UAAK,OAAO,aAAc,cAAI,SAAS,eAAe,EAAE,QAAO,IAAU;AAAA;AAAA;AAAA,YA3D5E;AAAA,UA4DP;AAAA,QAEJ,CAAC;AAAA;AAAA,MA9EI;AAAA,IA+EP;AAAA,KACF;AAEJ;","names":["todayIndex"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sereno-ds/ui",
3
- "version": "0.41.2",
3
+ "version": "0.41.3",
4
4
  "description": "Sereno Design System: React primitives (token-driven, inline styles, no UI base lib).",
5
5
  "license": "MIT",
6
6
  "author": "Sereno",