Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: improve calculation of when to hide comments button, to account …
Browse files Browse the repository at this point in the history
…for changes in sidebar style
  • Loading branch information
Raspincel committed Feb 25, 2024
1 parent cade90a commit cef92bd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
47 changes: 36 additions & 11 deletions src/web-components/comments/components/float-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,46 @@ export class CommentsFloatButton extends WebComponentsBaseElement {
if (!floatButton) return;

floatButton.setAttribute('style', this.positionStyles);

const windowSize = window.document.body.getBoundingClientRect().width;
const buttonPosition = floatButton.getBoundingClientRect();
const sideBarWidth = 320;

if (!this.commentsPosition || this.commentsPosition === 'left') {
this.shouldHide = buttonPosition.x < sideBarWidth;
return;
}

this.shouldHide = windowSize - buttonPosition.right < sideBarWidth;
});
}

private calculateIfShouldHide() {
const sidebar = document
.getElementsByTagName('superviz-comments')[0]
?.shadowRoot.querySelector('.superviz-comments');

const floatButton = this.shadowRoot.querySelector('.comments__floating-button');

if (!sidebar || !floatButton) return;

const {
left: sbLeft,
right: sbRight,
top: sbTop,
bottom: sbBottom,
} = sidebar.getBoundingClientRect();
const {
left: fbLeft,
right: fbRight,
top: fbTop,
bottom: fbBottom,
} = floatButton.getBoundingClientRect();

console.log(sbLeft, sbRight, sbTop, sbBottom);
console.log(fbLeft, fbRight, fbTop, fbBottom);

const sidebarHidesTop = sbBottom > fbTop && fbBottom > sbTop;
const sidebarHidesBottom = sbTop < fbBottom && fbTop < sbBottom;
const sidebarHidesLeft = sbRight > fbLeft && fbRight > sbLeft;
const sidebarHidesRight = sbLeft < fbRight && fbLeft < sbRight;

this.shouldHide =
(sidebarHidesBottom || sidebarHidesTop) && (sidebarHidesLeft || sidebarHidesRight);
}

protected render() {
this.calculateIfShouldHide();

const floatButtonClasses = {
'comments__floating-button': true,
'hide-button': !this.isHidden && this.shouldHide,
Expand Down
4 changes: 2 additions & 2 deletions src/web-components/comments/css/comments.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const commentsStyle = css`
position: fixed;
color: rgb(var(--sv-gray-700));
background: rgb(var(--sv-white));
top: 0;
top: 0px;
bottom: 0;
box-shadow: -2px 0 4px 0 rgba(0, 0, 0, 0.1);
height: 100%;
z-index: 99;
z-index: 100;
}
.container-close {
Expand Down
1 change: 1 addition & 0 deletions src/web-components/dropdown/index.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { css } from 'lit';
export const dropdownStyle = css`
.dropdown {
position: relative;
z-index: 100;
}
.dropdown-content {
Expand Down
2 changes: 1 addition & 1 deletion src/web-components/who-is-online/css/dropdown.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const dropdownStyle = css`
position: relative;
display: flex;
flex-direction: column;
z-index: 10;
z-index: 100;
}
.dropdown-list > div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const whoIsOnlineStyle = css`
display: flex;
flex-direction: column;
position: fixed;
z-index: 100;
z-index: 99;
}
.who-is-online__presence-control-message__text {
Expand Down

0 comments on commit cef92bd

Please sign in to comment.