@pie-lib/render-ui 4.35.1 → 4.36.0-mui-update.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -9
  2. package/lib/append-css-rules.js +10 -37
  3. package/lib/append-css-rules.js.map +1 -1
  4. package/lib/assets/enableAudioAutoplayImage.js +1 -2
  5. package/lib/assets/enableAudioAutoplayImage.js.map +1 -1
  6. package/lib/collapsible/index.js +31 -64
  7. package/lib/collapsible/index.js.map +1 -1
  8. package/lib/color.js +57 -201
  9. package/lib/color.js.map +1 -1
  10. package/lib/feedback.js +56 -97
  11. package/lib/feedback.js.map +1 -1
  12. package/lib/has-media.js +2 -7
  13. package/lib/has-media.js.map +1 -1
  14. package/lib/has-text.js +1 -7
  15. package/lib/has-text.js.map +1 -1
  16. package/lib/html-and-math.js +10 -30
  17. package/lib/html-and-math.js.map +1 -1
  18. package/lib/index.js +1 -24
  19. package/lib/index.js.map +1 -1
  20. package/lib/input-container.js +43 -44
  21. package/lib/input-container.js.map +1 -1
  22. package/lib/preview-layout.js +22 -58
  23. package/lib/preview-layout.js.map +1 -1
  24. package/lib/preview-prompt.js +89 -136
  25. package/lib/preview-prompt.js.map +1 -1
  26. package/lib/purpose.js +1 -7
  27. package/lib/purpose.js.map +1 -1
  28. package/lib/readable.js +1 -7
  29. package/lib/readable.js.map +1 -1
  30. package/lib/response-indicators.js +37 -86
  31. package/lib/response-indicators.js.map +1 -1
  32. package/lib/ui-layout.js +59 -81
  33. package/lib/ui-layout.js.map +1 -1
  34. package/lib/withUndoReset.js +51 -97
  35. package/lib/withUndoReset.js.map +1 -1
  36. package/package.json +14 -11
  37. package/src/collapsible/index.jsx +17 -17
  38. package/src/color.js +1 -5
  39. package/src/feedback.jsx +44 -46
  40. package/src/input-container.jsx +41 -32
  41. package/src/preview-layout.jsx +11 -23
  42. package/src/preview-prompt.jsx +62 -62
  43. package/src/response-indicators.jsx +22 -29
  44. package/src/ui-layout.jsx +49 -40
  45. package/src/withUndoReset.jsx +48 -50
@@ -1,13 +1,18 @@
1
1
  import React from 'react';
2
- import { withStyles } from '@material-ui/core/styles';
2
+ import { styled } from '@mui/material/styles';
3
3
  import PropTypes from 'prop-types';
4
4
  import UiLayout from './ui-layout';
5
5
 
