-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
47 lines (40 loc) · 1.39 KB
/
index.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
import type { SetupContext, ExtractPropTypes } from "vue-demi";
import { defineComponent } from "vue-demi";
import { basicProps, buttonProps, basicEmits, useListeners } from "~/constants";
import { h, dynamicComponent } from "~/utils";
import { useDict } from "~/composables";
export type RadioProps = ExtractPropTypes<typeof radioProps>;
export type RadioEmits = typeof radioEmits;
export type RadioEmitFn = SetupContext<RadioEmits>["emit"];
export type RadioInstance = InstanceType<typeof VDictRadio>;
export const radioProps = { ...basicProps, ...buttonProps };
export const radioEmits = basicEmits;
export const VDictRadio = defineComponent({
name: "VDictRadio",
props: radioProps,
emits: radioEmits,
setup(props, { emit, attrs }) {
const ElRadioGroup = dynamicComponent("el-radio-group");
const ElRadio = dynamicComponent("el-radio");
const ElRadioButton = dynamicComponent("el-radio-button");
const { data } = useDict(props.data, props.option, props.cache);
return () =>
h(
ElRadioGroup,
{
props: { ...props, ...attrs },
on: useListeners(emit, radioEmits)
},
() =>
data.value?.map(item =>
h(
props.button ? ElRadioButton : ElRadio,
{
props: { ...item, label: item.value }
},
() => item.label
)
)
);
}
});