This commit is contained in:
Ray Elliott 2022-07-19 11:13:58 +01:00
parent b6249574b8
commit 393c4a1553
4 changed files with 155 additions and 46 deletions

View File

@ -1,27 +1,26 @@
import { __ } from '@wordpress/i18n'; import { __ } from "@wordpress/i18n";
import { useBlockProps, InnerBlocks, InspectorControls } from '@wordpress/block-editor'; import {
import { useSelect } from '@wordpress/data'; useBlockProps,
import { ColorPicker } from '@wordpress/components'; InnerBlocks,
InspectorControls,
} from "@wordpress/block-editor";
import { useSelect } from "@wordpress/data";
import { ColorPicker } from "@wordpress/components";
import './editor.scss'; import "./editor.scss";
const InnerBlocksWithLimit = ( {clientId, limit=2, ...rest} ) => { const InnerBlocksWithLimit = ({ clientId, limit = 2, ...rest }) => {
const { blockCount } = useSelect(select => ({ const { blockCount } = useSelect((select) => ({
blockCount: select('core/block-editor').getBlockCount(clientId) blockCount: select("core/block-editor").getBlockCount(clientId),
})) }));
const blockAppender = () => { const blockAppender = () => {
return blockCount < limit ? (<InnerBlocks.DefaultBlockAppender />) : false; return blockCount < limit ? <InnerBlocks.DefaultBlockAppender /> : false;
} };
return ( return <InnerBlocks renderAppender={() => blockAppender()} {...rest} />;
<InnerBlocks };
renderAppender={ () => blockAppender() }
{...rest}
/>
)
}
export default function Edit({ attributes, setAttributes, clientId }) { export default function Edit({ attributes, setAttributes, clientId }) {
return ( return (
@ -29,26 +28,21 @@ export default function Edit({ attributes, setAttributes, clientId }) {
<InspectorControls> <InspectorControls>
<ColorPicker <ColorPicker
color={attributes.backgroundColor} color={attributes.backgroundColor}
onChange={(color) => onChange={(color) => setAttributes({ backgroundColor: color })}
setAttributes({backgroundColor: color})
}
enableAlpha enableAlpha
defaultValue="#000" defaultValue="#000"
/> />
</InspectorControls> </InspectorControls>
<li { ...useBlockProps({ <div
className: 'orbital', {...useBlockProps({
style: { style: {
color: attributes.backgroundColor, backgroundColor: attributes.backgroundColor,
} },
}) }> })}
<div className="orbital-content content-center anti-clockwise"> >
<div className="feature"> <InnerBlocksWithLimit orientation="horizontal" clientId={clientId} />
<InnerBlocksWithLimit orientation="horizontal" clientId={clientId} /> </div>
</div>
</div>
</li>
</> </>
); );
} }

View File

@ -8,15 +8,8 @@
display: flex; display: flex;
align-items: center; align-items: center;
list-style: none; list-style: none;
margin-bottom: 16px;
padding: 16px; padding: 16px;
background-color: currentColor;
> .orbital-content {
z-index: 20;
position: relative;
color: #555;
}
.block-editor-inner-blocks > .block-editor-block-list__layout { .block-editor-inner-blocks > .block-editor-block-list__layout {
display: flex; display: flex;

View File

@ -26,13 +26,16 @@ export default function save({ attributes }) {
return ( return (
<li <li
{...useBlockProps.save({ {...useBlockProps.save({
className: "orbital", className: "orbiter",
style: {
color: attributes.backgroundColor,
},
})} })}
> >
<div className="orbital-content content-center anti-clockwise"> <div
className="orbiter-bg"
style={{
backgroundColor: attributes.backgroundColor,
}}
/>
<div className="orbiter-content content-center anti-clockwise">
<div className="feature"> <div className="feature">
<InnerBlocks.Content /> <InnerBlocks.Content />
</div> </div>

View File

@ -6,4 +6,123 @@
*/ */
.wp-block-red-block-red-orbiter { .wp-block-red-block-red-orbiter {
--duration__feature-hover: 0.3s;
--duration__pulse: 1.5s;
.orbiter-bg {
position: absolute;
inset: 0;
border-radius: 50%;
}
.feature {
position: relative;
width: 100%;
height: 100%;
text-align: center;
img {
width: 75%;
height: 75%;
object-fit: contain;
}
& > * {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 0;
transition: opacity var(--duration__feature-hover);
&:nth-child(1) {
opacity: 1;
}
&:nth-child(2) {
opacity: 0;
}
}
&:hover {
& > * {
&:first-child {
opacity: 0;
}
&:last-child {
opacity: 1;
}
}
}
}
}
.wp-block-red-block-red-orbital.pulse {
.orbiter:hover {
> .orbiter-bg {
animation-play-state: paused;
}
}
.orbiter {
> .orbiter-bg {
animation: pulse var(--duration__pulse) alternate ease-in-out infinite
running;
}
&:nth-child(2) > .orbiter-bg {
&::before {
animation-delay: 2s;
}
}
&:nth-child(3) > .orbiter-bg {
&::before {
animation-delay: 0.4s;
}
}
&:nth-child(4) > .orbiter-bg {
&::before {
animation-delay: 1.5s;
}
}
&:nth-child(5) > .orbiter-bg {
&::before {
animation-delay: 0.7s;
}
}
&:nth-child(6) > .orbiter-bg {
&::before {
animation-delay: 0.2s;
}
}
&:nth-child(7) > .orbiter-bg {
&::before {
animation-delay: 1.1s;
}
}
&:nth-child(8) > .orbiter-bg {
&::before {
animation-delay: 0.4s;
}
}
}
}
@keyframes pulse {
from {
transform: scale(1);
}
to {
transform: scale(1.1);
}
} }