@elliemae/ds-read-more 2.3.1 → 3.0.0-alpha.3
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/DSReadMore.js +149 -0
- package/dist/cjs/DSReadMore.js.map +7 -0
- package/dist/cjs/MoreLessButton.js +65 -0
- package/dist/cjs/MoreLessButton.js.map +7 -0
- package/dist/cjs/index.d.js +27 -0
- package/dist/cjs/index.d.js.map +7 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/DSReadMore.js +120 -0
- package/dist/esm/DSReadMore.js.map +7 -0
- package/dist/esm/MoreLessButton.js +36 -0
- package/dist/esm/MoreLessButton.js.map +7 -0
- package/dist/esm/index.d.js +2 -0
- package/dist/esm/index.d.js.map +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/package.json +31 -26
- package/cjs/DSReadMore.js +0 -161
- package/cjs/MoreLessButton.js +0 -57
- package/cjs/index.d.js +0 -2
- package/cjs/index.js +0 -11
- package/esm/DSReadMore.js +0 -150
- package/esm/MoreLessButton.js +0 -48
- package/esm/index.d.js +0 -1
- package/esm/index.js +0 -1
- package/types/DSReadMore.d.ts +0 -14
- package/types/MoreLessButton.d.ts +0 -4
- package/types/index.d.d.ts +0 -19
- package/types/index.d.ts +0 -2
- package/types/tests/DSReadMore.test.d.ts +0 -1
|
@@ -0,0 +1,149 @@
|
|
|
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 DSReadMore_exports = {};
|
|
29
|
+
__export(DSReadMore_exports, {
|
|
30
|
+
DSReadMore: () => DSReadMore,
|
|
31
|
+
DSReadMoreWithSchema: () => DSReadMoreWithSchema,
|
|
32
|
+
default: () => DSReadMore_default
|
|
33
|
+
});
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_lodash = require("lodash");
|
|
37
|
+
var import_react_desc = require("react-desc");
|
|
38
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
39
|
+
var import_ds_tooltip = require("@elliemae/ds-tooltip");
|
|
40
|
+
var import_ds_button = require("@elliemae/ds-button");
|
|
41
|
+
var import_prop_types = require("@elliemae/ds-shared/prop-types");
|
|
42
|
+
var import_MoreLessButton = require("./MoreLessButton");
|
|
43
|
+
const Text = import_styled_components.default.span`
|
|
44
|
+
display: -webkit-box;
|
|
45
|
+
-webkit-line-clamp: ${({ lines, expanded }) => expanded ? "unset" : lines};
|
|
46
|
+
-webkit-box-orient: vertical;
|
|
47
|
+
-webkit-hyphens: auto;
|
|
48
|
+
-moz-hyphens: auto;
|
|
49
|
+
-ms-hyphens: auto;
|
|
50
|
+
hyphens: auto;
|
|
51
|
+
word-break: break-all;
|
|
52
|
+
`;
|
|
53
|
+
const DSReadMore = (props) => {
|
|
54
|
+
const {
|
|
55
|
+
lines = 2,
|
|
56
|
+
more = "more",
|
|
57
|
+
less = "less",
|
|
58
|
+
onMore = import_lodash.noop,
|
|
59
|
+
onLess = import_lodash.noop,
|
|
60
|
+
content,
|
|
61
|
+
ellipsis = "...",
|
|
62
|
+
withTooltip = false
|
|
63
|
+
} = props;
|
|
64
|
+
const ref = (0, import_react.useRef)(null);
|
|
65
|
+
const [showButton, setShowButton] = (0, import_react.useState)(false);
|
|
66
|
+
const [expanded, setExpanded] = (0, import_react.useState)(false);
|
|
67
|
+
const overflows = ({ offsetHeight, scrollHeight }) => offsetHeight + 2 < scrollHeight;
|
|
68
|
+
const binSearchTextOverflow = (0, import_react.useCallback)((element, parent) => {
|
|
69
|
+
const text = element.innerText;
|
|
70
|
+
let left = 1;
|
|
71
|
+
let right = text.length;
|
|
72
|
+
let textEnd = 0;
|
|
73
|
+
while (left <= right) {
|
|
74
|
+
const middle = (left + right) / 2;
|
|
75
|
+
element.innerText = content.slice(0, middle);
|
|
76
|
+
if (overflows(parent))
|
|
77
|
+
right = middle - 1;
|
|
78
|
+
else {
|
|
79
|
+
left = middle + 1;
|
|
80
|
+
textEnd = middle;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
element.innerText = content.slice(0, textEnd);
|
|
84
|
+
}, [content]);
|
|
85
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
86
|
+
const textElement = ref.current;
|
|
87
|
+
const parentElement = ref.current?.parentElement;
|
|
88
|
+
if (parentElement && textElement) {
|
|
89
|
+
textElement.innerText = content;
|
|
90
|
+
setShowButton(expanded || overflows(parentElement));
|
|
91
|
+
if (!expanded && overflows(parentElement)) {
|
|
92
|
+
binSearchTextOverflow(textElement, parentElement);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
|
|
96
|
+
const toggleExpanded = (newExpanded) => {
|
|
97
|
+
setExpanded(newExpanded);
|
|
98
|
+
if (newExpanded)
|
|
99
|
+
onMore();
|
|
100
|
+
else
|
|
101
|
+
onLess();
|
|
102
|
+
};
|
|
103
|
+
return /* @__PURE__ */ import_react.default.createElement(Text, {
|
|
104
|
+
lines,
|
|
105
|
+
expanded
|
|
106
|
+
}, /* @__PURE__ */ import_react.default.createElement("span", {
|
|
107
|
+
ref,
|
|
108
|
+
"data-testid": "ds-read_more-text",
|
|
109
|
+
"aria-label": content
|
|
110
|
+
}, content), showButton && !withTooltip && /* @__PURE__ */ import_react.default.createElement(import_MoreLessButton.MoreLessButton, {
|
|
111
|
+
expanded,
|
|
112
|
+
label: expanded ? less : more,
|
|
113
|
+
onClick: () => toggleExpanded(!expanded),
|
|
114
|
+
ariaLabel: expanded ? less : more,
|
|
115
|
+
ellipsis,
|
|
116
|
+
dataTestId: "ds-read_more-button"
|
|
117
|
+
}), withTooltip && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
118
|
+
style: {
|
|
119
|
+
display: "inline-block"
|
|
120
|
+
}
|
|
121
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_ds_tooltip.DSTooltipV3, {
|
|
122
|
+
text: content
|
|
123
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_MoreLessButton.MoreLessButton, {
|
|
124
|
+
expanded,
|
|
125
|
+
label: "...",
|
|
126
|
+
ariaLabel: content,
|
|
127
|
+
ellipsis,
|
|
128
|
+
withTooltip,
|
|
129
|
+
dataTestId: "ds-read_more-tooltip-button"
|
|
130
|
+
}))));
|
|
131
|
+
};
|
|
132
|
+
const DSReadMoreProps = {
|
|
133
|
+
lines: import_react_desc.PropTypes.number.description("Ammount of lines after you want to display an ellipsis + more/less button").defaultValue(2),
|
|
134
|
+
more: import_react_desc.PropTypes.string.description("Label which will appear on the 'More' button").defaultValue("more"),
|
|
135
|
+
less: import_react_desc.PropTypes.string.description("Label which will appear on the 'Less' button").defaultValue("less"),
|
|
136
|
+
onMore: import_react_desc.PropTypes.func.description("Function which will execute when the user click the 'More' button"),
|
|
137
|
+
onLess: import_react_desc.PropTypes.func.description("Function which will execute when the user click the 'Less' button"),
|
|
138
|
+
content: import_react_desc.PropTypes.string.description("The text content you want displayed").isRequired,
|
|
139
|
+
buttonType: import_react_desc.PropTypes.oneOf(import_ds_button.buttonTypes).description("The type for the more/less button").defaultValue("link"),
|
|
140
|
+
size: import_react_desc.PropTypes.oneOf(import_prop_types.dsBasicSizes).description("Size of the button").defaultValue("s"),
|
|
141
|
+
ellipsis: import_react_desc.PropTypes.string.description("The text you want to appear when truncating").defaultValue("..."),
|
|
142
|
+
withTooltip: import_react_desc.PropTypes.bool.description("Whether to show expandable tooltip on ellipsis focus instead of expandable buttons").defaultValue("false")
|
|
143
|
+
};
|
|
144
|
+
DSReadMore.propTypes = DSReadMoreProps;
|
|
145
|
+
const DSReadMoreWithSchema = (0, import_react_desc.describe)(DSReadMore);
|
|
146
|
+
DSReadMoreWithSchema.propTypes = DSReadMoreProps;
|
|
147
|
+
var DSReadMore_default = DSReadMore;
|
|
148
|
+
module.exports = __toCommonJS(DSReadMore_exports);
|
|
149
|
+
//# sourceMappingURL=DSReadMore.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/DSReadMore.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\nimport React, { useLayoutEffect, useRef, useState, useCallback } from 'react';\nimport { noop } from 'lodash';\nimport type { WeakValidationMap } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport styled from 'styled-components';\nimport { DSTooltipV3 } from '@elliemae/ds-tooltip';\n\nimport { buttonTypes } from '@elliemae/ds-button';\nimport { dsBasicSizes } from '@elliemae/ds-shared/prop-types';\nimport { MoreLessButton } from './MoreLessButton';\nimport { DSReadMoreT } from './index.d';\n\nconst Text = styled.span<{ lines: number; expanded: boolean }>`\n display: -webkit-box;\n -webkit-line-clamp: ${({ lines, expanded }) => (expanded ? 'unset' : lines)};\n -webkit-box-orient: vertical;\n -webkit-hyphens: auto;\n -moz-hyphens: auto;\n -ms-hyphens: auto;\n hyphens: auto;\n word-break: break-all;\n`;\n\nconst DSReadMore = (props: DSReadMoreT) => {\n const {\n lines = 2,\n more = 'more',\n less = 'less',\n onMore = noop,\n onLess = noop,\n content,\n ellipsis = '...',\n withTooltip = false,\n } = props;\n const ref = useRef<HTMLElement>(null);\n const [showButton, setShowButton] = useState(false);\n const [expanded, setExpanded] = useState(false);\n\n // offsetHeight + 2 takes into consideration any size of the button\n const overflows = ({ offsetHeight, scrollHeight }: { offsetHeight: number; scrollHeight: number }) =>\n offsetHeight + 2 < scrollHeight;\n\n // Searchs the optimum cut on the text to have the button in the same line\n const binSearchTextOverflow = useCallback(\n (element: HTMLElement, parent: HTMLElement) => {\n const text = element.innerText;\n let left = 1;\n let right = text.length;\n let textEnd = 0;\n while (left <= right) {\n const middle = (left + right) / 2;\n element.innerText = content.slice(0, middle);\n if (overflows(parent)) right = middle - 1;\n else {\n left = middle + 1;\n textEnd = middle;\n }\n }\n element.innerText = content.slice(0, textEnd);\n },\n [content],\n );\n\n useLayoutEffect(() => {\n const textElement = ref.current;\n const parentElement = ref.current?.parentElement;\n if (parentElement && textElement) {\n textElement.innerText = content;\n setShowButton(expanded || overflows(parentElement));\n if (!expanded && overflows(parentElement)) {\n binSearchTextOverflow(textElement, parentElement);\n }\n }\n }, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);\n\n const toggleExpanded = (newExpanded: boolean) => {\n setExpanded(newExpanded);\n if (newExpanded) onMore();\n else onLess();\n };\n\n return (\n <Text lines={lines} expanded={expanded}>\n <span ref={ref} data-testid=\"ds-read_more-text\" aria-label={content}>\n {content}\n </span>\n {showButton && !withTooltip && (\n <MoreLessButton\n expanded={expanded}\n label={expanded ? less : more}\n onClick={() => toggleExpanded(!expanded)}\n ariaLabel={expanded ? less : more}\n ellipsis={ellipsis}\n dataTestId=\"ds-read_more-button\"\n />\n )}\n {withTooltip && (\n <div\n style={{\n display: 'inline-block',\n }}\n >\n <DSTooltipV3 text={content}>\n <MoreLessButton\n expanded={expanded}\n label=\"...\"\n ariaLabel={content}\n ellipsis={ellipsis}\n withTooltip={withTooltip}\n dataTestId=\"ds-read_more-tooltip-button\"\n />\n </DSTooltipV3>\n </div>\n )}\n </Text>\n );\n};\n\nconst DSReadMoreProps = {\n /** Ammount of lines after you want to display an ellipsis + more/less button */\n lines: PropTypes.number\n .description('Ammount of lines after you want to display an ellipsis + more/less button')\n .defaultValue(2),\n /** Label which will appear on the 'More' button */\n more: PropTypes.string.description(\"Label which will appear on the 'More' button\").defaultValue('more'),\n /** Label which will appear on the 'Less' button */\n less: PropTypes.string.description(\"Label which will appear on the 'Less' button\").defaultValue('less'),\n /** Function which will execute when the user click the 'More' button */\n onMore: PropTypes.func.description(\"Function which will execute when the user click the 'More' button\"),\n /** Function which will execute when the user click the 'Less' button */\n onLess: PropTypes.func.description(\"Function which will execute when the user click the 'Less' button\"),\n /** The text content you want displayed */\n content: PropTypes.string.description('The text content you want displayed').isRequired,\n\n /** 'The type of button for more/less button' */\n buttonType: PropTypes.oneOf(buttonTypes).description('The type for the more/less button').defaultValue('link'),\n /**\n * ['s', 'm', 'l']\n */\n size: PropTypes.oneOf(dsBasicSizes as string[])\n .description('Size of the button')\n .defaultValue('s'),\n\n /** The text you want to appear when truncating */\n ellipsis: PropTypes.string.description('The text you want to appear when truncating').defaultValue('...'),\n withTooltip: PropTypes.bool\n .description('Whether to show expandable tooltip on ellipsis focus instead of expandable buttons')\n .defaultValue('false'),\n};\n\nDSReadMore.propTypes = DSReadMoreProps as WeakValidationMap<unknown>;\n\nconst DSReadMoreWithSchema = describe<DSReadMoreT>(DSReadMore);\n\nDSReadMoreWithSchema.propTypes = DSReadMoreProps;\n\nexport { DSReadMore, DSReadMoreWithSchema };\nexport default DSReadMore;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 MoreLessButton_exports = {};
|
|
29
|
+
__export(MoreLessButton_exports, {
|
|
30
|
+
MoreLessButton: () => MoreLessButton
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_react = __toESM(require("react"));
|
|
34
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
35
|
+
var import_ds_button = require("@elliemae/ds-button");
|
|
36
|
+
const StyledButton = (0, import_styled_components.default)(import_ds_button.DSButtonV2)`
|
|
37
|
+
padding: 0;
|
|
38
|
+
color: ${({ withTooltip, theme }) => withTooltip ? "inherit" : `${theme.colors.brand["600"]}`};
|
|
39
|
+
border: 0;
|
|
40
|
+
margin: 0;
|
|
41
|
+
font-size: 12px;
|
|
42
|
+
font-weight: 200;
|
|
43
|
+
min-width: 0px;
|
|
44
|
+
height: auto;
|
|
45
|
+
text-transform: unset;
|
|
46
|
+
&:hover:not([disabled]) {
|
|
47
|
+
color: ${({ withTooltip, theme }) => withTooltip ? "inherit" : `${theme.colors.brand["600"]}`};
|
|
48
|
+
background-color: transparent;
|
|
49
|
+
text-decoration: ${({ withTooltip }) => withTooltip ? "" : "underline"};
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const MoreLessButton = (props) => {
|
|
53
|
+
const { expanded, ariaLabel, label, onClick, ellipsis, withTooltip, dataTestId } = props;
|
|
54
|
+
return /* @__PURE__ */ import_react.default.createElement("span", null, expanded || withTooltip ? " " : ellipsis, /* @__PURE__ */ import_react.default.createElement(StyledButton, {
|
|
55
|
+
withTooltip,
|
|
56
|
+
"aria-label": ariaLabel,
|
|
57
|
+
buttonType: "text",
|
|
58
|
+
onClick,
|
|
59
|
+
"aria-hidden": true,
|
|
60
|
+
size: "s",
|
|
61
|
+
"data-testid": dataTestId
|
|
62
|
+
}, label));
|
|
63
|
+
};
|
|
64
|
+
module.exports = __toCommonJS(MoreLessButton_exports);
|
|
65
|
+
//# sourceMappingURL=MoreLessButton.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/MoreLessButton.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import React from 'react';\nimport styled from 'styled-components';\nimport { DSButtonV2 } from '@elliemae/ds-button';\n\nimport type { MoreLessButtonT } from './index.d';\n\nconst StyledButton = styled(DSButtonV2)<{ withTooltip: boolean }>`\n padding: 0;\n color: ${({ withTooltip, theme }) => (withTooltip ? 'inherit' : `${theme.colors.brand['600']}`)};\n border: 0;\n margin: 0;\n font-size: 12px;\n font-weight: 200;\n min-width: 0px;\n height: auto;\n text-transform: unset;\n &:hover:not([disabled]) {\n color: ${({ withTooltip, theme }) => (withTooltip ? 'inherit' : `${theme.colors.brand['600']}`)};\n background-color: transparent;\n text-decoration: ${({ withTooltip }) => (withTooltip ? '' : 'underline')};\n }\n`;\nconst MoreLessButton = (props: MoreLessButtonT) => {\n const { expanded, ariaLabel, label, onClick, ellipsis, withTooltip, dataTestId } = props;\n\n return (\n <span>\n {expanded || withTooltip ? ' ' : ellipsis}\n\n <StyledButton\n withTooltip={withTooltip}\n aria-label={ariaLabel}\n buttonType=\"text\"\n onClick={onClick}\n aria-hidden\n size=\"s\"\n data-testid={dataTestId}\n >\n {label}\n </StyledButton>\n </span>\n );\n};\n\nexport { MoreLessButton };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAClB,+BAAmB;AACnB,uBAA2B;AAI3B,MAAM,eAAe,sCAAO;AAAA;AAAA,WAEjB,CAAC,EAAE,aAAa,YAAa,cAAc,YAAY,GAAG,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAS3E,CAAC,EAAE,aAAa,YAAa,cAAc,YAAY,GAAG,MAAM,OAAO,MAAM;AAAA;AAAA,uBAEnE,CAAC,EAAE,kBAAmB,cAAc,KAAK;AAAA;AAAA;AAGhE,MAAM,iBAAiB,CAAC,UAA2B;AACjD,QAAM,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,aAAa,eAAe;AAEnF,SACE,mDAAC,QAAD,MACG,YAAY,cAAc,MAAM,UAEjC,mDAAC,cAAD;AAAA,IACE;AAAA,IACA,cAAY;AAAA,IACZ,YAAW;AAAA,IACX;AAAA,IACA,eAAW;AAAA,IACX,MAAK;AAAA,IACL,eAAa;AAAA,KAEZ;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 __reExport = (target, module2, copyDefault, desc) => {
|
|
9
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(module2))
|
|
11
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
12
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (module2, isNodeMode) => {
|
|
17
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
+
return (module2, temp) => {
|
|
21
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
+
};
|
|
23
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
+
var index_d_exports = {};
|
|
25
|
+
var React = __toESM(require("react"));
|
|
26
|
+
module.exports = __toCommonJS(index_d_exports);
|
|
27
|
+
//# sourceMappingURL=index.d.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.d.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["export interface DSReadMoreT {\n lines: number;\n more: string;\n less: string;\n onMore: () => void;\n onLess: () => void;\n content: string;\n ellipsis: string;\n withTooltip?: boolean;\n}\n\nexport interface MoreLessButtonT {\n expanded: boolean;\n label: string;\n onClick?: () => void;\n ellipsis: string;\n withTooltip?: boolean;\n ariaLabel: string;\n dataTestId: string;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;",
|
|
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_DSReadMore.default
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
__reExport(src_exports, require("./DSReadMore"));
|
|
34
|
+
var import_DSReadMore = __toESM(require("./DSReadMore"));
|
|
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 './DSReadMore';\nexport { default } from './DSReadMore';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,wBAAc;AACd,wBAAwB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useLayoutEffect, useRef, useState, useCallback } from "react";
|
|
3
|
+
import { noop } from "lodash";
|
|
4
|
+
import { describe, PropTypes } from "react-desc";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { DSTooltipV3 } from "@elliemae/ds-tooltip";
|
|
7
|
+
import { buttonTypes } from "@elliemae/ds-button";
|
|
8
|
+
import { dsBasicSizes } from "@elliemae/ds-shared/prop-types";
|
|
9
|
+
import { MoreLessButton } from "./MoreLessButton";
|
|
10
|
+
const Text = styled.span`
|
|
11
|
+
display: -webkit-box;
|
|
12
|
+
-webkit-line-clamp: ${({ lines, expanded }) => expanded ? "unset" : lines};
|
|
13
|
+
-webkit-box-orient: vertical;
|
|
14
|
+
-webkit-hyphens: auto;
|
|
15
|
+
-moz-hyphens: auto;
|
|
16
|
+
-ms-hyphens: auto;
|
|
17
|
+
hyphens: auto;
|
|
18
|
+
word-break: break-all;
|
|
19
|
+
`;
|
|
20
|
+
const DSReadMore = (props) => {
|
|
21
|
+
const {
|
|
22
|
+
lines = 2,
|
|
23
|
+
more = "more",
|
|
24
|
+
less = "less",
|
|
25
|
+
onMore = noop,
|
|
26
|
+
onLess = noop,
|
|
27
|
+
content,
|
|
28
|
+
ellipsis = "...",
|
|
29
|
+
withTooltip = false
|
|
30
|
+
} = props;
|
|
31
|
+
const ref = useRef(null);
|
|
32
|
+
const [showButton, setShowButton] = useState(false);
|
|
33
|
+
const [expanded, setExpanded] = useState(false);
|
|
34
|
+
const overflows = ({ offsetHeight, scrollHeight }) => offsetHeight + 2 < scrollHeight;
|
|
35
|
+
const binSearchTextOverflow = useCallback((element, parent) => {
|
|
36
|
+
const text = element.innerText;
|
|
37
|
+
let left = 1;
|
|
38
|
+
let right = text.length;
|
|
39
|
+
let textEnd = 0;
|
|
40
|
+
while (left <= right) {
|
|
41
|
+
const middle = (left + right) / 2;
|
|
42
|
+
element.innerText = content.slice(0, middle);
|
|
43
|
+
if (overflows(parent))
|
|
44
|
+
right = middle - 1;
|
|
45
|
+
else {
|
|
46
|
+
left = middle + 1;
|
|
47
|
+
textEnd = middle;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
element.innerText = content.slice(0, textEnd);
|
|
51
|
+
}, [content]);
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
const textElement = ref.current;
|
|
54
|
+
const parentElement = ref.current?.parentElement;
|
|
55
|
+
if (parentElement && textElement) {
|
|
56
|
+
textElement.innerText = content;
|
|
57
|
+
setShowButton(expanded || overflows(parentElement));
|
|
58
|
+
if (!expanded && overflows(parentElement)) {
|
|
59
|
+
binSearchTextOverflow(textElement, parentElement);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
|
|
63
|
+
const toggleExpanded = (newExpanded) => {
|
|
64
|
+
setExpanded(newExpanded);
|
|
65
|
+
if (newExpanded)
|
|
66
|
+
onMore();
|
|
67
|
+
else
|
|
68
|
+
onLess();
|
|
69
|
+
};
|
|
70
|
+
return /* @__PURE__ */ React2.createElement(Text, {
|
|
71
|
+
lines,
|
|
72
|
+
expanded
|
|
73
|
+
}, /* @__PURE__ */ React2.createElement("span", {
|
|
74
|
+
ref,
|
|
75
|
+
"data-testid": "ds-read_more-text",
|
|
76
|
+
"aria-label": content
|
|
77
|
+
}, content), showButton && !withTooltip && /* @__PURE__ */ React2.createElement(MoreLessButton, {
|
|
78
|
+
expanded,
|
|
79
|
+
label: expanded ? less : more,
|
|
80
|
+
onClick: () => toggleExpanded(!expanded),
|
|
81
|
+
ariaLabel: expanded ? less : more,
|
|
82
|
+
ellipsis,
|
|
83
|
+
dataTestId: "ds-read_more-button"
|
|
84
|
+
}), withTooltip && /* @__PURE__ */ React2.createElement("div", {
|
|
85
|
+
style: {
|
|
86
|
+
display: "inline-block"
|
|
87
|
+
}
|
|
88
|
+
}, /* @__PURE__ */ React2.createElement(DSTooltipV3, {
|
|
89
|
+
text: content
|
|
90
|
+
}, /* @__PURE__ */ React2.createElement(MoreLessButton, {
|
|
91
|
+
expanded,
|
|
92
|
+
label: "...",
|
|
93
|
+
ariaLabel: content,
|
|
94
|
+
ellipsis,
|
|
95
|
+
withTooltip,
|
|
96
|
+
dataTestId: "ds-read_more-tooltip-button"
|
|
97
|
+
}))));
|
|
98
|
+
};
|
|
99
|
+
const DSReadMoreProps = {
|
|
100
|
+
lines: PropTypes.number.description("Ammount of lines after you want to display an ellipsis + more/less button").defaultValue(2),
|
|
101
|
+
more: PropTypes.string.description("Label which will appear on the 'More' button").defaultValue("more"),
|
|
102
|
+
less: PropTypes.string.description("Label which will appear on the 'Less' button").defaultValue("less"),
|
|
103
|
+
onMore: PropTypes.func.description("Function which will execute when the user click the 'More' button"),
|
|
104
|
+
onLess: PropTypes.func.description("Function which will execute when the user click the 'Less' button"),
|
|
105
|
+
content: PropTypes.string.description("The text content you want displayed").isRequired,
|
|
106
|
+
buttonType: PropTypes.oneOf(buttonTypes).description("The type for the more/less button").defaultValue("link"),
|
|
107
|
+
size: PropTypes.oneOf(dsBasicSizes).description("Size of the button").defaultValue("s"),
|
|
108
|
+
ellipsis: PropTypes.string.description("The text you want to appear when truncating").defaultValue("..."),
|
|
109
|
+
withTooltip: PropTypes.bool.description("Whether to show expandable tooltip on ellipsis focus instead of expandable buttons").defaultValue("false")
|
|
110
|
+
};
|
|
111
|
+
DSReadMore.propTypes = DSReadMoreProps;
|
|
112
|
+
const DSReadMoreWithSchema = describe(DSReadMore);
|
|
113
|
+
DSReadMoreWithSchema.propTypes = DSReadMoreProps;
|
|
114
|
+
var DSReadMore_default = DSReadMore;
|
|
115
|
+
export {
|
|
116
|
+
DSReadMore,
|
|
117
|
+
DSReadMoreWithSchema,
|
|
118
|
+
DSReadMore_default as default
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=DSReadMore.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/DSReadMore.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\nimport React, { useLayoutEffect, useRef, useState, useCallback } from 'react';\nimport { noop } from 'lodash';\nimport type { WeakValidationMap } from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport styled from 'styled-components';\nimport { DSTooltipV3 } from '@elliemae/ds-tooltip';\n\nimport { buttonTypes } from '@elliemae/ds-button';\nimport { dsBasicSizes } from '@elliemae/ds-shared/prop-types';\nimport { MoreLessButton } from './MoreLessButton';\nimport { DSReadMoreT } from './index.d';\n\nconst Text = styled.span<{ lines: number; expanded: boolean }>`\n display: -webkit-box;\n -webkit-line-clamp: ${({ lines, expanded }) => (expanded ? 'unset' : lines)};\n -webkit-box-orient: vertical;\n -webkit-hyphens: auto;\n -moz-hyphens: auto;\n -ms-hyphens: auto;\n hyphens: auto;\n word-break: break-all;\n`;\n\nconst DSReadMore = (props: DSReadMoreT) => {\n const {\n lines = 2,\n more = 'more',\n less = 'less',\n onMore = noop,\n onLess = noop,\n content,\n ellipsis = '...',\n withTooltip = false,\n } = props;\n const ref = useRef<HTMLElement>(null);\n const [showButton, setShowButton] = useState(false);\n const [expanded, setExpanded] = useState(false);\n\n // offsetHeight + 2 takes into consideration any size of the button\n const overflows = ({ offsetHeight, scrollHeight }: { offsetHeight: number; scrollHeight: number }) =>\n offsetHeight + 2 < scrollHeight;\n\n // Searchs the optimum cut on the text to have the button in the same line\n const binSearchTextOverflow = useCallback(\n (element: HTMLElement, parent: HTMLElement) => {\n const text = element.innerText;\n let left = 1;\n let right = text.length;\n let textEnd = 0;\n while (left <= right) {\n const middle = (left + right) / 2;\n element.innerText = content.slice(0, middle);\n if (overflows(parent)) right = middle - 1;\n else {\n left = middle + 1;\n textEnd = middle;\n }\n }\n element.innerText = content.slice(0, textEnd);\n },\n [content],\n );\n\n useLayoutEffect(() => {\n const textElement = ref.current;\n const parentElement = ref.current?.parentElement;\n if (parentElement && textElement) {\n textElement.innerText = content;\n setShowButton(expanded || overflows(parentElement));\n if (!expanded && overflows(parentElement)) {\n binSearchTextOverflow(textElement, parentElement);\n }\n }\n }, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);\n\n const toggleExpanded = (newExpanded: boolean) => {\n setExpanded(newExpanded);\n if (newExpanded) onMore();\n else onLess();\n };\n\n return (\n <Text lines={lines} expanded={expanded}>\n <span ref={ref} data-testid=\"ds-read_more-text\" aria-label={content}>\n {content}\n </span>\n {showButton && !withTooltip && (\n <MoreLessButton\n expanded={expanded}\n label={expanded ? less : more}\n onClick={() => toggleExpanded(!expanded)}\n ariaLabel={expanded ? less : more}\n ellipsis={ellipsis}\n dataTestId=\"ds-read_more-button\"\n />\n )}\n {withTooltip && (\n <div\n style={{\n display: 'inline-block',\n }}\n >\n <DSTooltipV3 text={content}>\n <MoreLessButton\n expanded={expanded}\n label=\"...\"\n ariaLabel={content}\n ellipsis={ellipsis}\n withTooltip={withTooltip}\n dataTestId=\"ds-read_more-tooltip-button\"\n />\n </DSTooltipV3>\n </div>\n )}\n </Text>\n );\n};\n\nconst DSReadMoreProps = {\n /** Ammount of lines after you want to display an ellipsis + more/less button */\n lines: PropTypes.number\n .description('Ammount of lines after you want to display an ellipsis + more/less button')\n .defaultValue(2),\n /** Label which will appear on the 'More' button */\n more: PropTypes.string.description(\"Label which will appear on the 'More' button\").defaultValue('more'),\n /** Label which will appear on the 'Less' button */\n less: PropTypes.string.description(\"Label which will appear on the 'Less' button\").defaultValue('less'),\n /** Function which will execute when the user click the 'More' button */\n onMore: PropTypes.func.description(\"Function which will execute when the user click the 'More' button\"),\n /** Function which will execute when the user click the 'Less' button */\n onLess: PropTypes.func.description(\"Function which will execute when the user click the 'Less' button\"),\n /** The text content you want displayed */\n content: PropTypes.string.description('The text content you want displayed').isRequired,\n\n /** 'The type of button for more/less button' */\n buttonType: PropTypes.oneOf(buttonTypes).description('The type for the more/less button').defaultValue('link'),\n /**\n * ['s', 'm', 'l']\n */\n size: PropTypes.oneOf(dsBasicSizes as string[])\n .description('Size of the button')\n .defaultValue('s'),\n\n /** The text you want to appear when truncating */\n ellipsis: PropTypes.string.description('The text you want to appear when truncating').defaultValue('...'),\n withTooltip: PropTypes.bool\n .description('Whether to show expandable tooltip on ellipsis focus instead of expandable buttons')\n .defaultValue('false'),\n};\n\nDSReadMore.propTypes = DSReadMoreProps as WeakValidationMap<unknown>;\n\nconst DSReadMoreWithSchema = describe<DSReadMoreT>(DSReadMore);\n\nDSReadMoreWithSchema.propTypes = DSReadMoreProps;\n\nexport { DSReadMore, DSReadMoreWithSchema };\nexport default DSReadMore;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { DSButtonV2 } from "@elliemae/ds-button";
|
|
5
|
+
const StyledButton = styled(DSButtonV2)`
|
|
6
|
+
padding: 0;
|
|
7
|
+
color: ${({ withTooltip, theme }) => withTooltip ? "inherit" : `${theme.colors.brand["600"]}`};
|
|
8
|
+
border: 0;
|
|
9
|
+
margin: 0;
|
|
10
|
+
font-size: 12px;
|
|
11
|
+
font-weight: 200;
|
|
12
|
+
min-width: 0px;
|
|
13
|
+
height: auto;
|
|
14
|
+
text-transform: unset;
|
|
15
|
+
&:hover:not([disabled]) {
|
|
16
|
+
color: ${({ withTooltip, theme }) => withTooltip ? "inherit" : `${theme.colors.brand["600"]}`};
|
|
17
|
+
background-color: transparent;
|
|
18
|
+
text-decoration: ${({ withTooltip }) => withTooltip ? "" : "underline"};
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const MoreLessButton = (props) => {
|
|
22
|
+
const { expanded, ariaLabel, label, onClick, ellipsis, withTooltip, dataTestId } = props;
|
|
23
|
+
return /* @__PURE__ */ React2.createElement("span", null, expanded || withTooltip ? " " : ellipsis, /* @__PURE__ */ React2.createElement(StyledButton, {
|
|
24
|
+
withTooltip,
|
|
25
|
+
"aria-label": ariaLabel,
|
|
26
|
+
buttonType: "text",
|
|
27
|
+
onClick,
|
|
28
|
+
"aria-hidden": true,
|
|
29
|
+
size: "s",
|
|
30
|
+
"data-testid": dataTestId
|
|
31
|
+
}, label));
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
MoreLessButton
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=MoreLessButton.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/MoreLessButton.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport styled from 'styled-components';\nimport { DSButtonV2 } from '@elliemae/ds-button';\n\nimport type { MoreLessButtonT } from './index.d';\n\nconst StyledButton = styled(DSButtonV2)<{ withTooltip: boolean }>`\n padding: 0;\n color: ${({ withTooltip, theme }) => (withTooltip ? 'inherit' : `${theme.colors.brand['600']}`)};\n border: 0;\n margin: 0;\n font-size: 12px;\n font-weight: 200;\n min-width: 0px;\n height: auto;\n text-transform: unset;\n &:hover:not([disabled]) {\n color: ${({ withTooltip, theme }) => (withTooltip ? 'inherit' : `${theme.colors.brand['600']}`)};\n background-color: transparent;\n text-decoration: ${({ withTooltip }) => (withTooltip ? '' : 'underline')};\n }\n`;\nconst MoreLessButton = (props: MoreLessButtonT) => {\n const { expanded, ariaLabel, label, onClick, ellipsis, withTooltip, dataTestId } = props;\n\n return (\n <span>\n {expanded || withTooltip ? ' ' : ellipsis}\n\n <StyledButton\n withTooltip={withTooltip}\n aria-label={ariaLabel}\n buttonType=\"text\"\n onClick={onClick}\n aria-hidden\n size=\"s\"\n data-testid={dataTestId}\n >\n {label}\n </StyledButton>\n </span>\n );\n};\n\nexport { MoreLessButton };\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AAIA,MAAM,eAAe,OAAO;AAAA;AAAA,WAEjB,CAAC,EAAE,aAAa,YAAa,cAAc,YAAY,GAAG,MAAM,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAS3E,CAAC,EAAE,aAAa,YAAa,cAAc,YAAY,GAAG,MAAM,OAAO,MAAM;AAAA;AAAA,uBAEnE,CAAC,EAAE,kBAAmB,cAAc,KAAK;AAAA;AAAA;AAGhE,MAAM,iBAAiB,CAAC,UAA2B;AACjD,QAAM,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,aAAa,eAAe;AAEnF,SACE,qCAAC,QAAD,MACG,YAAY,cAAc,MAAM,UAEjC,qCAAC,cAAD;AAAA,IACE;AAAA,IACA,cAAY;AAAA,IACZ,YAAW;AAAA,IACX;AAAA,IACA,eAAW;AAAA,IACX,MAAK;AAAA,IACL,eAAa;AAAA,KAEZ;AAAA;",
|
|
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 './DSReadMore';\nexport { default } from './DSReadMore';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-read-more",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Read More",
|
|
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
|
"./MoreLessButton": {
|
|
15
|
-
"import": "./esm/MoreLessButton.js",
|
|
16
|
-
"require": "./cjs/MoreLessButton.js"
|
|
18
|
+
"import": "./dist/esm/MoreLessButton.js",
|
|
19
|
+
"require": "./dist/cjs/MoreLessButton.js"
|
|
17
20
|
},
|
|
18
21
|
"./DSReadMore": {
|
|
19
|
-
"import": "./esm/DSReadMore.js",
|
|
20
|
-
"require": "./cjs/DSReadMore.js"
|
|
22
|
+
"import": "./dist/esm/DSReadMore.js",
|
|
23
|
+
"require": "./dist/cjs/DSReadMore.js"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"sideEffects": [
|
|
@@ -29,38 +32,40 @@
|
|
|
29
32
|
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
30
33
|
},
|
|
31
34
|
"engines": {
|
|
32
|
-
"
|
|
33
|
-
"node": ">=
|
|
35
|
+
"pnpm": ">=6",
|
|
36
|
+
"node": ">=16"
|
|
34
37
|
},
|
|
35
38
|
"author": "ICE MT",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"jestSonar": {
|
|
40
|
+
"sonar56x": true,
|
|
41
|
+
"reportPath": "reports",
|
|
42
|
+
"reportFile": "tests.xml",
|
|
43
|
+
"indent": 4
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
|
-
"@elliemae/ds-button": "
|
|
44
|
-
"@elliemae/ds-shared": "
|
|
45
|
-
"@elliemae/ds-
|
|
46
|
-
"@elliemae/ds-tooltip": "2.3.1",
|
|
46
|
+
"@elliemae/ds-button": "3.0.0-alpha.3",
|
|
47
|
+
"@elliemae/ds-shared": "3.0.0-alpha.3",
|
|
48
|
+
"@elliemae/ds-tooltip": "3.0.0-alpha.3",
|
|
47
49
|
"react-desc": "~4.1.3"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@testing-library/dom": "~8.11.1",
|
|
51
52
|
"@testing-library/react": "~12.1.2",
|
|
52
|
-
"@testing-library/user-event": "~13.5.0",
|
|
53
53
|
"styled-components": "~5.3.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"lodash": "^4.17.21",
|
|
57
56
|
"react": "^17.0.2",
|
|
58
57
|
"react-dom": "^17.0.2",
|
|
59
58
|
"styled-components": "^5.3.3"
|
|
60
59
|
},
|
|
61
60
|
"publishConfig": {
|
|
62
61
|
"access": "public",
|
|
63
|
-
"
|
|
64
|
-
|
|
62
|
+
"typeSafety": false
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"dev": "cross-env NODE_ENV=development node ../../scripts/build/build.mjs --watch",
|
|
66
|
+
"test": "node ../../scripts/testing/test.mjs",
|
|
67
|
+
"lint": "node ../../scripts/lint.mjs",
|
|
68
|
+
"dts": "node ../../scripts/dts.mjs",
|
|
69
|
+
"build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs"
|
|
65
70
|
}
|
|
66
71
|
}
|
package/cjs/DSReadMore.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
-
require('core-js/modules/web.dom-collections.iterator.js');
|
|
7
|
-
var react = require('react');
|
|
8
|
-
var lodash = require('lodash');
|
|
9
|
-
var reactDesc = require('react-desc');
|
|
10
|
-
var styled = require('styled-components');
|
|
11
|
-
var dsTooltip = require('@elliemae/ds-tooltip');
|
|
12
|
-
var dsButton = require('@elliemae/ds-button');
|
|
13
|
-
var propTypes = require('@elliemae/ds-shared/prop-types');
|
|
14
|
-
var MoreLessButton = require('./MoreLessButton.js');
|
|
15
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
|
-
|
|
19
|
-
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
20
|
-
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
21
|
-
|
|
22
|
-
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
|
23
|
-
componentId: "sc-1c4w5m6-0"
|
|
24
|
-
})(["display:-webkit-box;-webkit-line-clamp:", ";-webkit-box-orient:vertical;-webkit-hyphens:auto;-moz-hyphens:auto;-ms-hyphens:auto;hyphens:auto;word-break:break-all;"], _ref => {
|
|
25
|
-
let {
|
|
26
|
-
lines,
|
|
27
|
-
expanded
|
|
28
|
-
} = _ref;
|
|
29
|
-
return expanded ? 'unset' : lines;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const DSReadMore = props => {
|
|
33
|
-
const {
|
|
34
|
-
lines = 2,
|
|
35
|
-
more = 'more',
|
|
36
|
-
less = 'less',
|
|
37
|
-
onMore = lodash.noop,
|
|
38
|
-
onLess = lodash.noop,
|
|
39
|
-
content,
|
|
40
|
-
ellipsis = '...',
|
|
41
|
-
withTooltip = false
|
|
42
|
-
} = props;
|
|
43
|
-
const ref = react.useRef(null);
|
|
44
|
-
const [showButton, setShowButton] = react.useState(false);
|
|
45
|
-
const [expanded, setExpanded] = react.useState(false); // offsetHeight + 2 takes into consideration any size of the button
|
|
46
|
-
|
|
47
|
-
const overflows = _ref2 => {
|
|
48
|
-
let {
|
|
49
|
-
offsetHeight,
|
|
50
|
-
scrollHeight
|
|
51
|
-
} = _ref2;
|
|
52
|
-
return offsetHeight + 2 < scrollHeight;
|
|
53
|
-
}; // Searchs the optimum cut on the text to have the button in the same line
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const binSearchTextOverflow = react.useCallback((element, parent) => {
|
|
57
|
-
const text = element.innerText;
|
|
58
|
-
let left = 1;
|
|
59
|
-
let right = text.length;
|
|
60
|
-
let textEnd = 0;
|
|
61
|
-
|
|
62
|
-
while (left <= right) {
|
|
63
|
-
const middle = (left + right) / 2;
|
|
64
|
-
element.innerText = content.slice(0, middle);
|
|
65
|
-
if (overflows(parent)) right = middle - 1;else {
|
|
66
|
-
left = middle + 1;
|
|
67
|
-
textEnd = middle;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
element.innerText = content.slice(0, textEnd);
|
|
72
|
-
}, [content]);
|
|
73
|
-
react.useLayoutEffect(() => {
|
|
74
|
-
var _ref$current;
|
|
75
|
-
|
|
76
|
-
const textElement = ref.current;
|
|
77
|
-
const parentElement = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.parentElement;
|
|
78
|
-
|
|
79
|
-
if (parentElement && textElement) {
|
|
80
|
-
textElement.innerText = content;
|
|
81
|
-
setShowButton(expanded || overflows(parentElement));
|
|
82
|
-
|
|
83
|
-
if (!expanded && overflows(parentElement)) {
|
|
84
|
-
binSearchTextOverflow(textElement, parentElement);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
|
|
88
|
-
|
|
89
|
-
const toggleExpanded = newExpanded => {
|
|
90
|
-
setExpanded(newExpanded);
|
|
91
|
-
if (newExpanded) onMore();else onLess();
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return /*#__PURE__*/_jsx2__default["default"](Text, {
|
|
95
|
-
lines: lines,
|
|
96
|
-
expanded: expanded
|
|
97
|
-
}, void 0, /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
98
|
-
ref: ref,
|
|
99
|
-
"data-testid": "ds-read_more-text",
|
|
100
|
-
"aria-label": content,
|
|
101
|
-
children: content
|
|
102
|
-
}), showButton && !withTooltip && /*#__PURE__*/_jsx2__default["default"](MoreLessButton.MoreLessButton, {
|
|
103
|
-
expanded: expanded,
|
|
104
|
-
label: expanded ? less : more,
|
|
105
|
-
onClick: () => toggleExpanded(!expanded),
|
|
106
|
-
ariaLabel: expanded ? less : more,
|
|
107
|
-
ellipsis: ellipsis,
|
|
108
|
-
dataTestId: "ds-read_more-button"
|
|
109
|
-
}), withTooltip && /*#__PURE__*/_jsx2__default["default"]("div", {
|
|
110
|
-
style: {
|
|
111
|
-
display: 'inline-block'
|
|
112
|
-
}
|
|
113
|
-
}, void 0, /*#__PURE__*/_jsx2__default["default"](dsTooltip.DSTooltipV3, {
|
|
114
|
-
text: content
|
|
115
|
-
}, void 0, /*#__PURE__*/_jsx2__default["default"](MoreLessButton.MoreLessButton, {
|
|
116
|
-
expanded: expanded,
|
|
117
|
-
label: "...",
|
|
118
|
-
ariaLabel: content,
|
|
119
|
-
ellipsis: ellipsis,
|
|
120
|
-
withTooltip: withTooltip,
|
|
121
|
-
dataTestId: "ds-read_more-tooltip-button"
|
|
122
|
-
}))));
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const DSReadMoreProps = {
|
|
126
|
-
/** Ammount of lines after you want to display an ellipsis + more/less button */
|
|
127
|
-
lines: reactDesc.PropTypes.number.description('Ammount of lines after you want to display an ellipsis + more/less button').defaultValue(2),
|
|
128
|
-
|
|
129
|
-
/** Label which will appear on the 'More' button */
|
|
130
|
-
more: reactDesc.PropTypes.string.description("Label which will appear on the 'More' button").defaultValue('more'),
|
|
131
|
-
|
|
132
|
-
/** Label which will appear on the 'Less' button */
|
|
133
|
-
less: reactDesc.PropTypes.string.description("Label which will appear on the 'Less' button").defaultValue('less'),
|
|
134
|
-
|
|
135
|
-
/** Function which will execute when the user click the 'More' button */
|
|
136
|
-
onMore: reactDesc.PropTypes.func.description("Function which will execute when the user click the 'More' button"),
|
|
137
|
-
|
|
138
|
-
/** Function which will execute when the user click the 'Less' button */
|
|
139
|
-
onLess: reactDesc.PropTypes.func.description("Function which will execute when the user click the 'Less' button"),
|
|
140
|
-
|
|
141
|
-
/** The text content you want displayed */
|
|
142
|
-
content: reactDesc.PropTypes.string.description('The text content you want displayed').isRequired,
|
|
143
|
-
|
|
144
|
-
/** 'The type of button for more/less button' */
|
|
145
|
-
buttonType: reactDesc.PropTypes.oneOf(dsButton.buttonTypes).description('The type for the more/less button').defaultValue('link'),
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* ['s', 'm', 'l']
|
|
149
|
-
*/
|
|
150
|
-
size: reactDesc.PropTypes.oneOf(propTypes.dsBasicSizes).description('Size of the button').defaultValue('s'),
|
|
151
|
-
|
|
152
|
-
/** The text you want to appear when truncating */
|
|
153
|
-
ellipsis: reactDesc.PropTypes.string.description('The text you want to appear when truncating').defaultValue('...'),
|
|
154
|
-
withTooltip: reactDesc.PropTypes.bool.description('Whether to show expandable tooltip on ellipsis focus instead of expandable buttons').defaultValue('false')
|
|
155
|
-
};
|
|
156
|
-
const DSReadMoreWithSchema = reactDesc.describe(DSReadMore);
|
|
157
|
-
DSReadMoreWithSchema.propTypes = DSReadMoreProps;
|
|
158
|
-
|
|
159
|
-
exports.DSReadMore = DSReadMore;
|
|
160
|
-
exports.DSReadMoreWithSchema = DSReadMoreWithSchema;
|
|
161
|
-
exports["default"] = DSReadMore;
|
package/cjs/MoreLessButton.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
-
require('react');
|
|
7
|
-
var styled = require('styled-components');
|
|
8
|
-
var dsButton = require('@elliemae/ds-button');
|
|
9
|
-
|
|
10
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
-
|
|
12
|
-
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
13
|
-
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
14
|
-
|
|
15
|
-
const StyledButton = /*#__PURE__*/styled__default["default"](dsButton.DSButtonV2).withConfig({
|
|
16
|
-
componentId: "sc-1innsd2-0"
|
|
17
|
-
})(["padding:0;color:", ";border:0;margin:0;font-size:12px;font-weight:200;min-width:0px;height:auto;text-transform:unset;&:hover:not([disabled]){color:", ";background-color:transparent;text-decoration:", ";}"], _ref => {
|
|
18
|
-
let {
|
|
19
|
-
withTooltip,
|
|
20
|
-
theme
|
|
21
|
-
} = _ref;
|
|
22
|
-
return withTooltip ? 'inherit' : "".concat(theme.colors.brand['600']);
|
|
23
|
-
}, _ref2 => {
|
|
24
|
-
let {
|
|
25
|
-
withTooltip,
|
|
26
|
-
theme
|
|
27
|
-
} = _ref2;
|
|
28
|
-
return withTooltip ? 'inherit' : "".concat(theme.colors.brand['600']);
|
|
29
|
-
}, _ref3 => {
|
|
30
|
-
let {
|
|
31
|
-
withTooltip
|
|
32
|
-
} = _ref3;
|
|
33
|
-
return withTooltip ? '' : 'underline';
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const MoreLessButton = props => {
|
|
37
|
-
const {
|
|
38
|
-
expanded,
|
|
39
|
-
ariaLabel,
|
|
40
|
-
label,
|
|
41
|
-
onClick,
|
|
42
|
-
ellipsis,
|
|
43
|
-
withTooltip,
|
|
44
|
-
dataTestId
|
|
45
|
-
} = props;
|
|
46
|
-
return /*#__PURE__*/_jsx2__default["default"]("span", {}, void 0, expanded || withTooltip ? ' ' : ellipsis, /*#__PURE__*/_jsx2__default["default"](StyledButton, {
|
|
47
|
-
withTooltip: withTooltip,
|
|
48
|
-
"aria-label": ariaLabel,
|
|
49
|
-
buttonType: "text",
|
|
50
|
-
onClick: onClick,
|
|
51
|
-
"aria-hidden": true,
|
|
52
|
-
size: "s",
|
|
53
|
-
"data-testid": dataTestId
|
|
54
|
-
}, void 0, label));
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
exports.MoreLessButton = MoreLessButton;
|
package/cjs/index.d.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 DSReadMore = require('./DSReadMore.js');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.DSReadMore = DSReadMore.DSReadMore;
|
|
10
|
-
exports.DSReadMoreWithSchema = DSReadMore.DSReadMoreWithSchema;
|
|
11
|
-
exports["default"] = DSReadMore.DSReadMore;
|
package/esm/DSReadMore.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import _jsx2 from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
3
|
-
import { useRef, useState, useCallback, useLayoutEffect } from 'react';
|
|
4
|
-
import { noop } from 'lodash';
|
|
5
|
-
import { PropTypes, describe } from 'react-desc';
|
|
6
|
-
import styled from 'styled-components';
|
|
7
|
-
import { DSTooltipV3 } from '@elliemae/ds-tooltip';
|
|
8
|
-
import { buttonTypes } from '@elliemae/ds-button';
|
|
9
|
-
import { dsBasicSizes } from '@elliemae/ds-shared/prop-types';
|
|
10
|
-
import { MoreLessButton } from './MoreLessButton.js';
|
|
11
|
-
import { jsx } from 'react/jsx-runtime';
|
|
12
|
-
|
|
13
|
-
const Text = /*#__PURE__*/styled.span.withConfig({
|
|
14
|
-
componentId: "sc-1c4w5m6-0"
|
|
15
|
-
})(["display:-webkit-box;-webkit-line-clamp:", ";-webkit-box-orient:vertical;-webkit-hyphens:auto;-moz-hyphens:auto;-ms-hyphens:auto;hyphens:auto;word-break:break-all;"], _ref => {
|
|
16
|
-
let {
|
|
17
|
-
lines,
|
|
18
|
-
expanded
|
|
19
|
-
} = _ref;
|
|
20
|
-
return expanded ? 'unset' : lines;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const DSReadMore = props => {
|
|
24
|
-
const {
|
|
25
|
-
lines = 2,
|
|
26
|
-
more = 'more',
|
|
27
|
-
less = 'less',
|
|
28
|
-
onMore = noop,
|
|
29
|
-
onLess = noop,
|
|
30
|
-
content,
|
|
31
|
-
ellipsis = '...',
|
|
32
|
-
withTooltip = false
|
|
33
|
-
} = props;
|
|
34
|
-
const ref = useRef(null);
|
|
35
|
-
const [showButton, setShowButton] = useState(false);
|
|
36
|
-
const [expanded, setExpanded] = useState(false); // offsetHeight + 2 takes into consideration any size of the button
|
|
37
|
-
|
|
38
|
-
const overflows = _ref2 => {
|
|
39
|
-
let {
|
|
40
|
-
offsetHeight,
|
|
41
|
-
scrollHeight
|
|
42
|
-
} = _ref2;
|
|
43
|
-
return offsetHeight + 2 < scrollHeight;
|
|
44
|
-
}; // Searchs the optimum cut on the text to have the button in the same line
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const binSearchTextOverflow = useCallback((element, parent) => {
|
|
48
|
-
const text = element.innerText;
|
|
49
|
-
let left = 1;
|
|
50
|
-
let right = text.length;
|
|
51
|
-
let textEnd = 0;
|
|
52
|
-
|
|
53
|
-
while (left <= right) {
|
|
54
|
-
const middle = (left + right) / 2;
|
|
55
|
-
element.innerText = content.slice(0, middle);
|
|
56
|
-
if (overflows(parent)) right = middle - 1;else {
|
|
57
|
-
left = middle + 1;
|
|
58
|
-
textEnd = middle;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
element.innerText = content.slice(0, textEnd);
|
|
63
|
-
}, [content]);
|
|
64
|
-
useLayoutEffect(() => {
|
|
65
|
-
var _ref$current;
|
|
66
|
-
|
|
67
|
-
const textElement = ref.current;
|
|
68
|
-
const parentElement = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.parentElement;
|
|
69
|
-
|
|
70
|
-
if (parentElement && textElement) {
|
|
71
|
-
textElement.innerText = content;
|
|
72
|
-
setShowButton(expanded || overflows(parentElement));
|
|
73
|
-
|
|
74
|
-
if (!expanded && overflows(parentElement)) {
|
|
75
|
-
binSearchTextOverflow(textElement, parentElement);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
|
|
79
|
-
|
|
80
|
-
const toggleExpanded = newExpanded => {
|
|
81
|
-
setExpanded(newExpanded);
|
|
82
|
-
if (newExpanded) onMore();else onLess();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return /*#__PURE__*/_jsx2(Text, {
|
|
86
|
-
lines: lines,
|
|
87
|
-
expanded: expanded
|
|
88
|
-
}, void 0, /*#__PURE__*/jsx("span", {
|
|
89
|
-
ref: ref,
|
|
90
|
-
"data-testid": "ds-read_more-text",
|
|
91
|
-
"aria-label": content,
|
|
92
|
-
children: content
|
|
93
|
-
}), showButton && !withTooltip && /*#__PURE__*/_jsx2(MoreLessButton, {
|
|
94
|
-
expanded: expanded,
|
|
95
|
-
label: expanded ? less : more,
|
|
96
|
-
onClick: () => toggleExpanded(!expanded),
|
|
97
|
-
ariaLabel: expanded ? less : more,
|
|
98
|
-
ellipsis: ellipsis,
|
|
99
|
-
dataTestId: "ds-read_more-button"
|
|
100
|
-
}), withTooltip && /*#__PURE__*/_jsx2("div", {
|
|
101
|
-
style: {
|
|
102
|
-
display: 'inline-block'
|
|
103
|
-
}
|
|
104
|
-
}, void 0, /*#__PURE__*/_jsx2(DSTooltipV3, {
|
|
105
|
-
text: content
|
|
106
|
-
}, void 0, /*#__PURE__*/_jsx2(MoreLessButton, {
|
|
107
|
-
expanded: expanded,
|
|
108
|
-
label: "...",
|
|
109
|
-
ariaLabel: content,
|
|
110
|
-
ellipsis: ellipsis,
|
|
111
|
-
withTooltip: withTooltip,
|
|
112
|
-
dataTestId: "ds-read_more-tooltip-button"
|
|
113
|
-
}))));
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const DSReadMoreProps = {
|
|
117
|
-
/** Ammount of lines after you want to display an ellipsis + more/less button */
|
|
118
|
-
lines: PropTypes.number.description('Ammount of lines after you want to display an ellipsis + more/less button').defaultValue(2),
|
|
119
|
-
|
|
120
|
-
/** Label which will appear on the 'More' button */
|
|
121
|
-
more: PropTypes.string.description("Label which will appear on the 'More' button").defaultValue('more'),
|
|
122
|
-
|
|
123
|
-
/** Label which will appear on the 'Less' button */
|
|
124
|
-
less: PropTypes.string.description("Label which will appear on the 'Less' button").defaultValue('less'),
|
|
125
|
-
|
|
126
|
-
/** Function which will execute when the user click the 'More' button */
|
|
127
|
-
onMore: PropTypes.func.description("Function which will execute when the user click the 'More' button"),
|
|
128
|
-
|
|
129
|
-
/** Function which will execute when the user click the 'Less' button */
|
|
130
|
-
onLess: PropTypes.func.description("Function which will execute when the user click the 'Less' button"),
|
|
131
|
-
|
|
132
|
-
/** The text content you want displayed */
|
|
133
|
-
content: PropTypes.string.description('The text content you want displayed').isRequired,
|
|
134
|
-
|
|
135
|
-
/** 'The type of button for more/less button' */
|
|
136
|
-
buttonType: PropTypes.oneOf(buttonTypes).description('The type for the more/less button').defaultValue('link'),
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* ['s', 'm', 'l']
|
|
140
|
-
*/
|
|
141
|
-
size: PropTypes.oneOf(dsBasicSizes).description('Size of the button').defaultValue('s'),
|
|
142
|
-
|
|
143
|
-
/** The text you want to appear when truncating */
|
|
144
|
-
ellipsis: PropTypes.string.description('The text you want to appear when truncating').defaultValue('...'),
|
|
145
|
-
withTooltip: PropTypes.bool.description('Whether to show expandable tooltip on ellipsis focus instead of expandable buttons').defaultValue('false')
|
|
146
|
-
};
|
|
147
|
-
const DSReadMoreWithSchema = describe(DSReadMore);
|
|
148
|
-
DSReadMoreWithSchema.propTypes = DSReadMoreProps;
|
|
149
|
-
|
|
150
|
-
export { DSReadMore, DSReadMoreWithSchema, DSReadMore as default };
|
package/esm/MoreLessButton.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import _jsx2 from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
-
import 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { DSButtonV2 } from '@elliemae/ds-button';
|
|
5
|
-
|
|
6
|
-
const StyledButton = /*#__PURE__*/styled(DSButtonV2).withConfig({
|
|
7
|
-
componentId: "sc-1innsd2-0"
|
|
8
|
-
})(["padding:0;color:", ";border:0;margin:0;font-size:12px;font-weight:200;min-width:0px;height:auto;text-transform:unset;&:hover:not([disabled]){color:", ";background-color:transparent;text-decoration:", ";}"], _ref => {
|
|
9
|
-
let {
|
|
10
|
-
withTooltip,
|
|
11
|
-
theme
|
|
12
|
-
} = _ref;
|
|
13
|
-
return withTooltip ? 'inherit' : "".concat(theme.colors.brand['600']);
|
|
14
|
-
}, _ref2 => {
|
|
15
|
-
let {
|
|
16
|
-
withTooltip,
|
|
17
|
-
theme
|
|
18
|
-
} = _ref2;
|
|
19
|
-
return withTooltip ? 'inherit' : "".concat(theme.colors.brand['600']);
|
|
20
|
-
}, _ref3 => {
|
|
21
|
-
let {
|
|
22
|
-
withTooltip
|
|
23
|
-
} = _ref3;
|
|
24
|
-
return withTooltip ? '' : 'underline';
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const MoreLessButton = props => {
|
|
28
|
-
const {
|
|
29
|
-
expanded,
|
|
30
|
-
ariaLabel,
|
|
31
|
-
label,
|
|
32
|
-
onClick,
|
|
33
|
-
ellipsis,
|
|
34
|
-
withTooltip,
|
|
35
|
-
dataTestId
|
|
36
|
-
} = props;
|
|
37
|
-
return /*#__PURE__*/_jsx2("span", {}, void 0, expanded || withTooltip ? ' ' : ellipsis, /*#__PURE__*/_jsx2(StyledButton, {
|
|
38
|
-
withTooltip: withTooltip,
|
|
39
|
-
"aria-label": ariaLabel,
|
|
40
|
-
buttonType: "text",
|
|
41
|
-
onClick: onClick,
|
|
42
|
-
"aria-hidden": true,
|
|
43
|
-
size: "s",
|
|
44
|
-
"data-testid": dataTestId
|
|
45
|
-
}, void 0, label));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { MoreLessButton };
|
package/esm/index.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DSReadMore, DSReadMoreWithSchema, DSReadMore as default } from './DSReadMore.js';
|
package/types/DSReadMore.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { DSReadMoreT } from './index.d';
|
|
4
|
-
declare const DSReadMore: {
|
|
5
|
-
(props: DSReadMoreT): JSX.Element;
|
|
6
|
-
propTypes: React.WeakValidationMap<unknown>;
|
|
7
|
-
};
|
|
8
|
-
declare const DSReadMoreWithSchema: {
|
|
9
|
-
(props?: DSReadMoreT | undefined): JSX.Element;
|
|
10
|
-
propTypes: unknown;
|
|
11
|
-
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
12
|
-
};
|
|
13
|
-
export { DSReadMore, DSReadMoreWithSchema };
|
|
14
|
-
export default DSReadMore;
|
package/types/index.d.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface DSReadMoreT {
|
|
2
|
-
lines: number;
|
|
3
|
-
more: string;
|
|
4
|
-
less: string;
|
|
5
|
-
onMore: () => void;
|
|
6
|
-
onLess: () => void;
|
|
7
|
-
content: string;
|
|
8
|
-
ellipsis: string;
|
|
9
|
-
withTooltip?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface MoreLessButtonT {
|
|
12
|
-
expanded: boolean;
|
|
13
|
-
label: string;
|
|
14
|
-
onClick?: () => void;
|
|
15
|
-
ellipsis: string;
|
|
16
|
-
withTooltip?: boolean;
|
|
17
|
-
ariaLabel: string;
|
|
18
|
-
dataTestId: string;
|
|
19
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|