@elliemae/ds-read-more 2.2.0-alpha.1 → 2.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/DSReadMore.js CHANGED
@@ -1,161 +1,149 @@
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;
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
30
33
  });
31
-
32
- const DSReadMore = props => {
34
+ var React = __toESM(require("react"));
35
+ var import_react = __toESM(require("react"));
36
+ var import_lodash = __toESM(require("lodash"));
37
+ var import_react_desc = __toESM(require("react-desc"));
38
+ var import_styled_components = __toESM(require("styled-components"));
39
+ var import_ds_tooltip = __toESM(require("@elliemae/ds-tooltip"));
40
+ var import_ds_button = __toESM(require("@elliemae/ds-button"));
41
+ var import_prop_types = __toESM(require("@elliemae/ds-shared/prop-types"));
42
+ var import_MoreLessButton = __toESM(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) => {
33
54
  const {
34
55
  lines = 2,
35
- more = 'more',
36
- less = 'less',
37
- onMore = lodash.noop,
38
- onLess = lodash.noop,
56
+ more = "more",
57
+ less = "less",
58
+ onMore = import_lodash.noop,
59
+ onLess = import_lodash.noop,
39
60
  content,
40
- ellipsis = '...',
61
+ ellipsis = "...",
41
62
  withTooltip = false
42
63
  } = 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) => {
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) => {
57
69
  const text = element.innerText;
58
70
  let left = 1;
59
71
  let right = text.length;
60
72
  let textEnd = 0;
61
-
62
73
  while (left <= right) {
63
74
  const middle = (left + right) / 2;
64
75
  element.innerText = content.slice(0, middle);
65
- if (overflows(parent)) right = middle - 1;else {
76
+ if (overflows(parent))
77
+ right = middle - 1;
78
+ else {
66
79
  left = middle + 1;
67
80
  textEnd = middle;
68
81
  }
69
82
  }
70
-
71
83
  element.innerText = content.slice(0, textEnd);
72
84
  }, [content]);
73
- react.useLayoutEffect(() => {
74
- var _ref$current;
75
-
85
+ (0, import_react.useLayoutEffect)(() => {
76
86
  const textElement = ref.current;
77
- const parentElement = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.parentElement;
78
-
87
+ const parentElement = ref.current?.parentElement;
79
88
  if (parentElement && textElement) {
80
89
  textElement.innerText = content;
81
90
  setShowButton(expanded || overflows(parentElement));
82
-
83
91
  if (!expanded && overflows(parentElement)) {
84
92
  binSearchTextOverflow(textElement, parentElement);
85
93
  }
86
94
  }
87
95
  }, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
88
-
89
- const toggleExpanded = newExpanded => {
96
+ const toggleExpanded = (newExpanded) => {
90
97
  setExpanded(newExpanded);
91
- if (newExpanded) onMore();else onLess();
98
+ if (newExpanded)
99
+ onMore();
100
+ else
101
+ onLess();
92
102
  };
93
-
94
- return /*#__PURE__*/_jsx2__default["default"](Text, {
95
- lines: lines,
96
- expanded: expanded
97
- }, void 0, /*#__PURE__*/jsxRuntime.jsx("span", {
98
- ref: ref,
103
+ return /* @__PURE__ */ import_react.default.createElement(Text, {
104
+ lines,
105
+ expanded
106
+ }, /* @__PURE__ */ import_react.default.createElement("span", {
107
+ ref,
99
108
  "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,
109
+ "aria-label": content
110
+ }, content), showButton && !withTooltip && /* @__PURE__ */ import_react.default.createElement(import_MoreLessButton.MoreLessButton, {
111
+ expanded,
104
112
  label: expanded ? less : more,
105
113
  onClick: () => toggleExpanded(!expanded),
106
114
  ariaLabel: expanded ? less : more,
107
- ellipsis: ellipsis,
115
+ ellipsis,
108
116
  dataTestId: "ds-read_more-button"
109
- }), withTooltip && /*#__PURE__*/_jsx2__default["default"]("div", {
117
+ }), withTooltip && /* @__PURE__ */ import_react.default.createElement("div", {
110
118
  style: {
111
- display: 'inline-block'
119
+ display: "inline-block"
112
120
  }
113
- }, void 0, /*#__PURE__*/_jsx2__default["default"](dsTooltip.DSTooltipV3, {
121
+ }, /* @__PURE__ */ import_react.default.createElement(import_ds_tooltip.DSTooltipV3, {
114
122
  text: content
115
- }, void 0, /*#__PURE__*/_jsx2__default["default"](MoreLessButton.MoreLessButton, {
116
- expanded: expanded,
123
+ }, /* @__PURE__ */ import_react.default.createElement(import_MoreLessButton.MoreLessButton, {
124
+ expanded,
117
125
  label: "...",
118
126
  ariaLabel: content,
119
- ellipsis: ellipsis,
120
- withTooltip: withTooltip,
127
+ ellipsis,
128
+ withTooltip,
121
129
  dataTestId: "ds-read_more-tooltip-button"
122
130
  }))));
123
131
  };
124
-
125
132
  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')
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")
155
143
  };
156
- const DSReadMoreWithSchema = reactDesc.describe(DSReadMore);
144
+ DSReadMore.propTypes = DSReadMoreProps;
145
+ const DSReadMoreWithSchema = (0, import_react_desc.describe)(DSReadMore);
157
146
  DSReadMoreWithSchema.propTypes = DSReadMoreProps;
158
-
159
- exports.DSReadMore = DSReadMore;
160
- exports.DSReadMoreWithSchema = DSReadMoreWithSchema;
161
- exports["default"] = DSReadMore;
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAsE;AACtE,oBAAqB;AAErB,wBAAoC;AACpC,+BAAmB;AACnB,wBAA4B;AAE5B,uBAA4B;AAC5B,wBAA6B;AAC7B,4BAA+B;AAG/B,MAAM,OAAO,iCAAO;AAAA;AAAA,wBAEI,CAAC,EAAE,OAAO,eAAgB,WAAW,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASvE,MAAM,aAAa,CAAC,UAAuB;AACzC,QAAM;AAAA,IACJ,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA,WAAW;AAAA,IACX,cAAc;AAAA,MACZ;AACJ,QAAM,MAAM,yBAAoB;AAChC,QAAM,CAAC,YAAY,iBAAiB,2BAAS;AAC7C,QAAM,CAAC,UAAU,eAAe,2BAAS;AAGzC,QAAM,YAAY,CAAC,EAAE,cAAc,mBACjC,eAAe,IAAI;AAGrB,QAAM,wBAAwB,8BAC5B,CAAC,SAAsB,WAAwB;AAC7C,UAAM,OAAO,QAAQ;AACrB,QAAI,OAAO;AACX,QAAI,QAAQ,KAAK;AACjB,QAAI,UAAU;AACd,WAAO,QAAQ,OAAO;AACpB,YAAM,SAAU,QAAO,SAAS;AAChC,cAAQ,YAAY,QAAQ,MAAM,GAAG;AACrC,UAAI,UAAU;AAAS,gBAAQ,SAAS;AAAA,WACnC;AACH,eAAO,SAAS;AAChB,kBAAU;AAAA;AAAA;AAGd,YAAQ,YAAY,QAAQ,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O,YAAY,uCAAuC;AAAA,EAG7E,YAAY,4BAAU,MAAM,8BAAa,YAAY,qCAAqC,aAAa;AAAA,EAIvG,MAAM,4BAAU,MAAM,gCACnB,YAAY,sBACZ,aAAa;AAAA,EAGhB,UAAU,4BAAU,OAAO,YAAY,+CAA+C,aAAa;AAAA,EACnG,aAAa,4BAAU,KACpB,YAAY,sFACZ,aAAa;AAAA;AAGlB,WAAW,YAAY;AAEvB,MAAM,uBAAuB,gCAAsB;AAEnD,qBAAqB,YAAY;AAGjC,IAAO,qBAAQ;",
6
+ "names": []
7
+ }
@@ -1,57 +1,65 @@
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';
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
34
31
  });
35
-
36
- const MoreLessButton = props => {
37
- const {
38
- expanded,
39
- ariaLabel,
40
- label,
41
- onClick,
42
- ellipsis,
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 = __toESM(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, {
43
55
  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
56
  "aria-label": ariaLabel,
49
57
  buttonType: "text",
50
- onClick: onClick,
58
+ onClick,
51
59
  "aria-hidden": true,
52
60
  size: "s",
53
61
  "data-testid": dataTestId
54
- }, void 0, label));
62
+ }, label));
55
63
  };
56
-
57
- exports.MoreLessButton = MoreLessButton;
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
+ }
package/cjs/index.d.js CHANGED
@@ -1,2 +1,27 @@
1
- 'use strict';
2
-
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
+ }
package/cjs/index.js CHANGED
@@ -1,11 +1,36 @@
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;
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, __toESM(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
+ }
package/esm/DSReadMore.js CHANGED
@@ -1,150 +1,120 @@
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 => {
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) => {
24
21
  const {
25
22
  lines = 2,
26
- more = 'more',
27
- less = 'less',
23
+ more = "more",
24
+ less = "less",
28
25
  onMore = noop,
29
26
  onLess = noop,
30
27
  content,
31
- ellipsis = '...',
28
+ ellipsis = "...",
32
29
  withTooltip = false
33
30
  } = props;
34
31
  const ref = useRef(null);
35
32
  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
-
33
+ const [expanded, setExpanded] = useState(false);
34
+ const overflows = ({ offsetHeight, scrollHeight }) => offsetHeight + 2 < scrollHeight;
47
35
  const binSearchTextOverflow = useCallback((element, parent) => {
48
36
  const text = element.innerText;
49
37
  let left = 1;
50
38
  let right = text.length;
51
39
  let textEnd = 0;
52
-
53
40
  while (left <= right) {
54
41
  const middle = (left + right) / 2;
55
42
  element.innerText = content.slice(0, middle);
56
- if (overflows(parent)) right = middle - 1;else {
43
+ if (overflows(parent))
44
+ right = middle - 1;
45
+ else {
57
46
  left = middle + 1;
58
47
  textEnd = middle;
59
48
  }
60
49
  }
61
-
62
50
  element.innerText = content.slice(0, textEnd);
63
51
  }, [content]);
64
52
  useLayoutEffect(() => {
65
- var _ref$current;
66
-
67
53
  const textElement = ref.current;
68
- const parentElement = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.parentElement;
69
-
54
+ const parentElement = ref.current?.parentElement;
70
55
  if (parentElement && textElement) {
71
56
  textElement.innerText = content;
72
57
  setShowButton(expanded || overflows(parentElement));
73
-
74
58
  if (!expanded && overflows(parentElement)) {
75
59
  binSearchTextOverflow(textElement, parentElement);
76
60
  }
77
61
  }
78
62
  }, [lines, content, binSearchTextOverflow, expanded, showButton, withTooltip, more, less]);
79
-
80
- const toggleExpanded = newExpanded => {
63
+ const toggleExpanded = (newExpanded) => {
81
64
  setExpanded(newExpanded);
82
- if (newExpanded) onMore();else onLess();
65
+ if (newExpanded)
66
+ onMore();
67
+ else
68
+ onLess();
83
69
  };
84
-
85
- return /*#__PURE__*/_jsx2(Text, {
86
- lines: lines,
87
- expanded: expanded
88
- }, void 0, /*#__PURE__*/jsx("span", {
89
- ref: ref,
70
+ return /* @__PURE__ */ React2.createElement(Text, {
71
+ lines,
72
+ expanded
73
+ }, /* @__PURE__ */ React2.createElement("span", {
74
+ ref,
90
75
  "data-testid": "ds-read_more-text",
91
- "aria-label": content,
92
- children: content
93
- }), showButton && !withTooltip && /*#__PURE__*/_jsx2(MoreLessButton, {
94
- expanded: expanded,
76
+ "aria-label": content
77
+ }, content), showButton && !withTooltip && /* @__PURE__ */ React2.createElement(MoreLessButton, {
78
+ expanded,
95
79
  label: expanded ? less : more,
96
80
  onClick: () => toggleExpanded(!expanded),
97
81
  ariaLabel: expanded ? less : more,
98
- ellipsis: ellipsis,
82
+ ellipsis,
99
83
  dataTestId: "ds-read_more-button"
100
- }), withTooltip && /*#__PURE__*/_jsx2("div", {
84
+ }), withTooltip && /* @__PURE__ */ React2.createElement("div", {
101
85
  style: {
102
- display: 'inline-block'
86
+ display: "inline-block"
103
87
  }
104
- }, void 0, /*#__PURE__*/_jsx2(DSTooltipV3, {
88
+ }, /* @__PURE__ */ React2.createElement(DSTooltipV3, {
105
89
  text: content
106
- }, void 0, /*#__PURE__*/_jsx2(MoreLessButton, {
107
- expanded: expanded,
90
+ }, /* @__PURE__ */ React2.createElement(MoreLessButton, {
91
+ expanded,
108
92
  label: "...",
109
93
  ariaLabel: content,
110
- ellipsis: ellipsis,
111
- withTooltip: withTooltip,
94
+ ellipsis,
95
+ withTooltip,
112
96
  dataTestId: "ds-read_more-tooltip-button"
113
97
  }))));
114
98
  };
115
-
116
99
  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 */
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"),
127
103
  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
104
  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')
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")
146
110
  };
111
+ DSReadMore.propTypes = DSReadMoreProps;
147
112
  const DSReadMoreWithSchema = describe(DSReadMore);
148
113
  DSReadMoreWithSchema.propTypes = DSReadMoreProps;
149
-
150
- export { DSReadMore, DSReadMoreWithSchema, DSReadMore as default };
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": "AAAA;ACCA;AACA;AAEA;AACA;AACA;AAEA;A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
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 {
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, {
10
24
  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
25
  "aria-label": ariaLabel,
40
26
  buttonType: "text",
41
- onClick: onClick,
27
+ onClick,
42
28
  "aria-hidden": true,
43
29
  size: "s",
44
30
  "data-testid": dataTestId
45
- }, void 0, label));
31
+ }, label));
32
+ };
33
+ export {
34
+ MoreLessButton
46
35
  };
47
-
48
- export { MoreLessButton };
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
+ }
package/esm/index.d.js CHANGED
@@ -1 +1,2 @@
1
-
1
+ import * as React from "react";
2
+ //# sourceMappingURL=index.d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": "AAAA;",
6
+ "names": []
7
+ }
package/esm/index.js CHANGED
@@ -1 +1,7 @@
1
- export { DSReadMore, DSReadMoreWithSchema, DSReadMore as default } from './DSReadMore.js';
1
+ import * as React from "react";
2
+ export * from "./DSReadMore";
3
+ import { default as default2 } from "./DSReadMore";
4
+ export {
5
+ default2 as default
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-read-more",
3
- "version": "2.2.0-alpha.1",
3
+ "version": "2.2.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Read More",
6
6
  "module": "./esm/index.js",
@@ -40,8 +40,8 @@
40
40
  "build": "node ../../scripts/build/build.js"
41
41
  },
42
42
  "dependencies": {
43
- "@elliemae/ds-button": "2.2.0-alpha.1",
44
- "@elliemae/ds-shared": "2.2.0-alpha.1",
43
+ "@elliemae/ds-button": "2.2.0-alpha.2",
44
+ "@elliemae/ds-shared": "2.2.0-alpha.2",
45
45
  "react-desc": "~4.1.3"
46
46
  },
47
47
  "devDependencies": {