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

Tutorial on how to create custom components #257

Open
bph opened this issue May 2, 2024 Discussed in #252 · 4 comments
Open

Tutorial on how to create custom components #257

bph opened this issue May 2, 2024 Discussed in #252 · 4 comments

Comments

@bph
Copy link
Collaborator

bph commented May 2, 2024

Discussed in #252

Originally posted by bph April 23, 2024
In the outreach channel, there was a discussion around this topic:

Jessica Lyschik elaborated:

When creating a custom block, I have some settings defined inside InspectorControls with like toggles, selects, inputs, etc. Now I have to implement a setting that I can't get done with the provided Components, so I'd like to know how to create my own component, preferably in JSX.

Fabian Kägy had some tips:

I tend to start by wrapping my control in the BaseControl

It already gives you all the styles for labels, help text etc. And from there it really is just plain react, and you can do whatever you want.

I’m building components like that here in this package for example: https://github.com/10up/block-components/

This here is a simple one that just exports a light wrapper around another control: https://github.com/10up/block-components/blob/develop/components/color-settings/index.js

But it can also be much more complex like in this example here for an icon picker: https://github.com/10up/block-components/blob/88f68d8df1e3912abf4c976b7c8b8fa72b964a3d/components/icon-picker/icon-picker.js#L68-L91

@fabiankaegy
Copy link
Member

I'm still happy to work on this one if that works for everyone :)

@bph
Copy link
Collaborator Author

bph commented May 2, 2024

Thank you, @fabiankaegy
Fabulous! Here are three links for you

Please let me know how I can assist.

@colorful-tones
Copy link
Member

I would be happy to proof if you need another set of eyes. This looks like a good one. Thanks!

@juanmaguitar
Copy link
Contributor

A nice addition to this post could be how to enhance core components with custom hooks and higher order components (here's an example - see useCharLimit and withCharLimit)
Or maybe this is material for a complementary post (that I'd be happy to write about).

@bph bph moved this from To-do to In Progress in Developer Blog Content Board Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

4 participants