-
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): convert widget style prop keys from camel to dash case #8991
base: master
Are you sure you want to change the base?
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.
result: {property: '--my-var', value: 'red'} | ||
}, | ||
{ | ||
title: 'camelCase property', |
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.
Can you please test the faulty Kebab-case as well? I wonder what our runner will do
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
Closes #8990
Change List
CompassWidget
,ZoomWidget
, andFullscreenWidget
with regex to convert camel cased style keys to their dash cased equivalent.I settled on
replace(/([a-z])([A-Z])/g, '$1-$2')
as the regex replacement (credit) but I'm open to suggestions if there is a better approach.