Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support adding classes to BlockListBlock in editor.BlockListBlock filter #7405

Closed
oxyc opened this issue Jun 20, 2018 · 5 comments
Closed

Support adding classes to BlockListBlock in editor.BlockListBlock filter #7405

oxyc opened this issue Jun 20, 2018 · 5 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@oxyc
Copy link
Member

oxyc commented Jun 20, 2018

Is your feature request related to a problem? Please describe.

I'm creating a plugin that adds support for background colors to all blocks.

Describe the solution you'd like

It would be useful if there was a separate property for the wrapperClassName where you can extend the list. For example:

		const wrapperClassName = classnames( 'editor-block-list__block', {
			'has-warning': ! isValid || !! error,
			'is-selected': shouldAppearSelected,
			'is-multi-selected': isMultiSelected,
			'is-hovered': isHovered && ! isEmptyDefaultBlock,
			'is-shared': isSharedBlock( blockType ),
			'is-hidden': dragging,
			'is-typing': isTypingWithinBlock,
                        [ this.props.wrapperClassName ]: !! this.props.wrapperClassName,
		} );

Describe alternatives you've considered

At the moment the only way is to apply classes is to override className through wrapperProps but then you need redefine all the above classes making it very unstable.

What I currently opt for is providing the classes data-* attributes like align does but that means that themes need additional styling rather than just has-*-background-color.

@gziolo gziolo added [Feature] Extensibility The ability to extend blocks or the editing experience [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Jun 20, 2018
@gziolo gziolo added this to To do in Extensibility via automation Jun 20, 2018
@2one2
Copy link

2one2 commented Jul 10, 2018

I agree, styling with data attributes is not the best approach.

My proposed solution:

wrapperClassName

const editWrapperClassNames = blockType.getEditWrapperClassNames( block.attributes ) || '';

const wrapperClassName = classnames( 'editor-block-list__block', {
	'has-warning': ! isValid || !! error,
	'is-selected': shouldAppearSelected,
	'is-multi-selected': isPartOfMultiSelection,
	'is-hovered': isHovered && ! isEmptyDefaultBlock,
	'is-shared': isSharedBlock( blockType ),
	'is-hidden': dragging,
	'is-typing': isTypingWithinBlock,
        editWrapperClassNames,
} );

Block Configuration

getEditWrapperClassNames( attributes ) {
	const { color } = attributes;
	if ( 'light' === color ) {
		return [ 'color-light', 'background-dark' ];
	} else {
		return 'color-dark';
	}
},

@chrisvanpatten
Copy link
Member

@aduth also proposed another idea which I really like in this comment: #7841 (comment)

@youknowriad
Copy link
Contributor

The BlockListBlock supports a className prop now, so this is possible now. Thanks.

Extensibility automation moved this from To Do to Done Nov 27, 2018
@mahdiyazdani
Copy link
Contributor

@youknowriad Would you mind clarifying in which version className prop has been added?

@youknowriad
Copy link
Contributor

I can't tell for sure, as it proved to be hard to navigate the history of that file but i can see that it's there for more than 6 months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
No open projects
Extensibility
  
Done
Development

No branches or pull requests

6 participants