UNPKG

panelsnap

Version:

A JavaScript plugin that provides snapping functionality to a set of panels within your interface.

101 lines (83 loc) 2.78 kB
<!doctype html> <html lang="en-us"> <!-- Note: this page is a great way to try React but it's not suitable for production. It slowly compiles JSX with Babel in the browser and uses a large development build of React. To set up a production-ready React build environment, follow these instructions: * https://reactjs.org/docs/add-react-to-a-new-app.html * https://reactjs.org/docs/add-react-to-an-existing-app.html You can also use React without JSX, in which case you can remove Babel: * https://reactjs.org/docs/react-without-jsx.html * https://reactjs.org/docs/cdn-links.html --> <head> <meta charset="utf-8"> <title>PanelSnap - Vue demo</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui"> <link href="https://fonts.googleapis.com/css?family=Lato:100,300" rel="stylesheet"> <link href="../../style.css" rel="stylesheet"> <script src="../../panelsnap.js" defer></script> <script src="https://unpkg.com/react@16/umd/react.development.js" defer crossorigin></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" defer crossorigin></script> <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js" defer></script> <script type="text/babel"> class App extends React.Component { constructor(props) { super(props); this.state = { activePanelName: undefined }; } componentDidMount() { this.panelSnapInstance = new PanelSnap({ panelSelector: '> #root > #app > section' }); this.panelSnapInstance.on('activatePanel', this.activatePanel.bind(this)); } activatePanel(panel) { this.setState({ activePanelName: panel.querySelector('h1').innerText }); } render() { return ( <div id="app"> <section> <h1>First</h1> </section> <section> <h1>Second</h1> </section> <section> <h1>Third</h1> </section> <div className="status"> Active panel: {this.state.activePanelName} </div> </div> ) } } ReactDOM.render( <App/>, document.getElementById('root') ); </script> <style> section:nth-child(2) { min-height: calc(100vh + 200px); } .status { position: fixed; bottom: 0; left: 0; right: 0; padding: 10px; text-align: center; } </style> </head> <body> <div id="root"></div> </body> </html>