@elice/material-quiz 1.221217.0 → 1.221228.0

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.
@@ -2,63 +2,69 @@ import React from 'react';
2
2
  import { useFormContext, Controller } from 'react-hook-form';
3
3
  import { useIntl } from 'react-intl';
4
4
  import { config, postGlobalRemoteFileAttachmentUpload } from '@elice/api-client';
5
- import { SortableListItem, Input, Dropdown, Flex, Text, Hspace, IconButton, Notification } from '@elice/blocks';
5
+ import { SortableListItem, Input, Dropdown, Flex, Text, Hspace, IconButton, Notification, Tooltip } from '@elice/blocks';
6
6
  import { base } from '@elice/design-tokens';
7
7
  import { eilMathsignMultiplyBasic } from '@elice/icons';
8
8
  import { useMaterialConfigApiClientUpdate } from '@elice/material-shared-utils';
9
9
  import cloneDeep from 'lodash-es/cloneDeep';
10
+ import trim from 'lodash-es/trim';
10
11
  import styled from 'styled-components';
11
12
  import { checkTwoDimensionArray } from '../../utils/checkTwoDimensionArray.js';
12
13
 
13
14
  const SHEET_Z_INDEX = 982;
14
- const OPTION_CONTENT_WIDTH = 205;
15
- const OPTION_GROUP_WIDTH = 180;
16
15
  const DEFAULT_OPTION_VALUE = -1;
16
+ const MIN_OPTION_INFO_COUNT = 2;
17
17
  const FILE_LABEL = 'file-label';
18
18
  const FILE_ACCEPT = '.mp3, .mp4, .mov, .png, .jpg, .svg, .gif';
19
19
  const MAX_FILE_SIZE = 3 * 1024 * 1024;
