add-item.js
2 months ago
delete-item-button.js
2 months ago
index.js
2 months ago
preview.js
2 months ago
delete-item-button.js
85 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { __, sprintf } from '@wordpress/i18n'; |
| 5 | import { useContext, useState } from '@wordpress/element'; |
| 6 | import { Button, Modal, Flex, FlexItem } from '@wordpress/components'; |
| 7 | |
| 8 | /** |
| 9 | * Internal dependencies |
| 10 | */ |
| 11 | import { AdminContext } from '@vkblocks/admin/index'; |
| 12 | |
| 13 | export const DeleteItemButton = (props) => { |
| 14 | const { vkBlocksOption, setVkBlocksOption } = useContext(AdminContext); |
| 15 | const { index, textStyleListObj } = props; |
| 16 | |
| 17 | const [isModalOpen, setIsModalOpen] = useState(false); |
| 18 | |
| 19 | const openModal = () => setIsModalOpen(true); |
| 20 | const closeModal = () => setIsModalOpen(false); |
| 21 | |
| 22 | const deleteItem = () => { |
| 23 | vkBlocksOption.custom_format_lists.splice(index, 1); |
| 24 | setVkBlocksOption({ |
| 25 | ...vkBlocksOption, |
| 26 | }); |
| 27 | }; |
| 28 | |
| 29 | const textStyleTitle = !!textStyleListObj.title |
| 30 | ? textStyleListObj.title |
| 31 | : __('Custom Format', 'vk-blocks'); |
| 32 | |
| 33 | return ( |
| 34 | <> |
| 35 | <Button |
| 36 | className="delete-item-button" |
| 37 | isDestructive |
| 38 | onClick={openModal} |
| 39 | > |
| 40 | {__('Delete', 'vk-blocks')} |
| 41 | </Button> |
| 42 | {isModalOpen && ( |
| 43 | <Modal |
| 44 | title={sprintf( |
| 45 | // translators: Would you like to delete %s |
| 46 | __('Would you like to delete %s?', 'vk-blocks'), |
| 47 | textStyleTitle |
| 48 | )} |
| 49 | onRequestClose={closeModal} |
| 50 | isDismissible={false} |
| 51 | > |
| 52 | <div className="custom_format_delete_modal"> |
| 53 | <p> |
| 54 | {__( |
| 55 | 'If the saved content has this format, the style will be unstyled.', |
| 56 | 'vk-blocks' |
| 57 | )} |
| 58 | </p> |
| 59 | <div className="custom_format_delete_modal_button_area"> |
| 60 | <Flex justify="flex-end"> |
| 61 | <FlexItem> |
| 62 | <Button isSecondary onClick={closeModal}> |
| 63 | {__('Cancel')} |
| 64 | </Button> |
| 65 | </FlexItem> |
| 66 | <FlexItem> |
| 67 | <Button |
| 68 | isDestructive |
| 69 | onClick={() => { |
| 70 | deleteItem(); |
| 71 | closeModal(); |
| 72 | }} |
| 73 | > |
| 74 | {__('Delete', 'vk-blocks')} |
| 75 | </Button> |
| 76 | </FlexItem> |
| 77 | </Flex> |
| 78 | </div> |
| 79 | </div> |
| 80 | </Modal> |
| 81 | )} |
| 82 | </> |
| 83 | ); |
| 84 | }; |
| 85 |