|
8 | 8 | * @see WAI-ARIA https://www.w3.org/TR/wai-aria-practices-1.2
|
9 | 9 | */
|
10 | 10 |
|
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" |
13 | 18 |
|
14 |
| -export const CSkipNav = defineComponent({ |
| 19 | +const FALLBACK_ID = "chakra-skip-nav" |
| 20 | + |
| 21 | +export const CSkipNavLink = defineComponent({ |
| 22 | + name: "CSkipNavLink", |
15 | 23 | props: {
|
16 |
| - as: { |
17 |
| - type: [Object, String] as PropType<DOMElements>, |
18 |
| - default: 'div', |
| 24 | + id: { |
| 25 | + type: String, |
| 26 | + default: FALLBACK_ID, |
19 | 27 | },
|
20 | 28 | },
|
21 | 29 | 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 | + } |
23 | 98 | },
|
24 | 99 | })
|
0 commit comments