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