@cognitap/radiant 0.0.35 → 0.0.36
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 +13 -5
- package/dist/library/ContextMenu.d.ts +38 -0
- package/dist/library/ContextMenu.d.ts.map +1 -0
- package/dist/library/ContextMenu.js +169 -0
- package/dist/library/ContextMenu.js.map +1 -0
- package/dist/library/Menu.d.ts +83 -3
- package/dist/library/Menu.d.ts.map +1 -1
- package/dist/library/Menu.js +209 -25
- package/dist/library/Menu.js.map +1 -1
- package/dist/library/Popover.d.ts +18 -2
- package/dist/library/Popover.d.ts.map +1 -1
- package/dist/library/Popover.js +24 -4
- package/dist/library/Popover.js.map +1 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +1 -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 +4 -0
- package/dist/library/react/usePopoverSurface.d.ts.map +1 -1
- package/dist/library/react/usePopoverSurface.js +13 -4
- package/dist/library/react/usePopoverSurface.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +3 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +1 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +35 -31
- package/package.json +1 -1
- package/src/ContextMenu.tsx +354 -0
- package/src/Menu.tsx +496 -40
- package/src/Popover.tsx +46 -4
- package/src/cn.ts +1 -0
- package/src/index.ts +57 -0
- package/src/react/usePopoverSurface.ts +17 -4
- package/src/themes/components.ts +1 -0
package/src/Popover.tsx
CHANGED
|
@@ -32,6 +32,7 @@ export type PopoverProps = (
|
|
|
32
32
|
}
|
|
33
33
|
export type PopoverState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }
|
|
34
34
|
type Context = PopoverState & {
|
|
35
|
+
anchorPoint?: { x: number; y: number }
|
|
35
36
|
trigger: HTMLElement | null
|
|
36
37
|
setTrigger: (node: HTMLElement | null) => void
|
|
37
38
|
content: RefObject<HTMLDivElement | null>
|
|
@@ -48,7 +49,22 @@ export function usePopoverContext() {
|
|
|
48
49
|
if (!value) throw new Error('Popover parts must render inside Popover.')
|
|
49
50
|
return value
|
|
50
51
|
}
|
|
51
|
-
export function Popover(
|
|
52
|
+
export function Popover(props: PopoverProps) {
|
|
53
|
+
return (
|
|
54
|
+
<PopoverRoot
|
|
55
|
+
{...props}
|
|
56
|
+
anchorPoint={undefined}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
/** Private pointer anchor for composed context menus; the real source retains focus ownership. */
|
|
61
|
+
export function PopoverRoot({
|
|
62
|
+
open,
|
|
63
|
+
defaultOpen,
|
|
64
|
+
onOpenChange,
|
|
65
|
+
children,
|
|
66
|
+
anchorPoint
|
|
67
|
+
}: PopoverProps & { anchorPoint?: { x: number; y: number } }) {
|
|
52
68
|
const state = useControllableState({
|
|
53
69
|
name: 'Popover',
|
|
54
70
|
value: open,
|
|
@@ -74,6 +90,7 @@ export function Popover({ open, defaultOpen, onOpenChange, children }: PopoverPr
|
|
|
74
90
|
open: state.value,
|
|
75
91
|
setOpen,
|
|
76
92
|
contentId,
|
|
93
|
+
anchorPoint,
|
|
77
94
|
trigger,
|
|
78
95
|
setTrigger,
|
|
79
96
|
content,
|
|
@@ -118,7 +135,22 @@ export function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps)
|
|
|
118
135
|
/>
|
|
119
136
|
)
|
|
120
137
|
}
|
|
121
|
-
export function PopoverClose(
|
|
138
|
+
export function PopoverClose(props: PopoverCloseProps) {
|
|
139
|
+
return (
|
|
140
|
+
<PopoverCloseRoot
|
|
141
|
+
{...props}
|
|
142
|
+
requestClose={undefined}
|
|
143
|
+
closeOnClick={undefined}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
/** Private close-action policy for composed menus; keeps the real Button and identities. */
|
|
148
|
+
export function PopoverCloseRoot({
|
|
149
|
+
onClick,
|
|
150
|
+
requestClose,
|
|
151
|
+
closeOnClick = true,
|
|
152
|
+
...props
|
|
153
|
+
}: PopoverCloseProps & { requestClose?: () => void; closeOnClick?: boolean }) {
|
|
122
154
|
const popover = usePopoverContext()
|
|
123
155
|
return (
|
|
124
156
|
<Button
|
|
@@ -126,7 +158,9 @@ export function PopoverClose({ onClick, ...props }: PopoverCloseProps) {
|
|
|
126
158
|
popoverTarget={undefined}
|
|
127
159
|
popoverTargetAction={undefined}
|
|
128
160
|
data-slot={joinIds('popover-close', props['data-slot'])}
|
|
129
|
-
onClick={composeAction(onClick, () =>
|
|
161
|
+
onClick={composeAction(onClick, () => {
|
|
162
|
+
if (closeOnClick) (requestClose ?? (() => popover.close(true)))()
|
|
163
|
+
})}
|
|
130
164
|
/>
|
|
131
165
|
)
|
|
132
166
|
}
|
|
@@ -190,7 +224,15 @@ export function PopoverContentRoot({
|
|
|
190
224
|
popover.open,
|
|
191
225
|
popover.close,
|
|
192
226
|
popover.restoreFocus,
|
|
193
|
-
{
|
|
227
|
+
{
|
|
228
|
+
side,
|
|
229
|
+
align,
|
|
230
|
+
sideOffset,
|
|
231
|
+
collisionPadding,
|
|
232
|
+
initialFocusRef,
|
|
233
|
+
onFocusOutside,
|
|
234
|
+
anchorPoint: popover.anchorPoint
|
|
235
|
+
}
|
|
194
236
|
)
|
|
195
237
|
return (
|
|
196
238
|
<div
|
package/src/cn.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export {
|
|
2
|
+
MenuGroup,
|
|
3
|
+
MenuLabel,
|
|
4
|
+
MenuSeparator,
|
|
5
|
+
MenuCheckboxItem,
|
|
6
|
+
MenuRadioGroup,
|
|
7
|
+
MenuRadioItem,
|
|
8
|
+
MenuSub,
|
|
9
|
+
MenuSubTrigger,
|
|
10
|
+
MenuSubContent
|
|
11
|
+
} from './Menu.js'
|
|
12
|
+
export type {
|
|
13
|
+
MenuGroupProps,
|
|
14
|
+
MenuLabelProps,
|
|
15
|
+
MenuSeparatorProps,
|
|
16
|
+
MenuCheckboxItemProps,
|
|
17
|
+
MenuRadioGroupProps,
|
|
18
|
+
MenuRadioItemProps,
|
|
19
|
+
MenuSubProps,
|
|
20
|
+
MenuSubTriggerProps,
|
|
21
|
+
MenuSubContentProps
|
|
22
|
+
} from './Menu.js'
|
|
1
23
|
export {
|
|
2
24
|
HoverCard,
|
|
3
25
|
HoverCardTrigger,
|
|
@@ -412,3 +434,38 @@ export type {
|
|
|
412
434
|
|
|
413
435
|
export { Toolbar } from './Toolbar.js'
|
|
414
436
|
export type { ToolbarProps, ToolbarOrientation } from './Toolbar.js'
|
|
437
|
+
|
|
438
|
+
export {
|
|
439
|
+
ContextMenu,
|
|
440
|
+
ContextMenuTrigger,
|
|
441
|
+
ContextMenuPortal,
|
|
442
|
+
ContextMenuContent,
|
|
443
|
+
ContextMenuItem,
|
|
444
|
+
ContextMenuGroup,
|
|
445
|
+
ContextMenuLabel,
|
|
446
|
+
ContextMenuSeparator,
|
|
447
|
+
ContextMenuCheckboxItem,
|
|
448
|
+
ContextMenuRadioGroup,
|
|
449
|
+
ContextMenuRadioItem,
|
|
450
|
+
ContextMenuSub,
|
|
451
|
+
ContextMenuSubTrigger,
|
|
452
|
+
ContextMenuSubContent,
|
|
453
|
+
useContextMenu
|
|
454
|
+
} from './ContextMenu.js'
|
|
455
|
+
export type {
|
|
456
|
+
ContextMenuProps,
|
|
457
|
+
ContextMenuTriggerProps,
|
|
458
|
+
ContextMenuPortalProps,
|
|
459
|
+
ContextMenuContentProps,
|
|
460
|
+
ContextMenuItemProps,
|
|
461
|
+
ContextMenuGroupProps,
|
|
462
|
+
ContextMenuLabelProps,
|
|
463
|
+
ContextMenuSeparatorProps,
|
|
464
|
+
ContextMenuCheckboxItemProps,
|
|
465
|
+
ContextMenuRadioGroupProps,
|
|
466
|
+
ContextMenuRadioItemProps,
|
|
467
|
+
ContextMenuSubProps,
|
|
468
|
+
ContextMenuSubTriggerProps,
|
|
469
|
+
ContextMenuSubContentProps,
|
|
470
|
+
ContextMenuState
|
|
471
|
+
} from './ContextMenu.js'
|
|
@@ -13,6 +13,7 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
13
13
|
close: (restore: boolean) => void,
|
|
14
14
|
restoreFocus: RefObject<boolean>,
|
|
15
15
|
options: {
|
|
16
|
+
anchorPoint?: { x: number; y: number }
|
|
16
17
|
initialFocusRef?: RefObject<HTMLElement | null>
|
|
17
18
|
onFocusOutside?: () => void
|
|
18
19
|
side: PopoverSide
|
|
@@ -28,7 +29,7 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
28
29
|
useLayoutEffect(() => {
|
|
29
30
|
latest.current = { ...options, open, close }
|
|
30
31
|
})
|
|
31
|
-
const { side, align, sideOffset, collisionPadding } = options
|
|
32
|
+
const { side, align, sideOffset, collisionPadding, anchorPoint } = options
|
|
32
33
|
|
|
33
34
|
useLayoutEffect(() => {
|
|
34
35
|
const node = nodeRef.current
|
|
@@ -66,7 +67,7 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
66
67
|
const shouldRestore = () => restoreFocus.current
|
|
67
68
|
const place = () => {
|
|
68
69
|
if (!node.isConnected || !node.matches(':popover-open')) return
|
|
69
|
-
const { side, align, sideOffset, collisionPadding } = latest.current
|
|
70
|
+
const { side, align, sideOffset, collisionPadding, anchorPoint } = latest.current
|
|
70
71
|
const viewport = win.visualViewport
|
|
71
72
|
const view = {
|
|
72
73
|
top: viewport?.offsetTop ?? 0,
|
|
@@ -84,7 +85,16 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
84
85
|
)
|
|
85
86
|
const css = win.getComputedStyle(node)
|
|
86
87
|
const next = positionPopover({
|
|
87
|
-
anchor:
|
|
88
|
+
anchor: anchorPoint
|
|
89
|
+
? {
|
|
90
|
+
top: anchorPoint.y,
|
|
91
|
+
bottom: anchorPoint.y,
|
|
92
|
+
left: anchorPoint.x,
|
|
93
|
+
right: anchorPoint.x,
|
|
94
|
+
width: 0,
|
|
95
|
+
height: 0
|
|
96
|
+
}
|
|
97
|
+
: trigger.getBoundingClientRect(),
|
|
88
98
|
width: node.offsetWidth,
|
|
89
99
|
height:
|
|
90
100
|
node.scrollHeight + parseFloat(css.borderTopWidth) + parseFloat(css.borderBottomWidth),
|
|
@@ -217,5 +227,8 @@ export function usePopoverSurface<Node extends HTMLElement>(
|
|
|
217
227
|
reposition.current = () => {}
|
|
218
228
|
}
|
|
219
229
|
}, [nodeRef, trigger, open, generation, restoreFocus])
|
|
220
|
-
useLayoutEffect(
|
|
230
|
+
useLayoutEffect(
|
|
231
|
+
() => reposition.current(),
|
|
232
|
+
[side, align, sideOffset, collisionPadding, anchorPoint?.x, anchorPoint?.y]
|
|
233
|
+
)
|
|
221
234
|
}
|
package/src/themes/components.ts
CHANGED