@pie-lib/render-ui 4.32.6-esmbeta.0 → 4.33.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 (49) hide show
  1. package/CHANGELOG.md +41 -0
  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 -98
  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 +26 -42
  21. package/lib/input-container.js.map +1 -1
  22. package/lib/preview-layout.js +19 -101
  23. package/lib/preview-layout.js.map +1 -1
  24. package/lib/preview-prompt.js +89 -128
  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 +85 -60
  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 -19
  37. package/src/collapsible/index.jsx +17 -17
  38. package/src/color.js +1 -5
  39. package/src/feedback.jsx +44 -47
  40. package/src/input-container.jsx +23 -26
  41. package/src/preview-layout.jsx +11 -70
  42. package/src/preview-prompt.jsx +62 -54
  43. package/src/response-indicators.jsx +22 -29
  44. package/src/ui-layout.jsx +74 -20
  45. package/src/withUndoReset.jsx +48 -50
  46. package/esm/index.css +0 -847
  47. package/esm/index.js +0 -48476
  48. package/esm/index.js.map +0 -1
  49. package/esm/package.json +0 -1
@@ -1,13 +1,18 @@
1
1
  import React from 'react';
2
- import { withStyles, createMuiTheme, MuiThemeProvider } 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,79 +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 } = 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}>
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 theme = createMuiTheme({
45
- typography: {
46
- useNextVariants: true,
47
- },
48
- palette: {
49
- action: {
50
- disabled: 'rgba(0, 0, 0, 0.54);',
51
- },
52
- },
53
- overrides: {
54
- MuiRadio: {
55
- root: {
56
- '&$checked': {
57
- color: '#3f51b5 !important',
58
- },
59
- },
60
- },
61
- MuiCheckbox: {
62
- root: {
63
- '&$checked': {
64
- color: '#3f51b5 !important',
65
- },
66
- },
67
- },
68
- MuiTabs: {
69
- root: {
70
- borderBottom: '1px solid #eee',
71
- },
72
- },
73
- MuiSwitch: {
74
- root: {
75
- '&$checked': {
76
- color: '#3f51b5 !important',
77
- '& + $bar': {
78
- backgroundColor: '#3f51b5 !important',
79
- opacity: 0.5,
80
- },
81
- },
82
- },
83
- },
84
- },
85
- });
86
-
87
- const Styled = withStyles(styles)(PreviewLayout);
88
-
89
- const RootElem = (props) => (
90
- <MuiThemeProvider theme={theme}>
91
- <Styled {...props} />
92
- </MuiThemeProvider>
93
- );
94
-
95
- 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,48 +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
- '&:not(.MathJax) > table tr': {
238
- '&:nth-child(2n)': {
239
- backgroundColor: '#f6f8fa',
240
- color: theme.palette.common.black,
241
- },
242
- },
243
- // align table content to left as per STAR requirement PD-3687
244
- '&:not(.MathJax) table td, &:not(.MathJax) table th': {
245
- padding: '.6em 1em',
246
- textAlign: 'left',
247
- },
248
- // added this to fix alignment of text in prompt imported from studio (PD-3423)
249
- '&:not(.MathJax) > table td > p.kds-indent': {
250
- textAlign: 'initial',
251
- },
252
- },
253
- });
254
- 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,75 @@
1
1
  import React from 'react';
2
- import { 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
 
8
+ const theme = createTheme({
9
+ typography: {
10
+ fontFamily: 'inherit',
11
+ },
12
+ palette: {
13
+ action: {
14
+ disabled: 'rgba(0, 0, 0, 0.54);',
15
+ },
16
+ },
17
+ components: {
18
+ MuiTypography: {
19
+ styleOverrides: {
20
+ root: { fontFamily: 'inherit' },
21
+ },
22
+ },
23
+ MuiRadio: {
24
+ styleOverrides: {
25
+ root: {
26
+ '&.Mui-checked': {
27
+ color: '#3f51b5 !important',
28
+ },
29
+ },
30
+ },
31
+ },
32
+ MuiCheckbox: {
33
+ styleOverrides: {
34
+ root: {
35
+ '&.Mui-checked': {
36
+ color: '#3f51b5 !important',
37
+ },
38
+ },
39
+ },
40
+ },
41
+ MuiTabs: {
42
+ styleOverrides: {
43
+ root: {
44
+ borderBottom: '1px solid #eee',
45
+ },
46
+ },
47
+ },
48
+ MuiSwitch: {
49
+ styleOverrides: {
50
+ root: {
51
+ '&.Mui-checked': {
52
+ color: '#3f51b5 !important',
53
+ '& + .MuiSwitch-track': {
54
+ backgroundColor: '#3f51b5 !important',
55
+ opacity: 0.5,
56
+ },
57
+ },
58
+ },
59
+ },
60
+ },
61
+ },
62
+ });
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
+
7
71
  class UiLayout extends AppendCSSRules {
8
72
  static propTypes = {
9
- classes: PropTypes.object,
10
73
  className: PropTypes.string,
11
74
  children: PropTypes.array,
12
75
  extraCSSRules: PropTypes.shape({
@@ -37,30 +100,21 @@ class UiLayout extends AppendCSSRules {
37
100
  }
38
101
 
39
102
  render() {
40
- const { children, className, classes, fontSizeFactor, ...rest } = this.props;
103
+ const { children, className, fontSizeFactor, ...rest } = this.props;
41
104
 
42
- const finalClass = classNames(className, classes.extraCSSRules, classes.uiLayoutContainer);
43
105
  const { extraCSSRules, ...restProps } = rest;
44
106
  const style = this.computeStyle(fontSizeFactor);
45
107
 
46
108
  return (
47
- <div className={finalClass} {...restProps} {...(style && { style })}>
48
- {children}
49
- </div>
109
+ <StyledEngineProvider injectFirst>
110
+ <ThemeProvider theme={theme}>
111
+ <StyledContainer className={className} {...restProps} {...(style && { style })}>
112
+ {children}
113
+ </StyledContainer>
114
+ </ThemeProvider>
115
+ </StyledEngineProvider>
50
116
  );
51
117
  }
52
118
  }
53
119
 
54
- const styles = {
55
- extraCSSRules: {},
56
- // need this because some browsers set their own style on table
57
- uiLayoutContainer: {
58
- '& table, th, td': {
59
- fontSize: 'inherit' /* Ensure table elements inherit font size */,
60
- },
61
- },
62
- };
63
-
64
- const Styled = withStyles(styles)(UiLayout);
65
-
66
- export default Styled;
120
+ 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;