Skip to content

Support the "as" prop to change the wrapper - #614

Merged
bokuweb merged 5 commits into
bokuweb:masterfrom
youknowriad:add/as-prop
May 13, 2020
Merged

bokuweb merged 5 commits into
bokuweb:masterfrom
youknowriad:add/as-prop

Conversation

@youknowriad

Copy link
Copy Markdown
Contributor

In Gutenberg, we have this use-case where we want to control the DOM precisely (to match between the frontend and the editor), and for one of these components we're using Resizable as a wrapper but "div" is not always the right element we want to use there.

We have this particular use-case in a lot of places in our code base and in general we rely on a "as" prop to do so. Other react libraries also use this technique (example Reakit).

I don't know if you're interested by adding the same prop but In this PR I added support for it.

What do you think?

Comment thread src/index.tsx Outdated
) => void | boolean;

export interface ResizableProps {
as: any;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried using string | React.ComponentType instead of any here but I faced a typing issue in the "ref" prop as a consequence and I was not able to solve it otherwise.

@bokuweb bokuweb May 13, 2020 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@youknowriad Thanks for your work :)
Could you please specify HTMLElement name like following.

as: 'div' | 'header' | ...|  React.ComponentType<any>;

This is because we need to ban elements that don't have children (i.e. input)
And please replace HTMLDivElement to HTMLElement

@bokuweb bokuweb May 13, 2020 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If you are ok could you please add story and testcase with as?
And please fix README.md too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, I added a story and a testcase and replaced HTMLDivElement.
I've used string | React.ComponentType<any>; as a type. is that ok? The list of elements can be long :).

Let me know what's missing thanks.

@bokuweb bokuweb left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks :) Looks good

@bokuweb
bokuweb merged commit 698aba1 into bokuweb:master May 13, 2020
@bokuweb

bokuweb commented May 13, 2020

Copy link
Copy Markdown
Owner

@youknowriad v6.4.0 published 🎉

@youknowriad

Copy link
Copy Markdown
Contributor Author

@bokuweb Perfect, thanks for the quick npm release :)

@youknowriad
youknowriad deleted the add/as-prop branch May 14, 2020 09:15
oxyc added a commit to oxyc/gutenberg that referenced this pull request Jun 21, 2020
noisysocks pushed a commit to WordPress/gutenberg that referenced this pull request Jun 22, 2020
* Use light block DOM for the Media & Text block

* Update re-resizable dependency

Specifically to support "as" from bokuweb/re-resizable#614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants