-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from beaverbuilder/subscription-checks
Subscription checks
- Loading branch information
Showing
14 changed files
with
208 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import classname from 'classnames' | ||
import Button from '../../button' | ||
import './style.scss' | ||
|
||
const Dialog = ( { | ||
className, | ||
title = '', | ||
message = '', | ||
buttons = [], | ||
isShowing = false, | ||
setIsShowing = () => {} | ||
} ) => { | ||
|
||
if ( ! isShowing ) { | ||
return null | ||
} | ||
|
||
const getRoot = () => { | ||
const root = document.getElementById( 'fluid-dialog-root' ) | ||
return root ? root : document.body | ||
} | ||
|
||
return ReactDOM.createPortal( ( | ||
<div className={ classname( 'fl-asst-dialog', className ) }> | ||
<div className='fl-asst-dialog-window'> | ||
{ title && | ||
<div className='fl-asst-dialog-title'> | ||
{ title } | ||
</div> | ||
} | ||
<div className='fl-asst-dialog-message'> | ||
{ message } | ||
</div> | ||
<div className='fl-asst-dialog-buttons'> | ||
{ buttons.map( ( { label, onClick, ...rest }, i ) => | ||
<Button | ||
key={ i } | ||
onClick={ () => { | ||
if ( onClick ) { | ||
onClick( { | ||
closeDialog: () => setIsShowing( false ) | ||
} ) | ||
} | ||
} } | ||
{ ...rest } | ||
> | ||
{ label } | ||
</Button> | ||
) } | ||
</div> | ||
</div> | ||
</div> | ||
), getRoot() ) | ||
} | ||
|
||
export default Dialog |
43 changes: 43 additions & 0 deletions
43
packages/@beaverbuilder/fluid/src/dialogs/dialog/style.scss
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,43 @@ | ||
.fl-asst-dialog { | ||
background-color: rgba(0,0,0,0.2); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: var(--fluid-med-space); | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: 1000; | ||
} | ||
|
||
.fl-asst-dialog-window { | ||
background: var(--fluid-background); | ||
border-radius: var(--fluid-radius); | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.25); | ||
padding: var(--fluid-lg-space); | ||
max-width: 460px; | ||
width: 100%; | ||
} | ||
|
||
.fl-asst-dialog-title { | ||
font-size: 20px; | ||
margin-bottom: var(--fluid-med-space); | ||
} | ||
|
||
.fl-asst-dialog-message { | ||
font-size: 14px; | ||
line-height: 1.6; | ||
margin-bottom: var(--fluid-lg-space); | ||
} | ||
|
||
.fl-asst-dialog-buttons { | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
button { | ||
margin-left: var(--fluid-sm-space); | ||
min-width: 70px !important; | ||
} | ||
} |
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,60 @@ | ||
import React, { useState } from 'react' | ||
import Dialog from '../dialog' | ||
|
||
export const useDialog = ( options ) => { | ||
const [ isShowing, setIsShowing ] = useState( false ) | ||
|
||
const showDialog = () => { | ||
setIsShowing( true ) | ||
} | ||
|
||
const DialogComponent = () => { | ||
return ( | ||
<Dialog | ||
isShowing={ isShowing } | ||
setIsShowing={ setIsShowing } | ||
{ ...options } | ||
/> | ||
) | ||
} | ||
|
||
return [ showDialog, DialogComponent ] | ||
} | ||
|
||
export const useAlert = ( options ) => { | ||
options.buttons = [ | ||
{ | ||
label: 'Ok', | ||
isSelected: true, | ||
onClick: ( { closeDialog } ) => closeDialog(), | ||
} | ||
] | ||
|
||
return useDialog( options ) | ||
} | ||
|
||
export const useConfirm = ( { | ||
onCancel = () => {}, | ||
onConfirm = () => {}, | ||
...options | ||
} ) => { | ||
options.buttons = [ | ||
{ | ||
label: 'Cancel', | ||
onClick: ( { closeDialog } ) => { | ||
closeDialog() | ||
onCancel() | ||
}, | ||
}, | ||
{ | ||
label: 'Ok', | ||
isSelected: true, | ||
onClick: ( { closeDialog } ) => { | ||
closeDialog() | ||
onConfirm() | ||
}, | ||
} | ||
] | ||
|
||
return useDialog( options ) | ||
} |
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,10 @@ | ||
import Dialog from './dialog' | ||
import DialogRoot from './root' | ||
import { useDialog, useAlert, useConfirm } from './hooks' | ||
|
||
Dialog.DialogRoot = DialogRoot | ||
Dialog.useDialog = useDialog | ||
Dialog.useAlert = useAlert | ||
Dialog.useConfirm = useConfirm | ||
|
||
export default Dialog |
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,9 @@ | ||
import React from 'react' | ||
|
||
const DialogRoot = () => { | ||
return ( | ||
<div id='fluid-dialog-root' /> | ||
) | ||
} | ||
|
||
export default DialogRoot |
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
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