-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(snackbar): allow snackbars to be stacked
fix Lundalogik/crm-feature#3355 fix Lundalogik/crm-feature#3356 Co-authored-by: Kiarokh Moattar <[email protected]>
- Loading branch information
1 parent
f48a332
commit 730c14a
Showing
10 changed files
with
198 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Container to keep track of all snackbar elements that gets added to the page. | ||
* When an element gets added or removed, the container will emit a | ||
* `changeOffset` event on all elements in the container, letting them know | ||
* the new offset to where they should position themselves. | ||
*/ | ||
export class SnackbarContainer { | ||
private snackbarElements: HTMLLimelSnackbarElement[] = []; | ||
|
||
/** | ||
* Add a new element to the container | ||
* | ||
* @param snackbar - element to add | ||
*/ | ||
public add(snackbar: HTMLLimelSnackbarElement) { | ||
const popover = this.getPopover(snackbar); | ||
|
||
// Stencil does not seem to recognise the existance of showPopover | ||
// @ts-ignore | ||
popover?.showPopover(); | ||
|
||
this.snackbarElements = [snackbar, ...this.snackbarElements]; | ||
this.emitOffsets(); | ||
} | ||
|
||
/** | ||
* Remove an element from the container | ||
* | ||
* @param snackbar - element to remove | ||
*/ | ||
public remove(snackbar: HTMLLimelSnackbarElement): void { | ||
const popover = this.getPopover(snackbar); | ||
|
||
// Stencil does not seem to recognise the existance of hidePopover | ||
// @ts-ignore | ||
popover?.hidePopover(); | ||
|
||
this.snackbarElements = this.snackbarElements.filter( | ||
(item) => item !== snackbar, | ||
); | ||
this.emitOffsets(); | ||
} | ||
|
||
private emitOffsets() { | ||
let offset = 0; | ||
this.snackbarElements.forEach((snackbar) => { | ||
snackbar.dispatchEvent( | ||
new CustomEvent('changeOffset', { | ||
detail: offset, | ||
}), | ||
); | ||
offset += this.getPopover(snackbar).getBoundingClientRect().height; | ||
}); | ||
} | ||
|
||
private getPopover(snackbar: HTMLLimelSnackbarElement) { | ||
return snackbar.shadowRoot.querySelector('[popover]'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.