@pie-lib/text-select 1.13.1-beta.0 → 1.15.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/src/legend.js CHANGED
@@ -2,9 +2,9 @@ import React from 'react';
2
2
  import { withStyles } from '@material-ui/core/styles';
3
3
  import Check from '@material-ui/icons/Check';
4
4
  import Close from '@material-ui/icons/Close';
5
- import Remove from '@material-ui/icons/Remove';
6
- import { color } from '@pie-lib/render-ui';
5
+ import { color } from '../../render-ui/src/index';
7
6
  import Translator from '@pie-lib/translator';
7
+ import classNames from 'classnames';
8
8
 
9
9
  const { translator } = Translator;
10
10
 
@@ -12,6 +12,7 @@ export const Legend = withStyles((theme) => ({
12
12
  flexContainer: {
13
13
  display: 'flex',
14
14
  flexDirection: 'row',
15
+ alignItems: 'center',
15
16
  gap: `${2 * theme.spacing.unit}px`,
16
17
  borderBottom: '1px solid lightgrey',
17
18
  borderTop: '1px solid lightgrey',
@@ -19,60 +20,77 @@ export const Legend = withStyles((theme) => ({
19
20
  paddingTop: theme.spacing.unit,
20
21
  marginBottom: theme.spacing.unit,
21
22
  },
23
+ key: {
24
+ fontSize: '14px',
25
+ fontWeight: 'bold',
26
+ color: color.black(),
27
+ marginLeft: theme.spacing.unit,
28
+ },
22
29
  container: {
23
- display: 'flex',
24
- flexDirection: 'row',
25
- gap: `${theme.spacing.unit / 2}px`,
26
- alignItems: 'center',
30
+ position: 'relative',
31
+ padding: '4px',
32
+ fontSize: '14px',
33
+ borderRadius: '4px',
27
34
  },
28
35
  correct: {
29
- fontSize: 'larger',
30
- color: color.correct(),
31
- backgroundColor: color.correctSecondary(),
32
- border: `2px solid ${color.correct()}`,
36
+ border: `${color.correctTertiary()} solid 2px`,
33
37
  },
34
38
  incorrect: {
35
- fontSize: 'larger',
36
- color: color.missing(),
37
- backgroundColor: color.incorrectSecondary(),
38
- border: `2px solid ${color.missing()}`,
39
+ border: `${color.incorrectWithIcon()} solid 2px`,
39
40
  },
40
41
  missing: {
41
- fontSize: 'larger',
42
- color: color.missing(),
43
- backgroundColor: color.incorrectSecondary(),
44
- border: `2px dashed ${color.missing()}`,
42
+ border: `${color.incorrectWithIcon()} dashed 2px`,
43
+ },
44
+ incorrectIcon: {
45
+ backgroundColor: color.incorrectWithIcon(),
46
+ },
47
+ correctIcon: {
48
+ backgroundColor: color.correctTertiary(),
45
49
  },
46
- }))(({ classes, language }) => {
47
- const icons = [
50
+ icon: {
51
+ color: color.white(),
52
+ position: 'absolute',
53
+ top: '-8px',
54
+ left: '-8px',
55
+ borderRadius: '50%',
56
+ fontSize: '12px',
57
+ padding: '2px',
58
+ },
59
+ }))(({ classes, language, showOnlyCorrect }) => {
60
+ const legendItems = [
48
61
  {
49
- iconName: Check,
62
+ Icon: Check,
50
63
  label: translator.t('selectText.correctAnswerSelected', { lng: language }),
51
- className: classes.correct,
64
+ containerClass: classNames(classes.correct, classes.container),
65
+ iconClass: classNames(classes.correctIcon, classes.icon),
52
66
  },
53
67
  {
54
- iconName: Remove,
55
- label: translator.t('selectText.correctAnswerNotSelected', { lng: language }),
56
- className: classes.missing,
68
+ Icon: Close,
69
+ label: translator.t('selectText.incorrectSelection', { lng: language }),
70
+ containerClass: classNames(classes.incorrect, classes.container),
71
+ iconClass: classNames(classes.incorrectIcon, classes.icon),
57
72
  },
58
73
  {
59
- iconName: Close,
60
- label: translator.t('selectText.incorrectSelection', { lng: language }),
61
- className: classes.incorrect,
74
+ Icon: Close,
75
+ label: translator.t('selectText.correctAnswerNotSelected', { lng: language }),
76
+ containerClass: classNames(classes.missing, classes.container),
77
+ iconClass: classNames(classes.incorrectIcon, classes.icon),
62
78
  },
63
79
  ];
64
80
 
81
+ if (showOnlyCorrect) {
82
+ legendItems.splice(1, 2);
83
+ }
84
+
65
85
  return (
66
86
  <div className={classes.flexContainer}>
67
- {icons.map((icon, index) => {
68
- const Icon = icon.iconName;
69
- return (
70
- <div key={index} className={classes.container}>
71
- <Icon className={icon.className} width={'19px'} height={'19px'}></Icon>
72
- <span>{icon.label}</span>
73
- </div>
74
- );
75
- })}
87
+ <span className={classes.key}>{translator.t('selectText.key', { lng: language })}</span>
88
+ {legendItems.map(({ Icon, label, containerClass, iconClass }, idx) => (
89
+ <div key={idx} className={containerClass}>
90
+ <Icon className={iconClass} />
91
+ <span>{label}</span>
92
+ </div>
93
+ ))}
76
94
  </div>
77
95
  );
78
96
  });
@@ -1,9 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`token snapshot renders 1`] = `
4
- <Wrapper
5
- useWrapper={false}
6
- >
4
+ <Wrapper>
7
5
  <span
8
6
  className="tokenRootClass token"
9
7
  dangerouslySetInnerHTML={
@@ -16,9 +14,7 @@ exports[`token snapshot renders 1`] = `
16
14
  `;
17
15
 
18
16
  exports[`token snapshot renders with brs 1`] = `
19
- <Wrapper
20
- useWrapper={false}
21
- >
17
+ <Wrapper>
22
18
  <span
23
19
  className="tokenRootClass token"
24
20
  dangerouslySetInnerHTML={
@@ -2,22 +2,26 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
  import classNames from 'classnames';
5
- import { color } from '@pie-lib/render-ui';
6
5
  import Check from '@material-ui/icons/Check';
7
6
  import Close from '@material-ui/icons/Close';
8
7
 
9
- const Wrapper = ({ useWrapper, children, classNameContainer, iconClass, Icon }) => {
10
- if (useWrapper) {
11
- return (
12
- <span className={classNameContainer}>
13
- {children}
14
- <Icon className={iconClass} viewBox={'0 1 24 24'} />
15
- </span>
16
- );
17
- }
8
+ import { color } from '../../render-ui/src/index';
18
9
 
19
- return children;
20
- };
10
+ // we need to use a larger line height for the token to be more readable
11
+ const LINE_HEIGHT_MULTIPLIER = 3.2;
12
+ // we need a bit more space for correctness indicators
13
+ const CORRECTNESS_LINE_HEIGHT_MULTIPLIER = 3.4;
14
+ const CORRECTNESS_PADDING = 2;
15
+
16
+ const Wrapper = ({ useWrapper, children, classNameContainer, iconClass, Icon }) =>
17
+ useWrapper ? (
18
+ <span className={classNameContainer}>
19
+ {children}
20
+ <Icon className={iconClass} />
21
+ </span>
22
+ ) : (
23
+ children
24
+ );
21
25
 
22
26
  Wrapper.propTypes = {
23
27
  useWrapper: PropTypes.bool,
@@ -38,11 +42,11 @@ export class Token extends React.Component {
38
42
  static propTypes = {
39
43
  ...TokenTypes,
40
44
  classes: PropTypes.object.isRequired,
45
+ text: PropTypes.string.isRequired,
41
46
  className: PropTypes.string,
42
47
  disabled: PropTypes.bool,
43
48
  highlight: PropTypes.bool,
44
49
  correct: PropTypes.bool,
45
- text: PropTypes.string.isRequired,
46
50
  };
47
51
 
48
52
  static defaultProps = {
@@ -50,39 +54,55 @@ export class Token extends React.Component {
50
54
  text: '',
51
55
  };
52
56
 
53
- render() {
57
+ getClassAndIconConfig = () => {
54
58
  const {
55
- text,
56
59
  selectable,
57
60
  selected,
58
61
  classes,
59
62
  className: classNameProp,
60
63
  disabled,
61
- index,
62
64
  highlight,
63
65
  correct,
64
66
  animationsDisabled,
65
67
  isMissing,
66
68
  } = this.props;
67
69
  const isTouchEnabled = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
68
-
69
- let className;
70
+ const baseClassName = Token.rootClassName;
70
71
  let classNameContainer;
71
72
  let Icon;
72
73
  let iconClass;
73
74
 
74
75
  if (correct === undefined && selected && disabled) {
75
- className = classNames(classes.token, classes.selected, classes.disabledBlack);
76
- } else if (correct !== undefined) {
77
- className = classNames(Token.rootClassName, classes.custom);
78
- Icon = correct ? Check : Close;
79
- classNameContainer = correct === true ? classes.correct : classes.incorrect;
80
- iconClass = correct === true ? classes.correctIcon : classes.incorrectIcon;
81
- } else if (isMissing) {
82
- className = classNames(Token.rootClassName, classes.custom, isMissing === true && classes.missing);
83
- } else {
84
- className = classNames(
85
- Token.rootClassName,
76
+ return {
77
+ className: classNames(classes.token, classes.selected, classes.disabledBlack),
78
+ };
79
+ }
80
+
81
+ if (correct !== undefined) {
82
+ const isCorrect = correct === true;
83
+ return {
84
+ className: classNames(baseClassName, classes.custom),
85
+ classNameContainer: classNames(isCorrect ? classes.correct : classes.incorrect, classes.commonTokenStyle),
86
+ Icon: isCorrect ? Check : Close,
87
+ iconClass: classNames(
88
+ classes.correctnessIndicatorIcon,
89
+ isCorrect ? classes.correctIcon : classes.incorrectIcon,
90
+ ),
91
+ };
92
+ }
93
+
94
+ if (isMissing) {
95
+ return {
96
+ className: classNames(baseClassName, classes.custom, classes.missing, classes.commonTokenStyle),
97
+ classNameContainer: classes.commonTokenStyle,
98
+ Icon: Close,
99
+ iconClass: classNames(classes.correctnessIndicatorIcon, classes.incorrectIcon),
100
+ };
101
+ }
102
+
103
+ return {
104
+ className: classNames(
105
+ baseClassName,
86
106
  classes.token,
87
107
  disabled && classes.disabled,
88
108
  selectable && !disabled && !isTouchEnabled && classes.selectable,
@@ -91,11 +111,20 @@ export class Token extends React.Component {
91
111
  highlight && selectable && !disabled && !selected && classes.highlight,
92
112
  animationsDisabled && classes.print,
93
113
  classNameProp,
94
- );
95
- }
114
+ ),
115
+ classNameContainer,
116
+ Icon,
117
+ iconClass,
118
+ };
119
+ };
120
+
121
+ render() {
122
+ const { text, index, correct, isMissing } = this.props;
123
+ const { className, classNameContainer, Icon, iconClass } = this.getClassAndIconConfig();
124
+
96
125
  return (
97
126
  <Wrapper
98
- useWrapper={correct !== undefined}
127
+ useWrapper={correct !== undefined || isMissing}
99
128
  classNameContainer={classNameContainer}
100
129
  iconClass={iconClass}
101
130
  Icon={Icon}
@@ -124,67 +153,73 @@ export default withStyles((theme) => {
124
153
  cursor: 'inherit',
125
154
  },
126
155
  disabledAndSelected: {
127
- backgroundColor: color.secondaryLight(),
156
+ backgroundColor: color.blueGrey100(),
128
157
  },
129
158
  selectable: {
130
159
  [theme.breakpoints.up(769)]: {
131
160
  '&:hover': {
132
- backgroundColor: color.primaryLight(),
161
+ backgroundColor: color.blueGrey300(),
133
162
  color: theme.palette.common.black,
134
163
  '& > *': {
135
- backgroundColor: color.primaryLight(),
164
+ backgroundColor: color.blueGrey300(),
136
165
  },
137
166
  },
138
167
  },
139
168
  },
140
169
  selected: {
141
- backgroundColor: color.primaryLight(),
170
+ backgroundColor: color.blueGrey100(),
142
171
  color: theme.palette.common.black,
143
- lineHeight: `${theme.spacing.unit * 3}px`,
172
+ lineHeight: `${theme.spacing.unit * LINE_HEIGHT_MULTIPLIER}px`,
173
+ border: `solid 2px ${color.blueGrey900()}`,
174
+ borderRadius: '4px',
144
175
  '& > *': {
145
- backgroundColor: color.primaryLight(),
176
+ backgroundColor: color.blueGrey100(),
146
177
  },
147
178
  },
148
179
  highlight: {
149
- border: `dashed 2px ${color.disabled()}`,
150
- lineHeight: `${theme.spacing.unit * 3}px`,
180
+ border: `dashed 2px ${color.blueGrey600()}`,
181
+ borderRadius: '4px',
182
+ lineHeight: `${theme.spacing.unit * LINE_HEIGHT_MULTIPLIER}px`,
151
183
  },
152
184
  print: {
153
- border: `dashed 2px ${color.disabled()}`,
154
- lineHeight: `${theme.spacing.unit * 3}px`,
185
+ border: `dashed 2px ${color.blueGrey600()}`,
186
+ borderRadius: '4px',
187
+ lineHeight: `${theme.spacing.unit * LINE_HEIGHT_MULTIPLIER}px`,
155
188
  color: color.text(),
156
189
  },
157
190
  custom: {
158
191
  display: 'initial',
159
192
  },
160
- correct: {
161
- backgroundColor: color.correctSecondary(),
162
- border: `${color.correct()} solid 2px`,
193
+ commonTokenStyle: {
194
+ position: 'relative',
195
+ borderRadius: '4px',
163
196
  color: theme.palette.common.black,
164
- lineHeight: `${theme.spacing.unit * 3}px`,
197
+ lineHeight: `${theme.spacing.unit * CORRECTNESS_LINE_HEIGHT_MULTIPLIER + CORRECTNESS_PADDING}px`,
198
+ padding: `${CORRECTNESS_PADDING}px`,
199
+ },
200
+ correct: {
201
+ border: `${color.correctTertiary()} solid 2px`,
165
202
  },
166
203
  incorrect: {
167
- backgroundColor: color.incorrectSecondary(),
168
- border: `${color.missing()} solid 2px`,
169
- color: theme.palette.common.black,
170
- lineHeight: `${theme.spacing.unit * 3}px`,
204
+ border: `${color.incorrectWithIcon()} solid 2px`,
171
205
  },
172
206
  missing: {
173
- backgroundColor: color.incorrectSecondary(),
174
- border: `${color.missing()} dashed 2px`,
175
- color: theme.palette.common.black,
176
- lineHeight: `${theme.spacing.unit * 3}px`,
177
- textDecoration: `line-through ${color.missing()}`,
207
+ border: `${color.incorrectWithIcon()} dashed 2px`,
178
208
  },
179
209
  incorrectIcon: {
180
- verticalAlign: 'middle',
181
- fontSize: 'larger',
182
- color: color.missing(),
210
+ backgroundColor: color.incorrectWithIcon(),
183
211
  },
184
212
  correctIcon: {
185
- verticalAlign: 'middle',
186
- fontSize: 'larger',
187
- color: color.correct(),
213
+ backgroundColor: color.correctTertiary(),
214
+ },
215
+ correctnessIndicatorIcon: {
216
+ color: color.white(),
217
+ position: 'absolute',
218
+ top: '-8px',
219
+ left: '-8px',
220
+ borderRadius: '50%',
221
+ fontSize: '12px',
222
+ padding: '2px',
188
223
  },
189
224
  };
190
225
  })(Token);
@@ -4,7 +4,7 @@ import Button from '@material-ui/core/Button';
4
4
  import { withStyles } from '@material-ui/core/styles';
5
5
  import Switch from '@material-ui/core/Switch';
6
6
  import FormControlLabel from '@material-ui/core/FormControlLabel';
7
- import { color } from '@pie-lib/render-ui';
7
+ import { color } from '../../../render-ui/src/index';
8
8
  import classNames from 'classnames';
9
9
 
10
10
  export class Controls extends React.Component {