Skip to content

Commit

Permalink
fix(FloatingUI): use object spread instead of Object.assign() (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgonzalezr committed Aug 18, 2023
1 parent ab965b4 commit 4991a74
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
110 changes: 55 additions & 55 deletions packages/bee-q/src/services/libraries/floating-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ export class FloatingUI {
constructor(trigger: HTMLElement, panel: HTMLElement, options?: FloatingUIOptions) {
this.trigger = trigger;
this.panel = panel;
this.options = Object.assign(
{
distance: options?.distance || 20,
placement: options?.placement || 'bottom',
strategy: options?.distance || 'fixed',
sameWidth: options?.sameWidth || false,
},
options,
);
this.options = {
distance: 20,
placement: 'bottom',
strategy: 'fixed',
sameWidth: false,
...options,
};
this.init(options);
}

Expand All @@ -29,57 +27,59 @@ export class FloatingUI {
}

update() {
this.cleanUp = autoUpdate(this.trigger, this.panel, async () => {
const { x, y, placement, middlewareData } = await computePosition(this.trigger, this.panel, {
placement: this.options.placement,
strategy: this.options.strategy,
middleware: [
offset({ mainAxis: this.options.distance, crossAxis: this.options.skidding }),
flip(),
shift(),
size(
this.options.sameWidth && {
apply({ rects, elements }) {
Object.assign(elements.floating.style, {
width: `${rects.reference.width}px`,
});
this.cleanUp = autoUpdate(this.trigger, this.panel, () => {
(async () => {
const { x, y, placement, middlewareData } = await computePosition(this.trigger, this.panel, {
placement: this.options.placement,
strategy: this.options.strategy,
middleware: [
offset({ mainAxis: this.options.distance, crossAxis: this.options.skidding }),
flip(),
shift(),
size(
this.options.sameWidth && {
apply({ rects, elements }) {
Object.assign(elements.floating.style, {
width: `${rects.reference.width}px`,
});
},
},
},
),
arrow({ element: this.options.arrow || null }),
this.positionChange(),
hide(),
],
});
),
arrow({ element: this.options.arrow || null }),
this.positionChange(),
hide(),
],
});

Object.assign(this.panel.style, {
top: '0',
left: '0',
transform: `translate(${this.roundByDPR(x)}px,${this.roundByDPR(y)}px)`,
});
Object.assign(this.panel.style, {
top: '0',
left: '0',
transform: `translate(${this.roundByDPR(x)}px,${this.roundByDPR(y)}px)`,
});

if (this.options.arrow) {
const { x: arrowX, y: arrowY } = middlewareData.arrow;
const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[placement.split('-')[0]];
if (this.options.arrow) {
const { x: arrowX, y: arrowY } = middlewareData.arrow;
const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[placement.split('-')[0]];

Object.assign(this.options.arrow.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: '-4px',
});
}
Object.assign(this.options.arrow.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: '-4px',
});
}

const { referenceHidden } = middlewareData.hide;
Object.assign(this.panel.style, {
visibility: referenceHidden ? 'hidden' : 'visible',
});
const { referenceHidden } = middlewareData.hide;
Object.assign(this.panel.style, {
visibility: referenceHidden ? 'hidden' : 'visible',
});
})();
});
}

Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sonar.organization=endava
sonar.projectKey=Endava_bee-q

sonar.cpd.exclusions=packages/bee-q/src/components/,packages/bee-q/src/shared/**/__test__/**/*,config/
sonar.exclusions=config/
sonar.cpd.exclusions=config/**/*,packages/bee-q/src/components/**/*,packages/bee-q/src/shared/**/__test__/**/*
sonar.exclusions=config/**/*
sonar.test.inclusions=**/*.spec.*
sonar.testExecutionReportPaths=packages/bee-q/test-report.xml
sonar.javascript.lcov.reportPaths=packages/bee-q/coverage/lcov.info

0 comments on commit 4991a74

Please sign in to comment.