@nswds/ui 9.5.0 → 9.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/alert-dialog.js +2 -2
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/button-group.d.ts +2 -2
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/combobox.js +2 -2
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/component-preview.d.ts +7 -5
- package/dist/components/component-preview.js +53 -7
- package/dist/components/component-preview.js.map +1 -1
- package/dist/components/dialog.js +2 -2
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/drawer.js +2 -2
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/hover-card.js +2 -2
- package/dist/components/hover-card.js.map +1 -1
- package/dist/components/input-otp.js +4 -1
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/native-select.js +10 -2
- package/dist/components/native-select.js.map +1 -1
- package/dist/components/navigation-menu.js +2 -1
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/popover.js +2 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/select.js +12 -4
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.js +2 -2
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/site-search.js +2 -2
- package/dist/components/site-search.js.map +1 -1
- package/dist/components/toggle.js +12 -2
- package/dist/components/toggle.js.map +1 -1
- package/dist/components/tooltip.js +2 -2
- package/dist/components/tooltip.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/portal-boundary.d.ts +47 -0
- package/dist/lib/portal-boundary.js +24 -0
- package/dist/lib/portal-boundary.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/site-search.tsx"],"names":[],"mappings":";;;;;;;;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A,EAAU,kBAAA;AAAA,sBACV,SAAA,EAAU,qFAAA;AAAA,sBAET,WAAC,KAAA,qBACA,IAAA;AAAA,wBAAC,YAAA,CAAa,KAAA;AAAA,wBAAb;AAAA,0BAEC,OAAO,KAAA,CAAM,KAAA;AAAA,0BACb,WAAA,EAAU,mBAAA;AAAA,0BAEV,QAAA,EAAA;AAAA,4CAAA,GAAA;AAAA,8BAAC,YAAA,CAAa,UAAA;AAAA,8BAAb;AAAA,gCACC,WAAA,EAAU,yBAAA;AAAA,gCACV,SAAA,EAAU,4DAAA;AAAA,gCAET,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,6BACT;AAAA,4CACA,GAAA,CAAC,YAAA,CAAa,UAAA,EAAb,EACE,WAAC,IAAA,qBACA,GAAA;AAAA,8BAAC,YAAA,CAAa,IAAA;AAAA,8BAAb;AAAA,gCAEC,KAAA,EAAO,IAAA;AAAA,gCACP,WAAA,EAAU,kBAAA;AAAA,gCACV,OAAA,EAAS,MAAM,YAAA,CAAa,IAAI,CAAA;AAAA,gCAGhC,SAAA,EAAU,4OAAA;AAAA,gCAET,QAAA,EAAA,IAAA,CAAK;AAAA,+BAAA;AAAA,8BARD,IAAA,CAAK;AAAA,6BASZ,EAEJ;AAAA;AAAA,yBAAA;AAAA,wBAxBK,KAAA,CAAM;AAAA;AAyBb;AAAA;AAEJ;AAAA;AAAA,aACF;AAAA,YAEC,YAAY,IAAA,mBACX,GAAA;AAAA,cAAC,KAAA;AAAA,cAAA;AAAA,gBACC,WAAA,EAAU,oBAAA;AAAA,gBACV,SAAA,EAAU,uEAAA;AAAA,gBAET;AAAA;AAAA,aACH,GACE;AAAA;AAAA;AAAA;AACN,KAAA,EACF,CAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"site-search.js","sourcesContent":["'use client'\n\nimport { Autocomplete } from '@base-ui/react/autocomplete'\nimport { Dialog } from '@base-ui/react/dialog'\nimport React from 'react'\n\nimport { IconSearch } from '../icons/search.js'\nimport { ButtonGroupBoundary } from '../lib/button-group-context.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\n\n/** A single searchable destination. `keywords` extend matching beyond the title. */\ntype SiteSearchItem = {\n title: string\n href: string\n keywords?: string[]\n}\n\n/** A titled section of results, rendered with a muted group heading. */\ntype SiteSearchGroup = {\n title: string\n items: SiteSearchItem[]\n}\n\ntype SiteSearchProps = {\n /** The searchable site map, as titled groups of items. */\n groups: SiteSearchGroup[]\n /**\n * Called with the chosen item on click or Enter, after the palette closes.\n * Navigation is the APP's job — call your router here (e.g. next/navigation's\n * `router.push(item.href)`). The design system ships no framework code, so it\n * never navigates itself; this mirrors the DS-wide framework-free rule\n * (see `Link` / `LinkProvider`).\n */\n onSelect: (item: SiteSearchItem) => void\n /** Whether the palette is open. Use when controlled. */\n open?: boolean\n /** Called whenever the palette asks to open or close. */\n onOpenChange?: (open: boolean) => void\n /** Whether the palette is initially open (uncontrolled). */\n defaultOpen?: boolean\n /**\n * Wire the global Cmd/Ctrl-K toggle on `document`, with cleanup on unmount.\n * Defaults to true. Only one shortcut-enabled SiteSearch should be mounted\n * per page, or each press toggles all of them.\n */\n shortcut?: boolean\n /**\n * Accessible name for the palette, applied as `aria-label` to the dialog\n * panel, the search input and the default trigger. Defaults to\n * `'Search site'`. Mirrors ExpandableSearch's `label` prop — localise it\n * rather than hardcoding English into consumers' pages.\n */\n label?: string\n /** Placeholder for the search input. */\n placeholder?: string\n /** Message shown when no items match the query. */\n emptyMessage?: string\n /**\n * The element that opens the palette. Defaults to a ghost icon `Button`\n * named by `label`. Pass an element to replace it — it is composed via Base\n * UI's `render` prop, so it inherits the trigger behaviour and ARIA — or\n * `null` to render no trigger at all (open via `open` or the shortcut).\n * A custom trigger owns its own accessible name — `label` is applied as\n * `aria-label` to the default icon button only, since overriding a visible\n * label that way fails WCAG 2.2, 2.5.3 Label in Name.\n *\n * Conditional triggers must resolve to `null`, not `false`: write\n * `cond ? <Button/> : null`, since `cond && <Button/>` yields `false`, which\n * Base UI's `render` prop rejects with an invalid-element error. TypeScript\n * catches it (`false` is not assignable here); plain-JS consumers see the\n * error at render.\n */\n trigger?: React.ReactElement | null\n /**\n * Extra content rendered at the foot of the panel, below the results —\n * e.g. shortcut hints or a \"browse all\" link.\n */\n children?: React.ReactNode\n /** Extra classes for the centred panel. */\n className?: string\n}\n\n/**\n * Cmd/Ctrl-K command-palette site search: a centred modal panel with a\n * filter-as-you-type input over a grouped list of destinations.\n *\n * Ported from nswds-app's `MobileSearch`, rebuilt framework-free: the app\n * version composed cmdk's `Command*` widgets with next/navigation's router;\n * this version composes Base UI's Autocomplete (the combobox/listbox pattern)\n * inside Base UI's Dialog, and hands the chosen item to `onSelect` instead of\n * navigating. The Autocomplete renders in `inline` mode — its input and list\n * sit statically inside the dialog panel with no popup of their own — which is\n * Base UI's documented composition for palettes (it avoids any portal /\n * focus-trap interplay between the two primitives; the always-`open` inline\n * root unmounts with the dialog, so the query and highlight reset on close).\n *\n * Accessibility contract (inherited, not hand-rolled):\n * - Dialog provides the modal behaviour: focus trap, scroll lock, Escape and\n * backdrop-press dismissal, and focus restoration to the trigger on close.\n * The panel is named via `aria-label` (WCAG 2.2, 4.1.2).\n * - Autocomplete provides the combobox pattern: the input is announced as a\n * combobox controlling a listbox, arrow keys move `aria-activedescendant`\n * highlight while DOM focus stays in the input, Enter activates the\n * highlighted item, and the empty state is announced politely.\n * - The trigger (default or custom) renders through `Dialog.Trigger`, so it\n * carries `aria-haspopup=\"dialog\"` / `aria-expanded` automatically.\n * - Result rows are at least 44px tall (2.5.8 Target Size, AAA-sized).\n * - Panel and backdrop transitions honour `prefers-reduced-motion` (2.3.3).\n *\n * Departures from the nswds-app source, beyond the rebuild above:\n * - `groups`/`onSelect` replace the app's `NavigationItem[]` + router: the\n * data shape is explicit (`title`/`href`/`keywords`) instead of the app's\n * nav config, and untitled/unlinked entries can't exist by construction\n * (the source filtered them at render time).\n * - Filtering matches `title` AND `keywords`, case-insensitively, via the\n * Autocomplete `filter` prop. Base UI's `useFilter` helper only matches one\n * string per item, so a custom predicate is the documented escape hatch for\n * multi-field matching; groups with no matching items are dropped by the\n * primitive, headings included.\n * - The Cmd/Ctrl-K listener can be disabled (`shortcut={false}`) — required\n * for pages that mount more than one instance. It still toggles, per the\n * source.\n */\nfunction SiteSearch({\n groups,\n onSelect,\n open: openProp,\n onOpenChange,\n defaultOpen = false,\n shortcut = true,\n label = 'Search site',\n placeholder = 'Type to search across the site...',\n emptyMessage = 'No results found.',\n trigger,\n children,\n className,\n}: SiteSearchProps) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n const isControlled = openProp !== undefined\n const open = isControlled ? openProp : uncontrolledOpen\n\n const inputRef = React.useRef<HTMLInputElement>(null)\n\n // Latest-value refs so the document-level shortcut listener (bound once per\n // `shortcut` value) never acts on a stale open state or stale callbacks.\n // They are written in a passive effect (not during render, per\n // react-hooks/refs) — safe because they are only read from event listeners,\n // which always fire after the commit that synced them.\n const openRef = React.useRef(open)\n const requestOpenChangeRef = React.useRef<(next: boolean) => void>(() => {})\n\n const requestOpenChange = (next: boolean) => {\n if (isControlled) {\n // Dedupe against the render-authoritative prop only — never write\n // openRef optimistically here. An optimistic write would let a parent\n // that vetoes a request (ignores it, so no re-render runs the resync\n // effect) permanently swallow every later identical request. Accepted\n // trade-off: a same-tick duplicate close (Escape reaching both the\n // Autocomplete and the Dialog) may reach `onOpenChange` twice with the\n // same value — idempotent for a setState parent, and correctness in\n // the veto case beats dedupe cosmetics.\n if (open === next) {\n return\n }\n onOpenChange?.(next)\n return\n }\n // Uncontrolled, the component owns the state, so the optimistic write is\n // safe (the commit below confirms it) and dedupes the double-report case\n // (both primitives announcing the same close) down to one callback.\n if (openRef.current === next) {\n return\n }\n openRef.current = next\n setUncontrolledOpen(next)\n onOpenChange?.(next)\n }\n\n React.useEffect(() => {\n // `open` (not `next` from an event) is authoritative here: in controlled\n // mode this effect is the ref's ONLY writer, so the shortcut listener\n // always toggles from the last value the parent actually rendered.\n openRef.current = open\n requestOpenChangeRef.current = requestOpenChange\n })\n\n React.useEffect(() => {\n if (!shortcut) {\n return undefined\n }\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key.toLowerCase() === 'k' &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n // Toggle, per the nswds-app source: the same chord opens and closes.\n requestOpenChangeRef.current(!openRef.current)\n }\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => document.removeEventListener('keydown', handleKeyDown)\n }, [shortcut])\n\n const handleSelect = (item: SiteSearchItem) => {\n // Close first, then hand over — mirrors the source's `runCommand`, so the\n // app's navigation starts from a closed palette.\n requestOpenChange(false)\n onSelect(item)\n }\n\n const filter = React.useCallback((item: SiteSearchItem, query: string) => {\n const q = query.trim().toLowerCase()\n if (q === '') {\n return true\n }\n if (item.title.toLowerCase().includes(q)) {\n return true\n }\n return (item.keywords ?? []).some((keyword) => keyword.toLowerCase().includes(q))\n }, [])\n\n const defaultTrigger = (\n <Button\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={label}\n leadingVisual={IconSearch}\n />\n )\n\n return (\n <Dialog.Root open={open} onOpenChange={(next) => requestOpenChange(next)}>\n {trigger === null ? null : (\n <Dialog.Trigger data-slot='site-search-trigger' render={trigger ?? defaultTrigger} />\n )}\n\n <Dialog.Portal>\n {/* Stops a ButtonGroup's context at the portal — see ButtonGroupBoundary. */}\n <ButtonGroupBoundary>\n <Dialog.Backdrop\n data-slot='site-search-overlay'\n className='fixed inset-0 z-50 bg-black/80 duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs motion-safe:transition-opacity'\n />\n <Dialog.Popup\n data-slot='site-search-panel'\n aria-label={label}\n // The default focus target on touch is the panel itself (to keep the\n // virtual keyboard closed) — wrong for a search palette, whose whole\n // purpose is typing. Always focus the input.\n initialFocus={inputRef}\n className={cn(\n // Centred panel on the house popup surface (popover.tsx / sheet.tsx).\n 'fixed top-[max(--spacing(4),15vh)] left-1/2 z-50 w-[calc(100vw-2rem)] max-w-2xl -translate-x-1/2',\n 'rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden',\n 'duration-150 ease-out motion-safe:transition',\n 'data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0',\n className,\n )}\n >\n <Autocomplete.Root\n items={groups}\n filter={filter}\n itemToStringValue={(item: SiteSearchItem) => item.title}\n autoHighlight\n // Inline mode: the list renders statically inside the dialog panel\n // (no Autocomplete portal/positioner), with `open` pinned per the\n // Base UI docs. Opening/closing belongs to the Dialog; the whole\n // Autocomplete unmounts with it, resetting query and highlight.\n inline\n open\n onOpenChange={(nextOpen, eventDetails) => {\n // The pinned-open inline Autocomplete still *requests* closes;\n // forward the ones that should dismiss the palette. Other\n // reasons (input-clear, focus-out) must not close the dialog —\n // clearing the query or tabbing within the trap isn't dismissal.\n if (\n !nextOpen &&\n (eventDetails.reason === 'escape-key' || eventDetails.reason === 'item-press')\n ) {\n requestOpenChange(false)\n }\n }}\n >\n <div\n data-slot='site-search-input-row'\n className='flex items-center gap-3 border-b border-foreground/10 px-4'\n >\n <IconSearch aria-hidden='true' className='size-5 shrink-0 text-muted-foreground' />\n <Autocomplete.Input\n data-slot='site-search-input'\n aria-label={label}\n placeholder={placeholder}\n className='h-12 w-full bg-transparent text-base text-foreground outline-hidden placeholder:text-muted-foreground'\n ref={inputRef}\n />\n </div>\n\n {/* Base UI renders Empty's children only while the list is empty;\n the padding lives on the inner div so the (always-mounted, for\n polite announcements) outer element paints nothing otherwise. */}\n <Autocomplete.Empty data-slot='site-search-empty'>\n <div className='px-4 py-6 text-center text-sm text-muted-foreground'>\n {emptyMessage}\n </div>\n </Autocomplete.Empty>\n\n <Autocomplete.List\n data-slot='site-search-list'\n className='max-h-[min(--spacing(96),60vh)] overflow-y-auto overscroll-contain p-2 empty:hidden'\n >\n {(group: SiteSearchGroup) => (\n <Autocomplete.Group\n key={group.title}\n items={group.items}\n data-slot='site-search-group'\n >\n <Autocomplete.GroupLabel\n data-slot='site-search-group-label'\n className='px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground'\n >\n {group.title}\n </Autocomplete.GroupLabel>\n <Autocomplete.Collection>\n {(item: SiteSearchItem) => (\n <Autocomplete.Item\n key={item.href}\n value={item}\n data-slot='site-search-item'\n onClick={() => handleSelect(item)}\n // Highlight treatment mirrors menubar.tsx: keyboard and\n // hover unify as data-highlighted, painted as 10% ink.\n className='flex min-h-11 cursor-default items-center gap-2 rounded-sm px-3 py-2 text-sm text-foreground outline-hidden select-none data-highlighted:bg-primary-800/10 data-highlighted:text-accent-foreground dark:data-highlighted:bg-primary-200/10'\n >\n {item.title}\n </Autocomplete.Item>\n )}\n </Autocomplete.Collection>\n </Autocomplete.Group>\n )}\n </Autocomplete.List>\n </Autocomplete.Root>\n\n {children != null ? (\n <div\n data-slot='site-search-footer'\n className='border-t border-foreground/10 px-4 py-2 text-xs text-muted-foreground'\n >\n {children}\n </div>\n ) : null}\n </Dialog.Popup>\n </ButtonGroupBoundary>\n </Dialog.Portal>\n </Dialog.Root>\n )\n}\n\nexport { SiteSearch }\nexport type { SiteSearchGroup, SiteSearchItem, SiteSearchProps }\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/site-search.tsx"],"names":[],"mappings":";;;;;;;;;AA6HA,SAAS,UAAA,CAAW;AAAA,EAClB,MAAA;AAAA,EACA,QAAA;AAAA,EACA,IAAA,EAAM,QAAA;AAAA,EACN,YAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,QAAA,GAAW,IAAA;AAAA,EACX,KAAA,GAAQ,aAAA;AAAA,EACR,WAAA,GAAc,mCAAA;AAAA,EACd,YAAA,GAAe,mBAAA;AAAA,EACf,OAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA,EAAoB;AAClB,EAAA,MAAM,CAAC,gBAAA,EAA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gCAET,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,6BACT;AAAA,4CACA,GAAA,CAAC,YAAA,CAAa,UAAA,EAAb,EACE,WAAC,IAAA,qBACA,GAAA;AAAA,8BAAC,YAAA,CAAa,IAAA;AAAA,8BAAb;AAAA,gCAEC,KAAA,EAAO,IAAA;AAAA,gCACP,WAAA,EAAU,kBAAA;AAAA,gCACV,OAAA,EAAS,MAAM,YAAA,CAAa,IAAI,CAAA;AAAA,gCAGhC,SAAA,EAAU,4OAAA;AAAA,gCAET,QAAA,EAAA,IAAA,CAAK;AAAA,+BAAA;AAAA,8BARD,IAAA,CAAK;AAAA,6BASZ,EAEJ;AAAA;AAAA,yBAAA;AAAA,wBAxBK,KAAA,CAAM;AAAA;AAyBb;AAAA;AAEJ;AAAA;AAAA,aACF;AAAA,YAEC,YAAY,IAAA,mBACX,GAAA;AAAA,cAAC,KAAA;AAAA,cAAA;AAAA,gBACC,WAAA,EAAU,oBAAA;AAAA,gBACV,SAAA,EAAU,uEAAA;AAAA,gBAET;AAAA;AAAA,aACH,GACE;AAAA;AAAA;AAAA;AACN,KAAA,EACF,CAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"site-search.js","sourcesContent":["'use client'\n\nimport { Autocomplete } from '@base-ui/react/autocomplete'\nimport { Dialog } from '@base-ui/react/dialog'\nimport React from 'react'\n\nimport { IconSearch } from '../icons/search.js'\nimport { PortalBoundary } from '../lib/portal-boundary.js'\nimport { cn } from '../lib/utils.js'\n\nimport { Button } from '../components/button.js'\n\n/** A single searchable destination. `keywords` extend matching beyond the title. */\ntype SiteSearchItem = {\n title: string\n href: string\n keywords?: string[]\n}\n\n/** A titled section of results, rendered with a muted group heading. */\ntype SiteSearchGroup = {\n title: string\n items: SiteSearchItem[]\n}\n\ntype SiteSearchProps = {\n /** The searchable site map, as titled groups of items. */\n groups: SiteSearchGroup[]\n /**\n * Called with the chosen item on click or Enter, after the palette closes.\n * Navigation is the APP's job — call your router here (e.g. next/navigation's\n * `router.push(item.href)`). The design system ships no framework code, so it\n * never navigates itself; this mirrors the DS-wide framework-free rule\n * (see `Link` / `LinkProvider`).\n */\n onSelect: (item: SiteSearchItem) => void\n /** Whether the palette is open. Use when controlled. */\n open?: boolean\n /** Called whenever the palette asks to open or close. */\n onOpenChange?: (open: boolean) => void\n /** Whether the palette is initially open (uncontrolled). */\n defaultOpen?: boolean\n /**\n * Wire the global Cmd/Ctrl-K toggle on `document`, with cleanup on unmount.\n * Defaults to true. Only one shortcut-enabled SiteSearch should be mounted\n * per page, or each press toggles all of them.\n */\n shortcut?: boolean\n /**\n * Accessible name for the palette, applied as `aria-label` to the dialog\n * panel, the search input and the default trigger. Defaults to\n * `'Search site'`. Mirrors ExpandableSearch's `label` prop — localise it\n * rather than hardcoding English into consumers' pages.\n */\n label?: string\n /** Placeholder for the search input. */\n placeholder?: string\n /** Message shown when no items match the query. */\n emptyMessage?: string\n /**\n * The element that opens the palette. Defaults to a ghost icon `Button`\n * named by `label`. Pass an element to replace it — it is composed via Base\n * UI's `render` prop, so it inherits the trigger behaviour and ARIA — or\n * `null` to render no trigger at all (open via `open` or the shortcut).\n * A custom trigger owns its own accessible name — `label` is applied as\n * `aria-label` to the default icon button only, since overriding a visible\n * label that way fails WCAG 2.2, 2.5.3 Label in Name.\n *\n * Conditional triggers must resolve to `null`, not `false`: write\n * `cond ? <Button/> : null`, since `cond && <Button/>` yields `false`, which\n * Base UI's `render` prop rejects with an invalid-element error. TypeScript\n * catches it (`false` is not assignable here); plain-JS consumers see the\n * error at render.\n */\n trigger?: React.ReactElement | null\n /**\n * Extra content rendered at the foot of the panel, below the results —\n * e.g. shortcut hints or a \"browse all\" link.\n */\n children?: React.ReactNode\n /** Extra classes for the centred panel. */\n className?: string\n}\n\n/**\n * Cmd/Ctrl-K command-palette site search: a centred modal panel with a\n * filter-as-you-type input over a grouped list of destinations.\n *\n * Ported from nswds-app's `MobileSearch`, rebuilt framework-free: the app\n * version composed cmdk's `Command*` widgets with next/navigation's router;\n * this version composes Base UI's Autocomplete (the combobox/listbox pattern)\n * inside Base UI's Dialog, and hands the chosen item to `onSelect` instead of\n * navigating. The Autocomplete renders in `inline` mode — its input and list\n * sit statically inside the dialog panel with no popup of their own — which is\n * Base UI's documented composition for palettes (it avoids any portal /\n * focus-trap interplay between the two primitives; the always-`open` inline\n * root unmounts with the dialog, so the query and highlight reset on close).\n *\n * Accessibility contract (inherited, not hand-rolled):\n * - Dialog provides the modal behaviour: focus trap, scroll lock, Escape and\n * backdrop-press dismissal, and focus restoration to the trigger on close.\n * The panel is named via `aria-label` (WCAG 2.2, 4.1.2).\n * - Autocomplete provides the combobox pattern: the input is announced as a\n * combobox controlling a listbox, arrow keys move `aria-activedescendant`\n * highlight while DOM focus stays in the input, Enter activates the\n * highlighted item, and the empty state is announced politely.\n * - The trigger (default or custom) renders through `Dialog.Trigger`, so it\n * carries `aria-haspopup=\"dialog\"` / `aria-expanded` automatically.\n * - Result rows are at least 44px tall (2.5.8 Target Size, AAA-sized).\n * - Panel and backdrop transitions honour `prefers-reduced-motion` (2.3.3).\n *\n * Departures from the nswds-app source, beyond the rebuild above:\n * - `groups`/`onSelect` replace the app's `NavigationItem[]` + router: the\n * data shape is explicit (`title`/`href`/`keywords`) instead of the app's\n * nav config, and untitled/unlinked entries can't exist by construction\n * (the source filtered them at render time).\n * - Filtering matches `title` AND `keywords`, case-insensitively, via the\n * Autocomplete `filter` prop. Base UI's `useFilter` helper only matches one\n * string per item, so a custom predicate is the documented escape hatch for\n * multi-field matching; groups with no matching items are dropped by the\n * primitive, headings included.\n * - The Cmd/Ctrl-K listener can be disabled (`shortcut={false}`) — required\n * for pages that mount more than one instance. It still toggles, per the\n * source.\n */\nfunction SiteSearch({\n groups,\n onSelect,\n open: openProp,\n onOpenChange,\n defaultOpen = false,\n shortcut = true,\n label = 'Search site',\n placeholder = 'Type to search across the site...',\n emptyMessage = 'No results found.',\n trigger,\n children,\n className,\n}: SiteSearchProps) {\n const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)\n const isControlled = openProp !== undefined\n const open = isControlled ? openProp : uncontrolledOpen\n\n const inputRef = React.useRef<HTMLInputElement>(null)\n\n // Latest-value refs so the document-level shortcut listener (bound once per\n // `shortcut` value) never acts on a stale open state or stale callbacks.\n // They are written in a passive effect (not during render, per\n // react-hooks/refs) — safe because they are only read from event listeners,\n // which always fire after the commit that synced them.\n const openRef = React.useRef(open)\n const requestOpenChangeRef = React.useRef<(next: boolean) => void>(() => {})\n\n const requestOpenChange = (next: boolean) => {\n if (isControlled) {\n // Dedupe against the render-authoritative prop only — never write\n // openRef optimistically here. An optimistic write would let a parent\n // that vetoes a request (ignores it, so no re-render runs the resync\n // effect) permanently swallow every later identical request. Accepted\n // trade-off: a same-tick duplicate close (Escape reaching both the\n // Autocomplete and the Dialog) may reach `onOpenChange` twice with the\n // same value — idempotent for a setState parent, and correctness in\n // the veto case beats dedupe cosmetics.\n if (open === next) {\n return\n }\n onOpenChange?.(next)\n return\n }\n // Uncontrolled, the component owns the state, so the optimistic write is\n // safe (the commit below confirms it) and dedupes the double-report case\n // (both primitives announcing the same close) down to one callback.\n if (openRef.current === next) {\n return\n }\n openRef.current = next\n setUncontrolledOpen(next)\n onOpenChange?.(next)\n }\n\n React.useEffect(() => {\n // `open` (not `next` from an event) is authoritative here: in controlled\n // mode this effect is the ref's ONLY writer, so the shortcut listener\n // always toggles from the last value the parent actually rendered.\n openRef.current = open\n requestOpenChangeRef.current = requestOpenChange\n })\n\n React.useEffect(() => {\n if (!shortcut) {\n return undefined\n }\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.key.toLowerCase() === 'k' &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n // Toggle, per the nswds-app source: the same chord opens and closes.\n requestOpenChangeRef.current(!openRef.current)\n }\n }\n document.addEventListener('keydown', handleKeyDown)\n return () => document.removeEventListener('keydown', handleKeyDown)\n }, [shortcut])\n\n const handleSelect = (item: SiteSearchItem) => {\n // Close first, then hand over — mirrors the source's `runCommand`, so the\n // app's navigation starts from a closed palette.\n requestOpenChange(false)\n onSelect(item)\n }\n\n const filter = React.useCallback((item: SiteSearchItem, query: string) => {\n const q = query.trim().toLowerCase()\n if (q === '') {\n return true\n }\n if (item.title.toLowerCase().includes(q)) {\n return true\n }\n return (item.keywords ?? []).some((keyword) => keyword.toLowerCase().includes(q))\n }, [])\n\n const defaultTrigger = (\n <Button\n variant='ghost'\n color='grey'\n size='icon'\n aria-label={label}\n leadingVisual={IconSearch}\n />\n )\n\n return (\n <Dialog.Root open={open} onOpenChange={(next) => requestOpenChange(next)}>\n {trigger === null ? null : (\n <Dialog.Trigger data-slot='site-search-trigger' render={trigger ?? defaultTrigger} />\n )}\n\n <Dialog.Portal>\n {/* Resets a ButtonGroup's context and applies any portal scope — see PortalBoundary. */}\n <PortalBoundary>\n <Dialog.Backdrop\n data-slot='site-search-overlay'\n className='fixed inset-0 z-50 bg-black/80 duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs motion-safe:transition-opacity'\n />\n <Dialog.Popup\n data-slot='site-search-panel'\n aria-label={label}\n // The default focus target on touch is the panel itself (to keep the\n // virtual keyboard closed) — wrong for a search palette, whose whole\n // purpose is typing. Always focus the input.\n initialFocus={inputRef}\n className={cn(\n // Centred panel on the house popup surface (popover.tsx / sheet.tsx).\n 'fixed top-[max(--spacing(4),15vh)] left-1/2 z-50 w-[calc(100vw-2rem)] max-w-2xl -translate-x-1/2',\n 'rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden',\n 'duration-150 ease-out motion-safe:transition',\n 'data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0',\n className,\n )}\n >\n <Autocomplete.Root\n items={groups}\n filter={filter}\n itemToStringValue={(item: SiteSearchItem) => item.title}\n autoHighlight\n // Inline mode: the list renders statically inside the dialog panel\n // (no Autocomplete portal/positioner), with `open` pinned per the\n // Base UI docs. Opening/closing belongs to the Dialog; the whole\n // Autocomplete unmounts with it, resetting query and highlight.\n inline\n open\n onOpenChange={(nextOpen, eventDetails) => {\n // The pinned-open inline Autocomplete still *requests* closes;\n // forward the ones that should dismiss the palette. Other\n // reasons (input-clear, focus-out) must not close the dialog —\n // clearing the query or tabbing within the trap isn't dismissal.\n if (\n !nextOpen &&\n (eventDetails.reason === 'escape-key' || eventDetails.reason === 'item-press')\n ) {\n requestOpenChange(false)\n }\n }}\n >\n <div\n data-slot='site-search-input-row'\n className='flex items-center gap-3 border-b border-foreground/10 px-4'\n >\n <IconSearch aria-hidden='true' className='size-5 shrink-0 text-muted-foreground' />\n <Autocomplete.Input\n data-slot='site-search-input'\n aria-label={label}\n placeholder={placeholder}\n className='h-12 w-full bg-transparent text-base text-foreground outline-hidden placeholder:text-muted-foreground'\n ref={inputRef}\n />\n </div>\n\n {/* Base UI renders Empty's children only while the list is empty;\n the padding lives on the inner div so the (always-mounted, for\n polite announcements) outer element paints nothing otherwise. */}\n <Autocomplete.Empty data-slot='site-search-empty'>\n <div className='px-4 py-6 text-center text-sm text-muted-foreground'>\n {emptyMessage}\n </div>\n </Autocomplete.Empty>\n\n <Autocomplete.List\n data-slot='site-search-list'\n className='max-h-[min(--spacing(96),60vh)] overflow-y-auto overscroll-contain p-2 empty:hidden'\n >\n {(group: SiteSearchGroup) => (\n <Autocomplete.Group\n key={group.title}\n items={group.items}\n data-slot='site-search-group'\n >\n <Autocomplete.GroupLabel\n data-slot='site-search-group-label'\n className='px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground'\n >\n {group.title}\n </Autocomplete.GroupLabel>\n <Autocomplete.Collection>\n {(item: SiteSearchItem) => (\n <Autocomplete.Item\n key={item.href}\n value={item}\n data-slot='site-search-item'\n onClick={() => handleSelect(item)}\n // Highlight treatment mirrors menubar.tsx: keyboard and\n // hover unify as data-highlighted, painted as 10% ink.\n className='flex min-h-11 cursor-default items-center gap-2 rounded-sm px-3 py-2 text-sm text-foreground outline-hidden select-none data-highlighted:bg-primary-800/10 data-highlighted:text-accent-foreground dark:data-highlighted:bg-primary-200/10'\n >\n {item.title}\n </Autocomplete.Item>\n )}\n </Autocomplete.Collection>\n </Autocomplete.Group>\n )}\n </Autocomplete.List>\n </Autocomplete.Root>\n\n {children != null ? (\n <div\n data-slot='site-search-footer'\n className='border-t border-foreground/10 px-4 py-2 text-xs text-muted-foreground'\n >\n {children}\n </div>\n ) : null}\n </Dialog.Popup>\n </PortalBoundary>\n </Dialog.Portal>\n </Dialog.Root>\n )\n}\n\nexport { SiteSearch }\nexport type { SiteSearchGroup, SiteSearchItem, SiteSearchProps }\n"]}
|
|
@@ -5,12 +5,22 @@ import { cva } from 'class-variance-authority';
|
|
|
5
5
|
import { cn } from '../lib/utils.js';
|
|
6
6
|
|
|
7
7
|
const toggleVariants = cva(
|
|
8
|
-
|
|
8
|
+
[
|
|
9
|
+
"group/toggle inline-flex items-center justify-center gap-1 rounded-sm text-xs font-medium whitespace-nowrap transition-all outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
10
|
+
// Pressed is the interactive fill with its foreground, as a selected
|
|
11
|
+
// segment. It was a `bg-muted` tint, 1.09:1 against the page in light and
|
|
12
|
+
// 1.00:1 in dark — pressed and not pressed looked the same (#255,
|
|
13
|
+
// WCAG 1.4.11). Base UI marks the state with aria-pressed (and
|
|
14
|
+
// data-pressed); the old `data-[state=on]` was Radix's and never matched.
|
|
15
|
+
"aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground"
|
|
16
|
+
],
|
|
9
17
|
{
|
|
10
18
|
variants: {
|
|
11
19
|
variant: {
|
|
12
20
|
default: "bg-transparent",
|
|
13
|
-
|
|
21
|
+
// The field family's border token (Input, Select), which clears 3:1
|
|
22
|
+
// against the page in both modes; `border-input` was 1.34:1 / 1.67:1.
|
|
23
|
+
outline: "border border-(--input-border) bg-transparent hover:bg-muted"
|
|
14
24
|
},
|
|
15
25
|
size: {
|
|
16
26
|
default: "h-7 min-w-7 px-2 has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/toggle.tsx"],"names":["TogglePrimitive"],"mappings":";;;;;AAOA,MAAM,cAAA,GAAiB,GAAA;AAAA,EACrB,
|
|
1
|
+
{"version":3,"sources":["../../src/components/toggle.tsx"],"names":["TogglePrimitive"],"mappings":";;;;;AAOA,MAAM,cAAA,GAAiB,GAAA;AAAA,EACrB;AAAA,IACE,seAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA;AAAA,GACF;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,OAAA,EAAS;AAAA,QACP,OAAA,EAAS,gBAAA;AAAA;AAAA;AAAA,QAGT,OAAA,EAAS;AAAA,OACX;AAAA,MACA,IAAA,EAAM;AAAA,QACJ,OAAA,EACE,wFAAA;AAAA,QACF,EAAA,EAAI,wJAAA;AAAA,QACJ,EAAA,EAAI;AAAA;AACN,KACF;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM;AAAA;AACR;AAEJ;AAEA,SAAS,MAAA,CAAO;AAAA,EACd,SAAA;AAAA,EACA,OAAA,GAAU,SAAA;AAAA,EACV,IAAA,GAAO,SAAA;AAAA,EACP,GAAG;AACL,CAAA,EAAgE;AAC9D,EAAA,uBACE,GAAA;AAAA,IAACA,QAAA;AAAA,IAAA;AAAA,MACC,WAAA,EAAU,QAAA;AAAA,MACV,SAAA,EAAW,GAAG,cAAA,CAAe,EAAE,SAAS,IAAA,EAAM,SAAA,EAAW,CAAC,CAAA;AAAA,MACzD,GAAG;AAAA;AAAA,GACN;AAEJ","file":"toggle.js","sourcesContent":["'use client'\n\nimport { Toggle as TogglePrimitive } from '@base-ui/react/toggle'\nimport { cva, type VariantProps } from 'class-variance-authority'\n\nimport { cn } from '../lib/utils.js'\n\nconst toggleVariants = cva(\n [\n \"group/toggle inline-flex items-center justify-center gap-1 rounded-sm text-xs font-medium whitespace-nowrap transition-all outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n // Pressed is the interactive fill with its foreground, as a selected\n // segment. It was a `bg-muted` tint, 1.09:1 against the page in light and\n // 1.00:1 in dark — pressed and not pressed looked the same (#255,\n // WCAG 1.4.11). Base UI marks the state with aria-pressed (and\n // data-pressed); the old `data-[state=on]` was Radix's and never matched.\n 'aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground',\n ],\n {\n variants: {\n variant: {\n default: 'bg-transparent',\n // The field family's border token (Input, Select), which clears 3:1\n // against the page in both modes; `border-input` was 1.34:1 / 1.67:1.\n outline: 'border border-(--input-border) bg-transparent hover:bg-muted',\n },\n size: {\n default:\n 'h-7 min-w-7 px-2 has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5',\n sm: \"h-6 min-w-6 rounded-sm px-2 text-[0.625rem] has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3\",\n lg: 'h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2',\n },\n },\n defaultVariants: {\n variant: 'default',\n size: 'default',\n },\n },\n)\n\nfunction Toggle({\n className,\n variant = 'default',\n size = 'default',\n ...props\n}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {\n return (\n <TogglePrimitive\n data-slot='toggle'\n className={cn(toggleVariants({ variant, size, className }))}\n {...props}\n />\n )\n}\n\nexport { Toggle, toggleVariants }\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
|
|
4
|
-
import {
|
|
4
|
+
import { PortalBoundary } from '../lib/portal-boundary.js';
|
|
5
5
|
import { cn } from '../lib/utils.js';
|
|
6
6
|
|
|
7
7
|
function TooltipProvider({ delay = 0, ...props }) {
|
|
@@ -22,7 +22,7 @@ function TooltipContent({
|
|
|
22
22
|
children,
|
|
23
23
|
...props
|
|
24
24
|
}) {
|
|
25
|
-
return /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(
|
|
25
|
+
return /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(PortalBoundary, { children: /* @__PURE__ */ jsx(
|
|
26
26
|
Tooltip$1.Positioner,
|
|
27
27
|
{
|
|
28
28
|
align,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/tooltip.tsx"],"names":["TooltipPrimitive"],"mappings":";;;;;AAOA,SAAS,gBAAgB,EAAE,KAAA,GAAQ,CAAA,EAAG,GAAG,OAAM,EAAoC;AACjF,EAAA,uBAAO,GAAA,CAACA,UAAiB,QAAA,EAAjB,EAA0B,aAAU,kBAAA,EAAmB,KAAA,EAAe,GAAG,KAAA,EAAO,CAAA;AAC1F;AAEA,SAAS,OAAA,CAAQ,EAAE,GAAG,KAAA,EAAM,EAAgC;AAC1D,EAAA,2BAAQA,SAAA,CAAiB,IAAA,EA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AAA,GAAQ,QAAA;AAAA,EACR,WAAA,GAAc,CAAA;AAAA,EACd,QAAA;AAAA,EACA,GAAG;AACL,CAAA,EAC4F;AAC1F,EAAA,uBACE,GAAA,CAACA,SAAA,CAAiB,MAAA,EAAjB,EAEC,8BAAC,cAAA,EAAA,EACC,QAAA,kBAAA,GAAA;AAAA,IAACA,SAAA,CAAiB,UAAA;AAAA,IAAjB;AAAA,MACC,KAAA;AAAA,MACA,WAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAA;AAAA,MACA,SAAA,EAAU,cAAA;AAAA,MAEV,QAAA,kBAAA,IAAA;AAAA,QAACA,SAAA,CAAiB,KAAA;AAAA,QAAjB;AAAA,UACC,WAAA,EAAU,iBAAA;AAAA,UACV,SAAA,EAAW,EAAA;AAAA,YACT,gwBAAA;AAAA,YACA;AAAA,WACF;AAAA,UACC,GAAG,KAAA;AAAA,UAEH,QAAA,EAAA;AAAA,YAAA,QAAA;AAAA,4BACD,GAAA,CAACA,SAAA,CAAiB,KAAA,EAAjB,EAAuB,WAAU,yhBAAA,EAA0hB;AAAA;AAAA;AAAA;AAC9jB;AAAA,KAEJ,CAAA,EACF,CAAA;AAEJ","file":"tooltip.js","sourcesContent":["'use client'\n\nimport { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip'\n\nimport { PortalBoundary } from '../lib/portal-boundary.js'\nimport { cn } from '../lib/utils.js'\n\nfunction TooltipProvider({ delay = 0, ...props }: TooltipPrimitive.Provider.Props) {\n return <TooltipPrimitive.Provider data-slot='tooltip-provider' delay={delay} {...props} />\n}\n\nfunction Tooltip({ ...props }: TooltipPrimitive.Root.Props) {\n return <TooltipPrimitive.Root data-slot='tooltip' {...props} />\n}\n\nfunction TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {\n return <TooltipPrimitive.Trigger data-slot='tooltip-trigger' {...props} />\n}\n\nfunction TooltipContent({\n className,\n side = 'top',\n sideOffset = 4,\n align = 'center',\n alignOffset = 0,\n children,\n ...props\n}: TooltipPrimitive.Popup.Props &\n Pick<TooltipPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {\n return (\n <TooltipPrimitive.Portal>\n {/* Resets a ButtonGroup's context and applies any portal scope — see PortalBoundary. */}\n <PortalBoundary>\n <TooltipPrimitive.Positioner\n align={align}\n alignOffset={alignOffset}\n side={side}\n sideOffset={sideOffset}\n className='isolate z-50'\n >\n <TooltipPrimitive.Popup\n data-slot='tooltip-content'\n className={cn(\n 'z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-sm bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pe-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-start-2 data-[side=inline-start]:slide-in-from-end-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',\n className,\n )}\n {...props}\n >\n {children}\n <TooltipPrimitive.Arrow className='z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:-start-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:-end-1 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5' />\n </TooltipPrimitive.Popup>\n </TooltipPrimitive.Positioner>\n </PortalBoundary>\n </TooltipPrimitive.Portal>\n )\n}\n\nexport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export { ToggleGroup, ToggleGroupItem } from './components/toggle-group.js';
|
|
|
71
71
|
export { Toggle, toggleVariants } from './components/toggle.js';
|
|
72
72
|
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './components/tooltip.js';
|
|
73
73
|
export { UseChromeHeightOptions, UseChromeHeightResult, useChromeHeight } from './hooks/use-chrome-height.js';
|
|
74
|
+
export { PortalBoundary, PortalScope, PortalScopeContext } from './lib/portal-boundary.js';
|
|
74
75
|
export { cn } from './lib/utils.js';
|
|
75
76
|
export { ButtonGroupBoundary } from './lib/button-group-context.js';
|
|
76
77
|
export { PreviewPalette as ComponentPreviewPalette } from './lib/preview-theme.js';
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,7 @@ export * from './components/toggle-group.js';
|
|
|
71
71
|
export * from './components/toggle.js';
|
|
72
72
|
export * from './components/tooltip.js';
|
|
73
73
|
export * from './hooks/use-chrome-height.js';
|
|
74
|
+
export * from './lib/portal-boundary.js';
|
|
74
75
|
export * from './lib/utils.js';
|
|
75
76
|
//# sourceMappingURL=index.js.map
|
|
76
77
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a region of the page hands the popups opened from inside it, so they
|
|
5
|
+
* look as though they were still inside it: a class, a text direction,
|
|
6
|
+
* attributes and custom properties for an element wrapped around the popup's
|
|
7
|
+
* portalled contents.
|
|
8
|
+
*
|
|
9
|
+
* A popup portals to the end of the page, so nothing set on an ancestor of its
|
|
10
|
+
* trigger reaches it through the DOM: not a custom property, not the `dark`
|
|
11
|
+
* class, not `dir`. React context does cross a portal, and every popup in this
|
|
12
|
+
* package passes through `PortalBoundary` there, which is where a scope is
|
|
13
|
+
* applied. ComponentPreview's stage provides one: its colour scheme, its
|
|
14
|
+
* tokens and its direction. `null` everywhere else, which leaves a portal's
|
|
15
|
+
* contents exactly as they were.
|
|
16
|
+
*/
|
|
17
|
+
type PortalScope = {
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
dir?: 'ltr' | 'rtl';
|
|
21
|
+
/** `data-*` attributes for the wrapping element. */
|
|
22
|
+
attributes?: Record<`data-${string}`, string | undefined>;
|
|
23
|
+
};
|
|
24
|
+
declare const PortalScopeContext: React.Context<PortalScope | null>;
|
|
25
|
+
/**
|
|
26
|
+
* The one child of every portal in this package. It does the two things a
|
|
27
|
+
* portal needs because React context crosses it and the DOM does not:
|
|
28
|
+
*
|
|
29
|
+
* - resets a ButtonGroup's context, so a Button inside the popup does not
|
|
30
|
+
* render as a segment of the group the popup was opened from (see
|
|
31
|
+
* `ButtonGroupBoundary`, which does only this);
|
|
32
|
+
* - applies the `PortalScope` the popup was opened in, if there is one, by
|
|
33
|
+
* wrapping the contents in one element that carries it.
|
|
34
|
+
*
|
|
35
|
+
* That element is `display: contents`, so it generates no box: the popup is
|
|
36
|
+
* positioned and stacked as before, and only inheritance and ancestor
|
|
37
|
+
* selectors see it. Outside a scope there is no element at all.
|
|
38
|
+
*
|
|
39
|
+
* Wrap the portalled contents of an overlay from another library in this to
|
|
40
|
+
* get both. `check:portal-boundary` requires it of every portal here.
|
|
41
|
+
*/
|
|
42
|
+
declare function PortalBoundary({ children }: {
|
|
43
|
+
children: React.ReactNode;
|
|
44
|
+
}): React.JSX.Element;
|
|
45
|
+
|
|
46
|
+
export { PortalBoundary, PortalScopeContext };
|
|
47
|
+
export type { PortalScope };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { ButtonGroupBoundary } from './button-group-context.js';
|
|
5
|
+
|
|
6
|
+
const PortalScopeContext = React.createContext(null);
|
|
7
|
+
function PortalBoundary({ children }) {
|
|
8
|
+
const scope = React.useContext(PortalScopeContext);
|
|
9
|
+
return /* @__PURE__ */ jsx(ButtonGroupBoundary, { children: scope ? /* @__PURE__ */ jsx(
|
|
10
|
+
"div",
|
|
11
|
+
{
|
|
12
|
+
...scope.attributes,
|
|
13
|
+
"data-slot": "portal-scope",
|
|
14
|
+
dir: scope.dir,
|
|
15
|
+
className: scope.className ? `contents ${scope.className}` : "contents",
|
|
16
|
+
style: scope.style,
|
|
17
|
+
children
|
|
18
|
+
}
|
|
19
|
+
) : children });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { PortalBoundary, PortalScopeContext };
|
|
23
|
+
//# sourceMappingURL=portal-boundary.js.map
|
|
24
|
+
//# sourceMappingURL=portal-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/portal-boundary.tsx"],"names":[],"mappings":";;;;AA4BA,MAAM,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAAkC,IAAI;AAmBvE,SAAS,cAAA,CAAe,EAAE,QAAA,EAAS,EAAkC;AACnE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,UAAA,CAAW,kBAAkB,CAAA;AAEjD,EAAA,uBACE,GAAA,CAAC,uBACE,QAAA,EAAA,KAAA,mBACC,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACE,GAAG,KAAA,CAAM,UAAA;AAAA,MACV,WAAA,EAAU,cAAA;AAAA,MACV,KAAK,KAAA,CAAM,GAAA;AAAA,MACX,WAAW,KAAA,CAAM,SAAA,GAAY,CAAA,SAAA,EAAY,KAAA,CAAM,SAAS,CAAA,CAAA,GAAK,UAAA;AAAA,MAC7D,OAAO,KAAA,CAAM,KAAA;AAAA,MAEZ;AAAA;AAAA,MAGH,QAAA,EAEJ,CAAA;AAEJ","file":"portal-boundary.js","sourcesContent":["'use client'\n\nimport * as React from 'react'\n\nimport { ButtonGroupBoundary } from './button-group-context.js'\n\n/**\n * What a region of the page hands the popups opened from inside it, so they\n * look as though they were still inside it: a class, a text direction,\n * attributes and custom properties for an element wrapped around the popup's\n * portalled contents.\n *\n * A popup portals to the end of the page, so nothing set on an ancestor of its\n * trigger reaches it through the DOM: not a custom property, not the `dark`\n * class, not `dir`. React context does cross a portal, and every popup in this\n * package passes through `PortalBoundary` there, which is where a scope is\n * applied. ComponentPreview's stage provides one: its colour scheme, its\n * tokens and its direction. `null` everywhere else, which leaves a portal's\n * contents exactly as they were.\n */\ntype PortalScope = {\n className?: string\n style?: React.CSSProperties\n dir?: 'ltr' | 'rtl'\n /** `data-*` attributes for the wrapping element. */\n attributes?: Record<`data-${string}`, string | undefined>\n}\n\nconst PortalScopeContext = React.createContext<PortalScope | null>(null)\n\n/**\n * The one child of every portal in this package. It does the two things a\n * portal needs because React context crosses it and the DOM does not:\n *\n * - resets a ButtonGroup's context, so a Button inside the popup does not\n * render as a segment of the group the popup was opened from (see\n * `ButtonGroupBoundary`, which does only this);\n * - applies the `PortalScope` the popup was opened in, if there is one, by\n * wrapping the contents in one element that carries it.\n *\n * That element is `display: contents`, so it generates no box: the popup is\n * positioned and stacked as before, and only inheritance and ancestor\n * selectors see it. Outside a scope there is no element at all.\n *\n * Wrap the portalled contents of an overlay from another library in this to\n * get both. `check:portal-boundary` requires it of every portal here.\n */\nfunction PortalBoundary({ children }: { children: React.ReactNode }) {\n const scope = React.useContext(PortalScopeContext)\n\n return (\n <ButtonGroupBoundary>\n {scope ? (\n <div\n {...scope.attributes}\n data-slot='portal-scope'\n dir={scope.dir}\n className={scope.className ? `contents ${scope.className}` : 'contents'}\n style={scope.style}\n >\n {children}\n </div>\n ) : (\n children\n )}\n </ButtonGroupBoundary>\n )\n}\n\nexport { PortalBoundary, PortalScopeContext }\nexport type { PortalScope }\n"]}
|