-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
presence.ts
43 lines (36 loc) · 1013 Bytes
/
presence.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
import { cloneVNode, defineComponent, toRefs } from 'vue'
import { useComposedRefs, useForwardRef } from '@oku-ui/use-composable'
import { usePresence } from './usePresence'
interface PresenceProps {
present: boolean
}
const presenceProps = {
present: Boolean,
}
const NAME = 'OkuPresence'
const presence = defineComponent({
name: NAME,
inheritAttrs: false,
props: {
...presenceProps,
},
setup(props, { slots }) {
const { present } = toRefs(props)
const forwardedRef = useForwardRef()
const { isPresent, ref: presenceRef } = usePresence(present)
const composedRefs = useComposedRefs(presenceRef, forwardedRef)
return () => {
const slot = slots.default?.({
isPresent,
})
const [child] = slot ?? []
return isPresent.value
? cloneVNode(child, {
ref: composedRefs,
}, true)
: null
}
},
})
const OkuPresence = presence as typeof presence & (new () => { $props: PresenceProps })
export { OkuPresence }