1+ import { Button } from '@openfun/cunningham-react' ;
12import { useRouter } from 'next/router' ;
2- import { useEffect } from 'react' ;
3+ import { useEffect , useState } from 'react' ;
34import { useTranslation } from 'react-i18next' ;
4- import styled , { css } from 'styled-components' ;
55
6- import { useCunninghamTheme } from '@/cunningham' ;
76import { MAIN_LAYOUT_ID } from '@/layouts/conf' ;
87
9- import { Box } from './Box' ;
10-
11- const SkipLink = styled ( Box ) < {
12- $colorsTokens : Record < string , string > ;
13- $spacingsTokens : Record < string , string > ;
14- } > `
15- ${ ( { $colorsTokens, $spacingsTokens } ) => css `
16- position : fixed;
17- top : 0.5rem ;
18- /* Position: padding header + logo(32px) + gap(3xs≈4px) + text "Docs"(≈70px) + 12px */
19- left : calc (
20- ${ $spacingsTokens [ 'base' ] } + 32px + ${ $spacingsTokens [ '3xs' ] } + 70px +
21- 12px
22- );
23- z-index : 9999 ;
24-
25- /* Figma specs - Layout */
26- display : inline-flex;
27- padding : ${ $spacingsTokens [ 'xs' ] } ${ $spacingsTokens [ 'xs' ] } ;
28- flex-direction : column;
29- justify-content : center;
30- align-items : flex-start;
31- gap : ${ $spacingsTokens [ '4xs' ] } ;
32-
33- /* Figma specs - Style */
34- border-radius : ${ $spacingsTokens [ '3xs' ] } ;
35- border : 1px solid
36- var (--c--theme--colors--primary-300 , ${ $colorsTokens [ 'primary-300' ] } );
37- background : var (
38- --c--theme--colors--primary-100 ,
39- ${ $colorsTokens [ 'primary-100' ] }
40- );
41- box-shadow : 0 6px 18px 0 rgba (0 , 0 , 145 , 0.05 );
42-
43- /* Figma specs - Typography */
44- color : ${ $colorsTokens [ 'primary-600' ] } ;
45- font-family : var (--c--theme--font--families--base , 'Marianne Variable' );
46- font-size : 14px ;
47- font-style : normal;
48- font-weight : 500 ;
49- line-height : 18px ;
50-
51- /* Skip link appearance - Fade in/out */
52- text-decoration : none;
53- white-space : nowrap;
54- opacity : 0 ;
55- pointer-events : none;
56- transition : opacity 0.3s ease-in-out;
57-
58- & : focus ,
59- & : focus-visible {
60- opacity : 1 ;
61- pointer-events : auto;
62- outline : 2px solid var (--c--theme--colors--primary-400 );
63- outline-offset : ${ $spacingsTokens [ '4xs' ] } ;
64- }
65-
66- & : focus : not (: focus-visible ) {
67- outline : none;
68- }
69-
70- & : hover {
71- background : var (
72- --c--theme--colors--primary-200 ,
73- ${ $colorsTokens [ 'primary-200' ] }
74- );
75- color : ${ $colorsTokens [ 'primary-700' ] } ;
76- }
77- ` }
78- ` ;
79-
808export const SkipToContent = ( ) => {
819 const { t } = useTranslation ( ) ;
82- const { colorsTokens, spacingsTokens } = useCunninghamTheme ( ) ;
8310 const router = useRouter ( ) ;
11+ const [ isVisible , setIsVisible ] = useState ( false ) ;
8412
8513 // Reset focus after route change so first TAB goes to skip link
8614 useEffect ( ( ) => {
@@ -101,7 +29,7 @@ export const SkipToContent = () => {
10129 } ;
10230 } , [ router . events ] ) ;
10331
104- const handleClick = ( e : React . MouseEvent < HTMLAnchorElement > ) => {
32+ const handleClick = ( e : React . MouseEvent ) => {
10533 e . preventDefault ( ) ;
10634 const mainContent = document . getElementById ( MAIN_LAYOUT_ID ) ;
10735 if ( mainContent ) {
@@ -111,14 +39,25 @@ export const SkipToContent = () => {
11139 } ;
11240
11341 return (
114- < SkipLink
115- as = "a"
42+ < Button
11643 href = { `#${ MAIN_LAYOUT_ID } ` }
11744 onClick = { handleClick }
118- $colorsTokens = { colorsTokens }
119- $spacingsTokens = { spacingsTokens }
45+ color = "tertiary"
46+ onFocus = { ( ) => setIsVisible ( true ) }
47+ onBlur = { ( ) => setIsVisible ( false ) }
48+ style = { {
49+ opacity : isVisible ? 1 : 0 ,
50+ pointerEvents : isVisible ? 'auto' : 'none' ,
51+ transition : 'opacity 0.3s ease-in-out' ,
52+ position : 'fixed' ,
53+ top : 'var(--c--theme--spacings--2xs)' ,
54+ // padding header + logo(32px) + gap(3xs≈4px) + text "Docs"(≈70px) + 12px
55+ left : 'calc(var(--c--theme--spacings--base) + 32px + var(--c--theme--spacings--3xs) + 70px + 12px)' ,
56+ zIndex : 9999 ,
57+ whiteSpace : 'nowrap' ,
58+ } }
12059 >
12160 { t ( 'Go to content' ) }
122- </ SkipLink >
61+ </ Button >
12362 ) ;
12463} ;
0 commit comments