@ultraviolet/ui 1.27.0 → 1.27.2
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/index.d.ts
CHANGED
|
@@ -181,7 +181,7 @@ const NumberInput = _ref21 => {
|
|
|
181
181
|
}
|
|
182
182
|
return defaultValue;
|
|
183
183
|
});
|
|
184
|
-
const currentValue = value !== undefined ? value : inputValue;
|
|
184
|
+
const currentValue = value !== undefined && value !== null ? value : inputValue;
|
|
185
185
|
const setValue = function (newValue,
|
|
186
186
|
/**
|
|
187
187
|
* If true, will check if newValue is between minValue and maxValue and set it to minValue or maxValue if it's not.
|
|
@@ -190,20 +190,17 @@ const NumberInput = _ref21 => {
|
|
|
190
190
|
if (hasMinMaxVerification === void 0) {
|
|
191
191
|
hasMinMaxVerification = true;
|
|
192
192
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
setInputValue(maxValue);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
193
|
+
let nextValue = newValue;
|
|
194
|
+
if (value === undefined && hasMinMaxVerification) {
|
|
195
|
+
if (newValue !== undefined && newValue < minValue) {
|
|
196
|
+
nextValue = minValue;
|
|
197
|
+
}
|
|
198
|
+
if (newValue !== undefined && maxValue !== undefined && newValue > maxValue) {
|
|
199
|
+
nextValue = maxValue;
|
|
203
200
|
}
|
|
204
|
-
setInputValue(newValue);
|
|
205
201
|
}
|
|
206
|
-
|
|
202
|
+
setInputValue(nextValue);
|
|
203
|
+
onChange?.(nextValue);
|
|
207
204
|
};
|
|
208
205
|
const offsetFn = direction => () => {
|
|
209
206
|
const localValue = currentValue ?? 0;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _styled from '@emotion/styled/base';
|
|
2
|
-
import {
|
|
2
|
+
import { useRef } from 'react';
|
|
3
3
|
import recursivelyGetChildrenString from '../../helpers/recursivelyGetChildrenString.js';
|
|
4
|
+
import { useIsOverflowing } from '../../hooks/useIsOverflowing.js';
|
|
4
5
|
import capitalize from '../../utils/capitalize.js';
|
|
5
6
|
import { Tooltip } from '../Tooltip/index.js';
|
|
6
7
|
import { jsx } from '@emotion/react/jsx-runtime';
|
|
@@ -79,20 +80,11 @@ const Text = _ref2 => {
|
|
|
79
80
|
'data-testid': dataTestId
|
|
80
81
|
} = _ref2;
|
|
81
82
|
const computedSentiment = sentiment ?? color;
|
|
82
|
-
const [isTruncated, setIsTruncated] = useState(false);
|
|
83
83
|
const elementRef = useRef(null);
|
|
84
|
+
const isOverflowing = useIsOverflowing(elementRef);
|
|
84
85
|
const finalStringChildren = recursivelyGetChildrenString(children);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (oneLine && elementRef?.current) {
|
|
87
|
-
const {
|
|
88
|
-
offsetWidth,
|
|
89
|
-
scrollWidth
|
|
90
|
-
} = elementRef.current;
|
|
91
|
-
setIsTruncated(offsetWidth < scrollWidth);
|
|
92
|
-
}
|
|
93
|
-
}, [oneLine]);
|
|
94
86
|
return jsx(Tooltip, {
|
|
95
|
-
text: oneLine &&
|
|
87
|
+
text: oneLine && isOverflowing ? finalStringChildren : '',
|
|
96
88
|
children: jsx(StyledText, {
|
|
97
89
|
ref: elementRef,
|
|
98
90
|
as: as,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This hook checks if the element has overflow based on the offsetWidth and scrollWidth of the element.
|
|
5
|
+
*/
|
|
6
|
+
const useIsOverflowing = (ref, callback) => {
|
|
7
|
+
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const handleResize = () => {
|
|
10
|
+
if (!ref.current) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const element = ref.current;
|
|
14
|
+
const hasOverflow = element.clientWidth < element.scrollWidth;
|
|
15
|
+
setIsOverflowing(hasOverflow);
|
|
16
|
+
if (callback) callback(hasOverflow);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// This will add the function into the browser event queue after the DOM is painted
|
|
20
|
+
// which is needed to get the correct offsetWidth and scrollWidth
|
|
21
|
+
setTimeout(() => handleResize(), 0);
|
|
22
|
+
|
|
23
|
+
// Listen for resize events
|
|
24
|
+
window.addEventListener('resize', handleResize);
|
|
25
|
+
|
|
26
|
+
// Cleanup the event listener
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('resize', handleResize);
|
|
29
|
+
};
|
|
30
|
+
}, [ref, callback]);
|
|
31
|
+
return isOverflowing;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { useIsOverflowing };
|