@choice-ui/react 1.5.6 → 1.5.8
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/calendar/dist/index.d.ts +17 -2
- package/dist/components/calendar/dist/index.js +59 -203
- package/dist/components/calendar/src/time-calendar/time-calendar.d.ts +18 -2
- package/dist/components/calendar/src/time-calendar/time-calendar.js +59 -202
- package/dist/components/calendar/src/utils/time.js +1 -1
- package/dist/components/dropdown/dist/index.js +41 -16
- package/dist/components/dropdown/src/dropdown.js +41 -16
- package/dist/components/menus/dist/index.js +27 -22
- package/dist/components/menus/src/components/menu-trigger.js +24 -18
- package/dist/components/menus/src/menus.js +1 -1
- package/dist/components/multi-select/dist/index.js +16 -11
- package/dist/components/multi-select/src/multi-select.js +16 -11
- package/dist/components/popover/dist/index.js +5 -2
- package/dist/components/popover/src/components/popover-trigger.js +5 -2
- package/dist/components/select/dist/index.js +33 -17
- package/dist/components/select/src/select.js +33 -17
- package/dist/components/slot/dist/index.d.ts +7 -11
- package/dist/components/slot/dist/index.js +45 -43
- package/dist/components/slot/src/slot.d.ts +7 -13
- package/dist/components/slot/src/slot.js +49 -47
- package/dist/components/tooltip/dist/index.js +7 -2
- package/dist/components/tooltip/src/components/tooltip-trigger.js +8 -3
- package/package.json +1 -1
|
@@ -355,6 +355,21 @@ const MultiSelectComponent = memo(
|
|
|
355
355
|
chipVariant,
|
|
356
356
|
valueDisabledMap
|
|
357
357
|
]);
|
|
358
|
+
const handleTouchStart = useEventCallback(() => {
|
|
359
|
+
setTouch(true);
|
|
360
|
+
});
|
|
361
|
+
const handlePointerMove = useEventCallback(({ pointerType }) => {
|
|
362
|
+
if (pointerType !== "touch") {
|
|
363
|
+
setTouch(false);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
const slotProps = useMemo(() => {
|
|
367
|
+
return getReferenceProps({
|
|
368
|
+
disabled,
|
|
369
|
+
onTouchStart: handleTouchStart,
|
|
370
|
+
onPointerMove: handlePointerMove
|
|
371
|
+
});
|
|
372
|
+
}, [getReferenceProps, disabled, handleTouchStart, handlePointerMove]);
|
|
358
373
|
if (!triggerElement || !contentElement) {
|
|
359
374
|
console.error(
|
|
360
375
|
"MultiSelect requires both MultiSelect.Trigger and MultiSelect.Content components as children"
|
|
@@ -366,17 +381,7 @@ const MultiSelectComponent = memo(
|
|
|
366
381
|
Slot,
|
|
367
382
|
{
|
|
368
383
|
ref: refs.setReference,
|
|
369
|
-
...
|
|
370
|
-
disabled,
|
|
371
|
-
onTouchStart() {
|
|
372
|
-
setTouch(true);
|
|
373
|
-
},
|
|
374
|
-
onPointerMove({ pointerType }) {
|
|
375
|
-
if (pointerType !== "touch") {
|
|
376
|
-
setTouch(false);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}),
|
|
384
|
+
...slotProps,
|
|
380
385
|
children: enhancedTriggerElement
|
|
381
386
|
}
|
|
382
387
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Slot } from "../../slot/dist/index.js";
|
|
2
2
|
import { ModalFooter, ModalContent, ModalHeader, Modal } from "../../modal/dist/index.js";
|
|
3
3
|
import { useFloatingParentNodeId, FloatingTree, useFloatingNodeId, FloatingNode, FloatingFocusManager, FloatingPortal, offset, flip, shift, size, useFloating, autoUpdate, useHover, safePolygon, useClick, useFocus, useDismiss, useRole, useInteractions } from "@floating-ui/react";
|
|
4
|
-
import { memo, forwardRef, useId, useRef, useEffect,
|
|
4
|
+
import { memo, forwardRef, useMemo, useId, useRef, useEffect, useCallback, createContext, useContext, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { useEventCallback } from "usehooks-ts";
|
|
7
7
|
import { findChildByType } from "../../../shared/utils/assertion.js";
|
|
@@ -37,11 +37,14 @@ var PopoverTrigger = memo(
|
|
|
37
37
|
forwardRef((props, forwardedRef) => {
|
|
38
38
|
const { children } = props;
|
|
39
39
|
const { getReferenceProps, refs } = usePopoverContext();
|
|
40
|
+
const slotProps = useMemo(() => {
|
|
41
|
+
return getReferenceProps();
|
|
42
|
+
}, [getReferenceProps]);
|
|
40
43
|
return /* @__PURE__ */ jsx(
|
|
41
44
|
Slot,
|
|
42
45
|
{
|
|
43
46
|
ref: mergeRefs(refs.setReference, forwardedRef),
|
|
44
|
-
...
|
|
47
|
+
...slotProps,
|
|
45
48
|
children
|
|
46
49
|
}
|
|
47
50
|
);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Slot } from "../../../slot/dist/index.js";
|
|
3
|
-
import { memo, forwardRef } from "react";
|
|
3
|
+
import { memo, forwardRef, useMemo } from "react";
|
|
4
4
|
import { usePopoverContext } from "../popover-context.js";
|
|
5
5
|
import { mergeRefs } from "../../../../shared/utils/merge-refs/merge-refs.js";
|
|
6
6
|
const PopoverTrigger = memo(
|
|
7
7
|
forwardRef((props, forwardedRef) => {
|
|
8
8
|
const { children } = props;
|
|
9
9
|
const { getReferenceProps, refs } = usePopoverContext();
|
|
10
|
+
const slotProps = useMemo(() => {
|
|
11
|
+
return getReferenceProps();
|
|
12
|
+
}, [getReferenceProps]);
|
|
10
13
|
return /* @__PURE__ */ jsx(
|
|
11
14
|
Slot,
|
|
12
15
|
{
|
|
13
16
|
ref: mergeRefs(refs.setReference, forwardedRef),
|
|
14
|
-
...
|
|
17
|
+
...slotProps,
|
|
15
18
|
children
|
|
16
19
|
}
|
|
17
20
|
);
|
|
@@ -373,6 +373,38 @@ var SelectComponent = memo(function SelectComponent2(props) {
|
|
|
373
373
|
size: sizeProp
|
|
374
374
|
});
|
|
375
375
|
}, [triggerElement, isControlledOpen, sizeProp]);
|
|
376
|
+
const handleTouchStart = useEventCallback(() => {
|
|
377
|
+
setTouch(true);
|
|
378
|
+
});
|
|
379
|
+
const handleMouseDown = useEventCallback(() => {
|
|
380
|
+
refs.isMouseDownFromTrigger.current = true;
|
|
381
|
+
});
|
|
382
|
+
const handlePointerMove = useEventCallback(({ pointerType }) => {
|
|
383
|
+
if (pointerType !== "touch") {
|
|
384
|
+
setTouch(false);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
const slotProps = useMemo(() => {
|
|
388
|
+
return {
|
|
389
|
+
"aria-haspopup": "listbox",
|
|
390
|
+
"aria-expanded": isControlledOpen,
|
|
391
|
+
"aria-controls": menuId,
|
|
392
|
+
...getReferenceProps({
|
|
393
|
+
disabled,
|
|
394
|
+
onTouchStart: handleTouchStart,
|
|
395
|
+
onMouseDown: handleMouseDown,
|
|
396
|
+
onPointerMove: handlePointerMove
|
|
397
|
+
})
|
|
398
|
+
};
|
|
399
|
+
}, [
|
|
400
|
+
isControlledOpen,
|
|
401
|
+
menuId,
|
|
402
|
+
getReferenceProps,
|
|
403
|
+
disabled,
|
|
404
|
+
handleTouchStart,
|
|
405
|
+
handleMouseDown,
|
|
406
|
+
handlePointerMove
|
|
407
|
+
]);
|
|
376
408
|
if (!triggerElement || !contentElement) {
|
|
377
409
|
console.error("Select requires both Select.Trigger and Select.Content components as children");
|
|
378
410
|
return null;
|
|
@@ -382,23 +414,7 @@ var SelectComponent = memo(function SelectComponent2(props) {
|
|
|
382
414
|
Slot,
|
|
383
415
|
{
|
|
384
416
|
ref: floating.refs.setReference,
|
|
385
|
-
|
|
386
|
-
"aria-expanded": isControlledOpen,
|
|
387
|
-
"aria-controls": menuId,
|
|
388
|
-
...getReferenceProps({
|
|
389
|
-
disabled,
|
|
390
|
-
onTouchStart() {
|
|
391
|
-
setTouch(true);
|
|
392
|
-
},
|
|
393
|
-
onMouseDown() {
|
|
394
|
-
refs.isMouseDownFromTrigger.current = true;
|
|
395
|
-
},
|
|
396
|
-
onPointerMove({ pointerType }) {
|
|
397
|
-
if (pointerType !== "touch") {
|
|
398
|
-
setTouch(false);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}),
|
|
417
|
+
...slotProps,
|
|
402
418
|
children: enhancedTriggerElement
|
|
403
419
|
}
|
|
404
420
|
),
|
|
@@ -373,6 +373,38 @@ const SelectComponent = memo(function SelectComponent2(props) {
|
|
|
373
373
|
size: sizeProp
|
|
374
374
|
});
|
|
375
375
|
}, [triggerElement, isControlledOpen, sizeProp]);
|
|
376
|
+
const handleTouchStart = useEventCallback(() => {
|
|
377
|
+
setTouch(true);
|
|
378
|
+
});
|
|
379
|
+
const handleMouseDown = useEventCallback(() => {
|
|
380
|
+
refs.isMouseDownFromTrigger.current = true;
|
|
381
|
+
});
|
|
382
|
+
const handlePointerMove = useEventCallback(({ pointerType }) => {
|
|
383
|
+
if (pointerType !== "touch") {
|
|
384
|
+
setTouch(false);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
const slotProps = useMemo(() => {
|
|
388
|
+
return {
|
|
389
|
+
"aria-haspopup": "listbox",
|
|
390
|
+
"aria-expanded": isControlledOpen,
|
|
391
|
+
"aria-controls": menuId,
|
|
392
|
+
...getReferenceProps({
|
|
393
|
+
disabled,
|
|
394
|
+
onTouchStart: handleTouchStart,
|
|
395
|
+
onMouseDown: handleMouseDown,
|
|
396
|
+
onPointerMove: handlePointerMove
|
|
397
|
+
})
|
|
398
|
+
};
|
|
399
|
+
}, [
|
|
400
|
+
isControlledOpen,
|
|
401
|
+
menuId,
|
|
402
|
+
getReferenceProps,
|
|
403
|
+
disabled,
|
|
404
|
+
handleTouchStart,
|
|
405
|
+
handleMouseDown,
|
|
406
|
+
handlePointerMove
|
|
407
|
+
]);
|
|
376
408
|
if (!triggerElement || !contentElement) {
|
|
377
409
|
console.error("Select requires both Select.Trigger and Select.Content components as children");
|
|
378
410
|
return null;
|
|
@@ -382,23 +414,7 @@ const SelectComponent = memo(function SelectComponent2(props) {
|
|
|
382
414
|
Slot,
|
|
383
415
|
{
|
|
384
416
|
ref: floating.refs.setReference,
|
|
385
|
-
|
|
386
|
-
"aria-expanded": isControlledOpen,
|
|
387
|
-
"aria-controls": menuId,
|
|
388
|
-
...getReferenceProps({
|
|
389
|
-
disabled,
|
|
390
|
-
onTouchStart() {
|
|
391
|
-
setTouch(true);
|
|
392
|
-
},
|
|
393
|
-
onMouseDown() {
|
|
394
|
-
refs.isMouseDownFromTrigger.current = true;
|
|
395
|
-
},
|
|
396
|
-
onPointerMove({ pointerType }) {
|
|
397
|
-
if (pointerType !== "touch") {
|
|
398
|
-
setTouch(false);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}),
|
|
417
|
+
...slotProps,
|
|
402
418
|
children: enhancedTriggerElement
|
|
403
419
|
}
|
|
404
420
|
),
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
2
3
|
interface SlotProps extends React.HTMLAttributes<HTMLElement> {
|
|
3
4
|
children?: React.ReactNode;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Slot component - Lightweight implementation
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 2. 简化 props 合并逻辑
|
|
11
|
-
* 3. 避免不必要的深度遍历
|
|
12
|
-
* 4. 更好的类型安全
|
|
9
|
+
* Based on @radix-ui/react-slot design, used for asChild pattern prop forwarding
|
|
10
|
+
* Performance optimization should be done at the consumer level (e.g., useMemo to cache props)
|
|
13
11
|
*/
|
|
14
12
|
declare const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
|
|
15
13
|
/**
|
|
16
|
-
* Hook
|
|
17
|
-
* 用于需要更细粒度控制的场景
|
|
14
|
+
* Hook version of Slot logic
|
|
18
15
|
*/
|
|
19
16
|
declare function useSlot(children: React.ReactNode, slotProps: Record<string, unknown>, forwardedRef?: React.Ref<unknown>): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined;
|
|
20
17
|
/**
|
|
21
|
-
*
|
|
22
|
-
* 用于替代 `const Component = asChild ? Slot : "button"` 模式
|
|
18
|
+
* asChild 模式 Hook
|
|
23
19
|
*/
|
|
24
20
|
declare function useAsChild<T extends React.ElementType = "button">(asChild: boolean | undefined, defaultElement: T): T | typeof Slot;
|
|
25
21
|
|
|
@@ -1,68 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { forwardRef } from "react";
|
|
2
3
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
4
|
var Slot = forwardRef(
|
|
4
5
|
({ children, ...slotProps }, forwardedRef) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return children;
|
|
8
|
-
}
|
|
9
|
-
const childRef = children.ref;
|
|
6
|
+
if (React.isValidElement(children)) {
|
|
7
|
+
const childrenRef = getElementRef(children);
|
|
10
8
|
const mergedProps = mergeProps(slotProps, children.props);
|
|
11
|
-
return
|
|
9
|
+
return React.cloneElement(children, {
|
|
12
10
|
...mergedProps,
|
|
13
|
-
ref: forwardedRef ? composeRefs(forwardedRef,
|
|
11
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
|
|
14
12
|
});
|
|
15
|
-
}
|
|
16
|
-
return /* @__PURE__ */ jsx(Fragment, { children
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
17
15
|
}
|
|
18
16
|
);
|
|
19
17
|
Slot.displayName = "Slot";
|
|
20
18
|
var SlotClone = forwardRef(
|
|
21
19
|
({ children, ...slotProps }, forwardedRef) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return children;
|
|
25
|
-
}
|
|
26
|
-
const childRef = children.ref;
|
|
20
|
+
if (React.isValidElement(children)) {
|
|
21
|
+
const childrenRef = getElementRef(children);
|
|
27
22
|
const mergedProps = mergeProps(slotProps, children.props);
|
|
28
|
-
return
|
|
23
|
+
return React.cloneElement(children, {
|
|
29
24
|
...mergedProps,
|
|
30
|
-
ref: forwardedRef ? composeRefs(forwardedRef,
|
|
25
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
|
|
31
26
|
});
|
|
32
|
-
}
|
|
33
|
-
return /* @__PURE__ */ jsx(Fragment, { children
|
|
27
|
+
}
|
|
28
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
34
29
|
}
|
|
35
30
|
);
|
|
36
31
|
SlotClone.displayName = "SlotClone";
|
|
37
32
|
function mergeProps(slotProps, childProps) {
|
|
38
33
|
const overrideProps = { ...childProps };
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
overrideProps.style = { ...slotProps.style, ...childProps.style };
|
|
46
|
-
} else if (slotProps.style) {
|
|
47
|
-
overrideProps.style = slotProps.style;
|
|
48
|
-
}
|
|
49
|
-
for (const propName in slotProps) {
|
|
50
|
-
if (propName.startsWith("on") && typeof slotProps[propName] === "function") {
|
|
51
|
-
const slotHandler = slotProps[propName];
|
|
52
|
-
const childHandler = childProps[propName];
|
|
53
|
-
if (childHandler && typeof childHandler === "function") {
|
|
34
|
+
for (const propName in childProps) {
|
|
35
|
+
const slotPropValue = slotProps[propName];
|
|
36
|
+
const childPropValue = childProps[propName];
|
|
37
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
38
|
+
if (isHandler) {
|
|
39
|
+
if (slotPropValue && childPropValue) {
|
|
54
40
|
overrideProps[propName] = (...args) => {
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
const result = childPropValue(...args);
|
|
42
|
+
slotPropValue(...args);
|
|
43
|
+
return result;
|
|
57
44
|
};
|
|
58
|
-
} else {
|
|
59
|
-
overrideProps[propName] =
|
|
45
|
+
} else if (slotPropValue) {
|
|
46
|
+
overrideProps[propName] = slotPropValue;
|
|
60
47
|
}
|
|
61
|
-
} else if (propName
|
|
62
|
-
overrideProps[propName] =
|
|
48
|
+
} else if (propName === "style") {
|
|
49
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
50
|
+
} else if (propName === "className") {
|
|
51
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
|
-
return overrideProps;
|
|
54
|
+
return { ...slotProps, ...overrideProps };
|
|
66
55
|
}
|
|
67
56
|
function composeRefs(...refs) {
|
|
68
57
|
return (node) => {
|
|
@@ -70,12 +59,25 @@ function composeRefs(...refs) {
|
|
|
70
59
|
if (typeof ref === "function") {
|
|
71
60
|
ref(node);
|
|
72
61
|
} else if (ref != null) {
|
|
73
|
-
|
|
74
|
-
mutableRef.current = node;
|
|
62
|
+
ref.current = node;
|
|
75
63
|
}
|
|
76
64
|
});
|
|
77
65
|
};
|
|
78
66
|
}
|
|
67
|
+
function getElementRef(element) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
let getter = (_a = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a.get;
|
|
70
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
71
|
+
if (mayWarn) {
|
|
72
|
+
return element.ref;
|
|
73
|
+
}
|
|
74
|
+
getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
|
|
75
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
76
|
+
if (mayWarn) {
|
|
77
|
+
return element.props.ref;
|
|
78
|
+
}
|
|
79
|
+
return element.props.ref || element.ref;
|
|
80
|
+
}
|
|
79
81
|
export {
|
|
80
82
|
Slot
|
|
81
83
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
export interface SlotProps extends React.HTMLAttributes<HTMLElement> {
|
|
3
3
|
children?: React.ReactNode;
|
|
4
4
|
}
|
|
@@ -6,28 +6,22 @@ interface SlotCloneProps {
|
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Slot component - Lightweight implementation
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* 2. 简化 props 合并逻辑
|
|
14
|
-
* 3. 避免不必要的深度遍历
|
|
15
|
-
* 4. 更好的类型安全
|
|
11
|
+
* Based on @radix-ui/react-slot design, used for asChild pattern prop forwarding
|
|
12
|
+
* Performance optimization should be done at the consumer level (e.g., useMemo to cache props)
|
|
16
13
|
*/
|
|
17
14
|
export declare const Slot: React.ForwardRefExoticComponent<SlotProps & React.RefAttributes<HTMLElement>>;
|
|
18
15
|
/**
|
|
19
|
-
* SlotClone 组件
|
|
20
|
-
* 当需要处理嵌套结构时使用
|
|
16
|
+
* SlotClone 组件
|
|
21
17
|
*/
|
|
22
18
|
export declare const SlotClone: React.ForwardRefExoticComponent<SlotCloneProps & React.RefAttributes<HTMLElement>>;
|
|
23
19
|
/**
|
|
24
|
-
* Hook
|
|
25
|
-
* 用于需要更细粒度控制的场景
|
|
20
|
+
* Hook version of Slot logic
|
|
26
21
|
*/
|
|
27
22
|
export declare function useSlot(children: React.ReactNode, slotProps: Record<string, unknown>, forwardedRef?: React.Ref<unknown>): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined;
|
|
28
23
|
/**
|
|
29
|
-
*
|
|
30
|
-
* 用于替代 `const Component = asChild ? Slot : "button"` 模式
|
|
24
|
+
* asChild 模式 Hook
|
|
31
25
|
*/
|
|
32
26
|
export declare function useAsChild<T extends React.ElementType = "button">(asChild: boolean | undefined, defaultElement: T): T | typeof Slot;
|
|
33
27
|
export {};
|
|
@@ -1,68 +1,57 @@
|
|
|
1
1
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { forwardRef, useMemo } from "react";
|
|
3
4
|
const Slot = forwardRef(
|
|
4
5
|
({ children, ...slotProps }, forwardedRef) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return children;
|
|
8
|
-
}
|
|
9
|
-
const childRef = children.ref;
|
|
6
|
+
if (React.isValidElement(children)) {
|
|
7
|
+
const childrenRef = getElementRef(children);
|
|
10
8
|
const mergedProps = mergeProps(slotProps, children.props);
|
|
11
|
-
return
|
|
9
|
+
return React.cloneElement(children, {
|
|
12
10
|
...mergedProps,
|
|
13
|
-
ref: forwardedRef ? composeRefs(forwardedRef,
|
|
11
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
|
|
14
12
|
});
|
|
15
|
-
}
|
|
16
|
-
return /* @__PURE__ */ jsx(Fragment, { children
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
17
15
|
}
|
|
18
16
|
);
|
|
19
17
|
Slot.displayName = "Slot";
|
|
20
18
|
const SlotClone = forwardRef(
|
|
21
19
|
({ children, ...slotProps }, forwardedRef) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return children;
|
|
25
|
-
}
|
|
26
|
-
const childRef = children.ref;
|
|
20
|
+
if (React.isValidElement(children)) {
|
|
21
|
+
const childrenRef = getElementRef(children);
|
|
27
22
|
const mergedProps = mergeProps(slotProps, children.props);
|
|
28
|
-
return
|
|
23
|
+
return React.cloneElement(children, {
|
|
29
24
|
...mergedProps,
|
|
30
|
-
ref: forwardedRef ? composeRefs(forwardedRef,
|
|
25
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
|
|
31
26
|
});
|
|
32
|
-
}
|
|
33
|
-
return /* @__PURE__ */ jsx(Fragment, { children
|
|
27
|
+
}
|
|
28
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
34
29
|
}
|
|
35
30
|
);
|
|
36
31
|
SlotClone.displayName = "SlotClone";
|
|
37
32
|
function mergeProps(slotProps, childProps) {
|
|
38
33
|
const overrideProps = { ...childProps };
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
overrideProps.style = { ...slotProps.style, ...childProps.style };
|
|
46
|
-
} else if (slotProps.style) {
|
|
47
|
-
overrideProps.style = slotProps.style;
|
|
48
|
-
}
|
|
49
|
-
for (const propName in slotProps) {
|
|
50
|
-
if (propName.startsWith("on") && typeof slotProps[propName] === "function") {
|
|
51
|
-
const slotHandler = slotProps[propName];
|
|
52
|
-
const childHandler = childProps[propName];
|
|
53
|
-
if (childHandler && typeof childHandler === "function") {
|
|
34
|
+
for (const propName in childProps) {
|
|
35
|
+
const slotPropValue = slotProps[propName];
|
|
36
|
+
const childPropValue = childProps[propName];
|
|
37
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
38
|
+
if (isHandler) {
|
|
39
|
+
if (slotPropValue && childPropValue) {
|
|
54
40
|
overrideProps[propName] = (...args) => {
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
const result = childPropValue(...args);
|
|
42
|
+
slotPropValue(...args);
|
|
43
|
+
return result;
|
|
57
44
|
};
|
|
58
|
-
} else {
|
|
59
|
-
overrideProps[propName] =
|
|
45
|
+
} else if (slotPropValue) {
|
|
46
|
+
overrideProps[propName] = slotPropValue;
|
|
60
47
|
}
|
|
61
|
-
} else if (propName
|
|
62
|
-
overrideProps[propName] =
|
|
48
|
+
} else if (propName === "style") {
|
|
49
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
50
|
+
} else if (propName === "className") {
|
|
51
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
|
-
return overrideProps;
|
|
54
|
+
return { ...slotProps, ...overrideProps };
|
|
66
55
|
}
|
|
67
56
|
function composeRefs(...refs) {
|
|
68
57
|
return (node) => {
|
|
@@ -70,22 +59,35 @@ function composeRefs(...refs) {
|
|
|
70
59
|
if (typeof ref === "function") {
|
|
71
60
|
ref(node);
|
|
72
61
|
} else if (ref != null) {
|
|
73
|
-
|
|
74
|
-
mutableRef.current = node;
|
|
62
|
+
ref.current = node;
|
|
75
63
|
}
|
|
76
64
|
});
|
|
77
65
|
};
|
|
78
66
|
}
|
|
67
|
+
function getElementRef(element) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
let getter = (_a = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a.get;
|
|
70
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
71
|
+
if (mayWarn) {
|
|
72
|
+
return element.ref;
|
|
73
|
+
}
|
|
74
|
+
getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
|
|
75
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
76
|
+
if (mayWarn) {
|
|
77
|
+
return element.props.ref;
|
|
78
|
+
}
|
|
79
|
+
return element.props.ref || element.ref;
|
|
80
|
+
}
|
|
79
81
|
function useSlot(children, slotProps, forwardedRef) {
|
|
80
82
|
return useMemo(() => {
|
|
81
|
-
if (!
|
|
83
|
+
if (!React.isValidElement(children)) {
|
|
82
84
|
return children;
|
|
83
85
|
}
|
|
84
|
-
const
|
|
86
|
+
const childrenRef = getElementRef(children);
|
|
85
87
|
const mergedProps = mergeProps(slotProps, children.props);
|
|
86
|
-
return
|
|
88
|
+
return React.cloneElement(children, {
|
|
87
89
|
...mergedProps,
|
|
88
|
-
ref: forwardedRef ? composeRefs(forwardedRef,
|
|
90
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
|
|
89
91
|
});
|
|
90
92
|
}, [children, slotProps, forwardedRef]);
|
|
91
93
|
}
|
|
@@ -184,12 +184,17 @@ var TooltipTrigger = forwardRef(
|
|
|
184
184
|
function TooltipTrigger2({ children, ...props }, propRef) {
|
|
185
185
|
const state = useTooltipState();
|
|
186
186
|
const ref = useMergeRefs([state.refs.setReference, propRef]);
|
|
187
|
+
const slotProps = useMemo(() => {
|
|
188
|
+
return {
|
|
189
|
+
...state.disabled && { disabled: true },
|
|
190
|
+
...state.getReferenceProps(props)
|
|
191
|
+
};
|
|
192
|
+
}, [state.disabled, state.getReferenceProps, props]);
|
|
187
193
|
return /* @__PURE__ */ jsx(
|
|
188
194
|
Slot,
|
|
189
195
|
{
|
|
190
196
|
ref,
|
|
191
|
-
...
|
|
192
|
-
...state.getReferenceProps(props),
|
|
197
|
+
...slotProps,
|
|
193
198
|
children
|
|
194
199
|
}
|
|
195
200
|
);
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Slot } from "../../../slot/dist/index.js";
|
|
3
3
|
import { useMergeRefs } from "@floating-ui/react";
|
|
4
|
-
import { forwardRef } from "react";
|
|
4
|
+
import { forwardRef, useMemo } from "react";
|
|
5
5
|
import { useTooltipState } from "../context/tooltip-context.js";
|
|
6
6
|
const TooltipTrigger = forwardRef(
|
|
7
7
|
function TooltipTrigger2({ children, ...props }, propRef) {
|
|
8
8
|
const state = useTooltipState();
|
|
9
9
|
const ref = useMergeRefs([state.refs.setReference, propRef]);
|
|
10
|
+
const slotProps = useMemo(() => {
|
|
11
|
+
return {
|
|
12
|
+
...state.disabled && { disabled: true },
|
|
13
|
+
...state.getReferenceProps(props)
|
|
14
|
+
};
|
|
15
|
+
}, [state.disabled, state.getReferenceProps, props]);
|
|
10
16
|
return /* @__PURE__ */ jsx(
|
|
11
17
|
Slot,
|
|
12
18
|
{
|
|
13
19
|
ref,
|
|
14
|
-
...
|
|
15
|
-
...state.getReferenceProps(props),
|
|
20
|
+
...slotProps,
|
|
16
21
|
children
|
|
17
22
|
}
|
|
18
23
|
);
|
package/package.json
CHANGED