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