@redocly/theme 0.25.3 → 0.26.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.
Files changed (72) hide show
  1. package/lib/components/Feedback/Comment.d.ts +1 -1
  2. package/lib/components/Feedback/Comment.js +28 -9
  3. package/lib/components/Feedback/Emotions.js +8 -25
  4. package/lib/components/Feedback/Feedback.js +6 -0
  5. package/lib/components/Feedback/Mood.js +115 -47
  6. package/lib/components/Feedback/Rating.d.ts +1 -0
  7. package/lib/components/Feedback/Rating.js +81 -42
  8. package/lib/components/Feedback/Reasons.d.ts +1 -1
  9. package/lib/components/Feedback/Reasons.js +4 -16
  10. package/lib/components/Feedback/Scale.d.ts +4 -0
  11. package/lib/components/Feedback/Scale.js +178 -0
  12. package/lib/components/Feedback/Sentiment.js +105 -35
  13. package/lib/components/Feedback/Stars.d.ts +8 -0
  14. package/lib/components/Feedback/Stars.js +54 -0
  15. package/lib/components/Feedback/Thumbs.d.ts +2 -6
  16. package/lib/components/Feedback/Thumbs.js +9 -46
  17. package/lib/components/Feedback/index.d.ts +1 -0
  18. package/lib/components/Feedback/index.js +3 -1
  19. package/lib/components/Feedback/types.d.ts +26 -5
  20. package/lib/components/Feedback/useReportDialog.js +3 -1
  21. package/lib/components/Markdown/MarkdownLayout.js +1 -0
  22. package/lib/config.d.ts +7 -4
  23. package/lib/config.js +3 -2
  24. package/lib/icons/CheckboxIcon/CheckboxIcon.js +3 -3
  25. package/lib/icons/ColorModeIcon/ColorModeIcon.js +4 -4
  26. package/lib/icons/DissatisfiedIcon/DissatisfiedIcon.js +5 -5
  27. package/lib/icons/NeutralIcon/NeutralIcon.js +5 -5
  28. package/lib/icons/RadioCheckButtonIcon/RadioCheckButtonIcon.d.ts +4 -0
  29. package/lib/icons/RadioCheckButtonIcon/RadioCheckButtonIcon.js +16 -0
  30. package/lib/icons/RadioCheckButtonIcon/index.d.ts +1 -0
  31. package/lib/icons/RadioCheckButtonIcon/index.js +18 -0
  32. package/lib/icons/SatisfiedIcon/SatisfiedIcon.js +5 -5
  33. package/lib/icons/ThumbDownIcon/ThumbDownIcon.d.ts +4 -0
  34. package/lib/icons/ThumbDownIcon/ThumbDownIcon.js +14 -0
  35. package/lib/icons/ThumbDownIcon/index.d.ts +1 -0
  36. package/lib/icons/ThumbDownIcon/index.js +18 -0
  37. package/lib/icons/ThumbUpIcon/ThumbUpIcon.d.ts +4 -0
  38. package/lib/icons/ThumbUpIcon/ThumbUpIcon.js +14 -0
  39. package/lib/icons/ThumbUpIcon/index.d.ts +1 -0
  40. package/lib/icons/ThumbUpIcon/index.js +18 -0
  41. package/lib/types/portal/src/shared/constants.d.ts +2 -1
  42. package/lib/types/portal/src/shared/constants.js +1 -0
  43. package/lib/types/portal/src/shared/types/feedback.d.ts +2 -2
  44. package/package.json +2 -2
  45. package/src/components/Feedback/Comment.tsx +53 -20
  46. package/src/components/Feedback/Emotions.tsx +11 -32
  47. package/src/components/Feedback/Feedback.tsx +13 -1
  48. package/src/components/Feedback/Mood.tsx +164 -80
  49. package/src/components/Feedback/Rating.tsx +106 -79
  50. package/src/components/Feedback/Reasons.tsx +3 -19
  51. package/src/components/Feedback/Scale.tsx +229 -0
  52. package/src/components/Feedback/Sentiment.tsx +150 -56
  53. package/src/components/Feedback/Stars.tsx +51 -0
  54. package/src/components/Feedback/Thumbs.tsx +9 -106
  55. package/src/components/Feedback/index.ts +1 -0
  56. package/src/components/Feedback/types.ts +23 -4
  57. package/src/components/Feedback/useReportDialog.ts +3 -1
  58. package/src/components/Markdown/MarkdownLayout.tsx +1 -0
  59. package/src/config.ts +3 -2
  60. package/src/icons/CheckboxIcon/CheckboxIcon.tsx +4 -4
  61. package/src/icons/ColorModeIcon/ColorModeIcon.tsx +4 -4
  62. package/src/icons/DissatisfiedIcon/DissatisfiedIcon.tsx +5 -15
  63. package/src/icons/NeutralIcon/NeutralIcon.tsx +5 -14
  64. package/src/icons/RadioCheckButtonIcon/RadioCheckButtonIcon.tsx +19 -0
  65. package/src/icons/RadioCheckButtonIcon/index.ts +1 -0
  66. package/src/icons/SatisfiedIcon/SatisfiedIcon.tsx +5 -9
  67. package/src/icons/ThumbDownIcon/ThumbDownIcon.tsx +15 -0
  68. package/src/icons/ThumbDownIcon/index.ts +1 -0
  69. package/src/icons/ThumbUpIcon/ThumbUpIcon.tsx +15 -0
  70. package/src/icons/ThumbUpIcon/index.ts +1 -0
  71. package/src/types/portal/src/shared/constants.ts +1 -0
  72. package/src/types/portal/src/shared/types/feedback.ts +2 -2
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { CommentProps } from '../../components/Feedback';
3
- export declare const Comment: ({ settings, onSubmit, onCancel, className }: CommentProps) => JSX.Element;
3
+ export declare const Comment: ({ settings, onSubmit, onCancel, className, standAlone, }: CommentProps) => JSX.Element;
@@ -31,7 +31,9 @@ const React = __importStar(require("react"));
31
31
  const styled_components_1 = __importDefault(require("styled-components"));
