rsuite 6.0.0-canary-20250620 → 6.0.0-canary-2025062016
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/SegmentedControl/package.json +7 -0
- package/SegmentedControl/styles/index.css +157 -0
- package/cjs/Grid/utils/styles.d.ts +1 -1
- package/cjs/RadioGroup/RadioGroup.d.ts +4 -1
- package/cjs/SegmentedControl/Indicator.d.ts +10 -0
- package/cjs/SegmentedControl/Indicator.js +22 -0
- package/cjs/SegmentedControl/SegmentedControl.d.ts +27 -0
- package/cjs/SegmentedControl/SegmentedControl.js +87 -0
- package/cjs/SegmentedControl/SegmentedItem.d.ts +16 -0
- package/cjs/SegmentedControl/SegmentedItem.js +44 -0
- package/cjs/SegmentedControl/hooks/useIndicatorPosition.d.ts +17 -0
- package/cjs/SegmentedControl/hooks/useIndicatorPosition.js +55 -0
- package/cjs/SegmentedControl/index.d.ts +4 -0
- package/cjs/SegmentedControl/index.js +11 -0
- package/cjs/Slider/ProgressBar.js +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +6 -0
- package/cjs/internals/Provider/types.d.ts +2 -0
- package/cjs/internals/hooks/useElementResize.d.ts +2 -1
- package/cjs/internals/hooks/useElementResize.js +50 -7
- package/cjs/internals/utils/style-sheet/css.d.ts +1 -1
- package/cjs/internals/utils/style-sheet/css.js +1 -1
- package/dist/rsuite-no-reset.css +197 -18
- package/dist/rsuite-no-reset.min.css +1 -1
- package/dist/rsuite.css +197 -18
- package/dist/rsuite.js +130 -5
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Grid/utils/styles.d.ts +1 -1
- package/esm/RadioGroup/RadioGroup.d.ts +4 -1
- package/esm/SegmentedControl/Indicator.d.ts +10 -0
- package/esm/SegmentedControl/Indicator.js +17 -0
- package/esm/SegmentedControl/SegmentedControl.d.ts +27 -0
- package/esm/SegmentedControl/SegmentedControl.js +81 -0
- package/esm/SegmentedControl/SegmentedItem.d.ts +16 -0
- package/esm/SegmentedControl/SegmentedItem.js +39 -0
- package/esm/SegmentedControl/hooks/useIndicatorPosition.d.ts +17 -0
- package/esm/SegmentedControl/hooks/useIndicatorPosition.js +50 -0
- package/esm/SegmentedControl/index.d.ts +4 -0
- package/esm/SegmentedControl/index.js +8 -0
- package/esm/Slider/ProgressBar.js +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/internals/Provider/types.d.ts +2 -0
- package/esm/internals/hooks/useElementResize.d.ts +2 -1
- package/esm/internals/hooks/useElementResize.js +50 -7
- package/esm/internals/utils/style-sheet/css.d.ts +1 -1
- package/esm/internals/utils/style-sheet/css.js +1 -1
- package/package.json +1 -1
|
@@ -3,4 +3,4 @@ import type { GutterType } from '../types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates CSS variable styles for grid gutters, supporting both single values and arrays [horizontal, vertical]
|
|
5
5
|
*/
|
|
6
|
-
export declare const getResponsiveGutterStyles: (gutter?: GutterType | ResponsiveValue<GutterType>) => Record<string, string>;
|
|
6
|
+
export declare const getResponsiveGutterStyles: (gutter?: GutterType | ResponsiveValue<GutterType>) => Record<string, string | undefined>;
|
|
@@ -14,7 +14,10 @@ export interface RadioContextProps {
|
|
|
14
14
|
]>;
|
|
15
15
|
}
|
|
16
16
|
export interface RadioGroupProps<T = string | number> extends BoxProps, FormControlBaseProps<T> {
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* A radio group can have different appearances
|
|
19
|
+
* @deprecated Use `<SegmentedControl indicator="underline" />` instead
|
|
20
|
+
*/
|
|
18
21
|
appearance?: 'default' | 'picker';
|
|
19
22
|
/** Name to use for form */
|
|
20
23
|
name?: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IndicatorProps {
|
|
3
|
+
style: React.CSSProperties;
|
|
4
|
+
classPrefix: string;
|
|
5
|
+
}
|
|
6
|
+
declare const Indicator: {
|
|
7
|
+
({ style, classPrefix }: IndicatorProps): React.JSX.Element;
|
|
8
|
+
displayName: string;
|
|
9
|
+
};
|
|
10
|
+
export default Indicator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useStyles } from "../internals/hooks/index.js";
|
|
4
|
+
const Indicator = ({
|
|
5
|
+
style,
|
|
6
|
+
classPrefix
|
|
7
|
+
}) => {
|
|
8
|
+
const {
|
|
9
|
+
prefix
|
|
10
|
+
} = useStyles(classPrefix);
|
|
11
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
12
|
+
className: prefix('indicator'),
|
|
13
|
+
style: style
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Indicator.displayName = 'Indicator';
|
|
17
|
+
export default Indicator;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BoxProps } from '../internals/Box';
|
|
3
|
+
import type { FormControlBaseProps, Size } from '../internals/types';
|
|
4
|
+
export interface SegmentedItemDataType {
|
|
5
|
+
/** The label of the item */
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
/** The value of the item */
|
|
8
|
+
value: string | number;
|
|
9
|
+
}
|
|
10
|
+
export interface SegmentedControlProps<T = string | number | null> extends BoxProps, Omit<FormControlBaseProps<T>, 'readOnly' | 'plaintext'> {
|
|
11
|
+
/** The indicator style of the segmented control */
|
|
12
|
+
indicator?: 'pill' | 'underline';
|
|
13
|
+
/** Name to use for form */
|
|
14
|
+
name?: string;
|
|
15
|
+
/** Data of segmented items */
|
|
16
|
+
data?: SegmentedItemDataType[];
|
|
17
|
+
/** Display block style, fit the width of the container */
|
|
18
|
+
block?: boolean;
|
|
19
|
+
/** A segmented control can have different sizes */
|
|
20
|
+
size?: Size;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The `SegmentedControl` component is used to offer multiple exclusive options.
|
|
24
|
+
* @see https://rsuitejs.com/components/segmented-control
|
|
25
|
+
*/
|
|
26
|
+
declare const SegmentedControl: import("../internals/types").InternalRefForwardingComponent<"div", SegmentedControlProps<string | number | null>, never> & Record<string, never>;
|
|
27
|
+
export default SegmentedControl;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import React, { useRef } from 'react';
|
|
4
|
+
import Box from "../internals/Box/index.js";
|
|
5
|
+
import SegmentedItem from "./SegmentedItem.js";
|
|
6
|
+
import Indicator from "./Indicator.js";
|
|
7
|
+
import { forwardRef, mergeRefs } from "../internals/utils/index.js";
|
|
8
|
+
import { useStyles, useCustom, useControlled, useEventCallback, useUniqueId } from "../internals/hooks/index.js";
|
|
9
|
+
import useIndicatorPosition from "./hooks/useIndicatorPosition.js";
|
|
10
|
+
/**
|
|
11
|
+
* The `SegmentedControl` component is used to offer multiple exclusive options.
|
|
12
|
+
* @see https://rsuitejs.com/components/segmented-control
|
|
13
|
+
*/
|
|
14
|
+
const SegmentedControl = forwardRef((props, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
propsWithDefaults
|
|
17
|
+
} = useCustom('SegmentedControl', props);
|
|
18
|
+
const {
|
|
19
|
+
as,
|
|
20
|
+
className,
|
|
21
|
+
classPrefix = 'segmented-control',
|
|
22
|
+
value: valueProp,
|
|
23
|
+
defaultValue,
|
|
24
|
+
indicator = 'pill',
|
|
25
|
+
size = 'md',
|
|
26
|
+
block = false,
|
|
27
|
+
name,
|
|
28
|
+
disabled,
|
|
29
|
+
data,
|
|
30
|
+
onChange,
|
|
31
|
+
...rest
|
|
32
|
+
} = propsWithDefaults;
|
|
33
|
+
const {
|
|
34
|
+
merge,
|
|
35
|
+
withPrefix
|
|
36
|
+
} = useStyles(classPrefix);
|
|
37
|
+
const classes = merge(className, withPrefix());
|
|
38
|
+
const [value, setValue] = useControlled(valueProp, defaultValue);
|
|
39
|
+
const id = useUniqueId('segmented', name);
|
|
40
|
+
|
|
41
|
+
// Ref for container element
|
|
42
|
+
const containerRef = useRef(null);
|
|
43
|
+
|
|
44
|
+
// Get the active item index
|
|
45
|
+
const activeIndex = data === null || data === void 0 ? void 0 : data.findIndex(item => item.value === value);
|
|
46
|
+
const {
|
|
47
|
+
style: indicatorStyle
|
|
48
|
+
} = useIndicatorPosition({
|
|
49
|
+
containerRef,
|
|
50
|
+
activeIndex,
|
|
51
|
+
indicator,
|
|
52
|
+
data
|
|
53
|
+
});
|
|
54
|
+
const handleChange = useEventCallback((nextValue, event) => {
|
|
55
|
+
setValue(nextValue);
|
|
56
|
+
onChange === null || onChange === void 0 || onChange(nextValue !== null && nextValue !== void 0 ? nextValue : '', event);
|
|
57
|
+
});
|
|
58
|
+
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
59
|
+
as: as,
|
|
60
|
+
role: "radiogroup",
|
|
61
|
+
ref: mergeRefs(ref, containerRef),
|
|
62
|
+
className: classes,
|
|
63
|
+
"data-size": size,
|
|
64
|
+
"data-block": block || undefined,
|
|
65
|
+
"data-indicator": indicator
|
|
66
|
+
}, rest), data === null || data === void 0 ? void 0 : data.map((item, index) => /*#__PURE__*/React.createElement(SegmentedItem, {
|
|
67
|
+
key: index,
|
|
68
|
+
item: item,
|
|
69
|
+
index: index,
|
|
70
|
+
name: id,
|
|
71
|
+
active: value === item.value,
|
|
72
|
+
disabled: disabled,
|
|
73
|
+
classPrefix: classPrefix,
|
|
74
|
+
onChange: handleChange
|
|
75
|
+
})), activeIndex !== -1 && /*#__PURE__*/React.createElement(Indicator, {
|
|
76
|
+
style: indicatorStyle,
|
|
77
|
+
classPrefix: classPrefix
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
SegmentedControl.displayName = 'SegmentedControl';
|
|
81
|
+
export default SegmentedControl;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SegmentedItemDataType } from './SegmentedControl';
|
|
3
|
+
export interface SegmentedItemProps {
|
|
4
|
+
item: SegmentedItemDataType;
|
|
5
|
+
index: number;
|
|
6
|
+
name?: string;
|
|
7
|
+
active: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
classPrefix: string;
|
|
10
|
+
onChange: (value: string | number, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const SegmentedItem: {
|
|
13
|
+
({ item, index, name, active, disabled, classPrefix, onChange }: SegmentedItemProps): React.JSX.Element;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
16
|
+
export default SegmentedItem;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useStyles } from "../internals/hooks/index.js";
|
|
4
|
+
const SegmentedItem = ({
|
|
5
|
+
item,
|
|
6
|
+
index,
|
|
7
|
+
name,
|
|
8
|
+
active,
|
|
9
|
+
disabled,
|
|
10
|
+
classPrefix,
|
|
11
|
+
onChange
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
prefix
|
|
15
|
+
} = useStyles(classPrefix);
|
|
16
|
+
const handleChange = event => {
|
|
17
|
+
if (disabled) return;
|
|
18
|
+
onChange(item.value, event);
|
|
19
|
+
};
|
|
20
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
21
|
+
className: prefix('item'),
|
|
22
|
+
"data-value": item.value,
|
|
23
|
+
"data-index": index,
|
|
24
|
+
"data-active": active || undefined,
|
|
25
|
+
"data-disabled": disabled || undefined
|
|
26
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
27
|
+
type: "radio",
|
|
28
|
+
name: name,
|
|
29
|
+
value: String(item.value),
|
|
30
|
+
checked: active,
|
|
31
|
+
disabled: disabled,
|
|
32
|
+
onChange: handleChange,
|
|
33
|
+
className: prefix('radio')
|
|
34
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
35
|
+
className: prefix('label')
|
|
36
|
+
}, item.label));
|
|
37
|
+
};
|
|
38
|
+
SegmentedItem.displayName = 'SegmentedItem';
|
|
39
|
+
export default SegmentedItem;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
interface UseIndicatorPositionProps {
|
|
3
|
+
containerRef: RefObject<HTMLDivElement | null>;
|
|
4
|
+
activeIndex?: number;
|
|
5
|
+
indicator: 'pill' | 'underline';
|
|
6
|
+
data?: Array<{
|
|
7
|
+
value: string | number;
|
|
8
|
+
}>;
|
|
9
|
+
block?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Custom hook to calculate and update the indicator position
|
|
13
|
+
*/
|
|
14
|
+
declare const useIndicatorPosition: ({ containerRef, activeIndex, indicator, data }: UseIndicatorPositionProps) => {
|
|
15
|
+
style: import("react").CSSProperties;
|
|
16
|
+
};
|
|
17
|
+
export default useIndicatorPosition;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
4
|
+
import { useElementResize } from "../../internals/hooks/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Updates the indicator position based on the active item
|
|
7
|
+
*/
|
|
8
|
+
const updateIndicatorPosition = (container, activeIndex, indicator) => {
|
|
9
|
+
if (activeIndex === -1) return {};
|
|
10
|
+
const activeItem = container.querySelector(`[data-index="${activeIndex}"]`);
|
|
11
|
+
if (!activeItem) return {};
|
|
12
|
+
const containerStyle = window.getComputedStyle(container);
|
|
13
|
+
const paddingLeft = parseFloat(containerStyle.paddingLeft) || 0;
|
|
14
|
+
return {
|
|
15
|
+
transform: `translateX(${activeItem.offsetLeft - paddingLeft}px)`,
|
|
16
|
+
width: activeItem.offsetWidth,
|
|
17
|
+
height: indicator === 'underline' ? 2 : activeItem.offsetHeight
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Custom hook to calculate and update the indicator position
|
|
23
|
+
*/
|
|
24
|
+
const useIndicatorPosition = ({
|
|
25
|
+
containerRef,
|
|
26
|
+
activeIndex,
|
|
27
|
+
indicator,
|
|
28
|
+
data
|
|
29
|
+
}) => {
|
|
30
|
+
const [indicatorStyle, setIndicatorStyle] = useState({});
|
|
31
|
+
const updatePosition = useCallback(() => {
|
|
32
|
+
if (!(containerRef !== null && containerRef !== void 0 && containerRef.current)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const newStyle = updateIndicatorPosition(containerRef.current, activeIndex, indicator);
|
|
36
|
+
setIndicatorStyle(prev => isEqual(prev, newStyle) ? prev : newStyle);
|
|
37
|
+
}, [containerRef, activeIndex, indicator]);
|
|
38
|
+
|
|
39
|
+
// Update position when active item or data changes
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
updatePosition();
|
|
42
|
+
}, [updatePosition, data]);
|
|
43
|
+
|
|
44
|
+
// Set up resize observer
|
|
45
|
+
useElementResize(containerRef, updatePosition);
|
|
46
|
+
return {
|
|
47
|
+
style: indicatorStyle
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export default useIndicatorPosition;
|
|
@@ -20,7 +20,7 @@ const ProgressBar = forwardRef((props, ref) => {
|
|
|
20
20
|
withPrefix
|
|
21
21
|
} = useStyles(classPrefix);
|
|
22
22
|
const sizeKey = vertical ? 'height' : 'width';
|
|
23
|
-
const startKey = vertical ? 'bottom' : '
|
|
23
|
+
const startKey = vertical ? 'bottom' : 'insetInlineStart';
|
|
24
24
|
const styles = mergeStyles(style, {
|
|
25
25
|
[startKey]: `${start}%`,
|
|
26
26
|
[sizeKey]: `${end - start}%`
|
package/esm/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export * from './RadioGroup';
|
|
|
57
57
|
export * from './RadioTile';
|
|
58
58
|
export * from './RadioTileGroup';
|
|
59
59
|
export * from './SelectPicker';
|
|
60
|
+
export * from './SegmentedControl';
|
|
60
61
|
export * from './CheckPicker';
|
|
61
62
|
export * from './InputPicker';
|
|
62
63
|
export * from './TagPicker';
|
package/esm/index.js
CHANGED
|
@@ -81,6 +81,7 @@ export * from "./RadioGroup/index.js";
|
|
|
81
81
|
export * from "./RadioTile/index.js";
|
|
82
82
|
export * from "./RadioTileGroup/index.js";
|
|
83
83
|
export * from "./SelectPicker/index.js";
|
|
84
|
+
export * from "./SegmentedControl/index.js";
|
|
84
85
|
export * from "./CheckPicker/index.js";
|
|
85
86
|
export * from "./InputPicker/index.js";
|
|
86
87
|
export * from "./TagPicker/index.js";
|
|
@@ -87,6 +87,7 @@ import type { RangeSliderProps } from '../../RangeSlider';
|
|
|
87
87
|
import type { RateProps } from '../../Rate';
|
|
88
88
|
import type { RowProps } from '../../Row';
|
|
89
89
|
import type { SelectPickerProps } from '../../SelectPicker';
|
|
90
|
+
import type { SegmentedControlProps } from '../../SegmentedControl';
|
|
90
91
|
import type { SidebarProps } from '../../Sidebar';
|
|
91
92
|
import type { SidenavProps } from '../../Sidenav';
|
|
92
93
|
import type { SliderProps } from '../../Slider';
|
|
@@ -209,6 +210,7 @@ export interface ReactSuiteComponents {
|
|
|
209
210
|
Rate: ComponentProps<RateProps>;
|
|
210
211
|
Row: ComponentProps<RowProps>;
|
|
211
212
|
SelectPicker: ComponentProps<SelectPickerProps>;
|
|
213
|
+
SegmentedControl: ComponentProps<SegmentedControlProps>;
|
|
212
214
|
Sidebar: ComponentProps<SidebarProps>;
|
|
213
215
|
Sidenav: ComponentProps<SidenavProps>;
|
|
214
216
|
Slider: ComponentProps<SliderProps>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
/**
|
|
2
3
|
* Attach the event handler directly to the specified DOM element,
|
|
3
4
|
* and it will be triggered when the size of the DOM element is changed.
|
|
@@ -5,5 +6,5 @@
|
|
|
5
6
|
* @param eventTarget The target to listen for events on
|
|
6
7
|
* @param listener An event handler
|
|
7
8
|
*/
|
|
8
|
-
export declare function useElementResize(eventTarget: Element | null | (() => Element | null)
|
|
9
|
+
export declare function useElementResize(eventTarget: Element | null | (() => Element | null) | React.RefObject<Element | null>, listener: ResizeObserverCallback): void;
|
|
9
10
|
export default useElementResize;
|
|
@@ -11,18 +11,61 @@ import { ResizeObserver } from '@juggle/resize-observer';
|
|
|
11
11
|
*/
|
|
12
12
|
export function useElementResize(eventTarget, listener) {
|
|
13
13
|
const resizeObserver = useRef(null);
|
|
14
|
+
const currentElement = useRef(null);
|
|
15
|
+
|
|
16
|
+
// Create the observer
|
|
14
17
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// Get the target element
|
|
19
|
+
let target = null;
|
|
20
|
+
if (eventTarget) {
|
|
21
|
+
if (typeof eventTarget === 'function') {
|
|
22
|
+
target = eventTarget();
|
|
23
|
+
} else if ('current' in eventTarget) {
|
|
24
|
+
target = eventTarget.current;
|
|
25
|
+
} else {
|
|
26
|
+
target = eventTarget;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// If target changed, disconnect the previous observer
|
|
31
|
+
if (currentElement.current !== target) {
|
|
32
|
+
if (resizeObserver.current) {
|
|
33
|
+
resizeObserver.current.disconnect();
|
|
34
|
+
resizeObserver.current = null;
|
|
20
35
|
}
|
|
36
|
+
currentElement.current = target;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// If we have a target and no observer, create one
|
|
40
|
+
if (target && !resizeObserver.current) {
|
|
41
|
+
const observer = new ResizeObserver(listener);
|
|
42
|
+
observer.observe(target);
|
|
43
|
+
resizeObserver.current = observer;
|
|
21
44
|
}
|
|
45
|
+
|
|
46
|
+
// Cleanup function
|
|
22
47
|
return () => {
|
|
23
|
-
|
|
24
|
-
|
|
48
|
+
if (resizeObserver.current) {
|
|
49
|
+
resizeObserver.current.disconnect();
|
|
50
|
+
resizeObserver.current = null;
|
|
51
|
+
}
|
|
52
|
+
currentElement.current = null;
|
|
25
53
|
};
|
|
26
54
|
}, [eventTarget, listener]);
|
|
55
|
+
|
|
56
|
+
// Update the current element reference if it changes
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (eventTarget) {
|
|
59
|
+
if (typeof eventTarget === 'function') {
|
|
60
|
+
currentElement.current = eventTarget();
|
|
61
|
+
} else if ('current' in eventTarget) {
|
|
62
|
+
currentElement.current = eventTarget.current;
|
|
63
|
+
} else {
|
|
64
|
+
currentElement.current = eventTarget;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
currentElement.current = null;
|
|
68
|
+
}
|
|
69
|
+
}, [eventTarget]);
|
|
27
70
|
}
|
|
28
71
|
export default useElementResize;
|
|
@@ -3,7 +3,7 @@ import type { StyleProperties } from '../../types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Processes and returns a value suitable for CSS (with a unit).
|
|
5
5
|
*/
|
|
6
|
-
export declare function getCssValue(value?: number | string | null, unit?: string): string;
|
|
6
|
+
export declare function getCssValue(value?: number | string | null, unit?: string): string | undefined;
|
|
7
7
|
/**
|
|
8
8
|
* Merge multiple style objects, filtering out undefined values
|
|
9
9
|
*/
|