Skip to content

Commit

Permalink
Pass handlers instead of elements
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 19, 2020
1 parent 89f3bfb commit 9d24a74
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function Demo(props) {
component={DemoComponent}
iframe={demoOptions.iframe}
name={demoName}
resetDemo={resetDemo}
onResetDemoClick={resetDemo}
/>
</div>
<div className={classes.anchorLink} id={`${demoName}.js`} />
Expand Down
12 changes: 8 additions & 4 deletions docs/src/modules/components/DemoErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';
import Button from '@material-ui/core/Button';

export default class DemoErrorBoundary extends React.Component {
state = {
Expand All @@ -13,7 +14,7 @@ export default class DemoErrorBoundary extends React.Component {
}

render() {
const { children, errorActions } = this.props;
const { children, onResetDemoClick, t } = this.props;
const { error } = this.state;

if (error) {
Expand All @@ -34,7 +35,9 @@ export default class DemoErrorBoundary extends React.Component {
.
</Typography>
<pre>{error.toString()}</pre>
{errorActions}
<Button color="secondary" onClick={onResetDemoClick} variant="text">
{t('resetDemo')}
</Button>
</div>
);
/* eslint-enable material-ui/no-hardcoded-labels */
Expand All @@ -46,8 +49,9 @@ export default class DemoErrorBoundary extends React.Component {

DemoErrorBoundary.propTypes = {
children: PropTypes.node,
onResetDemoClick: PropTypes.func.isRequired,
/**
* actions that should be displayed when the error fallback is displayed
* translate function from redux store
*/
errorActions: PropTypes.node,
t: PropTypes.func.isRequired,
};
13 changes: 3 additions & 10 deletions docs/src/modules/components/DemoSandboxed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import { create } from 'jss';
import { withStyles, useTheme, jssPreset, StylesProvider } from '@material-ui/core/styles';
import NoSsr from '@material-ui/core/NoSsr';
import Button from '@material-ui/core/Button';
import rtl from 'jss-rtl';
import Frame from 'react-frame-component';
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -87,20 +86,14 @@ const StyledFrame = withStyles(styles)(DemoFrame);
* to an `iframe` if `iframe={true}`.
*/
function DemoSandboxed(props) {
const { component: Component, iframe, name, resetDemo, ...other } = props;
const { component: Component, iframe, name, onResetDemoClick, ...other } = props;
const Sandbox = iframe ? StyledFrame : React.Fragment;
const sandboxProps = iframe ? { title: `${name} demo`, ...other } : {};

const t = useSelector(state => state.options.t);

return (
<DemoErrorBoundary
errorActions={
<Button color="secondary" onClick={resetDemo} variant="text">
{t('resetDemo')}
</Button>
}
>
<DemoErrorBoundary onResetDemoClick={onResetDemoClick} t={t}>
<Sandbox {...sandboxProps}>
<Component />
</Sandbox>
Expand All @@ -112,7 +105,7 @@ DemoSandboxed.propTypes = {
component: PropTypes.elementType.isRequired,
iframe: PropTypes.bool,
name: PropTypes.string.isRequired,
resetDemo: PropTypes.func.isRequired,
onResetDemoClick: PropTypes.func.isRequired,
};

export default React.memo(DemoSandboxed);

0 comments on commit 9d24a74

Please sign in to comment.