Skip to content

Commit

Permalink
feat (inner column block): display name as "Slide" if used as childre…
Browse files Browse the repository at this point in the history
…n of carousels or horizontal scrollers
  • Loading branch information
[email protected] committed Feb 21, 2024
1 parent f15ef35 commit 4669123
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/block/column/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* External dependencies
*/
import { ColumnIcon } from '~stackable/icons'
import { i18n } from 'stackable'

/**
* Internal dependencies
Expand All @@ -20,6 +21,7 @@ import metadata from './block.json'
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n'
import { select } from '@wordpress/data'

export const settings = {
...metadata,
Expand All @@ -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 ''
},
}

0 comments on commit 4669123

Please sign in to comment.