@contentful/field-editor-rating 1.6.12 → 1.6.14

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.
@@ -73,16 +73,15 @@ function getStarCount(count) {
73
73
  return defaultValue;
74
74
  }
75
75
  }
76
- function RatingEditor(props) {
77
- const { field } = props;
78
- const starsCount = getStarCount((0, _get.default)(props.parameters, [
76
+ function RatingEditor({ field, parameters, isInitiallyDisabled = true }) {
77
+ const starsCount = getStarCount((0, _get.default)(parameters, [
79
78
  'instance',
80
79
  'stars'
81
80
  ]));
82
81
  return /*#__PURE__*/ _react.createElement(_fieldeditorshared.FieldConnector, {
83
82
  debounce: 0,
84
83
  field: field,
85
- isInitiallyDisabled: props.isInitiallyDisabled
84
+ isInitiallyDisabled: isInitiallyDisabled
86
85
  }, ({ disabled, value, setValue })=>{
87
86
  const clearOption = ()=>{
88
87
  setValue(null);
@@ -107,6 +106,3 @@ function RatingEditor(props) {
107
106
  }, "Clear")));
108
107
  });
109
108
  }
110
- RatingEditor.defaultProps = {
111
- isInitiallyDisabled: true
112
- };
@@ -76,7 +76,7 @@ describe('RatingEditor', ()=>{
76
76
  }));
77
77
  expect(getAllByTestId('rating-editor-star')).toHaveLength(20);
78
78
  });
79
- it('should should setValue by clicking on a item and removeValue by clicking on clear', ()=>{
79
+ it('should setValue by clicking on a item and removeValue by clicking on clear', ()=>{
80
80
  const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
81
81
  jest.spyOn(field, 'setValue');
82
82
  jest.spyOn(field, 'removeValue');
@@ -92,11 +92,11 @@ describe('RatingEditor', ()=>{
92
92
  expect(queryByTestId('rating-editor-clean')).not.toBeInTheDocument();
93
93
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(0);
94
94
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(5);
95
- _react1.fireEvent.click($stars[4]);
95
+ _react1.fireEvent.mouseDown($stars[4]);
96
96
  expect(field.setValue).toHaveBeenCalledWith(5);
97
97
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(5);
98
98
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(0);
99
- _react1.fireEvent.click($stars[0]);
99
+ _react1.fireEvent.mouseDown($stars[0]);
100
100
  expect(field.setValue).toHaveBeenCalledWith(1);
101
101
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(1);
102
102
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(4);
@@ -92,8 +92,10 @@ class RatingRibbon extends _react.Component {
92
92
  testId: "rating-editor-star",
93
93
  isDisabled: this.props.disabled,
94
94
  key: num,
95
- onClick: ()=>{
96
- this.props.onSelect(num);
95
+ onMouseDown: (e)=>{
96
+ if (e.button === 0) {
97
+ this.props.onSelect(num);
98
+ }
97
99
  },
98
100
  onKeyDown: (e)=>{
99
101
  if (e.keyCode === 13) {
@@ -17,16 +17,15 @@ function getStarCount(count) {
17
17
  return defaultValue;
18
18
  }
19
19
  }
20
- export function RatingEditor(props) {
21
- const { field } = props;
22
- const starsCount = getStarCount(get(props.parameters, [
20
+ export function RatingEditor({ field, parameters, isInitiallyDisabled = true }) {
21
+ const starsCount = getStarCount(get(parameters, [
23
22
  'instance',
24
23
  'stars'
25
24
  ]));
26
25
  return /*#__PURE__*/ React.createElement(FieldConnector, {
27
26
  debounce: 0,
28
27
  field: field,
29
- isInitiallyDisabled: props.isInitiallyDisabled
28
+ isInitiallyDisabled: isInitiallyDisabled
30
29
  }, ({ disabled, value, setValue })=>{
31
30
  const clearOption = ()=>{
32
31
  setValue(null);
@@ -51,6 +50,3 @@ export function RatingEditor(props) {
51
50
  }, "Clear")));
52
51
  });
53
52
  }
54
- RatingEditor.defaultProps = {
55
- isInitiallyDisabled: true
56
- };
@@ -31,7 +31,7 @@ describe('RatingEditor', ()=>{
31
31
  }));
32
32
  expect(getAllByTestId('rating-editor-star')).toHaveLength(20);
33
33
  });
34
- it('should should setValue by clicking on a item and removeValue by clicking on clear', ()=>{
34
+ it('should setValue by clicking on a item and removeValue by clicking on clear', ()=>{
35
35
  const [field] = createFakeFieldAPI((field)=>{
36
36
  jest.spyOn(field, 'setValue');
37
37
  jest.spyOn(field, 'removeValue');
@@ -47,11 +47,11 @@ describe('RatingEditor', ()=>{
47
47
  expect(queryByTestId('rating-editor-clean')).not.toBeInTheDocument();
48
48
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(0);
49
49
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(5);
50
- fireEvent.click($stars[4]);
50
+ fireEvent.mouseDown($stars[4]);
51
51
  expect(field.setValue).toHaveBeenCalledWith(5);
52
52
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(5);
53
53
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(0);
54
- fireEvent.click($stars[0]);
54
+ fireEvent.mouseDown($stars[0]);
55
55
  expect(field.setValue).toHaveBeenCalledWith(1);
56
56
  expect(container.querySelectorAll('[data-selected="true"]')).toHaveLength(1);
57
57
  expect(container.querySelectorAll('[data-selected="false"]')).toHaveLength(4);
@@ -36,8 +36,10 @@ export class RatingRibbon extends React.Component {
36
36
  testId: "rating-editor-star",
37
37
  isDisabled: this.props.disabled,
38
38
  key: num,
39
- onClick: ()=>{
40
- this.props.onSelect(num);
39
+ onMouseDown: (e)=>{
40
+ if (e.button === 0) {
41
+ this.props.onSelect(num);
42
+ }
41
43
  },
42
44
  onKeyDown: (e)=>{
43
45
  if (e.keyCode === 13) {
@@ -16,9 +16,4 @@ export interface RatingEditorProps {
16
16
  stars?: number;
17
17
  }, Record<string, any>>;
18
18
  }
19
- export declare function RatingEditor(props: RatingEditorProps): React.JSX.Element;
20
- export declare namespace RatingEditor {
21
- var defaultProps: {
22
- isInitiallyDisabled: boolean;
23
- };
24
- }
19
+ export declare function RatingEditor({ field, parameters, isInitiallyDisabled }: RatingEditorProps): React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rating",
3
- "version": "1.6.12",
3
+ "version": "1.6.14",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@contentful/f36-components": "^5.4.1",
40
40
  "@contentful/f36-tokens": "^5.1.0",
41
- "@contentful/field-editor-shared": "^2.13.5",
41
+ "@contentful/field-editor-shared": "^2.13.6",
42
42
  "emotion": "^10.0.17",
43
43
  "lodash": "^4.17.15"
44
44
  },
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "registry": "https://npm.pkg.github.com/"
55
55
  },
56
- "gitHead": "0534746626483359387c34f48952d76f90be6e1f"
56
+ "gitHead": "f679be8ac8868788ca52d88939ae63d3ea046775"
57
57
  }