32
32
  const Button_1 = require("../../components/Button/Button");
33
33
  const hooks_1 = require("../../mocks/hooks");
34
- const Comment = ({ settings, onSubmit, onCancel, className }) => {
34
+ const RadioCheckButtonIcon_1 = require("../../icons/RadioCheckButtonIcon");
35
+ const media_css_1 = require("../../mocks/media-css");
36
+ const Comment = ({ settings, onSubmit, onCancel, className, standAlone = true, }) => {
35
37
  const { label, submitText } = settings || {};
36
38
  const [text, setText] = React.useState('');
37
39
  const [submitValue, setSubmitValue] = React.useState('');
@@ -43,25 +45,42 @@ const Comment = ({ settings, onSubmit, onCancel, className }) => {
43
45
  onSubmit({ comment: text });
44
46
  };
45
47
  const handleTextAreaChange = (e) => {
46
- setText(e.target.value);
48
+ const commentValue = e.target.value;
49
+ setText(commentValue);
50
+ if (!standAlone) {
51
+ onSubmit({ comment: commentValue });
52
+ }
47
53
  };
48
54
  if (submitValue) {
49
- return (React.createElement(Wrapper, { className: className },
50
- React.createElement(Label, { "data-translation-key": "theme.feedback.settings.comment.submitText" }, translate('theme.feedback.settings.comment.submitText', submitText || 'Thank you for helping improve our documentation!'))));
55
+ return (React.createElement(StateWrapper, { className: className },
56
+ React.createElement(Label, { "data-translation-key": "theme.feedback.settings.comment.submitText" }, translate('theme.feedback.settings.comment.submitText', submitText || 'Thank you for helping improve our documentation!')),
57
+ React.createElement(RadioCheckButtonIcon_1.RadioCheckButtonIcon, null)));
51
58
  }
52
- return (React.createElement(Wrapper, { "data-component-name": "Feedback/Comment", className: className },
59
+ return (React.createElement(Wrapper, { "data-component-name": "Feedback/Comment", className: className, style: standAlone ? { width: '424px', padding: '16px 24px' } : { width: 'auto' } },
53
60
  React.createElement(Label, { "data-translation-key": "theme.feedback.settings.comment.label" }, translate('theme.feedback.settings.comment.label', label || 'Please share your feedback with us.')),
54
61
  React.createElement(TextArea, { rows: 3, onChange: handleTextAreaChange }),
55
- React.createElement(ButtonsContainer, null,
62
+ standAlone && (React.createElement(ButtonsContainer, null,
56
63
  React.createElement(SendButton, { "data-translation-key": "theme.feedback.settings.comment.send", onClick: send }, translate('theme.feedback.settings.comment.send', 'Send')),
57
- onCancel && (React.createElement(CancelButton, { "data-translation-key": "theme.feedback.settings.comment.cancel", onClick: onCancel }, translate('theme.feedback.settings.comment.cancel', 'Cancel'))))));
64
+ onCancel && (React.createElement(CancelButton, { "data-translation-key": "theme.feedback.settings.comment.cancel", onClick: onCancel }, translate('theme.feedback.settings.comment.cancel', 'Cancel')))))));
58
65
  };
59
66
  exports.Comment = Comment;
60
67
  const Wrapper = styled_components_1.default.div `
61
68
  font-family: var(--font-family-base);
62
69
  display: flex;
63
70
  flex-direction: column;
64
- width: 100%;
71
+ justify-content: space-between;
72
+ border-radius: 8px;
73
+ background: var(--bg-raised);
74
+ `;
75
+ const StateWrapper = (0, styled_components_1.default)(Wrapper) `
76
+ flex-direction: row;
77
+ align-items: center;
78
+ width: 424px;
79
+ padding: 16px 24px;
80
+
81
+ @media screen and (max-width: ${media_css_1.breakpoints.small}) {
82
+ width: 100%;
83
+ }
65
84
  `;
66
85
  const Label = styled_components_1.default.h3 `
67
86
  font-family: var(--h3-font-family);
@@ -81,7 +100,7 @@ const TextArea = styled_components_1.default.textarea `
81
100
  `;
82
101
  const ButtonsContainer = styled_components_1.default.div `
83
102
  display: flex;
84
- justify-content: start;
103
+ justify-content: end;
85
104
  `;
86
105
  const SendButton = (0, styled_components_1.default)(Button_1.Button).attrs(() => ({
87
106
  color: 'primary',
@@ -31,40 +31,23 @@ const React = __importStar(require("react"));
31
31
  const styled_components_1 = __importDefault(require("styled-components"));
32
32
  const icons_1 = require("../../icons");
33
33
  const Satisfied = () => {
34
- return (React.createElement(Wrapper, null,
35
- React.createElement(Icon, null,
36
- React.createElement(icons_1.SatisfiedIcon, null))));
34
+ return (React.createElement(Icon, null,
35
+ React.createElement(icons_1.SatisfiedIcon, null)));
37
36
  };
38
37
  exports.Satisfied = Satisfied;
39
38
  const Dissatisfied = () => {
40
- return (React.createElement(Wrapper, null,
41
- React.createElement(Icon, null,
42
- React.createElement(icons_1.DissatisfiedIcon, null))));
39
+ return (React.createElement(Icon, null,
40
+ React.createElement(icons_1.DissatisfiedIcon, null)));
43
41
  };
44
42
  exports.Dissatisfied = Dissatisfied;
45
43
  const Neutral = () => {
46
- return (React.createElement(Wrapper, null,
47
- React.createElement(Icon, null,
48
- React.createElement(icons_1.NeutralIcon, null))));
44
+ return (React.createElement(Icon, null,
45
+ React.createElement(icons_1.NeutralIcon, null)));
49
46
  };
50
47
  exports.Neutral = Neutral;
51
- const Wrapper = styled_components_1.default.div `
52
- font-family: var(--font-family-base);
53
- display: flex;
54
- color: var(--color-info-text);
55
- &:hover {
56
- color: var(--color-info-text-active);
57
- svg {
58
- > g {
59
- fill: var(--color-info-text-active);
60
- }
61
- }
62
- }
63
- `;
64
48
  const Icon = styled_components_1.default.div `
65
- width: 16px;
66
- height: 16px;
67
- margin-right: 5px;
49
+ display: flex;
50
+ align-items: center;
68
51
  > svg {
69
52
  > g {
70
53
  fill: var(--color-info-text);
@@ -60,6 +60,12 @@ const Feedback = (props) => {
60
60
  submitFeedback({ type: 'mood', values, path });
61
61
  telemetry_1.telemetry.send('feedback_sent', { type: 'mood' });
62
62
  } })));
