Skip to content

Commit 4669123

Browse files
author
bfintal@gmail.com
committed
feat (inner column block): display name as "Slide" if used as children of carousels or horizontal scrollers
1 parent f15ef35 commit 4669123

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/block/column/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* External dependencies
77
*/
88
import { ColumnIcon } from '~stackable/icons'
9+
import { i18n } from 'stackable'
910

1011
/**
1112
* Internal dependencies
@@ -20,6 +21,7 @@ import metadata from './block.json'
2021
* WordPress dependencies
2122
*/
2223
import { __ } from '@wordpress/i18n'
24+
import { select } from '@wordpress/data'
2325

2426
export const settings = {
2527
...metadata,
@@ -38,4 +40,26 @@ export const settings = {
3840
deprecated,
3941
edit,
4042
save,
43+
44+
__experimentalLabel: ( attributes, { context } ) => {
45+
const customName = attributes?.metadata?.name
46+
if ( context === 'list-view' && customName ) {
47+
return customName
48+
}
49+
50+
if ( context === 'list-view' && attributes?.uniqueId ) {
51+
const { getEditorDom } = select( 'stackable/editor-dom' )
52+
const editorDom = getEditorDom()
53+
const isCarouselSlide = editorDom?.querySelector( `.stk-block-carousel__slider > * > * > * > * > [data-block-id="${ attributes.uniqueId }"]` )
54+
if ( isCarouselSlide ) {
55+
return __( 'Slide', i18n )
56+
}
57+
const isHorizontalScroller = editorDom?.querySelector( `.stk-block-horizontal-scroller > * > * > * > * > * > [data-block-id="${ attributes.uniqueId }"]` )
58+
if ( isHorizontalScroller ) {
59+
return __( 'Slide', i18n )
60+
}
61+
}
62+
63+
return ''
64+
},
4165
}

0 commit comments

Comments
 (0)