From 3505630af9c1353b1da3d41f2d84a3efb01dacf0 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Wed, 14 Jul 2021 14:53:59 +0800 Subject: [PATCH] style(description): add description default style --- example/App.vue | 14 ++++++--- packages/Descriptions/src/descriptions.vue | 34 ++++++++++----------- packages/styles/components/description.scss | 10 ++++++ packages/styles/components/index.scss | 1 + 4 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 packages/styles/components/description.scss diff --git a/example/App.vue b/example/App.vue index 033ee5e..75507f6 100644 --- a/example/App.vue +++ b/example/App.vue @@ -213,13 +213,17 @@

Descriptions

- - + + + + 900000 - 18100000000 - 苏州市 - 江苏省苏州市吴中区吴中大道 1188 号 + 18100000000 + 苏州市 + 江苏省苏州市吴中区吴中大道 1188 号 diff --git a/packages/Descriptions/src/descriptions.vue b/packages/Descriptions/src/descriptions.vue index 6cdac25..7dc0088 100644 --- a/packages/Descriptions/src/descriptions.vue +++ b/packages/Descriptions/src/descriptions.vue @@ -24,36 +24,34 @@ export default defineComponent({ components: { ElDescriptions, }, - setup(props: any, { slots }) { - const setName = (item: Slot) => { - if (typeof item.type === 'string' || item.type?.name !== 'EmqxDescriptionsItem') { + setup(props, { slots }) { + const resetToNativeName = (node: Slot) => { + if (typeof node.type === 'string' || node.type?.name !== 'EmqxDescriptionsItem') { return } - if (!item.type || typeof item.type === 'string') { - item.type = { + if (!node.type) { + node.type = { name: '', } } - item.type.name = 'ElDescriptionsItem' + // Why we set the type name to 'ElDescriptionsItem' + // https://github.com/element-plus/element-plus/blob/dev/packages/descriptions/src/index.vue#L100 + node.type.name = 'ElDescriptionsItem' } - const recursiveChange = (children: Array) => { - const temp: any = Array.isArray(children) ? children : [children] - temp.forEach((child: Slot) => { - if (Array.isArray(child.children)) { - child.children.forEach((item: Slot) => { - setName(item) + const recursiveChangeName = (nodes: Array) => { + nodes.forEach((node: Slot) => { + if (Array.isArray(node.children)) { + node.children.forEach((item: Slot) => { + resetToNativeName(item) }) - recursiveChange(child.children) + recursiveChangeName(node.children) } else { - setName(child) + resetToNativeName(node) } }) } - const changeName = () => { - recursiveChange(slots.default?.() as Array) - } - changeName() + recursiveChangeName(slots.default?.() as Array) }, }) diff --git a/packages/styles/components/description.scss b/packages/styles/components/description.scss new file mode 100644 index 0000000..95380d7 --- /dev/null +++ b/packages/styles/components/description.scss @@ -0,0 +1,10 @@ +.el-descriptions { + .el-descriptions__body { + .el-descriptions__label { + color: #96999C; + } + .el-descriptions__content { + color: #1D1D1D; + } + } +} diff --git a/packages/styles/components/index.scss b/packages/styles/components/index.scss index 68d4437..accca66 100644 --- a/packages/styles/components/index.scss +++ b/packages/styles/components/index.scss @@ -14,3 +14,4 @@ @import "select.scss"; @import "tags.scss"; @import "dropdown.scss"; +@import "description.scss";