@contentful/field-editor-rating 1.2.0 → 1.3.1
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/RatingEditor.js +110 -0
- package/dist/cjs/RatingEditor.spec.js +136 -0
- package/dist/cjs/RatingRibbon.js +133 -0
- package/dist/cjs/index.js +11 -0
- package/dist/esm/RatingEditor.js +56 -0
- package/dist/esm/RatingEditor.spec.js +93 -0
- package/dist/esm/RatingRibbon.js +84 -0
- package/dist/esm/index.js +1 -0
- package/dist/{RatingEditor.d.ts → types/RatingEditor.d.ts} +26 -26
- package/dist/types/RatingEditor.spec.d.ts +1 -0
- package/dist/{RatingRibbon.d.ts → types/RatingRibbon.d.ts} +20 -20
- package/dist/{index.d.ts → types/index.d.ts} +1 -1
- package/package.json +26 -13
- package/CHANGELOG.md +0 -198
- package/dist/field-editor-rating.cjs.development.js +0 -152
- package/dist/field-editor-rating.cjs.development.js.map +0 -1
- package/dist/field-editor-rating.cjs.production.min.js +0 -2
- package/dist/field-editor-rating.cjs.production.min.js.map +0 -1
- package/dist/field-editor-rating.esm.js +0 -146
- package/dist/field-editor-rating.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
disabled: boolean;
|
|
4
|
-
stars: number;
|
|
5
|
-
value: number | null | undefined;
|
|
6
|
-
onSelect: (val: number) => void;
|
|
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(): JSX.Element;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type RatingRibbonProps = {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
stars: number;
|
|
5
|
+
value: number | null | undefined;
|
|
6
|
+
onSelect: (val: number) => void;
|
|
7
|
+
};
|
|
8
|
+
type RatingRibbonState = {
|
|
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
|
+
}
|
|
20
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RatingEditor } from './RatingEditor';
|
|
1
|
+
export { RatingEditor } from './RatingEditor';
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rating",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/
|
|
6
|
-
"
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"require": "./dist/cjs/index.js",
|
|
11
|
+
"default": "./dist/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist"
|
|
9
17
|
],
|
|
@@ -14,25 +22,30 @@
|
|
|
14
22
|
"url": "https://github.com/contentful/field-editors"
|
|
15
23
|
},
|
|
16
24
|
"scripts": {
|
|
17
|
-
"watch": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
25
|
+
"watch": "yarn concurrently \"yarn:watch:*\"",
|
|
26
|
+
"watch:cjs": "yarn build:cjs -w",
|
|
27
|
+
"watch:esm": "yarn build:esm -w",
|
|
28
|
+
"watch:types": "yarn build:types --watch",
|
|
29
|
+
"build": "yarn build:types && yarn build:cjs && yarn build:esm",
|
|
30
|
+
"build:types": "tsc --outDir dist/types --emitDeclarationOnly",
|
|
31
|
+
"build:cjs": "swc src --config-file ../../.swcrc -d dist/cjs -C module.type=commonjs",
|
|
32
|
+
"build:esm": "swc src --config-file ../../.swcrc -d dist/esm",
|
|
33
|
+
"test": "jest --watch",
|
|
34
|
+
"test:ci": "jest --ci",
|
|
21
35
|
"tsc": "tsc -p ./ --noEmit"
|
|
22
36
|
},
|
|
23
37
|
"dependencies": {
|
|
24
38
|
"@contentful/f36-components": "^4.0.27",
|
|
25
39
|
"@contentful/f36-tokens": "^4.0.0",
|
|
26
|
-
"@contentful/field-editor-shared": "^1.
|
|
40
|
+
"@contentful/field-editor-shared": "^1.3.1",
|
|
27
41
|
"emotion": "^10.0.17",
|
|
28
|
-
"lodash": "^4.17.15"
|
|
29
|
-
"lodash-es": "^4.17.15"
|
|
42
|
+
"lodash": "^4.17.15"
|
|
30
43
|
},
|
|
31
44
|
"devDependencies": {
|
|
32
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
45
|
+
"@contentful/field-editor-test-utils": "^1.4.1"
|
|
33
46
|
},
|
|
34
47
|
"peerDependencies": {
|
|
35
48
|
"react": ">=16.8.0"
|
|
36
49
|
},
|
|
37
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ca904b19ca794a2c40d82e1f7ede9e0be3560f22"
|
|
38
51
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.11...@contentful/field-editor-rating@1.2.0) (2023-04-19)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- upgrade cypress [TOL-1036] ([#1391](https://github.com/contentful/field-editors/issues/1391)) ([9c1aec9](https://github.com/contentful/field-editors/commit/9c1aec98aabbe464cdc3f1236c3bb1cc29b8208d))
|
|
11
|
-
|
|
12
|
-
## [1.1.11](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.10...@contentful/field-editor-rating@1.1.11) (2023-03-14)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
15
|
-
|
|
16
|
-
## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.9...@contentful/field-editor-rating@1.1.10) (2023-03-10)
|
|
17
|
-
|
|
18
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
19
|
-
|
|
20
|
-
## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.8...@contentful/field-editor-rating@1.1.9) (2023-02-21)
|
|
21
|
-
|
|
22
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
23
|
-
|
|
24
|
-
## [1.1.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.7...@contentful/field-editor-rating@1.1.8) (2023-02-07)
|
|
25
|
-
|
|
26
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
27
|
-
|
|
28
|
-
## [1.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.6...@contentful/field-editor-rating@1.1.7) (2022-12-08)
|
|
29
|
-
|
|
30
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
31
|
-
|
|
32
|
-
## [1.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.5...@contentful/field-editor-rating@1.1.6) (2022-07-29)
|
|
33
|
-
|
|
34
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
35
|
-
|
|
36
|
-
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.4...@contentful/field-editor-rating@1.1.5) (2022-07-29)
|
|
37
|
-
|
|
38
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
39
|
-
|
|
40
|
-
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.3...@contentful/field-editor-rating@1.1.4) (2022-07-11)
|
|
41
|
-
|
|
42
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
43
|
-
|
|
44
|
-
## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.2...@contentful/field-editor-rating@1.1.3) (2022-06-22)
|
|
45
|
-
|
|
46
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
47
|
-
|
|
48
|
-
## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.1...@contentful/field-editor-rating@1.1.2) (2022-02-15)
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
- bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
|
|
53
|
-
|
|
54
|
-
## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.1.0...@contentful/field-editor-rating@1.1.1) (2022-02-14)
|
|
55
|
-
|
|
56
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
57
|
-
|
|
58
|
-
# [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.3...@contentful/field-editor-rating@1.1.0) (2022-01-11)
|
|
59
|
-
|
|
60
|
-
### Features
|
|
61
|
-
|
|
62
|
-
- bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
|
|
63
|
-
|
|
64
|
-
## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.2...@contentful/field-editor-rating@1.0.3) (2021-12-23)
|
|
65
|
-
|
|
66
|
-
### Bug Fixes
|
|
67
|
-
|
|
68
|
-
- markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
|
|
69
|
-
|
|
70
|
-
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.1...@contentful/field-editor-rating@1.0.2) (2021-12-20)
|
|
71
|
-
|
|
72
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
73
|
-
|
|
74
|
-
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@1.0.0...@contentful/field-editor-rating@1.0.1) (2021-11-17)
|
|
75
|
-
|
|
76
|
-
### Bug Fixes
|
|
77
|
-
|
|
78
|
-
- **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
|
|
79
|
-
|
|
80
|
-
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.13.0...@contentful/field-editor-rating@1.0.0) (2021-11-04)
|
|
81
|
-
|
|
82
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
83
|
-
|
|
84
|
-
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.6...@contentful/field-editor-rating@0.13.0) (2021-11-04)
|
|
85
|
-
|
|
86
|
-
### Features
|
|
87
|
-
|
|
88
|
-
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
89
|
-
|
|
90
|
-
### BREAKING CHANGES
|
|
91
|
-
|
|
92
|
-
- adopts a new Forma v4 beta
|
|
93
|
-
|
|
94
|
-
## [0.12.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.5...@contentful/field-editor-rating@0.12.6) (2021-10-14)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
97
|
-
|
|
98
|
-
## [0.12.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.4...@contentful/field-editor-rating@0.12.5) (2021-10-06)
|
|
99
|
-
|
|
100
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
101
|
-
|
|
102
|
-
## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.3...@contentful/field-editor-rating@0.12.4) (2021-09-17)
|
|
103
|
-
|
|
104
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
105
|
-
|
|
106
|
-
## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.2...@contentful/field-editor-rating@0.12.3) (2021-09-16)
|
|
107
|
-
|
|
108
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
109
|
-
|
|
110
|
-
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.1...@contentful/field-editor-rating@0.12.2) (2021-08-19)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
113
|
-
|
|
114
|
-
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.12.0...@contentful/field-editor-rating@0.12.1) (2021-07-29)
|
|
115
|
-
|
|
116
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
117
|
-
|
|
118
|
-
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.6...@contentful/field-editor-rating@0.12.0) (2021-07-23)
|
|
119
|
-
|
|
120
|
-
### Features
|
|
121
|
-
|
|
122
|
-
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
123
|
-
|
|
124
|
-
## [0.11.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.6) (2021-07-06)
|
|
125
|
-
|
|
126
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
127
|
-
|
|
128
|
-
## [0.11.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.5) (2021-07-06)
|
|
129
|
-
|
|
130
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
131
|
-
|
|
132
|
-
## [0.11.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.3...@contentful/field-editor-rating@0.11.4) (2021-06-23)
|
|
133
|
-
|
|
134
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
135
|
-
|
|
136
|
-
## [0.11.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.2...@contentful/field-editor-rating@0.11.3) (2021-06-23)
|
|
137
|
-
|
|
138
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
139
|
-
|
|
140
|
-
## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.1...@contentful/field-editor-rating@0.11.2) (2021-06-22)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
143
|
-
|
|
144
|
-
## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.11.0...@contentful/field-editor-rating@0.11.1) (2021-03-05)
|
|
145
|
-
|
|
146
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
147
|
-
|
|
148
|
-
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.2...@contentful/field-editor-rating@0.11.0) (2021-02-19)
|
|
149
|
-
|
|
150
|
-
### Features
|
|
151
|
-
|
|
152
|
-
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
153
|
-
|
|
154
|
-
## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.1...@contentful/field-editor-rating@0.10.2) (2021-02-09)
|
|
155
|
-
|
|
156
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
157
|
-
|
|
158
|
-
## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.10.0...@contentful/field-editor-rating@0.10.1) (2021-02-01)
|
|
159
|
-
|
|
160
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
161
|
-
|
|
162
|
-
# [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.9.1...@contentful/field-editor-rating@0.10.0) (2021-01-20)
|
|
163
|
-
|
|
164
|
-
### Features
|
|
165
|
-
|
|
166
|
-
- update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
|
|
167
|
-
|
|
168
|
-
## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.9.0...@contentful/field-editor-rating@0.9.1) (2021-01-15)
|
|
169
|
-
|
|
170
|
-
### Bug Fixes
|
|
171
|
-
|
|
172
|
-
- 🐛 small layout adjustments ([#555](https://github.com/contentful/field-editors/issues/555)) ([235c594](https://github.com/contentful/field-editors/commit/235c5941db152d2921a9ef134c1a71b0069a4dc2))
|
|
173
|
-
|
|
174
|
-
# [0.9.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.5...@contentful/field-editor-rating@0.9.0) (2021-01-12)
|
|
175
|
-
|
|
176
|
-
### Features
|
|
177
|
-
|
|
178
|
-
- update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
|
|
179
|
-
|
|
180
|
-
## [0.8.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.4...@contentful/field-editor-rating@0.8.5) (2020-12-16)
|
|
181
|
-
|
|
182
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
183
|
-
|
|
184
|
-
## [0.8.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.3...@contentful/field-editor-rating@0.8.4) (2020-11-06)
|
|
185
|
-
|
|
186
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
187
|
-
|
|
188
|
-
## [0.8.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.2...@contentful/field-editor-rating@0.8.3) (2020-11-06)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
191
|
-
|
|
192
|
-
## [0.8.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.1...@contentful/field-editor-rating@0.8.2) (2020-10-28)
|
|
193
|
-
|
|
194
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
195
|
-
|
|
196
|
-
## [0.8.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rating@0.8.0...@contentful/field-editor-rating@0.8.1) (2020-08-24)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @contentful/field-editor-rating
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var f36Components = require('@contentful/f36-components');
|
|
9
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
10
|
-
var get = _interopDefault(require('lodash/get'));
|
|
11
|
-
var f36Icons = require('@contentful/f36-icons');
|
|
12
|
-
var emotion = require('emotion');
|
|
13
|
-
|
|
14
|
-
class RatingRibbon extends React.Component {
|
|
15
|
-
constructor(...args) {
|
|
16
|
-
super(...args);
|
|
17
|
-
this.state = {
|
|
18
|
-
hovered: null
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
this.isSelected = num => {
|
|
22
|
-
const hovered = this.state.hovered;
|
|
23
|
-
const value = this.props.value;
|
|
24
|
-
|
|
25
|
-
if (hovered !== null) {
|
|
26
|
-
return num <= hovered;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (value) {
|
|
30
|
-
return num <= value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return false;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
this.onBlur = () => {
|
|
37
|
-
if (!this.props.disabled) {
|
|
38
|
-
this.setState({
|
|
39
|
-
hovered: null
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
this.onFocus = num => () => {
|
|
45
|
-
if (!this.props.disabled) {
|
|
46
|
-
this.setState({
|
|
47
|
-
hovered: num
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
render() {
|
|
54
|
-
const items = [];
|
|
55
|
-
|
|
56
|
-
for (let i = 1; i <= this.props.stars; i++) {
|
|
57
|
-
items.push(i);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return React.createElement(React.Fragment, null, items.map(num => React.createElement(f36Components.IconButton, {
|
|
61
|
-
variant: "transparent",
|
|
62
|
-
size: "small",
|
|
63
|
-
icon: React.createElement(f36Icons.StarIcon, {
|
|
64
|
-
variant: this.isSelected(num) ? 'primary' : 'muted',
|
|
65
|
-
className: emotion.css({
|
|
66
|
-
width: '22px',
|
|
67
|
-
height: '22px'
|
|
68
|
-
})
|
|
69
|
-
}),
|
|
70
|
-
"data-selected": this.isSelected(num) ? 'true' : 'false',
|
|
71
|
-
testId: "rating-editor-star",
|
|
72
|
-
isDisabled: this.props.disabled,
|
|
73
|
-
key: num,
|
|
74
|
-
onClick: () => {
|
|
75
|
-
this.props.onSelect(num);
|
|
76
|
-
},
|
|
77
|
-
onKeyDown: e => {
|
|
78
|
-
if (e.keyCode === 13) {
|
|
79
|
-
this.props.onSelect(num);
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
onMouseOver: this.onFocus(num),
|
|
83
|
-
onMouseLeave: this.onBlur,
|
|
84
|
-
onFocus: this.onFocus(num),
|
|
85
|
-
onBlur: this.onBlur,
|
|
86
|
-
"aria-label": num.toString()
|
|
87
|
-
})));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function isValidCount(count) {
|
|
93
|
-
return typeof count === 'number' && !isNaN(count) && count > 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function getStarCount(count) {
|
|
97
|
-
const defaultValue = 5;
|
|
98
|
-
|
|
99
|
-
if (isValidCount(count)) {
|
|
100
|
-
return Math.round(count);
|
|
101
|
-
} else if (typeof count === 'string') {
|
|
102
|
-
const parsed = parseInt(count, 10);
|
|
103
|
-
return isValidCount(parsed) ? Math.round(parsed) : defaultValue;
|
|
104
|
-
} else {
|
|
105
|
-
return defaultValue;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function RatingEditor(props) {
|
|
110
|
-
const {
|
|
111
|
-
field
|
|
112
|
-
} = props;
|
|
113
|
-
const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));
|
|
114
|
-
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
115
|
-
throttle: 0,
|
|
116
|
-
field: field,
|
|
117
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
118
|
-
}, ({
|
|
119
|
-
disabled,
|
|
120
|
-
value,
|
|
121
|
-
setValue
|
|
122
|
-
}) => {
|
|
123
|
-
const clearOption = () => {
|
|
124
|
-
setValue(null);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return React.createElement(f36Components.Flex, {
|
|
128
|
-
testId: "rating-editor",
|
|
129
|
-
flexDirection: "row",
|
|
130
|
-
marginTop: "spacingS"
|
|
131
|
-
}, React.createElement(RatingRibbon, {
|
|
132
|
-
disabled: disabled,
|
|
133
|
-
value: value,
|
|
134
|
-
stars: starsCount,
|
|
135
|
-
onSelect: num => {
|
|
136
|
-
setValue(num);
|
|
137
|
-
}
|
|
138
|
-
}), value !== undefined && !disabled && React.createElement(f36Components.Flex, {
|
|
139
|
-
marginLeft: "spacingM"
|
|
140
|
-
}, React.createElement(f36Components.TextLink, {
|
|
141
|
-
as: "button",
|
|
142
|
-
testId: "rating-editor-clear",
|
|
143
|
-
onClick: clearOption
|
|
144
|
-
}, "Clear")));
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
RatingEditor.defaultProps = {
|
|
148
|
-
isInitiallyDisabled: true
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
exports.RatingEditor = RatingEditor;
|
|
152
|
-
//# sourceMappingURL=field-editor-rating.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-rating.cjs.development.js","sources":["../src/RatingRibbon.tsx","../src/RatingEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\n\nimport { IconButton } from '@contentful/f36-components';\nimport { StarIcon } from '@contentful/f36-icons';\nimport { css } from 'emotion';\n\ntype RatingRibbonProps = {\n disabled: boolean;\n stars: number;\n value: number | null | undefined;\n onSelect: (val: number) => void;\n};\n\ntype RatingRibbonState = {\n hovered: null | number;\n};\n\nexport class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {\n state = {\n hovered: null,\n };\n\n isSelected = (num: number) => {\n const hovered = this.state.hovered;\n const value = this.props.value;\n\n if (hovered !== null) {\n return num <= hovered;\n }\n if (value) {\n return num <= value;\n }\n return false;\n };\n\n onBlur = () => {\n if (!this.props.disabled) {\n this.setState({ hovered: null });\n }\n };\n\n onFocus = (num: number) => () => {\n if (!this.props.disabled) {\n this.setState({ hovered: num });\n }\n };\n\n render() {\n const items: number[] = [];\n for (let i = 1; i <= this.props.stars; i++) {\n items.push(i);\n }\n\n return (\n <>\n {items.map((num) => (\n <IconButton\n variant=\"transparent\"\n size=\"small\"\n icon={\n <StarIcon\n variant={this.isSelected(num) ? 'primary' : 'muted'}\n className={css({ width: '22px', height: '22px' })}\n />\n }\n data-selected={this.isSelected(num) ? 'true' : 'false'}\n testId=\"rating-editor-star\"\n isDisabled={this.props.disabled}\n key={num}\n onClick={() => {\n this.props.onSelect(num);\n }}\n onKeyDown={(e: React.KeyboardEvent) => {\n if (e.keyCode === 13) {\n this.props.onSelect(num);\n }\n }}\n onMouseOver={this.onFocus(num)}\n onMouseLeave={this.onBlur}\n onFocus={this.onFocus(num)}\n onBlur={this.onBlur}\n aria-label={num.toString()}\n />\n ))}\n </>\n );\n }\n}\n","import * as React from 'react';\n\nimport { TextLink, Flex } from '@contentful/f36-components';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport get from 'lodash/get';\n\nimport { RatingRibbon } from './RatingRibbon';\n\n\nexport interface RatingEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n stars?: number;\n };\n };\n}\n\nfunction isValidCount(count?: string | number): count is number {\n return typeof count === 'number' && !isNaN(count) && count > 0;\n}\n\nfunction getStarCount(count?: number | string): number {\n const defaultValue = 5;\n\n if (isValidCount(count)) {\n return Math.round(count);\n } else if (typeof count === 'string') {\n const parsed = parseInt(count, 10);\n return isValidCount(parsed) ? Math.round(parsed) : defaultValue;\n } else {\n return defaultValue;\n }\n}\n\nexport function RatingEditor(props: RatingEditorProps) {\n const { field } = props;\n\n const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));\n\n return (\n <FieldConnector<number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"rating-editor\" flexDirection=\"row\" marginTop=\"spacingS\">\n <RatingRibbon\n disabled={disabled}\n value={value}\n stars={starsCount}\n onSelect={(num) => {\n setValue(num);\n }}\n />\n {value !== undefined && !disabled && (\n <Flex marginLeft=\"spacingM\">\n <TextLink as=\"button\" testId=\"rating-editor-clear\" onClick={clearOption}>\n Clear\n </TextLink>\n </Flex>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nRatingEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["RatingRibbon","React","state","hovered","isSelected","num","value","props","onBlur","disabled","setState","onFocus","render","items","i","stars","push","map","IconButton","variant","size","icon","StarIcon","className","css","width","height","testId","isDisabled","key","onClick","onSelect","onKeyDown","e","keyCode","onMouseOver","onMouseLeave","toString","isValidCount","count","isNaN","getStarCount","defaultValue","Math","round","parsed","parseInt","RatingEditor","field","starsCount","get","parameters","FieldConnector","throttle","isInitiallyDisabled","setValue","clearOption","Flex","flexDirection","marginTop","undefined","marginLeft","TextLink","as","defaultProps"],"mappings":";;;;;;;;;;;;;MAkBaA,qBAAqBC;;;SAChCC,QAAQ;AACNC,MAAAA,OAAO,EAAE;AADH;;SAIRC,aAAcC,GAAD;AACX,YAAMF,OAAO,GAAG,KAAKD,KAAL,CAAWC,OAA3B;AACA,YAAMG,KAAK,GAAG,KAAKC,KAAL,CAAWD,KAAzB;;AAEA,UAAIH,OAAO,KAAK,IAAhB,EAAsB;AACpB,eAAOE,GAAG,IAAIF,OAAd;AACD;;AACD,UAAIG,KAAJ,EAAW;AACT,eAAOD,GAAG,IAAIC,KAAd;AACD;;AACD,aAAO,KAAP;AACD;;SAEDE,SAAS;AACP,UAAI,CAAC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AAAA,KAAZ;AAAmBiD,IAAAA;AAAnB,GAAD;AACC,UAAMC,WAAW,GAAG;AAClBD,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;;AAIA,WACEtD,mBAAA,CAACwD,kBAAD;AAAM9B,MAAAA,MAAM,EAAC;AAAgB+B,MAAAA,aAAa,EAAC;AAAMC,MAAAA,SAAS,EAAC;KAA3D,EACE1D,mBAAA,CAACD,YAAD;AACES,MAAAA,QAAQ,EAAEA;AACVH,MAAAA,KAAK,EAAEA;AACPS,MAAAA,KAAK,EAAEkC;AACPlB,MAAAA,QAAQ,EAAG1B,GAAD;AACRkD,QAAAA,QAAQ,CAAClD,GAAD,CAAR;AACD;KANH,CADF,EASGC,KAAK,KAAKsD,SAAV,IAAuB,CAACnD,QAAxB,IACCR,mBAAA,CAACwD,kBAAD;AAAMI,MAAAA,UAAU,EAAC;KAAjB,EACE5D,mBAAA,CAAC6D,sBAAD;AAAUC,MAAAA,EAAE,EAAC;AAASpC,MAAAA,MAAM,EAAC;AAAsBG,MAAAA,OAAO,EAAE0B;KAA5D,SAAA,CADF,CAVJ,CADF;AAmBD,GA5BH,CADF;AAgCD;AAEDT,YAAY,CAACiB,YAAb,GAA4B;AAC1BV,EAAAA,mBAAmB,EAAE;AADK,CAA5B;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=require("@contentful/f36-components"),s=require("@contentful/field-editor-shared"),n=(e=require("lodash/get"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("@contentful/f36-icons"),o=require("emotion");class a extends t.Component{constructor(...e){super(...e),this.state={hovered:null},this.isSelected=e=>{const t=this.state.hovered,r=this.props.value;return null!==t?e<=t:!!r&&e<=r},this.onBlur=()=>{this.props.disabled||this.setState({hovered:null})},this.onFocus=e=>()=>{this.props.disabled||this.setState({hovered:e})}}render(){const e=[];for(let t=1;t<=this.props.stars;t++)e.push(t);return t.createElement(t.Fragment,null,e.map(e=>t.createElement(r.IconButton,{variant:"transparent",size:"small",icon:t.createElement(i.StarIcon,{variant:this.isSelected(e)?"primary":"muted",className:o.css({width:"22px",height:"22px"})}),"data-selected":this.isSelected(e)?"true":"false",testId:"rating-editor-star",isDisabled:this.props.disabled,key:e,onClick:()=>{this.props.onSelect(e)},onKeyDown:t=>{13===t.keyCode&&this.props.onSelect(e)},onMouseOver:this.onFocus(e),onMouseLeave:this.onBlur,onFocus:this.onFocus(e),onBlur:this.onBlur,"aria-label":e.toString()})))}}function l(e){return"number"==typeof e&&!isNaN(e)&&e>0}function u(e){const{field:i}=e,o=function(e){if(l(e))return Math.round(e);if("string"==typeof e){const t=parseInt(e,10);return l(t)?Math.round(t):5}return 5}(n(e.parameters,["instance","stars"]));return t.createElement(s.FieldConnector,{throttle:0,field:i,isInitiallyDisabled:e.isInitiallyDisabled},({disabled:e,value:s,setValue:n})=>t.createElement(r.Flex,{testId:"rating-editor",flexDirection:"row",marginTop:"spacingS"},t.createElement(a,{disabled:e,value:s,stars:o,onSelect:e=>{n(e)}}),void 0!==s&&!e&&t.createElement(r.Flex,{marginLeft:"spacingM"},t.createElement(r.TextLink,{as:"button",testId:"rating-editor-clear",onClick:()=>{n(null)}},"Clear"))))}u.defaultProps={isInitiallyDisabled:!0},exports.RatingEditor=u;
|
|
2
|
-
//# sourceMappingURL=field-editor-rating.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-rating.cjs.production.min.js","sources":["../src/RatingRibbon.tsx","../src/RatingEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\n\nimport { IconButton } from '@contentful/f36-components';\nimport { StarIcon } from '@contentful/f36-icons';\nimport { css } from 'emotion';\n\ntype RatingRibbonProps = {\n disabled: boolean;\n stars: number;\n value: number | null | undefined;\n onSelect: (val: number) => void;\n};\n\ntype RatingRibbonState = {\n hovered: null | number;\n};\n\nexport class RatingRibbon extends React.Component<RatingRibbonProps, RatingRibbonState> {\n state = {\n hovered: null,\n };\n\n isSelected = (num: number) => {\n const hovered = this.state.hovered;\n const value = this.props.value;\n\n if (hovered !== null) {\n return num <= hovered;\n }\n if (value) {\n return num <= value;\n }\n return false;\n };\n\n onBlur = () => {\n if (!this.props.disabled) {\n this.setState({ hovered: null });\n }\n };\n\n onFocus = (num: number) => () => {\n if (!this.props.disabled) {\n this.setState({ hovered: num });\n }\n };\n\n render() {\n const items: number[] = [];\n for (let i = 1; i <= this.props.stars; i++) {\n items.push(i);\n }\n\n return (\n <>\n {items.map((num) => (\n <IconButton\n variant=\"transparent\"\n size=\"small\"\n icon={\n <StarIcon\n variant={this.isSelected(num) ? 'primary' : 'muted'}\n className={css({ width: '22px', height: '22px' })}\n />\n }\n data-selected={this.isSelected(num) ? 'true' : 'false'}\n testId=\"rating-editor-star\"\n isDisabled={this.props.disabled}\n key={num}\n onClick={() => {\n this.props.onSelect(num);\n }}\n onKeyDown={(e: React.KeyboardEvent) => {\n if (e.keyCode === 13) {\n this.props.onSelect(num);\n }\n }}\n onMouseOver={this.onFocus(num)}\n onMouseLeave={this.onBlur}\n onFocus={this.onFocus(num)}\n onBlur={this.onBlur}\n aria-label={num.toString()}\n />\n ))}\n </>\n );\n }\n}\n","import * as React from 'react';\n\nimport { TextLink, Flex } from '@contentful/f36-components';\nimport { FieldAPI, ParametersAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport get from 'lodash/get';\n\nimport { RatingRibbon } from './RatingRibbon';\n\n\nexport interface RatingEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n stars?: number;\n };\n };\n}\n\nfunction isValidCount(count?: string | number): count is number {\n return typeof count === 'number' && !isNaN(count) && count > 0;\n}\n\nfunction getStarCount(count?: number | string): number {\n const defaultValue = 5;\n\n if (isValidCount(count)) {\n return Math.round(count);\n } else if (typeof count === 'string') {\n const parsed = parseInt(count, 10);\n return isValidCount(parsed) ? Math.round(parsed) : defaultValue;\n } else {\n return defaultValue;\n }\n}\n\nexport function RatingEditor(props: RatingEditorProps) {\n const { field } = props;\n\n const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));\n\n return (\n <FieldConnector<number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ disabled, value, setValue }) => {\n const clearOption = () => {\n setValue(null);\n };\n\n return (\n <Flex testId=\"rating-editor\" flexDirection=\"row\" marginTop=\"spacingS\">\n <RatingRibbon\n disabled={disabled}\n value={value}\n stars={starsCount}\n onSelect={(num) => {\n setValue(num);\n }}\n />\n {value !== undefined && !disabled && (\n <Flex marginLeft=\"spacingM\">\n <TextLink as=\"button\" testId=\"rating-editor-clear\" onClick={clearOption}>\n Clear\n </TextLink>\n </Flex>\n )}\n </Flex>\n );\n }}\n </FieldConnector>\n );\n}\n\nRatingEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["RatingRibbon","React","state","hovered","isSelected","num","this","value","props","onBlur","disabled","setState","onFocus","render","items","i","stars","push","map","IconButton","variant","size","icon","StarIcon","className","css","width","height","testId","isDisabled","key","onClick","onSelect","onKeyDown","e","keyCode","onMouseOver","onMouseLeave","toString","isValidCount","count","isNaN","RatingEditor","field","starsCount","Math","round","parsed","parseInt","getStarCount","get","parameters","FieldConnector","throttle","isInitiallyDisabled","setValue","Flex","flexDirection","marginTop","undefined","marginLeft","TextLink","as","defaultProps"],"mappings":"2TAkBaA,UAAqBC,+CAChCC,MAAQ,CACNC,QAAS,WAGXC,WAAcC,UACNF,EAAUG,KAAKJ,MAAMC,QACrBI,EAAQD,KAAKE,MAAMD,aAET,OAAZJ,EACKE,GAAOF,IAEZI,GACKF,GAAOE,QAKlBE,OAAS,KACFH,KAAKE,MAAME,eACTC,SAAS,CAAER,QAAS,aAI7BS,QAAWP,GAAgB,KACpBC,KAAKE,MAAME,eACTC,SAAS,CA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ACvBT,gBAACuD,QAAKI,WAAW,YACf3D,gBAAC4D,YAASC,GAAG,SAASlC,OAAO,sBAAsBG,QAhBvC,KAClBwB,EAAS,oBA2BnBb,EAAaqB,aAAe,CAC1BT,qBAAqB"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { Component, createElement, Fragment } from 'react';
|
|
2
|
-
import { IconButton, Flex, TextLink } from '@contentful/f36-components';
|
|
3
|
-
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
4
|
-
import get from 'lodash-es/get';
|
|
5
|
-
import { StarIcon } from '@contentful/f36-icons';
|
|
6
|
-
import { css } from 'emotion';
|
|
7
|
-
|
|
8
|
-
class RatingRibbon extends Component {
|
|
9
|
-
constructor(...args) {
|
|
10
|
-
super(...args);
|
|
11
|
-
this.state = {
|
|
12
|
-
hovered: null
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.isSelected = num => {
|
|
16
|
-
const hovered = this.state.hovered;
|
|
17
|
-
const value = this.props.value;
|
|
18
|
-
|
|
19
|
-
if (hovered !== null) {
|
|
20
|
-
return num <= hovered;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (value) {
|
|
24
|
-
return num <= value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return false;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
this.onBlur = () => {
|
|
31
|
-
if (!this.props.disabled) {
|
|
32
|
-
this.setState({
|
|
33
|
-
hovered: null
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
this.onFocus = num => () => {
|
|
39
|
-
if (!this.props.disabled) {
|
|
40
|
-
this.setState({
|
|
41
|
-
hovered: num
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
render() {
|
|
48
|
-
const items = [];
|
|
49
|
-
|
|
50
|
-
for (let i = 1; i <= this.props.stars; i++) {
|
|
51
|
-
items.push(i);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return createElement(Fragment, null, items.map(num => createElement(IconButton, {
|
|
55
|
-
variant: "transparent",
|
|
56
|
-
size: "small",
|
|
57
|
-
icon: createElement(StarIcon, {
|
|
58
|
-
variant: this.isSelected(num) ? 'primary' : 'muted',
|
|
59
|
-
className: css({
|
|
60
|
-
width: '22px',
|
|
61
|
-
height: '22px'
|
|
62
|
-
})
|
|
63
|
-
}),
|
|
64
|
-
"data-selected": this.isSelected(num) ? 'true' : 'false',
|
|
65
|
-
testId: "rating-editor-star",
|
|
66
|
-
isDisabled: this.props.disabled,
|
|
67
|
-
key: num,
|
|
68
|
-
onClick: () => {
|
|
69
|
-
this.props.onSelect(num);
|
|
70
|
-
},
|
|
71
|
-
onKeyDown: e => {
|
|
72
|
-
if (e.keyCode === 13) {
|
|
73
|
-
this.props.onSelect(num);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
onMouseOver: this.onFocus(num),
|
|
77
|
-
onMouseLeave: this.onBlur,
|
|
78
|
-
onFocus: this.onFocus(num),
|
|
79
|
-
onBlur: this.onBlur,
|
|
80
|
-
"aria-label": num.toString()
|
|
81
|
-
})));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function isValidCount(count) {
|
|
87
|
-
return typeof count === 'number' && !isNaN(count) && count > 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getStarCount(count) {
|
|
91
|
-
const defaultValue = 5;
|
|
92
|
-
|
|
93
|
-
if (isValidCount(count)) {
|
|
94
|
-
return Math.round(count);
|
|
95
|
-
} else if (typeof count === 'string') {
|
|
96
|
-
const parsed = parseInt(count, 10);
|
|
97
|
-
return isValidCount(parsed) ? Math.round(parsed) : defaultValue;
|
|
98
|
-
} else {
|
|
99
|
-
return defaultValue;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function RatingEditor(props) {
|
|
104
|
-
const {
|
|
105
|
-
field
|
|
106
|
-
} = props;
|
|
107
|
-
const starsCount = getStarCount(get(props.parameters, ['instance', 'stars']));
|
|
108
|
-
return createElement(FieldConnector, {
|
|
109
|
-
throttle: 0,
|
|
110
|
-
field: field,
|
|
111
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
112
|
-
}, ({
|
|
113
|
-
disabled,
|
|
114
|
-
value,
|
|
115
|
-
setValue
|
|
116
|
-
}) => {
|
|
117
|
-
const clearOption = () => {
|
|
118
|
-
setValue(null);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return createElement(Flex, {
|
|
122
|
-
testId: "rating-editor",
|
|
123
|
-
flexDirection: "row",
|
|
124
|
-
marginTop: "spacingS"
|
|
125
|
-
}, createElement(RatingRibbon, {
|
|
126
|
-
disabled: disabled,
|
|
127
|
-
value: value,
|
|
128
|
-
stars: starsCount,
|
|
129
|
-
onSelect: num => {
|
|
130
|
-
setValue(num);
|
|
131
|
-
}
|
|
132
|
-
}), value !== undefined && !disabled && createElement(Flex, {
|
|
133
|
-
marginLeft: "spacingM"
|
|
134
|
-
}, createElement(TextLink, {
|
|
135
|
-
as: "button",
|
|
136
|
-
testId: "rating-editor-clear",
|
|
137
|
-
onClick: clearOption
|
|
138
|
-
}, "Clear")));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
RatingEditor.defaultProps = {
|
|
142
|
-
isInitiallyDisabled: true
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export { RatingEditor };
|
|
146
|
-
//# sourceMappingURL=field-editor-rating.esm.js.map
|