1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Truncate = exports.TruncatePosition = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const React = tslib_1.__importStar(require("react"));
|
6 | const truncate_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Truncate/truncate"));
|
7 | const react_styles_1 = require("@patternfly/react-styles");
|
8 | const Tooltip_1 = require("../Tooltip");
|
9 | var TruncatePosition;
|
10 | (function (TruncatePosition) {
|
11 | TruncatePosition["start"] = "start";
|
12 | TruncatePosition["end"] = "end";
|
13 | TruncatePosition["middle"] = "middle";
|
14 | })(TruncatePosition = exports.TruncatePosition || (exports.TruncatePosition = {}));
|
15 | const truncateStyles = {
|
16 | start: truncate_1.default.truncateEnd,
|
17 | end: truncate_1.default.truncateStart
|
18 | };
|
19 | const minWidthCharacters = 12;
|
20 | const sliceContent = (str, slice) => [str.slice(0, str.length - slice), str.slice(-slice)];
|
21 | const Truncate = (_a) => {
|
22 | var { className, position = 'end', tooltipPosition = 'top', trailingNumChars = 7, content } = _a, props = tslib_1.__rest(_a, ["className", "position", "tooltipPosition", "trailingNumChars", "content"]);
|
23 | return (React.createElement(Tooltip_1.Tooltip, { position: tooltipPosition, content: content },
|
24 | React.createElement("span", Object.assign({ className: react_styles_1.css(truncate_1.default.truncate, className) }, props),
|
25 | (position === TruncatePosition.end || position === TruncatePosition.start) && (React.createElement("span", { className: truncateStyles[position] },
|
26 | content,
|
27 | position === TruncatePosition.start && React.createElement(React.Fragment, null, "\u200E"))),
|
28 | position === TruncatePosition.middle &&
|
29 | content.slice(0, content.length - trailingNumChars).length > minWidthCharacters && (React.createElement(React.Fragment, null,
|
30 | React.createElement("span", { className: truncate_1.default.truncateStart }, sliceContent(content, trailingNumChars)[0]),
|
31 | React.createElement("span", { className: truncate_1.default.truncateEnd }, sliceContent(content, trailingNumChars)[1]))),
|
32 | position === TruncatePosition.middle &&
|
33 | content.slice(0, content.length - trailingNumChars).length <= minWidthCharacters &&
|
34 | content)));
|
35 | };
|
36 | exports.Truncate = Truncate;
|
37 | exports.Truncate.displayName = 'Truncate';
|
38 |
|
\ | No newline at end of file |