63
+ case 'scale':
64
+ return (React.createElement(Wrapper, null,
65
+ React.createElement(Feedback_1.Scale, { settings: settings, onSubmit: (values) => {
66
+ submitFeedback({ type: 'scale', values, path });
67
+ telemetry_1.telemetry.send('feedback_sent', { type: 'scale' });
68
+ } })));
63
69
  case 'comment':
64
70
  return (React.createElement(Wrapper, null,
65
71
  React.createElement(Feedback_1.Comment, { settings: settings, onSubmit: (values) => {
@@ -28,10 +28,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Mood = exports.MOOD_STATES = void 0;
30
30
  const React = __importStar(require("react"));
31
+ const react_1 = require("react");
31
32
  const styled_components_1 = __importDefault(require("styled-components"));
32
33
  const hooks_1 = require("../../mocks/hooks");
33
34
  const Emotions_1 = require("../../components/Feedback/Emotions");
34
35
  const Feedback_1 = require("../../components/Feedback");
36
+ const RadioCheckButtonIcon_1 = require("../../icons/RadioCheckButtonIcon");
37
+ const components_1 = require("../../components");
38
+ const media_css_1 = require("../../mocks/media-css");
35
39
  var MOOD_STATES;
36
40
  (function (MOOD_STATES) {
37
41
  MOOD_STATES["SATISFIED"] = "satisfied";
@@ -45,69 +49,133 @@ const Mood = ({ settings, onSubmit, className }) => {
45
49
  const [comment, setComment] = React.useState('');
46
50
  const [reasons, setReasons] = React.useState([]);
47
51
  const { translate } = (0, hooks_1.useTranslate)();
48
- if (score && (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.enable) && !reasons.length) {
49
- const { label: reasonsLabel, items, multi } = reasonsSettings;
50
- const buttonText = (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable) ? 'Next' : 'Send';
51
- return (React.createElement(Feedback_1.Reasons, { onSubmit: ({ reasons }) => setReasons(reasons), settings: { label: reasonsLabel, items, multi, buttonText } }));
52
- }
53
- if (score && (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable) && !comment) {
54
- const renderCommentLabel = (score) => {
55
- switch (score) {
56
- case MOOD_STATES.SATISFIED:
57
- return translate('theme.feedback.settings.comment.satisfiedLabel', commentSettings.satisfiedLabel || 'What was most helpful?');
58
- case MOOD_STATES.NEUTRAL:
59
- return translate('theme.feedback.settings.comment.neutralLabel', commentSettings.neutralLabel || 'What can we improve?');
60
- case MOOD_STATES.DISSATISFIED:
61
- return translate('theme.feedback.settings.comment.dissatisfiedLabel', commentSettings.dissatisfiedLabel || 'What can we improve?');
62
- default:
63
- return translate('theme.feedback.settings.comment.satisfiedLabel', 'What can we improve?');
64
- }
65
- };
66
- return (React.createElement(Feedback_1.Comment, { onSubmit: ({ comment }) => setComment(comment), settings: { label: renderCommentLabel(score) } }));
67
- }
68
- if (score) {
69
- if (!isSubmitted) {
70
- onSubmit({
71
- score,
72
- comment,
73
- reasons,
74
- });
75
- setIsSubmitted(true);
52
+ const renderCommentLabel = (score) => {
53
+ if (!(commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable))
54
+ return '';
55
+ switch (score) {
56
+ case MOOD_STATES.SATISFIED:
57
+ return translate('theme.feedback.settings.comment.satisfiedLabel', commentSettings.satisfiedLabel || 'What was most helpful?');
58
+ case MOOD_STATES.NEUTRAL:
59
+ return translate('theme.feedback.settings.comment.neutralLabel', commentSettings.neutralLabel || 'What can we improve?');
60
+ case MOOD_STATES.DISSATISFIED:
61
+ return translate('theme.feedback.settings.comment.dissatisfiedLabel', commentSettings.dissatisfiedLabel || 'What can we improve?');
62
+ default:
63
+ return translate('theme.feedback.settings.comment.satisfiedLabel', 'What can we improve?');
64
+ }
65
+ };
66
+ const displayReasons = !!score && (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.enable);
67
+ const displayComment = !!score && (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable);
68
+ const displaySubmitBnt = !!score && (displayReasons || displayComment);
69
+ const onSubmitMoodForm = () => {
70
+ onSubmit({
71
+ score,
72
+ comment,
73
+ reasons,
74
+ });
75
+ setIsSubmitted(true);
76
+ };
77
+ (0, react_1.useEffect)(() => {
78
+ if (score && !displayComment && !displayReasons) {
79
+ onSubmitMoodForm();
76
80
  }
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [score, displayComment, displayReasons]);
83
+ if (isSubmitted) {
77
84
  return (React.createElement(Wrapper, null,
78
- React.createElement(Label, { "data-translation-key": "theme.feedback.settings.submitText" }, translate('theme.feedback.settings.submitText', submitText || 'Thank you for your feedback!'))));
85
+ React.createElement(Label, { "data-translation-key": "theme.feedback.settings.submitText" }, translate('theme.feedback.settings.submitText', submitText || 'Thank you for helping improve our documentation!')),
86
+ React.createElement(RadioCheckButtonIcon_1.RadioCheckButtonIcon, null)));
79
87
  }
80
88
  return (React.createElement(Wrapper, { "data-component-name": "Feedback/Mood", className: className },
81
- React.createElement(Label, { "data-translation-key": "theme.feedback.settings.label" }, translate('theme.feedback.settings.label', label || 'Was this page helpful?')),
82
- React.createElement(Vote, { onClick: () => {
83
- setScore(MOOD_STATES.DISSATISFIED);
84
- } },
85
- React.createElement(Emotions_1.Dissatisfied, null)),
86
- React.createElement(Vote, { onClick: () => {
87
- setScore(MOOD_STATES.NEUTRAL);
88
- } },
89
- React.createElement(Emotions_1.Neutral, null)),
90
- React.createElement(Vote, { onClick: () => {
91
- setScore(MOOD_STATES.SATISFIED);
92
- } },
93
- React.createElement(Emotions_1.Satisfied, null))));
89
+ React.createElement(StyledForm, null,
90
+ React.createElement(StyledFormMandatoryFields, null,
91
+ React.createElement(Label, { "data-translation-key": "theme.feedback.settings.label" }, translate('theme.feedback.settings.label', label || 'Was this page helpful?')),
92
+ React.createElement(StyledMandatoryFieldContainer, null,
93
+ React.createElement(React.Fragment, null,
94
+ React.createElement(Vote, { className: `${score === MOOD_STATES.DISSATISFIED ? 'active' : ''}`, onClick: () => {
95
+ setScore(MOOD_STATES.DISSATISFIED);
96
+ } },
97
+ React.createElement(Emotions_1.Dissatisfied, null)),
98
+ React.createElement(Vote, { className: `${score === MOOD_STATES.NEUTRAL ? 'active' : ''}`, onClick: () => {
99
+ setScore(MOOD_STATES.NEUTRAL);
100
+ } },
101
+ React.createElement(Emotions_1.Neutral, null)),
102
+ React.createElement(Vote, { className: `${score === MOOD_STATES.SATISFIED ? 'active' : ''}`, onClick: () => {
103
+ setScore(MOOD_STATES.SATISFIED);
104
+ } },
105
+ React.createElement(Emotions_1.Satisfied, null))))),
106
+ React.createElement(StyledFormOptionalFields, null,
107
+ displayReasons && (React.createElement(Feedback_1.Reasons, { settings: {
108
+ label: reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.label,
109
+ items: (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.items) || [],
110
+ multi: reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.multi,
111
+ }, onChange: setReasons })),
112
+ displayComment && (React.createElement(Feedback_1.Comment, { standAlone: false, onSubmit: ({ comment }) => setComment(comment), settings: { label: renderCommentLabel(score) } }))),
113
+ displaySubmitBnt && (React.createElement(ButtonsContainer, null,
114
+ React.createElement(SubmitButton, { onClick: onSubmitMoodForm }, "Submit"))))));
94
115
  };
95
116
  exports.Mood = Mood;
96
117
  const Wrapper = styled_components_1.default.div `
97
118
  font-family: var(--font-family-base);
98
119
  display: flex;
120
+ justify-content: space-between;
99
121
  align-items: center;
122
+ padding: 16px 24px;
123
+ width: 424px;
124
+ border-radius: 8px;
125
+ background: var(--bg-raised);
126
+
127
+ @media screen and (max-width: ${media_css_1.breakpoints.small}) {
128
+ width: 100%;
129
+ }
100
130
  `;
101
131
  const Label = styled_components_1.default.h3 `
102
- font-family: var(--h3-font-family);
103
- font-weight: var(--h3-font-weight);
104
- font-size: var(--h3-font-size);
105
- line-height: var(--h3-line-height);
106
- color: var(--h3-text-color);
107
132
  margin-right: 15px;
133
+ font-family: var(--h4-font-family);
134
+ font-weight: var(--h4-font-weight);
135
+ font-size: var(--h4-font-size);
136
+ line-height: var(--h4-line-height);
137
+ color: var(--h3-text-color);
108
138
  `;
109
139
  const Vote = styled_components_1.default.div `
110
140
  cursor: pointer;
111
141
  margin: 0 10px;
142
+ color: var(--text-description);
143
+ &.active {
144
+ color: var(--text-primary);
145
+ }
146
+ &:hover {
147
+ color: var(--text-primary);
148
+ svg {
149
+ > g {
150
+ fill: var(--text-primary);
151
+ }
152
+ }
153
+ }
154
+ `;
155
+ const SubmitButton = (0, styled_components_1.default)(components_1.Button).attrs(() => ({
156
+ color: 'primary',
157
+ })) `
158
+ width: 100px;
159
+ margin-left: 0;
160
+ margin-right: 0;
161
+ `;
162
+ const ButtonsContainer = styled_components_1.default.div `
163
+ display: flex;
164
+ justify-content: end;
165
+ `;
166
+ const StyledForm = styled_components_1.default.form `
167
+ width: 100%;
168
+ `;
169
+ const StyledFormOptionalFields = styled_components_1.default.div `
170
+ display: flex;
171
+ flex-flow: column;
172
+ `;
173
+ const StyledFormMandatoryFields = styled_components_1.default.div `
174
+ display: flex;
175
+ justify-content: space-between;
176
+ `;
177
+ const StyledMandatoryFieldContainer = styled_components_1.default.div `
178
+ display: flex;
179
+ align-items: center;
112
180
  `;
113
181
  //# sourceMappingURL=Mood.js.map
@@ -1,3 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import type { RatingProps } from '../../components/Feedback';
3
+ export declare const FEEDBACK_MAX_RATING = 5;
3
4
  export declare const Rating: ({ settings, onSubmit, className }: RatingProps) => JSX.Element;
@@ -26,69 +26,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Rating = void 0;
29
+ exports.Rating = exports.FEEDBACK_MAX_RATING = void 0;
30
30
  const React = __importStar(require("react"));
31
31
  const styled_components_1 = __importDefault(require("styled-components"));
32
+ const react_1 = require("react");
32
33
  const Feedback_1 = require("../../components/Feedback");
34
+ const components_1 = require("../../components");
33
35
  const hooks_1 = require("../../mocks/hooks");
36
+ const RadioCheckButtonIcon_1 = require("../../icons/RadioCheckButtonIcon");
37
+ const media_css_1 = require("../../mocks/media-css");
38
+ const Stars_1 = require("./Stars");
39
+ exports.FEEDBACK_MAX_RATING = 5;
34
40
  const Rating = ({ settings, onSubmit, className }) => {
35
- const { label, max, submitText, comment: commentSettings, reasons: reasonsSettings, } = settings || {};
41
+ const { label, submitText, comment: commentSettings, reasons: reasonsSettings } = settings || {};
36
42
  const [isSubmitted, setIsSubmitted] = React.useState(false);
37
43
  const [score, setScore] = React.useState(0);
38
- const [comment, setComment] = React.useState('');
39
44
  const [reasons, setReasons] = React.useState([]);
45
+ const [comment, setComment] = React.useState('');
40
46
  const { translate } = (0, hooks_1.useTranslate)();
41
- const maxRating = max || 5;
42
- if (score && (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.enable) && !reasons.length) {
43
- const { label: reasonsLabel, items, multi } = reasonsSettings;
44
- const buttonText = (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable) ? 'Next' : 'Send';
45
- return (React.createElement(Feedback_1.Reasons, { onSubmit: ({ reasons }) => setReasons(reasons), settings: { label: reasonsLabel, items, multi, buttonText } }));
46
- }
47
- if (score && (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable) && !comment) {
48
- return (React.createElement(Feedback_1.Comment, { onSubmit: ({ comment }) => setComment(comment), settings: { label: commentSettings.label } }));
49
- }
50
- if (score) {
51
- if (!isSubmitted) {
52
- onSubmit({
53
- score,
54
- comment,
55
- reasons,
56
- max: maxRating,
57
- });
58
- setIsSubmitted(true);
47
+ const onSubmitRatingForm = () => {
48
+ onSubmit({
49
+ score,
50
+ comment,
51
+ reasons,
52
+ max: exports.FEEDBACK_MAX_RATING,
53
+ });
54
+ setIsSubmitted(true);
55
+ };
56
+ const displayReasons = !!score && (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.enable);
57
+ const displayComment = !!score && (commentSettings === null || commentSettings === void 0 ? void 0 : commentSettings.enable);
58
+ const displaySubmitBnt = !!score && (displayReasons || displayComment);
59
+ (0, react_1.useEffect)(() => {
60
+ if (score && !displayComment && !displayReasons) {
61
+ onSubmitRatingForm();
59
62
  }
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, [score, displayComment, displayReasons]);
65
+ if (isSubmitted) {
60
66
  return (React.createElement(Wrapper, null,
61
- React.createElement(Label, { "data-translation-key": "theme.feedback.settings.submitText" }, translate('theme.feedback.settings.submitText', submitText || 'Thank you for helping improve our documentation!'))));
67
+ React.createElement(Label, { "data-translation-key": "theme.feedback.settings.submitText" }, translate('theme.feedback.settings.submitText', submitText || 'Thank you for helping improve our documentation!')),
68
+ React.createElement(RadioCheckButtonIcon_1.RadioCheckButtonIcon, null)));
62
69
  }
63
70
  return (React.createElement(Wrapper, { "data-component-name": "Feedback/Rating", className: className },
64
- React.createElement(Label, { "data-translation-key": "theme.feedback.settings.label" }, translate('theme.feedback.settings.label', label || 'How helpful was this page?')),
65
- React.createElement(Stars, { max: maxRating, onSubmit: setScore })));
71
+ React.createElement(StyledForm, null,
72
+ React.createElement(StyledFormMandatoryFields, null,
73
+ React.createElement(Label, { "data-translation-key": "theme.feedback.settings.label" }, translate('theme.feedback.settings.label', label || 'How helpful was this page?')),
74
+ React.createElement(StyledMandatoryFieldContainer, null,
75
+ React.createElement(Stars_1.Stars, { max: exports.FEEDBACK_MAX_RATING, onChange: setScore, value: score }))),
76
+ React.createElement(StyledFormOptionalFields, null,
77
+ displayReasons && (React.createElement(Feedback_1.Reasons, { settings: {
78
+ label: reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.label,
79
+ items: (reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.items) || [],
80
+ multi: reasonsSettings === null || reasonsSettings === void 0 ? void 0 : reasonsSettings.multi,
81
+ }, onChange: setReasons })),
82
+ displayComment && (React.createElement(Feedback_1.Comment, { standAlone: false, onSubmit: ({ comment }) => setComment(comment), settings: { label: commentSettings.label } }))),
83
+ displaySubmitBnt && (React.createElement(ButtonsContainer, null,
84
+ React.createElement(SubmitButton, { onClick: onSubmitRatingForm }, "Submit"))))));
66
85
  };
67
86
  exports.Rating = Rating;
68
- const Stars = ({ max, onSubmit }) => {
69
- const [hovered, setHovered] = React.useState(0);
70
- const stars = [];
71
- for (let index = 1; index <= max; index++) {
72
- stars.push(React.createElement(Star, { key: index, onClick: () => onSubmit(index), onMouseOver: () => setHovered(index), onMouseLeave: () => setHovered(0) },
73
- React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "20", viewBox: "0 0 20 20" }, hovered < index ? (React.createElement("g", { fill: "#e8c002" },
74
- React.createElement("path", { d: "M20 7h-7L10 .5 7 7H0l5.46 5.47-1.64 7 6.18-3.7 6.18 3.73-1.63-7zm-10 6.9-3.76 2.27 1-4.28L3.5 8.5h4.61L10 4.6l1.9 3.9h4.6l-3.73 3.4 1 4.28z" }))) : (React.createElement("g", { fill: "#e8c002" },
75
- React.createElement("path", { d: "M20 7h-7L10 .5 7 7H0l5.46 5.47-1.64 7 6.18-3.7 6.18 3.73-1.63-7z" }))))));
76
- }
77
- return React.createElement(React.Fragment, null, stars);
78
- };
87
+ const StyledForm = styled_components_1.default.form `
88
+ width: 100%;
89
+ `;
90
+ const StyledFormOptionalFields = styled_components_1.default.div `
91
+ display: flex;
92
+ flex-flow: column;
93
+ `;
94
+ const StyledFormMandatoryFields = styled_components_1.default.div `
95
+ display: flex;
96
+ justify-content: space-between;
97
+ `;
98
+ const StyledMandatoryFieldContainer = styled_components_1.default.div `
99
+ display: flex;
100
+ `;
79
101
  const Wrapper = styled_components_1.default.div `
80
102
  display: flex;
103
+ justify-content: space-between;
81
104
  align-items: center;
82
- `;
83
- const Star = styled_components_1.default.span `
84
- cursor: pointer;
105
+ padding: 16px 24px;
106
+ width: 424px;
107
+ border-radius: 8px;
108
+ background: var(--bg-raised);
109
+
110
+ @media screen and (max-width: ${media_css_1.breakpoints.small}) {
111
+ width: 100%;
112
+ }
85
113
  `;
86
114
  const Label = styled_components_1.default.h3 `
87
115
  margin-right: 15px;
88
- font-family: var(--h3-font-family);
89
- font-weight: var(--h3-font-weight);
90
- font-size: var(--h3-font-size);
91
- line-height: var(--h3-line-height);
116
+ font-family: var(--h4-font-family);
117
+ font-weight: var(--h4-font-weight);
118
+ font-size: var(--h4-font-size);
119
+ line-height: var(--h4-line-height);
92
120
  color: var(--h3-text-color);
93
121
  `;
122
+ const SubmitButton = (0, styled_components_1.default)(components_1.Button).attrs(() => ({
123
+ color: 'primary',
124
+ })) `
125
+ width: 100px;
126
+ margin-left: 0;
127
+ margin-right: 0;
128
+ `;
129
+ const ButtonsContainer = styled_components_1.default.div `
130
+ display: flex;
131
+ justify-content: end;
132
+ `;
94
133
  //# sourceMappingURL=Rating.js.map
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import type { ReasonsProps } from '../../components/Feedback';
3
- export declare const Reasons: ({ settings, onSubmit, className }: ReasonsProps) => JSX.Element;
3
+ export declare const Reasons: ({ settings, onChange, className }: ReasonsProps) => JSX.Element;
@@ -29,10 +29,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Reasons = void 0;
30
30
  const React = __importStar(require("react"));
31
31
  const styled_components_1 = __importDefault(require("styled-components"));
32
- const Button_1 = require("../../components/Button/Button");
33
32
  const hooks_1 = require("../../mocks/hooks");
34
- const Reasons = ({ settings, onSubmit, className }) => {
35
- const { label, multi, buttonText, items = [] } = settings;
33
+ const Reasons = ({ settings, onChange, className }) => {
34
+ const { label, multi, items = [] } = settings;
36
35
  const [checkedState, setCheckedState] = React.useState(new Array(items.length).fill(false));
37
36
  const { translate } = (0, hooks_1.useTranslate)();
38
37
  if (!items.length) {
@@ -44,16 +43,13 @@ const Reasons = ({ settings, onSubmit, className }) => {
44
43
  ? checkedState.map((item, index) => (index === position ? !item : item))
45
44
  : items.map((_, idx) => position === idx);
46
45
  setCheckedState(updatedCheckedState);
47
- };
48
- const submitForm = () => {
49
- onSubmit({ reasons: items.filter((_, index) => !!checkedState[index]) });
46
+ onChange(items.filter((_, index) => !!updatedCheckedState[index]));
50
47
  };
51
48
  return (React.createElement(Wrapper, { "data-component-name": "Feedback/Reasons", "data-translation-key": "theme.feedback.settings.reasons.label", className: className },
52
49
  React.createElement(Label, null, translate('theme.feedback.settings.reasons.label', label || 'Which statement describes your thoughts about this page?')),
53
50
  items.map((reason, idx) => (React.createElement(OptionWrapper, { key: reason },
54
51
  React.createElement("input", { type: input_type, value: reason, checked: checkedState[idx], name: "reasons", onChange: () => handleOptionChange(idx) }),
55
- React.createElement("label", { "data-translation-key": `theme.feedback.settings.reasons.items.${idx + 1}`, id: reason, onClick: () => handleOptionChange(idx) }, translate(`theme.feedback.settings.reasons.items.${idx + 1}`, reason))))),
56
- React.createElement(SendButton, { "data-translation-key": "theme.feedback.settings.reasons.send", onClick: submitForm }, translate('theme.feedback.settings.reasons.send', buttonText || 'Send'))));
52
+ React.createElement("label", { "data-translation-key": `theme.feedback.settings.reasons.items.${idx + 1}`, id: reason, onClick: () => handleOptionChange(idx) }, translate(`theme.feedback.settings.reasons.items.${idx + 1}`, reason)))))));
57
53
  };
58
54
  exports.Reasons = Reasons;
59
55
  const Wrapper = styled_components_1.default.div `
@@ -69,14 +65,6 @@ const Label = styled_components_1.default.h3 `
69
65
  color: var(--h3-text-color);
70
66
  margin-right: 15px;
71
67
  `;
72
- const SendButton = (0, styled_components_1.default)(Button_1.Button).attrs(() => ({
73
- color: 'primary',
74
- })) `
75
- width: 100px;
76
- margin-left: 0;
77
- margin-right: 0;
78
- margin-top: 15px;
79
- `;
80
68
  const OptionWrapper = styled_components_1.default.div `
81
69
  margin: 5px 0;
82
70
  display: flex;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { ScaleProps } from '../../components';
3
+ export declare const MAX_SCALE = 10;
4
+ export declare const Scale: ({ settings, onSubmit, className }: ScaleProps) => JSX.Element;