tidy up settings, add view control
This commit is contained in:
parent
b31320d3f6
commit
45ff8ba411
|
@ -14,5 +14,9 @@
|
||||||
"editorScript": "file:./index.js",
|
"editorScript": "file:./index.js",
|
||||||
"editorStyle": "file:./index.css",
|
"editorStyle": "file:./index.css",
|
||||||
"style": "file:./style-index.css",
|
"style": "file:./style-index.css",
|
||||||
"attributes": {}
|
"attributes": {
|
||||||
|
"count": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
43
src/edit.js
43
src/edit.js
|
@ -6,23 +6,29 @@ import {
|
||||||
InnerBlocks,
|
InnerBlocks,
|
||||||
InspectorControls,
|
InspectorControls,
|
||||||
} from "@wordpress/block-editor";
|
} from "@wordpress/block-editor";
|
||||||
import { __experimentalNumberControl as NumberControl } from "@wordpress/components";
|
import { __experimentalNumberControl as NumberControl, ToggleControl, Panel, PanelBody, PanelRow } from "@wordpress/components";
|
||||||
import { getSaveElement, createBlock } from "@wordpress/blocks";
|
import { getSaveElement, createBlock } from "@wordpress/blocks";
|
||||||
|
|
||||||
import "./editor.scss";
|
import "./editor.scss";
|
||||||
|
|
||||||
import Orbiter from "./orbiter.js";
|
import Orbiter from "./orbiter.js";
|
||||||
|
|
||||||
export default function Edit({ clientId }) {
|
export default function Edit({ attributes, setAttributes, clientId }) {
|
||||||
const { innerBlocks } = useSelect((select) =>
|
const { innerBlocks } = useSelect((select) =>
|
||||||
select("core/block-editor").getBlock(clientId)
|
select("core/block-editor").getBlock(clientId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isNaN(parseInt(attributes.count, 10))) {
|
||||||
|
setAttributes({count: innerBlocks.length});
|
||||||
|
}
|
||||||
|
|
||||||
const [removedBlocks, setRemovedBlocks] = useState([]);
|
const [removedBlocks, setRemovedBlocks] = useState([]);
|
||||||
|
const [isAnimating, setIsAnimating] = useState(false);
|
||||||
|
|
||||||
|
const animatingClass = ' clockwise';
|
||||||
|
|
||||||
const addBlock = () => {
|
const addBlock = () => {
|
||||||
const index = innerBlocks.length - 1;
|
const index = innerBlocks.length - 1;
|
||||||
console.log(index);
|
|
||||||
let block;
|
let block;
|
||||||
|
|
||||||
if (removedBlocks.length > 0) {
|
if (removedBlocks.length > 0) {
|
||||||
|
@ -33,6 +39,7 @@ export default function Edit({ clientId }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch("core/block-editor").insertBlock(block, index, clientId, false);
|
dispatch("core/block-editor").insertBlock(block, index, clientId, false);
|
||||||
|
setAttributes({count: parseInt(attributes.count, 10) + 1});
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeBlock = () => {
|
const removeBlock = () => {
|
||||||
|
@ -44,6 +51,8 @@ export default function Edit({ clientId }) {
|
||||||
const removedBlocksUpdate = removedBlocks;
|
const removedBlocksUpdate = removedBlocks;
|
||||||
removedBlocksUpdate.push(block);
|
removedBlocksUpdate.push(block);
|
||||||
setRemovedBlocks(removedBlocksUpdate);
|
setRemovedBlocks(removedBlocksUpdate);
|
||||||
|
|
||||||
|
setAttributes({count: parseInt(attributes.count, 10) - 1});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCountChange = (value) => {
|
const onCountChange = (value) => {
|
||||||
|
@ -81,20 +90,42 @@ export default function Edit({ clientId }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<InspectorControls>
|
<InspectorControls key="setting">
|
||||||
<div>
|
<div id="red-orbital-controls">
|
||||||
|
<Panel>
|
||||||
|
<PanelBody title="Settings" initialOpen={ true }>
|
||||||
|
<PanelRow>
|
||||||
|
<legend className="blocks-base-control__label">
|
||||||
|
{ __( 'Orbital count', 'red-orbital' ) }
|
||||||
|
</legend>
|
||||||
<NumberControl
|
<NumberControl
|
||||||
value={innerBlocks.length}
|
value={innerBlocks.length}
|
||||||
min={1}
|
min={1}
|
||||||
max={12}
|
max={12}
|
||||||
onChange={onCountChange}
|
onChange={onCountChange}
|
||||||
/>
|
/>
|
||||||
|
</PanelRow>
|
||||||
|
</PanelBody>
|
||||||
|
</Panel>
|
||||||
|
<Panel>
|
||||||
|
<PanelBody title="View Controls" initialOpen={ true }>
|
||||||
|
<PanelRow>
|
||||||
|
<ToggleControl
|
||||||
|
label="Play"
|
||||||
|
checked={ isAnimating }
|
||||||
|
onChange={ () => {
|
||||||
|
setIsAnimating( ( state ) => ! state );
|
||||||
|
} }
|
||||||
|
/>
|
||||||
|
</PanelRow>
|
||||||
|
</PanelBody>
|
||||||
|
</Panel>
|
||||||
</div>
|
</div>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
|
|
||||||
<div {...useBlockProps()}>
|
<div {...useBlockProps()}>
|
||||||
<div className="orbital-view">
|
<div className="orbital-view">
|
||||||
<ul className={`orbiters count-${innerBlocks.length}`}>{viewList}</ul>
|
<ul className={`orbiters count-${innerBlocks.length}${isAnimating ? animatingClass : ''}`}>{viewList}</ul>
|
||||||
|
|
||||||
<div className="inner-content">
|
<div className="inner-content">
|
||||||
<div className="image-hover">
|
<div className="image-hover">
|
||||||
|
|
|
@ -23,14 +23,13 @@ import { useBlockProps, InnerBlocks } from "@wordpress/block-editor";
|
||||||
* @return {WPElement} Element to render.
|
* @return {WPElement} Element to render.
|
||||||
*/
|
*/
|
||||||
export default function save({ attributes }) {
|
export default function save({ attributes }) {
|
||||||
|
|
||||||
const blockProps = useBlockProps.save({
|
const blockProps = useBlockProps.save({
|
||||||
className: "pulse",
|
className: "pulse",
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div {...blockProps}>
|
<div {...blockProps}>
|
||||||
<ul className={`orbiters clockwise`}>
|
<ul className={`orbiters clockwise count-${attributes.count}`}>
|
||||||
<InnerBlocks.Content />
|
<InnerBlocks.Content />
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue