@instructure/ui-rating 8.19.1-snapshot.8 → 8.20.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 +4 -0
- package/es/Rating/RatingLocator.js +2 -1
- package/es/Rating/index.js +6 -5
- package/es/Rating/props.js +0 -33
- package/es/RatingIcon/index.js +2 -1
- package/lib/Rating/RatingLocator.js +1 -0
- package/lib/Rating/index.js +6 -5
- package/lib/Rating/props.js +0 -33
- package/lib/RatingIcon/index.js +2 -1
- package/package.json +16 -17
- package/src/Rating/index.tsx +15 -28
- package/src/Rating/props.ts +27 -27
- package/src/RatingIcon/index.tsx +6 -8
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Rating/index.d.ts +7 -14
- package/types/Rating/index.d.ts.map +1 -1
- package/types/Rating/props.d.ts +27 -1
- package/types/Rating/props.d.ts.map +1 -1
- package/types/RatingIcon/index.d.ts +4 -3
- package/types/RatingIcon/index.d.ts.map +1 -1
- package/LICENSE.md +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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.20.0](https://github.com/instructure/instructure-ui/compare/v8.19.0...v8.20.0) (2022-03-22)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-rating
|
|
9
|
+
|
|
6
10
|
# [8.19.0](https://github.com/instructure/instructure-ui/compare/v8.18.0...v8.19.0) (2022-03-16)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-rating
|
|
@@ -22,5 +22,6 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
import { locator } from '@instructure/ui-test-locator';
|
|
25
|
-
import { Rating } from './index';
|
|
25
|
+
import { Rating } from './index'; // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
26
|
+
|
|
26
27
|
export const RatingLocator = locator(Rating.selector);
|
package/es/Rating/index.js
CHANGED
|
@@ -38,6 +38,7 @@ import { allowedProps, propTypes } from './props';
|
|
|
38
38
|
---
|
|
39
39
|
category: components
|
|
40
40
|
---
|
|
41
|
+
@tsProps
|
|
41
42
|
**/
|
|
42
43
|
|
|
43
44
|
let Rating = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Rating extends Component {
|
|
@@ -68,7 +69,7 @@ let Rating = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec(_c
|
|
|
68
69
|
iconCount = _this$props3.iconCount,
|
|
69
70
|
valueMax = _this$props3.valueMax; // prevent divide by zero errors
|
|
70
71
|
|
|
71
|
-
const max = valueMax > 0 ? valueMax : iconCount;
|
|
72
|
+
const max = !!valueMax && valueMax > 0 ? valueMax : iconCount;
|
|
72
73
|
const filledIcons = Math.round(valueNow * iconCount / max); // Handle edge case where valueNow is greater than valueMax
|
|
73
74
|
|
|
74
75
|
if (filledIcons > iconCount) {
|
|
@@ -92,20 +93,20 @@ let Rating = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec(_c
|
|
|
92
93
|
margin = _this$props4.margin,
|
|
93
94
|
label = _this$props4.label,
|
|
94
95
|
formatValueText = _this$props4.formatValueText;
|
|
95
|
-
const valueText = label + ' ' + formatValueText(this.filled, iconCount);
|
|
96
|
+
const valueText = label + ' ' + (formatValueText === null || formatValueText === void 0 ? void 0 : formatValueText(this.filled, iconCount));
|
|
96
97
|
const passthroughProps = View.omitViewProps(omitProps(this.props, Rating.allowedProps), Rating);
|
|
97
98
|
return jsx(View, Object.assign({}, passthroughProps, {
|
|
98
99
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rating,
|
|
99
100
|
margin: margin,
|
|
100
101
|
display: "inline-block",
|
|
101
102
|
elementRef: this.handleRef
|
|
102
|
-
}), jsx(ScreenReaderContent, null, valueText), [...Array(this.filled)].map((
|
|
103
|
+
}), jsx(ScreenReaderContent, null, valueText), [...Array(this.filled)].map((_x, i) => jsx(RatingIcon, {
|
|
103
104
|
key: i + 1,
|
|
104
105
|
filled: true,
|
|
105
106
|
animateFill: animateFill,
|
|
106
|
-
animationDelay: animateFill ? (i + 1) * 200 :
|
|
107
|
+
animationDelay: animateFill ? (i + 1) * 200 : void 0,
|
|
107
108
|
size: size
|
|
108
|
-
})), [...Array(this.empty)].map((
|
|
109
|
+
})), [...Array(this.empty)].map((_x, i) => jsx(RatingIcon, {
|
|
109
110
|
key: i + 1,
|
|
110
111
|
size: size
|
|
111
112
|
})));
|
package/es/Rating/props.js
CHANGED
|
@@ -24,46 +24,13 @@
|
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
import { ThemeablePropTypes } from '@instructure/emotion';
|
|
26
26
|
const propTypes = {
|
|
27
|
-
/**
|
|
28
|
-
* A label is required for accessibility
|
|
29
|
-
*/
|
|
30
27
|
label: PropTypes.string.isRequired,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A function that returns the current value formatted for screen readers
|
|
34
|
-
*/
|
|
35
28
|
formatValueText: PropTypes.func,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Choose from a 0-3 or 0-5 rating system
|
|
39
|
-
*/
|
|
40
29
|
iconCount: PropTypes.oneOf([3, 5]),
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Choose from different rating icon sizes
|
|
44
|
-
*/
|
|
45
30
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The maximum rating (defaults to iconCount)
|
|
49
|
-
*/
|
|
50
31
|
valueMax: PropTypes.number,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The current rating
|
|
54
|
-
*/
|
|
55
32
|
valueNow: PropTypes.number,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Set to make the icons animate when they become filled
|
|
59
|
-
*/
|
|
60
33
|
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
34
|
margin: ThemeablePropTypes.spacing
|
|
68
35
|
};
|
|
69
36
|
const allowedProps = ['label', 'formatValueText', 'iconCount', 'size', 'valueMax', 'valueNow', 'animateFill', 'margin'];
|
package/es/RatingIcon/index.js
CHANGED
|
@@ -38,11 +38,12 @@ import { allowedProps, propTypes } from './props';
|
|
|
38
38
|
parent: Rating
|
|
39
39
|
id: Rating.Icon
|
|
40
40
|
---
|
|
41
|
+
@tsProps
|
|
41
42
|
**/
|
|
42
43
|
|
|
43
44
|
let RatingIcon = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_temp = _class2 = class RatingIcon extends Component {
|
|
44
45
|
constructor(props) {
|
|
45
|
-
super();
|
|
46
|
+
super(props);
|
|
46
47
|
this.ref = null;
|
|
47
48
|
this._timeouts = [];
|
|
48
49
|
this._animation = void 0;
|
|
@@ -32,5 +32,6 @@ var _index = require("./index");
|
|
|
32
32
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
33
|
* SOFTWARE.
|
|
34
34
|
*/
|
|
35
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
35
36
|
const RatingLocator = (0, _locator.locator)(_index.Rating.selector);
|
|
36
37
|
exports.RatingLocator = RatingLocator;
|
package/lib/Rating/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var _dec, _dec2, _class, _class2, _temp;
|
|
|
31
31
|
---
|
|
32
32
|
category: components
|
|
33
33
|
---
|
|
34
|
+
@tsProps
|
|
34
35
|
**/
|
|
35
36
|
let Rating = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class Rating extends _react.Component {
|
|
36
37
|
constructor() {
|
|
@@ -60,7 +61,7 @@ let Rating = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0,
|
|
|
60
61
|
iconCount = _this$props3.iconCount,
|
|
61
62
|
valueMax = _this$props3.valueMax; // prevent divide by zero errors
|
|
62
63
|
|
|
63
|
-
const max = valueMax > 0 ? valueMax : iconCount;
|
|
64
|
+
const max = !!valueMax && valueMax > 0 ? valueMax : iconCount;
|
|
64
65
|
const filledIcons = Math.round(valueNow * iconCount / max); // Handle edge case where valueNow is greater than valueMax
|
|
65
66
|
|
|
66
67
|
if (filledIcons > iconCount) {
|
|
@@ -84,7 +85,7 @@ let Rating = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0,
|
|
|
84
85
|
margin = _this$props4.margin,
|
|
85
86
|
label = _this$props4.label,
|
|
86
87
|
formatValueText = _this$props4.formatValueText;
|
|
87
|
-
const valueText = label + ' ' + formatValueText(this.filled, iconCount);
|
|
88
|
+
const valueText = label + ' ' + (formatValueText === null || formatValueText === void 0 ? void 0 : formatValueText(this.filled, iconCount));
|
|
88
89
|
|
|
89
90
|
const passthroughProps = _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Rating.allowedProps), Rating);
|
|
90
91
|
|
|
@@ -93,13 +94,13 @@ let Rating = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0,
|
|
|
93
94
|
margin: margin,
|
|
94
95
|
display: "inline-block",
|
|
95
96
|
elementRef: this.handleRef
|
|
96
|
-
}), (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, valueText), [...Array(this.filled)].map((
|
|
97
|
+
}), (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, valueText), [...Array(this.filled)].map((_x, i) => (0, _emotion.jsx)(_RatingIcon.RatingIcon, {
|
|
97
98
|
key: i + 1,
|
|
98
99
|
filled: true,
|
|
99
100
|
animateFill: animateFill,
|
|
100
|
-
animationDelay: animateFill ? (i + 1) * 200 :
|
|
101
|
+
animationDelay: animateFill ? (i + 1) * 200 : void 0,
|
|
101
102
|
size: size
|
|
102
|
-
})), [...Array(this.empty)].map((
|
|
103
|
+
})), [...Array(this.empty)].map((_x, i) => (0, _emotion.jsx)(_RatingIcon.RatingIcon, {
|
|
103
104
|
key: i + 1,
|
|
104
105
|
size: size
|
|
105
106
|
})));
|
package/lib/Rating/props.js
CHANGED
|
@@ -35,46 +35,13 @@ var _emotion = require("@instructure/emotion");
|
|
|
35
35
|
* SOFTWARE.
|
|
36
36
|
*/
|
|
37
37
|
const propTypes = {
|
|
38
|
-
/**
|
|
39
|
-
* A label is required for accessibility
|
|
40
|
-
*/
|
|
41
38
|
label: _propTypes.default.string.isRequired,
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A function that returns the current value formatted for screen readers
|
|
45
|
-
*/
|
|
46
39
|
formatValueText: _propTypes.default.func,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Choose from a 0-3 or 0-5 rating system
|
|
50
|
-
*/
|
|
51
40
|
iconCount: _propTypes.default.oneOf([3, 5]),
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Choose from different rating icon sizes
|
|
55
|
-
*/
|
|
56
41
|
size: _propTypes.default.oneOf(['small', 'medium', 'large']),
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* The maximum rating (defaults to iconCount)
|
|
60
|
-
*/
|
|
61
42
|
valueMax: _propTypes.default.number,
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The current rating
|
|
65
|
-
*/
|
|
66
43
|
valueNow: _propTypes.default.number,
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Set to make the icons animate when they become filled
|
|
70
|
-
*/
|
|
71
44
|
animateFill: _propTypes.default.bool,
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
75
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
76
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
77
|
-
*/
|
|
78
45
|
margin: _emotion.ThemeablePropTypes.spacing
|
|
79
46
|
};
|
|
80
47
|
exports.propTypes = propTypes;
|
package/lib/RatingIcon/index.js
CHANGED
|
@@ -32,10 +32,11 @@ var _dec, _class, _class2, _temp;
|
|
|
32
32
|
parent: Rating
|
|
33
33
|
id: Rating.Icon
|
|
34
34
|
---
|
|
35
|
+
@tsProps
|
|
35
36
|
**/
|
|
36
37
|
let RatingIcon = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_temp = _class2 = class RatingIcon extends _react.Component {
|
|
37
38
|
constructor(props) {
|
|
38
|
-
super();
|
|
39
|
+
super(props);
|
|
39
40
|
this.ref = null;
|
|
40
41
|
this._timeouts = [];
|
|
41
42
|
this._animation = void 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-rating",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.20.0",
|
|
4
4
|
"description": "A static rating component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,23 +24,23 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.13.10",
|
|
27
|
-
"@instructure/console": "8.
|
|
28
|
-
"@instructure/emotion": "8.
|
|
29
|
-
"@instructure/shared-types": "8.
|
|
30
|
-
"@instructure/ui-a11y-content": "8.
|
|
31
|
-
"@instructure/ui-dom-utils": "8.
|
|
32
|
-
"@instructure/ui-icons": "8.
|
|
33
|
-
"@instructure/ui-motion": "8.
|
|
34
|
-
"@instructure/ui-react-utils": "8.
|
|
35
|
-
"@instructure/ui-testable": "8.
|
|
36
|
-
"@instructure/ui-view": "8.
|
|
27
|
+
"@instructure/console": "8.20.0",
|
|
28
|
+
"@instructure/emotion": "8.20.0",
|
|
29
|
+
"@instructure/shared-types": "8.20.0",
|
|
30
|
+
"@instructure/ui-a11y-content": "8.20.0",
|
|
31
|
+
"@instructure/ui-dom-utils": "8.20.0",
|
|
32
|
+
"@instructure/ui-icons": "8.20.0",
|
|
33
|
+
"@instructure/ui-motion": "8.20.0",
|
|
34
|
+
"@instructure/ui-react-utils": "8.20.0",
|
|
35
|
+
"@instructure/ui-testable": "8.20.0",
|
|
36
|
+
"@instructure/ui-view": "8.20.0",
|
|
37
37
|
"prop-types": "^15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@instructure/ui-babel-preset": "8.
|
|
41
|
-
"@instructure/ui-test-locator": "8.
|
|
42
|
-
"@instructure/ui-test-utils": "8.
|
|
43
|
-
"@instructure/ui-themes": "8.
|
|
40
|
+
"@instructure/ui-babel-preset": "8.20.0",
|
|
41
|
+
"@instructure/ui-test-locator": "8.20.0",
|
|
42
|
+
"@instructure/ui-test-utils": "8.20.0",
|
|
43
|
+
"@instructure/ui-themes": "8.20.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=16.8 <=17"
|
|
@@ -48,6 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"sideEffects": false
|
|
52
|
-
"gitHead": "8648faa3b9f006a729a4d13195dd9c28e23d1335"
|
|
51
|
+
"sideEffects": false
|
|
53
52
|
}
|
package/src/Rating/index.tsx
CHANGED
|
@@ -39,6 +39,7 @@ import { allowedProps, propTypes } from './props'
|
|
|
39
39
|
---
|
|
40
40
|
category: components
|
|
41
41
|
---
|
|
42
|
+
@tsProps
|
|
42
43
|
**/
|
|
43
44
|
@withStyle(generateStyle, null)
|
|
44
45
|
@testable()
|
|
@@ -50,8 +51,8 @@ class Rating extends Component<RatingProps> {
|
|
|
50
51
|
|
|
51
52
|
static defaultProps = {
|
|
52
53
|
animateFill: false,
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
formatValueText: (filled: number, iconCount: number) =>
|
|
55
|
+
`${filled} / ${iconCount}`,
|
|
55
56
|
iconCount: 3,
|
|
56
57
|
size: 'medium',
|
|
57
58
|
valueNow: 0
|
|
@@ -77,38 +78,27 @@ class Rating extends Component<RatingProps> {
|
|
|
77
78
|
const { valueNow, iconCount, valueMax } = this.props
|
|
78
79
|
|
|
79
80
|
// prevent divide by zero errors
|
|
80
|
-
|
|
81
|
-
const max = valueMax > 0 ? valueMax : iconCount
|
|
81
|
+
const max = !!valueMax && valueMax > 0 ? valueMax : iconCount!
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
const filledIcons = Math.round((valueNow * iconCount) / max)
|
|
83
|
+
const filledIcons = Math.round((valueNow! * iconCount!) / max)
|
|
85
84
|
|
|
86
85
|
// Handle edge case where valueNow is greater than valueMax
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return iconCount
|
|
86
|
+
if (filledIcons > iconCount!) {
|
|
87
|
+
return iconCount!
|
|
90
88
|
} else {
|
|
91
89
|
return filledIcons
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
get empty() {
|
|
96
|
-
|
|
97
|
-
return this.props.iconCount - this.filled
|
|
94
|
+
return this.props.iconCount! - this.filled!
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
render() {
|
|
101
|
-
const {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
margin,
|
|
106
|
-
label,
|
|
107
|
-
formatValueText
|
|
108
|
-
} = this.props
|
|
109
|
-
|
|
110
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
|
111
|
-
const valueText = label + ' ' + formatValueText(this.filled, iconCount)
|
|
98
|
+
const { iconCount, animateFill, size, margin, label, formatValueText } =
|
|
99
|
+
this.props
|
|
100
|
+
|
|
101
|
+
const valueText = label + ' ' + formatValueText?.(this.filled, iconCount!)
|
|
112
102
|
|
|
113
103
|
const passthroughProps = View.omitViewProps(
|
|
114
104
|
omitProps(this.props, Rating.allowedProps),
|
|
@@ -124,19 +114,16 @@ class Rating extends Component<RatingProps> {
|
|
|
124
114
|
elementRef={this.handleRef}
|
|
125
115
|
>
|
|
126
116
|
<ScreenReaderContent>{valueText}</ScreenReaderContent>
|
|
127
|
-
{
|
|
128
|
-
{[...Array(this.filled)].map((x, i) => (
|
|
117
|
+
{[...Array(this.filled)].map((_x, i) => (
|
|
129
118
|
<RatingIcon
|
|
130
119
|
key={i + 1}
|
|
131
120
|
filled
|
|
132
121
|
animateFill={animateFill}
|
|
133
|
-
|
|
134
|
-
animationDelay={animateFill ? (i + 1) * 200 : null}
|
|
122
|
+
animationDelay={animateFill ? (i + 1) * 200 : undefined}
|
|
135
123
|
size={size}
|
|
136
124
|
/>
|
|
137
125
|
))}
|
|
138
|
-
{
|
|
139
|
-
{[...Array(this.empty)].map((x, i) => (
|
|
126
|
+
{[...Array(this.empty)].map((_x, i) => (
|
|
140
127
|
<RatingIcon key={i + 1} size={size} />
|
|
141
128
|
))}
|
|
142
129
|
</View>
|
package/src/Rating/props.ts
CHANGED
|
@@ -36,13 +36,39 @@ import type {
|
|
|
36
36
|
} from '@instructure/shared-types'
|
|
37
37
|
|
|
38
38
|
type RatingOwnProps = {
|
|
39
|
+
/**
|
|
40
|
+
* A label is required for accessibility
|
|
41
|
+
*/
|
|
39
42
|
label: string
|
|
40
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A function that returns the current value formatted for screen readers
|
|
45
|
+
*/
|
|
46
|
+
formatValueText?: (filled: number, iconCount: number) => string
|
|
47
|
+
/**
|
|
48
|
+
* Choose from a 0-3 or 0-5 rating system
|
|
49
|
+
*/
|
|
41
50
|
iconCount?: 3 | 5
|
|
51
|
+
/**
|
|
52
|
+
* Choose from different rating icon sizes
|
|
53
|
+
*/
|
|
42
54
|
size?: 'small' | 'medium' | 'large'
|
|
55
|
+
/**
|
|
56
|
+
* The maximum rating (defaults to iconCount)
|
|
57
|
+
*/
|
|
43
58
|
valueMax?: number
|
|
59
|
+
/**
|
|
60
|
+
* The current rating
|
|
61
|
+
*/
|
|
44
62
|
valueNow?: number
|
|
63
|
+
/**
|
|
64
|
+
* Set to make the icons animate when they become filled
|
|
65
|
+
*/
|
|
45
66
|
animateFill?: boolean
|
|
67
|
+
/**
|
|
68
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
69
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
70
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
71
|
+
*/
|
|
46
72
|
margin?: Spacing
|
|
47
73
|
}
|
|
48
74
|
|
|
@@ -57,39 +83,13 @@ type RatingProps = RatingOwnProps &
|
|
|
57
83
|
type RatingStyle = ComponentStyle<'rating'>
|
|
58
84
|
|
|
59
85
|
const propTypes: PropValidators<PropKeys> = {
|
|
60
|
-
/**
|
|
61
|
-
* A label is required for accessibility
|
|
62
|
-
*/
|
|
63
86
|
label: PropTypes.string.isRequired,
|
|
64
|
-
/**
|
|
65
|
-
* A function that returns the current value formatted for screen readers
|
|
66
|
-
*/
|
|
67
87
|
formatValueText: PropTypes.func,
|
|
68
|
-
/**
|
|
69
|
-
* Choose from a 0-3 or 0-5 rating system
|
|
70
|
-
*/
|
|
71
88
|
iconCount: PropTypes.oneOf([3, 5]),
|
|
72
|
-
/**
|
|
73
|
-
* Choose from different rating icon sizes
|
|
74
|
-
*/
|
|
75
89
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
76
|
-
/**
|
|
77
|
-
* The maximum rating (defaults to iconCount)
|
|
78
|
-
*/
|
|
79
90
|
valueMax: PropTypes.number,
|
|
80
|
-
/**
|
|
81
|
-
* The current rating
|
|
82
|
-
*/
|
|
83
91
|
valueNow: PropTypes.number,
|
|
84
|
-
/**
|
|
85
|
-
* Set to make the icons animate when they become filled
|
|
86
|
-
*/
|
|
87
92
|
animateFill: PropTypes.bool,
|
|
88
|
-
/**
|
|
89
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
90
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
91
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
92
|
-
*/
|
|
93
93
|
margin: ThemeablePropTypes.spacing
|
|
94
94
|
}
|
|
95
95
|
|
package/src/RatingIcon/index.tsx
CHANGED
|
@@ -41,6 +41,7 @@ import { allowedProps, propTypes } from './props'
|
|
|
41
41
|
parent: Rating
|
|
42
42
|
id: Rating.Icon
|
|
43
43
|
---
|
|
44
|
+
@tsProps
|
|
44
45
|
**/
|
|
45
46
|
@withStyle(generateStyle, generateComponentTheme)
|
|
46
47
|
class RatingIcon extends Component<RatingIconProps, RatingIconState> {
|
|
@@ -56,25 +57,22 @@ class RatingIcon extends Component<RatingIconProps, RatingIconState> {
|
|
|
56
57
|
size: 'medium'
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
ref:
|
|
60
|
+
ref: HTMLSpanElement | null = null
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1-2 arguments, but got 0.
|
|
64
|
-
super()
|
|
62
|
+
constructor(props: RatingIconProps) {
|
|
63
|
+
super(props)
|
|
65
64
|
|
|
66
65
|
this.state = {
|
|
67
|
-
filled: props.filled && !props.animateFill
|
|
66
|
+
filled: props.filled! && !props.animateFill
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
_timeouts = []
|
|
70
|
+
_timeouts: ReturnType<typeof setTimeout>[] = []
|
|
72
71
|
_animation: RequestAnimationFrameType | undefined
|
|
73
72
|
|
|
74
73
|
componentDidMount() {
|
|
75
74
|
this.props.makeStyles?.(this.makeStyleProps())
|
|
76
75
|
if (this.props.animateFill) {
|
|
77
|
-
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Timeout' is not assignable to pa... Remove this comment to see the full error message
|
|
78
76
|
this._timeouts.push(setTimeout(this.fill, this.props.animationDelay))
|
|
79
77
|
}
|
|
80
78
|
}
|