Skip to content

Commit

Permalink
fix(widgets): convert widget style prop keys from camel to dash case
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerMatteo committed Jul 7, 2024
1 parent 7fa86b4 commit 70b961f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion modules/widgets/src/compass-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export class CompassWidget implements Widget<CompassWidgetProps> {
element.classList.add('deck-widget', 'deck-widget-compass');
if (className) element.classList.add(className);
if (style) {
Object.entries(style).map(([key, value]) => element.style.setProperty(key, value as string));
Object.entries(style).map(([key, value]) =>
element.style.setProperty(
key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
value as string
)
);
}
this.deck = deck;
this.element = element;
Expand Down
13 changes: 10 additions & 3 deletions modules/widgets/src/fullscreen-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class FullscreenWidget implements Widget<FullscreenWidgetProps> {
el.classList.add('deck-widget', 'deck-widget-fullscreen');
if (className) el.classList.add(className);
if (style) {
Object.entries(style).map(([key, value]) => el.style.setProperty(key, value as string));
Object.entries(style).map(([key, value]) =>
el.style.setProperty(key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), value as string)
);
}
this.deck = deck;
this.element = el;
Expand Down Expand Up @@ -99,11 +101,16 @@ export class FullscreenWidget implements Widget<FullscreenWidgetProps> {

if (!deepEqual(oldProps.style, props.style, 1)) {
if (oldProps.style) {
Object.entries(oldProps.style).map(([key]) => el.style.removeProperty(key));
Object.entries(oldProps.style).map(([key]) =>
el.style.removeProperty(key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase())
);
}
if (props.style) {
Object.entries(props.style).map(([key, value]) =>
el.style.setProperty(key, value as string)
el.style.setProperty(
key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
value as string
)
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion modules/widgets/src/zoom-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export class ZoomWidget implements Widget<ZoomWidgetProps> {
element.classList.add('deck-widget', 'deck-widget-zoom');
if (className) element.classList.add(className);
if (style) {
Object.entries(style).map(([key, value]) => element.style.setProperty(key, value as string));
Object.entries(style).map(([key, value]) =>
element.style.setProperty(
key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(),
value as string
)
);
}
const ui = (
<ButtonGroup orientation={this.orientation}>
Expand Down

0 comments on commit 70b961f

Please sign in to comment.