@choice-ui/react 1.4.2 → 1.4.3
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/command/dist/index.d.ts +2 -2
- package/dist/components/command/src/components/command-input.d.ts +2 -2
- package/dist/components/command/src/components/command-input.js +29 -28
- package/dist/components/command/src/tv.d.ts +3 -12
- package/dist/components/command/src/tv.js +3 -6
- package/dist/components/comments/src/comment-item/tv.d.ts +3 -3
- package/dist/components/popover/dist/index.d.ts +3 -6
- package/dist/components/popover/dist/index.js +27 -13
- package/dist/components/popover/src/hooks/use-floating-popover.d.ts +6 -3
- package/dist/components/popover/src/hooks/use-floating-popover.js +10 -4
- package/dist/components/popover/src/popover.d.ts +3 -6
- package/dist/components/popover/src/popover.js +17 -9
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as react__default, HTMLProps, ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TextFieldProps } from '../../text-field/src';
|
|
3
3
|
import { KbdKey } from '../../kbd/src';
|
|
4
4
|
import { ScrollAreaProps } from '../../scroll-area/src';
|
|
5
5
|
import * as _choice_ui_tabs from '../../tabs/src';
|
|
@@ -15,7 +15,7 @@ interface CommandGroupProps extends HTMLProps<HTMLDivElement> {
|
|
|
15
15
|
value?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface CommandInputProps extends Omit<
|
|
18
|
+
interface CommandInputProps extends Omit<TextFieldProps, "value" | "onChange" | "type"> {
|
|
19
19
|
onChange?: (search: string) => void;
|
|
20
20
|
prefixElement?: ReactNode;
|
|
21
21
|
suffixElement?: ReactNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TextFieldProps } from '../../../text-field/src';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
export interface CommandInputProps extends Omit<
|
|
3
|
+
export interface CommandInputProps extends Omit<TextFieldProps, "value" | "onChange" | "type"> {
|
|
4
4
|
onChange?: (search: string) => void;
|
|
5
5
|
prefixElement?: ReactNode;
|
|
6
6
|
suffixElement?: ReactNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { TextField } from "../../../text-field/dist/index.js";
|
|
3
3
|
import { forwardRef, useEffect } from "react";
|
|
4
4
|
import { useEventCallback } from "usehooks-ts";
|
|
5
5
|
import { commandInputTv } from "../tv.js";
|
|
@@ -25,33 +25,34 @@ const CommandInput = forwardRef((props, ref) => {
|
|
|
25
25
|
onChange == null ? void 0 : onChange(value2);
|
|
26
26
|
});
|
|
27
27
|
const tv = commandInputTv({ size: context.size });
|
|
28
|
-
return /* @__PURE__ */ jsxs(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
return /* @__PURE__ */ jsxs(
|
|
29
|
+
TextField,
|
|
30
|
+
{
|
|
31
|
+
ref,
|
|
32
|
+
...rest,
|
|
33
|
+
className: tcx(tv.input({ className })),
|
|
34
|
+
size: "large",
|
|
35
|
+
variant: props.variant || context.variant,
|
|
36
|
+
"data-command-input": "",
|
|
37
|
+
autoComplete: "off",
|
|
38
|
+
autoCorrect: "off",
|
|
39
|
+
spellCheck: false,
|
|
40
|
+
"aria-autocomplete": "list",
|
|
41
|
+
role: "combobox",
|
|
42
|
+
"aria-expanded": true,
|
|
43
|
+
"aria-controls": context.listId,
|
|
44
|
+
"aria-labelledby": context.labelId,
|
|
45
|
+
"aria-activedescendant": selectedItemId,
|
|
46
|
+
id: context.inputId,
|
|
47
|
+
type: "text",
|
|
48
|
+
value: isControlled ? value : search,
|
|
49
|
+
onChange: handleChange,
|
|
50
|
+
children: [
|
|
51
|
+
prefixElement && /* @__PURE__ */ jsx(TextField.Prefix, { children: prefixElement }),
|
|
52
|
+
suffixElement && /* @__PURE__ */ jsx(TextField.Suffix, { children: suffixElement })
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
);
|
|
55
56
|
});
|
|
56
57
|
CommandInput.displayName = "CommandInput";
|
|
57
58
|
export {
|
|
@@ -43,39 +43,30 @@ export declare const commandTv: import('tailwind-variants').TVReturnType<{
|
|
|
43
43
|
}, undefined, unknown, unknown, undefined>>;
|
|
44
44
|
export declare const commandInputTv: import('tailwind-variants').TVReturnType<{
|
|
45
45
|
size: {
|
|
46
|
-
default: {
|
|
47
|
-
input: string;
|
|
48
|
-
};
|
|
46
|
+
default: {};
|
|
49
47
|
large: {
|
|
50
48
|
input: string;
|
|
51
49
|
};
|
|
52
50
|
};
|
|
53
51
|
}, {
|
|
54
|
-
root: string;
|
|
55
52
|
input: string;
|
|
56
53
|
}, undefined, {
|
|
57
54
|
size: {
|
|
58
|
-
default: {
|
|
59
|
-
input: string;
|
|
60
|
-
};
|
|
55
|
+
default: {};
|
|
61
56
|
large: {
|
|
62
57
|
input: string;
|
|
63
58
|
};
|
|
64
59
|
};
|
|
65
60
|
}, {
|
|
66
|
-
root: string;
|
|
67
61
|
input: string;
|
|
68
62
|
}, import('tailwind-variants').TVReturnType<{
|
|
69
63
|
size: {
|
|
70
|
-
default: {
|
|
71
|
-
input: string;
|
|
72
|
-
};
|
|
64
|
+
default: {};
|
|
73
65
|
large: {
|
|
74
66
|
input: string;
|
|
75
67
|
};
|
|
76
68
|
};
|
|
77
69
|
}, {
|
|
78
|
-
root: string;
|
|
79
70
|
input: string;
|
|
80
71
|
}, undefined, unknown, unknown, undefined>>;
|
|
81
72
|
export declare const commandListTv: import('tailwind-variants').TVReturnType<{
|
|
@@ -19,16 +19,13 @@ const commandTv = tcv({
|
|
|
19
19
|
});
|
|
20
20
|
const commandInputTv = tcv({
|
|
21
21
|
slots: {
|
|
22
|
-
|
|
23
|
-
input: "w-full rounded-lg"
|
|
22
|
+
input: "m-2"
|
|
24
23
|
},
|
|
25
24
|
variants: {
|
|
26
25
|
size: {
|
|
27
|
-
default: {
|
|
28
|
-
input: "text-body-medium h-8 px-2"
|
|
29
|
-
},
|
|
26
|
+
default: {},
|
|
30
27
|
large: {
|
|
31
|
-
input: "leading-lg tracking-lg
|
|
28
|
+
input: "leading-lg tracking-lg px-4 text-body-large"
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
},
|
|
@@ -4,8 +4,8 @@ export declare const CommentItemTv: import('tailwind-variants').TVReturnType<{
|
|
|
4
4
|
meta?: import('tailwind-merge').ClassNameValue;
|
|
5
5
|
content?: import('tailwind-merge').ClassNameValue;
|
|
6
6
|
date?: import('tailwind-merge').ClassNameValue;
|
|
7
|
-
name?: import('tailwind-merge').ClassNameValue;
|
|
8
7
|
root?: import('tailwind-merge').ClassNameValue;
|
|
8
|
+
name?: import('tailwind-merge').ClassNameValue;
|
|
9
9
|
avatar?: import('tailwind-merge').ClassNameValue;
|
|
10
10
|
actionMenu?: import('tailwind-merge').ClassNameValue;
|
|
11
11
|
};
|
|
@@ -16,8 +16,8 @@ export declare const CommentItemTv: import('tailwind-variants').TVReturnType<{
|
|
|
16
16
|
meta?: import('tailwind-merge').ClassNameValue;
|
|
17
17
|
content?: import('tailwind-merge').ClassNameValue;
|
|
18
18
|
date?: import('tailwind-merge').ClassNameValue;
|
|
19
|
-
name?: import('tailwind-merge').ClassNameValue;
|
|
20
19
|
root?: import('tailwind-merge').ClassNameValue;
|
|
20
|
+
name?: import('tailwind-merge').ClassNameValue;
|
|
21
21
|
avatar?: import('tailwind-merge').ClassNameValue;
|
|
22
22
|
actionMenu?: import('tailwind-merge').ClassNameValue;
|
|
23
23
|
};
|
|
@@ -36,8 +36,8 @@ export declare const CommentItemTv: import('tailwind-variants').TVReturnType<{
|
|
|
36
36
|
meta?: import('tailwind-merge').ClassNameValue;
|
|
37
37
|
content?: import('tailwind-merge').ClassNameValue;
|
|
38
38
|
date?: import('tailwind-merge').ClassNameValue;
|
|
39
|
-
name?: import('tailwind-merge').ClassNameValue;
|
|
40
39
|
root?: import('tailwind-merge').ClassNameValue;
|
|
40
|
+
name?: import('tailwind-merge').ClassNameValue;
|
|
41
41
|
avatar?: import('tailwind-merge').ClassNameValue;
|
|
42
42
|
actionMenu?: import('tailwind-merge').ClassNameValue;
|
|
43
43
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModalHeaderProps, ModalContent, ModalFooter } from '../../modal/src';
|
|
2
|
-
import { FloatingFocusManagerProps, Placement } from '@floating-ui/react';
|
|
2
|
+
import { FloatingFocusManagerProps, OffsetOptions, Placement, UseTransitionStylesProps } from '@floating-ui/react';
|
|
3
3
|
import { default as react__default } from 'react';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
|
|
@@ -23,14 +23,10 @@ interface PopoverProps {
|
|
|
23
23
|
};
|
|
24
24
|
draggable?: boolean;
|
|
25
25
|
focusManagerProps?: Partial<FloatingFocusManagerProps>;
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated use focusManagerProps.initialFocus instead
|
|
28
|
-
*/
|
|
29
|
-
initialFocus?: number | react__default.MutableRefObject<HTMLElement | null>;
|
|
30
26
|
interactions?: "hover" | "click" | "focus" | "none";
|
|
31
27
|
matchTriggerWidth?: boolean;
|
|
32
28
|
maxWidth?: number;
|
|
33
|
-
offset?:
|
|
29
|
+
offset?: OffsetOptions;
|
|
34
30
|
onOpenChange?: (isOpen: boolean) => void;
|
|
35
31
|
open?: boolean;
|
|
36
32
|
outsidePressIgnore?: string | string[] | boolean;
|
|
@@ -44,6 +40,7 @@ interface PopoverProps {
|
|
|
44
40
|
*/
|
|
45
41
|
root?: HTMLElement | null;
|
|
46
42
|
triggerRef?: react__default.RefObject<HTMLElement>;
|
|
43
|
+
transitionStylesProps?: UseTransitionStylesProps;
|
|
47
44
|
}
|
|
48
45
|
declare const DragPopover: react__default.NamedExoticComponent<PopoverProps>;
|
|
49
46
|
interface PopoverComponent extends react__default.FC<PopoverProps> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Slot } from "../../slot/dist/index.js";
|
|
2
1
|
import { ModalFooter, ModalContent, ModalHeader, Modal } from "../../modal/dist/index.js";
|
|
3
|
-
import {
|
|
2
|
+
import { Slot } from "../../slot/dist/index.js";
|
|
3
|
+
import { useFloatingParentNodeId, FloatingTree, useFloatingNodeId, FloatingNode, FloatingFocusManager, FloatingPortal, offset, flip, shift, size, useFloating, autoUpdate, useTransitionStyles, useHover, safePolygon, useClick, useFocus, useDismiss, useRole, useInteractions } from "@floating-ui/react";
|
|
4
4
|
import { memo, forwardRef, useId, useRef, useEffect, useMemo, useCallback, createContext, useContext, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { useEventCallback } from "usehooks-ts";
|
|
@@ -202,7 +202,7 @@ function useFloatingPopover({
|
|
|
202
202
|
defaultOpen,
|
|
203
203
|
onOpenChange,
|
|
204
204
|
placement = "bottom",
|
|
205
|
-
offset: offsetDistance = 8,
|
|
205
|
+
offset: offsetDistance = { mainAxis: 8, crossAxis: 0 },
|
|
206
206
|
interactions = "click",
|
|
207
207
|
outsidePressIgnore,
|
|
208
208
|
delay,
|
|
@@ -215,7 +215,10 @@ function useFloatingPopover({
|
|
|
215
215
|
rememberPosition = false,
|
|
216
216
|
autoSize = true,
|
|
217
217
|
maxWidth: maxWidthValue = 320,
|
|
218
|
-
matchTriggerWidth = false
|
|
218
|
+
matchTriggerWidth = false,
|
|
219
|
+
transitionStylesProps = {
|
|
220
|
+
duration: 0
|
|
221
|
+
}
|
|
219
222
|
}) {
|
|
220
223
|
const [isClosing, setIsClosing] = useState(false);
|
|
221
224
|
const positionRef = useRef({ x: 0, y: 0 });
|
|
@@ -275,6 +278,7 @@ function useFloatingPopover({
|
|
|
275
278
|
middleware,
|
|
276
279
|
whileElementsMounted: autoUpdate$1 ? autoUpdate : void 0
|
|
277
280
|
});
|
|
281
|
+
const { isMounted, styles } = useTransitionStyles(context, transitionStylesProps);
|
|
278
282
|
useEffect(() => {
|
|
279
283
|
if (innerOpen && isPositioned && x !== null && y !== null) {
|
|
280
284
|
positionRef.current = { x, y };
|
|
@@ -387,7 +391,9 @@ function useFloatingPopover({
|
|
|
387
391
|
getStyles,
|
|
388
392
|
handleClose,
|
|
389
393
|
handleTriggerRef,
|
|
390
|
-
isClosing
|
|
394
|
+
isClosing,
|
|
395
|
+
isMounted,
|
|
396
|
+
styles
|
|
391
397
|
};
|
|
392
398
|
}
|
|
393
399
|
var PORTAL_ROOT_ID = "floating-popover-root";
|
|
@@ -399,7 +405,7 @@ var DragPopover = memo(function DragPopover2({
|
|
|
399
405
|
draggable = false,
|
|
400
406
|
placement = "bottom",
|
|
401
407
|
interactions = "click",
|
|
402
|
-
offset: offsetDistance = DEFAULT_OFFSET,
|
|
408
|
+
offset: offsetDistance = { mainAxis: DEFAULT_OFFSET, crossAxis: 0 },
|
|
403
409
|
open,
|
|
404
410
|
onOpenChange,
|
|
405
411
|
defaultOpen,
|
|
@@ -407,7 +413,6 @@ var DragPopover = memo(function DragPopover2({
|
|
|
407
413
|
closeOnEscape = true,
|
|
408
414
|
contentRef,
|
|
409
415
|
delay,
|
|
410
|
-
initialFocus,
|
|
411
416
|
focusManagerProps = {
|
|
412
417
|
returnFocus: true,
|
|
413
418
|
guards: false,
|
|
@@ -419,7 +424,8 @@ var DragPopover = memo(function DragPopover2({
|
|
|
419
424
|
autoSize = true,
|
|
420
425
|
rememberPosition = false,
|
|
421
426
|
maxWidth,
|
|
422
|
-
matchTriggerWidth = false
|
|
427
|
+
matchTriggerWidth = false,
|
|
428
|
+
transitionStylesProps
|
|
423
429
|
}) {
|
|
424
430
|
const titleId = useId();
|
|
425
431
|
const descriptionId = useId();
|
|
@@ -454,7 +460,8 @@ var DragPopover = memo(function DragPopover2({
|
|
|
454
460
|
closeOnEscape,
|
|
455
461
|
rememberPosition,
|
|
456
462
|
resetDragState,
|
|
457
|
-
resetPosition
|
|
463
|
+
resetPosition,
|
|
464
|
+
transitionStylesProps
|
|
458
465
|
});
|
|
459
466
|
useEffect(() => {
|
|
460
467
|
if (externalTriggerRef) {
|
|
@@ -464,6 +471,15 @@ var DragPopover = memo(function DragPopover2({
|
|
|
464
471
|
const combinedStyles = useMemo(() => {
|
|
465
472
|
return floating.getStyles(dragState.position, dragState.isDragging);
|
|
466
473
|
}, [floating, dragState.position, dragState.isDragging]);
|
|
474
|
+
const transitionStyles = useMemo(() => {
|
|
475
|
+
if (draggable && dragState.isDragging) {
|
|
476
|
+
return { ...floating.styles, transition: "none" };
|
|
477
|
+
}
|
|
478
|
+
if (floating.styles.transition) {
|
|
479
|
+
return { ...floating.styles, transition: floating.styles.transition };
|
|
480
|
+
}
|
|
481
|
+
return floating.styles;
|
|
482
|
+
}, [floating.styles, draggable, dragState.isDragging]);
|
|
467
483
|
const handleFloatingRef = useCallback(
|
|
468
484
|
(node) => {
|
|
469
485
|
floating.refs.setFloating(node);
|
|
@@ -534,7 +550,6 @@ var DragPopover = memo(function DragPopover2({
|
|
|
534
550
|
externalTriggerRef,
|
|
535
551
|
draggable,
|
|
536
552
|
handleDragStart
|
|
537
|
-
// titleId, descriptionId, dragContentRef 是稳定的,移除
|
|
538
553
|
]
|
|
539
554
|
);
|
|
540
555
|
return /* @__PURE__ */ jsx(FloatingNode, { id: nodeId, children: /* @__PURE__ */ jsxs(PopoverContext.Provider, { value: contextValue, children: [
|
|
@@ -542,7 +557,6 @@ var DragPopover = memo(function DragPopover2({
|
|
|
542
557
|
/* @__PURE__ */ jsx(
|
|
543
558
|
FloatingFocusManager,
|
|
544
559
|
{
|
|
545
|
-
initialFocus,
|
|
546
560
|
...focusManagerProps,
|
|
547
561
|
context: floating.context,
|
|
548
562
|
children: /* @__PURE__ */ jsx(
|
|
@@ -550,7 +564,7 @@ var DragPopover = memo(function DragPopover2({
|
|
|
550
564
|
{
|
|
551
565
|
id: portalId,
|
|
552
566
|
root,
|
|
553
|
-
children: floating.innerOpen && /* @__PURE__ */ jsxs(
|
|
567
|
+
children: floating.innerOpen && floating.isMounted && /* @__PURE__ */ jsx("div", { style: transitionStyles, children: /* @__PURE__ */ jsxs(
|
|
554
568
|
Modal,
|
|
555
569
|
{
|
|
556
570
|
ref: handleFloatingRef,
|
|
@@ -571,7 +585,7 @@ var DragPopover = memo(function DragPopover2({
|
|
|
571
585
|
footerContent
|
|
572
586
|
]
|
|
573
587
|
}
|
|
574
|
-
)
|
|
588
|
+
) })
|
|
575
589
|
}
|
|
576
590
|
)
|
|
577
591
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FloatingContext, Placement, ReferenceType } from '@floating-ui/react';
|
|
1
|
+
import { FloatingContext, OffsetOptions, Placement, ReferenceType, UseTransitionStylesProps } from '@floating-ui/react';
|
|
2
2
|
import { RefObject } from 'react';
|
|
3
3
|
interface UseFloatingPopoverReturn {
|
|
4
4
|
context: FloatingContext;
|
|
@@ -12,6 +12,7 @@ interface UseFloatingPopoverReturn {
|
|
|
12
12
|
handleTriggerRef: (triggerRef: RefObject<HTMLElement | null>) => void;
|
|
13
13
|
innerOpen: boolean;
|
|
14
14
|
isClosing: boolean;
|
|
15
|
+
isMounted: boolean;
|
|
15
16
|
positionReady: boolean;
|
|
16
17
|
refs: {
|
|
17
18
|
floating: React.MutableRefObject<HTMLElement | null>;
|
|
@@ -26,6 +27,7 @@ interface UseFloatingPopoverReturn {
|
|
|
26
27
|
}>;
|
|
27
28
|
x: number | null;
|
|
28
29
|
y: number | null;
|
|
30
|
+
styles: React.CSSProperties;
|
|
29
31
|
}
|
|
30
32
|
interface UseFloatingPopoverParams {
|
|
31
33
|
autoSize?: boolean;
|
|
@@ -41,7 +43,7 @@ interface UseFloatingPopoverParams {
|
|
|
41
43
|
matchTriggerWidth?: boolean;
|
|
42
44
|
maxWidth?: number;
|
|
43
45
|
nodeId: string | undefined;
|
|
44
|
-
offset?:
|
|
46
|
+
offset?: OffsetOptions;
|
|
45
47
|
onOpenChange?: (open: boolean) => void;
|
|
46
48
|
open?: boolean;
|
|
47
49
|
outsidePressIgnore?: string | string[] | boolean;
|
|
@@ -49,6 +51,7 @@ interface UseFloatingPopoverParams {
|
|
|
49
51
|
rememberPosition?: boolean;
|
|
50
52
|
resetDragState: () => void;
|
|
51
53
|
resetPosition: () => void;
|
|
54
|
+
transitionStylesProps?: UseTransitionStylesProps;
|
|
52
55
|
}
|
|
53
|
-
export declare function useFloatingPopover({ open, defaultOpen, onOpenChange, placement, offset: offsetDistance, interactions, outsidePressIgnore, delay, autoUpdate, closeOnEscape, draggable, nodeId, resetDragState, resetPosition, rememberPosition, autoSize, maxWidth: maxWidthValue, matchTriggerWidth, }: UseFloatingPopoverParams): UseFloatingPopoverReturn;
|
|
56
|
+
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;
|
|
54
57
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { offset, flip, shift, size, useFloating, autoUpdate, useHover, safePolygon, useClick, useFocus, useDismiss, useRole, useInteractions } from "@floating-ui/react";
|
|
1
|
+
import { offset, flip, shift, size, useFloating, autoUpdate, useTransitionStyles, useHover, safePolygon, useClick, useFocus, useDismiss, useRole, useInteractions } from "@floating-ui/react";
|
|
2
2
|
import { useState, useRef, useMemo, useEffect, useCallback } from "react";
|
|
3
3
|
import { useEventCallback } from "usehooks-ts";
|
|
4
4
|
import { useMergedValue } from "../../../../shared/hooks/use-merged-value/use-merged-value.js";
|
|
@@ -7,7 +7,7 @@ function useFloatingPopover({
|
|
|
7
7
|
defaultOpen,
|
|
8
8
|
onOpenChange,
|
|
9
9
|
placement = "bottom",
|
|
10
|
-
offset: offsetDistance = 8,
|
|
10
|
+
offset: offsetDistance = { mainAxis: 8, crossAxis: 0 },
|
|
11
11
|
interactions = "click",
|
|
12
12
|
outsidePressIgnore,
|
|
13
13
|
delay,
|
|
@@ -20,7 +20,10 @@ function useFloatingPopover({
|
|
|
20
20
|
rememberPosition = false,
|
|
21
21
|
autoSize = true,
|
|
22
22
|
maxWidth: maxWidthValue = 320,
|
|
23
|
-
matchTriggerWidth = false
|
|
23
|
+
matchTriggerWidth = false,
|
|
24
|
+
transitionStylesProps = {
|
|
25
|
+
duration: 0
|
|
26
|
+
}
|
|
24
27
|
}) {
|
|
25
28
|
const [isClosing, setIsClosing] = useState(false);
|
|
26
29
|
const positionRef = useRef({ x: 0, y: 0 });
|
|
@@ -80,6 +83,7 @@ function useFloatingPopover({
|
|
|
80
83
|
middleware,
|
|
81
84
|
whileElementsMounted: autoUpdate$1 ? autoUpdate : void 0
|
|
82
85
|
});
|
|
86
|
+
const { isMounted, styles } = useTransitionStyles(context, transitionStylesProps);
|
|
83
87
|
useEffect(() => {
|
|
84
88
|
if (innerOpen && isPositioned && x !== null && y !== null) {
|
|
85
89
|
positionRef.current = { x, y };
|
|
@@ -192,7 +196,9 @@ function useFloatingPopover({
|
|
|
192
196
|
getStyles,
|
|
193
197
|
handleClose,
|
|
194
198
|
handleTriggerRef,
|
|
195
|
-
isClosing
|
|
199
|
+
isClosing,
|
|
200
|
+
isMounted,
|
|
201
|
+
styles
|
|
196
202
|
};
|
|
197
203
|
}
|
|
198
204
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModalContent, ModalFooter } from '../../modal/src';
|
|
2
|
-
import { FloatingFocusManagerProps, Placement } from '@floating-ui/react';
|
|
2
|
+
import { FloatingFocusManagerProps, OffsetOptions, Placement, UseTransitionStylesProps } from '@floating-ui/react';
|
|
3
3
|
import { default as React } from 'react';
|
|
4
4
|
import { PopoverHeader, PopoverTrigger } from './components';
|
|
5
5
|
export interface PopoverProps {
|
|
@@ -16,14 +16,10 @@ export interface PopoverProps {
|
|
|
16
16
|
};
|
|
17
17
|
draggable?: boolean;
|
|
18
18
|
focusManagerProps?: Partial<FloatingFocusManagerProps>;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated use focusManagerProps.initialFocus instead
|
|
21
|
-
*/
|
|
22
|
-
initialFocus?: number | React.MutableRefObject<HTMLElement | null>;
|
|
23
19
|
interactions?: "hover" | "click" | "focus" | "none";
|
|
24
20
|
matchTriggerWidth?: boolean;
|
|
25
21
|
maxWidth?: number;
|
|
26
|
-
offset?:
|
|
22
|
+
offset?: OffsetOptions;
|
|
27
23
|
onOpenChange?: (isOpen: boolean) => void;
|
|
28
24
|
open?: boolean;
|
|
29
25
|
outsidePressIgnore?: string | string[] | boolean;
|
|
@@ -37,6 +33,7 @@ export interface PopoverProps {
|
|
|
37
33
|
*/
|
|
38
34
|
root?: HTMLElement | null;
|
|
39
35
|
triggerRef?: React.RefObject<HTMLElement>;
|
|
36
|
+
transitionStylesProps?: UseTransitionStylesProps;
|
|
40
37
|
}
|
|
41
38
|
export declare const DragPopover: React.NamedExoticComponent<PopoverProps>;
|
|
42
39
|
interface PopoverComponent extends React.FC<PopoverProps> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Slot } from "../../slot/dist/index.js";
|
|
3
2
|
import { Modal, ModalFooter, ModalContent } from "../../modal/dist/index.js";
|
|
3
|
+
import { Slot } from "../../slot/dist/index.js";
|
|
4
4
|
import { useFloatingNodeId, FloatingNode, FloatingFocusManager, FloatingPortal, useFloatingParentNodeId, FloatingTree } from "@floating-ui/react";
|
|
5
5
|
import { memo, useId, useRef, useEffect, useMemo, useCallback } from "react";
|
|
6
6
|
import { PopoverContext } from "./popover-context.js";
|
|
@@ -20,7 +20,7 @@ const DragPopover = memo(function DragPopover2({
|
|
|
20
20
|
draggable = false,
|
|
21
21
|
placement = "bottom",
|
|
22
22
|
interactions = "click",
|
|
23
|
-
offset: offsetDistance = DEFAULT_OFFSET,
|
|
23
|
+
offset: offsetDistance = { mainAxis: DEFAULT_OFFSET, crossAxis: 0 },
|
|
24
24
|
open,
|
|
25
25
|
onOpenChange,
|
|
26
26
|
defaultOpen,
|
|
@@ -28,7 +28,6 @@ const DragPopover = memo(function DragPopover2({
|
|
|
28
28
|
closeOnEscape = true,
|
|
29
29
|
contentRef,
|
|
30
30
|
delay,
|
|
31
|
-
initialFocus,
|
|
32
31
|
focusManagerProps = {
|
|
33
32
|
returnFocus: true,
|
|
34
33
|
guards: false,
|
|
@@ -40,7 +39,8 @@ const DragPopover = memo(function DragPopover2({
|
|
|
40
39
|
autoSize = true,
|
|
41
40
|
rememberPosition = false,
|
|
42
41
|
maxWidth,
|
|
43
|
-
matchTriggerWidth = false
|
|
42
|
+
matchTriggerWidth = false,
|
|
43
|
+
transitionStylesProps
|
|
44
44
|
}) {
|
|
45
45
|
const titleId = useId();
|
|
46
46
|
const descriptionId = useId();
|
|
@@ -75,7 +75,8 @@ const DragPopover = memo(function DragPopover2({
|
|
|
75
75
|
closeOnEscape,
|
|
76
76
|
rememberPosition,
|
|
77
77
|
resetDragState,
|
|
78
|
-
resetPosition
|
|
78
|
+
resetPosition,
|
|
79
|
+
transitionStylesProps
|
|
79
80
|
});
|
|
80
81
|
useEffect(() => {
|
|
81
82
|
if (externalTriggerRef) {
|
|
@@ -85,6 +86,15 @@ const DragPopover = memo(function DragPopover2({
|
|
|
85
86
|
const combinedStyles = useMemo(() => {
|
|
86
87
|
return floating.getStyles(dragState.position, dragState.isDragging);
|
|
87
88
|
}, [floating, dragState.position, dragState.isDragging]);
|
|
89
|
+
const transitionStyles = useMemo(() => {
|
|
90
|
+
if (draggable && dragState.isDragging) {
|
|
91
|
+
return { ...floating.styles, transition: "none" };
|
|
92
|
+
}
|
|
93
|
+
if (floating.styles.transition) {
|
|
94
|
+
return { ...floating.styles, transition: floating.styles.transition };
|
|
95
|
+
}
|
|
96
|
+
return floating.styles;
|
|
97
|
+
}, [floating.styles, draggable, dragState.isDragging]);
|
|
88
98
|
const handleFloatingRef = useCallback(
|
|
89
99
|
(node) => {
|
|
90
100
|
floating.refs.setFloating(node);
|
|
@@ -155,7 +165,6 @@ const DragPopover = memo(function DragPopover2({
|
|
|
155
165
|
externalTriggerRef,
|
|
156
166
|
draggable,
|
|
157
167
|
handleDragStart
|
|
158
|
-
// titleId, descriptionId, dragContentRef 是稳定的,移除
|
|
159
168
|
]
|
|
160
169
|
);
|
|
161
170
|
return /* @__PURE__ */ jsx(FloatingNode, { id: nodeId, children: /* @__PURE__ */ jsxs(PopoverContext.Provider, { value: contextValue, children: [
|
|
@@ -163,7 +172,6 @@ const DragPopover = memo(function DragPopover2({
|
|
|
163
172
|
/* @__PURE__ */ jsx(
|
|
164
173
|
FloatingFocusManager,
|
|
165
174
|
{
|
|
166
|
-
initialFocus,
|
|
167
175
|
...focusManagerProps,
|
|
168
176
|
context: floating.context,
|
|
169
177
|
children: /* @__PURE__ */ jsx(
|
|
@@ -171,7 +179,7 @@ const DragPopover = memo(function DragPopover2({
|
|
|
171
179
|
{
|
|
172
180
|
id: portalId,
|
|
173
181
|
root,
|
|
174
|
-
children: floating.innerOpen && /* @__PURE__ */ jsxs(
|
|
182
|
+
children: floating.innerOpen && floating.isMounted && /* @__PURE__ */ jsx("div", { style: transitionStyles, children: /* @__PURE__ */ jsxs(
|
|
175
183
|
Modal,
|
|
176
184
|
{
|
|
177
185
|
ref: handleFloatingRef,
|
|
@@ -192,7 +200,7 @@ const DragPopover = memo(function DragPopover2({
|
|
|
192
200
|
footerContent
|
|
193
201
|
]
|
|
194
202
|
}
|
|
195
|
-
)
|
|
203
|
+
) })
|
|
196
204
|
}
|
|
197
205
|
)
|
|
198
206
|
}
|
package/package.json
CHANGED