@patternfly/react-core 6.3.0-prerelease.12 → 6.3.0-prerelease.13
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/CHANGELOG.md +6 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/AboutModal/package.json +1 -1
- package/dist/dynamic/components/Accordion/package.json +1 -1
- package/dist/dynamic/components/ActionList/package.json +1 -1
- package/dist/dynamic/components/Alert/package.json +1 -1
- package/dist/dynamic/components/Avatar/package.json +1 -1
- package/dist/dynamic/components/BackToTop/package.json +1 -1
- package/dist/dynamic/components/Backdrop/package.json +1 -1
- package/dist/dynamic/components/BackgroundImage/package.json +1 -1
- package/dist/dynamic/components/Badge/package.json +1 -1
- package/dist/dynamic/components/Banner/package.json +1 -1
- package/dist/dynamic/components/Brand/package.json +1 -1
- package/dist/dynamic/components/Breadcrumb/package.json +1 -1
- package/dist/dynamic/components/Button/package.json +1 -1
- package/dist/dynamic/components/CalendarMonth/package.json +1 -1
- package/dist/dynamic/components/Card/package.json +1 -1
- package/dist/dynamic/components/Checkbox/package.json +1 -1
- package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
- package/dist/dynamic/components/CodeBlock/package.json +1 -1
- package/dist/dynamic/components/Content/package.json +1 -1
- package/dist/dynamic/components/DataList/package.json +1 -1
- package/dist/dynamic/components/DatePicker/package.json +1 -1
- package/dist/dynamic/components/DescriptionList/package.json +1 -1
- package/dist/dynamic/components/Divider/package.json +1 -1
- package/dist/dynamic/components/Drawer/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/components/EmptyState/package.json +1 -1
- package/dist/dynamic/components/ExpandableSection/package.json +1 -1
- package/dist/dynamic/components/FileUpload/package.json +1 -1
- package/dist/dynamic/components/Form/package.json +1 -1
- package/dist/dynamic/components/FormSelect/package.json +1 -1
- package/dist/dynamic/components/HelperText/package.json +1 -1
- package/dist/dynamic/components/Hint/package.json +1 -1
- package/dist/dynamic/components/Icon/package.json +1 -1
- package/dist/dynamic/components/InputGroup/package.json +1 -1
- package/dist/dynamic/components/JumpLinks/package.json +1 -1
- package/dist/dynamic/components/Label/package.json +1 -1
- package/dist/dynamic/components/List/package.json +1 -1
- package/dist/dynamic/components/LoginPage/package.json +1 -1
- package/dist/dynamic/components/Masthead/package.json +1 -1
- package/dist/dynamic/components/Menu/package.json +1 -1
- package/dist/dynamic/components/MenuToggle/package.json +1 -1
- package/dist/dynamic/components/Modal/package.json +1 -1
- package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
- package/dist/dynamic/components/Nav/package.json +1 -1
- package/dist/dynamic/components/NotificationBadge/package.json +1 -1
- package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
- package/dist/dynamic/components/NumberInput/package.json +1 -1
- package/dist/dynamic/components/OverflowMenu/package.json +1 -1
- package/dist/dynamic/components/Page/package.json +1 -1
- package/dist/dynamic/components/Pagination/package.json +1 -1
- package/dist/dynamic/components/Panel/package.json +1 -1
- package/dist/dynamic/components/Popover/package.json +1 -1
- package/dist/dynamic/components/Progress/package.json +1 -1
- package/dist/dynamic/components/ProgressStepper/package.json +1 -1
- package/dist/dynamic/components/Radio/package.json +1 -1
- package/dist/dynamic/components/SearchInput/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic/components/Sidebar/package.json +1 -1
- package/dist/dynamic/components/SimpleList/package.json +1 -1
- package/dist/dynamic/components/Skeleton/package.json +1 -1
- package/dist/dynamic/components/SkipToContent/package.json +1 -1
- package/dist/dynamic/components/Slider/package.json +1 -1
- package/dist/dynamic/components/Spinner/package.json +1 -1
- package/dist/dynamic/components/Switch/package.json +1 -1
- package/dist/dynamic/components/Tabs/package.json +1 -1
- package/dist/dynamic/components/TextArea/package.json +1 -1
- package/dist/dynamic/components/TextInput/package.json +1 -1
- package/dist/dynamic/components/TextInputGroup/package.json +1 -1
- package/dist/dynamic/components/TimePicker/package.json +1 -1
- package/dist/dynamic/components/Timestamp/package.json +1 -1
- package/dist/dynamic/components/Title/package.json +1 -1
- package/dist/dynamic/components/ToggleGroup/package.json +1 -1
- package/dist/dynamic/components/Toolbar/package.json +1 -1
- package/dist/dynamic/components/Tooltip/package.json +1 -1
- package/dist/dynamic/components/TreeView/package.json +1 -1
- package/dist/dynamic/components/Truncate/package.json +1 -1
- package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
- package/dist/dynamic/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/Chip/package.json +1 -1
- package/dist/dynamic/deprecated/components/DragDrop/package.json +1 -1
- package/dist/dynamic/deprecated/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/deprecated/components/Modal/package.json +1 -1
- package/dist/dynamic/deprecated/components/Tile/package.json +1 -1
- package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
- package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
- package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
- package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
- package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
- package/dist/dynamic/helpers/constants/package.json +1 -1
- package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
- package/dist/dynamic/helpers/fileUtils/package.json +1 -1
- package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
- package/dist/dynamic/helpers/package.json +1 -1
- package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
- package/dist/dynamic/helpers/typeUtils/package.json +1 -1
- package/dist/dynamic/helpers/useInterval/package.json +1 -1
- package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
- package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
- package/dist/dynamic/helpers/util/package.json +1 -1
- package/dist/dynamic/layouts/Bullseye/package.json +1 -1
- package/dist/dynamic/layouts/Flex/package.json +1 -1
- package/dist/dynamic/layouts/Gallery/package.json +1 -1
- package/dist/dynamic/layouts/Grid/package.json +1 -1
- package/dist/dynamic/layouts/Level/package.json +1 -1
- package/dist/dynamic/layouts/Split/package.json +1 -1
- package/dist/dynamic/layouts/Stack/package.json +1 -1
- package/dist/dynamic/styles/package.json +1 -1
- package/dist/dynamic-modules.json +1 -0
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.js +2 -2
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
- package/dist/esm/components/Truncate/Truncate.d.ts +11 -8
- package/dist/esm/components/Truncate/Truncate.d.ts.map +1 -1
- package/dist/esm/components/Truncate/Truncate.js +16 -9
- package/dist/esm/components/Truncate/Truncate.js.map +1 -1
- package/dist/esm/helpers/util.d.ts +7 -0
- package/dist/esm/helpers/util.d.ts.map +1 -1
- package/dist/esm/helpers/util.js +15 -0
- package/dist/esm/helpers/util.js.map +1 -1
- package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
- package/dist/js/components/ClipboardCopy/ClipboardCopy.js +2 -2
- package/dist/js/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
- package/dist/js/components/Truncate/Truncate.d.ts +11 -8
- package/dist/js/components/Truncate/Truncate.d.ts.map +1 -1
- package/dist/js/components/Truncate/Truncate.js +15 -9
- package/dist/js/components/Truncate/Truncate.js.map +1 -1
- package/dist/js/helpers/util.d.ts +7 -0
- package/dist/js/helpers/util.d.ts.map +1 -1
- package/dist/js/helpers/util.js +17 -1
- package/dist/js/helpers/util.js.map +1 -1
- package/dist/umd/assets/{output-85UrEgTH.css → output-C186DUfw.css} +19548 -19548
- package/dist/umd/react-core.min.js +1 -1
- package/helpers/package.json +1 -1
- package/layouts/package.json +1 -1
- package/next/package.json +1 -1
- package/package.json +2 -2
- package/src/components/ClipboardCopy/ClipboardCopy.tsx +2 -1
- package/src/components/Truncate/Truncate.tsx +40 -19
- package/src/components/Truncate/__tests__/Truncate.test.tsx +24 -0
- package/src/components/Truncate/examples/Truncate.md +8 -0
- package/src/components/Truncate/examples/TruncateLinks.tsx +22 -0
- package/src/helpers/util.ts +17 -0
package/helpers/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.3.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.3.0-prerelease.12","private":true}
|
package/layouts/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.3.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.3.0-prerelease.12","private":true}
|
package/next/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.3.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.3.0-prerelease.12","private":true}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "6.3.0-prerelease.
|
|
3
|
+
"version": "6.3.0-prerelease.13",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"react": "^17 || ^18 || ^19",
|
|
64
64
|
"react-dom": "^17 || ^18 || ^19"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "5c6511cf7ea76569ab3ad0e7696bb660a3d0b58f"
|
|
67
67
|
}
|
|
@@ -204,7 +204,7 @@ class ClipboardCopy extends Component<ClipboardCopyProps, ClipboardCopyState> {
|
|
|
204
204
|
const shouldTruncate = variant === ClipboardCopyVariant.inlineCompact && truncation;
|
|
205
205
|
const inlineCompactContent = shouldTruncate ? (
|
|
206
206
|
<Truncate
|
|
207
|
-
|
|
207
|
+
tooltipProps={{ triggerRef: this.clipboardRef }}
|
|
208
208
|
content={copyableText}
|
|
209
209
|
{...(typeof truncation === 'object' && truncation)}
|
|
210
210
|
/>
|
|
@@ -223,6 +223,7 @@ class ClipboardCopy extends Component<ClipboardCopyProps, ClipboardCopyState> {
|
|
|
223
223
|
className
|
|
224
224
|
)}
|
|
225
225
|
ref={this.clipboardRef}
|
|
226
|
+
{...(shouldTruncate && { tabIndex: 0 })}
|
|
226
227
|
{...divProps}
|
|
227
228
|
{...getOUIAProps(ClipboardCopy.displayName, ouiaId, ouiaSafe)}
|
|
228
229
|
>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Fragment, useEffect, useRef, useState } from 'react';
|
|
1
|
+
import { Fragment, useEffect, useRef, useState, forwardRef } from 'react';
|
|
2
2
|
import styles from '@patternfly/react-styles/css/components/Truncate/truncate';
|
|
3
3
|
import { css } from '@patternfly/react-styles';
|
|
4
|
-
import { Tooltip, TooltipPosition } from '../Tooltip';
|
|
4
|
+
import { Tooltip, TooltipPosition, TooltipProps } from '../Tooltip';
|
|
5
|
+
import { getReferenceElement } from '../../helpers';
|
|
5
6
|
import { getResizeObserver } from '../../helpers/resizeObserver';
|
|
6
7
|
|
|
7
8
|
export enum TruncatePosition {
|
|
@@ -17,11 +18,15 @@ const truncateStyles = {
|
|
|
17
18
|
|
|
18
19
|
const minWidthCharacters: number = 12;
|
|
19
20
|
|
|
20
|
-
export interface TruncateProps extends React.HTMLProps<HTMLSpanElement> {
|
|
21
|
+
export interface TruncateProps extends Omit<React.HTMLProps<HTMLSpanElement | HTMLAnchorElement>, 'ref'> {
|
|
21
22
|
/** Class to add to outer span */
|
|
22
23
|
className?: string;
|
|
23
24
|
/** Text to truncate */
|
|
24
25
|
content: string;
|
|
26
|
+
/** An HREF to turn the truncate wrapper into an anchor element. For more custom control, use the
|
|
27
|
+
* tooltipProps with a triggerRef property passed in.
|
|
28
|
+
*/
|
|
29
|
+
href?: string;
|
|
25
30
|
/** The number of characters displayed in the second half of a middle truncation. This will be overridden by
|
|
26
31
|
* the maxCharsDisplayed prop.
|
|
27
32
|
*/
|
|
@@ -52,24 +57,24 @@ export interface TruncateProps extends React.HTMLProps<HTMLSpanElement> {
|
|
|
52
57
|
| 'left-end'
|
|
53
58
|
| 'right-start'
|
|
54
59
|
| 'right-end';
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
refToGetParent?: React.RefObject<any>;
|
|
60
|
+
/** Additional props to pass to the tooltip. */
|
|
61
|
+
tooltipProps?: Omit<TooltipProps, 'content'>;
|
|
62
|
+
/** @hide Forwarded ref */
|
|
63
|
+
innerRef?: React.Ref<any>;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
const sliceTrailingContent = (str: string, slice: number) => [str.slice(0, str.length - slice), str.slice(-slice)];
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
const TruncateBase: React.FunctionComponent<TruncateProps> = ({
|
|
65
69
|
className,
|
|
70
|
+
href,
|
|
66
71
|
position = 'end',
|
|
67
72
|
tooltipPosition = 'top',
|
|
73
|
+
tooltipProps,
|
|
68
74
|
trailingNumChars = 7,
|
|
69
75
|
maxCharsDisplayed,
|
|
70
76
|
omissionContent = '\u2026',
|
|
71
77
|
content,
|
|
72
|
-
refToGetParent,
|
|
73
78
|
...props
|
|
74
79
|
}: TruncateProps) => {
|
|
75
80
|
const [isTruncated, setIsTruncated] = useState(true);
|
|
@@ -78,7 +83,8 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
78
83
|
const [shouldRenderByMaxChars, setShouldRenderByMaxChars] = useState(maxCharsDisplayed > 0);
|
|
79
84
|
|
|
80
85
|
const textRef = useRef<HTMLElement>(null);
|
|
81
|
-
const
|
|
86
|
+
const defaultSubParentRef = useRef<any>(null);
|
|
87
|
+
const subParentRef = tooltipProps?.triggerRef || defaultSubParentRef;
|
|
82
88
|
const observer = useRef(null);
|
|
83
89
|
|
|
84
90
|
if (maxCharsDisplayed <= 0) {
|
|
@@ -108,11 +114,14 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
108
114
|
if (textRef && textRef.current && !textElement) {
|
|
109
115
|
setTextElement(textRef.current);
|
|
110
116
|
}
|
|
117
|
+
}, [textRef, textElement]);
|
|
111
118
|
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
const refElement = getReferenceElement(subParentRef);
|
|
121
|
+
if (refElement?.parentElement && !parentElement) {
|
|
122
|
+
setParentElement(refElement.parentElement);
|
|
114
123
|
}
|
|
115
|
-
}, [
|
|
124
|
+
}, [subParentRef, parentElement]);
|
|
116
125
|
|
|
117
126
|
useEffect(() => {
|
|
118
127
|
if (textElement && parentElement && !observer.current && !shouldRenderByMaxChars) {
|
|
@@ -222,25 +231,37 @@ export const Truncate: React.FunctionComponent<TruncateProps> = ({
|
|
|
222
231
|
);
|
|
223
232
|
};
|
|
224
233
|
|
|
234
|
+
const TruncateWrapper = href ? 'a' : 'span';
|
|
225
235
|
const truncateBody = (
|
|
226
|
-
<
|
|
227
|
-
ref={subParentRef}
|
|
236
|
+
<TruncateWrapper
|
|
237
|
+
ref={!tooltipProps?.triggerRef ? (subParentRef as React.MutableRefObject<any>) : null}
|
|
238
|
+
href={href}
|
|
228
239
|
className={css(styles.truncate, shouldRenderByMaxChars && styles.modifiers.fixed, className)}
|
|
229
|
-
{...(isTruncated && { tabIndex: 0 })}
|
|
240
|
+
{...(isTruncated && !href && !tooltipProps?.triggerRef && { tabIndex: 0 })}
|
|
230
241
|
{...props}
|
|
231
242
|
>
|
|
232
243
|
{!shouldRenderByMaxChars ? renderResizeObserverContent() : renderMaxDisplayContent()}
|
|
233
|
-
</
|
|
244
|
+
</TruncateWrapper>
|
|
234
245
|
);
|
|
235
246
|
|
|
236
247
|
return (
|
|
237
248
|
<>
|
|
238
249
|
{isTruncated && (
|
|
239
|
-
<Tooltip
|
|
250
|
+
<Tooltip
|
|
251
|
+
hidden={!isTruncated}
|
|
252
|
+
position={tooltipPosition}
|
|
253
|
+
content={content}
|
|
254
|
+
triggerRef={subParentRef}
|
|
255
|
+
{...tooltipProps}
|
|
256
|
+
/>
|
|
240
257
|
)}
|
|
241
258
|
{truncateBody}
|
|
242
259
|
</>
|
|
243
260
|
);
|
|
244
261
|
};
|
|
245
262
|
|
|
263
|
+
export const Truncate = forwardRef((props: TruncateProps, ref: React.Ref<HTMLAnchorElement | HTMLSpanElement>) => (
|
|
264
|
+
<TruncateBase innerRef={ref} {...props} />
|
|
265
|
+
));
|
|
266
|
+
|
|
246
267
|
Truncate.displayName = 'Truncate';
|
|
@@ -19,6 +19,24 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
|
19
19
|
disconnect: jest.fn()
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
+
test('Renders with span wrapper by default', () => {
|
|
23
|
+
render(<Truncate content={''} data-testid="test-id" />);
|
|
24
|
+
|
|
25
|
+
expect(screen.getByTestId('test-id').tagName).toBe('SPAN');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('Renders with anchor wrapper when href prop is passed', () => {
|
|
29
|
+
render(<Truncate content={'Link content'} href="#" />);
|
|
30
|
+
|
|
31
|
+
expect(screen.getByRole('link')).toHaveTextContent('Link content');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Passes href to anchor when href prop is passed', () => {
|
|
35
|
+
render(<Truncate content={'Link content'} href="#home" />);
|
|
36
|
+
|
|
37
|
+
expect(screen.getByRole('link')).toHaveAttribute('href', '#home');
|
|
38
|
+
});
|
|
39
|
+
|
|
22
40
|
test(`renders with class ${styles.truncate}`, () => {
|
|
23
41
|
render(<Truncate content={''} aria-label="test-id" />);
|
|
24
42
|
|
|
@@ -145,6 +163,12 @@ test('renders tooltip content', () => {
|
|
|
145
163
|
expect(input).toBeVisible();
|
|
146
164
|
});
|
|
147
165
|
|
|
166
|
+
test('Renders with additional tooltip props spread', () => {
|
|
167
|
+
render(<Truncate content={''} tooltipProps={{ distance: 32 }} />);
|
|
168
|
+
|
|
169
|
+
expect(screen.getByTestId('Tooltip-mock')).toHaveAttribute('distance', '32');
|
|
170
|
+
});
|
|
171
|
+
|
|
148
172
|
test('renders with inherited element props spread to the component', () => {
|
|
149
173
|
render(<Truncate content={'Test'} data-testid="test-id" aria-label="labelling-id" />);
|
|
150
174
|
|
|
@@ -52,3 +52,11 @@ Truncating based on a maximum amount of characters will truncate the content at
|
|
|
52
52
|
```ts file="./TruncateMaxChars.tsx"
|
|
53
53
|
|
|
54
54
|
```
|
|
55
|
+
|
|
56
|
+
### With links
|
|
57
|
+
|
|
58
|
+
To truncate link text, you can pass the `href` property in.
|
|
59
|
+
|
|
60
|
+
```ts file="./TruncateLinks.tsx"
|
|
61
|
+
|
|
62
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Truncate } from '@patternfly/react-core';
|
|
2
|
+
|
|
3
|
+
export const TruncateLinks: React.FunctionComponent = () => {
|
|
4
|
+
const content = 'A very lengthy anchor text content to trigger truncation';
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<div>With default width-observing truncation:</div>
|
|
8
|
+
<div className="truncate-example-resize">
|
|
9
|
+
<Truncate href="#" content={content} />
|
|
10
|
+
<Truncate position="start" href="#" content={content} />
|
|
11
|
+
<Truncate position="middle" href="#" content={content} />
|
|
12
|
+
</div>
|
|
13
|
+
<br />
|
|
14
|
+
<div>With max characters truncation:</div>
|
|
15
|
+
<Truncate maxCharsDisplayed={15} href="#" content={content} />
|
|
16
|
+
<br />
|
|
17
|
+
<Truncate maxCharsDisplayed={15} position="start" href="#" content={content} />
|
|
18
|
+
<br />
|
|
19
|
+
<Truncate maxCharsDisplayed={15} position="middle" href="#" content={content} />
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
};
|
package/src/helpers/util.ts
CHANGED
|
@@ -545,3 +545,20 @@ export const getLanguageDirection = (targetElement: HTMLElement, defaultDirectio
|
|
|
545
545
|
|
|
546
546
|
return defaultDirection;
|
|
547
547
|
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Gets a reference element based on a ref property, which can typically be 1 of several types.
|
|
551
|
+
*
|
|
552
|
+
* @param {HTMLElement | (() => HTMLElement) | React.RefObject<any>} refProp The ref property to get a reference element from.
|
|
553
|
+
* @returns The reference element if one is found.
|
|
554
|
+
*/
|
|
555
|
+
export const getReferenceElement = (refProp: HTMLElement | (() => HTMLElement) | React.RefObject<any>) => {
|
|
556
|
+
if (refProp instanceof HTMLElement) {
|
|
557
|
+
return refProp;
|
|
558
|
+
}
|
|
559
|
+
if (typeof refProp === 'function') {
|
|
560
|
+
return refProp();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return refProp?.current;
|
|
564
|
+
};
|