@elliemae/ds-read-more 2.0.0-alpha.1 → 2.0.0-alpha.13
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 +32 -24
- package/cjs/MoreLessButton.js +17 -14
- package/cjs/index.js +1 -1
- package/esm/DSReadMore.js +28 -20
- package/esm/MoreLessButton.js +17 -14
- package/package.json +6 -4
- package/types/DSReadMore.d.ts +31 -8
- package/types/MoreLessButton.d.ts +6 -5
- package/cjs/package.json +0 -7
- package/esm/package.json +0 -7
package/cjs/DSReadMore.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _jsx2 = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
7
|
var react = require('react');
|
|
7
8
|
var reactDesc = require('react-desc');
|
|
8
9
|
var styled = require('styled-components');
|
|
@@ -16,32 +17,39 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
17
|
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
17
18
|
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
18
19
|
|
|
19
|
-
const Text = /*#__PURE__*/styled__default[
|
|
20
|
+
const Text = /*#__PURE__*/styled__default["default"].span.withConfig({
|
|
20
21
|
componentId: "sc-1c4w5m6-0"
|
|
21
|
-
})(["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;"],
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
})(["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 => {
|
|
23
|
+
let {
|
|
24
|
+
lines,
|
|
25
|
+
expanded
|
|
26
|
+
} = _ref;
|
|
27
|
+
return expanded ? 'unset' : lines;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const DSReadMore = _ref2 => {
|
|
31
|
+
let {
|
|
32
|
+
lines = 2,
|
|
33
|
+
more = 'more',
|
|
34
|
+
less = 'less',
|
|
35
|
+
onMore = () => null,
|
|
36
|
+
onLess = () => null,
|
|
37
|
+
content,
|
|
38
|
+
buttonType = 'link',
|
|
39
|
+
size = 's',
|
|
40
|
+
ellipsis = '...'
|
|
41
|
+
} = _ref2;
|
|
37
42
|
const ref = react.useRef();
|
|
38
43
|
const [showButton, setShowButton] = react.useState(false);
|
|
39
44
|
const [expanded, setExpanded] = react.useState(false); // offsetHeight + 2 takes into consideration any size of the button
|
|
40
45
|
|
|
41
|
-
const overflows =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
const overflows = _ref3 => {
|
|
47
|
+
let {
|
|
48
|
+
offsetHeight,
|
|
49
|
+
scrollHeight
|
|
50
|
+
} = _ref3;
|
|
51
|
+
return offsetHeight + 2 < scrollHeight;
|
|
52
|
+
}; // Searchs the optimum cut on the text to have the button in the same line
|
|
45
53
|
|
|
46
54
|
|
|
47
55
|
const binSearchTextOverflow = (element, parent) => {
|
|
@@ -83,14 +91,14 @@ const DSReadMore = ({
|
|
|
83
91
|
if (newExpanded) onMore();else onLess();
|
|
84
92
|
};
|
|
85
93
|
|
|
86
|
-
return /*#__PURE__*/_jsx2__default[
|
|
94
|
+
return /*#__PURE__*/_jsx2__default["default"](Text, {
|
|
87
95
|
lines: lines,
|
|
88
96
|
expanded: expanded
|
|
89
97
|
}, void 0, /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
90
98
|
ref: ref,
|
|
91
99
|
"data-testid": "ds-read_more-text",
|
|
92
100
|
children: content
|
|
93
|
-
}), showButton && /*#__PURE__*/_jsx2__default[
|
|
101
|
+
}), showButton && /*#__PURE__*/_jsx2__default["default"]("span", {}, void 0, /*#__PURE__*/_jsx2__default["default"](MoreLessButton.MoreLessButton, {
|
|
94
102
|
expanded: expanded,
|
|
95
103
|
label: expanded ? less : more,
|
|
96
104
|
onClick: () => toggleExpanded(!expanded),
|
|
@@ -135,4 +143,4 @@ DSReadMoreWithSchema.propTypes = DSReadMoreProps;
|
|
|
135
143
|
|
|
136
144
|
exports.DSReadMore = DSReadMore;
|
|
137
145
|
exports.DSReadMoreWithSchema = DSReadMoreWithSchema;
|
|
138
|
-
exports[
|
|
146
|
+
exports["default"] = DSReadMore;
|
package/cjs/MoreLessButton.js
CHANGED
|
@@ -11,19 +11,22 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
var _jsx2__default = /*#__PURE__*/_interopDefaultLegacy(_jsx2);
|
|
12
12
|
var DSButton__default = /*#__PURE__*/_interopDefaultLegacy(DSButton);
|
|
13
13
|
|
|
14
|
-
const MoreLessButton =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
const MoreLessButton = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
expanded,
|
|
17
|
+
label,
|
|
18
|
+
onClick,
|
|
19
|
+
buttonType,
|
|
20
|
+
size,
|
|
21
|
+
ellipsis
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/_jsx2__default["default"]("span", {}, void 0, expanded ? ' ' : ellipsis, /*#__PURE__*/_jsx2__default["default"](DSButton__default["default"], {
|
|
24
|
+
buttonType: buttonType,
|
|
25
|
+
labelText: label,
|
|
26
|
+
onClick: onClick,
|
|
27
|
+
size: size,
|
|
28
|
+
"data-testid": "ds-read_more-button"
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
28
31
|
|
|
29
32
|
exports.MoreLessButton = MoreLessButton;
|
package/cjs/index.js
CHANGED
package/esm/DSReadMore.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _jsx2 from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
2
3
|
import { useRef, useState, useLayoutEffect } from 'react';
|
|
3
4
|
import { PropTypes, describe } from 'react-desc';
|
|
4
5
|
import styled from 'styled-components';
|
|
@@ -9,30 +10,37 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
9
10
|
|
|
10
11
|
const Text = /*#__PURE__*/styled.span.withConfig({
|
|
11
12
|
componentId: "sc-1c4w5m6-0"
|
|
12
|
-
})(["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;"],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
})(["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 => {
|
|
14
|
+
let {
|
|
15
|
+
lines,
|
|
16
|
+
expanded
|
|
17
|
+
} = _ref;
|
|
18
|
+
return expanded ? 'unset' : lines;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const DSReadMore = _ref2 => {
|
|
22
|
+
let {
|
|
23
|
+
lines = 2,
|
|
24
|
+
more = 'more',
|
|
25
|
+
less = 'less',
|
|
26
|
+
onMore = () => null,
|
|
27
|
+
onLess = () => null,
|
|
28
|
+
content,
|
|
29
|
+
buttonType = 'link',
|
|
30
|
+
size = 's',
|
|
31
|
+
ellipsis = '...'
|
|
32
|
+
} = _ref2;
|
|
28
33
|
const ref = useRef();
|
|
29
34
|
const [showButton, setShowButton] = useState(false);
|
|
30
35
|
const [expanded, setExpanded] = useState(false); // offsetHeight + 2 takes into consideration any size of the button
|
|
31
36
|
|
|
32
|
-
const overflows =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const overflows = _ref3 => {
|
|
38
|
+
let {
|
|
39
|
+
offsetHeight,
|
|
40
|
+
scrollHeight
|
|
41
|
+
} = _ref3;
|
|
42
|
+
return offsetHeight + 2 < scrollHeight;
|
|
43
|
+
}; // Searchs the optimum cut on the text to have the button in the same line
|
|
36
44
|
|
|
37
45
|
|
|
38
46
|
const binSearchTextOverflow = (element, parent) => {
|
package/esm/MoreLessButton.js
CHANGED
|
@@ -2,19 +2,22 @@ import _jsx2 from '@babel/runtime/helpers/esm/jsx';
|
|
|
2
2
|
import 'react';
|
|
3
3
|
import DSButton from '@elliemae/ds-button';
|
|
4
4
|
|
|
5
|
-
const MoreLessButton =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
const MoreLessButton = _ref => {
|
|
6
|
+
let {
|
|
7
|
+
expanded,
|
|
8
|
+
label,
|
|
9
|
+
onClick,
|
|
10
|
+
buttonType,
|
|
11
|
+
size,
|
|
12
|
+
ellipsis
|
|
13
|
+
} = _ref;
|
|
14
|
+
return /*#__PURE__*/_jsx2("span", {}, void 0, expanded ? ' ' : ellipsis, /*#__PURE__*/_jsx2(DSButton, {
|
|
15
|
+
buttonType: buttonType,
|
|
16
|
+
labelText: label,
|
|
17
|
+
onClick: onClick,
|
|
18
|
+
size: size,
|
|
19
|
+
"data-testid": "ds-read_more-button"
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
19
22
|
|
|
20
23
|
export { MoreLessButton };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-read-more",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Read More",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -40,16 +40,18 @@
|
|
|
40
40
|
"build": "node ../../scripts/build/build.js"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elliemae/ds-button": "2.0.0-alpha.
|
|
43
|
+
"@elliemae/ds-button": "2.0.0-alpha.13",
|
|
44
|
+
"@elliemae/ds-shared": "2.0.0-alpha.13",
|
|
44
45
|
"react-desc": "~4.1.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
+
"@testing-library/react": "~12.1.2",
|
|
49
|
+
"styled-components": "~5.3.3"
|
|
48
50
|
},
|
|
49
51
|
"peerDependencies": {
|
|
50
52
|
"react": "^17.0.2",
|
|
51
53
|
"react-dom": "^17.0.2",
|
|
52
|
-
"styled-components": "^5.3.
|
|
54
|
+
"styled-components": "^5.3.3"
|
|
53
55
|
},
|
|
54
56
|
"publishConfig": {
|
|
55
57
|
"access": "public",
|
package/types/DSReadMore.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
1
2
|
/// <reference types="react" />
|
|
2
3
|
declare const DSReadMore: {
|
|
3
4
|
({ lines, more, less, onMore, onLess, content, buttonType, size, ellipsis, }: {
|
|
@@ -13,25 +14,47 @@ declare const DSReadMore: {
|
|
|
13
14
|
}): JSX.Element;
|
|
14
15
|
propTypes: {
|
|
15
16
|
/** Ammount of lines after you want to display an ellipsis + more/less button */
|
|
16
|
-
lines:
|
|
17
|
+
lines: {
|
|
18
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
19
|
+
};
|
|
17
20
|
/** Label which will appear on the 'More' button */
|
|
18
|
-
more:
|
|
21
|
+
more: {
|
|
22
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
23
|
+
};
|
|
19
24
|
/** Label which will appear on the 'Less' button */
|
|
20
|
-
less:
|
|
25
|
+
less: {
|
|
26
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
27
|
+
};
|
|
21
28
|
/** Function which will execute when the user click the 'More' button */
|
|
22
|
-
onMore:
|
|
29
|
+
onMore: {
|
|
30
|
+
defaultValue<T = unknown>(arg: T): {
|
|
31
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
32
|
+
};
|
|
33
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
34
|
+
};
|
|
23
35
|
/** Function which will execute when the user click the 'Less' button */
|
|
24
|
-
onLess:
|
|
36
|
+
onLess: {
|
|
37
|
+
defaultValue<T = unknown>(arg: T): {
|
|
38
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
39
|
+
};
|
|
40
|
+
isRequired: import("react-desc").PropTypesDescValidator;
|
|
41
|
+
};
|
|
25
42
|
/** The text content you want displayed */
|
|
26
43
|
content: any;
|
|
27
44
|
/** 'The type of button for more/less button' */
|
|
28
|
-
buttonType:
|
|
45
|
+
buttonType: {
|
|
46
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
47
|
+
};
|
|
29
48
|
/**
|
|
30
49
|
* ['s', 'm', 'l']
|
|
31
50
|
*/
|
|
32
|
-
size:
|
|
51
|
+
size: {
|
|
52
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
53
|
+
};
|
|
33
54
|
/** The text you want to appear when truncating */
|
|
34
|
-
ellipsis:
|
|
55
|
+
ellipsis: {
|
|
56
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
57
|
+
};
|
|
35
58
|
};
|
|
36
59
|
};
|
|
37
60
|
declare const DSReadMoreWithSchema: any;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
1
2
|
/// <reference types="react" />
|
|
2
3
|
declare const MoreLessButton: {
|
|
3
4
|
({ expanded, label, onClick, buttonType, size, ellipsis, }: {
|
|
@@ -10,11 +11,11 @@ declare const MoreLessButton: {
|
|
|
10
11
|
}): JSX.Element;
|
|
11
12
|
propTypes: {
|
|
12
13
|
expanded: any;
|
|
13
|
-
label:
|
|
14
|
-
onClick:
|
|
15
|
-
buttonType:
|
|
16
|
-
size:
|
|
17
|
-
ellipsis:
|
|
14
|
+
label: import("react-desc").PropTypesDescValue;
|
|
15
|
+
onClick: import("react-desc").PropTypesDescValue;
|
|
16
|
+
buttonType: import("react-desc").PropTypesDescValue;
|
|
17
|
+
size: import("react-desc").PropTypesDescValue;
|
|
18
|
+
ellipsis: import("react-desc").PropTypesDescValue;
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
21
|
export { MoreLessButton };
|
package/cjs/package.json
DELETED