-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
VisuallyHidden.ts
65 lines (54 loc) · 1.68 KB
/
VisuallyHidden.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Primitive } from '@oku-ui/primitive'
import type {
ElementType,
InstanceTypeRef,
MergeProps,
PrimitiveProps,
} from '@oku-ui/primitive'
import { useForwardRef } from '@oku-ui/use-composable'
import type { CSSProperties } from 'vue'
import { defineComponent, h } from 'vue'
const NAME = 'OkuVisuallyHidden'
type VisuallyHiddenElement = ElementType<'button'>
export type _VisuallyHiddenEl = HTMLButtonElement
interface VisuallyHiddenProps extends PrimitiveProps {}
const VisuallyHidden = defineComponent({
name: NAME,
inheritAttrs: false,
props: {
asChild: {
type: Boolean,
default: undefined,
},
},
setup(props, { attrs, expose }) {
const { ...visuallyHiddenAttrs } = attrs as VisuallyHiddenElement
const forwardedRef = useForwardRef()
const originalReturn = () =>
h(Primitive.span, {
ref: forwardedRef,
asChild: props.asChild,
...visuallyHiddenAttrs,
style: {
position: 'absolute',
border: 0,
width: 1,
height: 1,
padding: 0,
margin: -1,
overflow: 'hidden',
clip: 'rect(0, 0, 0, 0)',
whiteSpace: 'nowrap',
wordWrap: 'normal',
...(visuallyHiddenAttrs.style as CSSProperties),
},
})
return originalReturn
},
})
type _VisuallyHidden = MergeProps<VisuallyHiddenProps, VisuallyHiddenElement>
type InnerVisuallyHidden = InstanceTypeRef<typeof VisuallyHidden, _VisuallyHiddenEl>
const OkuVisuallyHidden = VisuallyHidden as typeof VisuallyHidden &
(new () => { $props: _VisuallyHidden })
export { OkuVisuallyHidden }
export type { VisuallyHiddenProps, InnerVisuallyHidden, _VisuallyHidden }