-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Revisiting Banner's withinContentContainer context #1303
Comments
I like the “principle of predictability” as a general rule, so I’m in favor of moving away from contextual styling. I like the idea of adding a prop, and I don’t expect too much confusion around it. Keeping the internal context-based behavior for now also seems right, because it’s being considerate. With v4 we could choose to deprecate the internal context-based behavior (not sure how we would signal that to users, since it’s not part of any API), and then remove in v5? |
Oh now that is cunning. It feels very possible to keep the context, then do something like: if (this.context.withinContentContainer && !this.props.inContent) {
console.warn('You're rendering a banner within content, please add the inContent prop so things still work when we remove the context to make this work automatically');
} With some particularly complex black-magic fuckery we might even be able to assert that through typings (but that might be a bit adventurous) |
In general I'm opposed to the approach this issue advocates for, and would prefer it remains a variant that is enabled through context. My rationale for that is we want this styling to be consistently applied in the proper context. Allowing a prop to configure it means it could be applied inconsistently as the implementor sees fit. Using context, we know that banners will always have this variant applied in the right context, and never in the wrong context. It's a guarantee (or contract) of consistency.
@BPScott raised the above point, but I don't believe it applies in this case. The component is still responsible for its own styling, and is defining a variant. That variant is just being activated through an alternative means to passing props. Regarding the point of this being challenging to apply due to how context works, and not wanting it to be a part of our public API, I think this problem goes away completely in our move to v4 and the new context API. Providing this context then becomes as trivial as importing a |
I'm happy to say that in V4 we keep the context as a way to render the new style. Allowing consumers to pick and choose when to use the inContent style has the potential to lead to inconsistant styling and makes it possible for mistakes to creep in. Importing a publically available Provider and using that is a lot less hacky than how we currently have to fudge the legacy context. It makes sure styles are applied consistently, while still giving people an escape hatch to use the inContent style if needed. Adding a Provider is enough friction to make people think twice about throwing it in anywhere and potentially using the inContent style in a place it shouldn't be used. Revised answers:
|
We're keeping the current behaviour, and the migration to the modern context has already happened in #902 All that remains is to ensure the context provider is included in our public API |
@BPScott I can polish this tomorrow, are we wanting to export it, or export it and document? |
I think just export it. Documenting it will just make people want to use it and 99% of the time they shouldn't need to |
Hi @BPScott I am not sure whether this is relevant, but currently there is a problem with the Polaris Banner v12.0.0+: It seems that by default, it displays as:
And, the majority of us, would like to see the one, displayed in the official docs:
The https://polaris.shopify.com/components/feedback-indicators/banner |
Hi @charlesr1971 👋 The Banner will display the default styling when it is not inside a When used within a If you need the banner to use the default style, you can do so by rendering it outside components that are using the |
@sam-b-rose Thanks for this information. It might be an idea to add this, to the official Banner docs, at: https://polaris.shopify.com/components/feedback-indicators/banner This thread shows that there is quite a bit of confusion, out there in the Shopify Polaris community: In fact, I managed to work out what was going on, as my last reply, in this thread, proves, but it took a few hours of inspecting CSS etc 😊 However, I feel that I shouldn't have needed to dig this deep, to find the answer. This little paragraph doesn't quite cut the mustard: It might be idea to show an image of both styles of the Banner, with a more detailed description? |
Agreed, there is a lot of text content here which can hide some of the component guidance. I like your suggestion—having images or rendered examples inline with the guidance would be helpful. I can create a new issue to improve this area of the documentation. Thanks @charlesr1971! |
No worries. |
Context
<Banner>
renders differently based upon if it is rendered within a "content container" - a<Card>
or<Modal>
component or not. It does this by consuming a context calledwithinContentContainer
which both<Card>
and<Modal>
set. You can see this in action in Storybook by comparing the "default banner" and "banner in a card" stories.While this is nice as it ensures the correct visual behaviour and "it just works™" in Cards and Modals it does go against the component design tenant of "define variations of components, don't style based on the container your component lives in".
Occasionally there are cases where it is useful to use the "within content" style of a banner not within a Card or Modal, which means that in these cases awkward hacks have to be used to create a context. This also occurs in Web's StoreSwitcher. I'm fairly sure that this will stop working in v4 as we move from the legacy to modern context API.
This then gets more complicated as there are two Card-style components in web that mock out the context too.
Having to rely on creating a context to control the layout of a component feels weird and I don't really like it. Alas I wasn't here when this was originally implemented so I'd love a bit more context on the thinking behind this decision at the time. I think @danrosenthal is the man with the answers I seek.
So here's some questions:
<Banner inContent>
(name up for debate)<Card><Banner/></Card>
and<Card><Banner inContent/></Card>
would render identically.Personal reckons:
Do people have any opinions on the above questions and any thoughts our current implementation or on alternative ways of solving this?
For more context, we started talking about this in slack
The text was updated successfully, but these errors were encountered: