@elliemae/ds-truncated-expandable-text 3.0.0-next.0 → 3.0.0-next.4
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/dist/cjs/TruncatedExpandableText.js +124 -0
- package/dist/cjs/TruncatedExpandableText.js.map +7 -0
- package/dist/cjs/defaultProps.js +35 -0
- package/dist/cjs/defaultProps.js.map +7 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/props.js +39 -0
- package/dist/cjs/props.js.map +7 -0
- package/dist/esm/TruncatedExpandableText.js +101 -0
- package/dist/esm/TruncatedExpandableText.js.map +7 -0
- package/dist/esm/defaultProps.js +6 -0
- package/dist/esm/defaultProps.js.map +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/props.js +10 -0
- package/dist/esm/props.js.map +7 -0
- package/package.json +31 -22
- package/cjs/TruncatedExpandableText.js +0 -100
- package/cjs/defaultProps.js +0 -10
- package/cjs/index.js +0 -11
- package/cjs/props.js +0 -15
- package/esm/TruncatedExpandableText.js +0 -89
- package/esm/defaultProps.js +0 -6
- package/esm/index.js +0 -1
- package/esm/props.js +0 -11
- package/types/TruncatedExpandableText.d.ts +0 -36
- package/types/defaultProps.d.ts +0 -4
- package/types/index.d.ts +0 -2
- package/types/props.d.ts +0 -17
- package/types/tests/TruncatedExpandableText.test.d.ts +0 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
30
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(module2))
|
|
32
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
33
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (module2, isNodeMode) => {
|
|
38
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
39
|
+
};
|
|
40
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
41
|
+
return (module2, temp) => {
|
|
42
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
43
|
+
};
|
|
44
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
45
|
+
var TruncatedExpandableText_exports = {};
|
|
46
|
+
__export(TruncatedExpandableText_exports, {
|
|
47
|
+
DSTruncatedExpandableTextWithSchema: () => DSTruncatedExpandableTextWithSchema,
|
|
48
|
+
TruncatedExpandableText: () => TruncatedExpandableText,
|
|
49
|
+
default: () => TruncatedExpandableText_default
|
|
50
|
+
});
|
|
51
|
+
var React = __toESM(require("react"));
|
|
52
|
+
var import_react = __toESM(require("react"));
|
|
53
|
+
var import_react_desc = require("react-desc");
|
|
54
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
55
|
+
var import_props = require("./props");
|
|
56
|
+
var import_defaultProps = require("./defaultProps");
|
|
57
|
+
const Text = import_styled_components.default.span`
|
|
58
|
+
text-overflow: ellipsis;
|
|
59
|
+
white-space: ${(props) => props.isExpanded ? "wrap" : "nowrap"};
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
display: ${(props) => props.isExpanded ? "-webkit-box" : "inline-block"};
|
|
62
|
+
-webkit-line-clamp: 3;
|
|
63
|
+
-webkit-box-orient: vertical;
|
|
64
|
+
max-width: 100%;
|
|
65
|
+
word-break: break-all;
|
|
66
|
+
`;
|
|
67
|
+
const TruncatedExpandableText = ({
|
|
68
|
+
containerProps,
|
|
69
|
+
value
|
|
70
|
+
}) => {
|
|
71
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
72
|
+
const ref = (0, import_react.useRef)(null);
|
|
73
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
74
|
+
if (typeof value !== "string")
|
|
75
|
+
return;
|
|
76
|
+
if (!open)
|
|
77
|
+
return;
|
|
78
|
+
let newHyphenizedValue = "";
|
|
79
|
+
const element = ref.current;
|
|
80
|
+
element.innerText = newHyphenizedValue;
|
|
81
|
+
let { height: previousHeight } = element.getBoundingClientRect();
|
|
82
|
+
value.split("").forEach((char, index) => {
|
|
83
|
+
element.innerText = `${newHyphenizedValue}-${char}`;
|
|
84
|
+
const { height: newHeight } = element.getBoundingClientRect();
|
|
85
|
+
if (!index || previousHeight === newHeight) {
|
|
86
|
+
newHyphenizedValue += char;
|
|
87
|
+
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
88
|
+
element.innerText = `${newHyphenizedValue}${char}`;
|
|
89
|
+
const { height: endOfWordHeight } = element.getBoundingClientRect();
|
|
90
|
+
if (endOfWordHeight === previousHeight)
|
|
91
|
+
newHyphenizedValue += char;
|
|
92
|
+
else
|
|
93
|
+
newHyphenizedValue += `-${char}`;
|
|
94
|
+
} else if (char.match(/\s/)) {
|
|
95
|
+
newHyphenizedValue += char;
|
|
96
|
+
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
97
|
+
newHyphenizedValue += ` ${char}`;
|
|
98
|
+
} else {
|
|
99
|
+
newHyphenizedValue += `-${char}`;
|
|
100
|
+
}
|
|
101
|
+
previousHeight = newHeight;
|
|
102
|
+
});
|
|
103
|
+
element.innerText = newHyphenizedValue;
|
|
104
|
+
}, [open, value]);
|
|
105
|
+
return /* @__PURE__ */ import_react.default.createElement(Text, __spreadProps(__spreadValues({
|
|
106
|
+
ref
|
|
107
|
+
}, containerProps), {
|
|
108
|
+
isExpanded: open,
|
|
109
|
+
onClick: (e) => {
|
|
110
|
+
e.persist();
|
|
111
|
+
setOpen(!open);
|
|
112
|
+
if (containerProps.onClick)
|
|
113
|
+
containerProps.onClick(e);
|
|
114
|
+
},
|
|
115
|
+
"data-testid": "ds-truncated-expandable-text"
|
|
116
|
+
}), value);
|
|
117
|
+
};
|
|
118
|
+
TruncatedExpandableText.propTypes = import_props.textProps;
|
|
119
|
+
TruncatedExpandableText.defaultProps = import_defaultProps.defaultProps;
|
|
120
|
+
const DSTruncatedExpandableTextWithSchema = (0, import_react_desc.describe)(TruncatedExpandableText);
|
|
121
|
+
DSTruncatedExpandableTextWithSchema.propTypes = import_props.textProps;
|
|
122
|
+
var TruncatedExpandableText_default = TruncatedExpandableText;
|
|
123
|
+
module.exports = __toCommonJS(TruncatedExpandableText_exports);
|
|
124
|
+
//# 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,KACI,iBAFN;AAAA,IAGE,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM;AACd,QAAE;AACF,cAAQ,CAAC;AACT,UAAI,eAAe;AAAS,uBAAe,QAAQ;AAAA;AAAA,IAErD,eAAY;AAAA,MAEX;AAAA;AAKP,wBAAwB,YAAY;AAEpC,wBAAwB,eAAe;AAEvC,MAAM,sCAAsC,gCAAS;AAErD,oCAAoC,YAAY;AAGhD,IAAO,kCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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, require("./TruncatedExpandableText"));
|
|
34
|
+
var import_TruncatedExpandableText = __toESM(require("./TruncatedExpandableText"));
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 = require("react-desc");
|
|
34
|
+
const 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
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import * as React from "react";
|
|
21
|
+
import React2, {
|
|
22
|
+
useRef,
|
|
23
|
+
useState,
|
|
24
|
+
useLayoutEffect
|
|
25
|
+
} from "react";
|
|
26
|
+
import { describe } from "react-desc";
|
|
27
|
+
import styled from "styled-components";
|
|
28
|
+
import { textProps } from "./props";
|
|
29
|
+
import { defaultProps } from "./defaultProps";
|
|
30
|
+
const Text = styled.span`
|
|
31
|
+
text-overflow: ellipsis;
|
|
32
|
+
white-space: ${(props) => props.isExpanded ? "wrap" : "nowrap"};
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
display: ${(props) => props.isExpanded ? "-webkit-box" : "inline-block"};
|
|
35
|
+
-webkit-line-clamp: 3;
|
|
36
|
+
-webkit-box-orient: vertical;
|
|
37
|
+
max-width: 100%;
|
|
38
|
+
word-break: break-all;
|
|
39
|
+
`;
|
|
40
|
+
const TruncatedExpandableText = ({
|
|
41
|
+
containerProps,
|
|
42
|
+
value
|
|
43
|
+
}) => {
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
const ref = useRef(null);
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
if (typeof value !== "string")
|
|
48
|
+
return;
|
|
49
|
+
if (!open)
|
|
50
|
+
return;
|
|
51
|
+
let newHyphenizedValue = "";
|
|
52
|
+
const element = ref.current;
|
|
53
|
+
element.innerText = newHyphenizedValue;
|
|
54
|
+
let { height: previousHeight } = element.getBoundingClientRect();
|
|
55
|
+
value.split("").forEach((char, index) => {
|
|
56
|
+
element.innerText = `${newHyphenizedValue}-${char}`;
|
|
57
|
+
const { height: newHeight } = element.getBoundingClientRect();
|
|
58
|
+
if (!index || previousHeight === newHeight) {
|
|
59
|
+
newHyphenizedValue += char;
|
|
60
|
+
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
61
|
+
element.innerText = `${newHyphenizedValue}${char}`;
|
|
62
|
+
const { height: endOfWordHeight } = element.getBoundingClientRect();
|
|
63
|
+
if (endOfWordHeight === previousHeight)
|
|
64
|
+
newHyphenizedValue += char;
|
|
65
|
+
else
|
|
66
|
+
newHyphenizedValue += `-${char}`;
|
|
67
|
+
} else if (char.match(/\s/)) {
|
|
68
|
+
newHyphenizedValue += char;
|
|
69
|
+
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
70
|
+
newHyphenizedValue += ` ${char}`;
|
|
71
|
+
} else {
|
|
72
|
+
newHyphenizedValue += `-${char}`;
|
|
73
|
+
}
|
|
74
|
+
previousHeight = newHeight;
|
|
75
|
+
});
|
|
76
|
+
element.innerText = newHyphenizedValue;
|
|
77
|
+
}, [open, value]);
|
|
78
|
+
return /* @__PURE__ */ React2.createElement(Text, __spreadProps(__spreadValues({
|
|
79
|
+
ref
|
|
80
|
+
}, containerProps), {
|
|
81
|
+
isExpanded: open,
|
|
82
|
+
onClick: (e) => {
|
|
83
|
+
e.persist();
|
|
84
|
+
setOpen(!open);
|
|
85
|
+
if (containerProps.onClick)
|
|
86
|
+
containerProps.onClick(e);
|
|
87
|
+
},
|
|
88
|
+
"data-testid": "ds-truncated-expandable-text"
|
|
89
|
+
}), value);
|
|
90
|
+
};
|
|
91
|
+
TruncatedExpandableText.propTypes = textProps;
|
|
92
|
+
TruncatedExpandableText.defaultProps = defaultProps;
|
|
93
|
+
const DSTruncatedExpandableTextWithSchema = describe(TruncatedExpandableText);
|
|
94
|
+
DSTruncatedExpandableTextWithSchema.propTypes = textProps;
|
|
95
|
+
var TruncatedExpandableText_default = TruncatedExpandableText;
|
|
96
|
+
export {
|
|
97
|
+
DSTruncatedExpandableTextWithSchema,
|
|
98
|
+
TruncatedExpandableText,
|
|
99
|
+
TruncatedExpandableText_default as default
|
|
100
|
+
};
|
|
101
|
+
//# 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,KACI,iBAFN;AAAA,IAGE,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM;AACd,QAAE;AACF,cAAQ,CAAC;AACT,UAAI,eAAe;AAAS,uBAAe,QAAQ;AAAA;AAAA,IAErD,eAAY;AAAA,MAEX;AAAA;AAKP,wBAAwB,YAAY;AAEpC,wBAAwB,eAAe;AAEvC,MAAM,sCAAsC,SAAS;AAErD,oCAAoC,YAAY;AAGhD,IAAO,kCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PropTypes } from "react-desc";
|
|
3
|
+
const textProps = {
|
|
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")
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
textProps
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-truncated-expandable-text",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Truncated Expandable Text",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
"main": "./dist/cjs/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
9
12
|
"exports": {
|
|
10
13
|
".": {
|
|
11
|
-
"import": "./esm/index.js",
|
|
12
|
-
"require": "./cjs/index.js"
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
13
16
|
},
|
|
14
17
|
"./TruncatedExpandableText": {
|
|
15
|
-
"import": "./esm/TruncatedExpandableText.js",
|
|
16
|
-
"require": "./cjs/TruncatedExpandableText.js"
|
|
18
|
+
"import": "./dist/esm/TruncatedExpandableText.js",
|
|
19
|
+
"require": "./dist/cjs/TruncatedExpandableText.js"
|
|
17
20
|
},
|
|
18
21
|
"./props": {
|
|
19
|
-
"import": "./esm/props.js",
|
|
20
|
-
"require": "./cjs/props.js"
|
|
22
|
+
"import": "./dist/esm/props.js",
|
|
23
|
+
"require": "./dist/cjs/props.js"
|
|
21
24
|
},
|
|
22
25
|
"./defaultProps": {
|
|
23
|
-
"import": "./esm/defaultProps.js",
|
|
24
|
-
"require": "./cjs/defaultProps.js"
|
|
26
|
+
"import": "./dist/esm/defaultProps.js",
|
|
27
|
+
"require": "./dist/cjs/defaultProps.js"
|
|
25
28
|
}
|
|
26
29
|
},
|
|
27
30
|
"sideEffects": [
|
|
@@ -33,15 +36,15 @@
|
|
|
33
36
|
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
34
37
|
},
|
|
35
38
|
"engines": {
|
|
36
|
-
"
|
|
37
|
-
"node": ">=
|
|
39
|
+
"pnpm": ">=6",
|
|
40
|
+
"node": ">=16"
|
|
38
41
|
},
|
|
39
42
|
"author": "ICE MT",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"jestSonar": {
|
|
44
|
+
"sonar56x": true,
|
|
45
|
+
"reportPath": "reports",
|
|
46
|
+
"reportFile": "tests.xml",
|
|
47
|
+
"indent": 4
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"react-desc": "~4.1.3"
|
|
@@ -49,7 +52,7 @@
|
|
|
49
52
|
"devDependencies": {
|
|
50
53
|
"@testing-library/react": "~12.1.2",
|
|
51
54
|
"@testing-library/user-event": "~13.5.0",
|
|
52
|
-
"@types/styled-components": "~5.1.
|
|
55
|
+
"@types/styled-components": "~5.1.19",
|
|
53
56
|
"styled-components": "~5.3.3"
|
|
54
57
|
},
|
|
55
58
|
"peerDependencies": {
|
|
@@ -60,7 +63,13 @@
|
|
|
60
63
|
},
|
|
61
64
|
"publishConfig": {
|
|
62
65
|
"access": "public",
|
|
63
|
-
"
|
|
64
|
-
|
|
66
|
+
"typeSafety": false
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"dev": "cross-env NODE_ENV=development node ../../scripts/build/build.mjs --watch",
|
|
70
|
+
"test": "node ../../scripts/testing/test.mjs",
|
|
71
|
+
"lint": "node ../../scripts/lint.mjs",
|
|
72
|
+
"dts": "node ../../scripts/dts.mjs",
|
|
73
|
+
"build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs"
|
|
65
74
|
}
|
|
66
75
|
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
-
require('core-js/modules/web.dom-collections.iterator.js');
|
|
7
|
-
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
8
|
-
require('core-js/modules/esnext.iterator.constructor.js');
|
|
9
|
-
require('core-js/modules/esnext.iterator.for-each.js');
|
|
10
|
-
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
11
|
-
require('core-js/modules/esnext.iterator.filter.js');
|
|
12
|
-
var react = require('react');
|
|
13
|
-
var reactDesc = require('react-desc');
|
|
14
|
-
var styled = require('styled-components');
|
|
15
|
-
var props = require('./props.js');
|
|
16
|
-
var defaultProps = require('./defaultProps.js');
|
|
17
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
18
|
-
|
|
19
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
-
|
|
21
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
22
|
-
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
23
|
-
|
|
24
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
-
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
-
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
|
28
|
-
componentId: "sc-1wjt65j-0"
|
|
29
|
-
})(["text-overflow:ellipsis;white-space:", ";overflow:hidden;display:", ";-webkit-line-clamp:3;-webkit-box-orient:vertical;max-width:100%;word-break:break-all;"], props => props.isExpanded ? 'wrap' : 'nowrap', props => props.isExpanded ? '-webkit-box' : 'inline-block');
|
|
30
|
-
|
|
31
|
-
const TruncatedExpandableText = _ref => {
|
|
32
|
-
let {
|
|
33
|
-
containerProps,
|
|
34
|
-
value
|
|
35
|
-
} = _ref;
|
|
36
|
-
const [open, setOpen] = react.useState(false);
|
|
37
|
-
const ref = react.useRef(null);
|
|
38
|
-
react.useLayoutEffect(() => {
|
|
39
|
-
if (typeof value !== 'string') return;
|
|
40
|
-
if (!open) return;
|
|
41
|
-
let newHyphenizedValue = '';
|
|
42
|
-
const element = ref.current;
|
|
43
|
-
element.innerText = newHyphenizedValue;
|
|
44
|
-
let {
|
|
45
|
-
height: previousHeight
|
|
46
|
-
} = element.getBoundingClientRect();
|
|
47
|
-
value.split('').forEach((char, index) => {
|
|
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
|
-
|
|
56
|
-
if (!index || previousHeight === newHeight) {
|
|
57
|
-
newHyphenizedValue += char;
|
|
58
|
-
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
59
|
-
// end of word
|
|
60
|
-
element.innerText = "".concat(newHyphenizedValue).concat(char); // sometimes the last character is wider and doesn't fit
|
|
61
|
-
|
|
62
|
-
const {
|
|
63
|
-
height: endOfWordHeight
|
|
64
|
-
} = element.getBoundingClientRect();
|
|
65
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
66
|
-
} else if (char.match(/\s/)) {
|
|
67
|
-
// we dont want "- ", leave the space character only
|
|
68
|
-
newHyphenizedValue += char;
|
|
69
|
-
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
70
|
-
// we produce and empty space to make sure to start on the next line
|
|
71
|
-
newHyphenizedValue += " ".concat(char);
|
|
72
|
-
} else {
|
|
73
|
-
newHyphenizedValue += "-".concat(char);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
previousHeight = newHeight;
|
|
77
|
-
});
|
|
78
|
-
element.innerText = newHyphenizedValue;
|
|
79
|
-
}, [open, value]);
|
|
80
|
-
return /*#__PURE__*/jsxRuntime.jsx(Text, _objectSpread(_objectSpread({
|
|
81
|
-
ref: ref
|
|
82
|
-
}, containerProps), {}, {
|
|
83
|
-
isExpanded: open,
|
|
84
|
-
onClick: e => {
|
|
85
|
-
e.persist();
|
|
86
|
-
setOpen(!open);
|
|
87
|
-
if (containerProps.onClick) containerProps.onClick(e);
|
|
88
|
-
},
|
|
89
|
-
"data-testid": "ds-truncated-expandable-text",
|
|
90
|
-
children: value
|
|
91
|
-
}));
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
TruncatedExpandableText.defaultProps = defaultProps.defaultProps;
|
|
95
|
-
const DSTruncatedExpandableTextWithSchema = reactDesc.describe(TruncatedExpandableText);
|
|
96
|
-
DSTruncatedExpandableTextWithSchema.propTypes = props.textProps;
|
|
97
|
-
|
|
98
|
-
exports.DSTruncatedExpandableTextWithSchema = DSTruncatedExpandableTextWithSchema;
|
|
99
|
-
exports.TruncatedExpandableText = TruncatedExpandableText;
|
|
100
|
-
exports["default"] = TruncatedExpandableText;
|
package/cjs/defaultProps.js
DELETED
package/cjs/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var TruncatedExpandableText = require('./TruncatedExpandableText.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.DSTruncatedExpandableTextWithSchema = TruncatedExpandableText.DSTruncatedExpandableTextWithSchema;
|
|
10
|
-
exports.TruncatedExpandableText = TruncatedExpandableText.TruncatedExpandableText;
|
|
11
|
-
exports["default"] = TruncatedExpandableText.TruncatedExpandableText;
|
package/cjs/props.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var reactDesc = require('react-desc');
|
|
6
|
-
|
|
7
|
-
const textProps = {
|
|
8
|
-
/** props injected to wrapper of page header */
|
|
9
|
-
containerProps: reactDesc.PropTypes.object.description('props injected to wrapper of truncated expandable text'),
|
|
10
|
-
|
|
11
|
-
/** Text that when truncated will trigger the tooltip interaction */
|
|
12
|
-
value: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.string, reactDesc.PropTypes.number]).description('Text that when truncated will trigger the tooltip interaction')
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.textProps = textProps;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
4
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
7
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
8
|
-
import { useState, useRef, useLayoutEffect } from 'react';
|
|
9
|
-
import { describe } from 'react-desc';
|
|
10
|
-
import styled from 'styled-components';
|
|
11
|
-
import { textProps } from './props.js';
|
|
12
|
-
import { defaultProps } from './defaultProps.js';
|
|
13
|
-
import { jsx } from 'react/jsx-runtime';
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
-
const Text = /*#__PURE__*/styled.span.withConfig({
|
|
19
|
-
componentId: "sc-1wjt65j-0"
|
|
20
|
-
})(["text-overflow:ellipsis;white-space:", ";overflow:hidden;display:", ";-webkit-line-clamp:3;-webkit-box-orient:vertical;max-width:100%;word-break:break-all;"], props => props.isExpanded ? 'wrap' : 'nowrap', props => props.isExpanded ? '-webkit-box' : 'inline-block');
|
|
21
|
-
|
|
22
|
-
const TruncatedExpandableText = _ref => {
|
|
23
|
-
let {
|
|
24
|
-
containerProps,
|
|
25
|
-
value
|
|
26
|
-
} = _ref;
|
|
27
|
-
const [open, setOpen] = useState(false);
|
|
28
|
-
const ref = useRef(null);
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
if (typeof value !== 'string') return;
|
|
31
|
-
if (!open) return;
|
|
32
|
-
let newHyphenizedValue = '';
|
|
33
|
-
const element = ref.current;
|
|
34
|
-
element.innerText = newHyphenizedValue;
|
|
35
|
-
let {
|
|
36
|
-
height: previousHeight
|
|
37
|
-
} = element.getBoundingClientRect();
|
|
38
|
-
value.split('').forEach((char, index) => {
|
|
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
|
-
|
|
47
|
-
if (!index || previousHeight === newHeight) {
|
|
48
|
-
newHyphenizedValue += char;
|
|
49
|
-
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
50
|
-
// end of word
|
|
51
|
-
element.innerText = "".concat(newHyphenizedValue).concat(char); // sometimes the last character is wider and doesn't fit
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
height: endOfWordHeight
|
|
55
|
-
} = element.getBoundingClientRect();
|
|
56
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
57
|
-
} else if (char.match(/\s/)) {
|
|
58
|
-
// we dont want "- ", leave the space character only
|
|
59
|
-
newHyphenizedValue += char;
|
|
60
|
-
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
61
|
-
// we produce and empty space to make sure to start on the next line
|
|
62
|
-
newHyphenizedValue += " ".concat(char);
|
|
63
|
-
} else {
|
|
64
|
-
newHyphenizedValue += "-".concat(char);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
previousHeight = newHeight;
|
|
68
|
-
});
|
|
69
|
-
element.innerText = newHyphenizedValue;
|
|
70
|
-
}, [open, value]);
|
|
71
|
-
return /*#__PURE__*/jsx(Text, _objectSpread(_objectSpread({
|
|
72
|
-
ref: ref
|
|
73
|
-
}, containerProps), {}, {
|
|
74
|
-
isExpanded: open,
|
|
75
|
-
onClick: e => {
|
|
76
|
-
e.persist();
|
|
77
|
-
setOpen(!open);
|
|
78
|
-
if (containerProps.onClick) containerProps.onClick(e);
|
|
79
|
-
},
|
|
80
|
-
"data-testid": "ds-truncated-expandable-text",
|
|
81
|
-
children: value
|
|
82
|
-
}));
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
TruncatedExpandableText.defaultProps = defaultProps;
|
|
86
|
-
const DSTruncatedExpandableTextWithSchema = describe(TruncatedExpandableText);
|
|
87
|
-
DSTruncatedExpandableTextWithSchema.propTypes = textProps;
|
|
88
|
-
|
|
89
|
-
export { DSTruncatedExpandableTextWithSchema, TruncatedExpandableText, TruncatedExpandableText as default };
|
package/esm/defaultProps.js
DELETED
package/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DSTruncatedExpandableTextWithSchema, TruncatedExpandableText, TruncatedExpandableText as default } from './TruncatedExpandableText.js';
|
package/esm/props.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PropTypes } from 'react-desc';
|
|
2
|
-
|
|
3
|
-
const textProps = {
|
|
4
|
-
/** props injected to wrapper of page header */
|
|
5
|
-
containerProps: PropTypes.object.description('props injected to wrapper of truncated expandable text'),
|
|
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')
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { textProps };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
-
import { HTMLAttributes } from 'react';
|
|
3
|
-
declare const TruncatedExpandableText: {
|
|
4
|
-
({ containerProps, value, }: {
|
|
5
|
-
containerProps: HTMLAttributes<HTMLSpanElement>;
|
|
6
|
-
value: string;
|
|
7
|
-
}): JSX.Element;
|
|
8
|
-
propTypes: {
|
|
9
|
-
containerProps: {
|
|
10
|
-
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
11
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
12
|
-
};
|
|
13
|
-
isRequired: import("react-desc").PropTypesDescValue;
|
|
14
|
-
};
|
|
15
|
-
value: {
|
|
16
|
-
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
17
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
18
|
-
};
|
|
19
|
-
isRequired: import("react-desc").PropTypesDescValue;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
defaultProps: {
|
|
23
|
-
containerProps: {};
|
|
24
|
-
value: string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
declare const DSTruncatedExpandableTextWithSchema: {
|
|
28
|
-
(props?: {
|
|
29
|
-
containerProps: HTMLAttributes<HTMLSpanElement>;
|
|
30
|
-
value: string;
|
|
31
|
-
} | undefined): JSX.Element;
|
|
32
|
-
propTypes: unknown;
|
|
33
|
-
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
34
|
-
};
|
|
35
|
-
export { TruncatedExpandableText, DSTruncatedExpandableTextWithSchema };
|
|
36
|
-
export default TruncatedExpandableText;
|
package/types/defaultProps.d.ts
DELETED
package/types/index.d.ts
DELETED
package/types/props.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
-
export declare const textProps: {
|
|
3
|
-
/** props injected to wrapper of page header */
|
|
4
|
-
containerProps: {
|
|
5
|
-
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
6
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
7
|
-
};
|
|
8
|
-
isRequired: import("react-desc").PropTypesDescValue;
|
|
9
|
-
};
|
|
10
|
-
/** Text that when truncated will trigger the tooltip interaction */
|
|
11
|
-
value: {
|
|
12
|
-
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
13
|
-
deprecated: import("react-desc").PropTypesDescValidator;
|
|
14
|
-
};
|
|
15
|
-
isRequired: import("react-desc").PropTypesDescValue;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|