react-awesome-stars-rating 0.13.2 → 0.13.4

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/dist/gradient.js CHANGED
@@ -4,27 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  var Gradient = function Gradient(_ref) {
15
11
  var primaryColor = _ref.primaryColor,
16
- secondaryColor = _ref.secondaryColor,
17
- offset = _ref.offset,
18
- index = _ref.index,
19
- value = _ref.value,
20
- fullId = _ref.fullId,
21
- halfId = _ref.halfId,
22
- noneId = _ref.noneId;
23
-
12
+ secondaryColor = _ref.secondaryColor,
13
+ offset = _ref.offset,
14
+ index = _ref.index,
15
+ value = _ref.value,
16
+ fullId = _ref.fullId,
17
+ halfId = _ref.halfId,
18
+ noneId = _ref.noneId;
24
19
  if (index === 1) {
25
20
  offset = value % 1 * 100;
26
21
  }
27
-
28
22
  return index === 1 && /*#__PURE__*/_react.default.createElement("defs", {
29
23
  "data-testid": "gradient",
30
24
  "data-offset": offset
@@ -48,7 +42,6 @@ var Gradient = function Gradient(_ref) {
48
42
  stopColor: secondaryColor
49
43
  })));
50
44
  };
51
-
52
45
  Gradient.propTypes = {
53
46
  primaryColor: _propTypes.default.string.isRequired,
54
47
  secondaryColor: _propTypes.default.string.isRequired,
package/dist/index.js CHANGED
@@ -1,64 +1,39 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _react = _interopRequireWildcard(require("react"));
11
-
12
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
10
  var _star = _interopRequireDefault(require("./star"));
15
-
16
11
  var _styles = _interopRequireDefault(require("./styles"));
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
15
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
25
-
26
16
  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; }
27
-
28
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; }
29
-
30
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
-
18
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
32
19
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
-
34
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
35
-
20
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
36
21
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
-
22
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
23
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
38
24
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
39
-
40
25
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
-
42
26
  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); }; }
43
-
44
27
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
45
-
46
28
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
47
-
48
29
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
49
-
50
30
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
51
-
52
31
  var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
53
32
  _inherits(ReactStarsRating, _PureComponent);
54
-
55
33
  var _super = _createSuper(ReactStarsRating);
