| 1 |
/** |
| 2 |
* Internal dependencies |
| 3 |
*/ |
| 4 |
import getIcon from '../../utils/get-icon'; |
| 5 |
|
| 6 |
/** |
| 7 |
* WordPress dependencies |
| 8 |
*/ |
| 9 |
const { Component } = wp.element; |
| 10 |
|
| 11 |
const { __ } = wp.i18n; |
| 12 |
|
| 13 |
const { Button, Popover } = wp.components; |
| 14 |
|
| 15 |
/** |
| 16 |
* Component Class |
| 17 |
*/ |
| 18 |
export default class RemoveButton extends Component { |
| 19 |
constructor(props) { |
| 20 |
super(props); |
| 21 |
|
| 22 |
this.state = { |
| 23 |
confirmed: -1, |
| 24 |
}; |
| 25 |
} |
| 26 |
|
| 27 |
render() { |
| 28 |
const { |
| 29 |
onRemove, |
| 30 |
show, |
| 31 |
style, |
| 32 |
tooltipText = __('Remove Block?', 'ghostkit'), |
| 33 |
tooltipRemoveText = __('Remove', 'ghostkit'), |
| 34 |
tooltipCancelText = __('Cancel', 'ghostkit'), |
| 35 |
} = this.props; |
| 36 |
|
| 37 |
const { confirmed } = this.state; |
| 38 |
|
| 39 |
if (!show) { |
| 40 |
return null; |
| 41 |
} |
| 42 |
|
| 43 |
return ( |
| 44 |
<Button |
| 45 |
className="ghostkit-component-remove-button" |
| 46 |
onClick={() => { |
| 47 |
if (confirmed === -1) { |
| 48 |
this.setState({ |
| 49 |
confirmed: 0, |
| 50 |
}); |
| 51 |
} |
| 52 |
}} |
| 53 |
style={style} |
| 54 |
> |
| 55 |
{confirmed === 0 ? ( |
| 56 |
<Popover |
| 57 |
className="ghostkit-component-remove-button-confirm" |
| 58 |
onClose={() => { |
| 59 |
this.setState({ |
| 60 |
confirmed: -1, |
| 61 |
}); |
| 62 |
}} |
| 63 |
onFocusOutside={() => { |
| 64 |
this.setState({ |
| 65 |
confirmed: -1, |
| 66 |
}); |
| 67 |
}} |
| 68 |
> |
| 69 |
{tooltipText} |
| 70 |
<Button className="ghostkit-component-remove-button-confirm-yep" onClick={onRemove}> |
| 71 |
{tooltipRemoveText} |
| 72 |
</Button> |
| 73 |
<Button |
| 74 |
className="ghostkit-component-remove-button-confirm-nope" |
| 75 |
onClick={() => { |
| 76 |
this.setState({ |
| 77 |
confirmed: -1, |
| 78 |
}); |
| 79 |
}} |
| 80 |
> |
| 81 |
{tooltipCancelText} |
| 82 |
</Button> |
| 83 |
</Popover> |
| 84 |
) : ( |
| 85 |
'' |
| 86 |
)} |
| 87 |
{getIcon('icon-trash')} |
| 88 |
</Button> |
| 89 |
); |
| 90 |
} |
| 91 |
} |
| 92 |
|