@lumx/react 3.18.2-alpha.4 → 3.19.0
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/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.
|
|
10
|
-
"@lumx/icons": "^3.
|
|
9
|
+
"@lumx/core": "^3.19.0",
|
|
10
|
+
"@lumx/icons": "^3.19.0",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -105,5 +105,5 @@
|
|
|
105
105
|
"build:storybook": "storybook build"
|
|
106
106
|
},
|
|
107
107
|
"sideEffects": false,
|
|
108
|
-
"version": "3.
|
|
108
|
+
"version": "3.19.0"
|
|
109
109
|
}
|
|
@@ -42,7 +42,7 @@ export const NavigationItem = Object.assign(
|
|
|
42
42
|
forwardRefPolymorphic(<E extends ElementType = 'a'>(props: NavigationItemProps<E>, ref: ComponentRef<E>) => {
|
|
43
43
|
const { className, icon, label, isCurrentPage, as: Element = 'a', ...forwardedProps } = props;
|
|
44
44
|
const theme = useTheme();
|
|
45
|
-
const { tooltipLabel, labelRef } = useOverflowTooltipLabel();
|
|
45
|
+
const { tooltipLabel, labelRef } = useOverflowTooltipLabel(label);
|
|
46
46
|
|
|
47
47
|
const buttonProps = Element === 'button' ? { type: 'button' } : {};
|
|
48
48
|
|
|
@@ -6,7 +6,7 @@ import { textElementArgType } from '@lumx/react/stories/controls/element';
|
|
|
6
6
|
import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
|
|
7
7
|
import { loremIpsum } from '@lumx/react/stories/utils/lorem';
|
|
8
8
|
import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
|
|
9
|
-
import { ColorPalette, ColorVariant, Icon, WhiteSpace } from '@lumx/react';
|
|
9
|
+
import { Button, ColorPalette, ColorVariant, Icon, WhiteSpace } from '@lumx/react';
|
|
10
10
|
import { mdiEarth, mdiHeart } from '@lumx/icons';
|
|
11
11
|
import { withResizableBox } from '@lumx/react/stories/decorators/withResizableBox';
|
|
12
12
|
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
@@ -107,6 +107,28 @@ export const Truncate = {
|
|
|
107
107
|
},
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Test the update of the `title` attribute when text overflows
|
|
112
|
+
*/
|
|
113
|
+
export const TestUpdateTruncateTitleLabel = {
|
|
114
|
+
render(args: any) {
|
|
115
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
116
|
+
const [content, setContent] = React.useState<string>('Some text');
|
|
117
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
118
|
+
const lengthen = React.useCallback(() => setContent((prevContent) => `${prevContent} ${prevContent}`), []);
|
|
119
|
+
return (
|
|
120
|
+
<>
|
|
121
|
+
<Button onClick={lengthen}>Lengthen text</Button>
|
|
122
|
+
<Text as="p" truncate style={{ maxWidth: 300 }} {...args}>
|
|
123
|
+
{content}
|
|
124
|
+
</Text>
|
|
125
|
+
</>
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
// Disables Chromatic snapshot (not relevant for this story).
|
|
129
|
+
parameters: { chromatic: { disable: true } },
|
|
130
|
+
};
|
|
131
|
+
|
|
110
132
|
/**
|
|
111
133
|
* Long text with multi line truncate ellipsis
|
|
112
134
|
*/
|
|
@@ -112,7 +112,7 @@ export const Text = forwardRef<TextProps>((props, ref) => {
|
|
|
112
112
|
!(isTruncated && !isTruncatedMultiline) &&
|
|
113
113
|
whiteSpace && { '--lumx-text-white-space': whiteSpace };
|
|
114
114
|
|
|
115
|
-
const { tooltipLabel, labelRef } = useOverflowTooltipLabel();
|
|
115
|
+
const { tooltipLabel, labelRef } = useOverflowTooltipLabel(children);
|
|
116
116
|
|
|
117
117
|
return (
|
|
118
118
|
<Component
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useTooltipContext } from '@lumx/react/components/tooltip/context';
|
|
3
|
+
import { VISUALLY_HIDDEN } from '@lumx/react/constants';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Compute a tooltip label based on a label element `innerText` if the text overflows.
|
|
6
|
-
*
|
|
7
|
-
* Warning: only works on first render, does not update on label element resize.
|
|
7
|
+
* Updates dynamically on content changes (but not on resize!)
|
|
8
8
|
*/
|
|
9
|
-
export const useOverflowTooltipLabel = () => {
|
|
9
|
+
export const useOverflowTooltipLabel = (content: React.ReactNode) => {
|
|
10
10
|
const parentTooltip = useTooltipContext();
|
|
11
11
|
const [tooltipLabel, setTooltipLabel] = React.useState<string | undefined>(undefined);
|
|
12
|
-
const
|
|
13
|
-
(labelElement: HTMLElement | null) => {
|
|
14
|
-
if (!labelElement || !!parentTooltip) {
|
|
15
|
-
// Skip if label element is unknown
|
|
16
|
-
// Skip if the parent has a tooltip
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
12
|
+
const [labelElement, setLabelElement] = React.useState<HTMLElement | null>(null);
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
React.useLayoutEffect(() => {
|
|
15
|
+
if (
|
|
16
|
+
// Not inside a tooltip
|
|
17
|
+
!parentTooltip &&
|
|
18
|
+
labelElement &&
|
|
19
|
+
// Not inside a visually hidden
|
|
20
|
+
!labelElement?.closest(`.${VISUALLY_HIDDEN}`) &&
|
|
21
|
+
// Text overflows
|
|
22
|
+
labelElement.offsetWidth < labelElement.scrollWidth
|
|
23
|
+
) {
|
|
24
|
+
// Set tooltip label
|
|
25
|
+
setTooltipLabel(labelElement.innerText);
|
|
26
|
+
} else {
|
|
27
|
+
setTooltipLabel(undefined);
|
|
28
|
+
}
|
|
29
|
+
}, [labelElement, parentTooltip, content]);
|
|
27
30
|
|
|
28
|
-
return { labelRef, tooltipLabel };
|
|
31
|
+
return { labelRef: setLabelElement, tooltipLabel };
|
|
29
32
|
};
|