20
20
  const StyledSortableListItem = styled(SortableListItem).withConfig({
21
21
  componentId: "sc-18q96lt-0"
22
- })(["display:flex;overflow:hidden;flex:1;z-index:", ";height:3.5rem;padding:0 0 0 1rem;border-radius:4px;border:1px solid ", ";background:", ";box-shadow:none;"], SHEET_Z_INDEX + 1, base.color.gray3, base.color.white);
23
- const StyledSortableListItemOption = styled.div.withConfig({
22
+ })(["display:flex;flex:1;z-index:", ";padding:0;background:transparent;box-shadow:none;&:not(:last-child){margin-bottom:0.5rem;}"], SHEET_Z_INDEX + 1);
23
+ const StyledSortableListItemOptionWrapper = styled.div.withConfig({
24
24
  componentId: "sc-18q96lt-1"
25
- })(["height:100%;&:not(:last-child){border-right:1px solid ", ";}"], base.color.gray3);
26
- const StyledQuizOptionContent = styled.div.withConfig({
25
+ })(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border:1px solid ", ";border-radius:4px;background:", ";"], base.color.gray3, base.color.white);
26
+ const StyledSortableListItemOption = styled.div.withConfig({
27
27
  componentId: "sc-18q96lt-2"
28
- })(["display:flex;align-items:center;width:", "px;height:100%;padding:0 1rem;"], OPTION_CONTENT_WIDTH);
29
- const StyledQuizOptionContentLabel = styled.label.withConfig({
28
+ })(["height:3.5rem;&:not(:last-child){border-right:1px solid ", ";}"], base.color.gray3);
29
+ const StyledQuizOptionContent = styled.div.withConfig({
30
30
  componentId: "sc-18q96lt-3"
31
- })(["display:flex;align-items:center;width:", "px;height:100%;padding:0 1rem;cursor:pointer;"], OPTION_CONTENT_WIDTH);
32
- const StyledQuizOptionTextInput = styled(Input).withConfig({
31
+ })(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;"]);
32
+ const StyledQuizOptionContentLabel = styled.label.withConfig({
33
33
  componentId: "sc-18q96lt-4"
34
+ })(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;cursor:pointer;"]);
35
+ const StyledQuizOptionTextInput = styled(Input).withConfig({
36
+ componentId: "sc-18q96lt-5"
34
37
  })(["& > div{border:0;}"]);
35
38
  const StyledQuizOptionContentInput = styled.input.withConfig({
36
- componentId: "sc-18q96lt-5"
39
+ componentId: "sc-18q96lt-6"
37
40
  })(["display:none;"]);
38
41
  const StyledDropdown = styled(Dropdown).withConfig({
39
- componentId: "sc-18q96lt-6"
40
- })(["border:0;&.eb-dropdown__inner{width:", "px;height:3.5rem;}"], OPTION_GROUP_WIDTH); //
42
+ componentId: "sc-18q96lt-7"
43
+ })(["border:0;&.eb-dropdown__inner{width:100%;height:3.5rem;}"]); //
41
44
  //
42
45
  //
43
46
 
44
47
  const OptionGroupAnswerListItem = ({
45
- optionId
48
+ optionId,
49
+ onRemoveItem
46
50
  }) => {
47
- var _a, _b, _c, _d;
51
+ var _a, _b, _c, _d, _e, _f, _g, _h;
48
52
 
49
53
  const intl = useIntl();
50
54
  const {
51
55
  control,
56
+ formState,
52
57
  watch,
53
58
  setValue
54
59
  } = useFormContext();
55
60
  const watchedOptions = watch('options');
56
61
  const watchedAnswerInfo = watch('answerInfo');
57
62
  const watchedGroupList = watch('groups');
58
- const isReady = useMaterialConfigApiClientUpdate(config.init);
63
+ const errorMessage = (_d = (_c = (_b = (_a = formState.errors) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b[optionId]) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.message;
59
64
  const groupIndex = watchedAnswerInfo.findIndex(answer => answer === null || answer === void 0 ? void 0 : answer.includes(optionId));
60
- const isOptionTitle = (_b = (_a = watchedOptions[optionId]) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.length;
61
- const isOptionContent = (_d = (_c = watchedOptions[optionId]) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.length;
65
+ const isReady = useMaterialConfigApiClientUpdate(config.init);
66
+ const isOptionTitle = (_f = (_e = watchedOptions[optionId]) === null || _e === void 0 ? void 0 : _e.title) === null || _f === void 0 ? void 0 : _f.length;
67
+ const isOptionContent = (_h = (_g = watchedOptions[optionId]) === null || _g === void 0 ? void 0 : _g.content) === null || _h === void 0 ? void 0 : _h.length;
62
68
  /**
63
69
  * File upload function.
64
70
  */
@@ -87,122 +93,208 @@ const OptionGroupAnswerListItem = ({
87
93
  }
88
94
 
89
95
  return contentUrl;
90
- }; //
91
- //
92
- //
96
+ };
97
+ /**
98
+ *
99
+ */
93
100
 
94
101
 
95
- if (!checkTwoDimensionArray(watchedAnswerInfo)) {
96
- return null;
97
- }
102
+ const renderOptionTitleInput = () => {
103
+ return React.createElement(StyledSortableListItemOption, {
104
+ style: {
105
+ width: '33.3%'
106
+ }
107
+ }, React.createElement(Controller, {
108
+ control: control,
109
+ name: `options.${optionId}.title`,
110
+ rules: {
111
+ required: {
112
+ value: !isOptionTitle && !isOptionContent,
113
+ message: intl.formatMessage({
114
+ id: 'answer.option.errorMessage'
115
+ })
116
+ },
117
+ validate: e => {
118
+ if (!trim(e).length) {
119
+ return intl.formatMessage({
120
+ id: 'answer.option.errorMessage'
121
+ });
122
+ }
123
+ }
124
+ },
125
+ render: ({
126
+ field
127
+ }) => React.createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
128
+ width: "full"
129
+ }))
130
+ }));
131
+ };
132
+ /**
133
+ *
134
+ */
98
135
 
99
- return React.createElement(StyledSortableListItem, {
100
- index: optionId
101
- }, React.createElement(StyledSortableListItemOption, {
102
- style: {
103
- flex: 1
104
- }
105
- }, React.createElement(Controller, {
106
- control: control,
107
- name: `options.${optionId}.title`,
108
- rules: {
109
- required: {
110
- value: !isOptionTitle && !isOptionContent,
111
- message: intl.formatMessage({
112
- id: 'answer.option.errorMessage'
113
- })
136
+
137
+ const renderOptionContentInput = () => {
138
+ return React.createElement(StyledSortableListItemOption, {
139
+ style: {
140
+ width: '33.3%'
114
141
  }
115
- },
116
- render: ({
117
- field
118
- }) => React.createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
119
- width: "full",
142
+ }, React.createElement(Controller, {
143
+ control: control,
144
+ name: `options.${optionId}.content`,
145
+ render: ({
146
+ field
147
+ }) => React.createElement(React.Fragment, null, field.value ? React.createElement(StyledQuizOptionContent, null, React.createElement(Flex, {
148
+ justify: "space-between",
149
+ align: "center",
150
+ width: "100%",
151
+ height: "100%"
152
+ }, React.createElement(Text, {
153
+ ellipsis: true
154
+ }, React.createElement("a", {
155
+ href: getContentUrl(field.value),
156
+ target: "_blank",
157
+ rel: "noreferrer"
158
+ }, getContentUrl(field.value))), React.createElement(Flex, {
159
+ align: "center"
160
+ }, React.createElement(Hspace, {
161
+ width: 0.5
162
+ }), React.createElement(IconButton, {
163
+ icon: eilMathsignMultiplyBasic,
164
+ role: "gray6",
165
+ size: "micro",
166
+ border: false,
167
+ transparent: true,
168
+ onClick: () => field.onChange('')
169
+ })))) : React.createElement(React.Fragment, null, React.createElement(StyledQuizOptionContentLabel, {
170
+ htmlFor: `${FILE_LABEL}_${optionId}`
171
+ }, React.createElement(Text, {
172
+ role: "primary",
173
+ underline: true
174
+ }, intl.formatMessage({
175
+ id: 'answer.option.file.label'
176
+ }))), React.createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
177
+ id: `${FILE_LABEL}_${optionId}`,
178
+ type: "file",
179
+ accept: FILE_ACCEPT,
180
+ onChange: async e => {
181
+ var _a, _b;
182
+
183
+ const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
184
+
185
+ if (!file) {
186
+ return;
187
+ }
188
+
189
+ if (file.size > MAX_FILE_SIZE) {
190
+ return Notification.error(intl.formatMessage({
191
+ id: 'answer.option.file.errorMessage.maxSize'
192
+ }, {
193
+ size: 3
194
+ }));
195
+ }
196
+
197
+ const contentFileUrl = await uploadContentFile(file);
198
+ field.onChange(`![](${String(contentFileUrl)})`);
199
+ }
200
+ }))))
201
+ }));
202
+ };
203
+ /**
204
+ *
205
+ */
206
+
207
+
208
+ const renderOptionGroupDropdown = () => {
209
+ return React.createElement(StyledSortableListItemOption, {
210
+ style: {
211
+ width: '33.3%'
212
+ }
213
+ }, React.createElement(StyledDropdown, {
214
+ value: groupIndex,
120
215
  onChange: e => {
121
- field.onChange(e.target.value.replace(' ', ''));
216
+ const cloneAnswerList = cloneDeep(watchedAnswerInfo);
217
+ const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
218
+
219
+ if (e === DEFAULT_OPTION_VALUE) {
220
+ return setValue('answerInfo', answerList);
221
+ }
222
+
223
+ if (answerList[e]) {
224
+ answerList[e] = [...answerList[e], optionId];
225
+ } else {
226
+ answerList[e] = [optionId];
227
+ }
228
+
229
+ setValue('answerInfo', answerList);
122
230
  }
123
- }))
124
- })), React.createElement(StyledSortableListItemOption, null, React.createElement(Controller, {
125
- control: control,
126
- name: `options.${optionId}.content`,
127
- render: ({
128
- field
129
- }) => React.createElement(React.Fragment, null, field.value ? React.createElement(StyledQuizOptionContent, null, React.createElement(Flex, {
130
- align: "center",
131
- width: "100%",
132
- height: "100%"
133
- }, React.createElement(Text, {
134
- ellipsis: true
135
- }, React.createElement("a", {
136
- href: getContentUrl(field.value),
137
- target: "_blank",
138
- rel: "noreferrer"
139
- }, getContentUrl(field.value))), React.createElement(Hspace, {
231
+ }, React.createElement("option", {
232
+ value: DEFAULT_OPTION_VALUE
233
+ }, intl.formatMessage({
234
+ id: 'answer.option.default.group'
235
+ })), watchedGroupList.map((group, index) => React.createElement("option", {
236
+ key: index,
237
+ value: index
238
+ }, group.group))));
239
+ };
240
+ /**
241
+ *
242
+ */
243
+
244
+
245
+ const renderOptionRemoveButton = () => {
246
+ const isMinimumOptions = (watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.length) <= MIN_OPTION_INFO_COUNT;
247
+ return React.createElement(React.Fragment, null, React.createElement(Hspace, {
140
248
  width: 0.5
141
- }), React.createElement("div", null, React.createElement(IconButton, {
249
+ }), React.createElement(Tooltip, {
250
+ title: isMinimumOptions ? intl.formatMessage({
251
+ id: 'answer.option.tooltip.minDisabled'
252
+ }) : undefined,
253
+ placement: "top"
254
+ }, React.createElement("span", null, React.createElement(IconButton, {
255
+ transparent: true,
142
256
  icon: eilMathsignMultiplyBasic,
143
257
  role: "gray6",
144
258
  size: "micro",
145
259
  border: false,
146
- transparent: true,
147
- onClick: () => field.onChange('')
148
- })))) : React.createElement(React.Fragment, null, React.createElement(StyledQuizOptionContentLabel, {
149
- htmlFor: `${FILE_LABEL}_${optionId}`
150
- }, React.createElement(Text, {
151
- role: "primary",
152
- underline: true
153
- }, intl.formatMessage({
154
- id: 'answer.option.file.label'
155
- }))), React.createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
156
- id: `${FILE_LABEL}_${optionId}`,
157
- type: "file",
158
- accept: FILE_ACCEPT,
159
- onChange: async e => {
160
- var _a, _b;
161
-
162
- const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
163
-
164
- if (!file) {
165
- return;
166
- }
260
+ disabled: isMinimumOptions,
261
+ onClick: onRemoveItem
262
+ }))));
263
+ };
264
+ /**
265
+ *
266
+ */
167
267
 
168
- if (file.size > MAX_FILE_SIZE) {
169
- return Notification.error(intl.formatMessage({
170
- id: 'answer.option.file.errorMessage.maxSize'
171
- }, {
172
- size: 3
173
- }));
174
- }
175
268
 
176
- const contentFileUrl = await uploadContentFile(file);
177
- field.onChange(`![](${String(contentFileUrl)})`);
178
- }
179
- }))))
180
- })), React.createElement(StyledSortableListItemOption, null, React.createElement(StyledDropdown, {
181
- value: groupIndex,
182
- onChange: e => {
183
- const cloneAnswerList = cloneDeep(watchedAnswerInfo);
184
- const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
185
-
186
- if (e === DEFAULT_OPTION_VALUE) {
187
- return setValue('answerInfo', answerList);
188
- }
269
+ const renderErrorMessage = () => {
270
+ if (!errorMessage) {
271
+ return null;
272
+ }
189
273
 
190
- if (answerList[e]) {
191
- answerList[e] = [...answerList[e], optionId];
192
- } else {
193
- answerList[e] = [optionId];
194
- }
274
+ return React.createElement(Flex, {
275
+ paddingleft: "0.25rem"
276
+ }, React.createElement(Text, {
277
+ size: "small",
278
+ role: "danger"
279
+ }, errorMessage));
280
+ }; //
281
+ //
282
+ //
195
283
 
196
- setValue('answerInfo', answerList);
197
- }
198
- }, React.createElement("option", {
199
- value: DEFAULT_OPTION_VALUE
200
- }, intl.formatMessage({
201
- id: 'answer.option.default.group'
202
- })), watchedGroupList.map((group, index) => React.createElement("option", {
203
- key: index,
204
- value: index
205
- }, group.group)))));
284
+
285
+ if (!checkTwoDimensionArray(watchedAnswerInfo)) {
286
+ return null;
287
+ }
288
+
289
+ return React.createElement(StyledSortableListItem, {
290
+ index: optionId
291
+ }, React.createElement(Flex, {
292
+ justify: "center",
293
+ width: "calc(100% - 1.5rem)",
294
+ column: true
295
+ }, React.createElement(Flex, {
296
+ align: "center"
297
+ }, React.createElement(StyledSortableListItemOptionWrapper, null, renderOptionTitleInput(), renderOptionContentInput(), renderOptionGroupDropdown()), renderOptionRemoveButton()), renderErrorMessage()));
206
298
  };
