-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components: Add component system context
#30877
Conversation
Size Change: +922 B (0%) Total Size: 1.47 MB
ℹ️ View Unchanged
|
This has limited usage because you can only pass down data/settings through the context for components that the parent component defines. Unless the consuming component will call |
I'm a little confused @gziolo. Maybe there is a misunderstanding of how this works, but the receiving component just has to declare it's name in the Maybe I'm misunderstanding what you're saying though? |
I guess the confusion comes from the fact that you can set the context with the I guess the idea is to use it the way it's done with Storybook stories, where the context is overridden outside of the actual components. This way you can tweak child components to have different props without using prop drilling anti-pattern. My biggest concern is why it's all based on the convention where you provide the name of the components and the key-value pairs for props. In practice, it creates two issues that I'm not sure if they are easy to solve:
|
You can't, that is a downside to this powerful and only rarely-necessary tool. Perhaps we can just restrict the API of a ButtonGroup to only allow the following: <ButtonGroup>
<Button />
<Button />
</ButtonGroup> And then follow the regular pattern of passing props via |
28c4bda
to
e57e799
Compare
Sorry for the pings everybody, I had the wrong base branch on this PR and it requested a ton of people as codeowners due to trunk changes! Sorry!!!!!!! |
@youknowriad @gziolo can I get a re-review on this? Thanks 🙂 After this PR we can start converting existing usages of G2 to use vanilla emotion. |
@@ -1,2 +1,8 @@ | |||
export { ComponentSystemProvider } from './component-system-provider'; | |||
export { withNext } from './with-next'; | |||
export { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New methods aren't exposed outside or @wordpress/components
for now, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! None of these are exposed in components/src/index.js
as that file explicitly only exports ComponentsSystemProvider
and withNext
, both as experimental anyway.
Is there any documentation explaining how it all works? 😄 There are stories that are fine for start but we should be actively thinking how to make those complex APIs approachable for usage outside of Gutenberg. |
I think this one is breaking the build. I just did a fresh update and run
|
Description
Adds the component system
context
.The component system's
context
is a pretty powerful tool. It allows us to safely pass props to children regardless of how far down the component tree they are. For example, if you have aButtonGroup
component and aButton
component, you may want to pass some props to theButton
to get it to render correctly (for example, to get them to render inline with each other).In that case you would create your
ButtonGroup
component the following way:Et viola! Now ever
Button
rendered inside ofButtonGroup
regardless of where in the component tree it lives will receive theinline: true
prop (so long as theButton
also callsuseContextSystem( props, 'Button' )
which connects it to the context.Depends on #30630
How has this been tested?
Unit tests and storybook.
Types of changes
New feature
Checklist:
*.native.js
files for terms that need renaming or removal).