@choice-ui/react 1.6.6 → 1.6.7
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/popover/dist/index.d.ts +5 -0
- package/dist/components/popover/dist/index.js +21 -2
- package/dist/components/popover/src/hooks/use-floating-popover.d.ts +2 -1
- package/dist/components/popover/src/hooks/use-floating-popover.js +18 -1
- package/dist/components/popover/src/popover.d.ts +5 -0
- package/dist/components/popover/src/popover.js +3 -1
- package/package.json +2 -2
|
@@ -41,6 +41,11 @@ interface PopoverProps extends Omit<React__default.HTMLAttributes<HTMLElement>,
|
|
|
41
41
|
*/
|
|
42
42
|
root?: HTMLElement | null;
|
|
43
43
|
triggerRef?: React__default.RefObject<HTMLElement>;
|
|
44
|
+
/**
|
|
45
|
+
* CSS selector string to find the trigger element in the DOM.
|
|
46
|
+
* Alternative to triggerRef for cases where you want to use a selector instead of a ref.
|
|
47
|
+
*/
|
|
48
|
+
triggerSelector?: string;
|
|
44
49
|
}
|
|
45
50
|
interface PopoverComponent extends React__default.FC<PopoverProps> {
|
|
46
51
|
Content: typeof ModalContent;
|
|
@@ -221,7 +221,8 @@ function useFloatingPopover({
|
|
|
221
221
|
matchTriggerWidth = false,
|
|
222
222
|
transitionStylesProps = {
|
|
223
223
|
duration: 0
|
|
224
|
-
}
|
|
224
|
+
},
|
|
225
|
+
triggerSelector
|
|
225
226
|
}) {
|
|
226
227
|
const [isClosing, setIsClosing] = useState(false);
|
|
227
228
|
const positionRef = useRef({ x: 0, y: 0 });
|
|
@@ -385,6 +386,22 @@ function useFloatingPopover({
|
|
|
385
386
|
},
|
|
386
387
|
[refs]
|
|
387
388
|
);
|
|
389
|
+
const isOpenRef = useRef(innerOpen);
|
|
390
|
+
isOpenRef.current = innerOpen;
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
if (!triggerSelector) return;
|
|
393
|
+
const element = document.querySelector(triggerSelector);
|
|
394
|
+
if (!element) return;
|
|
395
|
+
refs.setReference(element);
|
|
396
|
+
const handleClick = (e) => {
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
handleOpenChange(!isOpenRef.current);
|
|
399
|
+
};
|
|
400
|
+
element.addEventListener("click", handleClick);
|
|
401
|
+
return () => {
|
|
402
|
+
element.removeEventListener("click", handleClick);
|
|
403
|
+
};
|
|
404
|
+
}, [triggerSelector, refs, handleOpenChange]);
|
|
388
405
|
return {
|
|
389
406
|
refs,
|
|
390
407
|
triggerRefs,
|
|
@@ -409,6 +426,7 @@ var DragPopover = memo(function DragPopover2({
|
|
|
409
426
|
className,
|
|
410
427
|
children,
|
|
411
428
|
triggerRef: externalTriggerRef,
|
|
429
|
+
triggerSelector,
|
|
412
430
|
draggable = false,
|
|
413
431
|
placement = "bottom",
|
|
414
432
|
interactions = "click",
|
|
@@ -467,7 +485,8 @@ var DragPopover = memo(function DragPopover2({
|
|
|
467
485
|
closeOnEscape,
|
|
468
486
|
rememberPosition,
|
|
469
487
|
resetDragState,
|
|
470
|
-
resetPosition
|
|
488
|
+
resetPosition,
|
|
489
|
+
triggerSelector
|
|
471
490
|
});
|
|
472
491
|
useEffect(() => {
|
|
473
492
|
if (externalTriggerRef) {
|
|
@@ -50,6 +50,7 @@ interface UseFloatingPopoverParams {
|
|
|
50
50
|
resetDragState: () => void;
|
|
51
51
|
resetPosition: () => void;
|
|
52
52
|
transitionStylesProps?: UseTransitionStylesProps;
|
|
53
|
+
triggerSelector?: string;
|
|
53
54
|
}
|
|
54
|
-
export declare function useFloatingPopover({ open, defaultOpen, onOpenChange, placement, offset: offsetDistance, interactions, outsidePressIgnore, delay, autoUpdate, closeOnEscape, draggable, nodeId, resetDragState, resetPosition, rememberPosition, autoSize, maxWidth: maxWidthValue, matchTriggerWidth, transitionStylesProps, }: UseFloatingPopoverParams): UseFloatingPopoverReturn;
|
|
55
|
+
export declare function useFloatingPopover({ open, defaultOpen, onOpenChange, placement, offset: offsetDistance, interactions, outsidePressIgnore, delay, autoUpdate, closeOnEscape, draggable, nodeId, resetDragState, resetPosition, rememberPosition, autoSize, maxWidth: maxWidthValue, matchTriggerWidth, transitionStylesProps, triggerSelector, }: UseFloatingPopoverParams): UseFloatingPopoverReturn;
|
|
55
56
|
export {};
|
|
@@ -23,7 +23,8 @@ function useFloatingPopover({
|
|
|
23
23
|
matchTriggerWidth = false,
|
|
24
24
|
transitionStylesProps = {
|
|
25
25
|
duration: 0
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
|
+
triggerSelector
|
|
27
28
|
}) {
|
|
28
29
|
const [isClosing, setIsClosing] = useState(false);
|
|
29
30
|
const positionRef = useRef({ x: 0, y: 0 });
|
|
@@ -187,6 +188,22 @@ function useFloatingPopover({
|
|
|
187
188
|
},
|
|
188
189
|
[refs]
|
|
189
190
|
);
|
|
191
|
+
const isOpenRef = useRef(innerOpen);
|
|
192
|
+
isOpenRef.current = innerOpen;
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
if (!triggerSelector) return;
|
|
195
|
+
const element = document.querySelector(triggerSelector);
|
|
196
|
+
if (!element) return;
|
|
197
|
+
refs.setReference(element);
|
|
198
|
+
const handleClick = (e) => {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
handleOpenChange(!isOpenRef.current);
|
|
201
|
+
};
|
|
202
|
+
element.addEventListener("click", handleClick);
|
|
203
|
+
return () => {
|
|
204
|
+
element.removeEventListener("click", handleClick);
|
|
205
|
+
};
|
|
206
|
+
}, [triggerSelector, refs, handleOpenChange]);
|
|
190
207
|
return {
|
|
191
208
|
refs,
|
|
192
209
|
triggerRefs,
|
|
@@ -34,6 +34,11 @@ export interface PopoverProps extends Omit<React.HTMLAttributes<HTMLElement>, "t
|
|
|
34
34
|
*/
|
|
35
35
|
root?: HTMLElement | null;
|
|
36
36
|
triggerRef?: React.RefObject<HTMLElement>;
|
|
37
|
+
/**
|
|
38
|
+
* CSS selector string to find the trigger element in the DOM.
|
|
39
|
+
* Alternative to triggerRef for cases where you want to use a selector instead of a ref.
|
|
40
|
+
*/
|
|
41
|
+
triggerSelector?: string;
|
|
37
42
|
}
|
|
38
43
|
export declare const DragPopover: React.NamedExoticComponent<PopoverProps>;
|
|
39
44
|
interface PopoverComponent extends React.FC<PopoverProps> {
|
|
@@ -18,6 +18,7 @@ const DragPopover = memo(function DragPopover2({
|
|
|
18
18
|
className,
|
|
19
19
|
children,
|
|
20
20
|
triggerRef: externalTriggerRef,
|
|
21
|
+
triggerSelector,
|
|
21
22
|
draggable = false,
|
|
22
23
|
placement = "bottom",
|
|
23
24
|
interactions = "click",
|
|
@@ -76,7 +77,8 @@ const DragPopover = memo(function DragPopover2({
|
|
|
76
77
|
closeOnEscape,
|
|
77
78
|
rememberPosition,
|
|
78
79
|
resetDragState,
|
|
79
|
-
resetPosition
|
|
80
|
+
resetPosition,
|
|
81
|
+
triggerSelector
|
|
80
82
|
});
|
|
81
83
|
useEffect(() => {
|
|
82
84
|
if (externalTriggerRef) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choice-ui/react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
4
4
|
"description": "A desktop-first React UI component library built for professional desktop applications with comprehensive documentation",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"remark-math": "^6.0.0",
|
|
61
61
|
"harden-react-markdown": "^1.0.4",
|
|
62
62
|
"shiki": "^3.9.2",
|
|
63
|
-
"@choice-ui/design-tokens": "0.2.
|
|
63
|
+
"@choice-ui/design-tokens": "0.2.13"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@babel/core": "^7.27.1",
|