| 1 |
const { dispatch } = wp.data; |
| 2 |
|
| 3 |
import { |
| 4 |
handleDesktopBtnClick, |
| 5 |
handleMobileBtnClick, |
| 6 |
handleTabBtnClick, |
| 7 |
} from "../helpers"; |
| 8 |
|
| 9 |
export default function WithResButtons({ |
| 10 |
className, |
| 11 |
children, |
| 12 |
resRequiredProps, |
| 13 |
label, // this prop is passed only from background control |
| 14 |
}) { |
| 15 |
const { setAttributes, resOption } = resRequiredProps; |
| 16 |
const editorType = window?.betterDocsBlocksHelper?.editorType ?? editorType; |
| 17 |
|
| 18 |
return ( |
| 19 |
<div className={`wrap_res ${className || " "}`}> |
| 20 |
<div className={`${label ? `resBtns` : `resIcons`}`}> |
| 21 |
{/* 'label' prop is used in background-control */} |
| 22 |
{label && ( |
| 23 |
<span style={{ paddingRight: "5px" }} className="resLabel"> |
| 24 |
{label} |
| 25 |
</span> |
| 26 |
)} |
| 27 |
<span |
| 28 |
onClick={() => |
| 29 |
handleDesktopBtnClick({ |
| 30 |
setAttributes, |
| 31 |
setPreviewDeviceType: |
| 32 |
dispatch(editorType) |
| 33 |
.__experimentalSetPreviewDeviceType, |
| 34 |
}) |
| 35 |
} |
| 36 |
className={`typoResButton dashicons dashicons-desktop ${ |
| 37 |
resOption === "Desktop" ? "active" : " " |
| 38 |
}`} |
| 39 |
></span> |
| 40 |
<span |
| 41 |
onClick={() => |
| 42 |
handleTabBtnClick({ |
| 43 |
setAttributes, |
| 44 |
setPreviewDeviceType: |
| 45 |
dispatch(editorType) |
| 46 |
.__experimentalSetPreviewDeviceType, |
| 47 |
}) |
| 48 |
} |
| 49 |
className={`typoResButton dashicons dashicons-tablet ${ |
| 50 |
resOption === "Tablet" ? "active" : " " |
| 51 |
}`} |
| 52 |
></span> |
| 53 |
<span |
| 54 |
onClick={() => |
| 55 |
handleMobileBtnClick({ |
| 56 |
setAttributes, |
| 57 |
setPreviewDeviceType: |
| 58 |
dispatch(editorType) |
| 59 |
.__experimentalSetPreviewDeviceType, |
| 60 |
}) |
| 61 |
} |
| 62 |
className={`typoResButton dashicons dashicons-smartphone ${ |
| 63 |
resOption === "Mobile" ? "active" : " " |
| 64 |
}`} |
| 65 |
></span> |
| 66 |
</div> |
| 67 |
{children} |
| 68 |
</div> |
| 69 |
); |
| 70 |
} |
| 71 |
|