Last active
November 30, 2023 12:49
-
-
Save brettsmason/3562e812a78ada2ffc20996673f76938 to your computer and use it in GitHub Desktop.
Registering a variation of the Pulsar carousel block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Register a custom variation within Pulsar. | |
// as this variation will be displaying multiple slides from an innerBlock, that block will be wrapped in the track instead. | |
import domReady from '@wordpress/dom-ready'; | |
import { registerBlockVariation } from '@wordpress/blocks'; | |
domReady(() => { | |
registerBlockVariation('pulsar/carousel', { | |
name: 'carousel-posts', | |
title: 'Posts Carousel', | |
attributes: { | |
templateLock: 'all', | |
hasTrack: false, | |
template: [['pulsar/posts', {}]], | |
}, | |
isActive: ['template'], | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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