Skip to content

Commit

Permalink
chore(widgets) cleanup widget constructors (#9312)
Browse files Browse the repository at this point in the history
* chore(widgets) copy props and use nullish coalescing operator
  • Loading branch information
chrisgervang authored Dec 22, 2024
1 parent 17ab465 commit 7a23912
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
19 changes: 11 additions & 8 deletions modules/widgets/src/compass-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ export class CompassWidget implements Widget<CompassWidgetProps> {
element?: HTMLDivElement;

constructor(props: CompassWidgetProps) {
this.id = props.id || 'compass';
this.viewId = props.viewId || null;
this.placement = props.placement || 'top-left';
props.transitionDuration = props.transitionDuration || 200;
props.label = props.label || 'Compass';
props.style = props.style || {};
this.props = props;
this.id = props.id ?? this.id;
this.viewId = props.viewId ?? this.viewId;
this.placement = props.placement ?? this.placement;

this.props = {
...props,
transitionDuration: props.transitionDuration ?? 200,
label: props.label ?? 'Reset Compass',
style: props.style ?? {}
};
}

setProps(props: Partial<CompassWidgetProps>) {
Expand Down Expand Up @@ -125,7 +128,7 @@ export class CompassWidget implements Widget<CompassWidgetProps> {
this.handleCompassReset(viewport);
}
}}
label={this.props.label}
title={this.props.label}
style={{transform: `rotateX(${rx}deg)`}}
>
<svg fill="none" width="100%" height="100%" viewBox="0 0 26 26">
Expand Down
15 changes: 9 additions & 6 deletions modules/widgets/src/fullscreen-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ export class FullscreenWidget implements Widget<FullscreenWidgetProps> {
fullscreen: boolean = false;

constructor(props: FullscreenWidgetProps) {
this.id = props.id || 'fullscreen';
this.placement = props.placement || 'top-left';
props.enterLabel = props.enterLabel || 'Enter Fullscreen';
props.exitLabel = props.exitLabel || 'Exit Fullscreen';
props.style = props.style || {};
this.props = props;
this.id = props.id ?? this.id;
this.placement = props.placement ?? this.placement;

this.props = {
...props,
enterLabel: props.enterLabel ?? 'Enter Fullscreen',
exitLabel: props.exitLabel ?? 'Exit Fullscreen',
style: props.style ?? {}
};
}

onAdd({deck}: {deck: Deck<any>}): HTMLDivElement {
Expand Down
21 changes: 12 additions & 9 deletions modules/widgets/src/zoom-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ export class ZoomWidget implements Widget<ZoomWidgetProps> {
element?: HTMLDivElement;

constructor(props: ZoomWidgetProps) {
this.id = props.id || 'zoom';
this.viewId = props.viewId || null;
this.placement = props.placement || 'top-left';
props.orientation = props.orientation || 'vertical';
props.transitionDuration = props.transitionDuration || 200;
props.zoomInLabel = props.zoomInLabel || 'Zoom In';
props.zoomOutLabel = props.zoomOutLabel || 'Zoom Out';
props.style = props.style || {};
this.props = props;
this.id = props.id ?? this.id;
this.viewId = props.viewId ?? this.viewId;
this.placement = props.placement ?? this.placement;

this.props = {
...props,
orientation: props.orientation ?? 'vertical',
transitionDuration: props.transitionDuration ?? 200,
zoomInLabel: props.zoomInLabel ?? 'Zoom In',
zoomOutLabel: props.zoomOutLabel ?? 'Zoom Out',
style: props.style ?? {}
};
}

onAdd({deck}: {deck: Deck<any>}): HTMLDivElement {
Expand Down

0 comments on commit 7a23912

Please sign in to comment.