Skip to content

Instantly share code, notes, and snippets.

@brettsmason
Last active November 30, 2023 12:49
Show Gist options
  • Save brettsmason/3562e812a78ada2ffc20996673f76938 to your computer and use it in GitHub Desktop.
Save brettsmason/3562e812a78ada2ffc20996673f76938 to your computer and use it in GitHub Desktop.
Registering a variation of the Pulsar carousel block
// block.json example for our custom child block.
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "pulsar/posts",
"parent": ["pulsar/carousel"],
"version": "0.1.0",
"title": "Posts",
"category": "text",
"icon": "universal-access-alt",
"textdomain": "pulsar",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"render": "file:./render.php"
}
// Barebones example of the pulsar/posts child block edit function.
// Markup must include `splide__track` and `splide__list`.
import { useBlockProps } from '@wordpress/block-editor';
/**
* The edit function describes the structure of your block in the context of the
* editor. This represents what the editor will render when the block is used.
*
* @return {WPElement} Element to render.
*/
export default function Edit() {
const blockProps = useBlockProps({ className: 'splide__track' });
return (
<div {...blockProps}>
<ul className="splide__list">
<li className="splide__slide">1</li>
<li className="splide__slide">2</li>
<li className="splide__slide">3</li>
<li className="splide__slide">4</li>
<li className="splide__slide">5</li>
<li className="splide__slide">6</li>
</ul>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment