@@ -2,6 +2,15 @@ import React, { useState, useEffect } from 'react';
22import ReactDOM from 'react-dom' ;
33import './modali.css' ;
44
5+ const Button = ( { onClick, label, isStyleDefault, isStyleCancel, isStyleDestructive } ) => (
6+ < button
7+ className = { `modali-button ${ isStyleCancel && 'modali-button-cancel' } ${ isStyleDefault && 'modali-button-default' } ${ isStyleDestructive && 'modali-button-destructive' } ` }
8+ onClick = { onClick }
9+ >
10+ { label }
11+ </ button >
12+ ) ;
13+
514const Modali = ( { isShown, hide, options, children } ) => {
615
716 function handleOverlayClicked ( e ) {
@@ -20,6 +29,33 @@ const Modali = ({ isShown, hide, options, children }) => {
2029 }
2130 }
2231
32+ function renderBody ( ) {
33+ if ( children ) {
34+ return children ;
35+ } else if ( options !== undefined && options . message !== undefined ) {
36+ return (
37+ < div className = "modali-body-style" >
38+ { options . message }
39+ </ div >
40+ ) ;
41+ }
42+ }
43+
44+ function renderFooter ( ) {
45+ const { buttons } = options ;
46+ return (
47+ < div className = "modali-footer" >
48+ { buttons . map ( ( button , index ) => (
49+ < React . Fragment
50+ key = { `modali-button-${ index } ` }
51+ >
52+ { button }
53+ </ React . Fragment >
54+ ) ) }
55+ </ div >
56+ ) ;
57+ }
58+
2359 return isShown ? ReactDOM . createPortal (
2460 < React . Fragment >
2561 < div className = "modali-overlay" />
@@ -28,21 +64,28 @@ const Modali = ({ isShown, hide, options, children }) => {
2864 < div className = "modali-content" >
2965 { options !== undefined && options . closeButton === false ? null : (
3066 < div className = "modali-header" >
67+ { options !== undefined && options . title !== undefined && (
68+ < div className = "modali-title" >
69+ { options . title }
70+ </ div >
71+ ) }
3172 < button type = "button" className = "modali-close-button" data-dismiss = "modal" aria-label = "Close" onClick = { hide } >
3273 < span aria-hidden = "true" > ×</ span >
3374 </ button >
3475 </ div >
3576 ) }
3677 < div className = "modali-body" >
37- { children }
78+ { renderBody ( ) }
3879 </ div >
80+ { options !== undefined && options . buttons !== undefined && options . buttons . length > 0 && renderFooter ( ) }
3981 </ div >
4082 </ div >
4183 </ div >
4284 </ React . Fragment > , document . body
4385 ) : null ;
4486} ;
4587
88+ Modali . Button = Button ;
4689export default Modali ;
4790
4891export const useModali = ( options ) => {
0 commit comments