@instructure/ui-rating 11.7.2-snapshot-18 → 11.7.2-snapshot-20

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/es/Rating/v2/index.js +114 -0
  3. package/es/Rating/v2/props.js +26 -0
  4. package/es/Rating/v2/styles.js +43 -0
  5. package/es/RatingIcon/v2/index.js +124 -0
  6. package/es/RatingIcon/v2/props.js +26 -0
  7. package/es/RatingIcon/v2/styles.js +59 -0
  8. package/es/exports/b.js +25 -0
  9. package/lib/Rating/v2/index.js +119 -0
  10. package/lib/Rating/v2/props.js +31 -0
  11. package/lib/Rating/v2/styles.js +49 -0
  12. package/lib/RatingIcon/v2/index.js +129 -0
  13. package/lib/RatingIcon/v2/props.js +31 -0
  14. package/lib/RatingIcon/v2/styles.js +65 -0
  15. package/lib/exports/b.js +19 -0
  16. package/package.json +23 -23
  17. package/src/Rating/v2/README.md +104 -0
  18. package/src/Rating/v2/index.tsx +131 -0
  19. package/src/Rating/v2/props.ts +90 -0
  20. package/src/Rating/v2/styles.ts +46 -0
  21. package/src/RatingIcon/v2/index.tsx +140 -0
  22. package/src/RatingIcon/v2/props.ts +55 -0
  23. package/src/RatingIcon/v2/styles.ts +71 -0
  24. package/src/exports/b.ts +28 -0
  25. package/tsconfig.build.tsbuildinfo +1 -1
  26. package/types/Rating/v2/index.d.ts +39 -0
  27. package/types/Rating/v2/index.d.ts.map +1 -0
  28. package/types/Rating/v2/props.d.ts +46 -0
  29. package/types/Rating/v2/props.d.ts.map +1 -0
  30. package/types/Rating/v2/styles.d.ts +14 -0
  31. package/types/Rating/v2/styles.d.ts.map +1 -0
  32. package/types/RatingIcon/v2/index.d.ts +39 -0
  33. package/types/RatingIcon/v2/index.d.ts.map +1 -0
  34. package/types/RatingIcon/v2/props.d.ts +19 -0
  35. package/types/RatingIcon/v2/props.d.ts.map +1 -0
  36. package/types/RatingIcon/v2/styles.d.ts +15 -0
  37. package/types/RatingIcon/v2/styles.d.ts.map +1 -0
  38. package/types/exports/b.d.ts +5 -0
  39. package/types/exports/b.d.ts.map +1 -0
