PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / components / responsive / responsive.js

responsive.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.2, at src/components/responsive/responsive.js

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Button } from "@wordpress/components";
2 import { dispatch } from "@wordpress/data";
3 import "./editor.scss";
4 import { DesktopIcon, MobileIcon, TabletIcon } from "./icon";
5 import { useDeviceType } from "../../controls/controls";
6
7 const Responsive = () => {
8 const Device = (e) => {
9 const canvas = document.getElementsByClassName("edit-site-visual-editor__editor-canvas");
10 if (canvas.length > 0) {
11 dispatch("core/edit-site").__experimentalSetPreviewDeviceType(e.target.closest("button").value);
12 } else {
13 dispatch("core/edit-post").__experimentalSetPreviewDeviceType(e.target.closest("button").value);
14 }
15 };
16
17 const deviceType = useDeviceType();
18
19 const DeviceIcon = () => {
20 if ("Desktop" === deviceType) {
21 return <DesktopIcon />;
22 }
23 if ("Tablet" === deviceType) {
24 return <TabletIcon />;
25 }
26 if ("Mobile" === deviceType) {
27 return <MobileIcon />;
28 }
29 };
30
31 return (
32 <>
33 <div className="sp-smart-post-responsive">
34 <div className="sp-smart-post-units">
35 <span aria-label="Change device preview">
36 <DeviceIcon />
37 </span>
38 <div className="sp-smart-post-units-btn">
39 <Button
40 aria-label="Switch to desktop view"
41 className={deviceType === "Desktop" ? "active" : ""}
42 value={"Desktop"}
43 onClick={Device}
44 >
45 <DesktopIcon />
46 </Button>
47 <Button
48 aria-label="Switch to tablet view"
49 className={deviceType === "Tablet" ? "active" : ""}
50 value={"Tablet"}
51 onClick={Device}
52 >
53 <TabletIcon />
54 </Button>
55 <Button
56 aria-label="Switch to mobile view"
57 className={deviceType === "Mobile" ? "active" : ""}
58 value={"Mobile"}
59 onClick={Device}
60 >
61 <MobileIcon />
62 </Button>
63 </div>
64 </div>
65 </div>
66 </>
67 );
68 };
69
70 export default Responsive;
71