react-show-more-text 1.4.2 → 1.4.6

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/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.4.6] - 2020-11-01
5
+ ### Fixed
6
+ - [#20](https://github.com/devzonetech/react-show-more-text/issues/20) Incorrect appearance
7
+ - [#23](https://github.com/devzonetech/react-show-more-text/issues/23) Show more/less anchor breaks in case of hash routers
8
+
9
+ ## [1.4.5] - 2020-10-20
10
+ ### Fixed
11
+ - [#12](https://github.com/devzonetech/react-show-more-text/issues/12) className prop for the wrapper div of component content
12
+
13
+ ## [1.4.4] - 2020-08-21
14
+ ### Fixed
15
+ - [#16](https://github.com/devzonetech/react-show-more-text/issues/16) @ showing at the end of the line
16
+
17
+ ## [1.4.3] - 2020-08-08
18
+ ### Fixed
19
+ - [#18](https://github.com/devzonetech/react-show-more-text/issues/18) Missing links, when the content surrounded by the component contains only one line
20
+ - [#16](https://github.com/devzonetech/react-show-more-text/issues/16) @ showing at the end of the line
21
+
4
22
  ## [1.4.2] - 2020-04-02
5
23
  ### Changed
6
24
  - State update on unmounted component #14
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
  [![NPM version][npm-image]][npm-url]
3
3
  [![Downloads][downloads-image]][npm-url]
4
4
  [![Build status][travis-image]][travis-url]
5
- [![Coverage status][coveralls-image]][coveralls-url]
6
5
  [![Dependency status][david-dm-image]][david-dm-url]
7
- [![Dev dependency status][david-dm-dev-image]][david-dm-dev-url]
8
6
 
9
7
  The text surrounded by the component will be truncated. Anything surrounded by the component could be evaluated as text. The component react-show-more-text/ShowMoreText is fork of react-show-more/ShowMore, applied improvements, works with React 16.x.x, added onClick event.
10
8
 
@@ -35,19 +33,19 @@ class Foo extends Component {
35
33
  lines={3}
36
34
  more='Show more'
37
35
  less='Show less'
38
- anchorClass=''
36
+ className='content-css'
37
+ anchorClass='my-anchor-css-class'
39
38
  onClick={this.executeOnClick}
40
39
  expanded={false}
41
40
  width={280}
42
41
  >
43
- Lorem ipsum dolor sit amet, consectetur <a href="https://www.yahoo.com/" target="_blank">yahoo.com</a> adipiscing elit, sed do eiusmod tempor incididunt
44
- <a href="https://www.google.bg/" title="Google" rel="nofollow" target="_blank">www.google.bg</a> ut labore et dolore magna amet, consectetur adipiscing elit,
42
+ Lorem ipsum dolor sit amet, consectetur <a href="https://www.yahoo.com/" target="_blank" rel="noopener noreferrer">yahoo.com</a> adipiscing elit, sed do eiusmod tempor incididunt
43
+ <a href="https://www.google.bg/" title="Google" rel="nofollow" target="_blank" rel="noopener noreferrer">www.google.bg</a> ut labore et dolore magna amet, consectetur adipiscing elit,
45
44
  sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
46
45
  minim veniam, quis nostrud exercitation ullamco laboris nisi
47
46
  ut aliquip ex Lorem ipsum dolor sit amet, consectetur
48
47
  adipiscing elit, sed do eiusmod tempor incididunt ut labore
49
48
 
50
-
51
49
  et dolore magna aliqua. Ut enim ad minim veniam, quis
52
50
  nostrud exercitation ullamco laboris nisi ut aliquip ex
53
51
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
@@ -66,6 +64,7 @@ class Foo extends Component {
66
64
  | children | string, React node | | The text to be truncated. Anything that can be evaluated as text. | `'Some text'`, `<p>Some paragraph <a/>with other text-based inline elements<a></p>`, `<span>Some</span><span>siblings</span>` |
67
65
  | more | string, React node | 'Show more' | The text to display in the anchor element to show more. | `'Show more'`, `<span>Show more</span>`
68
66
  | less | string, React node | 'Show less' | The text to display in the anchor element to show less. | `'Show less'`, `<span>Show less</span>`
67
+ | className | string | '' | Class name(s) to add on component content wrapper div. | `'wrapper-class'`, `'wrapper-class-1 wrapper-class-2'`
69
68
  | anchorClass | string | '' | Class name(s) to add to the anchor elements. | `'my-anchor-class'`, `'class-1 class-2'`
70
69
  | onClick | Function | | Function executed on click on 'Show more' or 'Show less' | `onClick={this.executeOnClick}`
71
70
  | expanded | boolean | 'false' | Control the text to be shown as expanded | `expanded={true}`
@@ -96,11 +95,9 @@ $ npm run compile
96
95
  [npm-url]: https://npmjs.org/package/react-show-more-text
97
96
  [downloads-image]: http://img.shields.io/npm/dm/react-show-more-text.svg
98
97
  [npm-image]: https://badge.fury.io/js/react-show-more-text.svg
99
- [travis-url]: https://travis-ci.org/One-com/react-show-more-text
100
- [travis-image]: http://img.shields.io/travis/One-com/react-show-more-text.svg
101
- [coveralls-url]:https://coveralls.io/r/One-com/react-show-more-text
102
- [coveralls-image]:https://coveralls.io/repos/One-com/react-show-more-text/badge.svg
103
- [david-dm-url]:https://david-dm.org/One-com/react-show-more-text
104
- [david-dm-image]:https://david-dm.org/One-com/react-show-more-text.svg
105
- [david-dm-dev-url]:https://david-dm.org/One-com/react-show-more-text#info=devDependencies
106
- [david-dm-dev-image]:https://david-dm.org/One-com/react-show-more-text/dev-status.svg
98
+
99
+ [travis-url]: https://travis-ci.com/devzonetech/react-show-more-text
100
+ [travis-image]: https://travis-ci.com/devzonetech/react-show-more-text.svg?branch=master
101
+
102
+ [david-dm-url]:https://david-dm.org/devzonetech/react-show-more-text
103
+ [david-dm-image]:https://david-dm.org/devzonetech/react-show-more-text.svg
@@ -29,7 +29,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
29
29
 
30
30
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
31
 
32
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33
33
 
34
34
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
35
35
 
@@ -119,16 +119,19 @@ var ShowMoreText = /*#__PURE__*/function (_Component) {
119
119
  less = _this$props.less,
120
120
  lines = _this$props.lines,
121
121
  anchorClass = _this$props.anchorClass,
122
+ className = _this$props.className,
122
123
  width = _this$props.width,
123
124
  keepNewLines = _this$props.keepNewLines;
124
125
  var _this$state = this.state,
125
126
  expanded = _this$state.expanded,
126
127
  truncated = _this$state.truncated;
127
- return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_Truncate.default, {
128
+ return /*#__PURE__*/_react.default.createElement("div", {
129
+ className: className
130
+ }, /*#__PURE__*/_react.default.createElement(_Truncate.default, {
128
131
  width: width,
129
132
  lines: !expanded && lines,
130
133
  ellipsis: /*#__PURE__*/_react.default.createElement("span", null, "...", ' ', /*#__PURE__*/_react.default.createElement("a", {
131
- href: "#",
134
+ href: "",
132
135
  className: anchorClass,
133
136
  onClick: this.toggleLines
134
137
  }, more)),
@@ -149,7 +152,7 @@ var ShowMoreText = /*#__PURE__*/function (_Component) {
149
152
  })];
150
153
  }
151
154
  }) : children), !truncated && expanded && /*#__PURE__*/_react.default.createElement("span", null, ' ', /*#__PURE__*/_react.default.createElement("a", {
152
- href: "#",
155
+ href: "",
153
156
  className: anchorClass,
154
157
  onClick: this.toggleLines
155
158
  }, less)));
@@ -176,6 +179,7 @@ _defineProperty(ShowMoreText, "propTypes", {
176
179
  more: _propTypes.PropTypes.node,
177
180
  less: _propTypes.PropTypes.node,
178
181
  anchorClass: _propTypes.PropTypes.string,
182
+ className: _propTypes.PropTypes.string,
179
183
  onClick: _propTypes.PropTypes.func,
180
184
  expanded: _propTypes.PropTypes.bool,
181
185
  width: _propTypes.PropTypes.number,
package/lib/Truncate.js CHANGED
@@ -29,7 +29,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
29
29
 
30
30
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
31
 
32
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33
33
 
34
34
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
35
35
 
@@ -66,7 +66,7 @@ var Truncate = /*#__PURE__*/function (_React$Component) {
66
66
  _this.replacedLinks = [];
67
67
  content.replace(/(<a[\s]+([^>]+)>((?:.(?!\<\/a\>))*.)<\/a>)/g, function () {
68
68
  var item = Array.prototype.slice.call(arguments, 1, 4);
69
- item.key = '@'.repeat(item[2].length - 1) + '=' + i++;
69
+ item.key = '[' + '@'.repeat(item[2].length - 1) + '=' + i++ + ']';
70
70
 
71
71
  _self.replacedLinks.push(item);
72
72
 
@@ -80,8 +80,7 @@ var Truncate = /*#__PURE__*/function (_React$Component) {
80
80
  content = content.replace(item.key, item[0]);
81
81
  });
82
82
 
83
- content = _this.createMarkup(content);
84
- return content;
83
+ return _this.createMarkup(content);
85
84
  });
86
85
 
87
86
  _defineProperty(_assertThisInitialized(_this), "innerText", function (node) {
@@ -206,6 +205,7 @@ var Truncate = /*#__PURE__*/function (_React$Component) {
206
205
  if (textLines.length === 1) {
207
206
  // Line is end of text and fits without truncating
208
207
  didTruncate = false;
208
+ resultLine = restoreReplacedLinks(resultLine);
209
209
  lines.push(resultLine);
210
210
  break;
211
211
  }
@@ -239,6 +239,12 @@ var Truncate = /*#__PURE__*/function (_React$Component) {
239
239
  }
240
240
  }
241
241
 
242
+ if (lastLineText.substr(lastLineText.length - 2) === '][') {
243
+ lastLineText = lastLineText.substring(0, lastLineText.length - 1);
244
+ }
245
+
246
+ ;
247
+ lastLineText = lastLineText.replace(/\[(@)\1{2,}$/, '');
242
248
  lastLineText = restoreReplacedLinks(lastLineText);
243
249
  resultLine = /*#__PURE__*/_react.default.createElement("span", null, lastLineText, ellipsis);
244
250
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-show-more-text",
3
- "version": "1.4.2",
3
+ "version": "1.4.6",
4
4
  "description": "The text surrounded by the component will be truncated. Anything surrounded by the component could be evaluated as text. The component react-show-more-text/ShowMoreText is fork of react-show-more/ShowMore, applied improvements, works with React 16.x.x, added onClick event.",
5
5
  "main": "lib/ShowMoreText.js",
6
6
  "files": [
@@ -14,8 +14,9 @@
14
14
  "prepublish": "rm -rf ./lib && npm run compile",
15
15
  "preversion": "npm run test",
16
16
  "report-coverage": "npm run coverage | coveralls",
17
- "test": "jest --watch",
18
- "travis": "npm run lint && npm run compile && npm run test"
17
+ "test": "./node_modules/.bin/jest",
18
+ "test:watch": "./node_modules/.bin/jest --watch",
19
+ "travis": "npm run compile && npm run test"
19
20
  },
20
21
  "repository": {
21
22
  "type": "git",
@@ -40,32 +41,32 @@
40
41
  "react": ">= 16.x.x"
41
42
  },
42
43
  "devDependencies": {
43
- "@babel/cli": "^7.8.4",
44
- "@babel/core": "^7.9.0",
45
- "@babel/plugin-proposal-class-properties": "^7.8.3",
46
- "@babel/preset-env": "^7.9.5",
47
- "@babel/preset-react": "^7.9.4",
44
+ "@babel/cli": "^7.12.1",
45
+ "@babel/core": "^7.12.3",
46
+ "@babel/plugin-proposal-class-properties": "^7.12.1",
47
+ "@babel/preset-env": "^7.12.1",
48
+ "@babel/preset-react": "^7.12.1",
48
49
  "babel-eslint": "^10.1.0",
49
50
  "babel-preset-minify": "^0.5.1",
50
51
  "canvas": "^2.6.1",
51
52
  "core-js": "^3.6.5",
52
53
  "coveralls": "^3.0.7",
53
54
  "enzyme": "^3.11.0",
54
- "enzyme-adapter-react-16": "^1.15.2",
55
+ "enzyme-adapter-react-16": "^1.15.5",
55
56
  "eslint": "^4.14.0",
56
57
  "eslint-config-onelint": "^3.0.0",
57
58
  "eslint-config-onelint-react": "^2.0.1",
58
- "eslint-plugin-jest": "^23.8.2",
59
- "eslint-plugin-react": "^7.16.0",
59
+ "eslint-plugin-jest": "^23.20.0",
60
+ "eslint-plugin-react": "^7.21.5",
60
61
  "jest": "^25.3.0",
61
62
  "jest-enzyme": "^7.1.2",
62
63
  "nyc": "^14.1.1",
63
64
  "onchange": "^6.1.1",
64
- "react": "^16.11.0",
65
- "react-dom": "^16.11.0"
65
+ "react": "^16.14.0",
66
+ "react-dom": "^16.14.0"
66
67
  },
67
68
  "dependencies": {
68
- "@babel/polyfill": "^7.8.7",
69
+ "@babel/polyfill": "^7.12.1",
69
70
  "prop-types": "^15.7.2"
70
71
  },
71
72
  "browserslist": "> 0.25%, not dead"