|
| 1 | +import Component from '@glimmer/component'; |
| 2 | +import { action } from '@ember/object'; |
| 3 | + |
| 4 | +interface SideHoverPanelArgs { |
| 5 | + side: string; |
| 6 | + stickTo: string; |
| 7 | + width: string; |
| 8 | + height: string; |
| 9 | + disableScrolling: boolean; |
| 10 | + isOverContent: boolean; |
| 11 | + shouldAnimate: boolean; |
| 12 | + backdropAction: () => void; |
| 13 | +} |
| 14 | + |
| 15 | +export default class SideHoverPanel extends Component<SideHoverPanelArgs> { |
| 16 | + hoverPanel: HTMLElement | null = null; |
| 17 | + panelBackdrop: HTMLElement | null = null; |
| 18 | + |
| 19 | + get computedClassNames(): string { |
| 20 | + let classes = ['__side-hover-panel']; |
| 21 | + if (this.args.isOverContent) { |
| 22 | + classes.push('__side-hover-panel--over-content'); |
| 23 | + } |
| 24 | + return classes.join(' '); |
| 25 | + } |
| 26 | + |
| 27 | + get backdropAction(): () => void { |
| 28 | + return this.args.backdropAction; |
| 29 | + } |
| 30 | + |
| 31 | + get side(): string { |
| 32 | + return this.args.side ?? 'right'; |
| 33 | + } |
| 34 | + |
| 35 | + get shouldAnimate(): boolean { |
| 36 | + return this.args.shouldAnimate ?? true; |
| 37 | + } |
| 38 | + |
| 39 | + get width(): string { |
| 40 | + return this.args.width ?? '100%'; |
| 41 | + } |
| 42 | + |
| 43 | + get height(): string { |
| 44 | + return this.args.height ?? '100%'; |
| 45 | + } |
| 46 | + |
| 47 | + get disableScrolling(): boolean { |
| 48 | + return this.args.disableScrolling ?? false; |
| 49 | + } |
| 50 | + |
| 51 | + get stickTo(): string { |
| 52 | + return this.args.stickTo ?? 'right'; |
| 53 | + } |
| 54 | + |
| 55 | + initialize(element: HTMLElement) { |
| 56 | + this.hoverPanel = element.querySelector('.hover-panel')! as HTMLElement; |
| 57 | + this.hoverPanel.classList.add(this.side + '_side'); |
| 58 | + this.hoverPanel.classList.add(this.stickTo + '_align'); |
| 59 | + |
| 60 | + if (this.shouldAnimate) { |
| 61 | + this.hoverPanel.classList.add('animate'); |
| 62 | + } |
| 63 | + |
| 64 | + this.hoverPanel.classList.add(this.side + '_transform'); |
| 65 | + |
| 66 | + if (this.backdropAction != null) { |
| 67 | + this.panelBackdrop = element.querySelector('.panel-backdrop'); |
| 68 | + this.panelBackdrop!.classList.remove('hidden'); |
| 69 | + } |
| 70 | + |
| 71 | + this.hoverPanel.style.width = this.width; |
| 72 | + this.hoverPanel.style.height = this.height; |
| 73 | + |
| 74 | + if (this.disableScrolling) { |
| 75 | + document.querySelector('body')?.classList.add('disable-scrolling'); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + teardown() { |
| 80 | + this.hoverPanel?.remove(); |
| 81 | + this.panelBackdrop?.classList.add('hidden'); |
| 82 | + if (this.disableScrolling) { |
| 83 | + document.querySelector('body')?.classList.remove('disable-scrolling'); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + @action |
| 88 | + backdrop(): void { |
| 89 | + this.args.backdropAction?.(); |
| 90 | + } |
| 91 | +} |
0 commit comments