Skip to content

Commit

Permalink
refactor(element): refactor element slot pass way (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
muuyao authored Sep 25, 2021
1 parent 64445d0 commit da28fe7
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 82 deletions.
2 changes: 1 addition & 1 deletion packages/element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"axios": "^0.21.1",
"codesandbox": "^2.2.3",
"core-js": "^2.4.0",
"element-ui": "^2.15.2",
"element-ui": "latest",
"sass": "^1.34.1",
"ts-import-plugin": "^1.6.7",
"ttypescript": "^1.5.12",
Expand Down
6 changes: 2 additions & 4 deletions packages/element/src/array-cards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,20 @@ const ArrayCardsInner = observer(
},
},
{
default: () => [
content,
default: () => [content],
header: () =>
h(
Row,
{
props: {
type: 'flex',
justify: 'space-between',
},
slot: 'header',
},
{
default: () => [title, extra],
}
),
],
}
),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/element/src/array-collapse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export const ArrayCollapseInner = observer(
default: () => [content],
}
),
],
title: () =>
h(
Row,
{
Expand All @@ -251,7 +253,6 @@ export const ArrayCollapseInner = observer(
type: 'flex',
justify: 'space-between',
},
slot: 'title',
},
{
default: () => [
Expand All @@ -260,7 +261,6 @@ export const ArrayCollapseInner = observer(
],
}
),
],
}
)
})
Expand Down
36 changes: 7 additions & 29 deletions packages/element/src/array-tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,6 @@ export const ArrayTabs = observer(
}
}

const addButton = h(
Button,
{
class: [`${prefixCls}-addition`],
attrs: {
size: 'large',
icon: 'el-icon-plus',
},
on: {
click: (e: MouseEvent) => {
e.stopPropagation()
e.preventDefault()
onEdit(null, 'add')
},
},
},
{}
)

const badgedTab = (index: number) => {
const tab = `${field.title || 'Untitled'} ${index + 1}`
const path = field.address.concat(index)
Expand All @@ -71,7 +52,7 @@ export const ArrayTabs = observer(
if (errors.length) {
return h(
'span',
{ slot: 'label' },
{},
{
default: () => [
h(
Expand All @@ -86,19 +67,15 @@ export const ArrayTabs = observer(
default: () => [tab],
}
),
index === dataSource.length - 1 ? addButton : null,
],
}
)
}
return h(
'span',
{ slot: 'label' },
{},
{
default: () => [
tab,
index === dataSource.length - 1 ? addButton : null,
],
default: () => [tab],
}
)
}
Expand All @@ -120,7 +97,7 @@ export const ArrayTabs = observer(
},
},
{
default: () => [
default: () =>
h(
RecursionField,
{
Expand All @@ -131,8 +108,8 @@ export const ArrayTabs = observer(
},
{}
),
badgedTab(index),
],

label: () => [badgedTab(index)],
}
)
})
Expand All @@ -151,6 +128,7 @@ export const ArrayTabs = observer(
activeKey.value = key
},
'tab-remove': (target) => onEdit(target, 'remove'),
'tab-add': () => onEdit(null, 'add'),
},
},
{
Expand Down
7 changes: 3 additions & 4 deletions packages/element/src/editable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ const EditablePopover = observer(
},
},
{
default: () => [
slots.default(),
default: () => [slots.default()],
reference: () =>
h(
FormBaseItem,
{ slot: 'reference', class: [`${prefixCls}-trigger`] },
{ class: [`${prefixCls}-trigger`] },
{
default: () =>
h(
Expand Down Expand Up @@ -260,7 +260,6 @@ const EditablePopover = observer(
),
}
),
],
}
)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/element/src/form-collapse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ const FormCollapse = observer(
{
default: () => [
h(RecursionField, { props: { schema, name } }, {}),
],
title: () =>
h(
'span',
{ slot: 'title' },
{},
{ default: () => badgedHeader(name, props) }
),
],
}
)
})
Expand Down
18 changes: 6 additions & 12 deletions packages/element/src/form-dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,17 @@ export function FormDialog(
},
},
{
default: () => [
h(component, {}, {}),
default: () => [h(component, {}, {})],
title: () =>
h(
'div',
{
slot: 'title',
},
{},
{ default: () => resolveComponent(title) }
),
footer: () =>
h(
'div',
{
slot: 'footer',
},
{},
{
default: () => {
const FooterProtalTarget = h(
Expand Down Expand Up @@ -295,7 +292,6 @@ export function FormDialog(
},
}
),
],
}
),
}
Expand Down Expand Up @@ -402,9 +398,7 @@ const FormDialogFooter = defineComponent({
to: PORTAL_TARGET_NAME,
},
},
{
default: () => h(Fragment, {}, slots),
}
slots
)
}
},
Expand Down
13 changes: 3 additions & 10 deletions packages/element/src/form-drawer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,9 @@ export function FormDrawer(
},
}
),
h(
'div',
{
slot: 'title',
},
{ default: () => resolveComponent(title) }
),
],
title: () =>
h('div', {}, { default: () => resolveComponent(title) }),
}
),
}
Expand Down Expand Up @@ -408,9 +403,7 @@ const FormDrawerFooter = defineComponent({
to: PORTAL_TARGET_NAME,
},
},
{
default: () => h(Fragment, {}, slots),
}
slots
)
}
},
Expand Down
15 changes: 5 additions & 10 deletions packages/element/src/form-item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,18 @@ export const FormBaseItem = defineComponent<FormItemProps>({
},
},
{
default: () => [
labelChildren,
default: () => [labelChildren],
content: () =>
h(
'div',
{
slot: 'content',
},
{},
{
default: () => [
overflow.value && resolveComponent(label),
isTextTooltip && resolveComponent(tooltip),
],
}
),
],
}
)
} else {
Expand All @@ -309,19 +306,17 @@ export const FormBaseItem = defineComponent<FormItemProps>({
},
},
{
default: () => [
h('i', { class: 'el-icon-info' }, {}),
default: () => [h('i', { class: 'el-icon-info' }, {})],
content: () =>
h(
'div',
{
class: `${prefixCls}-label-tooltip-content`,
slot: 'content',
},
{
default: () => [resolveComponent(tooltip)],
}
),
],
}
),
],
Expand Down
8 changes: 3 additions & 5 deletions packages/element/src/form-tab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ const FormTabInner = observer(
},
{}
),
h(
'div',
{ slot: 'label' },
{ default: badgedTab(name, props) }
),
],
label: () => [
h('div', {}, { default: badgedTab(name, props) }),
],
}
)
Expand Down
2 changes: 0 additions & 2 deletions packages/vue/src/shared/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ if (isVue2) {
name: 'frag',
},
],
attrs: vm.$attrs,
scopedSlots: vm.$scopedSlots,
},
vm?.$scopedSlots?.default?.(vm.$attrs)
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/shared/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const compatibleCreateElement = (
children.push(
key === 'default'
? child
: hInVue2(FragmentComponent, { slot: key }, child)
: hInVue2(FragmentComponent, { slot: key }, [child])
)
} catch (error) {}
}
Expand Down

0 comments on commit da28fe7

Please sign in to comment.