Created
January 17, 2018 13:05
-
-
Save Peripona/c1915bc1b20611ea27fb38cb37978c7a to your computer and use it in GitHub Desktop.
Creating and using HMTL5 dialog with react
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
.App { | |
text-align: center; | |
} | |
.App-logo { | |
animation: App-logo-spin infinite 20s linear; | |
height: 80px; | |
} | |
.App-header { | |
background-color: #222; | |
height: 150px; | |
padding: 20px; | |
color: white; | |
} | |
.App-title { | |
font-size: 1.5em; | |
} | |
.App-intro { | |
font-size: large; | |
} | |
@keyframes App-logo-spin { | |
from { transform: rotate(0deg); } | |
to { transform: rotate(360deg); } | |
} |
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
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.showDialog = this.showDialog.bind(this); | |
this.hideDialog = this.hideDialog.bind(this); | |
this.state = { | |
isOpen: false, | |
}; | |
} | |
showDialog() { | |
this.setState({ | |
isOpen: true | |
}); | |
} | |
hideDialog() { | |
this.setState({ | |
isOpen: false | |
}); | |
} | |
render() { | |
const {isOpen} = this.state; | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<h1 className="App-title">Welcome to React</h1> | |
<img src={logo} alt="logo" className="App-logo"/> | |
</header> | |
<dialog id="dialog" open={isOpen}> | |
<button id="close" onClick={this.hideDialog}>Close Dialog</button> | |
<h2>Dialog Title</h2> | |
<img src={logo} alt="logo" className="App-logo"/> | |
<p>Dialog content and other stuff will go here</p> | |
</dialog> | |
<p className="App-intro"> | |
To get started, edit <code>src/App.js</code> and save to reload. | |
</p> | |
<button id="open" onClick={this.showDialog}>Open Dialog</button> | |
</div> | |
); | |
} | |
} | |
export default App; |
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
body { | |
margin: 0; | |
padding: 0; | |
font-family: sans-serif; | |
} |
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import './index.css'; | |
import App from './App'; | |
ReactDOM.render(<App />, document.getElementById('root')); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using HTML5.2 dialog with react by passing props is open on click of openDialog.