Skip to content

Commit 7151201

Browse files
committed
feat(props): renamed offset to top and bottom
BREAKING CHANGE: removed shim and offset props, now using: offset(Top|Bottom) for atTop and atBottom detection.
1 parent e7cf3a7 commit 7151201

File tree

3 files changed

+191
-117
lines changed

3 files changed

+191
-117
lines changed

src/lib/headroom/index.svelte

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
55
export let duration = '300ms'
66
export let easing = 'linear'
7-
export let offset = 0
8-
export let toleranceScroll = 0
9-
export let toleranceTop = 2
10-
export let toleranceBottom = 2
7+
export let offsetTop = 2
8+
export let offsetBottom = 2
9+
export let tolerance = 0
1110
export let bottom = false
1211
export let hideAtBottom = false
1312
export let hideAtTop = false
@@ -21,8 +20,8 @@
2120
let atTop = true
2221
let atBottom = false
2322
let style = `--duration:${duration}; --easing:${easing};`
24-
25-
validate({ duration, easing, offset, toleranceScroll, toleranceTop, toleranceBottom })
23+
24+
validate({ duration, easing, tolerance, offsetTop, offsetBottom })
2625
2726
const dispatch = createEventDispatcher()
2827
@@ -35,8 +34,8 @@
3534
})
3635
3736
function deriveClass(y = 0, scrolled = 0) {
38-
if (y < offset) return 'pin'
39-
if (!scrolled || Math.abs(scrolled) < toleranceScroll) return headerClass
37+
if (y < offsetTop) return 'pin'
38+
if (!scrolled || Math.abs(scrolled) < tolerance) return headerClass
4039
const dir = scrolled < 0 ? 'down' : 'up'
4140
if (dir === 'up') return 'pin'
4241
if (dir === 'down') return 'unpin'
@@ -52,8 +51,8 @@
5251
5352
$: {
5453
headerClass = updateClass(y)
55-
atTop = y <= toleranceTop
56-
atBottom = win && win.innerHeight + win.pageYOffset >= document.body.offsetHeight - toleranceBottom
54+
atTop = y <= offsetTop
55+
atBottom = win && win.innerHeight + win.pageYOffset >= document.body.offsetHeight - offsetBottom
5756
if (headerClass !== lastHeaderClass) {
5857
dispatch(headerClass)
5958
}

src/lib/headroom/validation.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const timingFunctions = [
99
'cubic-bezier()'
1010
]
1111

12-
export default function validate({ duration, easing, offset, toleranceScroll, toleranceTop, toleranceBottom }) {
13-
if (typeof offset !== "number")
14-
warn("The `offset` prop is not a number: ", offset)
15-
if (typeof toleranceScroll !== "number")
16-
warn("The `toleranceScroll` prop is not a number: ", toleranceScroll)
17-
if (typeof toleranceTop !== "number")
18-
warn("The `toleranceTop` prop is not a number: ", toleranceTop)
19-
if (typeof toleranceBottom !== "number")
20-
warn("The `toleranceBottom` prop is not a number: ", toleranceBottom)
12+
export default function validate({ duration, easing, tolerance, offsetTop, offsetBottom }) {
13+
// if (typeof offset !== "number")
14+
// warn("The `offset` prop is not a number: ", offset)
15+
if (typeof tolerance !== "number")
16+
warn("The `tolerance` prop is not a number: ", tolerance)
17+
if (typeof offsetTop !== "number")
18+
warn("The `offsetTop` prop is not a number: ", offsetTop)
19+
if (typeof offsetBottom !== "number")
20+
warn("The `offsetBottom` prop is not a number: ", offsetBottom)
2121
if (typeof duration !== "string")
2222
warn("The `duration` prop is not a string such as '200ms': ", duration)
2323
if (typeof easing !== "string" || ! timingFunctions.includes(easing) && ! easing.startsWith('cubic-bezier('))

0 commit comments

Comments
 (0)