@mistriwork/ui 1.0.0-rc.22 → 1.0.0-rc.25

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/Popover.d.ts CHANGED
@@ -6,6 +6,11 @@
6
6
  * `open`/`onOpenChange`, uncontrolled with `defaultOpen`. Where the
7
7
  * popup is a menu of actions, DropMenu is the right primitive instead:
8
8
  * a popover is a layer, not a list of commands.
9
+ *
10
+ * Placed as DropMenu places its menu: anchored on the zoom-aware ruler
11
+ * (anchor.ts) and fixed to the viewport, and drawn inside an enclosing
12
+ * dialog, so the density zoom cannot throw it a room away from its trigger
13
+ * and a dialog's focus trap keeps it as its own.
9
14
  */
10
15
  import { type ReactNode } from 'react';
11
16
  export interface PopoverProps {
package/dist/Popover.js CHANGED
@@ -7,14 +7,23 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
7
  * `open`/`onOpenChange`, uncontrolled with `defaultOpen`. Where the
8
8
  * popup is a menu of actions, DropMenu is the right primitive instead:
9
9
  * a popover is a layer, not a list of commands.
10
+ *
11
+ * Placed as DropMenu places its menu: anchored on the zoom-aware ruler
12
+ * (anchor.ts) and fixed to the viewport, and drawn inside an enclosing
13
+ * dialog, so the density zoom cannot throw it a room away from its trigger
14
+ * and a dialog's focus trap keeps it as its own.
10
15
  */
11
- import { isValidElement } from 'react';
16
+ import { isValidElement, useRef } from 'react';
12
17
  import { Popover as BasePopover } from '@base-ui/react/popover';
18
+ import { layoutViewport, zoomAnchor } from './internal/anchor.js';
19
+ import { popupContainer, useDialogContainer } from './internal/popups.js';
13
20
  export function Popover({ trigger, children, open, defaultOpen, onOpenChange, className, ariaLabel }) {
14
21
  /* The trigger is rendered as the trigger, not inside one: a button
15
22
  passed as a child nested inside Base UI's own button, giving two
16
23
  buttons for one control. The render prop merges onto the caller's
17
24
  element (DropMenu.tsx does the same for its trigger). */
18
25
  const triggerElement = isValidElement(trigger) ? trigger : _jsx("button", { type: "button", children: trigger });
19
- return (_jsxs(BasePopover.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: [_jsx(BasePopover.Trigger, { className: "ui-popover-trigger", render: triggerElement }), _jsx(BasePopover.Portal, { children: _jsx(BasePopover.Positioner, { sideOffset: 8, children: _jsx(BasePopover.Popup, { className: ['ui-popover', className].filter(Boolean).join(' '), "aria-label": ariaLabel, children: children }) }) })] }));
26
+ const anchor = useRef(null);
27
+ const container = useDialogContainer(anchor);
28
+ return (_jsxs(BasePopover.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: [_jsx(BasePopover.Trigger, { className: "ui-popover-trigger", render: triggerElement, ref: anchor }), _jsx(BasePopover.Portal, { container: container ?? popupContainer(), children: _jsx(BasePopover.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BasePopover.Popup, { className: ['ui-popover', className].filter(Boolean).join(' '), "aria-label": ariaLabel, children: children }) }) })] }));
20
29
  }
package/dist/Tooltip.d.ts CHANGED
@@ -14,6 +14,9 @@
14
14
  * never hovers must still understand the trigger from its own label, and
15
15
  * a note that carries an action belongs in a Popover instead, where it
16
16
  * can be reached and used.
17
+ *
18
+ * Placed as Popover.tsx places its layer: on the zoom-aware ruler, fixed to
19
+ * the viewport, and inside an enclosing dialog.
17
20
  */
18
21
  import { type ReactNode } from 'react';
