Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some element-plus components doesn't has props 'options' #5082

Closed
wants to merge 5 commits into from
45 changes: 40 additions & 5 deletions apps/web-ele/src/adapter/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {
ElInput,
ElInputNumber,
ElNotification,
ElRadio,
ElRadioGroup,
ElSelect,
ElSelectV2,
ElSpace,
ElSwitch,
ElTimePicker,
Expand All @@ -38,6 +39,12 @@ const withDefaultPlaceholder = <T extends Component>(
};
};

type TKV = {
[key: string]: any;
label: string;
value: any;
};

// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
export type ComponentType =
| 'Checkbox'
Expand All @@ -62,9 +69,23 @@ async function initComponentAdapter() {
// import('xxx').then((res) => res.Button),

Checkbox: ElCheckbox,
CheckboxGroup: ElCheckboxGroup,
CheckboxGroup: (props, { attrs, slots }) => {
return h(
ElCheckboxGroup,
{ ...props, attrs },
props.options
? () =>
props.options?.map((option: TKV) => {
return h(ElCheckbox, {
label: option.label,
value: option.value,
});
})
: slots,
);
},
ArthurDarkstone marked this conversation as resolved.
Show resolved Hide resolved
// 自定义默认按钮
DefaulButton: (props, { attrs, slots }) => {
DefaultButton: (props, { attrs, slots }) => {
return h(ElButton, { ...props, attrs, type: 'info' }, slots);
},
// 自定义主要按钮
Expand All @@ -74,8 +95,22 @@ async function initComponentAdapter() {
Divider: ElDivider,
Input: withDefaultPlaceholder(ElInput, 'input'),
InputNumber: withDefaultPlaceholder(ElInputNumber, 'input'),
RadioGroup: ElRadioGroup,
Select: withDefaultPlaceholder(ElSelect, 'select'),
RadioGroup: (props, { attrs, slots }) => {
return h(
ElRadioGroup,
{ ...props, attrs },
props.options
? () =>
props.options?.map((option: TKV) => {
return h(ElRadio, {
label: option.label,
value: option.value,
});
})
: slots,
);
},
ArthurDarkstone marked this conversation as resolved.
Show resolved Hide resolved
Select: withDefaultPlaceholder(ElSelectV2, 'select'),
Space: ElSpace,
Switch: ElSwitch,
TimePicker: ElTimePicker,
Expand Down
Loading