@elliemae/ds-truncated-expandable-text 2.1.0-rc.7 → 2.2.0-alpha.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/cjs/TruncatedExpandableText.js +88 -81
- package/cjs/TruncatedExpandableText.js.map +7 -0
- package/cjs/defaultProps.js +34 -9
- package/cjs/defaultProps.js.map +7 -0
- package/cjs/index.js +36 -11
- package/cjs/index.js.map +7 -0
- package/cjs/props.js +38 -14
- package/cjs/props.js.map +7 -0
- package/esm/TruncatedExpandableText.js +57 -64
- package/esm/TruncatedExpandableText.js.map +7 -0
- package/esm/defaultProps.js +5 -5
- package/esm/defaultProps.js.map +7 -0
- package/esm/index.js +7 -1
- package/esm/index.js.map +7 -0
- package/esm/props.js +8 -9
- package/esm/props.js.map +7 -0
- package/package.json +1 -1
|
@@ -1,100 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var TruncatedExpandableText_exports = {};
|
|
29
|
+
__export(TruncatedExpandableText_exports, {
|
|
30
|
+
DSTruncatedExpandableTextWithSchema: () => DSTruncatedExpandableTextWithSchema,
|
|
31
|
+
TruncatedExpandableText: () => TruncatedExpandableText,
|
|
32
|
+
default: () => TruncatedExpandableText_default
|
|
33
|
+
});
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_react_desc = __toESM(require("react-desc"));
|
|
37
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
38
|
+
var import_props = __toESM(require("./props"));
|
|
39
|
+
var import_defaultProps = __toESM(require("./defaultProps"));
|
|
40
|
+
const Text = import_styled_components.default.span`
|
|
41
|
+
text-overflow: ellipsis;
|
|
42
|
+
white-space: ${(props) => props.isExpanded ? "wrap" : "nowrap"};
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
display: ${(props) => props.isExpanded ? "-webkit-box" : "inline-block"};
|
|
45
|
+
-webkit-line-clamp: 3;
|
|
46
|
+
-webkit-box-orient: vertical;
|
|
47
|
+
max-width: 100%;
|
|
48
|
+
word-break: break-all;
|
|
49
|
+
`;
|
|
50
|
+
const TruncatedExpandableText = ({
|
|
51
|
+
containerProps,
|
|
52
|
+
value
|
|
53
|
+
}) => {
|
|
54
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
55
|
+
const ref = (0, import_react.useRef)(null);
|
|
56
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
57
|
+
if (typeof value !== "string")
|
|
58
|
+
return;
|
|
59
|
+
if (!open)
|
|
60
|
+
return;
|
|
61
|
+
let newHyphenizedValue = "";
|
|
42
62
|
const element = ref.current;
|
|
43
63
|
element.innerText = newHyphenizedValue;
|
|
44
|
-
let {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// try the hyphen here
|
|
49
|
-
element.innerText = "".concat(newHyphenizedValue, "-").concat(char);
|
|
50
|
-
const {
|
|
51
|
-
height: newHeight
|
|
52
|
-
} = element.getBoundingClientRect(); // if it's the first line or the height didn't change, hyphen doesn't go here,
|
|
53
|
-
// since we tried "-c", we are sure that "c-" fits in the line (so we don't
|
|
54
|
-
// ever have a case where the hyphen goes to the next line
|
|
55
|
-
|
|
64
|
+
let { height: previousHeight } = element.getBoundingClientRect();
|
|
65
|
+
value.split("").forEach((char, index) => {
|
|
66
|
+
element.innerText = `${newHyphenizedValue}-${char}`;
|
|
67
|
+
const { height: newHeight } = element.getBoundingClientRect();
|
|
56
68
|
if (!index || previousHeight === newHeight) {
|
|
57
69
|
newHyphenizedValue += char;
|
|
58
70
|
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
71
|
+
element.innerText = `${newHyphenizedValue}${char}`;
|
|
72
|
+
const { height: endOfWordHeight } = element.getBoundingClientRect();
|
|
73
|
+
if (endOfWordHeight === previousHeight)
|
|
74
|
+
newHyphenizedValue += char;
|
|
75
|
+
else
|
|
76
|
+
newHyphenizedValue += `-${char}`;
|
|
66
77
|
} else if (char.match(/\s/)) {
|
|
67
|
-
// we dont want "- ", leave the space character only
|
|
68
78
|
newHyphenizedValue += char;
|
|
69
79
|
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
70
|
-
|
|
71
|
-
newHyphenizedValue += " ".concat(char);
|
|
80
|
+
newHyphenizedValue += ` ${char}`;
|
|
72
81
|
} else {
|
|
73
|
-
newHyphenizedValue +=
|
|
82
|
+
newHyphenizedValue += `-${char}`;
|
|
74
83
|
}
|
|
75
|
-
|
|
76
84
|
previousHeight = newHeight;
|
|
77
85
|
});
|
|
78
86
|
element.innerText = newHyphenizedValue;
|
|
79
87
|
}, [open, value]);
|
|
80
|
-
return
|
|
81
|
-
ref
|
|
82
|
-
|
|
88
|
+
return /* @__PURE__ */ import_react.default.createElement(Text, {
|
|
89
|
+
ref,
|
|
90
|
+
...containerProps,
|
|
83
91
|
isExpanded: open,
|
|
84
|
-
onClick: e => {
|
|
92
|
+
onClick: (e) => {
|
|
85
93
|
e.persist();
|
|
86
94
|
setOpen(!open);
|
|
87
|
-
if (containerProps.onClick)
|
|
95
|
+
if (containerProps.onClick)
|
|
96
|
+
containerProps.onClick(e);
|
|
88
97
|
},
|
|
89
|
-
"data-testid": "ds-truncated-expandable-text"
|
|
90
|
-
|
|
91
|
-
}));
|
|
98
|
+
"data-testid": "ds-truncated-expandable-text"
|
|
99
|
+
}, value);
|
|
92
100
|
};
|
|
93
|
-
|
|
94
|
-
TruncatedExpandableText.defaultProps =
|
|
95
|
-
const DSTruncatedExpandableTextWithSchema =
|
|
96
|
-
DSTruncatedExpandableTextWithSchema.propTypes =
|
|
97
|
-
|
|
98
|
-
exports
|
|
99
|
-
|
|
100
|
-
exports["default"] = TruncatedExpandableText;
|
|
101
|
+
TruncatedExpandableText.propTypes = import_props.textProps;
|
|
102
|
+
TruncatedExpandableText.defaultProps = import_defaultProps.defaultProps;
|
|
103
|
+
const DSTruncatedExpandableTextWithSchema = (0, import_react_desc.describe)(TruncatedExpandableText);
|
|
104
|
+
DSTruncatedExpandableTextWithSchema.propTypes = import_props.textProps;
|
|
105
|
+
var TruncatedExpandableText_default = TruncatedExpandableText;
|
|
106
|
+
module.exports = __toCommonJS(TruncatedExpandableText_exports);
|
|
107
|
+
//# sourceMappingURL=TruncatedExpandableText.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/TruncatedExpandableText.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import React, {\n useRef,\n useState,\n useLayoutEffect,\n HTMLAttributes,\n} from 'react';\nimport { describe } from 'react-desc';\nimport styled from 'styled-components';\nimport { textProps } from './props';\nimport { defaultProps } from './defaultProps';\n\ntype TextProps = HTMLAttributes<HTMLSpanElement> & { isExpanded: boolean };\n\nconst Text = styled.span<TextProps>`\n text-overflow: ellipsis;\n white-space: ${(props) => (props.isExpanded ? 'wrap' : 'nowrap')};\n overflow: hidden;\n display: ${(props) => (props.isExpanded ? '-webkit-box' : 'inline-block')};\n -webkit-line-clamp: 3;\n -webkit-box-orient: vertical;\n max-width: 100%;\n word-break: break-all;\n`;\n\nconst TruncatedExpandableText = ({\n containerProps,\n value,\n}: {\n containerProps: HTMLAttributes<HTMLSpanElement>;\n value: string;\n}): JSX.Element => {\n const [open, setOpen] = useState(false);\n const ref = useRef<HTMLSpanElement>(null);\n\n useLayoutEffect(() => {\n if (typeof value !== 'string') return;\n if (!open) return;\n\n let newHyphenizedValue = '';\n\n const element = ref.current;\n element.innerText = newHyphenizedValue;\n let { height: previousHeight } = element.getBoundingClientRect();\n\n value.split('').forEach((char, index) => {\n // try the hyphen here\n element.innerText = `${newHyphenizedValue}-${char}`;\n const { height: newHeight } = element.getBoundingClientRect();\n // if it's the first line or the height didn't change, hyphen doesn't go here,\n // since we tried \"-c\", we are sure that \"c-\" fits in the line (so we don't\n // ever have a case where the hyphen goes to the next line\n if (!index || previousHeight === newHeight) {\n newHyphenizedValue += char;\n } else if (index < value.length - 1 && value[index + 1].match(/\\s/)) {\n // end of word\n element.innerText = `${newHyphenizedValue}${char}`;\n\n // sometimes the last character is wider and doesn't fit\n const { height: endOfWordHeight } = element.getBoundingClientRect();\n if (endOfWordHeight === previousHeight) newHyphenizedValue += char;\n else newHyphenizedValue += `-${char}`;\n } else if (char.match(/\\s/)) {\n // we dont want \"- \", leave the space character only\n newHyphenizedValue += char;\n } else if (\n newHyphenizedValue.length &&\n newHyphenizedValue[newHyphenizedValue.length - 1].match(/\\s/)\n ) {\n // we produce and empty space to make sure to start on the next line\n newHyphenizedValue += ` ${char}`;\n } else {\n newHyphenizedValue += `-${char}`;\n }\n previousHeight = newHeight;\n });\n element.innerText = newHyphenizedValue;\n }, [open, value]);\n\n return (\n <Text\n ref={ref}\n {...containerProps}\n isExpanded={open}\n onClick={(e) => {\n e.persist();\n setOpen(!open);\n if (containerProps.onClick) containerProps.onClick(e);\n }}\n data-testid=\"ds-truncated-expandable-text\"\n >\n {value}\n </Text>\n );\n};\n\nTruncatedExpandableText.propTypes = textProps;\n\nTruncatedExpandableText.defaultProps = defaultProps;\n\nconst DSTruncatedExpandableTextWithSchema = describe(TruncatedExpandableText);\n\nDSTruncatedExpandableTextWithSchema.propTypes = textProps;\n\nexport { TruncatedExpandableText, DSTruncatedExpandableTextWithSchema };\nexport default TruncatedExpandableText;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAKO;AACP,wBAAyB;AACzB,+BAAmB;AACnB,mBAA0B;AAC1B,0BAA6B;AAI7B,MAAM,OAAO,iCAAO;AAAA;AAAA,iBAEH,CAAC,UAAW,MAAM,aAAa,SAAS;AAAA;AAAA,aAE5C,CAAC,UAAW,MAAM,aAAa,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAO5D,MAAM,0BAA0B,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,MAIiB;AACjB,QAAM,CAAC,MAAM,WAAW,2BAAS;AACjC,QAAM,MAAM,yBAAwB;AAEpC,oCAAgB,MAAM;AACpB,QAAI,OAAO,UAAU;AAAU;AAC/B,QAAI,CAAC;AAAM;AAEX,QAAI,qBAAqB;AAEzB,UAAM,UAAU,IAAI;AACpB,YAAQ,YAAY;AACpB,QAAI,EAAE,QAAQ,mBAAmB,QAAQ;AAEzC,UAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,UAAU;AAEvC,cAAQ,YAAY,GAAG,sBAAsB;AAC7C,YAAM,EAAE,QAAQ,cAAc,QAAQ;AAItC,UAAI,CAAC,SAAS,mBAAmB,WAAW;AAC1C,8BAAsB;AAAA,iBACb,QAAQ,MAAM,SAAS,KAAK,MAAM,QAAQ,GAAG,MAAM,OAAO;AAEnE,gBAAQ,YAAY,GAAG,qBAAqB;AAG5C,cAAM,EAAE,QAAQ,oBAAoB,QAAQ;AAC5C,YAAI,oBAAoB;AAAgB,gCAAsB;AAAA;AACzD,gCAAsB,IAAI;AAAA,iBACtB,KAAK,MAAM,OAAO;AAE3B,8BAAsB;AAAA,iBAEtB,mBAAmB,UACnB,mBAAmB,mBAAmB,SAAS,GAAG,MAAM,OACxD;AAEA,8BAAsB,IAAI;AAAA,aACrB;AACL,8BAAsB,IAAI;AAAA;AAE5B,uBAAiB;AAAA;AAEnB,YAAQ,YAAY;AAAA,KACnB,CAAC,MAAM;AAEV,SACE,mDAAC,MAAD;AAAA,IACE;AAAA,OACI;AAAA,IACJ,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM;AACd,QAAE;AACF,cAAQ,CAAC;AACT,UAAI,eAAe;AAAS,uBAAe,QAAQ;AAAA;AAAA,IAErD,eAAY;AAAA,KAEX;AAAA;AAKP,wBAAwB,YAAY;AAEpC,wBAAwB,eAAe;AAEvC,MAAM,sCAAsC,gCAAS;AAErD,oCAAoC,YAAY;AAGhD,IAAO,kCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/cjs/defaultProps.js
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
11
|
};
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var defaultProps_exports = {};
|
|
29
|
+
__export(defaultProps_exports, {
|
|
30
|
+
defaultProps: () => defaultProps
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
const defaultProps = { containerProps: {}, value: "" };
|
|
34
|
+
module.exports = __toCommonJS(defaultProps_exports);
|
|
35
|
+
//# sourceMappingURL=defaultProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/defaultProps.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["export const defaultProps = { containerProps: {}, value: '' };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAhB,MAAM,eAAe,EAAE,gBAAgB,IAAI,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/cjs/index.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
default: () => import_TruncatedExpandableText.default
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
__reExport(src_exports, __toESM(require("./TruncatedExpandableText")));
|
|
34
|
+
var import_TruncatedExpandableText = __toESM(require("./TruncatedExpandableText"));
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["export * from './TruncatedExpandableText';\nexport { default } from './TruncatedExpandableText';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,wBAAc;AACd,qCAAwB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/cjs/props.js
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var props_exports = {};
|
|
29
|
+
__export(props_exports, {
|
|
30
|
+
textProps: () => textProps
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react_desc = __toESM(require("react-desc"));
|
|
7
34
|
const textProps = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.textProps = textProps;
|
|
35
|
+
containerProps: import_react_desc.PropTypes.object.description("props injected to wrapper of truncated expandable text"),
|
|
36
|
+
value: import_react_desc.PropTypes.oneOfType([import_react_desc.PropTypes.string, import_react_desc.PropTypes.number]).description("Text that when truncated will trigger the tooltip interaction")
|
|
37
|
+
};
|
|
38
|
+
module.exports = __toCommonJS(props_exports);
|
|
39
|
+
//# sourceMappingURL=props.js.map
|
package/cjs/props.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/props.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { PropTypes } from 'react-desc';\n\nexport const textProps = {\n /** props injected to wrapper of page header */\n containerProps: PropTypes.object.description(\n 'props injected to wrapper of truncated expandable text',\n ),\n /** Text that when truncated will trigger the tooltip interaction */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description(\n 'Text that when truncated will trigger the tooltip interaction',\n ),\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,wBAA0B;AAEnB,MAAM,YAAY;AAAA,EAEvB,gBAAgB,4BAAU,OAAO,YAC/B;AAAA,EAGF,OAAO,4BAAU,UAAU,CAAC,4BAAU,QAAQ,4BAAU,SAAS,YAC/D;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,89 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value
|
|
26
|
-
} = _ref;
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, {
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
useLayoutEffect
|
|
6
|
+
} from "react";
|
|
7
|
+
import { describe } from "react-desc";
|
|
8
|
+
import styled from "styled-components";
|
|
9
|
+
import { textProps } from "./props";
|
|
10
|
+
import { defaultProps } from "./defaultProps";
|
|
11
|
+
const Text = styled.span`
|
|
12
|
+
text-overflow: ellipsis;
|
|
13
|
+
white-space: ${(props) => props.isExpanded ? "wrap" : "nowrap"};
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
display: ${(props) => props.isExpanded ? "-webkit-box" : "inline-block"};
|
|
16
|
+
-webkit-line-clamp: 3;
|
|
17
|
+
-webkit-box-orient: vertical;
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
word-break: break-all;
|
|
20
|
+
`;
|
|
21
|
+
const TruncatedExpandableText = ({
|
|
22
|
+
containerProps,
|
|
23
|
+
value
|
|
24
|
+
}) => {
|
|
27
25
|
const [open, setOpen] = useState(false);
|
|
28
26
|
const ref = useRef(null);
|
|
29
27
|
useLayoutEffect(() => {
|
|
30
|
-
if (typeof value !==
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (typeof value !== "string")
|
|
29
|
+
return;
|
|
30
|
+
if (!open)
|
|
31
|
+
return;
|
|
32
|
+
let newHyphenizedValue = "";
|
|
33
33
|
const element = ref.current;
|
|
34
34
|
element.innerText = newHyphenizedValue;
|
|
35
|
-
let {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// try the hyphen here
|
|
40
|
-
element.innerText = "".concat(newHyphenizedValue, "-").concat(char);
|
|
41
|
-
const {
|
|
42
|
-
height: newHeight
|
|
43
|
-
} = element.getBoundingClientRect(); // if it's the first line or the height didn't change, hyphen doesn't go here,
|
|
44
|
-
// since we tried "-c", we are sure that "c-" fits in the line (so we don't
|
|
45
|
-
// ever have a case where the hyphen goes to the next line
|
|
46
|
-
|
|
35
|
+
let { height: previousHeight } = element.getBoundingClientRect();
|
|
36
|
+
value.split("").forEach((char, index) => {
|
|
37
|
+
element.innerText = `${newHyphenizedValue}-${char}`;
|
|
38
|
+
const { height: newHeight } = element.getBoundingClientRect();
|
|
47
39
|
if (!index || previousHeight === newHeight) {
|
|
48
40
|
newHyphenizedValue += char;
|
|
49
41
|
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
42
|
+
element.innerText = `${newHyphenizedValue}${char}`;
|
|
43
|
+
const { height: endOfWordHeight } = element.getBoundingClientRect();
|
|
44
|
+
if (endOfWordHeight === previousHeight)
|
|
45
|
+
newHyphenizedValue += char;
|
|
46
|
+
else
|
|
47
|
+
newHyphenizedValue += `-${char}`;
|
|
57
48
|
} else if (char.match(/\s/)) {
|
|
58
|
-
// we dont want "- ", leave the space character only
|
|
59
49
|
newHyphenizedValue += char;
|
|
60
50
|
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
61
|
-
|
|
62
|
-
newHyphenizedValue += " ".concat(char);
|
|
51
|
+
newHyphenizedValue += ` ${char}`;
|
|
63
52
|
} else {
|
|
64
|
-
newHyphenizedValue +=
|
|
53
|
+
newHyphenizedValue += `-${char}`;
|
|
65
54
|
}
|
|
66
|
-
|
|
67
55
|
previousHeight = newHeight;
|
|
68
56
|
});
|
|
69
57
|
element.innerText = newHyphenizedValue;
|
|
70
58
|
}, [open, value]);
|
|
71
|
-
return
|
|
72
|
-
ref
|
|
73
|
-
|
|
59
|
+
return /* @__PURE__ */ React2.createElement(Text, {
|
|
60
|
+
ref,
|
|
61
|
+
...containerProps,
|
|
74
62
|
isExpanded: open,
|
|
75
|
-
onClick: e => {
|
|
63
|
+
onClick: (e) => {
|
|
76
64
|
e.persist();
|
|
77
65
|
setOpen(!open);
|
|
78
|
-
if (containerProps.onClick)
|
|
66
|
+
if (containerProps.onClick)
|
|
67
|
+
containerProps.onClick(e);
|
|
79
68
|
},
|
|
80
|
-
"data-testid": "ds-truncated-expandable-text"
|
|
81
|
-
|
|
82
|
-
}));
|
|
69
|
+
"data-testid": "ds-truncated-expandable-text"
|
|
70
|
+
}, value);
|
|
83
71
|
};
|
|
84
|
-
|
|
72
|
+
TruncatedExpandableText.propTypes = textProps;
|
|
85
73
|
TruncatedExpandableText.defaultProps = defaultProps;
|
|
86
74
|
const DSTruncatedExpandableTextWithSchema = describe(TruncatedExpandableText);
|
|
87
75
|
DSTruncatedExpandableTextWithSchema.propTypes = textProps;
|
|
88
|
-
|
|
89
|
-
export {
|
|
76
|
+
var TruncatedExpandableText_default = TruncatedExpandableText;
|
|
77
|
+
export {
|
|
78
|
+
DSTruncatedExpandableTextWithSchema,
|
|
79
|
+
TruncatedExpandableText,
|
|
80
|
+
TruncatedExpandableText_default as default
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=TruncatedExpandableText.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/TruncatedExpandableText.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, {\n useRef,\n useState,\n useLayoutEffect,\n HTMLAttributes,\n} from 'react';\nimport { describe } from 'react-desc';\nimport styled from 'styled-components';\nimport { textProps } from './props';\nimport { defaultProps } from './defaultProps';\n\ntype TextProps = HTMLAttributes<HTMLSpanElement> & { isExpanded: boolean };\n\nconst Text = styled.span<TextProps>`\n text-overflow: ellipsis;\n white-space: ${(props) => (props.isExpanded ? 'wrap' : 'nowrap')};\n overflow: hidden;\n display: ${(props) => (props.isExpanded ? '-webkit-box' : 'inline-block')};\n -webkit-line-clamp: 3;\n -webkit-box-orient: vertical;\n max-width: 100%;\n word-break: break-all;\n`;\n\nconst TruncatedExpandableText = ({\n containerProps,\n value,\n}: {\n containerProps: HTMLAttributes<HTMLSpanElement>;\n value: string;\n}): JSX.Element => {\n const [open, setOpen] = useState(false);\n const ref = useRef<HTMLSpanElement>(null);\n\n useLayoutEffect(() => {\n if (typeof value !== 'string') return;\n if (!open) return;\n\n let newHyphenizedValue = '';\n\n const element = ref.current;\n element.innerText = newHyphenizedValue;\n let { height: previousHeight } = element.getBoundingClientRect();\n\n value.split('').forEach((char, index) => {\n // try the hyphen here\n element.innerText = `${newHyphenizedValue}-${char}`;\n const { height: newHeight } = element.getBoundingClientRect();\n // if it's the first line or the height didn't change, hyphen doesn't go here,\n // since we tried \"-c\", we are sure that \"c-\" fits in the line (so we don't\n // ever have a case where the hyphen goes to the next line\n if (!index || previousHeight === newHeight) {\n newHyphenizedValue += char;\n } else if (index < value.length - 1 && value[index + 1].match(/\\s/)) {\n // end of word\n element.innerText = `${newHyphenizedValue}${char}`;\n\n // sometimes the last character is wider and doesn't fit\n const { height: endOfWordHeight } = element.getBoundingClientRect();\n if (endOfWordHeight === previousHeight) newHyphenizedValue += char;\n else newHyphenizedValue += `-${char}`;\n } else if (char.match(/\\s/)) {\n // we dont want \"- \", leave the space character only\n newHyphenizedValue += char;\n } else if (\n newHyphenizedValue.length &&\n newHyphenizedValue[newHyphenizedValue.length - 1].match(/\\s/)\n ) {\n // we produce and empty space to make sure to start on the next line\n newHyphenizedValue += ` ${char}`;\n } else {\n newHyphenizedValue += `-${char}`;\n }\n previousHeight = newHeight;\n });\n element.innerText = newHyphenizedValue;\n }, [open, value]);\n\n return (\n <Text\n ref={ref}\n {...containerProps}\n isExpanded={open}\n onClick={(e) => {\n e.persist();\n setOpen(!open);\n if (containerProps.onClick) containerProps.onClick(e);\n }}\n data-testid=\"ds-truncated-expandable-text\"\n >\n {value}\n </Text>\n );\n};\n\nTruncatedExpandableText.propTypes = textProps;\n\nTruncatedExpandableText.defaultProps = defaultProps;\n\nconst DSTruncatedExpandableTextWithSchema = describe(TruncatedExpandableText);\n\nDSTruncatedExpandableTextWithSchema.propTypes = textProps;\n\nexport { TruncatedExpandableText, DSTruncatedExpandableTextWithSchema };\nexport default TruncatedExpandableText;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAAA;AAAA;AAAA;AAAA;AAMA;AACA;AACA;AACA;AAIA,MAAM,OAAO,OAAO;AAAA;AAAA,iBAEH,CAAC,UAAW,MAAM,aAAa,SAAS;AAAA;AAAA,aAE5C,CAAC,UAAW,MAAM,aAAa,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAO5D,MAAM,0BAA0B,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,MAIiB;AACjB,QAAM,CAAC,MAAM,WAAW,SAAS;AACjC,QAAM,MAAM,OAAwB;AAEpC,kBAAgB,MAAM;AACpB,QAAI,OAAO,UAAU;AAAU;AAC/B,QAAI,CAAC;AAAM;AAEX,QAAI,qBAAqB;AAEzB,UAAM,UAAU,IAAI;AACpB,YAAQ,YAAY;AACpB,QAAI,EAAE,QAAQ,mBAAmB,QAAQ;AAEzC,UAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,UAAU;AAEvC,cAAQ,YAAY,GAAG,sBAAsB;AAC7C,YAAM,EAAE,QAAQ,cAAc,QAAQ;AAItC,UAAI,CAAC,SAAS,mBAAmB,WAAW;AAC1C,8BAAsB;AAAA,iBACb,QAAQ,MAAM,SAAS,KAAK,MAAM,QAAQ,GAAG,MAAM,OAAO;AAEnE,gBAAQ,YAAY,GAAG,qBAAqB;AAG5C,cAAM,EAAE,QAAQ,oBAAoB,QAAQ;AAC5C,YAAI,oBAAoB;AAAgB,gCAAsB;AAAA;AACzD,gCAAsB,IAAI;AAAA,iBACtB,KAAK,MAAM,OAAO;AAE3B,8BAAsB;AAAA,iBAEtB,mBAAmB,UACnB,mBAAmB,mBAAmB,SAAS,GAAG,MAAM,OACxD;AAEA,8BAAsB,IAAI;AAAA,aACrB;AACL,8BAAsB,IAAI;AAAA;AAE5B,uBAAiB;AAAA;AAEnB,YAAQ,YAAY;AAAA,KACnB,CAAC,MAAM;AAEV,SACE,qCAAC,MAAD;AAAA,IACE;AAAA,OACI;AAAA,IACJ,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM;AACd,QAAE;AACF,cAAQ,CAAC;AACT,UAAI,eAAe;AAAS,uBAAe,QAAQ;AAAA;AAAA,IAErD,eAAY;AAAA,KAEX;AAAA;AAKP,wBAAwB,YAAY;AAEpC,wBAAwB,eAAe;AAEvC,MAAM,sCAAsC,SAAS;AAErD,oCAAoC,YAAY;AAGhD,IAAO,kCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/defaultProps.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/defaultProps.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export const defaultProps = { containerProps: {}, value: '' };\n"],
|
|
5
|
+
"mappings": "AAAA;ACAO,MAAM,eAAe,EAAE,gBAAgB,IAAI,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export * from "./TruncatedExpandableText";
|
|
3
|
+
import { default as default2 } from "./TruncatedExpandableText";
|
|
4
|
+
export {
|
|
5
|
+
default2 as default
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './TruncatedExpandableText';\nexport { default } from './TruncatedExpandableText';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/esm/props.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PropTypes } from "react-desc";
|
|
3
3
|
const textProps = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** Text that when truncated will trigger the tooltip interaction */
|
|
8
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Text that when truncated will trigger the tooltip interaction')
|
|
4
|
+
containerProps: PropTypes.object.description("props injected to wrapper of truncated expandable text"),
|
|
5
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description("Text that when truncated will trigger the tooltip interaction")
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export {
|
|
8
|
+
textProps
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=props.js.map
|
package/esm/props.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/props.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes } from 'react-desc';\n\nexport const textProps = {\n /** props injected to wrapper of page header */\n containerProps: PropTypes.object.description(\n 'props injected to wrapper of truncated expandable text',\n ),\n /** Text that when truncated will trigger the tooltip interaction */\n value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description(\n 'Text that when truncated will trigger the tooltip interaction',\n ),\n};\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AAEO,MAAM,YAAY;AAAA,EAEvB,gBAAgB,UAAU,OAAO,YAC/B;AAAA,EAGF,OAAO,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,SAAS,YAC/D;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|