@elice/material-quiz 1.220803.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/README.md +3 -0
- package/cjs/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/cjs/components/eb-sortable/EbDraggable.js +112 -0
- package/cjs/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/cjs/components/eb-sortable/EbDroppable.js +60 -0
- package/cjs/components/eb-sortable/EbSortable.d.ts +17 -0
- package/cjs/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.js +55 -0
- package/cjs/components/material-quiz/MaterialQuiz.js +114 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +55 -0
- package/cjs/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.js +74 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +203 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +468 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.js +191 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.js +61 -0
- package/cjs/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizText.js +181 -0
- package/cjs/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/cjs/components/material-quiz/QuizResultBadge.js +48 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.js +38 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.js +134 -0
- package/cjs/components/material-quiz/index.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +91 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +463 -0
- package/cjs/components/material-quiz-edit/context.d.ts +6 -0
- package/cjs/components/material-quiz-edit/context.js +15 -0
- package/cjs/components/material-quiz-edit/index.d.ts +2 -0
- package/cjs/components/material-quiz-edit/locales.d.ts +34 -0
- package/cjs/components/material-quiz-edit/locales.js +73 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +204 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +205 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +207 -0
- package/cjs/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionText.js +99 -0
- package/cjs/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/cjs/components/material-quiz-edit/utils/editValue.js +37 -0
- package/cjs/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/cjs/components/material-quiz-edit/utils/randomId.js +12 -0
- package/cjs/components/shared/QuestionBox.d.ts +16 -0
- package/cjs/components/shared/QuestionBox.js +111 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.js +31 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.js +36 -0
- package/cjs/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/cjs/components/shared/QuizDraggbleOption.js +191 -0
- package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
- package/cjs/components/shared/StyledMarkdown.js +14 -0
- package/cjs/components/shared/index.d.ts +7 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +188 -0
- package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +156 -0
- package/cjs/helpers/index.d.ts +50 -0
- package/cjs/helpers/index.js +86 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +27 -0
- package/es/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/es/components/eb-sortable/EbDraggable.js +105 -0
- package/es/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/es/components/eb-sortable/EbDroppable.js +53 -0
- package/es/components/eb-sortable/EbSortable.d.ts +17 -0
- package/es/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.js +50 -0
- package/es/components/material-quiz/MaterialQuiz.js +106 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +48 -0
- package/es/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.js +68 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.js +197 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +461 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.js +185 -0
- package/es/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizShimmer.js +54 -0
- package/es/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizText.js +174 -0
- package/es/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/es/components/material-quiz/QuizResultBadge.js +42 -0
- package/es/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/es/components/material-quiz/QuizSubmitStatusText.js +32 -0
- package/es/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/es/components/material-quiz/context/MaterialQuizContext.js +124 -0
- package/es/components/material-quiz/index.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +86 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.js +456 -0
- package/es/components/material-quiz-edit/context.d.ts +6 -0
- package/es/components/material-quiz-edit/context.js +6 -0
- package/es/components/material-quiz-edit/index.d.ts +2 -0
- package/es/components/material-quiz-edit/locales.d.ts +34 -0
- package/es/components/material-quiz-edit/locales.js +68 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +197 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +198 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +200 -0
- package/es/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionText.js +93 -0
- package/es/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/es/components/material-quiz-edit/utils/editValue.js +32 -0
- package/es/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/es/components/material-quiz-edit/utils/randomId.js +8 -0
- package/es/components/shared/QuestionBox.d.ts +16 -0
- package/es/components/shared/QuestionBox.js +101 -0
- package/es/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/es/components/shared/QuizDraggbleDroppedOption.js +25 -0
- package/es/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/es/components/shared/QuizDraggbleDummyOption.js +29 -0
- package/es/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/es/components/shared/QuizDraggbleOption.js +184 -0
- package/es/components/shared/StyledMarkdown.d.ts +3 -0
- package/es/components/shared/StyledMarkdown.js +8 -0
- package/es/components/shared/index.d.ts +7 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +181 -0
- package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/es/components/shared/question-radio/QuestionRadio.js +19 -0
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
- package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioOption.js +149 -0
- package/es/helpers/index.d.ts +50 -0
- package/es/helpers/index.js +78 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +10 -0
- package/package.json +75 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
var reactTransitionGroup = require('react-transition-group');
|
|
7
|
+
var blocks = require('@elice/blocks');
|
|
8
|
+
var icons = require('@elice/icons');
|
|
9
|
+
var styled = require('styled-components');
|
|
10
|
+
var context = require('../context.js');
|
|
11
|
+
var randomId = require('../utils/randomId.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
17
|
+
|
|
18
|
+
const MIN_OPTION_INFO_COUNT = 2;
|
|
19
|
+
const MAX_OPTION_INFO_COUNT = 20;
|
|
20
|
+
const StyledWrap = styled__default["default"].div.withConfig({
|
|
21
|
+
componentId: "sc-1nbx9b8-0"
|
|
22
|
+
})([""]);
|
|
23
|
+
const StyledInputGroup = styled__default["default"].div.withConfig({
|
|
24
|
+
componentId: "sc-1nbx9b8-1"
|
|
25
|
+
})(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
|
|
26
|
+
|
|
27
|
+
const OptionSelectMultiple = () => {
|
|
28
|
+
const intl = reactIntl.useIntl();
|
|
29
|
+
const {
|
|
30
|
+
disabled
|
|
31
|
+
} = context.useMaterialQuizEditContext();
|
|
32
|
+
const {
|
|
33
|
+
control,
|
|
34
|
+
getValues,
|
|
35
|
+
setValue,
|
|
36
|
+
watch
|
|
37
|
+
} = reactHookForm.useFormContext();
|
|
38
|
+
const {
|
|
39
|
+
fields: optionInfoFields,
|
|
40
|
+
append: appendOptionInfoFieldItem,
|
|
41
|
+
remove: removeOptionInfoFieldItem
|
|
42
|
+
} = reactHookForm.useFieldArray({
|
|
43
|
+
name: 'optionInfo',
|
|
44
|
+
keyName: 'id',
|
|
45
|
+
shouldUnregister: true
|
|
46
|
+
});
|
|
47
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
48
|
+
/**
|
|
49
|
+
* Update answer info.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const updateAnswerInfo = option => {
|
|
53
|
+
const prevAnswerInfo = getValues('answerInfo');
|
|
54
|
+
|
|
55
|
+
if (!Array.isArray(prevAnswerInfo)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setValue('answerInfo', !option.checked ? prevAnswerInfo.filter(answerIndex => answerIndex !== option.index).map(answerIndex => option.removed ? // if answer removed, re-calculate answer index
|
|
60
|
+
answerIndex < option.index ? answerIndex : answerIndex - 1 : // or maintain current answer index
|
|
61
|
+
answerIndex) : [...prevAnswerInfo, option.index], {
|
|
62
|
+
shouldDirty: true,
|
|
63
|
+
shouldValidate: true
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Append option info.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const appendOptionInfo = () => {
|
|
72
|
+
appendOptionInfoFieldItem({
|
|
73
|
+
id: randomId.createRandomId(),
|
|
74
|
+
value: ''
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Remove item from option info at index.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const removeOptionInfo = index => {
|
|
83
|
+
updateAnswerInfo({
|
|
84
|
+
index,
|
|
85
|
+
checked: false,
|
|
86
|
+
removed: true
|
|
87
|
+
});
|
|
88
|
+
removeOptionInfoFieldItem(index);
|
|
89
|
+
}; //
|
|
90
|
+
//
|
|
91
|
+
//
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if (!Array.isArray(watchedAnswerInfo)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return React__default["default"].createElement(StyledWrap, null, React__default["default"].createElement(reactHookForm.Controller, {
|
|
99
|
+
name: "answerInfo",
|
|
100
|
+
control: control,
|
|
101
|
+
rules: {
|
|
102
|
+
validate: v => {
|
|
103
|
+
if (Array.isArray(v) && v.length < 1) {
|
|
104
|
+
return intl.formatMessage({
|
|
105
|
+
id: 'content.option.errorMessage.required'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
render: ({
|
|
113
|
+
fieldState
|
|
114
|
+
}) => {
|
|
115
|
+
var _a;
|
|
116
|
+
|
|
117
|
+
return React__default["default"].createElement(reactTransitionGroup.Transition, {
|
|
118
|
+
in: fieldState.invalid,
|
|
119
|
+
timeout: 0,
|
|
120
|
+
mountOnEnter: true,
|
|
121
|
+
unmountOnExit: true
|
|
122
|
+
}, React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.StatusText, {
|
|
123
|
+
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
124
|
+
role: "danger"
|
|
125
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
126
|
+
height: 0.5
|
|
127
|
+
})));
|
|
128
|
+
}
|
|
129
|
+
}), React__default["default"].createElement(StyledInputGroup, null, optionInfoFields.map(({
|
|
130
|
+
id
|
|
131
|
+
}, index) => React__default["default"].createElement(reactHookForm.Controller, {
|
|
132
|
+
key: id,
|
|
133
|
+
control: control,
|
|
134
|
+
name: `optionInfo.${index}.value`,
|
|
135
|
+
rules: {
|
|
136
|
+
required: {
|
|
137
|
+
value: true,
|
|
138
|
+
message: intl.formatMessage({
|
|
139
|
+
id: 'option.common.select.errorMessage.required'
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
render: ({
|
|
144
|
+
field,
|
|
145
|
+
fieldState
|
|
146
|
+
}) => {
|
|
147
|
+
var _a;
|
|
148
|
+
|
|
149
|
+
return React__default["default"].createElement(blocks.Input, Object.assign({
|
|
150
|
+
size: "small",
|
|
151
|
+
width: "full",
|
|
152
|
+
placeholder: intl.formatMessage({
|
|
153
|
+
id: 'option.common.select.placeholder'
|
|
154
|
+
}),
|
|
155
|
+
prefix: React__default["default"].createElement(blocks.Checkbox, {
|
|
156
|
+
checked: watchedAnswerInfo.includes(index),
|
|
157
|
+
disabled: disabled,
|
|
158
|
+
onChange: checked => updateAnswerInfo({
|
|
159
|
+
index,
|
|
160
|
+
checked
|
|
161
|
+
})
|
|
162
|
+
}),
|
|
163
|
+
suffix: React__default["default"].createElement(blocks.Tooltip, {
|
|
164
|
+
title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
165
|
+
id: 'option.common.select.tooltip.minOptionInfoItem'
|
|
166
|
+
}) : undefined,
|
|
167
|
+
placement: "top-start"
|
|
168
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
|
|
169
|
+
icon: icons.eilMathsignMultiplyBasic,
|
|
170
|
+
size: "tiny",
|
|
171
|
+
role: "grey9",
|
|
172
|
+
border: false,
|
|
173
|
+
transparent: true,
|
|
174
|
+
disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
|
|
175
|
+
onClick: () => removeOptionInfo(index)
|
|
176
|
+
}))),
|
|
177
|
+
readOnly: disabled,
|
|
178
|
+
invalid: fieldState.invalid,
|
|
179
|
+
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
|
|
180
|
+
}, field));
|
|
181
|
+
}
|
|
182
|
+
}))), React__default["default"].createElement(blocks.Vspace, {
|
|
183
|
+
height: 0.5
|
|
184
|
+
}), React__default["default"].createElement(blocks.Tooltip, {
|
|
185
|
+
title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
186
|
+
id: 'option.common.select.tooltip.maxOptionInfoItem'
|
|
187
|
+
}) : undefined,
|
|
188
|
+
placement: "bottom"
|
|
189
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
|
|
190
|
+
block: true,
|
|
191
|
+
size: "micro",
|
|
192
|
+
borderDashed: true,
|
|
193
|
+
transparent: true,
|
|
194
|
+
icon: React__default["default"].createElement(blocks.Icon, {
|
|
195
|
+
icon: icons.eilMathsignAddCircle
|
|
196
|
+
}),
|
|
197
|
+
disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
|
|
198
|
+
onClick: appendOptionInfo
|
|
199
|
+
}, React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
200
|
+
id: "option.common.select.addButton"
|
|
201
|
+
})))));
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
module.exports = OptionSelectMultiple;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
var reactTransitionGroup = require('react-transition-group');
|
|
7
|
+
var blocks = require('@elice/blocks');
|
|
8
|
+
var icons = require('@elice/icons');
|
|
9
|
+
var styled = require('styled-components');
|
|
10
|
+
var context = require('../context.js');
|
|
11
|
+
var randomId = require('../utils/randomId.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
17
|
+
|
|
18
|
+
const MIN_OPTION_INFO_COUNT = 2;
|
|
19
|
+
const MAX_OPTION_INFO_COUNT = 20;
|
|
20
|
+
const StyledWrap = styled__default["default"].div.withConfig({
|
|
21
|
+
componentId: "sc-1xufc1p-0"
|
|
22
|
+
})([""]);
|
|
23
|
+
const StyledInputGroup = styled__default["default"].div.withConfig({
|
|
24
|
+
componentId: "sc-1xufc1p-1"
|
|
25
|
+
})(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
|
|
26
|
+
|
|
27
|
+
const OptionSelectMultipleOrder = () => {
|
|
28
|
+
const intl = reactIntl.useIntl();
|
|
29
|
+
const {
|
|
30
|
+
disabled
|
|
31
|
+
} = context.useMaterialQuizEditContext();
|
|
32
|
+
const {
|
|
33
|
+
control,
|
|
34
|
+
getValues,
|
|
35
|
+
setValue,
|
|
36
|
+
watch
|
|
37
|
+
} = reactHookForm.useFormContext();
|
|
38
|
+
const {
|
|
39
|
+
fields: optionInfoFields,
|
|
40
|
+
append: appendOptionInfoFieldItem,
|
|
41
|
+
remove: removeOptionInfoFieldItem
|
|
42
|
+
} = reactHookForm.useFieldArray({
|
|
43
|
+
name: 'optionInfo',
|
|
44
|
+
keyName: 'id',
|
|
45
|
+
shouldUnregister: true
|
|
46
|
+
});
|
|
47
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
48
|
+
/**
|
|
49
|
+
* Update answer info.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const updateAnswerInfo = option => {
|
|
53
|
+
const prevAnswerInfo = getValues('answerInfo');
|
|
54
|
+
|
|
55
|
+
if (!Array.isArray(prevAnswerInfo)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setValue('answerInfo', !option.checked ? prevAnswerInfo.filter(answerIndex => answerIndex !== option.index).map(answerIndex => option.removed ? // if answer removed, re-calculate answer index
|
|
60
|
+
answerIndex < option.index ? answerIndex : answerIndex - 1 : // or maintain current answer index
|
|
61
|
+
answerIndex) : [...prevAnswerInfo, option.index], {
|
|
62
|
+
shouldDirty: true,
|
|
63
|
+
shouldValidate: true
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Append option info.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const appendOptionInfo = () => {
|
|
72
|
+
appendOptionInfoFieldItem({
|
|
73
|
+
id: randomId.createRandomId(),
|
|
74
|
+
value: ''
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Remove item from option info at index.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const removeOptionInfo = index => {
|
|
83
|
+
updateAnswerInfo({
|
|
84
|
+
index,
|
|
85
|
+
checked: false,
|
|
86
|
+
removed: true
|
|
87
|
+
});
|
|
88
|
+
removeOptionInfoFieldItem(index);
|
|
89
|
+
}; //
|
|
90
|
+
//
|
|
91
|
+
//
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if (!Array.isArray(watchedAnswerInfo)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return React__default["default"].createElement(StyledWrap, null, React__default["default"].createElement(reactHookForm.Controller, {
|
|
99
|
+
name: "answerInfo",
|
|
100
|
+
control: control,
|
|
101
|
+
rules: {
|
|
102
|
+
validate: v => {
|
|
103
|
+
if (Array.isArray(v) && v.length < 1) {
|
|
104
|
+
return intl.formatMessage({
|
|
105
|
+
id: 'content.option.errorMessage.required'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
render: ({
|
|
113
|
+
fieldState
|
|
114
|
+
}) => {
|
|
115
|
+
var _a;
|
|
116
|
+
|
|
117
|
+
return React__default["default"].createElement(reactTransitionGroup.Transition, {
|
|
118
|
+
in: fieldState.invalid,
|
|
119
|
+
timeout: 0,
|
|
120
|
+
mountOnEnter: true,
|
|
121
|
+
unmountOnExit: true
|
|
122
|
+
}, React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.StatusText, {
|
|
123
|
+
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
124
|
+
role: "danger"
|
|
125
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
126
|
+
height: 0.5
|
|
127
|
+
})));
|
|
128
|
+
}
|
|
129
|
+
}), React__default["default"].createElement(StyledInputGroup, null, optionInfoFields.map(({
|
|
130
|
+
id
|
|
131
|
+
}, index) => React__default["default"].createElement(reactHookForm.Controller, {
|
|
132
|
+
key: id,
|
|
133
|
+
control: control,
|
|
134
|
+
name: `optionInfo.${index}.value`,
|
|
135
|
+
rules: {
|
|
136
|
+
required: {
|
|
137
|
+
value: true,
|
|
138
|
+
message: intl.formatMessage({
|
|
139
|
+
id: 'option.common.select.errorMessage.required'
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
render: ({
|
|
144
|
+
field,
|
|
145
|
+
fieldState
|
|
146
|
+
}) => {
|
|
147
|
+
var _a;
|
|
148
|
+
|
|
149
|
+
return React__default["default"].createElement(blocks.Input, Object.assign({
|
|
150
|
+
size: "small",
|
|
151
|
+
width: "full",
|
|
152
|
+
placeholder: intl.formatMessage({
|
|
153
|
+
id: 'option.common.select.placeholder'
|
|
154
|
+
}),
|
|
155
|
+
prefix: React__default["default"].createElement(blocks.Checkbox, {
|
|
156
|
+
checked: watchedAnswerInfo.includes(index),
|
|
157
|
+
disabled: disabled,
|
|
158
|
+
altChar: watchedAnswerInfo.indexOf(index) + 1,
|
|
159
|
+
onChange: checked => updateAnswerInfo({
|
|
160
|
+
index,
|
|
161
|
+
checked
|
|
162
|
+
})
|
|
163
|
+
}),
|
|
164
|
+
suffix: React__default["default"].createElement(blocks.Tooltip, {
|
|
165
|
+
title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
166
|
+
id: 'option.common.select.tooltip.minOptionInfoItem'
|
|
167
|
+
}) : undefined,
|
|
168
|
+
placement: "top-start"
|
|
169
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
|
|
170
|
+
icon: icons.eilMathsignMultiplyBasic,
|
|
171
|
+
size: "tiny",
|
|
172
|
+
role: "grey9",
|
|
173
|
+
border: false,
|
|
174
|
+
transparent: true,
|
|
175
|
+
disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
|
|
176
|
+
onClick: () => removeOptionInfo(index)
|
|
177
|
+
}))),
|
|
178
|
+
readOnly: disabled,
|
|
179
|
+
invalid: fieldState.invalid,
|
|
180
|
+
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
|
|
181
|
+
}, field));
|
|
182
|
+
}
|
|
183
|
+
}))), React__default["default"].createElement(blocks.Vspace, {
|
|
184
|
+
height: 0.5
|
|
185
|
+
}), React__default["default"].createElement(blocks.Tooltip, {
|
|
186
|
+
title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
187
|
+
id: 'option.common.select.tooltip.maxOptionInfoItem'
|
|
188
|
+
}) : undefined,
|
|
189
|
+
placement: "bottom"
|
|
190
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
|
|
191
|
+
block: true,
|
|
192
|
+
size: "micro",
|
|
193
|
+
borderDashed: true,
|
|
194
|
+
transparent: true,
|
|
195
|
+
icon: React__default["default"].createElement(blocks.Icon, {
|
|
196
|
+
icon: icons.eilMathsignAddCircle
|
|
197
|
+
}),
|
|
198
|
+
disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
|
|
199
|
+
onClick: appendOptionInfo
|
|
200
|
+
}, React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
201
|
+
id: "option.common.select.addButton"
|
|
202
|
+
})))));
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
module.exports = OptionSelectMultipleOrder;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHookForm = require('react-hook-form');
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
var reactTransitionGroup = require('react-transition-group');
|
|
7
|
+
var blocks = require('@elice/blocks');
|
|
8
|
+
var icons = require('@elice/icons');
|
|
9
|
+
var styled = require('styled-components');
|
|
10
|
+
var context = require('../context.js');
|
|
11
|
+
var randomId = require('../utils/randomId.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
17
|
+
|
|
18
|
+
const MIN_OPTION_INFO_COUNT = 2;
|
|
19
|
+
const MAX_OPTION_INFO_COUNT = 20;
|
|
20
|
+
const StyledWrap = styled__default["default"].div.withConfig({
|
|
21
|
+
componentId: "sc-vizer2-0"
|
|
22
|
+
})([""]);
|
|
23
|
+
const StyledInputGroup = styled__default["default"].div.withConfig({
|
|
24
|
+
componentId: "sc-vizer2-1"
|
|
25
|
+
})(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
|
|
26
|
+
const StyledInputPrefixRadioOption = styled__default["default"](blocks.RadioOption).withConfig({
|
|
27
|
+
componentId: "sc-vizer2-2"
|
|
28
|
+
})([".eb-radio-option__label{display:none;}"]);
|
|
29
|
+
|
|
30
|
+
const OptionSelectOne = () => {
|
|
31
|
+
const intl = reactIntl.useIntl();
|
|
32
|
+
const {
|
|
33
|
+
disabled
|
|
34
|
+
} = context.useMaterialQuizEditContext();
|
|
35
|
+
const {
|
|
36
|
+
control,
|
|
37
|
+
getValues,
|
|
38
|
+
setValue,
|
|
39
|
+
watch
|
|
40
|
+
} = reactHookForm.useFormContext();
|
|
41
|
+
const {
|
|
42
|
+
fields: optionInfoFields,
|
|
43
|
+
append: appendOptionInfoFieldItem,
|
|
44
|
+
remove: removeOptionInfoFieldItem
|
|
45
|
+
} = reactHookForm.useFieldArray({
|
|
46
|
+
name: 'optionInfo',
|
|
47
|
+
keyName: 'id',
|
|
48
|
+
shouldUnregister: true
|
|
49
|
+
});
|
|
50
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
51
|
+
/**
|
|
52
|
+
* Update answer info.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const updateAnswerInfo = index => {
|
|
56
|
+
const prevAnswerInfo = getValues('answerInfo');
|
|
57
|
+
|
|
58
|
+
if (!Array.isArray(prevAnswerInfo)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setValue('answerInfo', [index], {
|
|
63
|
+
shouldDirty: true,
|
|
64
|
+
shouldValidate: true
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Append option info.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
const appendOptionInfo = () => {
|
|
73
|
+
appendOptionInfoFieldItem({
|
|
74
|
+
id: randomId.createRandomId(),
|
|
75
|
+
value: ''
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Remove item from option info at index.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const removeOptionInfo = index => {
|
|
84
|
+
// set answer info to 0 index,
|
|
85
|
+
// if this option is selected as answer.
|
|
86
|
+
const curAnswerInfo = getValues('answerInfo');
|
|
87
|
+
|
|
88
|
+
if (Array.isArray(curAnswerInfo) && curAnswerInfo.includes(index)) {
|
|
89
|
+
updateAnswerInfo(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
removeOptionInfoFieldItem(index);
|
|
93
|
+
}; //
|
|
94
|
+
//
|
|
95
|
+
//
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if (!Array.isArray(watchedAnswerInfo)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return React__default["default"].createElement(StyledWrap, null, React__default["default"].createElement(reactHookForm.Controller, {
|
|
103
|
+
name: "answerInfo",
|
|
104
|
+
control: control,
|
|
105
|
+
rules: {
|
|
106
|
+
validate: v => {
|
|
107
|
+
if (Array.isArray(v) && v.length < 1) {
|
|
108
|
+
return intl.formatMessage({
|
|
109
|
+
id: 'content.option.errorMessage.required'
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
render: ({
|
|
117
|
+
fieldState
|
|
118
|
+
}) => {
|
|
119
|
+
var _a;
|
|
120
|
+
|
|
121
|
+
return React__default["default"].createElement(reactTransitionGroup.Transition, {
|
|
122
|
+
in: fieldState.invalid,
|
|
123
|
+
timeout: 0,
|
|
124
|
+
mountOnEnter: true,
|
|
125
|
+
unmountOnExit: true
|
|
126
|
+
}, React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.StatusText, {
|
|
127
|
+
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
128
|
+
role: "danger"
|
|
129
|
+
}), React__default["default"].createElement(blocks.Vspace, {
|
|
130
|
+
height: 0.5
|
|
131
|
+
})));
|
|
132
|
+
}
|
|
133
|
+
}), React__default["default"].createElement(StyledInputGroup, null, optionInfoFields.map(({
|
|
134
|
+
id
|
|
135
|
+
}, index) => React__default["default"].createElement(reactHookForm.Controller, {
|
|
136
|
+
key: id,
|
|
137
|
+
control: control,
|
|
138
|
+
name: `optionInfo.${index}.value`,
|
|
139
|
+
rules: {
|
|
140
|
+
required: {
|
|
141
|
+
value: true,
|
|
142
|
+
message: intl.formatMessage({
|
|
143
|
+
id: 'option.common.select.errorMessage.required'
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
render: ({
|
|
148
|
+
field,
|
|
149
|
+
fieldState
|
|
150
|
+
}) => {
|
|
151
|
+
var _a;
|
|
152
|
+
|
|
153
|
+
return React__default["default"].createElement(blocks.Input, Object.assign({
|
|
154
|
+
size: "small",
|
|
155
|
+
width: "full",
|
|
156
|
+
placeholder: intl.formatMessage({
|
|
157
|
+
id: 'option.common.select.placeholder'
|
|
158
|
+
}),
|
|
159
|
+
prefix: React__default["default"].createElement(blocks.Radio, {
|
|
160
|
+
value: watchedAnswerInfo[0],
|
|
161
|
+
disabled: disabled,
|
|
162
|
+
onChange: updateAnswerInfo
|
|
163
|
+
}, React__default["default"].createElement(StyledInputPrefixRadioOption, {
|
|
164
|
+
value: index
|
|
165
|
+
}), React__default["default"].createElement(React__default["default"].Fragment, null)),
|
|
166
|
+
suffix: React__default["default"].createElement(blocks.Tooltip, {
|
|
167
|
+
title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
168
|
+
id: 'option.common.select.tooltip.minOptionInfoItem'
|
|
169
|
+
}) : undefined,
|
|
170
|
+
placement: "top-start"
|
|
171
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
|
|
172
|
+
icon: icons.eilMathsignMultiplyBasic,
|
|
173
|
+
size: "tiny",
|
|
174
|
+
role: "grey9",
|
|
175
|
+
border: false,
|
|
176
|
+
transparent: true,
|
|
177
|
+
disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
|
|
178
|
+
onClick: () => removeOptionInfo(index)
|
|
179
|
+
}))),
|
|
180
|
+
readOnly: disabled,
|
|
181
|
+
invalid: fieldState.invalid,
|
|
182
|
+
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
|
|
183
|
+
}, field));
|
|
184
|
+
}
|
|
185
|
+
}))), React__default["default"].createElement(blocks.Vspace, {
|
|
186
|
+
height: 0.5
|
|
187
|
+
}), React__default["default"].createElement(blocks.Tooltip, {
|
|
188
|
+
title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
189
|
+
id: 'option.common.select.tooltip.maxOptionInfoItem'
|
|
190
|
+
}) : undefined,
|
|
191
|
+
placement: "bottom"
|
|
192
|
+
}, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
|
|
193
|
+
block: true,
|
|
194
|
+
size: "micro",
|
|
195
|
+
borderDashed: true,
|
|
196
|
+
transparent: true,
|
|
197
|
+
icon: React__default["default"].createElement(blocks.Icon, {
|
|
198
|
+
icon: icons.eilMathsignAddCircle
|
|
199
|
+
}),
|
|
200
|
+
disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
|
|
201
|
+
onClick: appendOptionInfo
|
|
202
|
+
}, React__default["default"].createElement(reactIntl.FormattedMessage, {
|
|
203
|
+
id: "option.common.select.addButton"
|
|
204
|
+
})))));
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
module.exports = OptionSelectOne;
|