@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,136 @@
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 trim from 'lodash-es/trim';
8
+ import styled from 'styled-components';
9
+
10
+ const SHEET_Z_INDEX = 982;
11
+ const MIN_GROUP_INFO_COUNT = 2;
12
+ const StyledSortableListItem = styled(SortableListItem).withConfig({
13
+ componentId: "sc-hj5nic-0"
14
+ })(["display:flex;z-index:", ";width:100%;padding:0;background:transparent;box-shadow:none;&:not(:last-child){margin-bottom:0.5rem;}"], SHEET_Z_INDEX + 1);
15
+ const StyledSortableListItemOptionWrapper = styled.div.withConfig({
16
+ componentId: "sc-hj5nic-1"
17
+ })(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border-radius:4px;border:1px solid ", ";background:", ";"], ({
18
+ isGroupChildAnswer
19
+ }) => isGroupChildAnswer ? base.color.red8 : base.color.gray3, base.color.white);
20
+ const StyledInputGroup = styled(Input).withConfig({
21
+ componentId: "sc-hj5nic-2"
22
+ })(["& > div{border:0;}"]);
23
+
24
+ const OptionGroupGroupListItem = ({
25
+ groupId,
26
+ groupsCount,
27
+ onRemoveOption
28
+ }) => {
29
+ var _a, _b, _c, _d, _e;
30
+
31
+ const intl = useIntl();
32
+ const {
33
+ control,
34
+ formState,
35
+ watch
36
+ } = useFormContext();
37
+ const watchedAnswerInfo = watch('answerInfo');
38
+ const isGroupChildAnswer = Boolean((_a = watchedAnswerInfo[groupId]) === null || _a === void 0 ? void 0 : _a.length);
39
+ const isMinimumGroups = groupsCount <= MIN_GROUP_INFO_COUNT;
40
+ 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;
41
+ /**
42
+ *
43
+ */
44
+
45
+ const renderOptionGroupInput = () => {
46
+ return React.createElement(StyledSortableListItemOptionWrapper, {
47
+ isGroupChildAnswer: !isGroupChildAnswer
48
+ }, React.createElement(Controller, {
49
+ control: control,
50
+ name: `groups.${groupId}.group`,
51
+ rules: {
52
+ required: {
53
+ value: true,
54
+ message: intl.formatMessage({
55
+ id: 'group.option.errorMessage.required'
56
+ })
57
+ },
58
+ validate: e => {
59
+ if (!trim(e).length) {
60
+ return intl.formatMessage({
61
+ id: 'group.option.errorMessage.required'
62
+ });
63
+ }
64
+
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.createElement(StyledInputGroup, Object.assign({}, field, {
76
+ invalid: fieldState.invalid || !isGroupChildAnswer,
77
+ width: "full"
78
+ }))
79
+ }));
80
+ };
81
+ /**
82
+ *
83
+ */
84
+
85
+
86
+ const renderOptionRemoveButton = () => {
87
+ return React.createElement(React.Fragment, null, React.createElement(Hspace, {
88
+ width: 0.5
89
+ }), React.createElement(Tooltip, {
90
+ title: isMinimumGroups ? intl.formatMessage({
91
+ id: 'group.option.tooltip.minDisabled'
92
+ }) : undefined,
93
+ placement: "top"
94
+ }, React.createElement("span", null, React.createElement(IconButton, {
95
+ transparent: true,
96
+ icon: eilMathsignMultiplyBasic,
97
+ role: "gray6",
98
+ size: "micro",
99
+ border: false,
100
+ disabled: isMinimumGroups,
101
+ onClick: onRemoveOption
102
+ }))));
103
+ };
104
+ /**
105
+ *
106
+ */
107
+
108
+
109
+ const renderErrorMessage = () => {
110
+ if (!errorMessage) {
111
+ return null;
112
+ }
113
+
114
+ return React.createElement(Flex, {
115
+ paddingleft: "0.25rem"
116
+ }, React.createElement(Text, {
117
+ size: "small",
118
+ role: "danger"
119
+ }, errorMessage));
120
+ }; //
121
+ //
122
+ //
123
+
124
+
125
+ return React.createElement(StyledSortableListItem, {
126
+ index: groupId
127
+ }, React.createElement(Flex, {
128
+ justify: "center",
129
+ width: "100%",
130
+ column: true
131
+ }, React.createElement(Flex, {
132
+ align: "center"
133
+ }, renderOptionGroupInput(), renderOptionRemoveButton()), renderErrorMessage()));
134
+ };
135
+
136
+ export { OptionGroupGroupListItem as default };
@@ -1,3 +1,4 @@
1
+ import trim from 'lodash-es/trim';
1
2
  import { createRandomId } from './randomId.js';
2
3
 
3
4
  /**
@@ -30,13 +31,13 @@ function manipulateValue(v) {
30
31
  function restoreValue(v) {
31
32
  return Object.assign(Object.assign({}, v), {
32
33
  options: v.options.length ? v.options.map(option => ({
33
- title: option.title,
34
+ title: trim(option.title),
34
35
  content: option.content
35
36
  })) : null,
36
37
  answerInfo: Array.isArray(v.answerInfo) || typeof v.answerInfo === 'string' ? v.answerInfo : undefined,
37
38
  groups: v.groups.length ? v.groups.map(({
38
39
  group
39
- }) => group) : null
40
+ }) => trim(group)) : null
40
41
  });
41
42
  }
42
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-quiz",
3
- "version": "1.221217.0",
3
+ "version": "1.221228.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.221217.0",
62
- "@elice/material-shared-utils": "1.221217.0",
61
+ "@elice/material-shared-types": "1.221228.0",
62
+ "@elice/material-shared-utils": "1.221228.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": "0c56eb2b44bd1620a528da0b9d4e33fd76d91d46"
76
+ "gitHead": "53eaff58a939c390104c7e96f0bc3eb8738a3ee7"
77
77
  }