Skip to content

Commit

Permalink
Add ScrollLocker
Browse files Browse the repository at this point in the history
  • Loading branch information
willybrauner committed Aug 30, 2023
1 parent d90fca2 commit 5216a12
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apps/front/src/libs/dom/ScrollLocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { browserOnly } from "@cher-ami/utils"

class ScrollLocker {
isLocked = false
el = browserOnly(() => document.body)

public lock(): void {
if (!this.el) return
this.el.style.overflow = "hidden"
this.isLocked = true
}

public unlock(): void {
if (!this.el) return
this.el.style.overflow = "auto"
this.isLocked = false
}

public set(lock: boolean): void {
if (lock) this.lock()
else this.unlock()
}
}

export default new ScrollLocker()

0 comments on commit 5216a12

Please sign in to comment.