207
299
 
208
300
  export { OptionGroupAnswerListItem as default };
@@ -1,98 +1,27 @@
1
1
  import React from 'react';
2
- import { useFormContext, useFieldArray, Controller } from 'react-hook-form';
2
+ import { useFormContext, useFieldArray } from 'react-hook-form';
3
3
  import { useIntl } from 'react-intl';
4
4
  import { arrayMove } from 'react-sortable-hoc';
5
- import { SortableListItem, Input, Flex, Text, SortableListGroup, Hspace, Tooltip, IconButton, Button, Icon } from '@elice/blocks';
6
- import { base } from '@elice/design-tokens';
7
- import { eilMathsignMultiplyBasic, eilMathsignAddBasic } from '@elice/icons';
5
+ import { Flex, Text, SortableListGroup, Tooltip, Button, Icon } from '@elice/blocks';
6
+ import { eilMathsignAddBasic } from '@elice/icons';
8
7
  import cloneDeep from 'lodash-es/cloneDeep';
9
8
  import styled from 'styled-components';
10
9
  import { createRandomId } from '../../utils/randomId.js';
10
+ import OptionGroupGroupListItem from './OptionGroupGroupListItem.js';
11
11
 
12
- const SHEET_Z_INDEX = 982;
13
- const MIN_GROUP_INFO_COUNT = 2;
14
12
  const MAX_GROUP_INFO_COUNT = 6;
