-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(descriptions): add descriptions & descriptions item
- Loading branch information
1 parent
074f82d
commit 18efcc1
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { App } from 'vue' | ||
import Descriptions from './src/descriptions.vue' | ||
|
||
Descriptions.install = (vue: App): void => { | ||
vue.component(Descriptions.name, Descriptions) | ||
} | ||
|
||
export default Descriptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<template> | ||
<el-descriptions class="emqx-descriptions"> | ||
<slot></slot> | ||
<template v-if="$slots.title" #title> | ||
<slot name="title"></slot> | ||
</template> | ||
<template v-if="$slots.extra" #extra> | ||
<slot name="extra"></slot> | ||
</template> | ||
</el-descriptions> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import { ElDescriptions } from 'element-plus' | ||
interface Slot { | ||
type: string | { name: string } | ||
children?: Array<Slot> | ||
} | ||
export default defineComponent({ | ||
name: 'EmqxDescriptions', | ||
components: { | ||
ElDescriptions, | ||
}, | ||
setup(props: any, { slots }) { | ||
const setName = (item: Slot) => { | ||
if (typeof item.type === 'string' || item.type?.name !== 'EmqxDescriptionsItem') { | ||
return | ||
} | ||
if (!item.type || typeof item.type === 'string') { | ||
item.type = { | ||
name: '', | ||
} | ||
} | ||
item.type.name = 'ElDescriptionsItem' | ||
} | ||
const recursiveChange = (children: Array<Slot>) => { | ||
const temp: any = Array.isArray(children) ? children : [children] | ||
temp.forEach((child: Slot) => { | ||
if (Array.isArray(child.children)) { | ||
child.children.forEach((item: Slot) => { | ||
setName(item) | ||
}) | ||
recursiveChange(child.children) | ||
} else { | ||
setName(child) | ||
} | ||
}) | ||
} | ||
const changeName = () => { | ||
recursiveChange(slots.default?.() as Array<Slot>) | ||
} | ||
changeName() | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { App } from 'vue' | ||
import DescriptionsItem from './src/descriptions-item.vue' | ||
|
||
DescriptionsItem.install = (vue: App): void => { | ||
vue.component('EmqxDescriptionsItem', DescriptionsItem) | ||
} | ||
|
||
export default DescriptionsItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<el-descriptions-item class="emqx-descriptions-item"> | ||
<slot></slot> | ||
<template v-if="$slots.label" #label> | ||
<slot name="label"></slot> | ||
</template> | ||
</el-descriptions-item> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import { ElDescriptionsItem } from 'element-plus' | ||
export default defineComponent({ | ||
name: 'EmqxDescriptionsItem', | ||
components: { | ||
ElDescriptionsItem, | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters