diff --git a/src/blocks/carousel/block.json b/src/blocks/carousel/block.json new file mode 100644 index 000000000..a5e54b265 --- /dev/null +++ b/src/blocks/carousel/block.json @@ -0,0 +1,108 @@ +{ + "name": "carousel", + "category": "newspack", + "apiVersion": 3, + "attributes": { + "className": { + "type": "string", + "default": "" + }, + "imageFit": { + "type": "string", + "default": "cover" + }, + "autoplay": { + "type": "boolean", + "default": false + }, + "delay": { + "type": "number", + "default": 5 + }, + "postsToShow": { + "type": "integer", + "default": 3 + }, + "authors": { + "type": "array" + }, + "categories": { + "type": "array" + }, + "includeSubcategories": { + "type": "boolean", + "default": true + }, + "tags": { + "type": "array" + }, + "customTaxonomies": { + "type": "array" + }, + "showDate": { + "type": "boolean", + "default": true + }, + "showAuthor": { + "type": "boolean", + "default": true + }, + "showAvatar": { + "type": "boolean", + "default": true + }, + "showCaption": { + "type": "boolean", + "default": false + }, + "showCredit": { + "type": "boolean", + "default": false + }, + "showCategory": { + "type": "boolean", + "default": false + }, + "showTitle": { + "type": "boolean", + "default": true + }, + "postType": { + "type": "array", + "default": [ "post" ], + "items": { + "type": "string" + } + }, + "specificMode": { + "type": "boolean", + "default": false + }, + "specificPosts": { + "type": "array", + "default": [], + "items": { + "type": "integer" + } + }, + "slidesPerView": { + "type": "number", + "default": 1 + }, + "hideControls": { + "type": "boolean", + "default": false + }, + "aspectRatio": { + "type": "number", + "default": 0.75 + }, + "includedPostStatuses": { + "type": "array", + "default": [ "publish" ], + "items": { + "type": "string" + } + } + } +} diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index 0a7528249..39a891a31 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -19,7 +19,6 @@ import { Button, ButtonGroup, PanelBody, - PanelRow, Placeholder, RangeControl, Spinner, @@ -362,7 +361,7 @@ class Edit extends Component { - + { postsToShow && ( setAttributes( { customTaxonomies: value } ) } customTaxonomies={ customTaxonomies } specificMode={ specificMode } - onSpecificModeChange={ _specificMode => - setAttributes( { specificMode: _specificMode } ) - } + onSpecificModeChange={ () => setAttributes( { specificMode: true } ) } + onLoopModeChange={ () => setAttributes( { specificMode: false } ) } specificPosts={ specificPosts } onSpecificPostsChange={ _specificPosts => setAttributes( { specificPosts: _specificPosts } ) @@ -393,86 +391,18 @@ class Edit extends Component { /> ) } - - - - - { aspectRatioOptions.map( option => { - const isCurrent = aspectRatio === option.value; - return ( - - ); - } ) } - - - - - - - - - - - + { setAttributes( { hideControls: _hideControls } ); } } /> { setAttributes( { autoplay: _autoplay } ); @@ -480,18 +410,20 @@ class Edit extends Component { /> { autoplay && ( { setAttributes( { delay: _delay } ); } } min={ 1 } max={ 20 } + help={ __( 'Set the waiting time between automatic slide transitions in seconds.', 'newspack-blocks' ) } + __next40pxDefaultSize /> ) } { latestPosts && 1 < latestPosts.length && ( { setAttributes( { slidesPerView: _slidesPerView } ); @@ -502,61 +434,110 @@ class Edit extends Component { ? Math.min( MAX_NUMBER_OF_SLIDES, latestPosts.length ) : Math.min( MAX_NUMBER_OF_SLIDES, maxPosts ) } + help={ __( 'Choose how many slides appear on screen simultaneously.', 'newspack-blocks' ) } + __next40pxDefaultSize /> ) } - - - setAttributes( { showTitle: ! showTitle } ) } - /> - - - setAttributes( { showDate: ! showDate } ) } - /> - - - setAttributes( { showCategory: ! showCategory } ) } - /> - - - setAttributes( { showAuthor: ! showAuthor } ) } - /> - - { showAuthor && ( - - setAttributes( { showAvatar: ! showAvatar } ) } - /> - - ) } - - setAttributes( { showCaption: ! showCaption } ) } - /> - - - setAttributes( { showCredit: ! showCredit } ) } - /> - + + + + { aspectRatioOptions.map( option => { + const isCurrent = aspectRatio === option.value; + return ( + + ); + } ) } + + + + + + + + + setAttributes( { showCaption: ! showCaption } ) } + /> + setAttributes( { showCredit: ! showCredit } ) } + /> + + + setAttributes( { showTitle: ! showTitle } ) } + /> + setAttributes( { showDate: ! showDate } ) } + /> + setAttributes( { showCategory: ! showCategory } ) } + /> + setAttributes( { showAuthor: ! showAuthor } ) } + /> + setAttributes( { showAvatar: ! showAvatar } ) } + disabled={ ! showAuthor } + /> diff --git a/src/blocks/carousel/index.js b/src/blocks/carousel/index.js index 0d3daed73..f45589c80 100644 --- a/src/blocks/carousel/index.js +++ b/src/blocks/carousel/index.js @@ -14,9 +14,13 @@ import edit from './edit'; */ import './view.scss'; import './editor.scss'; +import metadata from './block.json'; +const { name, attributes, category } = metadata; -export const name = 'carousel'; -export const title = __( 'Post Carousel' ); +// Name must be exported separately. +export { name }; + +export const title = __( 'Content Carousel', 'newspack-blocks' ); export const icon = ( @@ -35,107 +39,18 @@ export const settings = { src: icon, foreground: '#36f', }, - category: 'newspack', - keywords: [ __( 'posts' ), __( 'slideshow' ), __( 'carousel' ) ], - description: __( 'A carousel of posts.' ), - attributes: { - className: { - type: 'string', - }, - imageFit: { - type: 'string', - default: 'cover', - }, - autoplay: { - type: 'boolean', - default: false, - }, - delay: { - type: 'number', - default: 5, - }, - postsToShow: { - type: 'integer', - default: 3, - }, - authors: { - type: 'array', - }, - categories: { - type: 'array', - }, - includeSubcategories: { - type: 'boolean', - default: true, - }, - tags: { - type: 'array', - }, - customTaxonomies: { - type: 'array', - }, - showDate: { - type: 'boolean', - default: true, - }, - showAuthor: { - type: 'boolean', - default: true, - }, - showAvatar: { - type: 'boolean', - default: true, - }, - showCaption: { - type: 'boolean', - default: false, - }, - showCredit: { - type: 'boolean', - default: false, - }, - showCategory: { - type: 'boolean', - default: false, - }, - showTitle: { - type: 'boolean', - default: true, - }, - postType: { - type: 'array', - default: [ 'post' ], - items: { - type: 'string', - }, - }, - specificMode: { - type: 'boolean', - default: false, - }, - specificPosts: { - type: 'array', - default: [], - items: { type: 'integer' }, - }, - slidesPerView: { - type: 'number', - default: 1, - }, - hideControls: { - type: 'boolean', - default: false, - }, - aspectRatio: { - type: 'number', - default: 0.75, - }, - includedPostStatuses: { - type: 'array', - default: [ 'publish' ], - items: { type: 'string' }, - }, - }, + attributes, + category, + keywords: [ + __( 'posts', 'newspack-blocks' ), + __( 'articles', 'newspack-blocks' ), + __( 'latest', 'newspack-blocks' ), + __( 'query', 'newspack-blocks' ), + ], + description: __( + 'An advanced block that displays content in a carousel format with customizable parameters and visual configurations.', + 'newspack-blocks' + ), supports: { html: false, align: [ 'center', 'wide', 'full' ],