@elliemae/ds-truncated-expandable-text 2.2.0-alpha.5 → 2.2.0-next.1

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