15
- const StyledSortableList = styled.ul.withConfig({
13
+ const StyledSortableList = styled.div.withConfig({
16
14
  componentId: "sc-9aq3yn-0"
17
- })(["margin:1rem 0;padding:0;"]);
18
- const StyledSortableListItemWrapper = styled.li.withConfig({
19
- componentId: "sc-9aq3yn-1"
20
- })(["display:flex;align-items:center;&:not(:last-child){margin-bottom:0.5rem;}"]);
21
- const StyledSortableListItem = styled(SortableListItem).withConfig({
22
- componentId: "sc-9aq3yn-2"
23
- })(["display:flex;overflow:hidden;z-index:", ";width:100%;padding:0 0 0 1rem;border-radius:4px;border:1px solid ", ";background:", ";box-shadow:none;"], SHEET_Z_INDEX + 1, ({
24
- isGroupChildAnswer
25
- }) => isGroupChildAnswer ? base.color.red8 : base.color.gray3, base.color.white);
26
- const StyledInputGroup = styled(Input).withConfig({
27
- componentId: "sc-9aq3yn-3"
28
- })(["& > div{border:0;}"]); //
15
+ })(["margin:1rem 0;padding:0;"]); //
29
16
  //
30
17
  //
31
18
 
32
- const OptionGroupGroupListItem = ({
33
- groupId
34
- }) => {
35
- var _a;
36
-
19
+ const OptionGroupGroupInfo = () => {
37
20
  const intl = useIntl();
38
21
  const {
39
- control,
22
+ setValue,
40
23
  watch
41
24
  } = useFormContext();
42
- const watchedAnswerInfo = watch('answerInfo');
43
- const isGroupChildAnswer = Boolean((_a = watchedAnswerInfo[groupId]) === null || _a === void 0 ? void 0 : _a.length); //
44
- //
45
- //
46
-
47
- return React.createElement(StyledSortableListItem, {
48
- index: groupId,
49
- isGroupChildAnswer: !isGroupChildAnswer
50
- }, React.createElement(Controller, {
51
- control: control,
52
- name: `groups.${groupId}.group`,
53
- rules: {
54
- required: {
55
- value: true,
56
- message: intl.formatMessage({
57
- id: 'group.option.errorMessage.required'
58
- })
59
- },
60
- validate: () => {
61
- if (!isGroupChildAnswer) {
62
- return intl.formatMessage({
63
- id: 'group.option.errorMessage.notChild'
64
- });
65
- }
66
- }
67
- },
68
- render: ({
69
- field,
70
- fieldState
71
- }) => {
72
- var _a;
73
-
74
- return React.createElement(StyledInputGroup, Object.assign({}, field, {
75
- invalid: fieldState.invalid || !isGroupChildAnswer,
76
- invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
77
- width: "full",
78
- onChange: e => {
79
- field.onChange(e.target.value.replace(' ', ''));
80
- }
81
- }));
82
- }
83
- }));
84
- }; //
85
- //
86
- //
87
-
88
-
89
- const OptionGroupGroupList = () => {
90
- const intl = useIntl();
91
- const {
92
- watch,
93
- setValue
94
- } = useFormContext();
95
- const watchedAnswerInfo = watch('answerInfo');
96
25
  const {
97
26
  fields: groupInfoFields,
98
27
  append: appendGroupInfoFieldItem,
@@ -102,7 +31,8 @@ const OptionGroupGroupList = () => {
102
31
  keyName: 'id',
103
32
  shouldUnregister: true
104
33
  });
105
- const isMinimumGroups = groupInfoFields.length <= MIN_GROUP_INFO_COUNT;
34
+ const watchedGroups = watch('groups');
35
+ const watchedAnswerInfo = watch('answerInfo');
106
36
  const isMaximumGroups = groupInfoFields.length >= MAX_GROUP_INFO_COUNT;
107
37
  /**
108
38
  *
@@ -123,72 +53,12 @@ const OptionGroupGroupList = () => {
123
53
  cloneAnswerList.splice(index, 1);
124
54
  setValue('answerInfo', cloneAnswerList.filter(Boolean));
125
55
  removeGroupInfoFieldItem(Number(index));
126
- }; //
127
- //
128
- //
129
-
130
-
131
- return React.createElement(React.Fragment, null, React.createElement(StyledSortableList, null, groupInfoFields.map((group, index) => {
132
- return React.createElement(StyledSortableListItemWrapper, {
133
- key: group.id
134
- }, React.createElement(OptionGroupGroupListItem, {
135
- groupId: index
136
- }), React.createElement(Hspace, {
137
- width: 0.5
138
- }), React.createElement(Tooltip, {
139
- title: isMinimumGroups ? intl.formatMessage({
140
- id: 'group.option.tooltip.minDisabled'
141
- }) : undefined,
142
- placement: "top"
143
- }, React.createElement("span", null, React.createElement(IconButton, {
144
- transparent: true,
145
- icon: eilMathsignMultiplyBasic,
146
- role: "gray6",
147
- size: "micro",
148
- border: false,
149
- disabled: isMinimumGroups,
150
- onClick: () => removeGroupAnswerInfo(Number(index))
151
- }))));
152
- })), React.createElement(Tooltip, {
153
- title: isMaximumGroups ? intl.formatMessage({
154
- id: 'group.option.tooltip.maxDisabled'
155
- }) : undefined,
156
- placement: "top"
157
- }, React.createElement("span", null, React.createElement(Button, {
158
- borderDashed: true,
159
- block: true,
160
- transparent: true,
161
- icon: React.createElement(Icon, {
162
- icon: eilMathsignAddBasic
163
- }),
164
- disabled: isMaximumGroups,
165
- onClick: () => {
166
- appendGroupInfoFieldItem({
167
- id: createRandomId(),
168
- group: ''
169
- });
170
- addGroupAnswerInfo();
171
- }
172
- }, intl.formatMessage({
173
- id: 'group.option.addButton'
174
- })))));
175
- }; //
176
- //
177
- //
178
-
179
-
180
- const OptionGroupGroupInfo = () => {
181
- const intl = useIntl();
182
- const {
183
- setValue,
184
- watch
185
- } = useFormContext();
186
- const watchedGroups = watch('groups');
187
- const watchedAnswerInfo = watch('answerInfo');
56
+ };
188
57
  /**
189
58
  *
190
59
  */
191
60
 
61
+
192
62
  const onSortEnd = ({
193
63
  oldIndex,
194
64
  newIndex
@@ -201,6 +71,52 @@ const OptionGroupGroupInfo = () => {
201
71
  shouldDirty: true
202
72
  });
203
73
  setValue('answerInfo', cloneAnswerList);
74
+ };
75
+ /**
76
+ *
77
+ */
78
+
79
+
80
+ const renderGroupOptionList = () => {
81
+ return React.createElement(SortableListGroup, {
82
+ onSortEnd: onSortEnd,
83
+ useDragHandle: true
84
+ }, React.createElement(StyledSortableList, null, groupInfoFields.map((group, index) => React.createElement(OptionGroupGroupListItem, {
85
+ key: group.id,
86
+ groupId: index,
87
+ groupsCount: groupInfoFields.length,
88
+ onRemoveOption: () => removeGroupAnswerInfo(index)
89
+ }))));
90
+ };
91
+ /**
92
+ *
93
+ */
94
+
95
+
96
+ const renderGroupOptionAddButton = () => {
97
+ return React.createElement(Tooltip, {
98
+ title: isMaximumGroups ? intl.formatMessage({
99
+ id: 'group.option.tooltip.maxDisabled'
100
+ }) : undefined,
101
+ placement: "top"
102
+ }, React.createElement("span", null, React.createElement(Button, {
103
+ borderDashed: true,
104
+ block: true,
105
+ transparent: true,
106
+ icon: React.createElement(Icon, {
107
+ icon: eilMathsignAddBasic
108
+ }),
109
+ disabled: isMaximumGroups,
110
+ onClick: () => {
111
+ appendGroupInfoFieldItem({
112
+ id: createRandomId(),
113
+ group: ''
114
+ });
115
+ addGroupAnswerInfo();
116
+ }
117
+ }, intl.formatMessage({
118
+ id: 'group.option.addButton'
119
+ }))));
204
120
  }; //
205
121
  //
206
122
  //
@@ -213,10 +129,7 @@ const OptionGroupGroupInfo = () => {
213
129
  bold: true
214
130
  }, intl.formatMessage({
215
131
  id: 'group.option.title'
216
- })), React.createElement(SortableListGroup, {
217
- onSortEnd: onSortEnd,
218
- useDragHandle: true
219
- }, React.createElement(OptionGroupGroupList, null)));
132
+ })), renderGroupOptionList(), renderGroupOptionAddButton());
220
133
  };
221
134
 
222
135
  export { OptionGroupGroupInfo as default };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ interface OptionGroupGroupListItemProps {
3
+ groupId: number;
4
+ groupsCount: number;
5
+ onRemoveOption: () => void;
6
+ }
7
+ declare const OptionGroupGroupListItem: React.FC<OptionGroupGroupListItemProps>;
8
+ export default OptionGroupGroupListItem;