@elice/material-quiz 1.221217.0 → 1.221222.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.
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +105 -125
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.d.ts +1 -0
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +206 -119
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +60 -141
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.d.ts +8 -0
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +139 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +107 -127
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.d.ts +1 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +207 -120
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +63 -144
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.d.ts +8 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +132 -0
- package/package.json +4 -4
|
@@ -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,22 @@ 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"].
|
|
21
|
+
const StyledSortableList = styled__default["default"].div.withConfig({
|
|
24
22
|
componentId: "sc-9aq3yn-0"
|
|
25
23
|
})(["margin:1rem 0;padding:0;"]);
|
|
26
|
-
const StyledSortableListItemWrapper = styled__default["default"].
|
|
24
|
+
const StyledSortableListItemWrapper = styled__default["default"].div.withConfig({
|
|
27
25
|
componentId: "sc-9aq3yn-1"
|
|
28
|
-
})(["display:flex;
|
|
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;}"]); //
|
|
26
|
+
})(["display:flex;flex-direction:column;&:not(:last-child){margin-bottom:0.5rem;}"]); //
|
|
37
27
|
//
|
|
38
28
|
//
|
|
39
29
|
|
|
40
|
-
const
|
|
41
|
-
groupId
|
|
42
|
-
}) => {
|
|
43
|
-
var _a;
|
|
44
|
-
|
|
30
|
+
const OptionGroupGroupInfo = () => {
|
|
45
31
|
const intl = reactIntl.useIntl();
|
|
46
32
|
const {
|
|
47
|
-
|
|
33
|
+
setValue,
|
|
48
34
|
watch
|
|
49
35
|
} = 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
36
|
const {
|
|
105
37
|
fields: groupInfoFields,
|
|
106
38
|
append: appendGroupInfoFieldItem,
|
|
@@ -110,7 +42,8 @@ const OptionGroupGroupList = () => {
|
|
|
110
42
|
keyName: 'id',
|
|
111
43
|
shouldUnregister: true
|
|
112
44
|
});
|
|
113
|
-
const
|
|
45
|
+
const watchedGroups = watch('groups');
|
|
46
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
114
47
|
const isMaximumGroups = groupInfoFields.length >= MAX_GROUP_INFO_COUNT;
|
|
115
48
|
/**
|
|
116
49
|
*
|
|
@@ -131,72 +64,12 @@ const OptionGroupGroupList = () => {
|
|
|
131
64
|
cloneAnswerList.splice(index, 1);
|
|
132
65
|
setValue('answerInfo', cloneAnswerList.filter(Boolean));
|
|
133
66
|
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');
|
|
67
|
+
};
|
|
196
68
|
/**
|
|
197
69
|
*
|
|
198
70
|
*/
|
|
199
71
|
|
|
72
|
+
|
|
200
73
|
const onSortEnd = ({
|
|
201
74
|
oldIndex,
|
|
202
75
|
newIndex
|
|
@@ -209,6 +82,55 @@ const OptionGroupGroupInfo = () => {
|
|
|
209
82
|
shouldDirty: true
|
|
210
83
|
});
|
|
211
84
|
setValue('answerInfo', cloneAnswerList);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const renderGroupOptionList = () => {
|
|
92
|
+
return React__default["default"].createElement(blocks.SortableListGroup, {
|
|
93
|
+
onSortEnd: onSortEnd,
|
|
94
|
+
useDragHandle: true
|
|
95
|
+
}, React__default["default"].createElement(StyledSortableList, null, groupInfoFields.map((group, index) => {
|
|
96
|
+
return React__default["default"].createElement(StyledSortableListItemWrapper, {
|
|
97
|
+
key: group.id
|
|
98
|
+
}, React__default["default"].createElement(OptionGroupGroupListItem, {
|
|
99
|
+
groupId: index,
|
|
100
|
+
groupsCount: groupInfoFields.length,
|
|
101
|
+
onRemoveOption: () => removeGroupAnswerInfo(index)
|
|
102
|
+
}));
|
|
103
|
+
})));
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
const renderGroupOptionAddButton = () => {
|
|
111
|
+
return React__default["default"].createElement(blocks.Tooltip, {
|
|
112
|
+
title: isMaximumGroups ? intl.formatMessage({
|
|
113
|
+
id: 'group.option.tooltip.maxDisabled'
|
|
114
|
+
}) : undefined,
|
|
115
|
+
placement: "top"
|
|
116
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
|
|
117
|
+
borderDashed: true,
|
|
118
|
+
block: true,
|
|
119
|
+
transparent: true,
|
|
120
|
+
icon: React__default["default"].createElement(blocks.Icon, {
|
|
121
|
+
icon: icons.eilMathsignAddBasic
|
|
122
|
+
}),
|
|
123
|
+
disabled: isMaximumGroups,
|
|
124
|
+
onClick: () => {
|
|
125
|
+
appendGroupInfoFieldItem({
|
|
126
|
+
id: randomId.createRandomId(),
|
|
127
|
+
group: ''
|
|
128
|
+
});
|
|
129
|
+
addGroupAnswerInfo();
|
|
130
|
+
}
|
|
131
|
+
}, intl.formatMessage({
|
|
132
|
+
id: 'group.option.addButton'
|
|
133
|
+
}))));
|
|
212
134
|
}; //
|
|
213
135
|
//
|
|
214
136
|
//
|
|
@@ -221,10 +143,7 @@ const OptionGroupGroupInfo = () => {
|
|
|
221
143
|
bold: true
|
|
222
144
|
}, intl.formatMessage({
|
|
223
145
|
id: 'group.option.title'
|
|
224
|
-
})),
|
|
225
|
-
onSortEnd: onSortEnd,
|
|
226
|
-
useDragHandle: true
|
|
227
|
-
}, React__default["default"].createElement(OptionGroupGroupList, null)));
|
|
146
|
+
})), renderGroupOptionList(), renderGroupOptionAddButton());
|
|
228
147
|
};
|
|
229
148
|
|
|
230
149
|
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;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
var blocks = require('@elice/blocks');
|
|
7
|
+
var designTokens = require('@elice/design-tokens');
|
|
8
|
+
var icons = require('@elice/icons');
|
|
9
|
+
var styled = require('styled-components');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
15
|
+
|
|
16
|
+
const SHEET_Z_INDEX = 982;
|
|
17
|
+
const MIN_GROUP_INFO_COUNT = 2;
|
|
18
|
+
const StyledSortableListItem = styled__default["default"](blocks.SortableListItem).withConfig({
|
|
19
|
+
componentId: "sc-hj5nic-0"
|
|
20
|
+
})(["display:flex;z-index:", ";width:100%;padding:0;background:transparent;box-shadow:none;"], SHEET_Z_INDEX + 1);
|
|
21
|
+
const StyledSortableListItemOptionWrapper = styled__default["default"].div.withConfig({
|
|
22
|
+
componentId: "sc-hj5nic-1"
|
|
23
|
+
})(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border-radius:4px;border:1px solid ", ";background:", ";"], ({
|
|
24
|
+
isGroupChildAnswer
|
|
25
|
+
}) => isGroupChildAnswer ? designTokens.base.color.red8 : designTokens.base.color.gray3, designTokens.base.color.white);
|
|
26
|
+
const StyledInputGroup = styled__default["default"](blocks.Input).withConfig({
|
|
27
|
+
componentId: "sc-hj5nic-2"
|
|
28
|
+
})(["& > div{border:0;}"]);
|
|
29
|
+
|
|
30
|
+
const OptionGroupGroupListItem = ({
|
|
31
|
+
groupId,
|
|
32
|
+
groupsCount,
|
|
33
|
+
onRemoveOption
|
|
34
|
+
}) => {
|
|
35
|
+
var _a, _b, _c, _d, _e;
|
|
36
|
+
|
|
37
|
+
const intl = reactIntl.useIntl();
|
|
38
|
+
const {
|
|
39
|
+
control,
|
|
40
|
+
formState,
|
|
41
|
+
watch
|
|
42
|
+
} = reactHookForm.useFormContext();
|
|
43
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
44
|
+
const isGroupChildAnswer = Boolean((_a = watchedAnswerInfo[groupId]) === null || _a === void 0 ? void 0 : _a.length);
|
|
45
|
+
const isMinimumGroups = groupsCount <= MIN_GROUP_INFO_COUNT;
|
|
46
|
+
const errorMessage = (_e = (_d = (_c = (_b = formState.errors) === null || _b === void 0 ? void 0 : _b.groups) === null || _c === void 0 ? void 0 : _c[groupId]) === null || _d === void 0 ? void 0 : _d.group) === null || _e === void 0 ? void 0 : _e.message;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
const renderOptionGroupInput = () => {
|
|
52
|
+
return React__default["default"].createElement(StyledSortableListItemOptionWrapper, {
|
|
53
|
+
isGroupChildAnswer: !isGroupChildAnswer
|
|
54
|
+
}, React__default["default"].createElement(reactHookForm.Controller, {
|
|
55
|
+
control: control,
|
|
56
|
+
name: `groups.${groupId}.group`,
|
|
57
|
+
rules: {
|
|
58
|
+
required: {
|
|
59
|
+
value: true,
|
|
60
|
+
message: intl.formatMessage({
|
|
61
|
+
id: 'group.option.errorMessage.required'
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
validate: () => {
|
|
65
|
+
if (!isGroupChildAnswer) {
|
|
66
|
+
return intl.formatMessage({
|
|
67
|
+
id: 'group.option.errorMessage.notChild'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
render: ({
|
|
73
|
+
field,
|
|
74
|
+
fieldState
|
|
75
|
+
}) => React__default["default"].createElement(StyledInputGroup, Object.assign({}, field, {
|
|
76
|
+
invalid: fieldState.invalid || !isGroupChildAnswer,
|
|
77
|
+
width: "full",
|
|
78
|
+
onChange: e => {
|
|
79
|
+
field.onChange(e.target.value.replace(' ', ''));
|
|
80
|
+
}
|
|
81
|
+
}))
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
const renderOptionRemoveButton = () => {
|
|
90
|
+
return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.Hspace, {
|
|
91
|
+
width: 0.5
|
|
92
|
+
}), React__default["default"].createElement(blocks.Tooltip, {
|
|
93
|
+
title: isMinimumGroups ? intl.formatMessage({
|
|
94
|
+
id: 'group.option.tooltip.minDisabled'
|
|
95
|
+
}) : undefined,
|
|
96
|
+
placement: "top"
|
|
97
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
|
|
98
|
+
transparent: true,
|
|
99
|
+
icon: icons.eilMathsignMultiplyBasic,
|
|
100
|
+
role: "gray6",
|
|
101
|
+
size: "micro",
|
|
102
|
+
border: false,
|
|
103
|
+
disabled: isMinimumGroups,
|
|
104
|
+
onClick: onRemoveOption
|
|
105
|
+
}))));
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const renderErrorMessage = () => {
|
|
113
|
+
if (!errorMessage) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return React__default["default"].createElement(blocks.Flex, {
|
|
118
|
+
paddingleft: "0.25rem"
|
|
119
|
+
}, React__default["default"].createElement(blocks.Text, {
|
|
120
|
+
size: "small",
|
|
121
|
+
role: "danger"
|
|
122
|
+
}, errorMessage));
|
|
123
|
+
}; //
|
|
124
|
+
//
|
|
125
|
+
//
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
return React__default["default"].createElement(StyledSortableListItem, {
|
|
129
|
+
index: groupId
|
|
130
|
+
}, React__default["default"].createElement(blocks.Flex, {
|
|
131
|
+
justify: "center",
|
|
132
|
+
width: "100%",
|
|
133
|
+
column: true
|
|
134
|
+
}, React__default["default"].createElement(blocks.Flex, {
|
|
135
|
+
align: "center"
|
|
136
|
+
}, renderOptionGroupInput(), renderOptionRemoveButton()), renderErrorMessage()));
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
module.exports = OptionGroupGroupListItem;
|
|
@@ -2,36 +2,32 @@ import React from 'react';
|
|
|
2
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 { Flex, Text, SortableListGroup,
|
|
6
|
-
import {
|
|
5
|
+
import { Flex, Text, SortableListGroup, Tooltip, Button, Icon, Vspace, StatusText } from '@elice/blocks';
|
|
6
|
+
import { eilMathsignAddBasic } from '@elice/icons';
|
|
7
7
|
import cloneDeep from 'lodash-es/cloneDeep';
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
import { checkTwoDimensionArray } from '../../utils/checkTwoDimensionArray.js';
|
|
10
10
|
import { createRandomId } from '../../utils/randomId.js';
|
|
11
11
|
import OptionGroupAnswerListItem from './OptionGroupAnswerListItem.js';
|
|
12
12
|
|
|
13
|
-
const OPTION_CONTENT_WIDTH = 205;
|
|
14
|
-
const OPTION_GROUP_WIDTH = 180;
|
|
15
|
-
const MIN_OPTION_INFO_COUNT = 2;
|
|
16
13
|
const MAX_OPTION_INFO_COUNT = 20;
|
|
17
|
-
const StyledSortableList = styled.
|
|
14
|
+
const StyledSortableList = styled.div.withConfig({
|
|
18
15
|
componentId: "sc-14yoda7-0"
|
|
19
16
|
})(["margin:1rem 0;padding:0;"]);
|
|
20
|
-
const StyledSortableListItemWrapper = styled.
|
|
17
|
+
const StyledSortableListItemWrapper = styled.div.withConfig({
|
|
21
18
|
componentId: "sc-14yoda7-1"
|
|
22
19
|
})(["display:flex;flex-direction:column;width:100%;&:not(:last-child){margin-bottom:0.5rem;}"]);
|
|
23
20
|
const StyledOptionTitle = styled.div.withConfig({
|
|
24
21
|
componentId: "sc-14yoda7-2"
|
|
25
|
-
})(["display:flex;width:calc(100% - 2rem);"]); //
|
|
22
|
+
})(["display:flex;width:calc(100% - 2rem - 1.5rem);"]); //
|
|
26
23
|
//
|
|
27
24
|
//
|
|
28
25
|
|
|
29
|
-
const
|
|
26
|
+
const OptionGroupAnswerInfo = () => {
|
|
30
27
|
const intl = useIntl();
|
|
31
28
|
const {
|
|
32
|
-
|
|
33
|
-
watch
|
|
34
|
-
setValue
|
|
29
|
+
setValue,
|
|
30
|
+
watch
|
|
35
31
|
} = useFormContext();
|
|
36
32
|
const {
|
|
37
33
|
append: appendOptionInfoFieldItem,
|
|
@@ -41,10 +37,9 @@ const OptionGroupAnswerList = () => {
|
|
|
41
37
|
keyName: 'id',
|
|
42
38
|
shouldUnregister: true
|
|
43
39
|
});
|
|
44
|
-
const
|
|
40
|
+
const watchedOptions = watch('options');
|
|
45
41
|
const watchedAnswerInfo = watch('answerInfo');
|
|
46
|
-
const
|
|
47
|
-
const isMaximumOptions = (optionInfoFields === null || optionInfoFields === void 0 ? void 0 : optionInfoFields.length) >= MAX_OPTION_INFO_COUNT;
|
|
42
|
+
const isMaximumOptions = (watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.length) >= MAX_OPTION_INFO_COUNT;
|
|
48
43
|
/**
|
|
49
44
|
*
|
|
50
45
|
*/
|
|
@@ -61,97 +56,12 @@ const OptionGroupAnswerList = () => {
|
|
|
61
56
|
const recalculationAnswerList = cloneAnswerList.map(answers => answers.map(answer => answer > index ? answer - 1 : answer));
|
|
62
57
|
removeOptionInfoFieldItem(index);
|
|
63
58
|
setValue('answerInfo', recalculationAnswerList);
|
|
64
|
-
};
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!checkTwoDimensionArray(watchedAnswerInfo)) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return React.createElement(React.Fragment, null, React.createElement(StyledSortableList, null, optionInfoFields === null || optionInfoFields === void 0 ? void 0 : optionInfoFields.map((option, index) => {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
75
|
-
|
|
76
|
-
const errorMessage = (_d = (_c = (_b = (_a = formState.errors) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b[index]) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.message;
|
|
77
|
-
return React.createElement(StyledSortableListItemWrapper, {
|
|
78
|
-
key: option.id
|
|
79
|
-
}, React.createElement(Flex, {
|
|
80
|
-
align: "center",
|
|
81
|
-
width: "100%"
|
|
82
|
-
}, React.createElement(OptionGroupAnswerListItem, {
|
|
83
|
-
optionId: index
|
|
84
|
-
}), React.createElement(Hspace, {
|
|
85
|
-
width: 0.5
|
|
86
|
-
}), React.createElement(Tooltip, {
|
|
87
|
-
title: isMinimumOptions ? intl.formatMessage({
|
|
88
|
-
id: 'answer.option.tooltip.minDisabled'
|
|
89
|
-
}) : undefined,
|
|
90
|
-
placement: "top"
|
|
91
|
-
}, React.createElement("span", null, React.createElement(IconButton, {
|
|
92
|
-
transparent: true,
|
|
93
|
-
icon: eilMathsignMultiplyBasic,
|
|
94
|
-
role: "gray6",
|
|
95
|
-
size: "micro",
|
|
96
|
-
border: false,
|
|
97
|
-
disabled: isMinimumOptions,
|
|
98
|
-
onClick: () => handleRemoveItem(index)
|
|
99
|
-
})))), errorMessage ? React.createElement(Text, {
|
|
100
|
-
size: "small",
|
|
101
|
-
role: "danger"
|
|
102
|
-
}, errorMessage) : null);
|
|
103
|
-
})), React.createElement(Tooltip, {
|
|
104
|
-
title: isMaximumOptions ? intl.formatMessage({
|
|
105
|
-
id: 'answer.option.tooltip.maxDisabled'
|
|
106
|
-
}) : undefined,
|
|
107
|
-
placement: "top"
|
|
108
|
-
}, React.createElement("span", null, React.createElement(Button, {
|
|
109
|
-
borderDashed: true,
|
|
110
|
-
block: true,
|
|
111
|
-
transparent: true,
|
|
112
|
-
disabled: isMaximumOptions,
|
|
113
|
-
icon: React.createElement(Icon, {
|
|
114
|
-
icon: eilMathsignAddBasic
|
|
115
|
-
}),
|
|
116
|
-
onClick: () => appendOptionInfoFieldItem({
|
|
117
|
-
id: createRandomId(),
|
|
118
|
-
title: '',
|
|
119
|
-
content: ''
|
|
120
|
-
})
|
|
121
|
-
}, intl.formatMessage({
|
|
122
|
-
id: 'answer.option.addButton'
|
|
123
|
-
})))), React.createElement(Vspace, {
|
|
124
|
-
height: 0.5
|
|
125
|
-
}), React.createElement(StatusText, {
|
|
126
|
-
role: "description"
|
|
127
|
-
}, intl.formatMessage({
|
|
128
|
-
id: 'answer.option.file.description.imageSize'
|
|
129
|
-
})), React.createElement(StatusText, {
|
|
130
|
-
role: "description"
|
|
131
|
-
}, intl.formatMessage({
|
|
132
|
-
id: 'answer.option.file.description.fileSize'
|
|
133
|
-
})), React.createElement(StatusText, {
|
|
134
|
-
role: "description"
|
|
135
|
-
}, intl.formatMessage({
|
|
136
|
-
id: 'answer.option.file.description.extension'
|
|
137
|
-
})));
|
|
138
|
-
}; //
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const OptionGroupAnswerInfo = () => {
|
|
144
|
-
const intl = useIntl();
|
|
145
|
-
const {
|
|
146
|
-
setValue,
|
|
147
|
-
watch
|
|
148
|
-
} = useFormContext();
|
|
149
|
-
const watchedOptions = watch('options');
|
|
150
|
-
const watchedAnswerInfo = watch('answerInfo');
|
|
59
|
+
};
|
|
151
60
|
/**
|
|
152
61
|
*
|
|
153
62
|
*/
|
|
154
63
|
|
|
64
|
+
|
|
155
65
|
const onSortEnd = ({
|
|
156
66
|
oldIndex,
|
|
157
67
|
newIndex
|
|
@@ -167,38 +77,108 @@ const OptionGroupAnswerInfo = () => {
|
|
|
167
77
|
setValue('options', arrayMove(watchedOptions, oldIndex, newIndex), {
|
|
168
78
|
shouldDirty: true
|
|
169
79
|
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
const renderAnswerTitle = () => {
|
|
87
|
+
return React.createElement(StyledOptionTitle, null, React.createElement(Flex, {
|
|
88
|
+
width: "33.3%",
|
|
89
|
+
auto: true
|
|
90
|
+
}, React.createElement(Text, {
|
|
91
|
+
size: "small",
|
|
92
|
+
bold: true
|
|
93
|
+
}, intl.formatMessage({
|
|
94
|
+
id: 'answer.option.title.text'
|
|
95
|
+
}))), React.createElement(Flex, {
|
|
96
|
+
width: "33.3%"
|
|
97
|
+
}, React.createElement(Text, {
|
|
98
|
+
size: "small",
|
|
99
|
+
bold: true
|
|
100
|
+
}, intl.formatMessage({
|
|
101
|
+
id: 'answer.option.title.file'
|
|
102
|
+
}))), React.createElement(Flex, {
|
|
103
|
+
width: "calc(33.3% - 1.5rem)"
|
|
104
|
+
}, React.createElement(Text, {
|
|
105
|
+
size: "small",
|
|
106
|
+
bold: true
|
|
107
|
+
}, intl.formatMessage({
|
|
108
|
+
id: 'answer.option.title.group'
|
|
109
|
+
}))));
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const renderAnswerOptionList = () => {
|
|
117
|
+
return React.createElement(SortableListGroup, {
|
|
118
|
+
onSortEnd: onSortEnd,
|
|
119
|
+
useDragHandle: true
|
|
120
|
+
}, React.createElement(StyledSortableList, null, watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.map((option, index) => React.createElement(StyledSortableListItemWrapper, {
|
|
121
|
+
key: option.id
|
|
122
|
+
}, React.createElement(OptionGroupAnswerListItem, {
|
|
123
|
+
optionId: index,
|
|
124
|
+
onRemoveItem: () => handleRemoveItem(index)
|
|
125
|
+
})))));
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const renderAnswerOptionAddButton = () => {
|
|
133
|
+
return React.createElement(React.Fragment, null, React.createElement(Tooltip, {
|
|
134
|
+
title: isMaximumOptions ? intl.formatMessage({
|
|
135
|
+
id: 'answer.option.tooltip.maxDisabled'
|
|
136
|
+
}) : undefined,
|
|
137
|
+
placement: "top"
|
|
138
|
+
}, React.createElement("span", null, React.createElement(Button, {
|
|
139
|
+
borderDashed: true,
|
|
140
|
+
block: true,
|
|
141
|
+
transparent: true,
|
|
142
|
+
disabled: isMaximumOptions,
|
|
143
|
+
icon: React.createElement(Icon, {
|
|
144
|
+
icon: eilMathsignAddBasic
|
|
145
|
+
}),
|
|
146
|
+
onClick: () => appendOptionInfoFieldItem({
|
|
147
|
+
id: createRandomId(),
|
|
148
|
+
title: '',
|
|
149
|
+
content: ''
|
|
150
|
+
})
|
|
151
|
+
}, intl.formatMessage({
|
|
152
|
+
id: 'answer.option.addButton'
|
|
153
|
+
})))), React.createElement(Vspace, {
|
|
154
|
+
height: 0.5
|
|
155
|
+
}), React.createElement(Flex, {
|
|
156
|
+
column: true
|
|
157
|
+
}, React.createElement(StatusText, {
|
|
158
|
+
role: "description"
|
|
159
|
+
}, intl.formatMessage({
|
|
160
|
+
id: 'answer.option.file.description.imageSize'
|
|
161
|
+
})), React.createElement(StatusText, {
|
|
162
|
+
role: "description"
|
|
163
|
+
}, intl.formatMessage({
|
|
164
|
+
id: 'answer.option.file.description.fileSize'
|
|
165
|
+
})), React.createElement(StatusText, {
|
|
166
|
+
role: "description"
|
|
167
|
+
}, intl.formatMessage({
|
|
168
|
+
id: 'answer.option.file.description.extension'
|
|
169
|
+
}))));
|
|
170
170
|
}; //
|
|
171
171
|
//
|
|
172
172
|
//
|
|
173
173
|
|
|
174
174
|
|
|
175
|
+
if (!checkTwoDimensionArray(watchedAnswerInfo)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
175
179
|
return React.createElement(Flex, {
|
|
176
180
|
column: true
|
|
177
|
-
},
|
|
178
|
-
auto: true
|
|
179
|
-
}, React.createElement(Text, {
|
|
180
|
-
size: "small",
|
|
181
|
-
bold: true
|
|
182
|
-
}, intl.formatMessage({
|
|
183
|
-
id: 'answer.option.title.text'
|
|
184
|
-
}))), React.createElement(Flex, {
|
|
185
|
-
width: `${OPTION_CONTENT_WIDTH}px`
|
|
186
|
-
}, React.createElement(Text, {
|
|
187
|
-
size: "small",
|
|
188
|
-
bold: true
|
|
189
|
-
}, intl.formatMessage({
|
|
190
|
-
id: 'answer.option.title.file'
|
|
191
|
-
}))), React.createElement(Flex, {
|
|
192
|
-
width: `${OPTION_GROUP_WIDTH}px`
|
|
193
|
-
}, React.createElement(Text, {
|
|
194
|
-
size: "small",
|
|
195
|
-
bold: true
|
|
196
|
-
}, intl.formatMessage({
|
|
197
|
-
id: 'answer.option.title.group'
|
|
198
|
-
})))), React.createElement(SortableListGroup, {
|
|
199
|
-
onSortEnd: onSortEnd,
|
|
200
|
-
useDragHandle: true
|
|
201
|
-
}, React.createElement(OptionGroupAnswerList, null)));
|
|
181
|
+
}, renderAnswerTitle(), renderAnswerOptionList(), renderAnswerOptionAddButton());
|
|
202
182
|
};
|
|
203
183
|
|
|
204
184
|
export { OptionGroupAnswerInfo as default };
|