-
Notifications
You must be signed in to change notification settings - Fork 30
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
Enable container overrides with CSS custom properties #9441
Conversation
Size Change: -12.6 kB (-2%) Total Size: 696 kB
ℹ️ View Unchanged
|
2b30917
to
edf21e1
Compare
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.
One non-blocking question for my own understanding but otherwise looks great!
c6aaa41
to
d8595db
Compare
There have been significant changes since the review
this enables overriding specific palette values in a container, if there is a special container palette applied to it. It demonstrates usage with `--headline-colour` usage in CardHeadline, which is overridden instead of having the three following values: - text.headline - text.cardHeadline - text.dynamoHeadline
d8595db
to
7f8c960
Compare
|
||
const paletteOverrides = { | ||
'--headline-colour': isDynamo | ||
? text?.dynamoHeadline ?? decidePalette(format).text.dynamoHeadline |
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.
Is the plan still to remove decidePalette at some point?
const paletteOverrides = { | ||
'--headline-colour': isDynamo | ||
? text?.dynamoHeadline ?? decidePalette(format).text.dynamoHeadline | ||
: text?.cardHeadline ?? decidePalette(format).text.cardHeadline, | ||
} satisfies Partial<Record<ColourName, string>>; |
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.
I find this quite tricky to read. I wonder if there's another way we could do this? Maybe bring the logic out into its own function, or create a "fallback" type helper function.
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.
Thanks for flagging! Which part specifically is tricky to read?
A helper function can removed the need for the satisfies Partial<Record<ColourName, string>>
but it cannot do away with the inherent complexity of how to pick the headline colour and its fallbacks.
css={[displayContents]} | ||
style={paletteOverrides} |
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.
Why do we use both css
and style
? Is it because of this?
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.
And also because inline styles have the highest specificity. You can clearly see what the colour override is without even having to look at the resulting CSS declaration generated by Emotion.
declare namespace React { | ||
interface CSSProperties { | ||
// Allow custom properties to be passed to the style prop | ||
[key: `--${string}`]: string | undefined; | ||
} | ||
} |
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.
I can see why it's here 🤔 but I thought we wanted to avoid using the global types file?
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.
I do not think this would work in any other file. It think it’s okay to have things that are truly global in there, such as the React
namespace. Do you have an idea of where it could go otherwise?
--headline-colour is overriden at the CardHeadline level
What does this change?
Create a wrapper component similar to
FormatBoundary
that allows to create container overrides for existing palette colours.Why?
This is a requirement as part of our move to the new palette and progressing with #9110
Screenshots
See Chromatic. There’s a demo of it in the new
CardHeadline
story: