|
| 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 | +} |
0 commit comments