@pie-lib/render-ui 4.35.3-next.0 → 4.35.3-next.155

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +9 -81
  2. package/esm/package.json +3 -0
  3. package/lib/append-css-rules.js +10 -37
  4. package/lib/append-css-rules.js.map +1 -1
  5. package/lib/assets/enableAudioAutoplayImage.js +1 -2
  6. package/lib/assets/enableAudioAutoplayImage.js.map +1 -1
  7. package/lib/collapsible/index.js +35 -65
  8. package/lib/collapsible/index.js.map +1 -1
  9. package/lib/color.js +57 -201
  10. package/lib/color.js.map +1 -1
  11. package/lib/feedback.js +71 -108
  12. package/lib/feedback.js.map +1 -1
  13. package/lib/has-media.js +2 -7
  14. package/lib/has-media.js.map +1 -1
  15. package/lib/has-text.js +1 -7
  16. package/lib/has-text.js.map +1 -1
  17. package/lib/html-and-math.js +10 -30
  18. package/lib/html-and-math.js.map +1 -1
  19. package/lib/index.js +1 -24
  20. package/lib/index.js.map +1 -1
  21. package/lib/input-container.js +43 -44
  22. package/lib/input-container.js.map +1 -1
  23. package/lib/preview-layout.js +22 -58
  24. package/lib/preview-layout.js.map +1 -1
  25. package/lib/preview-prompt.js +104 -131
  26. package/lib/preview-prompt.js.map +1 -1
  27. package/lib/purpose.js +1 -7
  28. package/lib/purpose.js.map +1 -1
  29. package/lib/readable.js +1 -7
  30. package/lib/readable.js.map +1 -1
  31. package/lib/response-indicators.js +37 -86
  32. package/lib/response-indicators.js.map +1 -1
  33. package/lib/ui-layout.js +53 -70
  34. package/lib/ui-layout.js.map +1 -1
  35. package/lib/withUndoReset.js +51 -97
  36. package/lib/withUndoReset.js.map +1 -1
  37. package/package.json +23 -13
  38. package/src/__tests__/html-and-math.test.js +26 -14
  39. package/src/__tests__/preview-prompt.test.jsx +43 -40
  40. package/src/__tests__/purpose.test.jsx +27 -23
  41. package/src/__tests__/readable.test.jsx +34 -29
  42. package/src/__tests__/response-indicators.test.jsx +104 -9
  43. package/src/__tests__/ui-layout.test.jsx +28 -12
  44. package/src/__tests__/withUndoReset.test.jsx +110 -188
  45. package/src/collapsible/__tests__/index.test.jsx +33 -7
  46. package/src/collapsible/index.jsx +17 -17
  47. package/src/color.js +1 -5
  48. package/src/feedback.jsx +59 -63
  49. package/src/input-container.jsx +41 -32
  50. package/src/preview-layout.jsx +11 -23
  51. package/src/preview-prompt.jsx +76 -58
  52. package/src/response-indicators.jsx +22 -29
  53. package/src/ui-layout.jsx +41 -28
  54. package/src/withUndoReset.jsx +48 -50
  55. package/src/__tests__/__snapshots__/html-and-math.test.js.snap +0 -11
  56. package/src/__tests__/__snapshots__/preview-prompt.test.jsx.snap +0 -37
  57. package/src/__tests__/__snapshots__/purpose.test.jsx.snap +0 -42
  58. package/src/__tests__/__snapshots__/readable.test.jsx.snap +0 -64
  59. package/src/__tests__/__snapshots__/response-indicators.test.jsx.snap +0 -27
  60. package/src/collapsible/__tests__/__snapshots__/index.test.jsx.snap +0 -18
@@ -1,31 +1,28 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import * as icons from '@pie-lib/icons';
4
- import Popover from '@material-ui/core/Popover';
5
- import { withStyles } from '@material-ui/core/styles';
4
+ import Popover from '@mui/material/Popover';
5
+ import { styled } from '@mui/material/styles';
6
6
  import Feedback from './feedback';
7
7
  import debug from 'debug';
8
8
 
9
9
  const log = debug('pie-libs:render-ui:response-indicators');
10
10
 