package/CHANGELOG.md CHANGED
@@ -3,9 +3,19 @@
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
- ## [11.7.2-snapshot-18](https://github.com/instructure/instructure-ui/compare/v11.7.1...v11.7.2-snapshot-18) (2026-04-01)
6
+ ## [11.7.2-snapshot-20](https://github.com/instructure/instructure-ui/compare/v11.7.1...v11.7.2-snapshot-20) (2026-04-01)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-rating
8
+
9
+ ### Features
10
+
11
+ * **ui-rating,ui-icons:** rework Rating ([af97f0c](https://github.com/instructure/instructure-ui/commit/af97f0c0bc3a5d8324d99f23645b428192152193))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * **ui-rating,ui-icons:** contains breaking changes due to component using the new theming system
17
+
18
+ INSTUI-4806
9
19
 
10
20
 
11
21
 
@@ -0,0 +1,114 @@
1
+ var _dec, _class, _Rating;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
27
+ import { View } from '@instructure/ui-view/latest';
28
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content';
29
+ import { omitProps } from '@instructure/ui-react-utils';
30
+ import { RatingIcon } from "../../RatingIcon/v2/index.js";
31
+ import { withStyle } from '@instructure/emotion';
32
+ import generateStyle from "./styles.js";
33
+ import { allowedProps } from "./props.js";
34
+ /**
35
+ ---
36
+ category: components
37
+ ---
38
+ **/
39
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
40
+ let Rating = (_dec = withStyle(generateStyle), _dec(_class = (_Rating = class Rating extends Component {
41
+ constructor(...args) {
42
+ super(...args);
43
+ this.ref = null;
44
+ this.handleRef = el => {
45
+ this.ref = el;
46
+ };
47
+ }
48
+ componentDidMount() {
49
+ var _this$props$makeStyle, _this$props;
50
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
51
+ }
52
+ componentDidUpdate() {
53
+ var _this$props$makeStyle2, _this$props2;
54
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
55
+ }
56
+ get filled() {
57
+ const _this$props3 = this.props,
58
+ valueNow = _this$props3.valueNow,
59
+ iconCount = _this$props3.iconCount,
60
+ valueMax = _this$props3.valueMax;
61
+
62
+ // prevent divide by zero errors
63
+ const max = !!valueMax && valueMax > 0 ? valueMax : iconCount;
64
+ const filledIcons = Math.round(valueNow * iconCount / max);
65
+
66
+ // Handle edge case where valueNow is greater than valueMax
67
+ if (filledIcons > iconCount) {
68
+ return iconCount;
69
+ } else {
70
+ return filledIcons;
71
+ }
72
+ }
73
+ get empty() {
74
+ return this.props.iconCount - this.filled;
75
+ }
76
+ render() {
77
+ var _this$props$styles;
78
+ const _this$props4 = this.props,
79
+ iconCount = _this$props4.iconCount,
80
+ animateFill = _this$props4.animateFill,
81
+ size = _this$props4.size,
82
+ margin = _this$props4.margin,
83
+ label = _this$props4.label,
84
+ formatValueText = _this$props4.formatValueText;
85
+ const valueText = label + ' ' + (formatValueText === null || formatValueText === void 0 ? void 0 : formatValueText(this.filled, iconCount));
86
+ const passthroughProps = View.omitViewProps(omitProps(this.props, Rating.allowedProps), Rating);
87
+ return _jsxs(View, {
88
+ ...passthroughProps,
89
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rating,
90
+ margin: margin,
91
+ display: "inline-block",
92
+ elementRef: this.handleRef,
93
+ "data-cid": "Rating",
94
+ children: [_jsx(ScreenReaderContent, {
95
+ children: valueText
96
+ }), [...Array(this.filled)].map((_x, i) => _jsx(RatingIcon, {
97
+ filled: true,
98
+ animateFill: animateFill,
99
+ animationDelay: animateFill ? (i + 1) * 200 : void 0,
100
+ size: size
101
+ }, i + 1)), [...Array(this.empty)].map((_x, i) => _jsx(RatingIcon, {
102
+ size: size
103
+ }, i + 1))]
104
+ });
105
+ }
106
+ }, _Rating.displayName = "Rating", _Rating.componentId = 'Rating', _Rating.allowedProps = allowedProps, _Rating.defaultProps = {
107
+ animateFill: false,
108
+ formatValueText: (filled, iconCount) => `${filled} / ${iconCount}`,
109
+ iconCount: 3,
110
+ size: 'medium',
111
+ valueNow: 0
112
+ }, _Rating.Icon = RatingIcon, _Rating)) || _class);
113
+ export default Rating;
114
+ export { Rating };
@@ -0,0 +1,26 @@
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
+
25
+ const allowedProps = ['label', 'formatValueText', 'iconCount', 'size', 'valueMax', 'valueNow', 'animateFill', 'margin'];
26
+ export { allowedProps };
@@ -0,0 +1,43 @@
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
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = () => {
36
+ return {
37
+ rating: {
38
+ label: 'rating',
39
+ lineHeight: 1
40
+ }
41
+ };
42
+ };
43
+ export default generateStyle;
@@ -0,0 +1,124 @@
1
+ var _dec, _class, _RatingIcon;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Component } from 'react';
27
+ import { StarInstUIIcon, StarSolidInstUIIcon } from '@instructure/ui-icons';
28
+ import { requestAnimationFrame } from '@instructure/ui-dom-utils';
29
+ import { Transition } from '@instructure/ui-motion';
30
+ import { withStyle } from '@instructure/emotion';
31
+ import generateStyle from "./styles.js";
32
+ import { allowedProps } from "./props.js";
33
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
34
+ const ratingIconSizeToIconSize = {
35
+ small: 'md',
36
+ medium: 'lg',
37
+ large: 'xl'
38
+ };
39
+
40
+ /**
41
+ ---
42
+ parent: Rating
43
+ id: Rating.Icon
44
+ ---
45
+ **/
46
+ let RatingIcon = (_dec = withStyle(generateStyle), _dec(_class = (_RatingIcon = class RatingIcon extends Component {
47
+ constructor(props) {
48
+ super(props);
49
+ this.ref = null;
50
+ this._timeouts = [];
51
+ this._animation = void 0;
52
+ this.makeStyleProps = () => {
53
+ return {
54
+ filled: this.state.filled
55
+ };
56
+ };
57
+ this.fill = () => {
58
+ this._animation = requestAnimationFrame(() => {
59
+ this.setState({
60
+ filled: true
61
+ });
62
+ });
63
+ };
64
+ this.state = {
65
+ filled: props.filled && !props.animateFill
66
+ };
67
+ }
68
+ componentDidMount() {
69
+ var _this$props$makeStyle, _this$props;
70
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
71
+ if (this.props.animateFill) {
72
+ this._timeouts.push(setTimeout(this.fill, this.props.animationDelay));
73
+ }
74
+ }
75
+ componentDidUpdate(prevProps) {
76
+ var _this$props$makeStyle2, _this$props2;
77
+ if (this.props.animateFill && this.props.filled && this.props.filled !== prevProps.filled) {
78
+ this.fill();
79
+ }
80
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
81
+ }
82
+ componentWillUnmount() {
83
+ this._animation && this._animation.cancel();
84
+ this._timeouts.forEach(timeout => clearTimeout(timeout));
85
+ }
86
+ render() {
87
+ var _this$props$styles, _this$props$styles2, _this$props$styles3;
88
+ const _this$props3 = this.props,
89
+ animateFill = _this$props3.animateFill,
90
+ size = _this$props3.size;
91
+ const Icon = this.state.filled ? StarSolidInstUIIcon : StarInstUIIcon;
92
+ const iconSize = ratingIconSizeToIconSize[size];
93
+ return _jsx("span", {
94
+ "aria-hidden": "true",
95
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.ratingIcon,
96
+ ref: el => {
97
+ this.ref = el;
98
+ },
99
+ children: this.state.filled && animateFill ? _jsx(Transition, {
100
+ in: true,
101
+ transitionOnMount: true,
102
+ type: "scale",
103
+ children: _jsx("span", {
104
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.icon,
105
+ children: _jsx(Icon, {
106
+ size: iconSize
107
+ })
108
+ })
109
+ }) : _jsx("span", {
110
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon,
111
+ children: _jsx(Icon, {
112
+ size: iconSize
113
+ })
114
+ })
115
+ });
116
+ }
117
+ }, _RatingIcon.displayName = "RatingIcon", _RatingIcon.componentId = 'Rating.Icon', _RatingIcon.allowedProps = allowedProps, _RatingIcon.defaultProps = {
118
+ animationDelay: 200,
119
+ animateFill: false,
120
+ filled: false,
121
+ size: 'medium'
122
+ }, _RatingIcon)) || _class);
123
+ export default RatingIcon;
124
+ export { RatingIcon };
@@ -0,0 +1,26 @@
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
+
25
+ const allowedProps = ['animationDelay', 'animateFill', 'filled', 'size'];
26
+ export { allowedProps };
@@ -0,0 +1,59 @@
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
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = (componentTheme, _props, state, _sharedTokens) => {
36
+ const filled = state.filled;
37
+ return {
38
+ ratingIcon: {
39
+ label: 'ratingIcon',
40
+ display: 'inline-block',
41
+ verticalAlign: 'bottom',
42
+ margin: `0 ${componentTheme.iconMargin}`,
43
+ lineHeight: 1,
44
+ '&:first-of-type': {
45
+ marginLeft: 0
46
+ },
47
+ '&:last-of-type': {
48
+ marginRight: 0
49
+ }
50
+ },
51
+ icon: {
52
+ label: 'ratingIcon__icon',
53
+ display: 'inline-block',
54
+ verticalAlign: 'bottom',
55
+ color: filled ? componentTheme.iconFilledColor : componentTheme.iconEmptyColor
56
+ }
57
+ };
58
+ };
59
+ export default generateStyle;
@@ -0,0 +1,25 @@
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
+ export { Rating } from "../Rating/v2/index.js";
25
+ export { RatingIcon } from "../RatingIcon/v2/index.js";
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Rating = void 0;
8
+ var _react = require("react");
9
+ var _latest = require("@instructure/ui-view/latest");
10
+ var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
11
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
12
+ var _v = require("../../RatingIcon/v2");
13
+ var _emotion = require("@instructure/emotion");
14
+ var _styles = _interopRequireDefault(require("./styles"));
15
+ var _props = require("./props");
16
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
+ var _dec, _class, _Rating;
18
+ /*
19
+ * The MIT License (MIT)
20
+ *
21
+ * Copyright (c) 2015 - present Instructure, Inc.
22
+ *
23
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ * of this software and associated documentation files (the "Software"), to deal
25
+ * in the Software without restriction, including without limitation the rights
26
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ * copies of the Software, and to permit persons to whom the Software is
28
+ * furnished to do so, subject to the following conditions:
29
+ *
30
+ * The above copyright notice and this permission notice shall be included in all
31
+ * copies or substantial portions of the Software.
32
+ *
33
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ * SOFTWARE.
40
+ */
41
+ /**
42
+ ---
43
+ category: components
44
+ ---
45
+ **/
46
+ let Rating = exports.Rating = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = (_Rating = class Rating extends _react.Component {
47
+ constructor(...args) {
48
+ super(...args);
49
+ this.ref = null;
50
+ this.handleRef = el => {
51
+ this.ref = el;
52
+ };
53
+ }
54
+ componentDidMount() {
55
+ var _this$props$makeStyle, _this$props;
56
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
57
+ }
58
+ componentDidUpdate() {
59
+ var _this$props$makeStyle2, _this$props2;
60
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
61
+ }
62
+ get filled() {
63
+ const _this$props3 = this.props,
64
+ valueNow = _this$props3.valueNow,
65
+ iconCount = _this$props3.iconCount,
66
+ valueMax = _this$props3.valueMax;
67
+
68
+ // prevent divide by zero errors
69
+ const max = !!valueMax && valueMax > 0 ? valueMax : iconCount;
70
+ const filledIcons = Math.round(valueNow * iconCount / max);
71
+
72
+ // Handle edge case where valueNow is greater than valueMax
73
+ if (filledIcons > iconCount) {
74
+ return iconCount;
75
+ } else {
76
+ return filledIcons;
77
+ }
78
+ }
79
+ get empty() {
80
+ return this.props.iconCount - this.filled;
81
+ }
82
+ render() {
83
+ var _this$props$styles;
84
+ const _this$props4 = this.props,
85
+ iconCount = _this$props4.iconCount,
86
+ animateFill = _this$props4.animateFill,
87
+ size = _this$props4.size,
88
+ margin = _this$props4.margin,
89
+ label = _this$props4.label,
90
+ formatValueText = _this$props4.formatValueText;
91
+ const valueText = label + ' ' + (formatValueText === null || formatValueText === void 0 ? void 0 : formatValueText(this.filled, iconCount));
92
+ const passthroughProps = _latest.View.omitViewProps((0, _omitProps.omitProps)(this.props, Rating.allowedProps), Rating);
93
+ return (0, _jsxRuntime.jsxs)(_latest.View, {
94
+ ...passthroughProps,
95
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.rating,
96
+ margin: margin,
97
+ display: "inline-block",
98
+ elementRef: this.handleRef,
99
+ "data-cid": "Rating",
100
+ children: [(0, _jsxRuntime.jsx)(_ScreenReaderContent.ScreenReaderContent, {
101
+ children: valueText
102
+ }), [...Array(this.filled)].map((_x, i) => (0, _jsxRuntime.jsx)(_v.RatingIcon, {
103
+ filled: true,
104
+ animateFill: animateFill,
105
+ animationDelay: animateFill ? (i + 1) * 200 : void 0,
106
+ size: size
107
+ }, i + 1)), [...Array(this.empty)].map((_x, i) => (0, _jsxRuntime.jsx)(_v.RatingIcon, {
108
+ size: size
109
+ }, i + 1))]
110
+ });
111
+ }
112
+ }, _Rating.displayName = "Rating", _Rating.componentId = 'Rating', _Rating.allowedProps = _props.allowedProps, _Rating.defaultProps = {
113
+ animateFill: false,
114
+ formatValueText: (filled, iconCount) => `${filled} / ${iconCount}`,
115
+ iconCount: 3,
116
+ size: 'medium',
117
+ valueNow: 0
118
+ }, _Rating.Icon = _v.RatingIcon, _Rating)) || _class);
119
+ var _default = exports.default = Rating;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.allowedProps = ['label', 'formatValueText', 'iconCount', 'size', 'valueMax', 'valueNow', 'animateFill', 'margin'];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} state the state of the component, the style is applied to
39
+ * @return {Object} The final style object, which will be used in the component
40
+ */
41
+ const generateStyle = () => {
42
+ return {
43
+ rating: {
44
+ label: 'rating',
45
+ lineHeight: 1
46
+ }
47
+ };
48
+ };
49
+ var _default = exports.default = generateStyle;