File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import DraftModeToast from '@/sections/DraftMode/DraftModeToast'
1616import { routing } from '../../i18n/routing'
1717import { GoogleTagManagerHead } from './GTMHead'
1818import { SiteImprove } from './SiteImprove'
19+ import GoToTopButton from '@/sections/GoToTopButton'
1920
2021const equinorRegular = localFont ( {
2122 src : '../fonts/equinor/Equinor-Regular.woff' ,
@@ -69,6 +70,7 @@ export default async function LocaleLayout({
6970 < body >
7071 < Toaster />
7172 { isDraftMode && < DraftModeToast /> }
73+ < GoToTopButton />
7274 { /* <SanityLive onError={handleError} /> */ }
7375 < NextIntlClientProvider >
7476 < PageProvider
Original file line number Diff line number Diff line change 1+ import { arrow_up } from '@equinor/eds-icons'
2+ import { forwardRef , type Ref , type SVGProps } from 'react'
3+ import { TransformableIcon } from './TransformableIcon'
4+
5+ export type ArrowUpProps = {
6+ /** Size, use if you need large icon resolutions
7+ * @default 24
8+ */
9+ size ?: 16 | 18 | 24 | 32 | 40 | 48
10+ /** @ignore */
11+ ref ?: Ref < SVGSVGElement >
12+ } & SVGProps < SVGSVGElement >
13+
14+ export const ArrowUp = forwardRef < SVGSVGElement , ArrowUpProps > (
15+ function ArrowUp ( { ...rest } , ref ) {
16+ return < TransformableIcon iconData = { arrow_up } { ...rest } ref = { ref } />
17+ } ,
18+ )
19+ export default ArrowUp
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ export { default as Linkedin } from './Linkedin'
44export { default as Twitter } from './Twitter'
55export { default as Youtube } from './Youtube'
66export { default as ArrowRight } from './ArrowRight'
7+ export { default as ArrowUp } from './ArrowUp'
78export { default as Play } from './Play'
89export { default as Pause } from './Pause'
910export { default as QuoteSymbol } from './QuoteSymbol'
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useEffect , useState } from 'react'
4+ import ArrowUp from '@/icons/ArrowUp'
5+
6+ export default function GoToTopButton ( ) {
7+ const [ isVisible , setIsVisible ] = useState ( false )
8+
9+ // Show button when page is scrolled down
10+ const toggleVisibility = ( ) => {
11+ if ( typeof window !== 'undefined' ) {
12+ setIsVisible ( window . scrollY > window . innerHeight )
13+ }
14+ }
15+
16+ // Scroll to top smoothly
17+ const scrollToTop = ( ) => {
18+ if ( typeof window !== 'undefined' ) {
19+ window . scrollTo ( {
20+ top : 0 ,
21+ behavior : 'smooth' ,
22+ } )
23+ }
24+ }
25+
26+ useEffect ( ( ) => {
27+ window . addEventListener ( 'scroll' , toggleVisibility )
28+ return ( ) => {
29+ window . removeEventListener ( 'scroll' , toggleVisibility )
30+ }
31+ } , [ ] )
32+
33+ return (
34+ < >
35+ { isVisible && (
36+ < button
37+ onClick = { scrollToTop }
38+ aria-label = "Go to top"
39+ className = "fixed bottom-8 right-8 z-40 p-3 rounded-full bg-slate-blue-95 text-white shadow-lg hover:shadow-xl transition-all duration-300 cursor-pointer"
40+ >
41+ < ArrowUp size = { 24 } />
42+ </ button >
43+ ) }
44+ </ >
45+ )
46+ }
You can’t perform that action at this time.
0 commit comments