-
Notifications
You must be signed in to change notification settings - Fork 863
[CSS-in-JS] Simplify shadow parameters #5892
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
Conversation
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5892/ |
| export const euiBottomBarStyles = (_euiTheme: UseEuiTheme) => { | ||
| const { euiTheme } = _euiTheme; |
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.
This distinction feels somewhat confusing to me and I wish we were a bit more consistent on whether we pass the entire returned context or just euiTheme between various helpers (e.g., the typography fns all pass euiTheme.euiTheme and not the parent context, but this is also because basically every single .styles.ts file deconstructs { euiTheme } automatically in its params).
I also wish we had a clearer naming convention for the context vs the actual theme data so that we don't end up essentially deconstructing _euiTheme.euiTheme 🙈 Maybe themeContext.euiTheme instead?...
@thompsongl, any thoughts here?
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.
Agreed with all those points. I wonder if it's just easiest to say, any mixin/function should accept the entirety of UseEuiTheme whether they only need the .euiTheme portion or not? It keeps them scalable in case of future needs to grab the colorMode.
As for naming we could just change to also ensure we're naming it as lowercase useEuiTheme so that it is clear.
| export const euiBottomBarStyles = (_euiTheme: UseEuiTheme) => { | |
| const { euiTheme } = _euiTheme; | |
| export const euiBottomBarStyles = (useEuiTheme: UseEuiTheme) => { | |
| const { euiTheme } = useEuiTheme; |
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.
Yeah I had mixins passing the full result of useEuiTheme originally. The cases where mixins needed colorMode were scarce so I went the other way. But I'd rather see consistency like you've suggested if working with the current mixin shape is difficult.
We should update all mixins and the createStyleHookFromMixin util with the new pattern.
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.
++
Also I just realized we could simplify the code portion a bit too by deconstructing in the parameters.
| export const euiBottomBarStyles = (_euiTheme: UseEuiTheme) => { | |
| const { euiTheme } = _euiTheme; | |
| export const euiBottomBarStyles = ({ euiTheme }: UseEuiTheme) => { | |
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 pushed a commit based on those latest comments. But I didn't touch the util (that one still confuses me a bit)
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 😸
😄 But are you ok if I do it and add a bunch to this PR?
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.
Or if you want to merge this I can do a follow up. Up to you!
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.
Yes, go for it. I'm out for the rest of the week.
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.
Hmm not sure I can make a generic function that works with mixins that do have required args and mixins that do not have required args.
const euiMixin(
euiTheme: UseEuiTheme;
required: PropertyThatIsRequired;
optional?: {
optionalKey1?: something;
optionalKey2?: something;
}
) => {}
vs
const euiMixin(
euiTheme: UseEuiTheme;
optional?: {
optionalKey1?: something;
optionalKey2?: something;
}
) => {}
So a couple options:
- Only have the former and you're required to pass an empty arg when no properties are required:
euiScrollBarStyles(euiThemeContext, {}, {size: 20}); - Move the required args and optional args into a single object:
const euiMixin(
euiTheme: UseEuiTheme;
options: {
requiredKey1: something;
optionalKey1?: something;
optionalKey2?: something;
}
) => {}
- Create a second version of
createStyleHookFromMixinso we have one with required args and one without - Scrap
createStyleHookFromMixinentirely and manually create hooks. (We lose the type safety/consistency that it adds to mixins; we have to just be consistent when creating new mixins).
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.
Honestly I think my (opinionated) vote goes to
Scrap createStyleHookFromMixin entirely and manually create hooks. (We lose the type safety/consistency that it adds to mixins; we have to just be consistent when creating new mixins).
I haven't used this helper personally despite having created a few mixins and I don't super see the need for it. 🤔 It's not really that tedious to manually write a 5-line hook next to a mixin.
If we do strongly want the helper still, then my next vote goes to Move the required args and optional args into a single object
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5892/ |
01812c5 to
3e8d27c
Compare
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5892/ |
Co-authored-by: Constance <[email protected]>
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5892/ |
|
Ok I've decided not to push anything to this branch and instead have a follow-up/parallel PR that removes the util and changes all the other mixins. We have a couple different patterns going that need to switch to the new style. |
cee-chen
left a comment
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.
PR looks good to me as-is!
|
Cool beans, I'll merge after CI |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5892/ |
Based on a comment I made in #5891 :
I've converted the shadow mixins to use this pattern. I think it simplifies them a lot.
I'm not considering this a breaking change since we just released these and under the Beta flag.
Checklist
[ ] Checked in mobile[ ] Props have proper autodocs and playground toggles[ ] Added documentation[ ] Checked Code Sandbox works for any docs examples[ ] Added or updated jest and cypress tests[ ] Checked for breaking changes and labeled appropriately[ ] Checked for accessibility including keyboard-only and screenreader modes[ ] Updated the Figma library counterpart