Commit 70ee1c840333c8b1d06b5bc059bc482d4832e082
Committed by
GitHub
1 parent
73469886
refactor: 插槽优先属性调整,prefixCls优先关系调整 (#2570)
Showing
1 changed file
with
27 additions
and
25 deletions
src/components/Container/src/collapse/CollapseHeader.vue
1 | -<template> | |
2 | - <div :class="[`${prefixCls}__header px-2 py-5`, $attrs.class]"> | |
3 | - <BasicTitle :helpMessage="helpMessage" normal> | |
4 | - <template v-if="title"> | |
5 | - {{ title }} | |
6 | - </template> | |
7 | - <template v-else> | |
8 | - <slot name="title"></slot> | |
9 | - </template> | |
10 | - </BasicTitle> | |
11 | - <div :class="`${prefixCls}__action`"> | |
12 | - <slot name="action"></slot> | |
13 | - <BasicArrow v-if="canExpan" up :expand="show" @click="$emit('expand')" /> | |
14 | - </div> | |
15 | - </div> | |
16 | -</template> | |
17 | -<script lang="ts"> | |
18 | - import { defineComponent } from 'vue'; | |
1 | +<script lang="tsx"> | |
2 | + import { defineComponent, computed, unref, type ExtractPropTypes } from 'vue'; | |
3 | + import { useDesign } from '/@/hooks/web/useDesign'; | |
19 | 4 | import { BasicArrow, BasicTitle } from '/@/components/Basic'; |
20 | 5 | |
21 | - const props = { | |
22 | - prefixCls: { type: String }, | |
6 | + const collapseHeaderProps = { | |
7 | + prefixCls: String, | |
8 | + title: String, | |
9 | + show: Boolean, | |
10 | + canExpan: Boolean, | |
23 | 11 | helpMessage: { |
24 | 12 | type: [Array, String] as PropType<string[] | string>, |
25 | 13 | default: '', |
26 | 14 | }, |
27 | - title: { type: String }, | |
28 | - show: { type: Boolean }, | |
29 | - canExpan: { type: Boolean }, | |
30 | 15 | }; |
31 | 16 | |
17 | + export type CollapseHeaderProps = ExtractPropTypes<typeof collapseHeaderProps>; | |
18 | + | |
32 | 19 | export default defineComponent({ |
33 | - components: { BasicArrow, BasicTitle }, | |
20 | + name: 'CollapseHeader', | |
34 | 21 | inheritAttrs: false, |
35 | - props, | |
22 | + props: collapseHeaderProps, | |
36 | 23 | emits: ['expand'], |
24 | + setup(props, { slots, attrs, emit }) { | |
25 | + const { prefixCls } = useDesign('collapse-container'); | |
26 | + const _prefixCls = computed(() => props.prefixCls || unref(prefixCls)); | |
27 | + return () => ( | |
28 | + <div class={[`${unref(_prefixCls)}__header px-2 py-5`, attrs.class]}> | |
29 | + <BasicTitle helpMessage={props.helpMessage} normal> | |
30 | + {slots.title?.() || props.title} | |
31 | + </BasicTitle> | |
32 | + | |
33 | + <div class={`${unref(_prefixCls)}__action`}> | |
34 | + {props.canExpan && <BasicArrow up expand={props.show} onClick={() => emit('expand')} />} | |
35 | + </div> | |
36 | + </div> | |
37 | + ); | |
38 | + }, | |
37 | 39 | }); |
38 | 40 | </script> | ... | ... |