| 1 |
import { Button, Popover } from '@wordpress/components'; |
| 2 |
import { useState } from '@wordpress/element'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
|
| 5 |
import getIcon from '../../utils/get-icon'; |
| 6 |
|
| 7 |
/** |
| 8 |
* Component Class |
| 9 |
* |
| 10 |
* @param props |
| 11 |
*/ |
| 12 |
export default function RemoveButton(props) { |
| 13 |
const [confirmed, setConfirmed] = useState(-1); |
| 14 |
|
| 15 |
const { |
| 16 |
onRemove, |
| 17 |
show, |
| 18 |
style, |
| 19 |
tooltipText = __('Remove Block?', 'ghostkit'), |
| 20 |
tooltipRemoveText = __('Remove', 'ghostkit'), |
| 21 |
tooltipCancelText = __('Cancel', 'ghostkit'), |
| 22 |
} = props; |
| 23 |
|
| 24 |
if (!show) { |
| 25 |
return null; |
| 26 |
} |
| 27 |
|
| 28 |
return ( |
| 29 |
<Button |
| 30 |
className="ghostkit-component-remove-button" |
| 31 |
onClick={() => { |
| 32 |
if (confirmed === -1) { |
| 33 |
setConfirmed(0); |
| 34 |
} |
| 35 |
}} |
| 36 |
style={style} |
| 37 |
> |
| 38 |
{confirmed === 0 ? ( |
| 39 |
<Popover |
| 40 |
className="ghostkit-component-remove-button-confirm" |
| 41 |
onClose={() => { |
| 42 |
setConfirmed(-1); |
| 43 |
}} |
| 44 |
onFocusOutside={() => { |
| 45 |
setConfirmed(-1); |
| 46 |
}} |
| 47 |
> |
| 48 |
{tooltipText} |
| 49 |
<Button |
| 50 |
className="ghostkit-component-remove-button-confirm-yep" |
| 51 |
onClick={onRemove} |
| 52 |
> |
| 53 |
{tooltipRemoveText} |
| 54 |
</Button> |
| 55 |
<Button |
| 56 |
className="ghostkit-component-remove-button-confirm-nope" |
| 57 |
onClick={() => { |
| 58 |
setConfirmed(-1); |
| 59 |
}} |
| 60 |
> |
| 61 |
{tooltipCancelText} |
| 62 |
</Button> |
| 63 |
</Popover> |
| 64 |
) : null} |
| 65 |
{getIcon('icon-trash')} |
| 66 |
</Button> |
| 67 |
); |
| 68 |
} |
| 69 |
|