mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 14:54:49 +00:00
* fix: move safe-area padding from body/HTML to navbars. Add script to compute app height dynamically. * fix: Initialize sankey tooltip with top-0 to avoid overflow * fix: add fallback to HTML height * fix: properly set bottom spacing and use position fixed for bottom navbar * fix: move viewport controller initialization
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class extends Controller {
|
|
static targets = ["content", "bottomNav"]
|
|
|
|
connect() {
|
|
this.updateViewport()
|
|
this.updateBottomSpacing()
|
|
|
|
window.addEventListener("resize", this.handleResize)
|
|
window.addEventListener("orientationchange", this.handleResize)
|
|
|
|
if (this.hasBottomNavTarget) {
|
|
this.resizeObserver = new ResizeObserver(() => {
|
|
this.updateBottomSpacing()
|
|
})
|
|
this.resizeObserver.observe(this.bottomNavTarget)
|
|
}
|
|
}
|
|
|
|
disconnect() {
|
|
window.removeEventListener("resize", this.handleResize)
|
|
window.removeEventListener("orientationchange", this.handleResize)
|
|
|
|
if (this.resizeObserver) {
|
|
this.resizeObserver.disconnect()
|
|
}
|
|
}
|
|
|
|
handleResize = () => {
|
|
this.updateViewport()
|
|
this.updateBottomSpacing()
|
|
}
|
|
|
|
updateViewport() {
|
|
const height = window.innerHeight
|
|
document.documentElement.style.setProperty("--app-height", `${height}px`)
|
|
}
|
|
|
|
updateBottomSpacing() {
|
|
if (!this.hasBottomNavTarget || !this.hasContentTarget) return
|
|
|
|
const navHeight = this.bottomNavTarget.offsetHeight
|
|
this.contentTarget.style.paddingBottom = `${navHeight}px`
|
|
}
|
|
}
|