@cognitap/radiant 0.0.15 → 0.0.17
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/CHANGELOG.md +9 -1
- package/dist/library/Menu.d.ts +22 -0
- package/dist/library/Menu.d.ts.map +1 -0
- package/dist/library/Menu.js +144 -0
- package/dist/library/Menu.js.map +1 -0
- package/dist/library/Popover.d.ts +1 -0
- package/dist/library/Popover.d.ts.map +1 -1
- package/dist/library/Popover.js +1 -1
- package/dist/library/Popover.js.map +1 -1
- package/dist/library/Tooltip.d.ts +40 -0
- package/dist/library/Tooltip.d.ts.map +1 -0
- package/dist/library/Tooltip.js +182 -0
- package/dist/library/Tooltip.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +16 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +4 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/react/usePopoverSurface.d.ts +1 -1
- package/dist/library/react/usePopoverSurface.d.ts.map +1 -1
- package/dist/library/react/usePopoverSurface.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +28 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +28 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +4 -4
- package/docs/theming.md +1 -1
- package/package.json +1 -1
- package/src/Menu.tsx +248 -0
- package/src/Popover.tsx +2 -1
- package/src/Tooltip.tsx +287 -0
- package/src/cn.ts +16 -0
- package/src/index.ts +20 -0
- package/src/react/usePopoverSurface.ts +2 -2
- package/src/themes/components.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.0.17
|
|
8
|
+
|
|
9
|
+
- Add Menu.
|
|
10
|
+
|
|
11
|
+
## 0.0.16
|
|
12
|
+
|
|
13
|
+
- Add Tooltip.
|
|
14
|
+
|
|
7
15
|
## 0.0.15
|
|
8
16
|
|
|
9
17
|
- Add Popover.
|
|
@@ -34,7 +42,7 @@
|
|
|
34
42
|
|
|
35
43
|
## 0.0.8
|
|
36
44
|
|
|
37
|
-
- Add Select with item focus, Field/
|
|
45
|
+
- Add Select with item focus, Field/forms, themes, springs and stable trigger-width alignment.
|
|
38
46
|
|
|
39
47
|
## 0.0.7
|
|
40
48
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type MouseEvent, type ReactNode } from 'react';
|
|
2
|
+
import { type PopoverProps, type PopoverState, type PopoverContentProps } from './Popover.js';
|
|
3
|
+
import type { ButtonProps, ButtonRenderProps } from './Button.js';
|
|
4
|
+
export type MenuProps = PopoverProps;
|
|
5
|
+
export type MenuState = PopoverState;
|
|
6
|
+
export type MenuRenderProps = ButtonRenderProps;
|
|
7
|
+
export type MenuPortalProps = {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export type MenuTriggerProps = Omit<ButtonProps, 'id' | 'aria-haspopup'>;
|
|
11
|
+
export type MenuContentProps = Omit<PopoverContentProps, 'role' | 'aria-labelledby' | 'aria-orientation' | 'tabIndex' | 'initialFocusRef'>;
|
|
12
|
+
export type MenuItemProps = Omit<ButtonProps, 'role' | 'tabIndex' | 'aria-disabled' | 'onSelect'> & {
|
|
13
|
+
textValue?: string;
|
|
14
|
+
onSelect?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
15
|
+
};
|
|
16
|
+
export declare function useMenu(): MenuState | null;
|
|
17
|
+
export declare function Menu({ children, ...props }: MenuProps): import("react").JSX.Element;
|
|
18
|
+
export declare function MenuTrigger({ ref, onKeyDown, onClick, ...props }: MenuTriggerProps): import("react").JSX.Element;
|
|
19
|
+
export declare function MenuPortal(props: MenuPortalProps): import("react").JSX.Element;
|
|
20
|
+
export declare function MenuContent({ ref, className, onKeyDown, ...props }: MenuContentProps): import("react").JSX.Element;
|
|
21
|
+
export declare function MenuItem({ disabled, textValue, onSelect, onClick, onFocus, onPointerMove, className, motion, ...props }: MenuItemProps): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=Menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../src/Menu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,OAAO,CAAA;AACd,OAAO,EAOL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAOjE,MAAM,MAAM,SAAS,GAAG,YAAY,CAAA;AACpC,MAAM,MAAM,SAAS,GAAG,YAAY,CAAA;AACpC,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAC/C,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAA;AACtD,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,eAAe,CAAC,CAAA;AACxE,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,mBAAmB,EACnB,MAAM,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,UAAU,GAAG,iBAAiB,CACjF,CAAA;AACD,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,WAAW,EACX,MAAM,GAAG,UAAU,GAAG,eAAe,GAAG,UAAU,CACnD,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;CAC1D,CAAA;AASD,wBAAgB,OAAO,IAAI,SAAS,GAAG,IAAI,CAE1C;AAMD,wBAAgB,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,+BAMrD;AAiCD,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,+BAiClF;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAGhD;AACD,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,+BAmEpF;AACD,wBAAgB,QAAQ,CAAC,EACvB,QAAgB,EAChB,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,aAAa,EACb,SAAS,EACT,MAAM,EACN,GAAG,KAAK,EACT,EAAE,aAAa,+BA8Bf"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useId, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import { Popover, PopoverTrigger, PopoverContent, PopoverClose, PopoverPortal, usePopover } from './Popover.js';
|
|
5
|
+
import { cn } from './cn.js';
|
|
6
|
+
import { composeAction } from './internal/events.js';
|
|
7
|
+
import { joinIds } from './internal/ids.js';
|
|
8
|
+
import { matchSelectText } from './internal/select.js';
|
|
9
|
+
import { useComposedRefs } from './react/useComposedRefs.js';
|
|
10
|
+
const MenuContext = createContext(null);
|
|
11
|
+
export function useMenu() {
|
|
12
|
+
return useContext(MenuContext);
|
|
13
|
+
}
|
|
14
|
+
function useMenuContext() {
|
|
15
|
+
const menu = useContext(MenuContext);
|
|
16
|
+
if (!menu)
|
|
17
|
+
throw new Error('Menu parts must render inside Menu.');
|
|
18
|
+
return menu;
|
|
19
|
+
}
|
|
20
|
+
export function Menu({ children, ...props }) {
|
|
21
|
+
return (_jsx(Popover, { ...props, children: _jsx(MenuOwner, { children: children }) }));
|
|
22
|
+
}
|
|
23
|
+
function MenuOwner({ children }) {
|
|
24
|
+
const state = usePopover();
|
|
25
|
+
const triggerId = useId();
|
|
26
|
+
const trigger = useRef(null);
|
|
27
|
+
const content = useRef(null);
|
|
28
|
+
const intent = useRef('first');
|
|
29
|
+
return (_jsx(MenuContext.Provider, { value: {
|
|
30
|
+
...state,
|
|
31
|
+
triggerId,
|
|
32
|
+
trigger,
|
|
33
|
+
content,
|
|
34
|
+
intent,
|
|
35
|
+
setIntent: edge => {
|
|
36
|
+
intent.current = edge;
|
|
37
|
+
}
|
|
38
|
+
}, children: children }));
|
|
39
|
+
}
|
|
40
|
+
function items(node) {
|
|
41
|
+
return Array.from(node.querySelectorAll('button[role="menuitem"]')).filter(item => item.closest('[role="menu"]') === node);
|
|
42
|
+
}
|
|
43
|
+
function focusItem(node, item) {
|
|
44
|
+
for (const candidate of items(node))
|
|
45
|
+
candidate.tabIndex = candidate === item ? 0 : -1;
|
|
46
|
+
(item ?? node).focus({ preventScroll: true });
|
|
47
|
+
}
|
|
48
|
+
export function MenuTrigger({ ref, onKeyDown, onClick, ...props }) {
|
|
49
|
+
const menu = useMenuContext();
|
|
50
|
+
const host = useComposedRefs(menu.trigger, ref);
|
|
51
|
+
return (_jsx(PopoverTrigger, { ...props, ref: host, id: menu.triggerId, "aria-haspopup": "menu", "data-slot": joinIds('menu-trigger', props['data-slot']), onClick: composeAction(onClick, () => {
|
|
52
|
+
menu.setIntent('first');
|
|
53
|
+
}), onKeyDown: composeAction(onKeyDown, event => {
|
|
54
|
+
if ((event.key !== 'ArrowDown' && event.key !== 'ArrowUp') ||
|
|
55
|
+
props.disabled ||
|
|
56
|
+
props.pending ||
|
|
57
|
+
event.currentTarget.matches(':disabled'))
|
|
58
|
+
return;
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
menu.setIntent(event.key === 'ArrowUp' ? 'last' : 'first');
|
|
61
|
+
if (menu.open && menu.content.current) {
|
|
62
|
+
const options = items(menu.content.current);
|
|
63
|
+
focusItem(menu.content.current, menu.intent.current === 'last' ? options.at(-1) : options[0]);
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
menu.setOpen(true);
|
|
67
|
+
}) }));
|
|
68
|
+
}
|
|
69
|
+
export function MenuPortal(props) {
|
|
70
|
+
useMenuContext();
|
|
71
|
+
return _jsx(PopoverPortal, { ...props });
|
|
72
|
+
}
|
|
73
|
+
export function MenuContent({ ref, className, onKeyDown, ...props }) {
|
|
74
|
+
const menu = useMenuContext();
|
|
75
|
+
const host = useComposedRefs(menu.content, ref);
|
|
76
|
+
const search = useRef({ text: '', time: 0 });
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
search.current = { text: '', time: 0 };
|
|
79
|
+
const node = menu.content.current;
|
|
80
|
+
if (!menu.open || !node)
|
|
81
|
+
return;
|
|
82
|
+
const options = items(node);
|
|
83
|
+
focusItem(node, menu.intent.current === 'last' ? options.at(-1) : options[0]);
|
|
84
|
+
}, [menu.open, menu.content, menu.intent]);
|
|
85
|
+
return (_jsx(PopoverContent, { ...props, ref: host, role: "menu", "aria-orientation": "vertical", "aria-labelledby": menu.triggerId, tabIndex: -1, "data-slot": joinIds('menu-content', props['data-slot']), className: cn('w-[var(--rad-menu-width,16rem)] gap-0 p-[var(--rad-menu-padding,0.25rem)] rounded-[var(--rad-menu-radius,var(--rad-surface-radius,0.75rem))]', 'bg-[var(--rad-menu-background,var(--rad-color-surface,white))] [color:var(--rad-menu-color,var(--rad-color-foreground))] [border-color:var(--rad-menu-border-color,var(--rad-color-border))] [border-width:var(--rad-menu-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-menu-border-style,var(--rad-surface-border-style,solid))] [box-shadow:var(--rad-menu-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]', 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]', className), onKeyDown: event => {
|
|
86
|
+
onKeyDown?.(event);
|
|
87
|
+
if (event.defaultPrevented)
|
|
88
|
+
return;
|
|
89
|
+
const node = event.currentTarget;
|
|
90
|
+
const target = event.target;
|
|
91
|
+
if (target.closest('[role="menu"]') !== node)
|
|
92
|
+
return;
|
|
93
|
+
if (event.key === 'Tab') {
|
|
94
|
+
// Let the browser continue from the opener after closing, in either direction.
|
|
95
|
+
menu.trigger.current?.focus({ preventScroll: true });
|
|
96
|
+
menu.setOpen(false);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.nativeEvent.isComposing)
|
|
100
|
+
return;
|
|
101
|
+
const options = items(node);
|
|
102
|
+
const index = options.indexOf(node.ownerDocument.activeElement);
|
|
103
|
+
let next;
|
|
104
|
+
if (event.key === 'Home')
|
|
105
|
+
next = options[0];
|
|
106
|
+
else if (event.key === 'End')
|
|
107
|
+
next = options.at(-1);
|
|
108
|
+
else if (event.key === 'ArrowDown')
|
|
109
|
+
next = options[(index + 1) % options.length];
|
|
110
|
+
else if (event.key === 'ArrowUp')
|
|
111
|
+
next = options[(index - 1 + options.length) % options.length];
|
|
112
|
+
else if (event.key.length === 1 && event.key !== ' ') {
|
|
113
|
+
const now = node.ownerDocument.defaultView.performance.now();
|
|
114
|
+
search.current.text =
|
|
115
|
+
(now - search.current.time > 700 ? '' : search.current.text) + event.key;
|
|
116
|
+
search.current.time = now;
|
|
117
|
+
const match = matchSelectText(options.map((item, i) => ({
|
|
118
|
+
value: String(i),
|
|
119
|
+
textValue: item.dataset.textValue ?? item.textContent ?? ''
|
|
120
|
+
})), search.current.text, String(index));
|
|
121
|
+
if (match !== undefined)
|
|
122
|
+
next = options[Number(match)];
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
if (next)
|
|
128
|
+
focusItem(node, next);
|
|
129
|
+
} }));
|
|
130
|
+
}
|
|
131
|
+
export function MenuItem({ disabled = false, textValue, onSelect, onClick, onFocus, onPointerMove, className, motion, ...props }) {
|
|
132
|
+
const menu = useMenuContext();
|
|
133
|
+
return (_jsx(PopoverClose, { ...props, disabled: undefined, "aria-disabled": disabled || undefined, role: "menuitem", tabIndex: -1, motion: disabled ? 'off' : motion, "data-slot": joinIds('menu-item', props['data-slot']), "data-text-value": textValue, className: cn('h-auto w-full justify-start [background-image:none] inset-shadow-none [border-width:0] [border-style:none] bg-transparent text-start text-inherit shadow-none p-[var(--rad-menu-item-padding,0.625rem)] rounded-[var(--rad-menu-item-radius,var(--rad-control-radius,0.5rem))]', 'hover:bg-[var(--rad-menu-item-focus-background,color-mix(in_oklab,var(--rad-color-accent)_12%,var(--rad-color-surface)))] focus:bg-[var(--rad-menu-item-focus-background,color-mix(in_oklab,var(--rad-color-accent)_12%,var(--rad-color-surface)))] focus:[color:var(--rad-menu-item-focus-color,color-mix(in_oklab,var(--rad-color-accent)_25%,var(--rad-color-foreground)))]', 'aria-disabled:cursor-not-allowed aria-disabled:opacity-[var(--rad-state-disabled-opacity,0.5)] forced-colors:aria-disabled:text-[GrayText] forced-colors:aria-disabled:opacity-100 forced-colors:focus:bg-[Highlight] forced-colors:focus:text-[HighlightText]', className), onClick: composeAction(onClick, onSelect, () => disabled), onFocus: event => {
|
|
134
|
+
onFocus?.(event);
|
|
135
|
+
const node = menu.content.current;
|
|
136
|
+
if (node)
|
|
137
|
+
for (const item of items(node))
|
|
138
|
+
item.tabIndex = item === event.currentTarget ? 0 : -1;
|
|
139
|
+
}, onPointerMove: composeAction(onPointerMove, event => {
|
|
140
|
+
if (event.pointerType !== 'touch')
|
|
141
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
142
|
+
}) }));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=Menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../src/Menu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,eAAe,EACf,MAAM,EAIP,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AAI,SAAS,EACpC,IAAI,EAAC,UAAU,EACf,QAAQ,EAAE,CAAC,CAAC,EACZ,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,eACtB,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,qBAClC,SAAS,EAC1B,SAAS,EAAE,EAAE,CACX,gRAAgR,EAChR,gXAAgX,EAChX,gQAAgQ,EAChQ,SAAS,CACV,EACD,OAAO,EAAE,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EACzD,OAAO,EAAE,KAAK,CAAC,EAAE;YACf,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YAChB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;YACjC,IAAI,IAAI;gBACN,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;oBAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACzF,CAAC,EACD,aAAa,EAAE,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE;YAClD,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO;gBAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;QACvF,CAAC,CAAC,GACF,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport {\n createContext,\n useContext,\n useId,\n useLayoutEffect,\n useRef,\n type MouseEvent,\n type ReactNode,\n type RefObject\n} from 'react'\nimport {\n Popover,\n PopoverTrigger,\n PopoverContent,\n PopoverClose,\n PopoverPortal,\n usePopover,\n type PopoverProps,\n type PopoverState,\n type PopoverContentProps\n} from './Popover.js'\nimport type { ButtonProps, ButtonRenderProps } from './Button.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport { matchSelectText } from './internal/select.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\n\nexport type MenuProps = PopoverProps\nexport type MenuState = PopoverState\nexport type MenuRenderProps = ButtonRenderProps\nexport type MenuPortalProps = { children?: ReactNode }\nexport type MenuTriggerProps = Omit<ButtonProps, 'id' | 'aria-haspopup'>\nexport type MenuContentProps = Omit<\n PopoverContentProps,\n 'role' | 'aria-labelledby' | 'aria-orientation' | 'tabIndex' | 'initialFocusRef'\n>\nexport type MenuItemProps = Omit<\n ButtonProps,\n 'role' | 'tabIndex' | 'aria-disabled' | 'onSelect'\n> & {\n textValue?: string\n onSelect?: (event: MouseEvent<HTMLButtonElement>) => void\n}\ntype Context = MenuState & {\n triggerId: string\n trigger: RefObject<HTMLButtonElement | null>\n content: RefObject<HTMLDivElement | null>\n intent: RefObject<'first' | 'last'>\n setIntent: (edge: 'first' | 'last') => void\n}\nconst MenuContext = createContext<Context | null>(null)\nexport function useMenu(): MenuState | null {\n return useContext(MenuContext)\n}\nfunction useMenuContext() {\n const menu = useContext(MenuContext)\n if (!menu) throw new Error('Menu parts must render inside Menu.')\n return menu\n}\nexport function Menu({ children, ...props }: MenuProps) {\n return (\n <Popover {...props}>\n <MenuOwner>{children}</MenuOwner>\n </Popover>\n )\n}\nfunction MenuOwner({ children }: { children?: ReactNode }) {\n const state = usePopover()!\n const triggerId = useId()\n const trigger = useRef<HTMLButtonElement>(null)\n const content = useRef<HTMLDivElement>(null)\n const intent = useRef<'first' | 'last'>('first')\n return (\n <MenuContext.Provider\n value={{\n ...state,\n triggerId,\n trigger,\n content,\n intent,\n setIntent: edge => {\n intent.current = edge\n }\n }}\n >\n {children}\n </MenuContext.Provider>\n )\n}\nfunction items(node: HTMLElement) {\n return Array.from(node.querySelectorAll<HTMLButtonElement>('button[role=\"menuitem\"]')).filter(\n item => item.closest('[role=\"menu\"]') === node\n )\n}\nfunction focusItem(node: HTMLElement, item?: HTMLButtonElement) {\n for (const candidate of items(node)) candidate.tabIndex = candidate === item ? 0 : -1\n ;(item ?? node).focus({ preventScroll: true })\n}\nexport function MenuTrigger({ ref, onKeyDown, onClick, ...props }: MenuTriggerProps) {\n const menu = useMenuContext()\n const host = useComposedRefs(menu.trigger, ref)\n return (\n <PopoverTrigger\n {...props}\n ref={host}\n id={menu.triggerId}\n aria-haspopup=\"menu\"\n data-slot={joinIds('menu-trigger', props['data-slot'])}\n onClick={composeAction(onClick, () => {\n menu.setIntent('first')\n })}\n onKeyDown={composeAction(onKeyDown, event => {\n if (\n (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') ||\n props.disabled ||\n props.pending ||\n event.currentTarget.matches(':disabled')\n )\n return\n event.preventDefault()\n menu.setIntent(event.key === 'ArrowUp' ? 'last' : 'first')\n if (menu.open && menu.content.current) {\n const options = items(menu.content.current)\n focusItem(\n menu.content.current,\n menu.intent.current === 'last' ? options.at(-1) : options[0]\n )\n } else menu.setOpen(true)\n })}\n />\n )\n}\nexport function MenuPortal(props: MenuPortalProps) {\n useMenuContext()\n return <PopoverPortal {...props} />\n}\nexport function MenuContent({ ref, className, onKeyDown, ...props }: MenuContentProps) {\n const menu = useMenuContext()\n const host = useComposedRefs(menu.content, ref)\n const search = useRef({ text: '', time: 0 })\n useLayoutEffect(() => {\n search.current = { text: '', time: 0 }\n const node = menu.content.current\n if (!menu.open || !node) return\n const options = items(node)\n focusItem(node, menu.intent.current === 'last' ? options.at(-1) : options[0])\n }, [menu.open, menu.content, menu.intent])\n return (\n <PopoverContent\n {...props}\n ref={host}\n role=\"menu\"\n aria-orientation=\"vertical\"\n aria-labelledby={menu.triggerId}\n tabIndex={-1}\n data-slot={joinIds('menu-content', props['data-slot'])}\n className={cn(\n 'w-[var(--rad-menu-width,16rem)] gap-0 p-[var(--rad-menu-padding,0.25rem)] rounded-[var(--rad-menu-radius,var(--rad-surface-radius,0.75rem))]',\n 'bg-[var(--rad-menu-background,var(--rad-color-surface,white))] [color:var(--rad-menu-color,var(--rad-color-foreground))] [border-color:var(--rad-menu-border-color,var(--rad-color-border))] [border-width:var(--rad-menu-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-menu-border-style,var(--rad-surface-border-style,solid))] [box-shadow:var(--rad-menu-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]',\n className\n )}\n onKeyDown={event => {\n onKeyDown?.(event)\n if (event.defaultPrevented) return\n const node = event.currentTarget\n const target = event.target as HTMLElement\n if (target.closest('[role=\"menu\"]') !== node) return\n if (event.key === 'Tab') {\n // Let the browser continue from the opener after closing, in either direction.\n menu.trigger.current?.focus({ preventScroll: true })\n menu.setOpen(false)\n return\n }\n if (event.altKey || event.ctrlKey || event.metaKey || event.nativeEvent.isComposing) return\n const options = items(node)\n const index = options.indexOf(node.ownerDocument.activeElement as HTMLButtonElement)\n let next: HTMLButtonElement | undefined\n if (event.key === 'Home') next = options[0]\n else if (event.key === 'End') next = options.at(-1)\n else if (event.key === 'ArrowDown') next = options[(index + 1) % options.length]\n else if (event.key === 'ArrowUp')\n next = options[(index - 1 + options.length) % options.length]\n else if (event.key.length === 1 && event.key !== ' ') {\n const now = node.ownerDocument.defaultView!.performance.now()\n search.current.text =\n (now - search.current.time > 700 ? '' : search.current.text) + event.key\n search.current.time = now\n const match = matchSelectText(\n options.map((item, i) => ({\n value: String(i),\n textValue: item.dataset.textValue ?? item.textContent ?? ''\n })),\n search.current.text,\n String(index)\n )\n if (match !== undefined) next = options[Number(match)]\n } else return\n event.preventDefault()\n if (next) focusItem(node, next)\n }}\n />\n )\n}\nexport function MenuItem({\n disabled = false,\n textValue,\n onSelect,\n onClick,\n onFocus,\n onPointerMove,\n className,\n motion,\n ...props\n}: MenuItemProps) {\n const menu = useMenuContext()\n return (\n <PopoverClose\n {...props}\n disabled={undefined}\n aria-disabled={disabled || undefined}\n role=\"menuitem\"\n tabIndex={-1}\n motion={disabled ? 'off' : motion}\n data-slot={joinIds('menu-item', props['data-slot'])}\n data-text-value={textValue}\n className={cn(\n 'h-auto w-full justify-start [background-image:none] inset-shadow-none [border-width:0] [border-style:none] bg-transparent text-start text-inherit shadow-none p-[var(--rad-menu-item-padding,0.625rem)] rounded-[var(--rad-menu-item-radius,var(--rad-control-radius,0.5rem))]',\n 'hover:bg-[var(--rad-menu-item-focus-background,color-mix(in_oklab,var(--rad-color-accent)_12%,var(--rad-color-surface)))] focus:bg-[var(--rad-menu-item-focus-background,color-mix(in_oklab,var(--rad-color-accent)_12%,var(--rad-color-surface)))] focus:[color:var(--rad-menu-item-focus-color,color-mix(in_oklab,var(--rad-color-accent)_25%,var(--rad-color-foreground)))]',\n 'aria-disabled:cursor-not-allowed aria-disabled:opacity-[var(--rad-state-disabled-opacity,0.5)] forced-colors:aria-disabled:text-[GrayText] forced-colors:aria-disabled:opacity-100 forced-colors:focus:bg-[Highlight] forced-colors:focus:text-[HighlightText]',\n className\n )}\n onClick={composeAction(onClick, onSelect, () => disabled)}\n onFocus={event => {\n onFocus?.(event)\n const node = menu.content.current\n if (node)\n for (const item of items(node)) item.tabIndex = item === event.currentTarget ? 0 : -1\n }}\n onPointerMove={composeAction(onPointerMove, event => {\n if (event.pointerType !== 'touch') event.currentTarget.focus({ preventScroll: true })\n })}\n />\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.d.ts","sourceRoot":"","sources":["../../src/Popover.tsx"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAI9E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAKtE,OAAO,KAAK,EAAE,UAAU,EAAE,MA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AAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,+BAWpE;AACD,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,sCAK7D;AAgBD,wBAAgB,cAAc,CAAC,EAC7B,GAAG,EACH,SAAS,EACT,IAAe,EACf,KAAe,EACf,UAAc,EACd,gBAAoB,EACpB,eAAe,EACf,MAAkB,EAClB,GAAG,KAAK,EACT,EAAE,mBAAmB,+BAsCrB"}
|
package/dist/library/Popover.js
CHANGED
|
@@ -87,7 +87,7 @@ export function PopoverContent({ ref, className, side = 'bottom', align = 'start
|
|
|
87
87
|
const hostRef = useComposedRefs(popover.content, ref);
|
|
88
88
|
const { ref: transitionRef, active: motionActive, off: motionOff } = useTransitionHost('popup', hostRef, motion === 'off');
|
|
89
89
|
usePopoverSurface(popover.content, popover.trigger, popover.open, popover.close, popover.restoreFocus, { side, align, sideOffset, collisionPadding, initialFocusRef });
|
|
90
|
-
return (_jsx("div", { ...props, ref: transitionRef, id: popover.contentId, popover: "manual", "data-slot":
|
|
90
|
+
return (_jsx("div", { ...props, ref: transitionRef, id: popover.contentId, popover: "manual", "data-slot": joinIds('popover-content', props['data-slot']), "data-state": popover.open ? 'open' : 'closed', "data-side": side, "data-align": align, "data-motion": motion, className: cn(surfaceClass, motionActive &&
|
|
91
91
|
!motionOff &&
|
|
92
92
|
'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100', className) }));
|
|
93
93
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../src/Popover.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EAIT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAA4C,MAAM,aAAa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AC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrD,MAAM,EACJ,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,EACf,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,CAAA;IACzD,iBAAiB,CACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,YAAY,EACpB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAC/D,CAAA;IACD,OAAO,CACL,iBACM,KAAK,EACT,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,CAAC,SAAS,EACrB,OAAO,EAAC,QAAQ,eACN,iBAAiB,gBACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,eACjC,IAAI,gBACH,KAAK,iBACJ,MAAM,EACnB,SAAS,EAAE,EAAE,CACX,YAAY,EACZ,YAAY;YACV,CAAC,SAAS;YACV,+DAA+D,EACjE,SAAS,CACV,GACD,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport {\n createContext,\n useContext,\n useId,\n useRef,\n useState,\n type ComponentProps,\n type ReactNode,\n type RefObject\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { usePopoverSurface } from './react/usePopoverSurface.js'\nimport { useTransitionHost } from './motion/host.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nexport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nexport type PopoverProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n onOpenChange?: (open: boolean) => void\n children?: ReactNode\n}\nexport type PopoverState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }\ntype Context = PopoverState & {\n trigger: HTMLButtonElement | null\n setTrigger: (node: HTMLButtonElement | null) => void\n content: RefObject<HTMLDivElement | null>\n restoreFocus: RefObject<boolean>\n close: (restore: boolean) => void\n}\nconst PopoverContext = createContext<Context | null>(null)\nexport function usePopover(): PopoverState | null {\n return useContext(PopoverContext)\n}\nfunction usePopoverContext() {\n const value = useContext(PopoverContext)\n if (!value) throw new Error('Popover parts must render inside Popover.')\n return value\n}\nexport function Popover({ open, defaultOpen, onOpenChange, children }: PopoverProps) {\n const state = useControllableState({\n name: 'Popover',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n const contentId = useId()\n const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)\n const content = useRef<HTMLDivElement>(null)\n const restoreFocus = useRef(true)\n const setOpen = (next: boolean) => {\n restoreFocus.current = true\n state.request(next)\n }\n const close = (restore: boolean) => {\n restoreFocus.current = restore\n state.request(false)\n }\n return (\n <PopoverContext.Provider\n value={{\n open: state.value,\n setOpen,\n contentId,\n trigger,\n setTrigger,\n content,\n restoreFocus,\n close\n }}\n >\n {children}\n </PopoverContext.Provider>\n )\n}\n\nexport type PopoverTriggerProps = ButtonProps\nexport type PopoverCloseProps = ButtonProps\nexport type PopoverRenderProps = ButtonRenderProps\nexport type PopoverPortalProps = { children?: ReactNode }\nexport type PopoverContentProps = Omit<ComponentProps<'div'>, 'style' | 'popover' | 'id'> & {\n style?: ThemeStyle\n side?: PopoverSide\n align?: PopoverAlign\n sideOffset?: number\n collisionPadding?: number\n /** Keep focus on the opener by default; optionally focus a descendant on each open. */\n initialFocusRef?: RefObject<HTMLElement | null>\n motion?: 'inherit' | 'off'\n}\n\nexport function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps) {\n const popover = usePopoverContext()\n const hostRef = useComposedRefs(popover.setTrigger, ref)\n return (\n <Button\n {...props}\n ref={hostRef}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n aria-controls={popover.contentId}\n aria-expanded={popover.open}\n data-slot={joinIds('popover-trigger', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.setOpen(!popover.open))}\n />\n )\n}\nexport function PopoverClose({ onClick, ...props }: PopoverCloseProps) {\n const popover = usePopoverContext()\n return (\n <Button\n {...props}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n data-slot={joinIds('popover-close', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.close(true))}\n />\n )\n}\n/** The local portal preserves theme, native form ownership and modal ancestry. */\nexport function PopoverPortal({ children }: PopoverPortalProps) {\n const popover = usePopoverContext()\n return popover.trigger?.parentElement\n ? createPortal(children, popover.trigger.parentElement)\n : null\n}\n\nconst surfaceClass = [\n 'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-auto overscroll-contain text-start antialiased',\n '[&:not(:popover-open)]:hidden',\n 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] w-[var(--rad-popover-width,20rem)] max-w-[var(--_rad-popover-max-width,calc(100vw-1rem))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]',\n 'grid gap-[var(--rad-popover-gap,var(--rad-surface-gap,1rem))] p-[var(--rad-popover-padding,var(--rad-surface-padding,1.5rem))]',\n 'rounded-[var(--rad-popover-radius,var(--rad-surface-radius,0.75rem))] [corner-shape:var(--rad-popover-corner-shape,var(--rad-surface-corner-shape,round))]',\n '[border-width:var(--rad-popover-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-popover-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-popover-border-color,var(--rad-color-border))]',\n 'bg-[var(--rad-popover-background,var(--rad-color-surface,white))] [color:var(--rad-popover-color,var(--rad-color-foreground))] [box-shadow:var(--rad-popover-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))] [backdrop-filter:var(--rad-popover-backdrop-filter,none)]',\n 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',\n 'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-popover-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-popover-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-popover-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-popover-focus-style,var(--rad-focus-style,solid))]',\n 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'\n].join(' ')\n\nexport function PopoverContent({\n ref,\n className,\n side = 'bottom',\n align = 'start',\n sideOffset = 8,\n collisionPadding = 8,\n initialFocusRef,\n motion = 'inherit',\n ...props\n}: PopoverContentProps) {\n const popover = usePopoverContext()\n if (![sideOffset, collisionPadding].every(value => Number.isFinite(value) && value >= 0))\n throw new TypeError('Popover offsets and padding must be finite, nonnegative numbers.')\n const hostRef = useComposedRefs(popover.content, ref)\n const {\n ref: transitionRef,\n active: motionActive,\n off: motionOff\n } = useTransitionHost('popup', hostRef, motion === 'off')\n usePopoverSurface(\n popover.content,\n popover.trigger,\n popover.open,\n popover.close,\n popover.restoreFocus,\n { side, align, sideOffset, collisionPadding, initialFocusRef }\n )\n return (\n <div\n {...props}\n ref={transitionRef}\n id={popover.contentId}\n popover=\"manual\"\n data-slot=\"popover-content\"\n data-state={popover.open ? 'open' : 'closed'}\n data-side={side}\n data-align={align}\n data-motion={motion}\n className={cn(\n surfaceClass,\n motionActive &&\n !motionOff &&\n 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',\n className\n )}\n />\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../src/Popover.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EAIT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAmBpD,MAAM,cAAc,GAAG,aAAa,CAAiB,IAAI,CAAC,CAAA;AAC1D,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC;AACD,SAAS,iBAAiB;IACxB,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IACxC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IACxE,OAAO,KAAK,CAAA;AACd,CAAC;AACD,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAgB;IACjF,MAAM,KAAK,GAAG,oBAAoB,CAAC;QACjC,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,WAAW;QACzB,YAAY,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,GAAG,SAAS,EAClB,GAAG,KAAK,EACY;IACpB,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAA;IACnC,IAAI,CAAC,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACtF,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAA;IACzF,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrD,MAAM,EACJ,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,EACf,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,CAAA;IACzD,iBAAiB,CACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,YAAY,EACpB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAC/D,CAAA;IACD,OAAO,CACL,iBACM,KAAK,EACT,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,CAAC,SAAS,EACrB,OAAO,EAAC,QAAQ,eACL,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,gBAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,eACjC,IAAI,gBACH,KAAK,iBACJ,MAAM,EACnB,SAAS,EAAE,EAAE,CACX,YAAY,EACZ,YAAY;YACV,CAAC,SAAS;YACV,+DAA+D,EACjE,SAAS,CACV,GACD,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport {\n createContext,\n useContext,\n useId,\n useRef,\n useState,\n type ComponentProps,\n type ReactNode,\n type RefObject\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { usePopoverSurface } from './react/usePopoverSurface.js'\nimport { useTransitionHost } from './motion/host.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nexport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nexport type PopoverProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n onOpenChange?: (open: boolean) => void\n children?: ReactNode\n}\nexport type PopoverState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }\ntype Context = PopoverState & {\n trigger: HTMLButtonElement | null\n setTrigger: (node: HTMLButtonElement | null) => void\n content: RefObject<HTMLDivElement | null>\n restoreFocus: RefObject<boolean>\n close: (restore: boolean) => void\n}\nconst PopoverContext = createContext<Context | null>(null)\nexport function usePopover(): PopoverState | null {\n return useContext(PopoverContext)\n}\nfunction usePopoverContext() {\n const value = useContext(PopoverContext)\n if (!value) throw new Error('Popover parts must render inside Popover.')\n return value\n}\nexport function Popover({ open, defaultOpen, onOpenChange, children }: PopoverProps) {\n const state = useControllableState({\n name: 'Popover',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n const contentId = useId()\n const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)\n const content = useRef<HTMLDivElement>(null)\n const restoreFocus = useRef(true)\n const setOpen = (next: boolean) => {\n restoreFocus.current = true\n state.request(next)\n }\n const close = (restore: boolean) => {\n restoreFocus.current = restore\n state.request(false)\n }\n return (\n <PopoverContext.Provider\n value={{\n open: state.value,\n setOpen,\n contentId,\n trigger,\n setTrigger,\n content,\n restoreFocus,\n close\n }}\n >\n {children}\n </PopoverContext.Provider>\n )\n}\n\nexport type PopoverTriggerProps = ButtonProps\nexport type PopoverCloseProps = ButtonProps\nexport type PopoverRenderProps = ButtonRenderProps\nexport type PopoverPortalProps = { children?: ReactNode }\nexport type PopoverContentProps = Omit<ComponentProps<'div'>, 'style' | 'popover' | 'id'> & {\n style?: ThemeStyle\n 'data-slot'?: string\n side?: PopoverSide\n align?: PopoverAlign\n sideOffset?: number\n collisionPadding?: number\n /** Keep focus on the opener by default; optionally focus a descendant on each open. */\n initialFocusRef?: RefObject<HTMLElement | null>\n motion?: 'inherit' | 'off'\n}\n\nexport function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps) {\n const popover = usePopoverContext()\n const hostRef = useComposedRefs(popover.setTrigger, ref)\n return (\n <Button\n {...props}\n ref={hostRef}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n aria-controls={popover.contentId}\n aria-expanded={popover.open}\n data-slot={joinIds('popover-trigger', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.setOpen(!popover.open))}\n />\n )\n}\nexport function PopoverClose({ onClick, ...props }: PopoverCloseProps) {\n const popover = usePopoverContext()\n return (\n <Button\n {...props}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n data-slot={joinIds('popover-close', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.close(true))}\n />\n )\n}\n/** The local portal preserves theme, native form ownership and modal ancestry. */\nexport function PopoverPortal({ children }: PopoverPortalProps) {\n const popover = usePopoverContext()\n return popover.trigger?.parentElement\n ? createPortal(children, popover.trigger.parentElement)\n : null\n}\n\nconst surfaceClass = [\n 'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-auto overscroll-contain text-start antialiased',\n '[&:not(:popover-open)]:hidden',\n 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] w-[var(--rad-popover-width,20rem)] max-w-[var(--_rad-popover-max-width,calc(100vw-1rem))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]',\n 'grid gap-[var(--rad-popover-gap,var(--rad-surface-gap,1rem))] p-[var(--rad-popover-padding,var(--rad-surface-padding,1.5rem))]',\n 'rounded-[var(--rad-popover-radius,var(--rad-surface-radius,0.75rem))] [corner-shape:var(--rad-popover-corner-shape,var(--rad-surface-corner-shape,round))]',\n '[border-width:var(--rad-popover-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-popover-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-popover-border-color,var(--rad-color-border))]',\n 'bg-[var(--rad-popover-background,var(--rad-color-surface,white))] [color:var(--rad-popover-color,var(--rad-color-foreground))] [box-shadow:var(--rad-popover-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))] [backdrop-filter:var(--rad-popover-backdrop-filter,none)]',\n 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',\n 'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-popover-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-popover-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-popover-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-popover-focus-style,var(--rad-focus-style,solid))]',\n 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'\n].join(' ')\n\nexport function PopoverContent({\n ref,\n className,\n side = 'bottom',\n align = 'start',\n sideOffset = 8,\n collisionPadding = 8,\n initialFocusRef,\n motion = 'inherit',\n ...props\n}: PopoverContentProps) {\n const popover = usePopoverContext()\n if (![sideOffset, collisionPadding].every(value => Number.isFinite(value) && value >= 0))\n throw new TypeError('Popover offsets and padding must be finite, nonnegative numbers.')\n const hostRef = useComposedRefs(popover.content, ref)\n const {\n ref: transitionRef,\n active: motionActive,\n off: motionOff\n } = useTransitionHost('popup', hostRef, motion === 'off')\n usePopoverSurface(\n popover.content,\n popover.trigger,\n popover.open,\n popover.close,\n popover.restoreFocus,\n { side, align, sideOffset, collisionPadding, initialFocusRef }\n )\n return (\n <div\n {...props}\n ref={transitionRef}\n id={popover.contentId}\n popover=\"manual\"\n data-slot={joinIds('popover-content', props['data-slot'])}\n data-state={popover.open ? 'open' : 'closed'}\n data-side={side}\n data-align={align}\n data-motion={motion}\n className={cn(\n surfaceClass,\n motionActive &&\n !motionOff &&\n 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',\n className\n )}\n />\n )\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
import { type ButtonProps, type ButtonRenderProps } from './Button.js';
|
|
3
|
+
import type { PopoverSide, PopoverAlign } from './internal/popover.js';
|
|
4
|
+
import type { ThemeStyle } from './themes/defineTheme.js';
|
|
5
|
+
export type TooltipProps = ({
|
|
6
|
+
open: boolean;
|
|
7
|
+
defaultOpen?: never;
|
|
8
|
+
} | {
|
|
9
|
+
open?: undefined;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
}) & {
|
|
12
|
+
onOpenChange?: (open: boolean) => void;
|
|
13
|
+
openDelay?: number;
|
|
14
|
+
closeDelay?: number;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
};
|
|
17
|
+
export type TooltipState = {
|
|
18
|
+
open: boolean;
|
|
19
|
+
setOpen: (open: boolean) => void;
|
|
20
|
+
contentId: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function useTooltip(): TooltipState | null;
|
|
23
|
+
export declare function Tooltip({ open, defaultOpen, onOpenChange, openDelay, closeDelay, children }: TooltipProps): import("react").JSX.Element;
|
|
24
|
+
export type TooltipTriggerProps = ButtonProps;
|
|
25
|
+
export type TooltipRenderProps = ButtonRenderProps;
|
|
26
|
+
export type TooltipPortalProps = {
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
};
|
|
29
|
+
export type TooltipContentProps = Omit<ComponentProps<'span'>, 'style' | 'id' | 'role' | 'popover' | 'tabIndex'> & {
|
|
30
|
+
style?: ThemeStyle;
|
|
31
|
+
side?: PopoverSide;
|
|
32
|
+
align?: PopoverAlign;
|
|
33
|
+
sideOffset?: number;
|
|
34
|
+
collisionPadding?: number;
|
|
35
|
+
motion?: 'inherit' | 'off';
|
|
36
|
+
};
|
|
37
|
+
export declare function TooltipTrigger({ ref, onClick, onFocus, onBlur, onPointerEnter, onPointerLeave, onPointerDown, ...props }: TooltipTriggerProps): import("react").JSX.Element;
|
|
38
|
+
export declare function TooltipPortal({ children }: TooltipPortalProps): ReactNode;
|
|
39
|
+
export declare function TooltipContent({ ref, className, side, align, sideOffset, collisionPadding, motion, onPointerEnter, onPointerLeave, ...props }: TooltipContentProps): import("react").JSX.Element;
|
|
40
|
+
//# sourceMappingURL=Tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAA;AAEd,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAI9E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAKtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,MAAM,YAAY,GAAG,CACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,GACtC;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA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E,mBAAmB,+BA8BrB;AACD,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,aAG7D;AACD,wBAAgB,cAAc,CAAC,EAC7B,GAAG,EACH,SAAS,EACT,IAAY,EACZ,KAAgB,EAChB,UAAc,EACd,gBAAoB,EACpB,MAAkB,EAClB,cAAc,EACd,cAAc,EACd,GAAG,KAAK,EACT,EAAE,mBAAmB,+BA4CrB"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { Button } from './Button.js';
|
|
6
|
+
import { cn } from './cn.js';
|
|
7
|
+
import { joinIds } from './internal/ids.js';
|
|
8
|
+
import { composeAction } from './internal/events.js';
|
|
9
|
+
import { useControllableState } from './react/useControllableState.js';
|
|
10
|
+
import { useComposedRefs } from './react/useComposedRefs.js';
|
|
11
|
+
import { usePopoverSurface } from './react/usePopoverSurface.js';
|
|
12
|
+
import { useTransitionHost } from './motion/host.js';
|
|
13
|
+
const TooltipContext = createContext(null);
|
|
14
|
+
export function useTooltip() {
|
|
15
|
+
return useContext(TooltipContext);
|
|
16
|
+
}
|
|
17
|
+
function useTooltipContext() {
|
|
18
|
+
const value = useContext(TooltipContext);
|
|
19
|
+
if (!value)
|
|
20
|
+
throw new Error('Tooltip parts must render inside Tooltip.');
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
export function Tooltip({ open, defaultOpen, onOpenChange, openDelay = 500, closeDelay = 150, children }) {
|
|
24
|
+
if (![openDelay, closeDelay].every(n => Number.isFinite(n) && n >= 0))
|
|
25
|
+
throw new TypeError('Tooltip delays must be finite, nonnegative numbers.');
|
|
26
|
+
const state = useControllableState({
|
|
27
|
+
name: 'Tooltip',
|
|
28
|
+
value: open,
|
|
29
|
+
defaultValue: defaultOpen,
|
|
30
|
+
initialValue: false,
|
|
31
|
+
onChange: onOpenChange
|
|
32
|
+
});
|
|
33
|
+
const contentId = useId();
|
|
34
|
+
const [trigger, setTrigger] = useState(null);
|
|
35
|
+
const content = useRef(null);
|
|
36
|
+
const timer = useRef(null);
|
|
37
|
+
const activity = useRef({ focused: false, hovered: false, suppressed: false, touch: false });
|
|
38
|
+
const clear = () => {
|
|
39
|
+
if (timer.current)
|
|
40
|
+
timer.current.view.clearTimeout(timer.current.id);
|
|
41
|
+
timer.current = null;
|
|
42
|
+
};
|
|
43
|
+
const latest = useRef(state.request);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
latest.current = state.request;
|
|
46
|
+
});
|
|
47
|
+
useEffect(() => () => clear(), []);
|
|
48
|
+
const schedule = useCallback((next, delay) => {
|
|
49
|
+
clear();
|
|
50
|
+
const view = trigger?.ownerDocument.defaultView;
|
|
51
|
+
if (!view)
|
|
52
|
+
return;
|
|
53
|
+
timer.current = {
|
|
54
|
+
view,
|
|
55
|
+
id: view.setTimeout(() => {
|
|
56
|
+
timer.current = null;
|
|
57
|
+
latest.current(next);
|
|
58
|
+
}, delay)
|
|
59
|
+
};
|
|
60
|
+
}, [trigger]);
|
|
61
|
+
const dismiss = () => {
|
|
62
|
+
clear();
|
|
63
|
+
activity.current.suppressed = true;
|
|
64
|
+
state.request(false);
|
|
65
|
+
};
|
|
66
|
+
const enter = (focus = false) => {
|
|
67
|
+
if (focus && !activity.current.focused)
|
|
68
|
+
activity.current.suppressed = false;
|
|
69
|
+
if (focus)
|
|
70
|
+
activity.current.focused = true;
|
|
71
|
+
else
|
|
72
|
+
activity.current.hovered = true;
|
|
73
|
+
clear();
|
|
74
|
+
if (activity.current.suppressed || activity.current.touch)
|
|
75
|
+
return;
|
|
76
|
+
if (focus)
|
|
77
|
+
state.request(true);
|
|
78
|
+
else if (!state.value)
|
|
79
|
+
schedule(true, openDelay);
|
|
80
|
+
};
|
|
81
|
+
const leave = (focus = false) => {
|
|
82
|
+
if (focus) {
|
|
83
|
+
activity.current.focused = false;
|
|
84
|
+
activity.current.touch = false;
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
activity.current.hovered = false;
|
|
88
|
+
if (activity.current.focused || activity.current.hovered)
|
|
89
|
+
return;
|
|
90
|
+
activity.current.suppressed = false;
|
|
91
|
+
schedule(false, closeDelay);
|
|
92
|
+
};
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!trigger || !state.value)
|
|
95
|
+
return;
|
|
96
|
+
const move = (event) => {
|
|
97
|
+
if (event.pointerType === 'touch' ||
|
|
98
|
+
activity.current.focused ||
|
|
99
|
+
activity.current.hovered ||
|
|
100
|
+
activity.current.suppressed)
|
|
101
|
+
return;
|
|
102
|
+
const panel = content.current;
|
|
103
|
+
if (!panel)
|
|
104
|
+
return;
|
|
105
|
+
const a = trigger.getBoundingClientRect();
|
|
106
|
+
const b = panel.getBoundingClientRect();
|
|
107
|
+
// Keep a hoverable bridge across the placement gap, including magnified pointer movement.
|
|
108
|
+
const within = event.clientX >= Math.min(a.left, b.left) &&
|
|
109
|
+
event.clientX <= Math.max(a.right, b.right) &&
|
|
110
|
+
event.clientY >= Math.min(a.top, b.top) &&
|
|
111
|
+
event.clientY <= Math.max(a.bottom, b.bottom);
|
|
112
|
+
if (within)
|
|
113
|
+
clear();
|
|
114
|
+
else if (!timer.current)
|
|
115
|
+
schedule(false, closeDelay);
|
|
116
|
+
};
|
|
117
|
+
trigger.ownerDocument.addEventListener('pointermove', move);
|
|
118
|
+
return () => trigger.ownerDocument.removeEventListener('pointermove', move);
|
|
119
|
+
}, [trigger, state.value, closeDelay, schedule]);
|
|
120
|
+
return (_jsx(TooltipContext.Provider, { value: {
|
|
121
|
+
open: state.value,
|
|
122
|
+
setOpen: state.request,
|
|
123
|
+
contentId,
|
|
124
|
+
trigger,
|
|
125
|
+
setTrigger,
|
|
126
|
+
content,
|
|
127
|
+
enter,
|
|
128
|
+
leave,
|
|
129
|
+
dismiss,
|
|
130
|
+
touch: () => {
|
|
131
|
+
activity.current.touch = true;
|
|
132
|
+
dismiss();
|
|
133
|
+
}
|
|
134
|
+
}, children: children }));
|
|
135
|
+
}
|
|
136
|
+
export function TooltipTrigger({ ref, onClick, onFocus, onBlur, onPointerEnter, onPointerLeave, onPointerDown, ...props }) {
|
|
137
|
+
const tip = useTooltipContext();
|
|
138
|
+
const hostRef = useComposedRefs(tip.setTrigger, ref);
|
|
139
|
+
return (_jsx(Button, { ...props, ref: hostRef, "data-slot": joinIds('tooltip-trigger', props['data-slot']), "aria-describedby": joinIds(tip.contentId, props['aria-describedby']), onFocus: event => {
|
|
140
|
+
onFocus?.(event);
|
|
141
|
+
tip.enter(true);
|
|
142
|
+
}, onBlur: event => {
|
|
143
|
+
onBlur?.(event);
|
|
144
|
+
tip.leave(true);
|
|
145
|
+
}, onPointerEnter: composeAction(onPointerEnter, event => {
|
|
146
|
+
if (event.pointerType !== 'touch')
|
|
147
|
+
tip.enter();
|
|
148
|
+
}), onPointerLeave: composeAction(onPointerLeave, event => {
|
|
149
|
+
if (event.pointerType !== 'touch')
|
|
150
|
+
tip.leave();
|
|
151
|
+
}), onPointerDown: event => {
|
|
152
|
+
onPointerDown?.(event);
|
|
153
|
+
if (event.pointerType === 'touch')
|
|
154
|
+
tip.touch();
|
|
155
|
+
}, onClick: composeAction(onClick, tip.dismiss) }));
|
|
156
|
+
}
|
|
157
|
+
export function TooltipPortal({ children }) {
|
|
158
|
+
const tip = useTooltipContext();
|
|
159
|
+
return tip.trigger?.parentElement ? createPortal(children, tip.trigger.parentElement) : children;
|
|
160
|
+
}
|
|
161
|
+
export function TooltipContent({ ref, className, side = 'top', align = 'center', sideOffset = 8, collisionPadding = 8, motion = 'inherit', onPointerEnter, onPointerLeave, ...props }) {
|
|
162
|
+
const tip = useTooltipContext();
|
|
163
|
+
if (![sideOffset, collisionPadding].every(n => Number.isFinite(n) && n >= 0))
|
|
164
|
+
throw new TypeError('Tooltip offsets must be finite, nonnegative numbers.');
|
|
165
|
+
const hostRef = useComposedRefs(tip.content, ref);
|
|
166
|
+
const restoreFocus = useRef(false);
|
|
167
|
+
const { ref: transitionRef, active, off } = useTransitionHost('popup', hostRef, motion === 'off');
|
|
168
|
+
usePopoverSurface(tip.content, tip.trigger, tip.open, tip.dismiss, restoreFocus, {
|
|
169
|
+
side,
|
|
170
|
+
align,
|
|
171
|
+
sideOffset,
|
|
172
|
+
collisionPadding
|
|
173
|
+
});
|
|
174
|
+
return (_jsx("span", { ...props, ref: transitionRef, id: tip.contentId, role: "tooltip", popover: "manual", tabIndex: undefined, "data-slot": "tooltip-content", "data-state": tip.open ? 'open' : 'closed', "data-side": side, "data-align": align, "data-motion": motion, onPointerEnter: composeAction(onPointerEnter, event => {
|
|
175
|
+
if (event.pointerType !== 'touch')
|
|
176
|
+
tip.enter();
|
|
177
|
+
}), onPointerLeave: composeAction(onPointerLeave, event => {
|
|
178
|
+
if (event.pointerType !== 'touch')
|
|
179
|
+
tip.leave();
|
|
180
|
+
}), className: cn('fixed right-auto bottom-auto m-0 box-border block min-w-0 w-max overflow-auto break-words text-start antialiased [&:not(:popover-open)]:hidden', 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] max-w-[min(var(--rad-tooltip-max-width,20rem),var(--_rad-popover-max-width,calc(100vw-1rem)))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]', 'p-[var(--rad-tooltip-padding,0.625rem)] rounded-[var(--rad-tooltip-radius,var(--rad-control-radius,0.5rem))]', 'bg-[var(--rad-tooltip-background,var(--rad-color-surface,white))] [color:var(--rad-tooltip-color,var(--rad-color-foreground))] [border-color:var(--rad-tooltip-border-color,var(--rad-color-border))] [border-width:var(--rad-tooltip-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-tooltip-border-style,var(--rad-surface-border-style,solid))] [box-shadow:var(--rad-tooltip-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]', 'font-[family-name:var(--rad-typography-roles-ui-supporting-family,system-ui,sans-serif)] text-[length:var(--rad-tooltip-font-size,var(--rad-typography-roles-ui-supporting-size,0.8125rem))] font-[number:var(--rad-tooltip-font-weight,var(--rad-typography-roles-ui-supporting-weight,400))] leading-[var(--rad-typography-roles-ui-supporting-line-height,1.5)]', 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]', active && !off && 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100', className) }));
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../src/Tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,KAAK,EACL,MAAM,EACN,QAAQ,EAIT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAsBpD,MAAM,cAAc,GAAG,aAAa,CAAiB,IAAI,CAAC,CAAA;AAC1D,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC;AACD,SAAS,iBAAiB;IACxB,MAAM,KAAK,GAAG,UAAU,CAAC,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AC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE;QAC/E,IAAI;QACJ,KAAK;QACL,UAAU;QACV,gBAAgB;KACjB,CAAC,CAAA;IACF,OAAO,CACL,kBACM,KAAK,EACT,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,GAAG,CAAC,SAAS,EACjB,IAAI,EAAC,SAAS,EACd,OAAO,EAAC,QAAQ,EAChB,QAAQ,EAAE,SAAS,eACT,iBAAiB,gBACf,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,eAC7B,IAAI,gBACH,KAAK,iBACJ,MAAM,EACnB,cAAc,EAAE,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE;YACpD,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO;gBAAE,GAAG,CAAC,KAAK,EAAE,CAAA;QAChD,CAAC,CAAC,EACF,cAAc,EAAE,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE;YACpD,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO;gBAAE,GAAG,CAAC,KAAK,EAAE,CAAA;QAChD,CAAC,CAAC,EACF,SAAS,EAAE,EAAE,CACX,gJAAgJ,EAChJ,+NAA+N,EAC/N,8GAA8G,EAC9G,ycAAyc,EACzc,oWAAoW,EACpW,6FAA6F,EAC7F,MAAM,IAAI,CAAC,GAAG,IAAI,+DAA+D,EACjF,SAAS,CACV,GACD,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useId,\n useRef,\n useState,\n type ComponentProps,\n type ReactNode,\n type RefObject\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { cn } from './cn.js'\nimport { joinIds } from './internal/ids.js'\nimport { composeAction } from './internal/events.js'\nimport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { usePopoverSurface } from './react/usePopoverSurface.js'\nimport { useTransitionHost } from './motion/host.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nexport type TooltipProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n onOpenChange?: (open: boolean) => void\n openDelay?: number\n closeDelay?: number\n children?: ReactNode\n}\nexport type TooltipState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }\ntype Context = TooltipState & {\n trigger: HTMLButtonElement | null\n setTrigger: (node: HTMLButtonElement | null) => void\n content: RefObject<HTMLSpanElement | null>\n enter: (focus?: boolean) => void\n leave: (focus?: boolean) => void\n dismiss: () => void\n touch: () => void\n}\nconst TooltipContext = createContext<Context | null>(null)\nexport function useTooltip(): TooltipState | null {\n return useContext(TooltipContext)\n}\nfunction useTooltipContext() {\n const value = useContext(TooltipContext)\n if (!value) throw new Error('Tooltip parts must render inside Tooltip.')\n return value\n}\n\nexport function Tooltip({\n open,\n defaultOpen,\n onOpenChange,\n openDelay = 500,\n closeDelay = 150,\n children\n}: TooltipProps) {\n if (![openDelay, closeDelay].every(n => Number.isFinite(n) && n >= 0))\n throw new TypeError('Tooltip delays must be finite, nonnegative numbers.')\n const state = useControllableState({\n name: 'Tooltip',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n const contentId = useId()\n const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)\n const content = useRef<HTMLSpanElement>(null)\n const timer = useRef<{ view: Window; id: number } | null>(null)\n const activity = useRef({ focused: false, hovered: false, suppressed: false, touch: false })\n const clear = () => {\n if (timer.current) timer.current.view.clearTimeout(timer.current.id)\n timer.current = null\n }\n const latest = useRef(state.request)\n useEffect(() => {\n latest.current = state.request\n })\n useEffect(() => () => clear(), [])\n const schedule = useCallback(\n (next: boolean, delay: number) => {\n clear()\n const view = trigger?.ownerDocument.defaultView\n if (!view) return\n timer.current = {\n view,\n id: view.setTimeout(() => {\n timer.current = null\n latest.current(next)\n }, delay)\n }\n },\n [trigger]\n )\n const dismiss = () => {\n clear()\n activity.current.suppressed = true\n state.request(false)\n }\n const enter = (focus = false) => {\n if (focus && !activity.current.focused) activity.current.suppressed = false\n if (focus) activity.current.focused = true\n else activity.current.hovered = true\n clear()\n if (activity.current.suppressed || activity.current.touch) return\n if (focus) state.request(true)\n else if (!state.value) schedule(true, openDelay)\n }\n const leave = (focus = false) => {\n if (focus) {\n activity.current.focused = false\n activity.current.touch = false\n } else activity.current.hovered = false\n if (activity.current.focused || activity.current.hovered) return\n activity.current.suppressed = false\n schedule(false, closeDelay)\n }\n useEffect(() => {\n if (!trigger || !state.value) return\n const move = (event: PointerEvent) => {\n if (\n event.pointerType === 'touch' ||\n activity.current.focused ||\n activity.current.hovered ||\n activity.current.suppressed\n )\n return\n const panel = content.current\n if (!panel) return\n const a = trigger.getBoundingClientRect()\n const b = panel.getBoundingClientRect()\n // Keep a hoverable bridge across the placement gap, including magnified pointer movement.\n const within =\n event.clientX >= Math.min(a.left, b.left) &&\n event.clientX <= Math.max(a.right, b.right) &&\n event.clientY >= Math.min(a.top, b.top) &&\n event.clientY <= Math.max(a.bottom, b.bottom)\n if (within) clear()\n else if (!timer.current) schedule(false, closeDelay)\n }\n trigger.ownerDocument.addEventListener('pointermove', move)\n return () => trigger.ownerDocument.removeEventListener('pointermove', move)\n }, [trigger, state.value, closeDelay, schedule])\n return (\n <TooltipContext.Provider\n value={{\n open: state.value,\n setOpen: state.request,\n contentId,\n trigger,\n setTrigger,\n content,\n enter,\n leave,\n dismiss,\n touch: () => {\n activity.current.touch = true\n dismiss()\n }\n }}\n >\n {children}\n </TooltipContext.Provider>\n )\n}\n\nexport type TooltipTriggerProps = ButtonProps\nexport type TooltipRenderProps = ButtonRenderProps\nexport type TooltipPortalProps = { children?: ReactNode }\nexport type TooltipContentProps = Omit<\n ComponentProps<'span'>,\n 'style' | 'id' | 'role' | 'popover' | 'tabIndex'\n> & {\n style?: ThemeStyle\n side?: PopoverSide\n align?: PopoverAlign\n sideOffset?: number\n collisionPadding?: number\n motion?: 'inherit' | 'off'\n}\nexport function TooltipTrigger({\n ref,\n onClick,\n onFocus,\n onBlur,\n onPointerEnter,\n onPointerLeave,\n onPointerDown,\n ...props\n}: TooltipTriggerProps) {\n const tip = useTooltipContext()\n const hostRef = useComposedRefs(tip.setTrigger, ref)\n return (\n <Button\n {...props}\n ref={hostRef}\n data-slot={joinIds('tooltip-trigger', props['data-slot'])}\n aria-describedby={joinIds(tip.contentId, props['aria-describedby'])}\n onFocus={event => {\n onFocus?.(event)\n tip.enter(true)\n }}\n onBlur={event => {\n onBlur?.(event)\n tip.leave(true)\n }}\n onPointerEnter={composeAction(onPointerEnter, event => {\n if (event.pointerType !== 'touch') tip.enter()\n })}\n onPointerLeave={composeAction(onPointerLeave, event => {\n if (event.pointerType !== 'touch') tip.leave()\n })}\n onPointerDown={event => {\n onPointerDown?.(event)\n if (event.pointerType === 'touch') tip.touch()\n }}\n onClick={composeAction(onClick, tip.dismiss)}\n />\n )\n}\nexport function TooltipPortal({ children }: TooltipPortalProps) {\n const tip = useTooltipContext()\n return tip.trigger?.parentElement ? createPortal(children, tip.trigger.parentElement) : children\n}\nexport function TooltipContent({\n ref,\n className,\n side = 'top',\n align = 'center',\n sideOffset = 8,\n collisionPadding = 8,\n motion = 'inherit',\n onPointerEnter,\n onPointerLeave,\n ...props\n}: TooltipContentProps) {\n const tip = useTooltipContext()\n if (![sideOffset, collisionPadding].every(n => Number.isFinite(n) && n >= 0))\n throw new TypeError('Tooltip offsets must be finite, nonnegative numbers.')\n const hostRef = useComposedRefs(tip.content, ref)\n const restoreFocus = useRef(false)\n const { ref: transitionRef, active, off } = useTransitionHost('popup', hostRef, motion === 'off')\n usePopoverSurface(tip.content, tip.trigger, tip.open, tip.dismiss, restoreFocus, {\n side,\n align,\n sideOffset,\n collisionPadding\n })\n return (\n <span\n {...props}\n ref={transitionRef}\n id={tip.contentId}\n role=\"tooltip\"\n popover=\"manual\"\n tabIndex={undefined}\n data-slot=\"tooltip-content\"\n data-state={tip.open ? 'open' : 'closed'}\n data-side={side}\n data-align={align}\n data-motion={motion}\n onPointerEnter={composeAction(onPointerEnter, event => {\n if (event.pointerType !== 'touch') tip.enter()\n })}\n onPointerLeave={composeAction(onPointerLeave, event => {\n if (event.pointerType !== 'touch') tip.leave()\n })}\n className={cn(\n 'fixed right-auto bottom-auto m-0 box-border block min-w-0 w-max overflow-auto break-words text-start antialiased [&:not(:popover-open)]:hidden',\n 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] max-w-[min(var(--rad-tooltip-max-width,20rem),var(--_rad-popover-max-width,calc(100vw-1rem)))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]',\n 'p-[var(--rad-tooltip-padding,0.625rem)] rounded-[var(--rad-tooltip-radius,var(--rad-control-radius,0.5rem))]',\n 'bg-[var(--rad-tooltip-background,var(--rad-color-surface,white))] [color:var(--rad-tooltip-color,var(--rad-color-foreground))] [border-color:var(--rad-tooltip-border-color,var(--rad-color-border))] [border-width:var(--rad-tooltip-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-tooltip-border-style,var(--rad-surface-border-style,solid))] [box-shadow:var(--rad-tooltip-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]',\n 'font-[family-name:var(--rad-typography-roles-ui-supporting-family,system-ui,sans-serif)] text-[length:var(--rad-tooltip-font-size,var(--rad-typography-roles-ui-supporting-size,0.8125rem))] font-[number:var(--rad-tooltip-font-weight,var(--rad-typography-roles-ui-supporting-weight,400))] leading-[var(--rad-typography-roles-ui-supporting-line-height,1.5)]',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]',\n active && !off && 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',\n className\n )}\n />\n )\n}\n"]}
|
package/dist/library/cn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/cn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAOpC,eAAO,MAAM,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/cn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAOpC,eAAO,MAAM,EAAE,EAAE,UAqKf,CAAA"}
|