@contentful/field-editor-rating 2.2.1 → 2.2.2-canary.30
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/cjs/RatingRibbon.js +53 -75
- package/dist/esm/RatingRibbon.js +53 -75
- package/dist/types/RatingRibbon.d.ts +1 -12
- package/package.json +3 -3
package/dist/cjs/RatingRibbon.js
CHANGED
|
@@ -13,19 +13,6 @@ const _f36components = require("@contentful/f36-components");
|
|
|
13
13
|
const _f36icons = require("@contentful/f36-icons");
|
|
14
14
|
const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
|
|
15
15
|
const _css = require("@emotion/css");
|
|
16
|
-
function _define_property(obj, key, value) {
|
|
17
|
-
if (key in obj) {
|
|
18
|
-
Object.defineProperty(obj, key, {
|
|
19
|
-
value: value,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
obj[key] = value;
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
16
|
function _interop_require_default(obj) {
|
|
30
17
|
return obj && obj.__esModule ? obj : {
|
|
31
18
|
default: obj
|
|
@@ -72,69 +59,60 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
72
59
|
}
|
|
73
60
|
return newObj;
|
|
74
61
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
function RatingRibbon({ disabled, stars, value, onSelect }) {
|
|
63
|
+
const [hovered, setHovered] = _react.useState(null);
|
|
64
|
+
const isSelected = (num)=>{
|
|
65
|
+
if (hovered !== null) {
|
|
66
|
+
return num <= hovered;
|
|
80
67
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
isDisabled: this.props.disabled,
|
|
95
|
-
key: num,
|
|
96
|
-
onMouseDown: (e)=>{
|
|
97
|
-
if (e.button === 0) {
|
|
98
|
-
this.props.onSelect(num);
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
onKeyDown: (e)=>{
|
|
102
|
-
if (e.keyCode === 13) {
|
|
103
|
-
this.props.onSelect(num);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
onMouseOver: this.onFocus(num),
|
|
107
|
-
onMouseLeave: this.onBlur,
|
|
108
|
-
onFocus: this.onFocus(num),
|
|
109
|
-
onBlur: this.onBlur,
|
|
110
|
-
"aria-label": num.toString()
|
|
111
|
-
})));
|
|
112
|
-
}
|
|
113
|
-
constructor(...args){
|
|
114
|
-
super(...args), _define_property(this, "state", {
|
|
115
|
-
hovered: null
|
|
116
|
-
}), _define_property(this, "isSelected", (num)=>{
|
|
117
|
-
const hovered = this.state.hovered;
|
|
118
|
-
const value = this.props.value;
|
|
119
|
-
if (hovered !== null) {
|
|
120
|
-
return num <= hovered;
|
|
121
|
-
}
|
|
122
|
-
if (value) {
|
|
123
|
-
return num <= value;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}), _define_property(this, "onBlur", ()=>{
|
|
127
|
-
if (!this.props.disabled) {
|
|
128
|
-
this.setState({
|
|
129
|
-
hovered: null
|
|
130
|
-
});
|
|
68
|
+
if (value) {
|
|
69
|
+
return num <= value;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
const onBlur = ()=>{
|
|
74
|
+
if (!disabled) {
|
|
75
|
+
setHovered(null);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const onFocus = (num)=>()=>{
|
|
79
|
+
if (!disabled) {
|
|
80
|
+
setHovered(num);
|
|
131
81
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
});
|
|
82
|
+
};
|
|
83
|
+
const items = [];
|
|
84
|
+
for(let i = 1; i <= stars; i++){
|
|
85
|
+
items.push(i);
|
|
139
86
|
}
|
|
87
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, items.map((num)=>/*#__PURE__*/ _react.createElement(_f36components.IconButton, {
|
|
88
|
+
variant: "transparent",
|
|
89
|
+
size: "small",
|
|
90
|
+
icon: /*#__PURE__*/ _react.createElement(_f36icons.StarIcon, {
|
|
91
|
+
isActive: isSelected(num),
|
|
92
|
+
color: isSelected(num) ? _f36tokens.default.colorPrimary : _f36tokens.default.gray600,
|
|
93
|
+
className: (0, _css.css)({
|
|
94
|
+
width: '22px',
|
|
95
|
+
height: '22px'
|
|
96
|
+
})
|
|
97
|
+
}),
|
|
98
|
+
"data-selected": isSelected(num) ? 'true' : 'false',
|
|
99
|
+
testId: "rating-editor-star",
|
|
100
|
+
isDisabled: disabled,
|
|
101
|
+
key: num,
|
|
102
|
+
onMouseDown: (e)=>{
|
|
103
|
+
if (e.button === 0) {
|
|
104
|
+
onSelect(num);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
onKeyDown: (e)=>{
|
|
108
|
+
if (e.keyCode === 13) {
|
|
109
|
+
onSelect(num);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
onMouseOver: onFocus(num),
|
|
113
|
+
onMouseLeave: onBlur,
|
|
114
|
+
onFocus: onFocus(num),
|
|
115
|
+
onBlur: onBlur,
|
|
116
|
+
"aria-label": num.toString()
|
|
117
|
+
})));
|
|
140
118
|
}
|
package/dist/esm/RatingRibbon.js
CHANGED
|
@@ -1,84 +1,62 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
1
|
import * as React from 'react';
|
|
15
2
|
import { IconButton } from '@contentful/f36-components';
|
|
16
3
|
import { StarIcon } from '@contentful/f36-icons';
|
|
17
4
|
import tokens from '@contentful/f36-tokens';
|
|
18
5
|
import { css } from '@emotion/css';
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
export function RatingRibbon({ disabled, stars, value, onSelect }) {
|
|
7
|
+
const [hovered, setHovered] = React.useState(null);
|
|
8
|
+
const isSelected = (num)=>{
|
|
9
|
+
if (hovered !== null) {
|
|
10
|
+
return num <= hovered;
|
|
24
11
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
isDisabled: this.props.disabled,
|
|
39
|
-
key: num,
|
|
40
|
-
onMouseDown: (e)=>{
|
|
41
|
-
if (e.button === 0) {
|
|
42
|
-
this.props.onSelect(num);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
onKeyDown: (e)=>{
|
|
46
|
-
if (e.keyCode === 13) {
|
|
47
|
-
this.props.onSelect(num);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
onMouseOver: this.onFocus(num),
|
|
51
|
-
onMouseLeave: this.onBlur,
|
|
52
|
-
onFocus: this.onFocus(num),
|
|
53
|
-
onBlur: this.onBlur,
|
|
54
|
-
"aria-label": num.toString()
|
|
55
|
-
})));
|
|
56
|
-
}
|
|
57
|
-
constructor(...args){
|
|
58
|
-
super(...args), _define_property(this, "state", {
|
|
59
|
-
hovered: null
|
|
60
|
-
}), _define_property(this, "isSelected", (num)=>{
|
|
61
|
-
const hovered = this.state.hovered;
|
|
62
|
-
const value = this.props.value;
|
|
63
|
-
if (hovered !== null) {
|
|
64
|
-
return num <= hovered;
|
|
65
|
-
}
|
|
66
|
-
if (value) {
|
|
67
|
-
return num <= value;
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}), _define_property(this, "onBlur", ()=>{
|
|
71
|
-
if (!this.props.disabled) {
|
|
72
|
-
this.setState({
|
|
73
|
-
hovered: null
|
|
74
|
-
});
|
|
12
|
+
if (value) {
|
|
13
|
+
return num <= value;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
const onBlur = ()=>{
|
|
18
|
+
if (!disabled) {
|
|
19
|
+
setHovered(null);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const onFocus = (num)=>()=>{
|
|
23
|
+
if (!disabled) {
|
|
24
|
+
setHovered(num);
|
|
75
25
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
26
|
+
};
|
|
27
|
+
const items = [];
|
|
28
|
+
for(let i = 1; i <= stars; i++){
|
|
29
|
+
items.push(i);
|
|
83
30
|
}
|
|
31
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, items.map((num)=>/*#__PURE__*/ React.createElement(IconButton, {
|
|
32
|
+
variant: "transparent",
|
|
33
|
+
size: "small",
|
|
34
|
+
icon: /*#__PURE__*/ React.createElement(StarIcon, {
|
|
35
|
+
isActive: isSelected(num),
|
|
36
|
+
color: isSelected(num) ? tokens.colorPrimary : tokens.gray600,
|
|
37
|
+
className: css({
|
|
38
|
+
width: '22px',
|
|
39
|
+
height: '22px'
|
|
40
|
+
})
|
|
41
|
+
}),
|
|
42
|
+
"data-selected": isSelected(num) ? 'true' : 'false',
|
|
43
|
+
testId: "rating-editor-star",
|
|
44
|
+
isDisabled: disabled,
|
|
45
|
+
key: num,
|
|
46
|
+
onMouseDown: (e)=>{
|
|
47
|
+
if (e.button === 0) {
|
|
48
|
+
onSelect(num);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
onKeyDown: (e)=>{
|
|
52
|
+
if (e.keyCode === 13) {
|
|
53
|
+
onSelect(num);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
onMouseOver: onFocus(num),
|
|
57
|
+
onMouseLeave: onBlur,
|
|
58
|
+
onFocus: onFocus(num),
|
|
59
|
+
onBlur: onBlur,
|
|
60
|
+
"aria-label": num.toString()
|
|
61
|
+
})));
|
|
84
62
|
}
|
|
@@ -5,16 +5,5 @@ type RatingRibbonProps = {
|
|
|
5
5
|
value: number | null | undefined;
|
|
6
6
|
onSelect: (val: number) => void;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
hovered: null | number;
|
|
10
|
-
};
|
|
11
|
-
export declare class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {
|
|
12
|
-
state: {
|
|
13
|
-
hovered: null;
|
|
14
|
-
};
|
|
15
|
-
isSelected: (num: number) => boolean;
|
|
16
|
-
onBlur: () => void;
|
|
17
|
-
onFocus: (num: number) => () => void;
|
|
18
|
-
render(): React.JSX.Element;
|
|
19
|
-
}
|
|
8
|
+
export declare function RatingRibbon({ disabled, stars, value, onSelect }: RatingRibbonProps): React.JSX.Element;
|
|
20
9
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rating",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2-canary.30+69033935",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@contentful/f36-components": "^6.7.1",
|
|
40
40
|
"@contentful/f36-icons": "^6.7.1",
|
|
41
41
|
"@contentful/f36-tokens": "^6.1.2",
|
|
42
|
-
"@contentful/field-editor-shared": "^4.5.
|
|
42
|
+
"@contentful/field-editor-shared": "^4.5.2-canary.30+69033935",
|
|
43
43
|
"@emotion/css": "^11.13.5",
|
|
44
44
|
"lodash": "^4.17.15"
|
|
45
45
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"registry": "https://npm.pkg.github.com/"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "69033935571ab64c941e30158340242c5a449c64"
|
|
59
59
|
}
|