| 1 |
const { dispatch } = wp.data; |
| 2 |
import { |
| 3 |
handleDesktopBtnClick, |
| 4 |
handleTabBtnClick, |
| 5 |
handleMobileBtnClick, |
| 6 |
} from "../helpers"; |
| 7 |
|
| 8 |
export default function WithResBtns({ |
| 9 |
children, |
| 10 |
resRequiredProps, |
| 11 |
label, |
| 12 |
controlName, |
| 13 |
onReset, |
| 14 |
noUnits, |
| 15 |
}) { |
| 16 |
const editorType = window?.betterDocsBlocksHelper?.editorType ?? editorType; |
| 17 |
const { setAttributes, resOption, objAttributes } = resRequiredProps; |
| 18 |
onReset = () => { |
| 19 |
if (noUnits) { |
| 20 |
resOption == "Desktop" |
| 21 |
? setAttributes({ |
| 22 |
[`${controlName}Range`]: |
| 23 |
objAttributes[`${controlName}Range`].default, |
| 24 |
}) |
| 25 |
: ""; |
| 26 |
resOption == "Tablet" |
| 27 |
? setAttributes({ |
| 28 |
[`TAB${controlName}Range`]: |
| 29 |
objAttributes[`TAB${controlName}Range`].default, |
| 30 |
}) |
| 31 |
: ""; |
| 32 |
resOption == "Mobile" |
| 33 |
? setAttributes({ |
| 34 |
[`MOB${controlName}Range`]: |
| 35 |
objAttributes[`MOB${controlName}Range`].default, |
| 36 |
}) |
| 37 |
: ""; |
| 38 |
} else { |
| 39 |
resOption == "Desktop" |
| 40 |
? setAttributes({ |
| 41 |
[`${controlName}Range`]: |
| 42 |
objAttributes[`${controlName}Range`].default, |
| 43 |
[`${controlName}Unit`]: |
| 44 |
objAttributes[`${controlName}Unit`].default || "px", |
| 45 |
}) |
| 46 |
: ""; |
| 47 |
resOption == "Tablet" |
| 48 |
? setAttributes({ |
| 49 |
[`TAB${controlName}Range`]: |
| 50 |
objAttributes[`TAB${controlName}Range`].default, |
| 51 |
[`TAB${controlName}Unit`]: |
| 52 |
objAttributes[`TAB${controlName}Unit`].default || |
| 53 |
"px", |
| 54 |
}) |
| 55 |
: ""; |
| 56 |
resOption == "Mobile" |
| 57 |
? setAttributes({ |
| 58 |
[`MOB${controlName}Range`]: |
| 59 |
objAttributes[`MOB${controlName}Range`].default, |
| 60 |
[`MOB${controlName}Unit`]: |
| 61 |
objAttributes[`MOB${controlName}Unit`].default || |
| 62 |
"px", |
| 63 |
}) |
| 64 |
: ""; |
| 65 |
} |
| 66 |
}; |
| 67 |
return ( |
| 68 |
<div className={`responsive-btn-wrapper`}> |
| 69 |
<div className="responsive-btn"> |
| 70 |
<span className="responsive-btn-label components-base-control__label"> |
| 71 |
{label} |
| 72 |
</span> |
| 73 |
<span |
| 74 |
onClick={() => |
| 75 |
handleDesktopBtnClick({ |
| 76 |
setPreviewDeviceType: |
| 77 |
dispatch(editorType) |
| 78 |
.__experimentalSetPreviewDeviceType, |
| 79 |
setAttributes, |
| 80 |
}) |
| 81 |
} |
| 82 |
className={`typoResButton dashicons dashicons-desktop ${ |
| 83 |
resOption === "Desktop" ? "active" : " " |
| 84 |
}`} |
| 85 |
></span> |
| 86 |
<span |
| 87 |
onClick={() => |
| 88 |
handleTabBtnClick({ |
| 89 |
setPreviewDeviceType: |
| 90 |
dispatch(editorType) |
| 91 |
.__experimentalSetPreviewDeviceType, |
| 92 |
setAttributes, |
| 93 |
}) |
| 94 |
} |
| 95 |
className={`typoResButton dashicons dashicons-tablet ${ |
| 96 |
resOption === "Tablet" ? "active" : " " |
| 97 |
}`} |
| 98 |
></span> |
| 99 |
<span |
| 100 |
onClick={() => |
| 101 |
handleMobileBtnClick({ |
| 102 |
setPreviewDeviceType: |
| 103 |
dispatch(editorType) |
| 104 |
.__experimentalSetPreviewDeviceType, |
| 105 |
setAttributes, |
| 106 |
}) |
| 107 |
} |
| 108 |
className={`typoResButton dashicons dashicons-smartphone ${ |
| 109 |
resOption === "Mobile" ? "active" : " " |
| 110 |
}`} |
| 111 |
></span> |
| 112 |
</div> |
| 113 |
<div className="eb-component-wrapper"> |
| 114 |
{children} |
| 115 |
<button className="eb-range-reset-button" onClick={onReset}> |
| 116 |
<span className="dashicon dashicons dashicons-image-rotate"></span> |
| 117 |
</button> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
); |
| 121 |
} |
| 122 |
|