@true-engineering/true-react-common-ui-kit 4.0.0-alpha63 → 4.0.0-alpha64
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/hooks/use-resize-ref.d.ts +2 -1
- package/dist/true-react-common-ui-kit.js +14 -16
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/ControlWrapper/ControlWrapper.tsx +5 -9
- package/src/components/Input/InputBase.tsx +4 -8
- package/src/hooks/use-resize-ref.ts +11 -4
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CSSProperties, FC, ReactNode,
|
|
1
|
+
import { CSSProperties, FC, ReactNode, useState } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import {
|
|
4
4
|
addClickHandler,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
isNotEmpty,
|
|
11
11
|
isReactNodeNotEmpty,
|
|
12
12
|
} from '@true-engineering/true-react-platform-helpers';
|
|
13
|
-
import { useTweakStyles } from '../../hooks';
|
|
13
|
+
import { useResizeRef, useTweakStyles } from '../../hooks';
|
|
14
14
|
import { IClickHandlerEvent, ICommonProps } from '../../types';
|
|
15
15
|
import { IIcon, renderIcon } from '../Icon';
|
|
16
16
|
import { ThemedPreloader } from '../ThemedPreloader';
|
|
@@ -85,13 +85,9 @@ export const ControlWrapper: FC<IControlWrapperProps> = ({
|
|
|
85
85
|
currentComponentName: 'ControlWrapper',
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
const startControlsRef =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
-
[startIcon, size],
|
|
94
|
-
);
|
|
88
|
+
const startControlsRef = useResizeRef({
|
|
89
|
+
onTargetChange: (target) => setStartControlsWidth(target.clientWidth),
|
|
90
|
+
});
|
|
95
91
|
|
|
96
92
|
const renderIconControl = (
|
|
97
93
|
{ key, iconComponent, onClick, shouldResetSize = false }: IControlWrapperIcon,
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
InputHTMLAttributes,
|
|
7
7
|
MutableRefObject,
|
|
8
8
|
ReactNode,
|
|
9
|
-
useCallback,
|
|
10
9
|
useEffect,
|
|
11
10
|
useRef,
|
|
12
11
|
useState,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
isReactNodeNotEmpty,
|
|
21
20
|
isStringNotEmpty,
|
|
22
21
|
} from '@true-engineering/true-react-platform-helpers';
|
|
23
|
-
import { useMergedRefs, useTweakStyles } from '../../hooks';
|
|
22
|
+
import { useMergedRefs, useResizeRef, useTweakStyles } from '../../hooks';
|
|
24
23
|
import { IClickHandlerEvent, ICommonProps } from '../../types';
|
|
25
24
|
import { ControlWrapper, IControlWrapperProps } from '../ControlWrapper';
|
|
26
25
|
import { IChangeInputEvent } from './types';
|
|
@@ -156,12 +155,9 @@ export const InputBase = forwardRef<HTMLInputElement, IInputBaseProps>(function
|
|
|
156
155
|
inputRef.current?.focus();
|
|
157
156
|
};
|
|
158
157
|
|
|
159
|
-
const unitsRef =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
},
|
|
163
|
-
[units],
|
|
164
|
-
);
|
|
158
|
+
const unitsRef = useResizeRef({
|
|
159
|
+
onTargetChange: (target) => setUnitsWidth(target.clientWidth),
|
|
160
|
+
});
|
|
165
161
|
|
|
166
162
|
const props: InputHTMLAttributes<HTMLInputElement> = {
|
|
167
163
|
className: clsx(classes.input, {
|
|
@@ -5,7 +5,8 @@ import { useLatestRef } from './use-latest-ref';
|
|
|
5
5
|
export interface IResizeRefOptions {
|
|
6
6
|
/** @default false */
|
|
7
7
|
isDisabled?: boolean;
|
|
8
|
-
onChange
|
|
8
|
+
onChange?: (entry: ResizeObserverEntry) => void;
|
|
9
|
+
onTargetChange?: (target: Element) => void;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export const useResizeRef = (options: IResizeRefOptions): RefCallback<Element> => {
|
|
@@ -15,14 +16,20 @@ export const useResizeRef = (options: IResizeRefOptions): RefCallback<Element> =
|
|
|
15
16
|
const observer = new ResizeObserver(([entry]) => {
|
|
16
17
|
const { current } = optionsRef;
|
|
17
18
|
if (!current.isDisabled) {
|
|
18
|
-
current?.
|
|
19
|
+
current.onChange?.(entry);
|
|
20
|
+
current.onTargetChange?.(entry.target);
|
|
19
21
|
}
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
const observerRef: RefCallback<Element> = (node) => {
|
|
23
25
|
observer.disconnect();
|
|
24
|
-
if (isNotEmpty(node)) {
|
|
25
|
-
|
|
26
|
+
if (!isNotEmpty(node)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
observer.observe(node);
|
|
31
|
+
if (!optionsRef.current.isDisabled) {
|
|
32
|
+
optionsRef.current.onTargetChange?.(node);
|
|
26
33
|
}
|
|
27
34
|
};
|
|
28
35
|
|