-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Set the infrastructure for a full page demo (#13314)
- Loading branch information
1 parent
79444f1
commit 06967ec
Showing
25 changed files
with
1,105 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { create } from 'jss'; | ||
import { | ||
withStyles, | ||
createGenerateClassName, | ||
jssPreset, | ||
MuiThemeProvider, | ||
} from '@material-ui/core/styles'; | ||
import rtl from 'jss-rtl'; | ||
import Frame from 'react-frame-component'; | ||
import JssProvider from 'react-jss/lib/JssProvider'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
backgroundColor: theme.palette.background.default, | ||
flexGrow: 1, | ||
height: 400, | ||
border: 'none', | ||
boxShadow: theme.shadows[1], | ||
}, | ||
}); | ||
|
||
const generateClassName = createGenerateClassName(); | ||
|
||
class DemoFrame extends React.Component { | ||
state = { | ||
ready: false, | ||
}; | ||
|
||
handleRef = ref => { | ||
this.contentDocument = ref ? ref.node.contentDocument : null; | ||
}; | ||
|
||
onContentDidMount = () => { | ||
this.setState({ | ||
ready: true, | ||
jss: create({ | ||
plugins: [...jssPreset().plugins, rtl()], | ||
insertionPoint: this.contentDocument.querySelector('#demo-frame-jss'), | ||
}), | ||
sheetsManager: new Map(), | ||
container: this.contentDocument.body, | ||
}); | ||
}; | ||
|
||
onContentDidUpdate = () => { | ||
this.contentDocument.body.dir = this.props.theme.direction; | ||
}; | ||
|
||
render() { | ||
const { children, classes, theme } = this.props; | ||
|
||
const inIframe = this.state.ready ? ( | ||
<JssProvider jss={this.state.jss} generateClassName={generateClassName}> | ||
<MuiThemeProvider theme={theme} sheetsManager={this.state.sheetsManager}> | ||
{React.cloneElement(children, { | ||
container: this.state.container, | ||
})} | ||
</MuiThemeProvider> | ||
</JssProvider> | ||
) : null; | ||
|
||
return ( | ||
<Frame | ||
ref={this.handleRef} | ||
className={classes.root} | ||
contentDidMount={this.onContentDidMount} | ||
contentDidUpdate={this.onContentDidUpdate} | ||
> | ||
<div id="demo-frame-jss" /> | ||
{inIframe} | ||
</Frame> | ||
); | ||
} | ||
} | ||
|
||
DemoFrame.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
classes: PropTypes.object.isRequired, | ||
theme: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles, { withTheme: true })(DemoFrame); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.