@instructure/ui-rating 8.8.1-snapshot.3 → 8.9.0

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
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [8.9.0](https://github.com/instructure/instructure-ui/compare/v8.8.0...v8.9.0) (2021-09-15)
7
+
8
+ ### Bug Fixes
9
+
10
+ - fix shared-types TS errors ([7b83164](https://github.com/instructure/instructure-ui/commit/7b83164f4c5872f3a217e010563f59bf584ae4fc))
11
+
6
12
  # [8.8.0](https://github.com/instructure/instructure-ui/compare/v8.7.0...v8.8.0) (2021-08-27)
7
13
 
8
14
  **Note:** Version bump only for package @instructure/ui-rating
@@ -26,34 +26,38 @@ var _dec, _dec2, _class, _class2, _temp;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component } from 'react';
29
- import PropTypes from 'prop-types';
30
29
  import { View } from '@instructure/ui-view';
31
30
  import { ScreenReaderContent } from '@instructure/ui-a11y-content';
32
31
  import { omitProps } from '@instructure/ui-react-utils';
33
32
  import { testable } from '@instructure/ui-testable';
34
33
  import { RatingIcon } from '../RatingIcon';
35
- import { withStyle, jsx, ThemeablePropTypes } from '@instructure/emotion';
34
+ import { withStyle, jsx } from '@instructure/emotion';
36
35
  import generateStyle from './styles';
37
-
36
+ import { allowedProps, propTypes } from './props';
38
37
  /**
39
38
  ---
40
39
  category: components
41
40
  ---
42
41
  **/
42
+
43
43
  let Rating = (_dec = withStyle(generateStyle), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Rating extends Component {
44
44
  componentDidMount() {
45
- this.props.makeStyles();
45
+ var _this$props$makeStyle, _this$props;
46
+
47
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
46
48
  }
47
49
 
48
- componentDidUpdate(prevProps, prevState, snapshot) {
49
- this.props.makeStyles();
50
+ componentDidUpdate() {
51
+ var _this$props$makeStyle2, _this$props2;
52
+
53
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
50
54
  }
51
55
 
52
56
  get filled() {
53
- const _this$props = this.props,
54
- valueNow = _this$props.valueNow,
55
- iconCount = _this$props.iconCount,
56
- valueMax = _this$props.valueMax; // prevent divide by zero errors
57
+ const _this$props3 = this.props,
58
+ valueNow = _this$props3.valueNow,
59
+ iconCount = _this$props3.iconCount,
60
+ valueMax = _this$props3.valueMax; // prevent divide by zero errors
57
61
 
58
62
  const max = valueMax > 0 ? valueMax : iconCount;
59
63
  const filledIcons = Math.round(valueNow * iconCount / max); // Handle edge case where valueNow is greater than valueMax
@@ -70,17 +74,19 @@ let Rating = (_dec = withStyle(generateStyle), _dec2 = testable(), _dec(_class =
70
74
  }
71
75
 
72
76
  render() {
73
- const _this$props2 = this.props,
74
- iconCount = _this$props2.iconCount,
75
- animateFill = _this$props2.animateFill,
76
- size = _this$props2.size,
77
- margin = _this$props2.margin,
78
- label = _this$props2.label,
79
- formatValueText = _this$props2.formatValueText;
77
+ var _this$props$styles;
78
+
79
+ const _this$props4 = this.props,
80
+ iconCount = _this$props4.iconCount,
81
+ animateFill = _this$props4.animateFill,
82
+ size = _this$props4.size,
83
+ margin = _this$props4.margin,
84
+ label = _this$props4.label,
85
+ formatValueText = _this$props4.formatValueText;
80
86
  const valueText = label + ' ' + formatValueText(this.filled, iconCount);
81
87
  const passthroughProps = View.omitViewProps(omitProps(this.props, Rating.propTypes), Rating);
82
88
  return jsx(View, Object.assign({}, passthroughProps, {
83
- css: this.props.styles.rating,
89
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rating,
84
90
  margin: margin,
85
91
  display: "inline-block"
86
92
  }), jsx(ScreenReaderContent, null, valueText), [...Array(this.filled)].map((x, i) => jsx(RatingIcon, {
@@ -95,60 +101,12 @@ let Rating = (_dec = withStyle(generateStyle), _dec2 = testable(), _dec(_class =
95
101
  })));
96
102
  }
97
103
 
98
- }, _class2.displayName = "Rating", _class2.componentId = 'Rating', _class2.propTypes = {
99
- /**
100
- * A label is required for accessibility
101
- */
102
- label: PropTypes.string.isRequired,
103
-
104
- /**
105
- * A function that returns the current value formatted for screen readers
106
- */
107
- formatValueText: PropTypes.func,
108
-
109
- /**
110
- * Choose from a 0-3 or 0-5 rating system
111
- */
112
- iconCount: PropTypes.oneOf([3, 5]),
113
-
114
- /**
115
- * Choose from different rating icon sizes
116
- */
117
- size: PropTypes.oneOf(['small', 'medium', 'large']),
118
-
119
- /**
120
- * The maximum rating (defaults to iconCount)
121
- */
122
- valueMax: PropTypes.number,
123
-
124
- /**
125
- * The current rating
126
- */
127
- valueNow: PropTypes.number,
128
-
129
- /**
130
- * Set to make the icons animate when they become filled
131
- */
132
- animateFill: PropTypes.bool,
133
-
134
- /**
135
- * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
136
- * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
137
- * familiar CSS-like shorthand. For example: `margin="small auto large"`.
138
- */
139
- margin: ThemeablePropTypes.spacing,
140
- // eslint-disable-next-line react/require-default-props
141
- makeStyles: PropTypes.func,
142
- // eslint-disable-next-line react/require-default-props
143
- styles: PropTypes.object
144
- }, _class2.defaultProps = {
104
+ }, _class2.displayName = "Rating", _class2.componentId = 'Rating', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
145
105
  animateFill: false,
146
106
  formatValueText: (filled, iconCount) => `${filled} / ${iconCount}`,
147
107
  iconCount: 3,
148
108
  size: 'medium',
149
- valueNow: 0,
150
- margin: void 0,
151
- valueMax: void 0
109
+ valueNow: 0
152
110
  }, _class2.Icon = RatingIcon, _temp)) || _class) || _class);
153
111
  export default Rating;
154
112
  export { Rating };
@@ -0,0 +1,70 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import PropTypes from 'prop-types';
25
+ import { ThemeablePropTypes } from '@instructure/emotion';
26
+ const propTypes = {
27
+ /**
28
+ * A label is required for accessibility
29
+ */
30
+ label: PropTypes.string.isRequired,
31
+
32
+ /**
33
+ * A function that returns the current value formatted for screen readers
34
+ */
35
+ formatValueText: PropTypes.func,
36
+
37
+ /**
38
+ * Choose from a 0-3 or 0-5 rating system
39
+ */
40
+ iconCount: PropTypes.oneOf([3, 5]),
41
+
42
+ /**
43
+ * Choose from different rating icon sizes
44
+ */
45
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
46
+
47
+ /**
48
+ * The maximum rating (defaults to iconCount)
49
+ */
50
+ valueMax: PropTypes.number,
51
+
52
+ /**
53
+ * The current rating
54
+ */
55
+ valueNow: PropTypes.number,
56
+
57
+ /**
58
+ * Set to make the icons animate when they become filled
59
+ */
60
+ animateFill: PropTypes.bool,
61
+
62
+ /**
63
+ * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
64
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
65
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
66
+ */
67
+ margin: ThemeablePropTypes.spacing
68
+ };
69
+ const allowedProps = ['label', 'formatValueText', 'iconCount', 'size', 'valueMax', 'valueNow', 'animateFill', 'margin'];
70
+ export { propTypes, allowedProps };
@@ -26,20 +26,20 @@ var _dec, _class, _class2, _temp;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component } from 'react';
29
- import PropTypes from 'prop-types';
30
29
  import { IconStarSolid, IconStarLightSolid } from '@instructure/ui-icons';
31
30
  import { requestAnimationFrame } from '@instructure/ui-dom-utils';
32
31
  import { Transition } from '@instructure/ui-motion';
33
32
  import { withStyle, jsx } from '@instructure/emotion';
34
33
  import generateStyle from './styles';
35
34
  import generateComponentTheme from './theme';
36
-
35
+ import { allowedProps, propTypes } from './props';
37
36
  /**
38
37
  ---
39
38
  parent: Rating
40
39
  id: Rating.Icon
41
40
  ---
42
41
  **/
42
+
43
43
  let RatingIcon = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class RatingIcon extends Component {
44
44
  constructor(props) {
45
45
  super();
@@ -66,19 +66,23 @@ let RatingIcon = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(
66
66
  }
67
67
 
68
68
  componentDidMount() {
69
- this.props.makeStyles(this.makeStyleProps());
69
+ var _this$props$makeStyle, _this$props;
70
+
71
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
70
72
 
71
73
  if (this.props.animateFill) {
72
74
  this._timeouts.push(setTimeout(this.fill, this.props.animationDelay));
73
75
  }
74
76
  }
75
77
 
76
- componentDidUpdate(prevProps, prevState, snapshot) {
78
+ componentDidUpdate(prevProps) {
79
+ var _this$props$makeStyle2, _this$props2;
80
+
77
81
  if (this.props.animateFill && this.props.filled && this.props.filled !== prevProps.filled) {
78
82
  this.fill();
79
83
  }
80
84
 
81
- this.props.makeStyles(this.makeStyleProps());
85
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
82
86
  }
83
87
 
84
88
  componentWillUnmount() {
@@ -88,31 +92,24 @@ let RatingIcon = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(
88
92
  }
89
93
 
90
94
  render() {
95
+ var _this$props$styles, _this$props$styles2, _this$props$styles3;
96
+
91
97
  const animateFill = this.props.animateFill;
92
98
  const Icon = this.state.filled ? IconStarSolid : IconStarLightSolid;
93
99
  return jsx("span", {
94
- css: this.props.styles.ratingIcon
100
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.ratingIcon
95
101
  }, jsx("span", null, this.state.filled && animateFill ? jsx(Transition, {
96
102
  in: true,
97
103
  transitionOnMount: true,
98
104
  type: "scale"
99
105
  }, jsx(Icon, {
100
- css: this.props.styles.icon
106
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.icon
101
107
  })) : jsx(Icon, {
102
- css: this.props.styles.icon
108
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon
103
109
  })));
104
110
  }
105
111
 
106
- }, _class2.displayName = "RatingIcon", _class2.componentId = 'Rating.Icon', _class2.propTypes = {
107
- animationDelay: PropTypes.number,
108
- animateFill: PropTypes.bool,
109
- filled: PropTypes.bool,
110
- size: PropTypes.oneOf(['small', 'medium', 'large']),
111
- // eslint-disable-next-line react/require-default-props
112
- makeStyles: PropTypes.func,
113
- // eslint-disable-next-line react/require-default-props
114
- styles: PropTypes.object
115
- }, _class2.defaultProps = {
112
+ }, _class2.displayName = "RatingIcon", _class2.componentId = 'Rating.Icon', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
116
113
  animationDelay: 200,
117
114
  animateFill: false,
118
115
  filled: false,
@@ -21,16 +21,12 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
-
25
- export type RatingIconProps = {
26
- animationDelay?: number
27
- animateFill?: boolean
28
- filled?: boolean
29
- size?: 'small' | 'medium' | 'large'
30
- makeStyles?: (...args: any[]) => any
31
- styles?: any
32
- }
33
-
34
- export type RatingIconState = {
35
- filled: boolean
36
- }
24
+ import PropTypes from 'prop-types';
25
+ const propTypes = {
26
+ animationDelay: PropTypes.number,
27
+ animateFill: PropTypes.bool,
28
+ filled: PropTypes.bool,
29
+ size: PropTypes.oneOf(['small', 'medium', 'large'])
30
+ };
31
+ const allowedProps = ['animationDelay', 'animateFill', 'filled', 'size'];
32
+ export { propTypes, allowedProps };
@@ -9,8 +9,6 @@ exports.Rating = exports.default = void 0;
9
9
 
10
10
  var _react = require("react");
11
11
 
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
12
  var _View = require("@instructure/ui-view/lib/View");
15
13
 
16
14
  var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
@@ -25,6 +23,8 @@ var _emotion = require("@instructure/emotion");
25
23
 
26
24
  var _styles = _interopRequireDefault(require("./styles"));
27
25
 
26
+ var _props = require("./props");
27
+
28
28
  var _dec, _dec2, _class, _class2, _temp;
29
29
 
30
30
  /**
@@ -34,18 +34,22 @@ category: components
34
34
  **/
35
35
  let Rating = (_dec = (0, _emotion.withStyle)(_styles.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class Rating extends _react.Component {
36
36
  componentDidMount() {
37
- this.props.makeStyles();
37
+ var _this$props$makeStyle, _this$props;
38
+
39
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
38
40
  }
39
41
 
40
- componentDidUpdate(prevProps, prevState, snapshot) {
41
- this.props.makeStyles();
42
+ componentDidUpdate() {
43
+ var _this$props$makeStyle2, _this$props2;
44
+
45
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
42
46
  }
43
47
 
44
48
  get filled() {
45
- const _this$props = this.props,
46
- valueNow = _this$props.valueNow,
47
- iconCount = _this$props.iconCount,
48
- valueMax = _this$props.valueMax; // prevent divide by zero errors
49
+ const _this$props3 = this.props,
50
+ valueNow = _this$props3.valueNow,
51
+ iconCount = _this$props3.iconCount,
52
+ valueMax = _this$props3.valueMax; // prevent divide by zero errors
49
53
 
50
54
  const max = valueMax > 0 ? valueMax : iconCount;
51
55
  const filledIcons = Math.round(valueNow * iconCount / max); // Handle edge case where valueNow is greater than valueMax
@@ -62,19 +66,21 @@ let Rating = (_dec = (0, _emotion.withStyle)(_styles.default), _dec2 = (0, _test
62
66
  }
63
67
 
64
68
  render() {
65
- const _this$props2 = this.props,
66
- iconCount = _this$props2.iconCount,
67
- animateFill = _this$props2.animateFill,
68
- size = _this$props2.size,
69
- margin = _this$props2.margin,
70
- label = _this$props2.label,
71
- formatValueText = _this$props2.formatValueText;
69
+ var _this$props$styles;
70
+
71
+ const _this$props4 = this.props,
72
+ iconCount = _this$props4.iconCount,
73
+ animateFill = _this$props4.animateFill,
74
+ size = _this$props4.size,
75
+ margin = _this$props4.margin,
76
+ label = _this$props4.label,
77
+ formatValueText = _this$props4.formatValueText;
72
78
  const valueText = label + ' ' + formatValueText(this.filled, iconCount);
73
79
 
74
80
  const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Rating.propTypes), Rating);
75
81
 
76
82
  return (0, _emotion.jsx)(_View.View, Object.assign({}, passthroughProps, {
77
- css: this.props.styles.rating,
83
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rating,
78
84
  margin: margin,
79
85
  display: "inline-block"
80
86
  }), (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, valueText), [...Array(this.filled)].map((x, i) => (0, _emotion.jsx)(_RatingIcon.RatingIcon, {
@@ -89,60 +95,12 @@ let Rating = (_dec = (0, _emotion.withStyle)(_styles.default), _dec2 = (0, _test
89
95
  })));
90
96
  }
91
97
 
92
- }, _class2.displayName = "Rating", _class2.componentId = 'Rating', _class2.propTypes = {
93
- /**
94
- * A label is required for accessibility
95
- */
96
- label: _propTypes.default.string.isRequired,
97
-
98
- /**
99
- * A function that returns the current value formatted for screen readers
100
- */
101
- formatValueText: _propTypes.default.func,
102
-
103
- /**
104
- * Choose from a 0-3 or 0-5 rating system
105
- */
106
- iconCount: _propTypes.default.oneOf([3, 5]),
107
-
108
- /**
109
- * Choose from different rating icon sizes
110
- */
111
- size: _propTypes.default.oneOf(['small', 'medium', 'large']),
112
-
113
- /**
114
- * The maximum rating (defaults to iconCount)
115
- */
116
- valueMax: _propTypes.default.number,
117
-
118
- /**
119
- * The current rating
120
- */
121
- valueNow: _propTypes.default.number,
122
-
123
- /**
124
- * Set to make the icons animate when they become filled
125
- */
126
- animateFill: _propTypes.default.bool,
127
-
128
- /**
129
- * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
130
- * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
131
- * familiar CSS-like shorthand. For example: `margin="small auto large"`.
132
- */
133
- margin: _emotion.ThemeablePropTypes.spacing,
134
- // eslint-disable-next-line react/require-default-props
135
- makeStyles: _propTypes.default.func,
136
- // eslint-disable-next-line react/require-default-props
137
- styles: _propTypes.default.object
138
- }, _class2.defaultProps = {
98
+ }, _class2.displayName = "Rating", _class2.componentId = 'Rating', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
139
99
  animateFill: false,
140
100
  formatValueText: (filled, iconCount) => `${filled} / ${iconCount}`,
141
101
  iconCount: 3,
142
102
  size: 'medium',
143
- valueNow: 0,
144
- margin: void 0,
145
- valueMax: void 0
103
+ valueNow: 0
146
104
  }, _class2.Icon = _RatingIcon.RatingIcon, _temp)) || _class) || _class);
147
105
  exports.Rating = Rating;
148
106
  var _default = Rating;