ConfirmDialog.js
1 month ago
LabelWithTooltip.js
1 month ago
ProGate.js
1 month ago
SectionCard.js
1 month ago
SettingsDataProvider.js
1 month ago
SettingsPageShell.js
1 month ago
UnsavedChangesDialog.js
1 month ago
navigationGuard.js
1 month ago
ConfirmDialog.js
77 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { useState } from 'react'; |
| 3 | import { Dialog, Button } from '@bsf/force-ui'; |
| 4 | |
| 5 | const ConfirmDialog = ( { |
| 6 | open, |
| 7 | title, |
| 8 | description, |
| 9 | confirmLabel, |
| 10 | cancelLabel, |
| 11 | confirmVariant = 'primary', |
| 12 | confirmDestructive = false, |
| 13 | onConfirm, |
| 14 | onCancel, |
| 15 | children, |
| 16 | } ) => { |
| 17 | const [ isBusy, setIsBusy ] = useState( false ); |
| 18 | |
| 19 | const handleConfirm = async () => { |
| 20 | setIsBusy( true ); |
| 21 | try { |
| 22 | await onConfirm?.(); |
| 23 | } finally { |
| 24 | setIsBusy( false ); |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | return ( |
| 29 | <Dialog |
| 30 | design="simple" |
| 31 | exitOnEsc |
| 32 | scrollLock |
| 33 | open={ open } |
| 34 | setOpen={ ( next ) => { |
| 35 | if ( ! next ) { |
| 36 | onCancel?.(); |
| 37 | } |
| 38 | } } |
| 39 | > |
| 40 | <Dialog.Backdrop /> |
| 41 | <Dialog.Panel> |
| 42 | <Dialog.Header> |
| 43 | <Dialog.Title>{ title }</Dialog.Title> |
| 44 | </Dialog.Header> |
| 45 | |
| 46 | { ( description || children ) && ( |
| 47 | <Dialog.Body> |
| 48 | { description && ( |
| 49 | <Dialog.Description> |
| 50 | { description } |
| 51 | </Dialog.Description> |
| 52 | ) } |
| 53 | { children } |
| 54 | </Dialog.Body> |
| 55 | ) } |
| 56 | |
| 57 | <Dialog.Footer> |
| 58 | <Button variant="ghost" onClick={ onCancel } disabled={ isBusy }> |
| 59 | { cancelLabel || __( 'Cancel', 'presto-player' ) } |
| 60 | </Button> |
| 61 | <Button |
| 62 | variant={ confirmVariant } |
| 63 | destructive={ confirmDestructive } |
| 64 | onClick={ handleConfirm } |
| 65 | disabled={ isBusy } |
| 66 | loading={ isBusy } |
| 67 | > |
| 68 | { confirmLabel || __( 'Confirm', 'presto-player' ) } |
| 69 | </Button> |
| 70 | </Dialog.Footer> |
| 71 | </Dialog.Panel> |
| 72 | </Dialog> |
| 73 | ); |
| 74 | }; |
| 75 | |
| 76 | export default ConfirmDialog; |
| 77 |