@cloud-ru/ds-truncate-string 1.0.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/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +87 -0
- package/dist/cjs/TruncateString.d.ts +10 -0
- package/dist/cjs/TruncateString.js +17 -0
- package/dist/cjs/constants.d.ts +9 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/helperComponents/TruncateStringEnd/TruncateStringEnd.d.ts +18 -0
- package/dist/cjs/helperComponents/TruncateStringEnd/TruncateStringEnd.js +43 -0
- package/dist/cjs/helperComponents/TruncateStringEnd/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TruncateStringEnd/index.js +17 -0
- package/dist/cjs/helperComponents/TruncateStringEnd/styles.module.css +22 -0
- package/dist/cjs/helperComponents/TruncateStringMiddle/TruncateStringMiddle.d.ts +12 -0
- package/dist/cjs/helperComponents/TruncateStringMiddle/TruncateStringMiddle.js +40 -0
- package/dist/cjs/helperComponents/TruncateStringMiddle/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TruncateStringMiddle/index.js +17 -0
- package/dist/cjs/helperComponents/TruncateStringMiddle/styles.module.css +33 -0
- package/dist/cjs/helperComponents/index.d.ts +2 -0
- package/dist/cjs/helperComponents/index.js +18 -0
- package/dist/cjs/helpers/index.d.ts +2 -0
- package/dist/cjs/helpers/index.js +18 -0
- package/dist/cjs/helpers/isEllipsisActive.d.ts +1 -0
- package/dist/cjs/helpers/isEllipsisActive.js +10 -0
- package/dist/cjs/helpers/truncateStringMiddle.d.ts +5 -0
- package/dist/cjs/helpers/truncateStringMiddle.js +37 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +55 -0
- package/dist/cjs/types.d.ts +3 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/TruncateString.d.ts +10 -0
- package/dist/esm/TruncateString.js +14 -0
- package/dist/esm/constants.d.ts +9 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/helperComponents/TruncateStringEnd/TruncateStringEnd.d.ts +18 -0
- package/dist/esm/helperComponents/TruncateStringEnd/TruncateStringEnd.js +37 -0
- package/dist/esm/helperComponents/TruncateStringEnd/index.d.ts +1 -0
- package/dist/esm/helperComponents/TruncateStringEnd/index.js +1 -0
- package/dist/esm/helperComponents/TruncateStringEnd/styles.module.css +22 -0
- package/dist/esm/helperComponents/TruncateStringMiddle/TruncateStringMiddle.d.ts +12 -0
- package/dist/esm/helperComponents/TruncateStringMiddle/TruncateStringMiddle.js +34 -0
- package/dist/esm/helperComponents/TruncateStringMiddle/index.d.ts +1 -0
- package/dist/esm/helperComponents/TruncateStringMiddle/index.js +1 -0
- package/dist/esm/helperComponents/TruncateStringMiddle/styles.module.css +33 -0
- package/dist/esm/helperComponents/index.d.ts +2 -0
- package/dist/esm/helperComponents/index.js +2 -0
- package/dist/esm/helpers/index.d.ts +2 -0
- package/dist/esm/helpers/index.js +2 -0
- package/dist/esm/helpers/isEllipsisActive.d.ts +1 -0
- package/dist/esm/helpers/isEllipsisActive.js +6 -0
- package/dist/esm/helpers/truncateStringMiddle.d.ts +5 -0
- package/dist/esm/helpers/truncateStringMiddle.js +33 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/style.css +55 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.js +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +44 -0
- package/src/TruncateString.tsx +30 -0
- package/src/constants.ts +10 -0
- package/src/helperComponents/TruncateStringEnd/TruncateStringEnd.tsx +92 -0
- package/src/helperComponents/TruncateStringEnd/index.ts +1 -0
- package/src/helperComponents/TruncateStringEnd/styles.module.scss +31 -0
- package/src/helperComponents/TruncateStringMiddle/TruncateStringMiddle.tsx +88 -0
- package/src/helperComponents/TruncateStringMiddle/index.ts +1 -0
- package/src/helperComponents/TruncateStringMiddle/styles.module.scss +38 -0
- package/src/helperComponents/index.ts +2 -0
- package/src/helpers/index.ts +2 -0
- package/src/helpers/isEllipsisActive.ts +7 -0
- package/src/helpers/truncateStringMiddle.ts +48 -0
- package/src/index.ts +3 -0
- package/src/types.ts +5 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.truncateStringMiddle = void 0;
|
|
4
|
+
const isEllipsisActive_1 = require("./isEllipsisActive");
|
|
5
|
+
const CONFIG = [
|
|
6
|
+
{ potentialDelimiterWidth: 0.5, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
7
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
8
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0.5, rightHalfDelta: 0 },
|
|
9
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0, rightHalfDelta: 0.5 },
|
|
10
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
11
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 1, rightHalfDelta: 0 },
|
|
12
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 0, rightHalfDelta: 1 },
|
|
13
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
14
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 1, rightHalfDelta: 0 },
|
|
15
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 0, rightHalfDelta: 1 },
|
|
16
|
+
{ potentialDelimiterWidth: 4, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
17
|
+
];
|
|
18
|
+
const DELIMITER = '...';
|
|
19
|
+
const truncateStringMiddle = ({ text, element, truncatedElement, }) => {
|
|
20
|
+
if (element && truncatedElement && (0, isEllipsisActive_1.isEllipsisActive)(element)) {
|
|
21
|
+
const baseWidth = element.scrollWidth / text.length;
|
|
22
|
+
let result = text;
|
|
23
|
+
for (const { potentialDelimiterWidth, leftHalfDelta, rightHalfDelta } of CONFIG) {
|
|
24
|
+
const half = Math.floor((element.offsetWidth / baseWidth - potentialDelimiterWidth) / 2);
|
|
25
|
+
const leftHalf = text.slice(0, half - leftHalfDelta);
|
|
26
|
+
const rightHalf = text.slice(text.length - half + rightHalfDelta, text.length);
|
|
27
|
+
result = `${leftHalf}${DELIMITER}${rightHalf}`;
|
|
28
|
+
truncatedElement.innerText = result;
|
|
29
|
+
if (truncatedElement.scrollWidth <= element.offsetWidth - 1) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return text;
|
|
36
|
+
};
|
|
37
|
+
exports.truncateStringMiddle = truncateStringMiddle;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TruncateString"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
.text1Line{
|
|
2
|
+
overflow:hidden;
|
|
3
|
+
display:block;
|
|
4
|
+
max-width:100%;
|
|
5
|
+
text-overflow:ellipsis;
|
|
6
|
+
white-space:nowrap;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.text2AndMoreLines{
|
|
10
|
+
overflow:hidden;
|
|
11
|
+
display:-webkit-box;
|
|
12
|
+
-webkit-box-orient:vertical;
|
|
13
|
+
-webkit-line-clamp:var(--max-lines);
|
|
14
|
+
max-width:100%;
|
|
15
|
+
margin:0;
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
word-break:initial;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tooltipTrigger{
|
|
21
|
+
display:grid;
|
|
22
|
+
}
|
|
23
|
+
.wrapper{
|
|
24
|
+
position:relative;
|
|
25
|
+
overflow:hidden;
|
|
26
|
+
display:inline-flex;
|
|
27
|
+
flex-direction:column;
|
|
28
|
+
max-width:100%;
|
|
29
|
+
white-space:nowrap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.truncatedText{
|
|
33
|
+
position:absolute;
|
|
34
|
+
left:0;
|
|
35
|
+
display:-webkit-box;
|
|
36
|
+
-webkit-box-orient:vertical;
|
|
37
|
+
width:-moz-fit-content;
|
|
38
|
+
width:fit-content;
|
|
39
|
+
max-width:100%;
|
|
40
|
+
margin:0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fullText{
|
|
44
|
+
display:-webkit-box;
|
|
45
|
+
-webkit-box-orient:vertical;
|
|
46
|
+
width:-moz-fit-content;
|
|
47
|
+
width:fit-content;
|
|
48
|
+
max-width:100%;
|
|
49
|
+
margin:0;
|
|
50
|
+
opacity:0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.textContainer{
|
|
54
|
+
display:inline-flex;
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VARIANT } from './constants.js';
|
|
2
|
+
import { TruncateStringEndProps, TruncateStringMiddleProps } from './helperComponents/index.js';
|
|
3
|
+
export type TruncateStringProps = ({
|
|
4
|
+
/** Вариант обрезания строки: `End` - с конца */
|
|
5
|
+
variant?: typeof VARIANT.End;
|
|
6
|
+
} & TruncateStringEndProps) | ({
|
|
7
|
+
/** `Middle` - по середине */
|
|
8
|
+
variant: typeof VARIANT.Middle;
|
|
9
|
+
} & TruncateStringMiddleProps);
|
|
10
|
+
export declare function TruncateString({ variant, ...props }: TruncateStringProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { VARIANT } from './constants.js';
|
|
3
|
+
import { TruncateStringEnd, TruncateStringMiddle, } from './helperComponents/index.js';
|
|
4
|
+
export function TruncateString({ variant = VARIANT.End, ...props }) {
|
|
5
|
+
switch (variant) {
|
|
6
|
+
case VARIANT.Middle: {
|
|
7
|
+
return _jsx(TruncateStringMiddle, { ...props });
|
|
8
|
+
}
|
|
9
|
+
case VARIANT.End:
|
|
10
|
+
default: {
|
|
11
|
+
return _jsx(TruncateStringEnd, { ...props });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const VARIANT: {
|
|
2
|
+
readonly Middle: "middle";
|
|
3
|
+
readonly End: "end";
|
|
4
|
+
};
|
|
5
|
+
export declare const TEST_IDS: {
|
|
6
|
+
readonly root: "truncate-string";
|
|
7
|
+
readonly fullText: "truncate-string__full-text";
|
|
8
|
+
readonly truncatedText: "truncate-string__truncated-text";
|
|
9
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TooltipProps } from '@cloud-ru/ds-tooltip';
|
|
2
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
export type TruncateStringEndProps = WithSupportProps<{
|
|
4
|
+
className?: string;
|
|
5
|
+
/** Стиль для тултипа */
|
|
6
|
+
tooltipClassName?: string;
|
|
7
|
+
/** Скрывать ли тултип с полным текстом */
|
|
8
|
+
hideTooltip?: boolean;
|
|
9
|
+
/** Максимальное кол-во строк, до которого может сворачиваться текст. */
|
|
10
|
+
maxLines?: number;
|
|
11
|
+
/** Положение тултипа относительно обрезанного текста. */
|
|
12
|
+
placement?: TooltipProps['placement'];
|
|
13
|
+
/** Текст, который будет обрезаться */
|
|
14
|
+
text: string;
|
|
15
|
+
/** Условие отображения тултипа */
|
|
16
|
+
trigger?: TooltipProps['trigger'];
|
|
17
|
+
}>;
|
|
18
|
+
export declare function TruncateStringEnd({ text, className, tooltipClassName, hideTooltip, maxLines, placement, trigger, ...rest }: TruncateStringEndProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip } from '@cloud-ru/ds-tooltip';
|
|
3
|
+
import { extractSupportProps, throttle, useLayoutEffect } from '@cloud-ru/ds-utils';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { isEllipsisActive } from '../../helpers/index.js';
|
|
7
|
+
import styles from './styles.module.css';
|
|
8
|
+
export function TruncateStringEnd({ text, className, tooltipClassName, hideTooltip, maxLines = 1, placement = 'top', trigger = 'hoverAndFocusVisible', ...rest }) {
|
|
9
|
+
const textElementRef = useRef(null);
|
|
10
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
11
|
+
const toggleShowTooltip = useCallback(() => {
|
|
12
|
+
setShowTooltip(isEllipsisActive(textElementRef.current));
|
|
13
|
+
}, []);
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
if (textElementRef.current) {
|
|
16
|
+
toggleShowTooltip();
|
|
17
|
+
}
|
|
18
|
+
}, [text, toggleShowTooltip]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const throttledToggleShowTooltip = throttle(() => {
|
|
21
|
+
toggleShowTooltip();
|
|
22
|
+
}, 50);
|
|
23
|
+
const observer = new ResizeObserver(throttledToggleShowTooltip);
|
|
24
|
+
if (textElementRef.current) {
|
|
25
|
+
toggleShowTooltip();
|
|
26
|
+
observer.observe(textElementRef.current);
|
|
27
|
+
}
|
|
28
|
+
return () => {
|
|
29
|
+
observer.disconnect();
|
|
30
|
+
};
|
|
31
|
+
}, [showTooltip, hideTooltip, toggleShowTooltip]);
|
|
32
|
+
const textElement = (_jsx("span", { ref: textElementRef, className: cn(maxLines > 1 ? styles.text2AndMoreLines : styles.text1Line, className), style: { '--max-lines': maxLines }, ...extractSupportProps(rest), children: text }));
|
|
33
|
+
if (showTooltip && !hideTooltip) {
|
|
34
|
+
return (_jsx(Tooltip, { tip: text, placement: placement, hoverDelayOpen: 500, className: tooltipClassName, triggerClassName: styles.tooltipTrigger, trigger: trigger, children: textElement }));
|
|
35
|
+
}
|
|
36
|
+
return textElement;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TruncateStringEnd.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TruncateStringEnd.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.text1Line{
|
|
2
|
+
overflow:hidden;
|
|
3
|
+
display:block;
|
|
4
|
+
max-width:100%;
|
|
5
|
+
text-overflow:ellipsis;
|
|
6
|
+
white-space:nowrap;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.text2AndMoreLines{
|
|
10
|
+
overflow:hidden;
|
|
11
|
+
display:-webkit-box;
|
|
12
|
+
-webkit-box-orient:vertical;
|
|
13
|
+
-webkit-line-clamp:var(--max-lines);
|
|
14
|
+
max-width:100%;
|
|
15
|
+
margin:0;
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
word-break:initial;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tooltipTrigger{
|
|
21
|
+
display:grid;
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TooltipProps } from '@cloud-ru/ds-tooltip';
|
|
2
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
export type TruncateStringMiddleProps = WithSupportProps<{
|
|
4
|
+
className?: string;
|
|
5
|
+
/** Стиль для тултипа */
|
|
6
|
+
tooltipClassName?: string;
|
|
7
|
+
hideTooltip?: boolean;
|
|
8
|
+
placement?: TooltipProps['placement'];
|
|
9
|
+
text: string;
|
|
10
|
+
trigger?: TooltipProps['trigger'];
|
|
11
|
+
}>;
|
|
12
|
+
export declare function TruncateStringMiddle({ text, className, tooltipClassName, hideTooltip, placement, trigger, ...rest }: TruncateStringMiddleProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip } from '@cloud-ru/ds-tooltip';
|
|
3
|
+
import { extractSupportProps, throttle } from '@cloud-ru/ds-utils';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { TEST_IDS } from '../../constants.js';
|
|
7
|
+
import { isEllipsisActive, truncateStringMiddle } from '../../helpers/index.js';
|
|
8
|
+
import styles from './styles.module.css';
|
|
9
|
+
export function TruncateStringMiddle({ text, className, tooltipClassName, hideTooltip, placement = 'top', trigger = 'hoverAndFocusVisible', ...rest }) {
|
|
10
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
11
|
+
const [truncatedString, setTruncatedString] = useState(text);
|
|
12
|
+
const textElementRef = useRef(null);
|
|
13
|
+
const truncatedTextElementRef = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const setTruncate = throttle(() => {
|
|
16
|
+
setTruncatedString(truncateStringMiddle({
|
|
17
|
+
element: textElementRef.current,
|
|
18
|
+
truncatedElement: truncatedTextElementRef.current,
|
|
19
|
+
text,
|
|
20
|
+
}));
|
|
21
|
+
setShowTooltip(isEllipsisActive(textElementRef.current));
|
|
22
|
+
}, 50);
|
|
23
|
+
setTruncate();
|
|
24
|
+
const observer = new ResizeObserver(setTruncate);
|
|
25
|
+
if (textElementRef.current) {
|
|
26
|
+
observer.observe(textElementRef.current);
|
|
27
|
+
}
|
|
28
|
+
return () => {
|
|
29
|
+
observer.disconnect();
|
|
30
|
+
};
|
|
31
|
+
}, [showTooltip, text, hideTooltip]);
|
|
32
|
+
const textElement = (_jsxs(_Fragment, { children: [_jsx("span", { ref: textElementRef, className: styles.fullText, "data-test-id": TEST_IDS.fullText, children: text }), _jsx("span", { ref: truncatedTextElementRef, className: styles.truncatedText, "data-test-id": TEST_IDS.truncatedText, children: truncatedString })] }));
|
|
33
|
+
return (_jsx("span", { className: cn(styles.wrapper, className), ...extractSupportProps(rest), children: showTooltip && !hideTooltip ? (_jsx(Tooltip, { tip: text, placement: placement, hoverDelayOpen: 500, triggerClassName: styles.textContainer, className: tooltipClassName, trigger: trigger, children: textElement })) : (textElement) }));
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TruncateStringMiddle.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TruncateStringMiddle.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.wrapper{
|
|
2
|
+
position:relative;
|
|
3
|
+
overflow:hidden;
|
|
4
|
+
display:inline-flex;
|
|
5
|
+
flex-direction:column;
|
|
6
|
+
max-width:100%;
|
|
7
|
+
white-space:nowrap;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.truncatedText{
|
|
11
|
+
position:absolute;
|
|
12
|
+
left:0;
|
|
13
|
+
display:-webkit-box;
|
|
14
|
+
-webkit-box-orient:vertical;
|
|
15
|
+
width:-moz-fit-content;
|
|
16
|
+
width:fit-content;
|
|
17
|
+
max-width:100%;
|
|
18
|
+
margin:0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.fullText{
|
|
22
|
+
display:-webkit-box;
|
|
23
|
+
-webkit-box-orient:vertical;
|
|
24
|
+
width:-moz-fit-content;
|
|
25
|
+
width:fit-content;
|
|
26
|
+
max-width:100%;
|
|
27
|
+
margin:0;
|
|
28
|
+
opacity:0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.textContainer{
|
|
32
|
+
display:inline-flex;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEllipsisActive: (element: HTMLElement | null) => boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isEllipsisActive } from './isEllipsisActive.js';
|
|
2
|
+
const CONFIG = [
|
|
3
|
+
{ potentialDelimiterWidth: 0.5, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
4
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
5
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0.5, rightHalfDelta: 0 },
|
|
6
|
+
{ potentialDelimiterWidth: 1, leftHalfDelta: 0, rightHalfDelta: 0.5 },
|
|
7
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
8
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 1, rightHalfDelta: 0 },
|
|
9
|
+
{ potentialDelimiterWidth: 2, leftHalfDelta: 0, rightHalfDelta: 1 },
|
|
10
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
11
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 1, rightHalfDelta: 0 },
|
|
12
|
+
{ potentialDelimiterWidth: 3, leftHalfDelta: 0, rightHalfDelta: 1 },
|
|
13
|
+
{ potentialDelimiterWidth: 4, leftHalfDelta: 0, rightHalfDelta: 0 },
|
|
14
|
+
];
|
|
15
|
+
const DELIMITER = '...';
|
|
16
|
+
export const truncateStringMiddle = ({ text, element, truncatedElement, }) => {
|
|
17
|
+
if (element && truncatedElement && isEllipsisActive(element)) {
|
|
18
|
+
const baseWidth = element.scrollWidth / text.length;
|
|
19
|
+
let result = text;
|
|
20
|
+
for (const { potentialDelimiterWidth, leftHalfDelta, rightHalfDelta } of CONFIG) {
|
|
21
|
+
const half = Math.floor((element.offsetWidth / baseWidth - potentialDelimiterWidth) / 2);
|
|
22
|
+
const leftHalf = text.slice(0, half - leftHalfDelta);
|
|
23
|
+
const rightHalf = text.slice(text.length - half + rightHalfDelta, text.length);
|
|
24
|
+
result = `${leftHalf}${DELIMITER}${rightHalf}`;
|
|
25
|
+
truncatedElement.innerText = result;
|
|
26
|
+
if (truncatedElement.scrollWidth <= element.offsetWidth - 1) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
return text;
|
|
33
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
.text1Line{
|
|
2
|
+
overflow:hidden;
|
|
3
|
+
display:block;
|
|
4
|
+
max-width:100%;
|
|
5
|
+
text-overflow:ellipsis;
|
|
6
|
+
white-space:nowrap;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.text2AndMoreLines{
|
|
10
|
+
overflow:hidden;
|
|
11
|
+
display:-webkit-box;
|
|
12
|
+
-webkit-box-orient:vertical;
|
|
13
|
+
-webkit-line-clamp:var(--max-lines);
|
|
14
|
+
max-width:100%;
|
|
15
|
+
margin:0;
|
|
16
|
+
text-overflow:ellipsis;
|
|
17
|
+
word-break:initial;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tooltipTrigger{
|
|
21
|
+
display:grid;
|
|
22
|
+
}
|
|
23
|
+
.wrapper{
|
|
24
|
+
position:relative;
|
|
25
|
+
overflow:hidden;
|
|
26
|
+
display:inline-flex;
|
|
27
|
+
flex-direction:column;
|
|
28
|
+
max-width:100%;
|
|
29
|
+
white-space:nowrap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.truncatedText{
|
|
33
|
+
position:absolute;
|
|
34
|
+
left:0;
|
|
35
|
+
display:-webkit-box;
|
|
36
|
+
-webkit-box-orient:vertical;
|
|
37
|
+
width:-moz-fit-content;
|
|
38
|
+
width:fit-content;
|
|
39
|
+
max-width:100%;
|
|
40
|
+
margin:0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fullText{
|
|
44
|
+
display:-webkit-box;
|
|
45
|
+
-webkit-box-orient:vertical;
|
|
46
|
+
width:-moz-fit-content;
|
|
47
|
+
width:fit-content;
|
|
48
|
+
max-width:100%;
|
|
49
|
+
margin:0;
|
|
50
|
+
opacity:0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.textContainer{
|
|
54
|
+
display:inline-flex;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|