File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Component } from "react" ;
2+
3+ export class Alert extends Component {
4+ constructor ( props ) {
5+ super ( props ) ;
6+ this . state = { visible : true } ;
7+ }
8+ render ( ) {
9+ const {
10+ type = "information" ,
11+ heading,
12+ children,
13+ closable,
14+ onClose
15+ } = this . props ;
16+
17+ if ( ! this . state . visible ) {
18+ return null ;
19+ }
20+ const handleCloseClick = ( ) => {
21+ this . setState ( { visible : false } ) ;
22+ if ( onClose ) {
23+ onClose ( ) ;
24+ }
25+ } ;
26+ return (
27+ < div >
28+ < div >
29+ < span
30+ role = "img"
31+ aria-label = { type === "warning" ? "Warning" : "Information" }
32+ >
33+ { type === "warning" ? "⚠" : "ℹ️" }
34+ </ span >
35+ < span > { heading } </ span >
36+ </ div >
37+ { closable && (
38+ < button aria-label = "Close" onClick = { handleCloseClick } >
39+ < span role = "img" aria-label = "Close" >
40+ ❌
41+ </ span >
42+ </ button >
43+ ) }
44+ < div > { children } </ div >
45+ </ div >
46+ ) ;
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ import { Alert } from "./Alert" ;
2+ import "./styles.css" ;
3+
4+ export default function App ( ) {
5+ return (
6+ < div className = "App" >
7+ < Alert
8+ type = "information"
9+ heading = "Success"
10+ closable
11+ onClose = { ( ) => console . log ( "closed" ) }
12+ >
13+ Everything is really good!
14+ </ Alert >
15+ </ div >
16+ ) ;
17+ }
You can’t perform that action at this time.
0 commit comments