11
- const styles = () => ({
12
- responseIndicator: {
13
- cursor: 'pointer',
14
- },
15
- paper: {
16
- padding: '0',
17
- borderRadius: '4px',
18
- },
19
- popover: {
20
- cursor: 'pointer',
21
- },
22
- popperClose: {
23
- cursor: 'pointer',
24
- },
11
+ const ResponseIndicatorContainer = styled('div')(({ hasFeedback }) => ({
12
+ cursor: hasFeedback ? 'pointer' : 'default',
13
+ }));
14
+
15
+ const StyledPopover = styled(Popover)({
16
+ cursor: 'pointer',
17
+ });
18
+
19
+ const PopoverPaper = styled('div')({
20
+ padding: '0',
21
+ borderRadius: '4px',
25
22
  });
26
23
 
27
24
  const BuildIndicator = (Icon, correctness) => {
28
- class RawIndicator extends React.Component {
25
+ class Indicator extends React.Component {
29
26
  constructor(props) {
30
27
  super(props);
31
28
  this.state = {};
@@ -41,20 +38,17 @@ const BuildIndicator = (Icon, correctness) => {
41
38
  };
42
39
 
43
40
  render() {
44
- const { feedback, classes } = this.props;
41
+ const { feedback } = this.props;
45
42
  const { anchorEl } = this.state;
46
43
  return (
47
- <div className={feedback && classes.responseIndicator}>
44
+ <ResponseIndicatorContainer hasFeedback={!!feedback}>
48
45
  <span ref={(r) => (this.icon = r)} onClick={this.handlePopoverOpen}>
49
46
  <Icon />
50
47
  </span>
51
48
 
52
49
  {feedback && (
53
- <Popover
54
- className={classes.popover}
55
- classes={{
56
- paper: classes.paper,
57
- }}
50
+ <StyledPopover
51
+ PaperComponent={PopoverPaper}
58
52
  open={!!anchorEl}
59
53
  anchorEl={anchorEl}
60
54
  anchorOrigin={{
@@ -68,19 +62,18 @@ const BuildIndicator = (Icon, correctness) => {
68
62
  onClose={this.handlePopoverClose}
69
63
  >
70
64
  <Feedback feedback={feedback} correctness={correctness} />
71
- </Popover>
65
+ </StyledPopover>
72
66
  )}
73
- </div>
67
+ </ResponseIndicatorContainer>
74
68
  );
75
69
  }
76
70
  }
77
71
 
78
- RawIndicator.propTypes = {
72
+ Indicator.propTypes = {
79
73
  feedback: PropTypes.string,
80
- classes: PropTypes.object.isRequired,
81
74
  };
82
75
 
83
- return withStyles(styles)(RawIndicator);
76
+ return Indicator;
84
77
  };
85
78
 
86
79
  export const Correct = BuildIndicator(icons.Correct, 'correct');
package/src/ui-layout.jsx CHANGED
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
- import { createMuiTheme, MuiThemeProvider, withStyles } from '@material-ui/core/styles';
2
+ import { createTheme, ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
3
+ import { styled } from '@mui/material/styles';
3
4
  import PropTypes from 'prop-types';
4
- import classNames from 'classnames';
5
5
  import AppendCSSRules from './append-css-rules';
6
6
 
7
- const theme = createMuiTheme({
7
+ const theme = createTheme({
8
8
  typography: {
9
- useNextVariants: true,
10
9
  fontFamily: 'inherit',
11
10
  },
12
11
  palette: {
@@ -14,27 +13,50 @@ const theme = createMuiTheme({
14
13
  disabled: 'rgba(0, 0, 0, 0.54);',
15
14
  },
16
15
  },
17
- overrides: {
16
+ components: {
18
17
  MuiTypography: {
19
- root: { fontFamily: 'inherit' },
18
+ styleOverrides: {
19
+ root: { fontFamily: 'inherit' },
20
+ },
20
21
  },
22
+ MuiButton: {
23
+ styleOverrides: {
24
+ contained: {
25
+ backgroundColor: '#e0e0e0',
26
+ color: '#000000',
27
+ '&:hover': {
28
+ backgroundColor: '#bdbdbd',
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ });
35
+
36
+ const StyledContainer = styled('div')({
37
+ // need this because some browsers set their own style on table
38
+ '& table, th, td': {
39
+ fontSize: 'inherit' /* Ensure table elements inherit font size */,
21
40
  },
22
41
  });
23
42
 
24
43
  class UiLayout extends AppendCSSRules {
25
44
  static propTypes = {
26
- classes: PropTypes.object,
27
45
  className: PropTypes.string,
28
46
  children: PropTypes.array,
29
47
  extraCSSRules: PropTypes.shape({
30
48
  names: PropTypes.arrayOf(PropTypes.string),
31
49
  rules: PropTypes.string,
32
50
  }),
51
+ classes: PropTypes.shape({
52
+ extraCSSRules: PropTypes.string,
53
+ }),
33
54
  fontSizeFactor: PropTypes.number,
34
55
  };
35
56
 
36
57
  static defaultProps = {
37
58
  extraCSSRules: {},
59
+ classes: {},
38
60
  fontSizeFactor: 1,
39
61
  };
40
62
 
@@ -50,36 +72,27 @@ class UiLayout extends AppendCSSRules {
50
72
  const bodyFontSize = getFontSize(document.body);
51
73
  const effectiveFontSize = Math.max(rootFontSize, bodyFontSize);
52
74
 
53
- return fontSizeFactor !== 1 ? { fontSize: `${effectiveFontSize * fontSizeFactor}px` } : null;
75
+ // Handle null, undefined, or invalid values by defaulting to 1
76
+ const factor = fontSizeFactor != null && typeof fontSizeFactor === 'number' ? fontSizeFactor : 1;
77
+ return factor !== 1 ? { fontSize: `${effectiveFontSize * factor}px` } : null;
54
78
  }
55
79
 
56
80
  render() {
57
- const { children, className, classes, fontSizeFactor, ...rest } = this.props;
81
+ const { children, className, fontSizeFactor, ...rest } = this.props;
58
82
 
59
- const finalClass = classNames(className, classes.extraCSSRules, classes.uiLayoutContainer);
60
83
  const { extraCSSRules, ...restProps } = rest;
61
84
  const style = this.computeStyle(fontSizeFactor);
62
85
 
63
86
  return (
64
- <MuiThemeProvider theme={theme}>
65
- <div className={finalClass} {...restProps} {...(style && { style })}>
66
- {children}
67
- </div>
68
- </MuiThemeProvider>
87
+ <StyledEngineProvider injectFirst>
88
+ <ThemeProvider theme={theme}>
89
+ <StyledContainer className={className} {...restProps} {...(style && { style })}>
90
+ {children}
91
+ </StyledContainer>
92
+ </ThemeProvider>
93
+ </StyledEngineProvider>
69
94
  );
70
95
  }
71
96
  }
72
97
 
73
- const styles = {
74
- extraCSSRules: {},
75
- // need this because some browsers set their own style on table
76
- uiLayoutContainer: {
77
- '& table, th, td': {
78
- fontSize: 'inherit' /* Ensure table elements inherit font size */,
79
- },
80
- },
81
- };
82
-
83
- const Styled = withStyles(styles)(UiLayout);
84
-
85
- export default Styled;
98
+ export default UiLayout;
@@ -1,41 +1,43 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import Button from '@material-ui/core/Button';
4
- import { withStyles } from '@material-ui/core/styles';
5
- import Restore from '@material-ui/icons/Restore';
6
- import Undo from '@material-ui/icons/Undo';
7
-
8
- const styles = (theme) => ({
9
- wrapper: {
10
- display: 'flex',
11
- flexDirection: 'column',
12
- },
13
- resetUndoContainer: {
14
- display: 'flex',
15
- alignItems: 'center',
16
- justifyContent: 'center',
17
- },
18
- icon: {
19
- width: '24px',
20
- height: '24px',
21
- color: 'gray',
22
- marginRight: theme.spacing.unit,
23
- },
24
- buttonContainer: {
25
- display: 'flex',
26
- alignItems: 'center',
27
- marginLeft: theme.spacing.unit * 3,
28
- marginRight: theme.spacing.unit * 3,
29
- },
3
+ import Button from '@mui/material/Button';
4
+ import { styled } from '@mui/material/styles';
5
+ import Restore from '@mui/icons-material/Restore';
6
+ import Undo from '@mui/icons-material/Undo';
7
+
8
+ const Wrapper = styled('div')({
9
+ display: 'flex',
10
+ flexDirection: 'column',
11
+ });
12
+
13
+ const ResetUndoContainer = styled('div')({
14
+ display: 'flex',
15
+ alignItems: 'center',
16
+ justifyContent: 'center',
30
17
  });
31
18
 
19
+ const StyledIcon = styled('div')(({ theme }) => ({
20
+ width: '24px',
21
+ height: '24px',
22
+ color: 'gray',
23
+ marginRight: theme.spacing(1),
24
+ display: 'flex',
25
+ alignItems: 'center',
26
+ }));
27
+
28
+ const StyledButton = styled(Button)(({ theme }) => ({
29
+ display: 'flex',
30
+ alignItems: 'center',
31
+ marginLeft: theme.spacing(3),
32
+ marginRight: theme.spacing(3),
33
+ }));
34
+
32
35
  /**
33
36
  * HOC that adds undo and reset functionality for session values
34
37
  */
35
38
  const withUndoReset = (WrappedComponent) => {
36
39
  class WithUndoReset extends React.Component {
37
40
  static propTypes = {
38
- classes: PropTypes.object,
39
41
  session: PropTypes.object,
40
42
  onSessionChange: PropTypes.func,
41
43
  };
@@ -81,36 +83,32 @@ const withUndoReset = (WrappedComponent) => {
81
83
  };
82
84
 
83
85
  render() {
84
- const { classes, ...rest } = this.props;
86
+ const { ...rest } = this.props;
85
87
  const { changes, session } = this.state;
86
88
 
87
89
  return (
88
- <div className={classes.wrapper}>
89
- <div className={classes.resetUndoContainer}>
90
- <Button
91
- className={classes.buttonContainer}
92
- color="primary"
93
- disabled={changes.length === 0}
94
- onClick={this.onUndo}
95
- >
96
- <Undo className={classes.icon} /> Undo
97
- </Button>
98
- <Button
99
- className={classes.buttonContainer}
100
- color="primary"
101
- disabled={changes.length === 0}
102
- onClick={this.onReset}
103
- >
104
- <Restore className={classes.icon} /> Start Over
105
- </Button>
106
- </div>
90
+ <Wrapper>
91
+ <ResetUndoContainer>
92
+ <StyledButton color="primary" disabled={changes.length === 0} onClick={this.onUndo}>
93
+ <StyledIcon>
94
+ <Undo />
95
+ </StyledIcon>
96
+ Undo
97
+ </StyledButton>
98
+ <StyledButton color="primary" disabled={changes.length === 0} onClick={this.onReset}>
99
+ <StyledIcon>
100
+ <Restore />
101
+ </StyledIcon>
102
+ Start Over
103
+ </StyledButton>
104
+ </ResetUndoContainer>
107
105
  <WrappedComponent {...rest} session={session} onSessionChange={this.onSessionChange} />
108
- </div>
106
+ </Wrapper>
109
107
  );
110
108
  }
111
109
  }
112
110
 
113
- return withStyles(styles)(WithUndoReset);
111
+ return WithUndoReset;
114
112
  };
115
113
 
116
114
  export default withUndoReset;
@@ -1,11 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`html-and-math render renders 1`] = `
4
- <div
5
- dangerouslySetInnerHTML={
6
- Object {
7
- "__html": "<p>hi</p>",
8
- }
9
- }
10
- />
11
- `;
@@ -1,37 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Prompt with Custom tag renders with custom tag "span" correctly renders 1`] = `
4
- <PreviewPrompt
5
- className="prompt"
6
- classes={
7
- Object {
8
- "label": "PreviewPrompt-label-4",
9
- "legend": "PreviewPrompt-legend-2",
10
- "prompt": "PreviewPrompt-prompt-1",
11
- "promptTable": "PreviewPrompt-promptTable-5",
12
- "rationale": "PreviewPrompt-rationale-3",
13
- }
14
- }
15
- onClick={[Function]}
16
- prompt="Which of these northern European countries are EU members? <math><mstack><msrow><mn>111</mn></msrow><msline/></mstack></math>"
17
- tagName="span"
18
- />
19
- `;
20
-
21
- exports[`Prompt without Custom tag default class with markup renders 1`] = `
22
- <PreviewPrompt
23
- className=""
24
- classes={
25
- Object {
26
- "label": "PreviewPrompt-label-4",
27
- "legend": "PreviewPrompt-legend-2",
28
- "prompt": "PreviewPrompt-prompt-1",
29
- "promptTable": "PreviewPrompt-promptTable-5",
30
- "rationale": "PreviewPrompt-rationale-3",
31
- }
32
- }
33
- onClick={[Function]}
34
- prompt="Which of these northern European countries are EU members? <math><mstack><msrow><mn>111</mn></msrow><msline/></mstack></math>"
35
- tagName=""
36
- />
37
- `;
@@ -1,42 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Purpose renders fine renders child unaltered 1`] = `
4
- <Purpose
5
- purpose="passage"
6
- >
7
- <div
8
- data-pie-purpose="passage"
9
- key=".0"
10
- >
11
- text
12
- </div>
13
- </Purpose>
14
- `;
15
-
16
- exports[`Purpose renders fine renders child unaltered without purpose prop 1`] = `
17
- <Purpose>
18
- <div
19
- key=".0"
20
- >
21
- text
22
- </div>
23
- </Purpose>
24
- `;
25
-
26
- exports[`Purpose renders fine renders children unaltered 1`] = `
27
- <Purpose
28
- purpose="something"
29
- >
30
- <div
31
- data-pie-purpose="something"
32
- key=".0"
33
- >
34
- <div>
35
- text1
36
- </div>
37
- <div>
38
- text2
39
- </div>
40
- </div>
41
- </Purpose>
42
- `;
@@ -1,64 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Readable renders fine renders child unaltered 1`] = `
4
- <Readable>
5
- <div
6
- data-pie-readable={true}
7
- key=".0"
8
- >
9
- text
10
- </div>
11
- </Readable>
12
- `;
13
-
14
- exports[`Readable renders fine renders children unaltered 1`] = `
15
- <Readable>
16
- <div
17
- data-pie-readable={true}
18
- key=".0"
19
- >
20
- <div>
21
- text1
22
- </div>
23
- <div>
24
- text2
25
- </div>
26
- </div>
27
- </Readable>
28
- `;
29
-
30
- exports[`Readable renders fine renders even with specific true tag 1`] = `
31
- <Readable
32
- false={true}
33
- >
34
- <div
35
- data-pie-readable={false}
36
- key=".0"
37
- >
38
- <div>
39
- text1
40
- </div>
41
- <div>
42
- text2
43
- </div>
44
- </div>
45
- </Readable>
46
- `;
47
-
48
- exports[`Readable renders fine renders with false tag 1`] = `
49
- <Readable
50
- false={true}
51
- >
52
- <div
53
- data-pie-readable={false}
54
- key=".0"
55
- >
56
- <div>
57
- text1
58
- </div>
59
- <div>
60
- text2
61
- </div>
62
- </div>
63
- </Readable>
64
- `;
@@ -1,27 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`response-indicators snapshot - no feedback 1`] = `
4
- <div>
5
- <span
6
- onClick={[Function]}
7
- >
8
- <div>
9
- correct
10
- </div>
11
- </span>
12
- </div>
13
- `;
14
-
15
- exports[`response-indicators snapshot - with feedback 1`] = `
16
- <div
17
- className="RawIndicator-responseIndicator-1"
18
- >
19
- <span
20
- onClick={[Function]}
21
- >
22
- <div>
23
- correct
24
- </div>
25
- </span>
26
- </div>
27
- `;
@@ -1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`collapsible snapshot renders 1`] = `
4
- <div>
5
- <div
6
- onClick={[Function]}
7
- >
8
- <span>
9
- Show
10
- </span>
11
- </div>
12
- <WithStyles(Collapse)
13
- in={false}
14
- timeout="auto"
15
- unmountOnExit={true}
16
- />
17
- </div>
18
- `;