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

Commit 0f8181b

Browse files
feat(c-skip-nav): build components
1 parent eecdac0 commit 0f8181b

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

packages/c-skip-nav/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"clean": "rimraf dist"
2626
},
2727
"dependencies": {
28+
"@chakra-ui/vue-next": "1.0.0-alpha.13",
2829
"@chakra-ui/vue-system": "0.1.0-alpha.10"
2930
},
3031
"devDependencies": {

packages/c-skip-nav/src/c-skip-nav.ts

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,92 @@
88
* @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2
99
*/
1010

11-
import { h, defineComponent, PropType } from 'vue'
12-
import { chakra, DOMElements } from '@chakra-ui/vue-system'
11+
import { h, defineComponent } from "vue"
12+
import {
13+
chakra,
14+
SystemStyleObject,
15+
useStyleConfig,
16+
} from "@chakra-ui/vue-system"
17+
import { CBox } from "@chakra-ui/vue-next"
1318

14-
export const CSkipNav = defineComponent({
19+
const FALLBACK_ID = "chakra-skip-nav"
20+
21+
export const CSkipNavLink = defineComponent({
22+
name: "CSkipNavLink",
1523
props: {
16-
as: {
17-
type: [Object, String] as PropType<DOMElements>,
18-
default: 'div',
24+
id: {
25+
type: String,
26+
default: FALLBACK_ID,
1927
},
2028
},
2129
setup(props, { slots, attrs }) {
22-
return () => h(chakra(props.as), { ...attrs }, slots)
30+
function getBaseStyles(styles: any): SystemStyleObject {
31+
return {
32+
userSelect: "none",
33+
border: "0",
34+
borderRadius: "md",
35+
fontWeight: "semibold",
36+
height: "1px",
37+
width: "1px",
38+
margin: "-1px",
39+
padding: "0",
40+
outline: "0",
41+
overflow: "hidden",
42+
position: "absolute",
43+
clip: "rect(0 0 0 0)",
44+
...styles,
45+
_focus: {
46+
clip: "auto",
47+
width: "auto",
48+
height: "auto",
49+
boxShadow: "outline",
50+
padding: "1rem",
51+
position: "fixed",
52+
top: "1.5rem",
53+
insetStart: "1.5rem",
54+
...styles["_focusVisible"],
55+
},
56+
}
57+
}
58+
59+
const styles = useStyleConfig("SkipLink", props)
60+
61+
return () => {
62+
return h(
63+
chakra("a", {
64+
__css: {
65+
...getBaseStyles(styles.value),
66+
},
67+
}),
68+
{
69+
...attrs,
70+
href: `#${props.id}`,
71+
},
72+
slots
73+
)
74+
}
75+
},
76+
})
77+
78+
export const CSkipNavContent = defineComponent({
79+
name: "CSkipNavContent",
80+
props: {
81+
id: {
82+
type: String,
83+
default: FALLBACK_ID,
84+
},
85+
},
86+
setup(props, { attrs, slots }) {
87+
return () => {
88+
return h(
89+
chakra(CBox),
90+
{
91+
...attrs,
92+
id: props.id,
93+
tabIndex: "-1",
94+
},
95+
slots
96+
)
97+
}
2398
},
2499
})

0 commit comments

Comments
 (0)