56
-
57
34
  function ReactStarsRating(props) {
58
35
  var _this;
59
-
60
36
  _classCallCheck(this, ReactStarsRating);
61
-
62
37
  _this = _super.call(this, props);
63
38
  _this.state = {
64
39
  value: props.value,
@@ -71,7 +46,6 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
71
46
  _this.onBlur = _this.onBlur.bind(_assertThisInitialized(_this));
72
47
  return _this;
73
48
  }
74
-
75
49
  _createClass(ReactStarsRating, [{
76
50
  key: "componentDidUpdate",
77
51
  value: function componentDidUpdate(prevProps) {
@@ -93,15 +67,12 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
93
67
  value: function onMouseMove(event) {
94
68
  var isHalf = this.props.isHalf;
95
69
  var value = Number(event.target.getAttribute('data-stars'));
96
-
97
70
  if (isHalf) {
98
71
  var isMoreThanHalf = this.isMoreThanHalf(event);
99
-
100
72
  if (!isMoreThanHalf) {
101
73
  value -= 0.5;
102
74
  }
103
75
  }
104
-
105
76
  this.setState({
106
77
  value: value
107
78
  });
@@ -128,18 +99,15 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
128
99
  key: "onChange",
129
100
  value: function onChange(event) {
130
101
  var _this$props = this.props,
131
- onChange = _this$props.onChange,
132
- isHalf = _this$props.isHalf;
102
+ onChange = _this$props.onChange,
103
+ isHalf = _this$props.isHalf;
133
104
  var value = Number(event.target.getAttribute('data-stars'));
134
-
135
105
  if (isHalf) {
136
106
  var isMoreThanHalf = this.isMoreThanHalf(event);
137
-
138
107
  if (!isMoreThanHalf) {
139
108
  value -= 0.5;
140
109
  }
141
110
  }
142
-
143
111
  onChange(value);
144
112
  }
145
113
  }, {
@@ -147,20 +115,16 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
147
115
  value: function onChangeStars(newValue) {
148
116
  var value = this.state.value;
149
117
  var count = this.props.count;
150
-
151
118
  if (value > 0 || value < count) {
152
119
  var _this$props2 = this.props,
153
- isArrowSubmit = _this$props2.isArrowSubmit,
154
- onChange = _this$props2.onChange;
155
-
120
+ isArrowSubmit = _this$props2.isArrowSubmit,
121
+ onChange = _this$props2.onChange;
156
122
  if (value > 0 && newValue < 0 || value < count && newValue > 0) {
157
123
  value = (value % 1 === 0.5 ? value : Math.round(value)) + newValue;
158
124
  }
159
-
160
125
  this.setState({
161
126
  value: value
162
127
  });
163
-
164
128
  if (isArrowSubmit) {
165
129
  onChange(value);
166
130
  }
@@ -172,22 +136,18 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
172
136
  var keyCode = event.keyCode;
173
137
  var value = this.state.value;
174
138
  var _this$props3 = this.props,
175
- isHalf = _this$props3.isHalf,
176
- onChange = _this$props3.onChange;
177
-
139
+ isHalf = _this$props3.isHalf,
140
+ onChange = _this$props3.onChange;
178
141
  switch (keyCode) {
179
142
  case 37:
180
143
  this.onChangeStars(isHalf ? -0.5 : -1);
181
144
  break;
182
-
183
145
  case 39:
184
146
  this.onChangeStars(isHalf ? 0.5 : 1);
185
147
  break;
186
-
187
148
  case 13:
188
149
  onChange(value);
189
150
  break;
190
-
191
151
  default:
192
152
  break;
193
153
  }
@@ -196,14 +156,14 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
196
156
  key: "renderStars",
197
157
  value: function renderStars() {
198
158
  var _this$props4 = this.props,
199
- count = _this$props4.count,
200
- size = _this$props4.size,
201
- isHalf = _this$props4.isHalf,
202
- isEdit = _this$props4.isEdit,
203
- primaryColor = _this$props4.primaryColor,
204
- secondaryColor = _this$props4.secondaryColor,
205
- starGap = _this$props4.starGap,
206
- id = _this$props4.id;
159
+ count = _this$props4.count,
160
+ size = _this$props4.size,
161
+ isHalf = _this$props4.isHalf,
162
+ isEdit = _this$props4.isEdit,
163
+ primaryColor = _this$props4.primaryColor,
164
+ secondaryColor = _this$props4.secondaryColor,
165
+ starGap = _this$props4.starGap,
166
+ id = _this$props4.id;
207
167
  var value = this.state.value;
208
168
  var starsList = [];
209
169
  var props = {
@@ -213,7 +173,6 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
213
173
  var fullId = "fullId-".concat(id);
214
174
  var halfId = "halfId-".concat(id);
215
175
  var noneId = "noneId-".concat(id);
216
-
217
176
  if (isEdit) {
218
177
  props = _objectSpread(_objectSpread({}, props), {}, {
219
178
  onMouseMove: this.onMouseMove,
@@ -221,7 +180,6 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
221
180
  onChange: this.onChange
222
181
  });
223
182
  }
224
-
225
183
  for (var i = 1; i <= count; i++) {
226
184
  var style = i !== count ? {
227
185
  paddingRight: starGap
@@ -241,23 +199,21 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
241
199
  noneId: noneId
242
200
  }, props))));
243
201
  }
244
-
245
202
  return starsList;
246
203
  }
247
204
  }, {
248
205
  key: "render",
249
206
  value: function render() {
250
207
  var _this$props5 = this.props,
251
- isEdit = _this$props5.isEdit,
252
- className = _this$props5.className,
253
- isArrowSubmit = _this$props5.isArrowSubmit,
254
- id = _this$props5.id;
208
+ isEdit = _this$props5.isEdit,
209
+ className = _this$props5.className,
210
+ isArrowSubmit = _this$props5.isArrowSubmit,
211
+ id = _this$props5.id;
255
212
  var stars = this.renderStars();
256
213
  var props = {
257
214
  tabIndex: -1
258
215
  };
259
216
  var isSubmitted = this.state.isSubmitted;
260
-
261
217
  if ((isEdit || isArrowSubmit) && !isSubmitted) {
262
218
  props = {
263
219
  onKeyDown: this.onKeyDown,
@@ -265,7 +221,6 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
265
221
  tabIndex: 0
266
222
  };
267
223
  }
268
-
269
224
  return /*#__PURE__*/_react.default.createElement("span", _extends({
270
225
  id: id,
271
226
  role: "button"
@@ -278,10 +233,8 @@ var ReactStarsRating = /*#__PURE__*/function (_PureComponent) {
278
233
  }), stars);
279
234
  }
280
235
  }]);
281
-
282
236
  return ReactStarsRating;
283
237
  }(_react.PureComponent);
284
-
285
238
  ReactStarsRating.propTypes = {
286
239
  onChange: _propTypes.default.func.isRequired,
287
240
  count: _propTypes.default.number.isRequired,
package/dist/star.js CHANGED
@@ -4,32 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _gradient = _interopRequireDefault(require("./gradient"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  var StarSVG = function StarSVG(_ref) {
17
12
  var viewBox = _ref.viewBox,
18
- size = _ref.size,
19
- onMouseMove = _ref.onMouseMove,
20
- onMouseLeave = _ref.onMouseLeave,
21
- onChange = _ref.onChange,
22
- index = _ref.index,
23
- value = _ref.value,
24
- isHalf = _ref.isHalf,
25
- primaryColor = _ref.primaryColor,
26
- secondaryColor = _ref.secondaryColor,
27
- fill = _ref.fill,
28
- offset = _ref.offset,
29
- fullId = _ref.fullId,
30
- halfId = _ref.halfId,
31
- noneId = _ref.noneId;
32
-
13
+ size = _ref.size,
14
+ onMouseMove = _ref.onMouseMove,
15
+ onMouseLeave = _ref.onMouseLeave,
16
+ onChange = _ref.onChange,
17
+ index = _ref.index,
18
+ value = _ref.value,
19
+ isHalf = _ref.isHalf,
20
+ primaryColor = _ref.primaryColor,
21
+ secondaryColor = _ref.secondaryColor,
22
+ fill = _ref.fill,
23
+ offset = _ref.offset,
24
+ fullId = _ref.fullId,
25
+ halfId = _ref.halfId,
26
+ noneId = _ref.noneId;
33
27
  if (index <= value) {
34
28
  fill = "url(#".concat(fullId, ")");
35
29
  } else if (isHalf && Math.ceil(value) === index) {
@@ -37,7 +31,6 @@ var StarSVG = function StarSVG(_ref) {
37
31
  } else {
38
32
  fill = "url(#".concat(noneId, ")");
39
33
  }
40
-
41
34
  var props = {
42
35
  primaryColor: primaryColor,
43
36
  secondaryColor: secondaryColor,
@@ -63,7 +56,6 @@ var StarSVG = function StarSVG(_ref) {
63
56
  pointerEvents: "none"
64
57
  }));
65
58
  };
66
-
67
59
  StarSVG.propTypes = {
68
60
  viewBox: _propTypes.default.string,
69
61
  size: _propTypes.default.number.isRequired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-awesome-stars-rating",
3
- "version": "0.13.2",
3
+ "version": "0.13.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "files": [
@@ -73,16 +73,16 @@
73
73
  "react-dom": "^17.0.2"
74
74
  },
75
75
  "devDependencies": {
76
- "@babel/cli": "^7.19.3",
76
+ "@babel/cli": "^7.20.7",
77
77
  "@testing-library/jest-dom": "^5.16.5",
78
78
  "@testing-library/react": "^12.1.5",
79
79
  "@testing-library/user-event": "^14.4.3",
80
- "eslint-config-prettier": "^8.4.0",
80
+ "eslint-config-prettier": "^8.6.0",
81
81
  "eslint-plugin-prettier": "^4.2.1",
82
- "prettier": "^2.8.1",
82
+ "prettier": "^2.8.3",
83
83
  "react-redux": "^7.2.9",
84
84
  "react-scripts": "5.0.1",
85
- "redux": "^4.2.0",
85
+ "redux": "^4.2.1",
86
86
  "redux-form": "^8.3.9"
87
87
  }
88
88
  }