-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
47 lines (40 loc) · 1.46 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 CheckboxProps = ExtractPropTypes<typeof checkboxProps>;
export type CheckboxEmits = typeof checkboxEmits;
export type CheckboxEmitFn = SetupContext<CheckboxEmits>["emit"];
export type CheckboxInstance = InstanceType<typeof VDictCheckbox>;
export const checkboxProps = { ...basicProps, ...buttonProps };
export const checkboxEmits = basicEmits;
export const VDictCheckbox = defineComponent({
name: "VDictCheckbox",
props: checkboxProps,
emits: checkboxEmits,
setup(props, { emit, attrs }) {
const ElCheckboxGroup = dynamicComponent("el-checkbox-group");
const ElCheckbox = dynamicComponent("el-checkbox");
const ElCheckboxButton = dynamicComponent("el-checkbox-button");
const { data } = useDict(props.data, props.option, props.cache);
return () =>
h(
ElCheckboxGroup,
{
props: { ...props, ...attrs },
on: useListeners(emit, checkboxEmits)
},
() =>
data.value?.map(item =>
h(
props.button ? ElCheckboxButton : ElCheckbox,
{
props: { ...item, label: item.value }
},
() => item.label
)
)
);
}
});