|
1 | 1 | import React from 'react' |
2 | | -import {Box} from '@primer/react' |
| 2 | +import {Box, themeGet} from '@primer/react' |
3 | 3 | import styled from 'styled-components' |
4 | 4 | import Link from './link' |
5 | | -import {SCROLL_MARGIN_TOP} from '../constants' |
| 5 | +import {SCROLL_MARGIN_TOP, SKIP_TO_CONTENT_ID} from '../constants' |
6 | 6 |
|
7 | | -const ID = 'skip-nav' |
8 | | - |
9 | | -const SkipLinkBase = props => ( |
10 | | - <Link |
11 | | - {...props} |
12 | | - href={`#${ID}`} |
13 | | - sx={{ |
14 | | - p: 3, |
15 | | - color: 'fg.onEmphasis', |
16 | | - backgroundColor: 'accent.emphasis', |
17 | | - fontSize: 1, |
18 | | - }} |
19 | | - > |
20 | | - Skip to content |
21 | | - </Link> |
22 | | -) |
| 7 | +export const SkipLink = styled(Link)` |
| 8 | + color: ${themeGet('colors.accent.emphasis')}; |
| 9 | + padding: ${themeGet('space.1')}; |
| 10 | + &:focus { |
| 11 | + text-decoration: underline; |
| 12 | + } |
| 13 | +` |
23 | 14 |
|
24 | 15 | // The following rules are to ensure that the element is visually hidden, unless |
25 | 16 | // it has focus. This is the recommended way to hide content from: |
26 | 17 | // https://webaim.org/techniques/css/invisiblecontent/#techniques |
27 | | -export const SkipLink = styled(SkipLinkBase)` |
| 18 | +export const SkipBox = styled.div` |
| 19 | + display: inline-flex; |
28 | 20 | z-index: 20; |
29 | | - width: auto; |
30 | | - height: auto; |
31 | | - clip: auto; |
32 | | - position: absolute; |
33 | | - overflow: hidden; |
34 | 21 | left: 10px; |
| 22 | + gap: 3px; |
| 23 | + position: absolute; |
| 24 | + transform: translateY(-100%); |
| 25 | + transition: transform 0.3s; |
| 26 | + padding: ${themeGet('space.2')}; |
| 27 | + background-color: ${themeGet('colors.canvas.default')}; |
| 28 | + border: 1px solid ${themeGet('colors.accent.emphasis')}; |
| 29 | + border-top: 0; |
| 30 | + font-size: ${themeGet('fontSizes.1')}; |
| 31 | + border-radius: 0 0 ${themeGet('radii.2')} ${themeGet('radii.2')}; |
| 32 | + |
| 33 | +
|
| 34 | + &:focus-within { |
| 35 | + transform: translateY(0%); |
| 36 | + } |
| 37 | +
|
| 38 | + & > * { |
| 39 | + margin-right: ${themeGet('space.1')}; |
| 40 | + } |
35 | 41 |
|
36 | | - &:not(:focus) { |
37 | | - clip: rect(1px, 1px, 1px, 1px); |
38 | | - clip-path: inset(50%); |
39 | | - height: 1px; |
40 | | - width: 1px; |
41 | | - margin: -1px; |
42 | | - padding: 0; |
| 42 | + & > *:last-child { |
| 43 | + margin-right: 0; |
43 | 44 | } |
44 | 45 | ` |
45 | 46 |
|
46 | | -const SkipNavBase = props => <Box id={ID} {...props} /> |
| 47 | +const SkipNavBase = props => <Box id={SKIP_TO_CONTENT_ID} {...props} /> |
47 | 48 |
|
48 | 49 | export const SkipNav = styled(SkipNavBase)` |
49 | 50 | scroll-margin-top: ${SCROLL_MARGIN_TOP}px; |
|
0 commit comments