@elliemae/ds-truncated-expandable-text 2.0.0-alpha.10 → 2.0.0-alpha.14
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.
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
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');
|
|
6
12
|
var react = require('react');
|
|
7
13
|
var reactDesc = require('react-desc');
|
|
8
14
|
var styled = require('styled-components');
|
|
@@ -22,10 +28,11 @@ const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
|
|
22
28
|
componentId: "sc-1wjt65j-0"
|
|
23
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');
|
|
24
30
|
|
|
25
|
-
const TruncatedExpandableText =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
const TruncatedExpandableText = _ref => {
|
|
32
|
+
let {
|
|
33
|
+
containerProps,
|
|
34
|
+
value
|
|
35
|
+
} = _ref;
|
|
29
36
|
const [open, setOpen] = react.useState(false);
|
|
30
37
|
const ref = react.useRef(null);
|
|
31
38
|
react.useLayoutEffect(() => {
|
|
@@ -39,7 +46,7 @@ const TruncatedExpandableText = ({
|
|
|
39
46
|
} = element.getBoundingClientRect();
|
|
40
47
|
value.split('').forEach((char, index) => {
|
|
41
48
|
// try the hyphen here
|
|
42
|
-
element.innerText =
|
|
49
|
+
element.innerText = "".concat(newHyphenizedValue, "-").concat(char);
|
|
43
50
|
const {
|
|
44
51
|
height: newHeight
|
|
45
52
|
} = element.getBoundingClientRect(); // if it's the first line or the height didn't change, hyphen doesn't go here,
|
|
@@ -50,20 +57,20 @@ const TruncatedExpandableText = ({
|
|
|
50
57
|
newHyphenizedValue += char;
|
|
51
58
|
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
52
59
|
// end of word
|
|
53
|
-
element.innerText =
|
|
60
|
+
element.innerText = "".concat(newHyphenizedValue).concat(char); // sometimes the last character is wider and doesn't fit
|
|
54
61
|
|
|
55
62
|
const {
|
|
56
63
|
height: endOfWordHeight
|
|
57
64
|
} = element.getBoundingClientRect();
|
|
58
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue +=
|
|
65
|
+
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
59
66
|
} else if (char.match(/\s/)) {
|
|
60
67
|
// we dont want "- ", leave the space character only
|
|
61
68
|
newHyphenizedValue += char;
|
|
62
69
|
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
63
70
|
// we produce and empty space to make sure to start on the next line
|
|
64
|
-
newHyphenizedValue +=
|
|
71
|
+
newHyphenizedValue += " ".concat(char);
|
|
65
72
|
} else {
|
|
66
|
-
newHyphenizedValue +=
|
|
73
|
+
newHyphenizedValue += "-".concat(char);
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
previousHeight = newHeight;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
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';
|
|
2
8
|
import { useState, useRef, useLayoutEffect } from 'react';
|
|
3
9
|
import { describe } from 'react-desc';
|
|
4
10
|
import styled from 'styled-components';
|
|
@@ -13,10 +19,11 @@ const Text = /*#__PURE__*/styled.span.withConfig({
|
|
|
13
19
|
componentId: "sc-1wjt65j-0"
|
|
14
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');
|
|
15
21
|
|
|
16
|
-
const TruncatedExpandableText =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
const TruncatedExpandableText = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
containerProps,
|
|
25
|
+
value
|
|
26
|
+
} = _ref;
|
|
20
27
|
const [open, setOpen] = useState(false);
|
|
21
28
|
const ref = useRef(null);
|
|
22
29
|
useLayoutEffect(() => {
|
|
@@ -30,7 +37,7 @@ const TruncatedExpandableText = ({
|
|
|
30
37
|
} = element.getBoundingClientRect();
|
|
31
38
|
value.split('').forEach((char, index) => {
|
|
32
39
|
// try the hyphen here
|
|
33
|
-
element.innerText =
|
|
40
|
+
element.innerText = "".concat(newHyphenizedValue, "-").concat(char);
|
|
34
41
|
const {
|
|
35
42
|
height: newHeight
|
|
36
43
|
} = element.getBoundingClientRect(); // if it's the first line or the height didn't change, hyphen doesn't go here,
|
|
@@ -41,20 +48,20 @@ const TruncatedExpandableText = ({
|
|
|
41
48
|
newHyphenizedValue += char;
|
|
42
49
|
} else if (index < value.length - 1 && value[index + 1].match(/\s/)) {
|
|
43
50
|
// end of word
|
|
44
|
-
element.innerText =
|
|
51
|
+
element.innerText = "".concat(newHyphenizedValue).concat(char); // sometimes the last character is wider and doesn't fit
|
|
45
52
|
|
|
46
53
|
const {
|
|
47
54
|
height: endOfWordHeight
|
|
48
55
|
} = element.getBoundingClientRect();
|
|
49
|
-
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue +=
|
|
56
|
+
if (endOfWordHeight === previousHeight) newHyphenizedValue += char;else newHyphenizedValue += "-".concat(char);
|
|
50
57
|
} else if (char.match(/\s/)) {
|
|
51
58
|
// we dont want "- ", leave the space character only
|
|
52
59
|
newHyphenizedValue += char;
|
|
53
60
|
} else if (newHyphenizedValue.length && newHyphenizedValue[newHyphenizedValue.length - 1].match(/\s/)) {
|
|
54
61
|
// we produce and empty space to make sure to start on the next line
|
|
55
|
-
newHyphenizedValue +=
|
|
62
|
+
newHyphenizedValue += " ".concat(char);
|
|
56
63
|
} else {
|
|
57
|
-
newHyphenizedValue +=
|
|
64
|
+
newHyphenizedValue += "-".concat(char);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
previousHeight = newHeight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-truncated-expandable-text",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Truncated Expandable Text",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -44,18 +44,19 @@
|
|
|
44
44
|
"build": "node ../../scripts/build/build.js"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"@elliemae/ds-utilities": "2.0.0-alpha.10"
|
|
47
|
+
"react-desc": "~4.1.3"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
50
|
+
"@testing-library/react": "~12.1.2",
|
|
51
|
+
"@testing-library/user-event": "~13.5.0",
|
|
52
|
+
"@types/styled-components": "~5.1.15",
|
|
53
|
+
"styled-components": "~5.3.3"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"lodash": "^4.17.21",
|
|
56
57
|
"react": "^17.0.2",
|
|
57
58
|
"react-dom": "^17.0.2",
|
|
58
|
-
"styled-components": "^5.3.
|
|
59
|
+
"styled-components": "^5.3.3"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
1
2
|
import { HTMLAttributes } from 'react';
|
|
2
3
|
declare const TruncatedExpandableText: {
|
|
3
4
|
({ containerProps, value, }: {
|
|
@@ -5,14 +6,31 @@ declare const TruncatedExpandableText: {
|
|
|
5
6
|
value: string;
|
|
6
7
|
}): JSX.Element;
|
|
7
8
|
propTypes: {
|
|
8
|
-
containerProps:
|
|
9
|
-
|
|
9
|
+
containerProps: {
|
|
10
|
+
defaultValue<T = unknown>(arg: T): {
|
|
11
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
12
|
+
};
|
|
13
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
14
|
+
};
|
|
15
|
+
value: {
|
|
16
|
+
defaultValue<T = unknown>(arg: T): {
|
|
17
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
18
|
+
};
|
|
19
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
20
|
+
};
|
|
10
21
|
};
|
|
11
22
|
defaultProps: {
|
|
12
23
|
containerProps: {};
|
|
13
24
|
value: string;
|
|
14
25
|
};
|
|
15
26
|
};
|
|
16
|
-
declare const DSTruncatedExpandableTextWithSchema:
|
|
27
|
+
declare const DSTruncatedExpandableTextWithSchema: {
|
|
28
|
+
(props?: {
|
|
29
|
+
containerProps: HTMLAttributes<HTMLSpanElement>;
|
|
30
|
+
value: string;
|
|
31
|
+
} | undefined): JSX.Element;
|
|
32
|
+
propTypes: unknown;
|
|
33
|
+
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
34
|
+
};
|
|
17
35
|
export { TruncatedExpandableText, DSTruncatedExpandableTextWithSchema };
|
|
18
36
|
export default TruncatedExpandableText;
|
package/types/props.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
1
2
|
export declare const textProps: {
|
|
2
3
|
/** props injected to wrapper of page header */
|
|
3
|
-
containerProps:
|
|
4
|
+
containerProps: {
|
|
5
|
+
defaultValue<T = unknown>(arg: T): {
|
|
6
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
7
|
+
};
|
|
8
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
9
|
+
};
|
|
4
10
|
/** Text that when truncated will trigger the tooltip interaction */
|
|
5
|
-
value:
|
|
11
|
+
value: {
|
|
12
|
+
defaultValue<T = unknown>(arg: T): {
|
|
13
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
14
|
+
};
|
|
15
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
16
|
+
};
|
|
6
17
|
};
|
package/cjs/package.json
DELETED