-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcollapsibleContent.ts
91 lines (80 loc) · 2.65 KB
/
collapsibleContent.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import type { PropType } from 'vue'
import { Transition, defineComponent, h, toRefs } from 'vue'
import { useForwardRef } from '@oku-ui/use-composable'
import { primitiveProps } from '@oku-ui/primitive'
import type { ElementType, PrimitiveProps } from '@oku-ui/primitive'
import type { isPresent } from '@oku-ui/presence'
import { OkuPresence } from '@oku-ui/presence'
import { OkuCollapsibleContentImpl } from './collapsibleContentImpl'
import { useCollapsibleInject } from './collapsible'
import type { ScopeCollapsible } from './utils'
import { scopeCollapsibleProps } from './utils'
export const CONTENT_NAME = 'OkuCollapsibleContent'
export type CollapsibleContentIntrinsicElement = ElementType<'div'>
export type CollapsibleContentElement = HTMLDivElement
export interface CollapsibleContentProps extends PrimitiveProps {
/**
* Used to force mounting when more control is needed. Useful when
* controlling animation with React animation libraries.
*/
forceMount?: true
}
export const collapsibleContentProps = {
props: {
/**
* Used to force mounting when more control is needed. Useful when
* controlling animation with React animation libraries.
*/
forceMount: {
type: Boolean as PropType<true | undefined>,
default: undefined,
},
},
}
const collapsibleContent = defineComponent({
name: CONTENT_NAME,
components: {
OkuCollapsibleContentImpl,
Transition,
},
inheritAttrs: false,
props: {
...collapsibleContentProps.props,
...scopeCollapsibleProps,
...primitiveProps,
},
setup(props, { attrs, slots }) {
const { scopeOkuCollapsible, forceMount } = toRefs(props)
const { ...contentAttrs } = attrs as CollapsibleContentIntrinsicElement
const context = useCollapsibleInject(CONTENT_NAME, scopeOkuCollapsible.value)
const forwardedRef = useForwardRef()
// TODO: Transition
const originalReturn = () => h(
OkuPresence,
{
present: forceMount.value || context.open.value,
},
{
default: ({ isPresent }: { isPresent: isPresent }) => h(
OkuCollapsibleContentImpl,
{
...contentAttrs as any,
ref: forwardedRef,
asChild: props.asChild,
scopeCollapsible: scopeOkuCollapsible.value,
present: isPresent,
},
{
default: () => slots.default && slots.default(),
},
),
},
)
return originalReturn
},
})
// TODO: https://github.com/vuejs/core/pull/7444 after delete
export const OkuCollapsibleContent = collapsibleContent as typeof collapsibleContent &
(new () => {
$props: ScopeCollapsible<Partial<CollapsibleContentElement>>
})