From fb31dcbb8d8d0c61925d344e386b3fa473535689 Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 25 Jul 2022 15:19:11 +0100 Subject: [PATCH] refactor controls to separate component --- src/controls.js | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ src/edit.js | 99 ++++-------------------------------------- 2 files changed, 122 insertions(+), 90 deletions(-) create mode 100644 src/controls.js diff --git a/src/controls.js b/src/controls.js new file mode 100644 index 0000000..b1b2f16 --- /dev/null +++ b/src/controls.js @@ -0,0 +1,113 @@ +import { InspectorControls, MediaPlaceholder } from "@wordpress/block-editor"; +import { __ } from "@wordpress/i18n"; + +import { + __experimentalNumberControl as NumberControl, + Button, + ToggleControl, + Panel, + PanelBody, + PanelRow, +} from "@wordpress/components"; + +export default function Controls({ + attributes, + setAttributes, + innerBlocks, + onCountChange, + isAnimating, + setIsAnimating, +}) { + return ( + +
+ + + + + {__("Orbital count", "red-orbital")} + + + + + + { + setAttributes({ imgUrl: img.url }); + }} + allowedTypes={["image"]} + multiple={false} + mediaPreview={ + attributes.imgUrl !== "" ? ( +
+ + +
+ ) : ( +

No image selected.

+ ) + } + /> +
+ + + + + { + setAttributes({ imgUrlHover: img.url }); + }} + allowedTypes={["image"]} + multiple={false} + mediaPreview={ + attributes.imgUrlHover !== "" ? ( +
+ + +
+ ) : ( +

No image selected.

+ ) + } + /> +
+
+
+ + + + { + setIsAnimating((state) => !state); + }} + /> + + + +
+
+ ); +} diff --git a/src/edit.js b/src/edit.js index ae89ff2..1c2891c 100644 --- a/src/edit.js +++ b/src/edit.js @@ -1,6 +1,5 @@ import { useSelect, dispatch } from "@wordpress/data"; import { useState } from "@wordpress/element"; -import { __ } from "@wordpress/i18n"; import { useBlockProps, InnerBlocks, @@ -19,6 +18,7 @@ import { getSaveElement, createBlock } from "@wordpress/blocks"; import "./editor.scss"; +import Controls from "./controls.js"; import Orbiter from "./orbiter.js"; export default function Edit({ attributes, setAttributes, clientId }) { @@ -98,95 +98,14 @@ export default function Edit({ attributes, setAttributes, clientId }) { return ( <> - -
- - - - - {__("Orbital count", "red-orbital")} - - - - - - { - console.log("onSelect", img); - setAttributes({ imgUrl: img.url }); - }} - allowedTypes={["image"]} - multiple={false} - mediaPreview={ - attributes.imgUrl !== "" ? ( -
- - -
- ) : ( -

No image selected.

- ) - } - /> -
- - - - - - { - console.log("onSelect", img); - setAttributes({ imgUrlHover: img.url }); - }} - allowedTypes={["image"]} - multiple={false} - mediaPreview={ - attributes.imgUrlHover !== "" ? ( -
- - -
- ) : ( -

No image selected.

- ) - } - /> -
-
-
- - - - { - setIsAnimating((state) => !state); - }} - /> - - - -
-
+