From 46691230c8bcaddc593dc93ac5efc0e13a6f0470 Mon Sep 17 00:00:00 2001 From: "bfintal@gmail.com" <> Date: Wed, 21 Feb 2024 23:44:52 +0800 Subject: [PATCH] feat (inner column block): display name as "Slide" if used as children of carousels or horizontal scrollers --- src/block/column/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/block/column/index.js b/src/block/column/index.js index 337742736..a6b8de70b 100644 --- a/src/block/column/index.js +++ b/src/block/column/index.js @@ -6,6 +6,7 @@ * External dependencies */ import { ColumnIcon } from '~stackable/icons' +import { i18n } from 'stackable' /** * Internal dependencies @@ -20,6 +21,7 @@ import metadata from './block.json' * WordPress dependencies */ import { __ } from '@wordpress/i18n' +import { select } from '@wordpress/data' export const settings = { ...metadata, @@ -38,4 +40,26 @@ export const settings = { deprecated, edit, save, + + __experimentalLabel: ( attributes, { context } ) => { + const customName = attributes?.metadata?.name + if ( context === 'list-view' && customName ) { + return customName + } + + if ( context === 'list-view' && attributes?.uniqueId ) { + const { getEditorDom } = select( 'stackable/editor-dom' ) + const editorDom = getEditorDom() + const isCarouselSlide = editorDom?.querySelector( `.stk-block-carousel__slider > * > * > * > * > [data-block-id="${ attributes.uniqueId }"]` ) + if ( isCarouselSlide ) { + return __( 'Slide', i18n ) + } + const isHorizontalScroller = editorDom?.querySelector( `.stk-block-horizontal-scroller > * > * > * > * > * > [data-block-id="${ attributes.uniqueId }"]` ) + if ( isHorizontalScroller ) { + return __( 'Slide', i18n ) + } + } + + return '' + }, }