6
+ const StyledUiLayout = styled(UiLayout)({
7
+ display: 'flex',
8
+ flexDirection: 'column',
9
+ position: 'relative',
10
+ });
11
+
6
12
  class PreviewLayout extends React.Component {
7
13
  static propTypes = {
8
14
  ariaLabel: PropTypes.string,
9
15
  children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
10
- classes: PropTypes.object,
11
16
  role: PropTypes.string,
12
17
  extraCSSRules: PropTypes.shape({
13
18
  names: PropTypes.arrayOf(PropTypes.string),
@@ -17,32 +22,15 @@ class PreviewLayout extends React.Component {
17
22
  };
18
23
 
19
24
  render() {
20
- const { children, classes, ariaLabel, role, extraCSSRules, fontSizeFactor } = this.props;
25
+ const { children, ariaLabel, role, extraCSSRules, fontSizeFactor, classes } = this.props;
21
26
  const accessibility = ariaLabel ? { 'aria-label': ariaLabel, role } : {};
22
27
 
23
28
  return (
24
- <UiLayout
25
- className={classes.container}
26
- {...accessibility}
27
- extraCSSRules={extraCSSRules}
28
- fontSizeFactor={fontSizeFactor}
29
- >
29
+ <StyledUiLayout {...accessibility} extraCSSRules={extraCSSRules} fontSizeFactor={fontSizeFactor} classes={classes}>
30
30
  {children}
31
- </UiLayout>
31
+ </StyledUiLayout>
32
32
  );
33
33
  }
34
34
  }
35
35
 
36
- const styles = () => ({
37
- container: {
38
- display: 'flex',
39
- flexDirection: 'column',
40
- position: 'relative',
41
- },
42
- });
43
-
44
- const Styled = withStyles(styles)(PreviewLayout);
45
-
46
- const RootElem = (props) => <Styled {...props} />;
47
-
48
- export default RootElem;
36
+ export default PreviewLayout;
@@ -1,15 +1,68 @@
1
1
  import React, { Component } from 'react';
2
- import { withStyles } from '@material-ui/core/styles';
2
+ import { styled } from '@mui/material/styles';
3
3
  import PropTypes from 'prop-types';
4
4
  import * as color from './color';
5
5
 
6
+ const StyledPromptContainer = styled('div')(({ theme, tagName }) => ({
7
+ // Base promptTable styles
8
+ '&:not(.MathJax) > table': {
9
+ borderCollapse: 'collapse',
10
+ },
11
+ // Apply vertical striping only when first column is a header column (th)
12
+ '&:not(.MathJax) > table:has(tr:first-child th:first-child) td': {
13
+ '&:nth-child(2n)': {
14
+ backgroundColor: '#f6f8fa',
15
+ color: theme.palette.common.black,
16
+ },
17
+ },
18
+ // Apply horizontal striping for tables where first element is NOT a header (th)
19
+ '&:not(.MathJax) > table:not(:has(tr:first-child th:first-child)) tr': {
20
+ '&:nth-child(2n)': {
21
+ backgroundColor: '#f6f8fa',
22
+ color: theme.palette.common.black,
23
+ },
24
+ },
25
+ // align table content to left as per STAR requirement PD-3687
26
+ '&:not(.MathJax) table td, &:not(.MathJax) table th': {
27
+ padding: '.6em 1em',
28
+ textAlign: 'left',
29
+ },
30
+ // added this to fix alignment of text in prompt imported from studio (PD-3423)
31
+ '&:not(.MathJax) > table td > p.kds-indent': {
32
+ textAlign: 'initial',
33
+ },
34
+
35
+ // Conditional styles based on class names
36
+ '&.prompt': {
37
+ verticalAlign: 'middle',
38
+ color: color.text(),
39
+ },
40
+ '&.legend': {
41
+ width: '100%',
42
+ fontSize: 'inherit !important',
43
+ },
44
+ '&.rationale': {
45
+ paddingLeft: theme.spacing(4),
46
+ paddingBottom: theme.spacing(1),
47
+ },
48
+ '&.label': {
49
+ color: `${color.text()} !important`,
50
+ display: 'flex',
51
+ flexDirection: 'column',
52
+ verticalAlign: 'middle',
53
+ cursor: 'pointer',
54
+ '& > p': {
55
+ margin: '0 0 0 0 !important',
56
+ },
57
+ },
58
+ }));
59
+
6
60
  //Used these below to replace \\embed{newLine} with \\newline from prompt which will get parsed in MathJax
7
61
  const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
8
62
  const NEWLINE_LATEX = '\\newline ';
9
63
 
10
64
  export class PreviewPrompt extends Component {
11
65
  static propTypes = {
12
- classes: PropTypes.object,
13
66
  prompt: PropTypes.string,
14
67
  tagName: PropTypes.string,
15
68
  className: PropTypes.string,
@@ -186,19 +239,18 @@ export class PreviewPrompt extends Component {
186
239
  }
187
240
 
188
241
  render() {
189
- const { prompt, classes, tagName, className, onClick, defaultClassName } = this.props;
190
- const CustomTag = tagName || 'div';
191
- // legend tag was added once with accessibility tasks, wee need extra style to make it work with images alignment
242
+ const { prompt, tagName, className, onClick, defaultClassName } = this.props;
243
+ // legend tag was added once with accessibility tasks, we need extra style to make it work with images alignment
192
244
  const legendClass = tagName === 'legend' ? 'legend' : '';
193
- const customClasses = `${classes.promptTable} ${classes[className] || ''} ${defaultClassName || ''} ${classes[
194
- legendClass
195
- ] || ''}`;
245
+ const customClasses = `${className || ''} ${defaultClassName || ''} ${legendClass}`.trim();
196
246
 
197
247
  return (
198
- <CustomTag
248
+ <StyledPromptContainer
249
+ as={tagName || 'div'}
199
250
  id={'preview-prompt'}
200
251
  onClick={onClick}
201
252
  className={customClasses}
253
+ tagName={tagName}
202
254
  dangerouslySetInnerHTML={{
203
255
  __html: this.parsedText(prompt || '').replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX),
204
256
  }}
@@ -207,56 +259,4 @@ export class PreviewPrompt extends Component {
207
259
  }
208
260
  }
209
261
 
210
- const styles = (theme) => ({
211
- prompt: {
212
- verticalAlign: 'middle',
213
- color: color.text(),
214
- },
215
- legend: {
216
- width: '100%',
217
- fontSize: 'inherit !important',
218
- },
219
- rationale: {
220
- paddingLeft: theme.spacing.unit * 4,
221
- paddingBottom: theme.spacing.unit,
222
- },
223
- label: {
224
- color: `${color.text()} !important`, //'var(--choice-input-color, black)',
225
- display: 'flex',
226
- flexDirection: 'column',
227
- verticalAlign: 'middle',
228
- cursor: 'pointer',
229
- '& > p': {
230
- margin: '0 0 0 0 !important',
231
- },
232
- },
233
- promptTable: {
234
- '&:not(.MathJax) > table': {
235
- borderCollapse: 'collapse',
236
- },
237
- // Apply vertical striping only when first column is a header column (th)
238
- '&:not(.MathJax) > table:has(tr:first-child th:first-child) td': {
239
- '&:nth-child(2n)': {
240
- backgroundColor: '#f6f8fa',
241
- color: theme.palette.common.black,
242
- },
243
- },
244
- // Apply horizontal striping for tables where first element is NOT a header (th)
245
- '&:not(.MathJax) > table:not(:has(tr:first-child th:first-child)) tr': {
246
- '&:nth-child(2n)': {
247
- backgroundColor: '#f6f8fa',
248
- color: theme.palette.common.black,
249
- },
250
- },
251
- // align table content to left as per STAR requirement PD-3687
252
- '&:not(.MathJax) table td, &:not(.MathJax) table th': {
253
- padding: '.6em 1em',
254
- textAlign: 'left',
255
- },
256
- // added this to fix alignment of text in prompt imported from studio (PD-3423)
257
- '&:not(.MathJax) > table td > p.kds-indent': {
258
- textAlign: 'initial',
259
- },
260
- },
261
- });
262
- export default withStyles(styles)(PreviewPrompt);
262
+ export default PreviewPrompt;
@@ -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,12 @@
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
5
  import classNames from 'classnames';
5
6
  import AppendCSSRules from './append-css-rules';
6
7
 
7
- const theme = createMuiTheme({
8
+ const theme = createTheme({
8
9
  typography: {
9
- useNextVariants: true,
10
10
  fontFamily: 'inherit',
11
11
  },
12
12
  palette: {
@@ -14,36 +14,46 @@ const theme = createMuiTheme({
14
14
  disabled: 'rgba(0, 0, 0, 0.54);',
15
15
  },
16
16
  },
17
- overrides: {
17
+ components: {
18
18
  MuiTypography: {
19
- root: { fontFamily: 'inherit' },
19
+ styleOverrides: {
20
+ root: { fontFamily: 'inherit' },
21
+ },
20
22
  },
21
23
  MuiRadio: {
22
- root: {
23
- '&$checked': {
24
- color: '#3f51b5 !important',
24
+ styleOverrides: {
25
+ root: {
26
+ '&.Mui-checked': {
27
+ color: '#3f51b5 !important',
28
+ },
25
29
  },
26
30
  },
27
31
  },
28
32
  MuiCheckbox: {
29
- root: {
30
- '&$checked': {
31
- color: '#3f51b5 !important',
33
+ styleOverrides: {
34
+ root: {
35
+ '&.Mui-checked': {
36
+ color: '#3f51b5 !important',
37
+ },
32
38
  },
33
39
  },
34
40
  },
35
41
  MuiTabs: {
36
- root: {
37
- borderBottom: '1px solid #eee',
42
+ styleOverrides: {
43
+ root: {
44
+ borderBottom: '1px solid #eee',
45
+ },
38
46
  },
39
47
  },
40
48
  MuiSwitch: {
41
- root: {
42
- '&$checked': {
43
- color: '#3f51b5 !important',
44
- '& + $bar': {
45
- backgroundColor: '#3f51b5 !important',
46
- opacity: 0.5,
49
+ styleOverrides: {
50
+ root: {
51
+ '&.Mui-checked': {
52
+ color: '#3f51b5 !important',
53
+ '& + .MuiSwitch-track': {
54
+ backgroundColor: '#3f51b5 !important',
55
+ opacity: 0.5,
56
+ },
47
57
  },
48
58
  },
49
59
  },
@@ -51,20 +61,30 @@ const theme = createMuiTheme({
51
61
  },
52
62
  });
53
63
 
64
+ const StyledContainer = styled('div')({
65
+ // need this because some browsers set their own style on table
66
+ '& table, th, td': {
67
+ fontSize: 'inherit' /* Ensure table elements inherit font size */,
68
+ },
69
+ });
70
+
54
71
  class UiLayout extends AppendCSSRules {
55
72
  static propTypes = {
56
- classes: PropTypes.object,
57
73
  className: PropTypes.string,
58
74
  children: PropTypes.array,
59
75
  extraCSSRules: PropTypes.shape({
60
76
  names: PropTypes.arrayOf(PropTypes.string),
61
77
  rules: PropTypes.string,
62
78
  }),
79
+ classes: PropTypes.shape({
80
+ extraCSSRules: PropTypes.string,
81
+ }),
63
82
  fontSizeFactor: PropTypes.number,
64
83
  };
65
84
 
66
85
  static defaultProps = {
67
86
  extraCSSRules: {},
87
+ classes: {},
68
88
  fontSizeFactor: 1,
69
89
  };
70
90
 
@@ -84,32 +104,21 @@ class UiLayout extends AppendCSSRules {
84
104
  }
85
105
 
86
106
  render() {
87
- const { children, className, classes, fontSizeFactor, ...rest } = this.props;
107
+ const { children, className, fontSizeFactor, ...rest } = this.props;
88
108
 
89
- const finalClass = classNames(className, classes.extraCSSRules, classes.uiLayoutContainer);
90
109
  const { extraCSSRules, ...restProps } = rest;
91
110
  const style = this.computeStyle(fontSizeFactor);
92
111
 
93
112
  return (
94
- <MuiThemeProvider theme={theme}>
95
- <div className={finalClass} {...restProps} {...(style && { style })}>
96
- {children}
97
- </div>
98
- </MuiThemeProvider>
113
+ <StyledEngineProvider injectFirst>
114
+ <ThemeProvider theme={theme}>
115
+ <StyledContainer className={className} {...restProps} {...(style && { style })}>
116
+ {children}
117
+ </StyledContainer>
118
+ </ThemeProvider>
119
+ </StyledEngineProvider>
99
120
  );
100
121
  }
101
122
  }
102
123
 
103
- const styles = {
104
- extraCSSRules: {},
105
- // need this because some browsers set their own style on table
106
- uiLayoutContainer: {
107
- '& table, th, td': {
108
- fontSize: 'inherit' /* Ensure table elements inherit font size */,
109
- },
110
- },
111
- };
112
-
113
- const Styled = withStyles(styles)(UiLayout);
114
-
115
- export default Styled;
124
+ 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;