Skip to content

Conversation

@ajitbohra
Copy link
Member

With #10651 custom block categories can have a custom icon.

This PR adds the same to docs https://wordpress.org/gutenberg/handbook/extensibility/extending-blocks/#managing-block-categories

cc: @tyxla

@ajitbohra ajitbohra added the [Type] Developer Documentation Documentation for developers label Oct 29, 2018
Copy link
Contributor

@chrisvanpatten chrisvanpatten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small suggestions :)

Copy link
Contributor

@chrisvanpatten chrisvanpatten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving but also it'd be great to get width/height attributes in as per my comment.

'slug' => 'my-category',
'title' => __( 'My category', 'my-plugin' ),
'icon' => 'screenoptions',
'icon' => '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="none" d="M0 0h24v24H0V0z" /><path d="M19 13H5v-2h14v2z" /></svg>',
Copy link
Contributor

@chrisvanpatten chrisvanpatten Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing, but we also want to encourage block devs to include width and height attributes.

Copy link
Member Author

@ajitbohra ajitbohra Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icon component is used to render proper icons and currently, it enforces default width for dashicons and svg icons. Let me know if should add the width/height to the example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a default width that works I think this is fine.

add_filter( 'block_categories', 'my_plugin_block_categories', 10, 2 );
```

You can also display an icon with your block category by setting an `icon` attribute. The value can be the slug of a [WordPress Dashicon](https://developer.wordpress.org/resource/dashicons/), or a custom `svg` element.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, components and functions are supported as well - you can refer to https://github.com/wordpress/gutenberg/blob/729fa981795ba1ca90c90eccff6b8e6da38d19f9/packages/components/src/icon/README.md for details, or maybe link to it here in the docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to link to Icon component for all available options. I guess the same is applicable for block icon also as we are using the same icon component.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are PHP docs though, so referencing a component or function isn't really applicable. I think this README is fine.

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

@ajitbohra ajitbohra merged commit 0620892 into master Nov 1, 2018
@ajitbohra ajitbohra deleted the update/docs-custom-categories branch November 1, 2018 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants