@pie-lib/math-toolbar 3.0.3-next.38 → 3.0.3-next.83

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,499 @@
1
+ import React from 'react';
2
+ import debug from 'debug';
3
+ import PropTypes from 'prop-types';
4
+ import Button from '@mui/material/Button';
5
+ import { styled } from '@mui/material/styles';
6
+ import MenuItem from '@mui/material/MenuItem';
7
+ import Select from '@mui/material/Select';
8
+ import { isEqual } from 'lodash-es';
9
+ import FormControl from '@mui/material/FormControl';
10
+ import InputLabel from '@mui/material/InputLabel';
11
+
12
+ import { HorizontalKeypad, mq, updateSpans } from '@pie-lib/math-input';
13
+ import { color } from '@pie-lib/render-ui';
14
+ import { markFractionBaseSuperscripts } from './utils';
15
+
16
+ const { commonMqFontStyles, commonMqKeyboardStyles, longdivStyles, supsubStyles } = mq.CommonMqStyles;
17
+ const log = debug('@pie-lib:math-toolbar:editor-and-pad');
18
+
19
+ const decimalRegex = /\.|,/g;
20
+
21
+ const MathToolbarContainer = styled('div')(({ theme }) => ({
22
+ zIndex: 9,
23
+ position: 'relative',
24
+ textAlign: 'center',
25
+ width: 'auto',
26
+ '& > .mq-math-mode': {
27
+ border: 'solid 1px lightgrey',
28
+ },
29
+ '& > .mq-focused': {
30
+ outline: 'none',
31
+ boxShadow: 'none',
32
+ border: `dotted 1px ${theme.palette.primary.main}`,
33
+ borderRadius: '0px',
34
+ },
35
+ '& .mq-overarrow-inner': {
36
+ border: 'none !important',
37
+ paddingTop: '0 !important',
38
+ },
39
+ '& .mq-overarrow-inner-right': {
40
+ display: 'none !important',
41
+ },
42
+ '& .mq-overarrow-inner-left': {
43
+ display: 'none !important',
44
+ },
45
+ '& .mq-longdiv-inner': {
46
+ borderTop: '1px solid !important',
47
+ paddingTop: '1.5px !important',
48
+ },
49
+ '& .mq-overarrow.mq-arrow-both': {
50
+ top: '7.8px',
51
+ marginTop: '0px',
52
+ minWidth: '1.23em',
53
+ },
54
+ '& .mq-parallelogram': {
55
+ lineHeight: 0.85,
56
+ },
57
+ }));
58
+
59
+ const InputAndTypeContainer = styled('div')(({ theme, hide }) => ({
60
+ display: hide ? 'none' : 'flex',
61
+ alignItems: 'center',
62
+ '& .mq-editable-field .mq-cursor': {
63
+ top: '-4px',
64
+ },
65
+ '& .mq-math-mode .mq-selection, .mq-editable-field .mq-selection': {
66
+ paddingTop: '18px',
67
+ },
68
+ '& .mq-math-mode .mq-overarrow': {
69
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
70
+ },
71
+ '& .mq-math-mode .mq-overline .mq-overline-inner': {
72
+ paddingTop: '0.4em !important',
73
+ },
74
+ '& .mq-overarrow.mq-arrow-both': {
75
+ minWidth: '1.23em',
76
+ '& *': {
77
+ lineHeight: '1 !important',
78
+ },
79
+ '&:before': {
80
+ top: '-0.45em',
81
+ left: '-1px',
82
+ },
83
+ '&:after': {
84
+ position: 'absolute !important',
85
+ top: '0px !important',
86
+ right: '-2px',
87
+ },
88
+ '&.mq-empty:after': {
89
+ top: '-0.45em',
90
+ },
91
+ },
92
+ '& .mq-overarrow.mq-arrow-right': {
93
+ '&:before': {
94
+ top: '-0.4em',
95
+ right: '-1px',
96
+ },
97
+ },
98
+ '& *': {
99
+ ...commonMqFontStyles,
100
+ ...supsubStyles,
101
+ ...longdivStyles,
102
+ '& .mq-math-mode .mq-sqrt-prefix': {
103
+ verticalAlign: 'baseline !important',
104
+ top: '1px !important',
105
+ left: '-0.1em !important',
106
+ },
107
+ '& .mq-math-mode .mq-overarc ': {
108
+ paddingTop: '0.45em !important',
109
+ },
110
+ '& .mq-math-mode .mq-empty': {
111
+ padding: '9px 1px !important',
112
+ },
113
+ '& .mq-math-mode .mq-root-block': {
114
+ paddingTop: '10px',
115
+ },
116
+ '& .mq-scaled .mq-sqrt-prefix': {
117
+ top: '0 !important',
118
+ },
119
+ '& .mq-math-mode .mq-longdiv .mq-longdiv-inner': {
120
+ marginLeft: '4px !important',
121
+ paddingTop: '6px !important',
122
+ paddingLeft: '6px !important',
123
+ },
124
+ '& .mq-math-mode .mq-paren': {
125
+ verticalAlign: 'top !important',
126
+ padding: '1px 0.1em !important',
127
+ },
128
+ '& .mq-math-mode .mq-sqrt-stem': {
129
+ borderTop: '0.07em solid',
130
+ marginLeft: '-1.5px',
131
+ marginTop: '-2px !important',
132
+ paddingTop: '5px !important',
133
+ },
134
+ '& .mq-math-mode .mq-denominator': {
135
+ marginTop: '-5px !important',
136
+ padding: '0.5em 0.1em 0.1em !important',
137
+ },
138
+ '& .mq-math-mode .mq-numerator, .mq-math-mode .mq-over': {
139
+ padding: '0 0.1em !important',
140
+ paddingBottom: '0 !important',
141
+ marginBottom: '-2px',
142
+ },
143
+ },
144
+ '& span[data-prime="true"]': {
145
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
146
+ },
147
+ }));
148
+
149
+ const StyledFormControl = styled(FormControl)({
150
+ flex: 'initial',
151
+ width: '25%',
152
+ minWidth: '100px',
153
+ marginLeft: '15px',
154
+ marginTop: '5px',
155
+ marginBottom: '5px',
156
+ marginRight: '5px',
157
+ '& label': {
158
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
159
+ },
160
+ '& div': {
161
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
162
+ },
163
+ });
164
+
165
+ const StyledInputLabel = styled(InputLabel)(() => ({
166
+ backgroundColor: 'transparent',
167
+ }));
168
+
169
+ const InputContainerDiv = styled('div')(({ theme, error }) => ({
170
+ minWidth: '500px',
171
+ maxWidth: '900px',
172
+ minHeight: '30px',
173
+ width: '100%',
174
+ display: 'flex',
175
+ marginTop: theme.spacing(1),
176
+ marginBottom: theme.spacing(1),
177
+ ...(error && {
178
+ border: '2px solid red',
179
+ }),
180
+ '& .mq-sqrt-prefix .mq-scaled': {
181
+ verticalAlign: 'middle !important',
182
+ },
183
+ }));
184
+
185
+ const MathEditor = styled(mq.Input)(({ controlledKeypadMode }) => ({
186
+ maxWidth: controlledKeypadMode ? '400px' : '500px',
187
+ color: color.text(),
188
+ backgroundColor: color.background(),
189
+ padding: '2px',
190
+ }));
191
+
192
+ const AddAnswerBlockButton = styled(Button)({
193
+ position: 'absolute',
194
+ right: '12px',
195
+ border: '1px solid lightgrey',
196
+ color: color.text(),
197
+ });
198
+
199
+ const StyledHr = styled('hr')(({ theme }) => ({
200
+ padding: 0,
201
+ margin: 0,
202
+ height: '1px',
203
+ border: 'none',
204
+ borderBottom: `solid 1px ${theme.palette.primary.main}`,
205
+ }));
206
+
207
+ const KeyboardContainer = styled(HorizontalKeypad)(({ mode }) => ({
208
+ ...commonMqKeyboardStyles,
209
+ ...(mode === 'language' && {
210
+ '& *': {
211
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif !important',
212
+ },
213
+ }),
214
+ }));
215
+
216
+ const toNodeData = (data) => {
217
+ if (!data) {
218
+ return;
219
+ }
220
+
221
+ const { type, value } = data;
222
+
223
+ if (type === 'command' || type === 'cursor') {
224
+ return data;
225
+ } else if (type === 'answer') {
226
+ return { type: 'answer', ...data };
227
+ } else if (value === 'clear') {
228
+ return { type: 'clear' };
229
+ } else {
230
+ return { type: 'write', value };
231
+ }
232
+ };
233
+
234
+ export class EditorAndPad extends React.Component {
235
+ static propTypes = {
236
+ classNames: PropTypes.object,
237
+ keypadMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
238
+ autoFocus: PropTypes.bool,
239
+ allowAnswerBlock: PropTypes.bool,
240
+ showKeypad: PropTypes.bool,
241
+ controlledKeypad: PropTypes.bool,
242
+ controlledKeypadMode: PropTypes.bool,
243
+ error: PropTypes.string,
244
+ noDecimal: PropTypes.bool,
245
+ hideInput: PropTypes.bool,
246
+ noLatexHandling: PropTypes.bool,
247
+ layoutForKeyPad: PropTypes.object,
248
+ maxResponseAreas: PropTypes.number,
249
+ additionalKeys: PropTypes.array,
250
+ latex: PropTypes.string.isRequired,
251
+ onAnswerBlockAdd: PropTypes.func,
252
+ onFocus: PropTypes.func,
253
+ onBlur: PropTypes.func,
254
+ onChange: PropTypes.func.isRequired,
255
+ setKeypadInteraction: PropTypes.func,
256
+ };
257
+
258
+ constructor(props) {
259
+ super(props);
260
+
261
+ this.state = { equationEditor: 'item-authoring', addDisabled: false };
262
+ }
263
+
264
+ componentDidMount() {
265
+ if (this.input && this.props.autoFocus) {
266
+ // adding a timeout to wait for other stuff related to focus to be finished
267
+ setTimeout(() => this.input.focus(), 0);
268
+ }
269
+ }
270
+
271
+ onClick = (data) => {
272
+ const { noDecimal, noLatexHandling, onChange } = this.props;
273
+ const c = toNodeData(data);
274
+ log('mathChange: ', c);
275
+
276
+ if (noLatexHandling) {
277
+ onChange(c.value);
278
+ return;
279
+ }
280
+
281
+ // if decimals are not allowed for this response, we discard the input
282
+ if (noDecimal && (c.value === '.' || c.value === ',')) {
283
+ return;
284
+ }
285
+
286
+ if (!c) {
287
+ return;
288
+ }
289
+
290
+ if (c.type === 'clear') {
291
+ log('call clear...');
292
+ this.input.clear();
293
+ } else if (c.type === 'command') {
294
+ this.input.command(c.value);
295
+ } else if (c.type === 'cursor') {
296
+ this.input.keystroke(c.value);
297
+ } else if (c.type === 'answer') {
298
+ this.input.write('%response%');
299
+ } else {
300
+ this.input.write(c.value);
301
+ }
302
+ };
303
+
304
+ updateDisable = (isEdit) => {
305
+ const { maxResponseAreas } = this.props;
306
+
307
+ if (maxResponseAreas) {
308
+ const shouldDisable = this.checkResponseAreasNumber(maxResponseAreas, isEdit);
309
+
310
+ this.setState({ addDisabled: shouldDisable });
311
+ }
312
+ };
313
+
314
+ onAnswerBlockClick = () => {
315
+ this.props.onAnswerBlockAdd();
316
+ this.onClick({
317
+ type: 'answer',
318
+ });
319
+
320
+ this.updateDisable(true);
321
+ };
322
+
323
+ onEditorChange = (latex) => {
324
+ const { onChange, noDecimal } = this.props;
325
+
326
+ updateSpans();
327
+ markFractionBaseSuperscripts();
328
+
329
+ this.updateDisable(true);
330
+
331
+ // if no decimals are allowed and the last change is a decimal dot, discard the change
332
+ if (noDecimal && (latex.indexOf('.') !== -1 || latex.indexOf(',') !== -1) && this.input) {
333
+ this.input.clear();
334
+ this.input.write(latex.replace(decimalRegex, ''));
335
+ return;
336
+ }
337
+
338
+ // eslint-disable-next-line no-useless-escape
339
+ const regexMatch = latex.match(/[0-9]\\ \\frac\{[^\{]*\}\{ \}/);
340
+
341
+ if (this.input && regexMatch && regexMatch?.length) {
342
+ try {
343
+ this.input.mathField.__controller.cursor.insLeftOf(this.input.mathField.__controller.cursor.parent[-1].parent);
344
+ this.input.mathField.el().dispatchEvent(new KeyboardEvent('keydown', { keyCode: 8 }));
345
+ } catch (e) {
346
+ // eslint-disable-next-line no-console
347
+ console.error(e.toString());
348
+ }
349
+
350
+ return;
351
+ }
352
+
353
+ onChange(latex);
354
+ };
355
+
356
+ /** Only render if the mathquill instance's latex is different
357
+ * or the keypad state changed from one state to the other (shown / hidden) */
358
+ shouldComponentUpdate(nextProps, nextState) {
359
+ const inputIsDifferent = this.input.mathField.latex() !== nextProps.latex;
360
+ log('[shouldComponentUpdate] ', 'inputIsDifferent: ', inputIsDifferent);
361
+
362
+ if (!isEqual(this.props.error, nextProps.error)) {
363
+ return true;
364
+ }
365
+
366
+ if (!inputIsDifferent && this.props.keypadMode !== nextProps.keypadMode) {
367
+ return true;
368
+ }
369
+
370
+ if (!inputIsDifferent && this.props.noDecimal !== nextProps.noDecimal) {
371
+ return true;
372
+ }
373
+
374
+ if (!inputIsDifferent && this.state.equationEditor !== nextState.equationEditor) {
375
+ return true;
376
+ }
377
+
378
+ if (!inputIsDifferent && this.props.controlledKeypad) {
379
+ return this.props.showKeypad !== nextProps.showKeypad;
380
+ }
381
+
382
+ return inputIsDifferent;
383
+ }
384
+
385
+ onEditorTypeChange = (evt) => {
386
+ this.setState({ equationEditor: evt.target.value });
387
+ };
388
+
389
+ checkResponseAreasNumber = (maxResponseAreas, isEdit) => {
390
+ const { latex } = (this.input && this.input.props) || {};
391
+
392
+ if (latex) {
393
+ const count = (latex.match(/answerBlock/g) || []).length;
394
+
395
+ return isEdit ? count === maxResponseAreas - 1 : count === maxResponseAreas;
396
+ }
397
+
398
+ return false;
399
+ };
400
+
401
+ render() {
402
+ const {
403
+ classNames,
404
+ keypadMode,
405
+ allowAnswerBlock,
406
+ additionalKeys,
407
+ controlledKeypad,
408
+ controlledKeypadMode,
409
+ showKeypad,
410
+ setKeypadInteraction,
411
+ noDecimal,
412
+ hideInput,
413
+ layoutForKeyPad,
414
+ latex,
415
+ onFocus,
416
+ onBlur,
417
+ error,
418
+ } = this.props;
419
+ const shouldShowKeypad = !controlledKeypad || (controlledKeypad && showKeypad);
420
+ const { addDisabled } = this.state;
421
+
422
+ log('[render]', latex);
423
+
424
+ return (
425
+ <MathToolbarContainer className={classNames.mathToolbar}>
426
+ <InputAndTypeContainer hide={hideInput}>
427
+ {controlledKeypadMode && (
428
+ <StyledFormControl variant={'standard'}>
429
+ <StyledInputLabel id="equation-editor-label">{'Equation Editor'}</StyledInputLabel>
430
+ <Select
431
+ labelId="equation-editor-label"
432
+ id="equation-editor-select"
433
+ name="equationEditor"
434
+ label={'Equation Editor'}
435
+ onChange={this.onEditorTypeChange}
436
+ value={this.state.equationEditor}
437
+ MenuProps={{ transitionDuration: { enter: 225, exit: 195 } }}
438
+ >
439
+ <MenuItem value="non-negative-integers">Numeric - Non-Negative Integers</MenuItem>
440
+ <MenuItem value="integers">Numeric - Integers</MenuItem>
441
+ <MenuItem value="decimals">Numeric - Decimals</MenuItem>
442
+ <MenuItem value="fractions">Numeric - Fractions</MenuItem>
443
+ <MenuItem value={1}>Grade 1 - 2</MenuItem>
444
+ <MenuItem value={3}>Grade 3 - 5</MenuItem>
445
+ <MenuItem value={6}>Grade 6 - 7</MenuItem>
446
+ <MenuItem value={8}>Grade 8 - HS</MenuItem>
447
+ <MenuItem value={'geometry'}>Geometry</MenuItem>
448
+ <MenuItem value={'advanced-algebra'}>Advanced Algebra</MenuItem>
449
+ <MenuItem value={'statistics'}>Statistics</MenuItem>
450
+ <MenuItem value={'item-authoring'}>Item Authoring</MenuItem>
451
+ </Select>
452
+ </StyledFormControl>
453
+ )}
454
+ <InputContainerDiv error={error}>
455
+ <MathEditor
456
+ onFocus={() => {
457
+ onFocus && onFocus();
458
+ this.updateDisable(false);
459
+ }}
460
+ onBlur={(event) => {
461
+ this.updateDisable(false);
462
+ onBlur && onBlur(event);
463
+ }}
464
+ className={(classNames && classNames.editor) || ''}
465
+ controlledKeypadMode={controlledKeypadMode}
466
+ ref={(r) => (this.input = r)}
467
+ latex={latex}
468
+ onChange={this.onEditorChange}
469
+ />
470
+ </InputContainerDiv>
471
+ </InputAndTypeContainer>
472
+ {allowAnswerBlock && (
473
+ <AddAnswerBlockButton
474
+ type="primary"
475
+ style={{ bottom: shouldShowKeypad ? '320px' : '20px' }}
476
+ onClick={this.onAnswerBlockClick}
477
+ disabled={addDisabled}
478
+ >
479
+ + Response Area
480
+ </AddAnswerBlockButton>
481
+ )}
482
+ <StyledHr />
483
+ {shouldShowKeypad && (
484
+ <KeyboardContainer
485
+ mode={controlledKeypadMode ? this.state.equationEditor : keypadMode}
486
+ controlledKeypadMode={controlledKeypadMode}
487
+ layoutForKeyPad={layoutForKeyPad}
488
+ additionalKeys={additionalKeys}
489
+ onClick={this.onClick}
490
+ noDecimal={noDecimal}
491
+ setKeypadInteraction={setKeypadInteraction}
492
+ />
493
+ )}
494
+ </MathToolbarContainer>
495
+ );
496
+ }
497
+ }
498
+
499
+ export default EditorAndPad;
package/src/index.jsx ADDED
@@ -0,0 +1,220 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import EditorAndPad from './editor-and-pad';
4
+ import { DoneButton } from './done-button';
5
+ import { styled } from '@mui/material/styles';
6
+ import MathPreview from './math-preview';
7
+
8
+ export { MathPreview };
9
+
10
+ const PureToolbarContainer = styled('div')({
11
+ display: 'flex',
12
+ width: '100%',
13
+ zIndex: 8,
14
+ alignItems: 'center',
15
+ });
16
+
17
+ export class MathToolbar extends React.Component {
18
+ static propTypes = {
19
+ autoFocus: PropTypes.bool,
20
+ allowAnswerBlock: PropTypes.bool,
21
+ controlledKeypad: PropTypes.bool,
22
+ controlledKeypadMode: PropTypes.bool,
23
+ keypadMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
24
+ classNames: PropTypes.object,
25
+ error: PropTypes.string,
26
+ maxResponseAreas: PropTypes.number,
27
+ showKeypad: PropTypes.bool,
28
+ noDecimal: PropTypes.bool,
29
+ additionalKeys: PropTypes.array,
30
+ latex: PropTypes.string.isRequired,
31
+ onAnswerBlockAdd: PropTypes.func,
32
+ onChange: PropTypes.func,
33
+ onDone: PropTypes.func.isRequired,
34
+ onFocus: PropTypes.func,
35
+ onBlur: PropTypes.func,
36
+ hideDoneButton: PropTypes.bool,
37
+ keyPadCharacterRef: PropTypes.func,
38
+ setKeypadInteraction: PropTypes.func,
39
+ };
40
+
41
+ static defaultProps = {
42
+ classNames: {},
43
+ keypadMode: 'item-authoring',
44
+ autoFocus: false,
45
+ allowAnswerBlock: false,
46
+ controlledKeypad: false,
47
+ controlledKeypadMode: false,
48
+ noDecimal: false,
49
+ showKeypad: true,
50
+ additionalKeys: [],
51
+ onChange: () => {},
52
+ onAnswerBlockAdd: () => {},
53
+ onFocus: () => {},
54
+ hideDoneButton: false,
55
+ };
56
+
57
+ constructor(props) {
58
+ super(props);
59
+ this.state = {
60
+ latex: props.latex,
61
+ };
62
+ }
63
+
64
+ done = () => {
65
+ this.props.onDone(this.state.latex);
66
+ };
67
+
68
+ UNSAFE_componentWillReceiveProps(nextProps) {
69
+ this.setState({ latex: nextProps.latex });
70
+ }
71
+
72
+ onChange = (latex) => {
73
+ this.setState({ latex });
74
+ this.props.onChange(latex);
75
+ };
76
+
77
+ render() {
78
+ const { latex } = this.state;
79
+ const {
80
+ classNames,
81
+ autoFocus,
82
+ allowAnswerBlock,
83
+ onAnswerBlockAdd,
84
+ controlledKeypad,
85
+ controlledKeypadMode,
86
+ keypadMode,
87
+ noDecimal,
88
+ additionalKeys,
89
+ showKeypad,
90
+ onFocus,
91
+ onBlur,
92
+ hideDoneButton,
93
+ error,
94
+ keyPadCharacterRef,
95
+ setKeypadInteraction,
96
+ maxResponseAreas,
97
+ } = this.props;
98
+
99
+ return (
100
+ <PureToolbar
101
+ autoFocus={autoFocus}
102
+ classNames={classNames}
103
+ onAnswerBlockAdd={onAnswerBlockAdd}
104
+ allowAnswerBlock={allowAnswerBlock}
105
+ latex={latex}
106
+ additionalKeys={additionalKeys}
107
+ noDecimal={noDecimal}
108
+ keypadMode={keypadMode}
109
+ keyPadCharacterRef={keyPadCharacterRef}
110
+ setKeypadInteraction={setKeypadInteraction}
111
+ onChange={this.onChange}
112
+ onDone={this.done}
113
+ onFocus={onFocus}
114
+ onBlur={onBlur}
115
+ showKeypad={showKeypad}
116
+ controlledKeypad={controlledKeypad}
117
+ controlledKeypadMode={controlledKeypadMode}
118
+ hideDoneButton={hideDoneButton}
119
+ error={error}
120
+ maxResponseAreas={maxResponseAreas}
121
+ />
122
+ );
123
+ }
124
+ }
125
+
126
+ export class RawPureToolbar extends React.Component {
127
+ static propTypes = {
128
+ classNames: PropTypes.object,
129
+ latex: PropTypes.string.isRequired,
130
+ keypadMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
131
+ hideInput: PropTypes.bool,
132
+ noLatexHandling: PropTypes.bool,
133
+ layoutForKeyPad: PropTypes.object,
134
+ onChange: PropTypes.func.isRequired,
135
+ onDone: PropTypes.func.isRequired,
136
+ onBlur: PropTypes.func,
137
+ onAnswerBlockAdd: PropTypes.func,
138
+ additionalKeys: PropTypes.array,
139
+ onFocus: PropTypes.func,
140
+ autoFocus: PropTypes.bool,
141
+ noDecimal: PropTypes.bool,
142
+ allowAnswerBlock: PropTypes.bool,
143
+ controlledKeypad: PropTypes.bool,
144
+ controlledKeypadMode: PropTypes.bool,
145
+ showKeypad: PropTypes.bool,
146
+ hideDoneButton: PropTypes.bool,
147
+ hideDoneButtonBackground: PropTypes.bool,
148
+ error: PropTypes.any,
149
+ maxResponseAreas: PropTypes.number,
150
+ keyPadCharacterRef: PropTypes.object,
151
+ setKeypadInteraction: PropTypes.func,
152
+ };
153
+
154
+ static defaultProps = {
155
+ classNames: {},
156
+ hideDoneButtonBackground: false,
157
+ };
158
+
159
+ render() {
160
+ const {
161
+ classNames,
162
+ autoFocus,
163
+ allowAnswerBlock,
164
+ onAnswerBlockAdd,
165
+ controlledKeypad,
166
+ controlledKeypadMode,
167
+ additionalKeys,
168
+ showKeypad,
169
+ keypadMode,
170
+ noDecimal,
171
+ hideInput,
172
+ noLatexHandling,
173
+ layoutForKeyPad,
174
+ keyPadCharacterRef,
175
+ setKeypadInteraction,
176
+ latex,
177
+ onChange,
178
+ onDone,
179
+ onFocus,
180
+ onBlur,
181
+ hideDoneButton,
182
+ hideDoneButtonBackground,
183
+ error,
184
+ maxResponseAreas,
185
+ } = this.props;
186
+
187
+ return (
188
+ <PureToolbarContainer className={(classNames && classNames.toolbar) || ''} ref={keyPadCharacterRef}>
189
+ <div />
190
+ <EditorAndPad
191
+ autoFocus={autoFocus}
192
+ keypadMode={keypadMode}
193
+ classNames={classNames || {}}
194
+ controlledKeypad={controlledKeypad}
195
+ controlledKeypadMode={controlledKeypadMode}
196
+ noDecimal={noDecimal}
197
+ hideInput={hideInput}
198
+ noLatexHandling={noLatexHandling}
199
+ layoutForKeyPad={layoutForKeyPad}
200
+ showKeypad={showKeypad}
201
+ additionalKeys={additionalKeys}
202
+ allowAnswerBlock={allowAnswerBlock}
203
+ onAnswerBlockAdd={onAnswerBlockAdd}
204
+ latex={latex}
205
+ onChange={onChange}
206
+ onFocus={onFocus}
207
+ onBlur={onBlur}
208
+ error={error}
209
+ maxResponseAreas={maxResponseAreas}
210
+ setKeypadInteraction={setKeypadInteraction}
211
+ />
212
+ {(!controlledKeypad || (controlledKeypad && showKeypad)) && !hideDoneButton && (
213
+ <DoneButton hideBackground={hideDoneButtonBackground} onClick={onDone} />
214
+ )}
215
+ </PureToolbarContainer>
216
+ );
217
+ }
218
+ }
219
+
220
+ export const PureToolbar = RawPureToolbar;