@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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useFormContext, Controller } from 'react-hook-form';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
import { SortableListItem, Input, Flex, Hspace, Tooltip, IconButton, Text } from '@elice/blocks';
|
|
5
|
+
import { base } from '@elice/design-tokens';
|
|
6
|
+
import { eilMathsignMultiplyBasic } from '@elice/icons';
|
|
7
|
+
import styled from 'styled-components';
|
|
8
|
+
|
|
9
|
+
const SHEET_Z_INDEX = 982;
|
|
10
|
+
const MIN_GROUP_INFO_COUNT = 2;
|
|
11
|
+
const StyledSortableListItem = styled(SortableListItem).withConfig({
|
|
12
|
+
componentId: "sc-hj5nic-0"
|
|
13
|
+
})(["display:flex;z-index:", ";width:100%;padding:0;background:transparent;box-shadow:none;"], SHEET_Z_INDEX + 1);
|
|
14
|
+
const StyledSortableListItemOptionWrapper = styled.div.withConfig({
|
|
15
|
+
componentId: "sc-hj5nic-1"
|
|
16
|
+
})(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border-radius:4px;border:1px solid ", ";background:", ";"], ({
|
|
17
|
+
isGroupChildAnswer
|
|
18
|
+
}) => isGroupChildAnswer ? base.color.red8 : base.color.gray3, base.color.white);
|
|
19
|
+
const StyledInputGroup = styled(Input).withConfig({
|
|
20
|
+
componentId: "sc-hj5nic-2"
|
|
21
|
+
})(["& > div{border:0;}"]);
|
|
22
|
+
|
|
23
|
+
const OptionGroupGroupListItem = ({
|
|
24
|
+
groupId,
|
|
25
|
+
groupsCount,
|
|
26
|
+
onRemoveOption
|
|
27
|
+
}) => {
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
29
|
+
|
|
30
|
+
const intl = useIntl();
|
|
31
|
+
const {
|
|
32
|
+
control,
|
|
33
|
+
formState,
|
|
34
|
+
watch
|
|
35
|
+
} = useFormContext();
|
|
36
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
37
|
+
const isGroupChildAnswer = Boolean((_a = watchedAnswerInfo[groupId]) === null || _a === void 0 ? void 0 : _a.length);
|
|
38
|
+
const isMinimumGroups = groupsCount <= MIN_GROUP_INFO_COUNT;
|
|
39
|
+
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;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const renderOptionGroupInput = () => {
|
|
45
|
+
return React.createElement(StyledSortableListItemOptionWrapper, {
|
|
46
|
+
isGroupChildAnswer: !isGroupChildAnswer
|
|
47
|
+
}, React.createElement(Controller, {
|
|
48
|
+
control: control,
|
|
49
|
+
name: `groups.${groupId}.group`,
|
|
50
|
+
rules: {
|
|
51
|
+
required: {
|
|
52
|
+
value: true,
|
|
53
|
+
message: intl.formatMessage({
|
|
54
|
+
id: 'group.option.errorMessage.required'
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
validate: () => {
|
|
58
|
+
if (!isGroupChildAnswer) {
|
|
59
|
+
return intl.formatMessage({
|
|
60
|
+
id: 'group.option.errorMessage.notChild'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
render: ({
|
|
66
|
+
field,
|
|
67
|
+
fieldState
|
|
68
|
+
}) => React.createElement(StyledInputGroup, Object.assign({}, field, {
|
|
69
|
+
invalid: fieldState.invalid || !isGroupChildAnswer,
|
|
70
|
+
width: "full",
|
|
71
|
+
onChange: e => {
|
|
72
|
+
field.onChange(e.target.value.replace(' ', ''));
|
|
73
|
+
}
|
|
74
|
+
}))
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const renderOptionRemoveButton = () => {
|
|
83
|
+
return React.createElement(React.Fragment, null, React.createElement(Hspace, {
|
|
84
|
+
width: 0.5
|
|
85
|
+
}), React.createElement(Tooltip, {
|
|
86
|
+
title: isMinimumGroups ? intl.formatMessage({
|
|
87
|
+
id: 'group.option.tooltip.minDisabled'
|
|
88
|
+
}) : undefined,
|
|
89
|
+
placement: "top"
|
|
90
|
+
}, React.createElement("span", null, React.createElement(IconButton, {
|
|
91
|
+
transparent: true,
|
|
92
|
+
icon: eilMathsignMultiplyBasic,
|
|
93
|
+
role: "gray6",
|
|
94
|
+
size: "micro",
|
|
95
|
+
border: false,
|
|
96
|
+
disabled: isMinimumGroups,
|
|
97
|
+
onClick: onRemoveOption
|
|
98
|
+
}))));
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
const renderErrorMessage = () => {
|
|
106
|
+
if (!errorMessage) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return React.createElement(Flex, {
|
|
111
|
+
paddingleft: "0.25rem"
|
|
112
|
+
}, React.createElement(Text, {
|
|
113
|
+
size: "small",
|
|
114
|
+
role: "danger"
|
|
115
|
+
}, errorMessage));
|
|
116
|
+
}; //
|
|
117
|
+
//
|
|
118
|
+
//
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
return React.createElement(StyledSortableListItem, {
|
|
122
|
+
index: groupId
|
|
123
|
+
}, React.createElement(Flex, {
|
|
124
|
+
justify: "center",
|
|
125
|
+
width: "100%",
|
|
126
|
+
column: true
|
|
127
|
+
}, React.createElement(Flex, {
|
|
128
|
+
align: "center"
|
|
129
|
+
}, renderOptionGroupInput(), renderOptionRemoveButton()), renderErrorMessage()));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export { OptionGroupGroupListItem as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elice/material-quiz",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.221222.0",
|
|
4
4
|
"description": "User view and editing components of Elice material quiz",
|
|
5
5
|
"repository": "https://git.elicer.io/elice/frontend/library/elice-material",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"@elice/icons": "^1.220803.0",
|
|
59
59
|
"@elice/icons-legacy": "npm:@elice/icons@0.220803.1",
|
|
60
60
|
"@elice/markdown": "^1.220803.0",
|
|
61
|
-
"@elice/material-shared-types": "1.
|
|
62
|
-
"@elice/material-shared-utils": "1.
|
|
61
|
+
"@elice/material-shared-types": "1.221222.0",
|
|
62
|
+
"@elice/material-shared-utils": "1.221222.0",
|
|
63
63
|
"@elice/types": "1.221217.0",
|
|
64
64
|
"@types/classnames": "^2.3.1",
|
|
65
65
|
"@types/jquery": "^3.5.13",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-use": "^17.2.4",
|
|
74
74
|
"styled-components": "^5.3.0"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "417f2c0d5c6c4ffc7c5c2ab95ec7a2ca36dca843"
|
|
77
77
|
}
|