19
22
  export interface TooltipProps {
package/dist/Tooltip.js CHANGED
@@ -15,9 +15,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
15
  * never hovers must still understand the trigger from its own label, and
16
16
  * a note that carries an action belongs in a Popover instead, where it
17
17
  * can be reached and used.
18
+ *
19
+ * Placed as Popover.tsx places its layer: on the zoom-aware ruler, fixed to
20
+ * the viewport, and inside an enclosing dialog.
18
21
  */
19
- import { cloneElement, isValidElement, useId, useState } from 'react';
22
+ import { cloneElement, isValidElement, useId, useRef, useState } from 'react';
20
23
  import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
24
+ import { layoutViewport, zoomAnchor } from './internal/anchor.js';
25
+ import { popupContainer, useDialogContainer } from './internal/popups.js';
21
26
  export function Tooltip({ trigger, children, open, defaultOpen, onOpenChange, className }) {
22
27
  const tooltipId = useId();
23
28
  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);
@@ -30,10 +35,12 @@ export function Tooltip({ trigger, children, open, defaultOpen, onOpenChange, cl
30
35
  const triggerElement = isOpen
31
36
  ? cloneElement(base, { 'aria-describedby': [existing, tooltipId].filter(Boolean).join(' ') })
32
37
  : base;
38
+ const anchor = useRef(null);
39
+ const container = useDialogContainer(anchor);
33
40
  return (_jsxs(BaseTooltip.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: (next, details) => {
34
41
  if (open === undefined)
35
42
  setUncontrolledOpen(next);
36
43
  onOpenChange?.(next);
37
44
  void details;
38
- }, children: [_jsx(BaseTooltip.Trigger, { className: "ui-tooltip-trigger", render: triggerElement }), _jsx(BaseTooltip.Portal, { children: _jsx(BaseTooltip.Positioner, { sideOffset: 8, children: _jsx(BaseTooltip.Popup, { id: tooltipId, role: "tooltip", className: ['ui-tooltip', className].filter(Boolean).join(' '), children: children }) }) })] }));
45
+ }, children: [_jsx(BaseTooltip.Trigger, { className: "ui-tooltip-trigger", render: triggerElement, ref: anchor }), _jsx(BaseTooltip.Portal, { container: container ?? popupContainer(), children: _jsx(BaseTooltip.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BaseTooltip.Popup, { id: tooltipId, role: "tooltip", className: ['ui-tooltip', className].filter(Boolean).join(' '), children: children }) }) })] }));
39
46
  }
@@ -11,3 +11,11 @@
11
11
  export declare const popupContainer: () => HTMLElement | undefined;
12
12
  /** Draw every popup in this container from now on. */
13
13
  export declare function drawPopupsIn(where: () => HTMLElement | undefined): void;
14
+ /**
15
+ * The dialog a trigger stands in, read once it is mounted: a layer opened
16
+ * there is drawn inside it, so it shares the dialog's stacking context and
17
+ * focus trap rather than landing behind it on the body.
18
+ */
19
+ export declare function useDialogContainer(trigger: {
20
+ current: Element | null;
21
+ }): HTMLElement | null;
@@ -7,6 +7,7 @@
7
7
  * names its own container with `drawPopupsIn`
8
8
  * (packages/mistri/src/embed/seams/shellHost.ts).
9
9
  */
10
+ import { useEffect, useState } from 'react';
10
11
  let container = () => undefined;
11
12
  /** The container handed to Base UI's portals. */
12
13
  export const popupContainer = () => container();
@@ -14,3 +15,15 @@ export const popupContainer = () => container();
14
15
  export function drawPopupsIn(where) {
15
16
  container = where;
16
17
  }
18
+ /**
19
+ * The dialog a trigger stands in, read once it is mounted: a layer opened
20
+ * there is drawn inside it, so it shares the dialog's stacking context and
21
+ * focus trap rather than landing behind it on the body.
22
+ */
23
+ export function useDialogContainer(trigger) {
24
+ const [dialog, setDialog] = useState(null);
25
+ useEffect(() => {
26
+ setDialog(trigger.current?.closest('dialog, [role="dialog"]'));
27
+ }, [trigger]);
28
+ return dialog;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/ui",
3
- "version": "1.0.0-rc.22",
3
+ "version": "1.0.0-rc.25",
4
4
  "description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over Base UI, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {