File size: 1,238 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { type CSSProperties, type Ref, forwardRef } from 'react'

export const Fader = forwardRef(function Fader(
  {
    stop,
    blur,
    side,
    style,
    height,
  }: {
    stop?: string
    blur?: string
    height?: number
    side: 'top' | 'bottom' | 'left' | 'right'
    className?: string
    style?: CSSProperties
  },
  ref: Ref<HTMLDivElement>
) {
  return (
    <div
      ref={ref}
      aria-hidden
      data-nextjs-scroll-fader
      className="nextjs-scroll-fader"
      data-side={side}
      style={
        {
          '--stop': stop,
          '--blur': blur,
          '--height': `${height}px`,
          ...style,
        } as React.CSSProperties
      }
    />
  )
})

export const FADER_STYLES = `
  .nextjs-scroll-fader {
    --blur: 1px;
    --stop: 25%;
    --height: 150px;
    --color-bg: var(--color-background-100);
    position: absolute;
    pointer-events: none;
    user-select: none;
    width: 100%;
    height: var(--height);
    left: 0;
    backdrop-filter: blur(var(--blur));

    &[data-side="top"] {
      top: 0;
      background: linear-gradient(to top, transparent, var(--color-bg));
      mask-image: linear-gradient(to bottom, var(--color-bg) var(--stop), transparent);
    }
  }
`