apply-popup-button-trigger-ui.js
10 months ago
apply-popup-image-trigger-placeholder.js
10 months ago
apply-popup-preview-toggle.js
10 months ago
apply-popup-preview-toggle.js
34 lines
| 1 | import { addFilter } from "@wordpress/hooks"; |
| 2 | import { createHigherOrderComponent } from "@wordpress/compose"; |
| 3 | import Context from "../blocks/popup/context/context"; |
| 4 | import PreviewToggle from "../blocks/popup/components/PreviewToggle"; |
| 5 | |
| 6 | /** |
| 7 | * Higher order component to add tab switcher to blocks in popup context |
| 8 | */ |
| 9 | const WithPopupPreviewToggle = createHigherOrderComponent((BlockEdit) => { |
| 10 | return (props) => ( |
| 11 | <Context.Consumer> |
| 12 | {(contextValue) => { |
| 13 | const { open, setOpen } = contextValue || {}; |
| 14 | return ( |
| 15 | <> |
| 16 | {contextValue && <PreviewToggle open={open} setOpen={setOpen} />} |
| 17 | <BlockEdit {...props} /> |
| 18 | </> |
| 19 | ); |
| 20 | }} |
| 21 | </Context.Consumer> |
| 22 | ); |
| 23 | }, "withPopupPreviewToggle"); |
| 24 | |
| 25 | /** |
| 26 | * Custom hook to initialize the popup tab switcher |
| 27 | */ |
| 28 | // Apply the filter to all block edits |
| 29 | addFilter( |
| 30 | "editor.BlockEdit", |
| 31 | "presto-player/popup-preview-toggle", |
| 32 | WithPopupPreviewToggle |
| 33 | ); |
| 34 |