Skip to content

Commit

Permalink
chore: optimize descriptions layout
Browse files Browse the repository at this point in the history
  • Loading branch information
cc-hearts committed Aug 13, 2024
1 parent 5053e28 commit 0194150
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
border: 1px solid var(--collapse-card-border);

@include e('active') {
.collapse-card__arrow > svg {
transform: rotate(180deg);
}
$is-at-root: false !global;

@include e('arrow') {
& > svg {
transform: rotate(180deg);

$is-at-root: false !global;
}
}

@include e('title') {
border-bottom: 1px solid var(--collapse-card-border);
}

$is-at-root: true !global;


}

@include e('title') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { ElCollapseTransition } from 'element-plus'
import ArrowDownIcon from './arrow-down-icon.vue'
import type { Props } from './helper'
import { ns } from './helper'
import type { Props } from './helper'
defineOptions({ name: 'CollapseCard' })
Expand Down
4 changes: 1 addition & 3 deletions packages/element-plus/src/components/collapse-card/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './collapse-card.scss'

import CollapseCard from './collapse-card.vue'

export { CollapseCard }
export { default as CollapseCard } from './collapse-card.vue'
33 changes: 25 additions & 8 deletions packages/element-plus/src/components/descriptions/descriptions.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
<script setup lang="ts">
import { ElDescriptions, ElDescriptionsItem } from 'element-plus'
import { _props } from './helper'
import { isUndef, isStr } from '@cc-heart/utils'
import type { Props } from './helper'
defineOptions({ name: 'Descriptions' })
defineProps(_props)
const props = withDefaults(defineProps<Props>(), {
columns: () => [],
border: false,
span: 3,
defaultValue: '-',
})
const internalFormatterValue = (value: string) => {
if ((!value && isUndef(value)) || (isStr(value) && value === '')) {
return props.defaultValue
}
return value
}
</script>

<template>
<el-descriptions :column="count" :border="border">
<template v-for="item in descriptionItems" :key="item.field">
<el-descriptions-item :span="item.span" :label="item.label">
<ElDescriptions :column="span" :border="border">
<template v-for="item in columns" :key="item.field">
<ElDescriptionsItem :span="item.span" :label="item.label">
<template v-if="item.labelSlot" #label>
<slot :name="item.labelSlot.name" :data="item" />
</template>

<template v-if="item.slot">
<slot :name="item.slot.name" :data="item" />
</template>

<template v-else>
{{ item.value }}
{{ internalFormatterValue(item.value) }}
</template>
</el-descriptions-item>
</ElDescriptionsItem>
</template>
</el-descriptions>
</ElDescriptions>
</template>
40 changes: 23 additions & 17 deletions packages/element-plus/src/components/descriptions/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { PropType } from 'vue'

export const VERSION = '0.0.1'

export interface DescriptionItem {
label: string
field: string
Expand All @@ -11,17 +7,27 @@ export interface DescriptionItem {
labelSlot?: { name: string }
}

export const _props = {
count: {
type: Number,
default: 3,
},
descriptionItems: {
type: Array as PropType<Array<DescriptionItem>>,
default: () => [],
},
border: {
type: Boolean,
default: true,
},
export interface Props {
/**
* @description: Number of columns displayed in a row
* @default 3
*/
span: number

/**
* @description An array of `DescriptionItem` objects defining the columns.
* @default []
*/
columns: Array<DescriptionItem>
/**
* @description Indicates whether to show a border.
* @default true
*/
border: boolean

/**
* @description The default value to use if none is provided.
* @default '-'
*/
defaultValue: string
}
8 changes: 1 addition & 7 deletions packages/element-plus/src/components/descriptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import { withInstall } from '@packages/vue-utils'
import Descriptions from './descriptions.vue'
import { VERSION } from './helper'

withInstall(Descriptions, VERSION)

export { Descriptions }
export { default as Descriptions } from './descriptions.vue'

0 comments on commit 0194150

Please sign in to comment.