-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathRadioIndicator.ts
66 lines (59 loc) · 1.97 KB
/
RadioIndicator.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
import { Primitive, primitiveProps } from '@oku-ui/primitive'
import type { ElementType, PrimitiveProps } from '@oku-ui/primitive'
import { computed, defineComponent, h, toRefs } from 'vue'
import type { PropType } from 'vue'
import { OkuPresence } from '@oku-ui/presence'
import { useForwardRef } from '@oku-ui/use-composable'
import { useRadioInject } from './Radio'
import type { ScopeRadio } from './utils'
import { getState, scopeRadioProps } from './utils'
const INDICATOR_NAME = 'OkuRadioIndicator'
export type RadioIndicatorIntrinsicElement = ElementType<'span'>
export type RadioIndicatorElement = HTMLSpanElement
export interface RadioIndicatorProps extends PrimitiveProps {
/**
* Used to force mounting when more control is needed. Useful when
* controlling animation with React animation libraries.
*/
forceMount?: true
}
export const radioIndicatorProps = {
props: {
forceMount: {
type: Boolean as PropType<true | undefined>,
default: undefined,
},
...primitiveProps,
},
}
const RadioIndicator = defineComponent({
name: INDICATOR_NAME,
inheritAttrs: false,
props: {
...radioIndicatorProps.props,
...scopeRadioProps,
},
setup(props, { attrs }) {
const { forceMount, scopeOkuRadio } = toRefs(props)
const inject = useRadioInject(INDICATOR_NAME, scopeOkuRadio.value)
const forwardedRef = useForwardRef()
return () => {
return h(OkuPresence, {
present: computed(() => forceMount.value || inject.checked.value).value,
}, {
default: () =>
h(Primitive.span, {
'data-state': getState(inject.checked.value),
'data-disabled': computed(() => inject.disabled?.value ? '' : undefined).value,
'asChild': props.asChild,
...attrs,
'ref': forwardedRef,
}),
})
}
},
})
export const OkuRadioIndicator = RadioIndicator as typeof RadioIndicator &
(new () => {
$props: ScopeRadio<Partial<RadioIndicatorIntrinsicElement>>
})