-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(widgets): widget style prop keys should accept camelCase css properties and dashed css variables #8991
fix(widgets): widget style prop keys should accept camelCase css properties and dashed css variables #8991
Conversation
b9bd9a3
to
d505e3f
Compare
@chrisgervang if I remember right, we used to use Alternatively we could just do this the dirty way by calling both of the above... |
@Pessimistress, that's correct, but I didn't account for camelCase styles. It's probably best to have a solution that supports at least variables and camelCase, or all three (even if kebab-case isn't popular). I think there are three solutions to consider.
if (property.startsWith('--')) {
// Assume CSS variable
element.style.setProperty(property, value);
} else {
// Assume camelCase
element.style[property] = value;
}
if (property.startsWith('--')) {
// Assume CSS variable
element.style.setProperty(property, value);
} else if (property.includes('-')) {
// Convert kebab-case to camelCase
const camelCaseProperty = property.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
element.style[camelCaseProperty] = value;
} else {
// Assume camelCase
element.style[property] = value;
} I've uploaded them into a gist for easy testing. While |
d505e3f
to
70b961f
Compare
@chrisgervang sounds reasonable to me - I hadn't considered css variables. Shall I go ahead and update my branch to implement solution 1? |
Yes, thank you! Could you also please take a look at the |
It might be easier to create a shared function |
9e75fc8
to
456d1eb
Compare
@chrisgervang I made that change and created a shared |
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.
Great progress! Left some comments. @Pessimistress would be the one to make a call on whether she wants these utility functions in core or not. I think we could consider whether or not it'd be useful to use the Deck class too.
Object.entries(oldProps.style).map(([key]) => { | ||
if (key.startsWith('--')) { | ||
// Assume CSS variable | ||
el.style.removeProperty(key); | ||
} else { | ||
// Assume camelCase | ||
el.style[key] = ''; | ||
} | ||
}); |
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.
Let's create a removeStyles as well. This seems useful to apply in all widgets when style has changed
…erties and dashed css variables (#8991) * fix(widgets): handle css variable and camel cased keys passed to widget style prop --------- Co-authored-by: Chris Gervang <[email protected]>
Closes #8990
Change List
style
prop onCompassWidget
,ZoomWidget
, andFullscreenWidget
to support camelCase CSS properties (e.g.backgroundColor
) and kabab-case CSS variables (e.g.--button-size
).