Skip to content

Commit

Permalink
feat: enhance component adapter with custom Checkbox and RadioGroup h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
ArthurDarkstone committed Dec 9, 2024
1 parent 01b60f0 commit 2d321bd
Showing 1 changed file with 40 additions and 5 deletions.
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,
);
},
// 自定义默认按钮
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,
);
},
Select: withDefaultPlaceholder(ElSelectV2, 'select'),
Space: ElSpace,
Switch: ElSwitch,
TimePicker: ElTimePicker,
Expand Down

0 comments on commit 2d321bd

Please sign in to comment.