Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 460057c

Browse files
feat(skip-nav): create skip nav components and story
1 parent f4e9f00 commit 460057c

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Hey! Welcome to @chakra-ui/vue Box
3+
*
4+
* Box is the most abstract component on top of which all
5+
* other @chakra-ui/vue components are built. By default, it renders a `div` element
6+
*
7+
* @see Docs https://vue.chakra-ui.com/box
8+
* @see Source https://github.com/chakra-ui/chakra-ui-vue/blob/master/packages/chakra-ui-core/src/CSkipNav/CSkipNav.js
9+
*/
10+
11+
import { SNA } from '../config/props.types'
12+
import { createStyledAttrsMixin, mode } from '../utils'
13+
import CBox from '../CBox'
14+
15+
const FALLBACK_ID = 'chakra-skip-nav'
16+
17+
const createSkipNavLinkStyles = (props) => {
18+
const baseStyles = {
19+
userSelect: 'none',
20+
border: '0',
21+
borderRadius: 'md',
22+
fontWeight: 'semibold',
23+
height: '1px',
24+
width: '1px',
25+
margin: '-1px',
26+
padding: '0',
27+
outline: '0',
28+
overflow: 'hidden',
29+
position: 'absolute',
30+
clip: 'rect(0 0 0 0)',
31+
_focus: {
32+
clip: 'auto',
33+
width: 'auto',
34+
height: 'auto',
35+
boxShadow: 'outline',
36+
padding: '1rem',
37+
position: 'fixed',
38+
top: '1.5rem',
39+
insetStart: '1.5rem',
40+
bg: mode('white', 'gray.700')
41+
}
42+
}
43+
44+
return { ...baseStyles }
45+
}
46+
47+
/**
48+
* CSkipNavLink component
49+
*
50+
* Renders a link that remains hidden until focused to skip to the main content.
51+
*
52+
* @see Docs https://vue.chakra-ui.com/skip-nav
53+
*/
54+
export const CSkipNavLink = {
55+
name: 'CSkipNavLink',
56+
mixins: [createStyledAttrsMixin('CSkipNavLink')],
57+
props: {
58+
id: {
59+
type: String,
60+
default: FALLBACK_ID
61+
}
62+
},
63+
computed: {
64+
colorMode () {
65+
return this.$chakraColorMode()
66+
},
67+
theme () {
68+
return this.$chakraTheme()
69+
},
70+
componentStyles () {
71+
return createSkipNavLinkStyles()
72+
}
73+
},
74+
render (h) {
75+
return h(
76+
'a',
77+
{
78+
class: this.className,
79+
attrs: {
80+
href: `#${this.id}`
81+
}
82+
},
83+
this.$slots.default
84+
)
85+
}
86+
}
87+
88+
/**
89+
* CSkipNavLink component
90+
*
91+
* Renders a div as the target for the link.
92+
*
93+
* @see Docs https://vue.chakra-ui.com/skip-nav
94+
*/
95+
export const CSkipNavContent = {
96+
name: 'CSkipNavContent',
97+
mixins: [createStyledAttrsMixin('CSkipNavContent')],
98+
props: {
99+
id: {
100+
type: String,
101+
default: FALLBACK_ID
102+
},
103+
to: SNA
104+
},
105+
render (h) {
106+
return h(
107+
CBox,
108+
{
109+
class: this.className,
110+
attrs: {
111+
id: this.id,
112+
tabIndex: '-1',
113+
style: {
114+
outline: 0
115+
}
116+
}
117+
},
118+
this.$slots.default
119+
)
120+
}
121+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { storiesOf } from '@storybook/vue'
2+
import CInput from '../CInput'
3+
import CText from '../CText'
4+
import CList, { CListItem, CListIcon } from '../CList'
5+
import { CSkipNavLink, CSkipNavContent } from './CSkipNav'
6+
7+
storiesOf('UI | SkipNav', module).add('Default', () => ({
8+
components: {
9+
CSkipNavLink,
10+
CSkipNavContent,
11+
CInput,
12+
CText,
13+
CList,
14+
CListItem,
15+
CListIcon
16+
},
17+
template: `
18+
<div>
19+
<CSkipNavLink>Skip to Content</CSkipNavLink>
20+
<CSkipNavContent>
21+
<main>
22+
<CText>
23+
To test the SkipNav Components:
24+
<CList mb="4">
25+
<CListItem>
26+
<CListIcon icon="chevron-right" />
27+
Place focus on the input
28+
</CListItem>
29+
<CListItem>
30+
<CListIcon icon="chevron-right" />
31+
Press "Shift + Tab" to make the SkipNavLink appear
32+
</CListItem>
33+
<CListItem>
34+
<CListIcon icon="chevron-right" />
35+
Hit "Enter". You might leave the page to load up the iFrame isolated
36+
</CListItem>
37+
<CListItem>
38+
<CListIcon icon="chevron-right" />
39+
You should now see a blue outline over all the content.
40+
</CListItem>
41+
</CList>
42+
</CText>
43+
<label>Example Form Search</label>
44+
<CInput placeholder="Search" />
45+
</main>
46+
</CSkipNavContent>
47+
</div>
48+
`
49+
}))

0 commit comments

Comments
 (0)