refactor: collapse/CollapseContainer (#2569)
This commit is contained in:
parent
d6fdfd9f93
commit
7346988622
|
|
@ -1,41 +1,14 @@
|
||||||
<template>
|
<script lang="tsx">
|
||||||
<div :class="prefixCls">
|
import { ref, unref, defineComponent, type PropType, type ExtractPropTypes } from 'vue';
|
||||||
<CollapseHeader v-bind="props" :prefixCls="prefixCls" :show="show" @expand="handleExpand">
|
|
||||||
<template #title>
|
|
||||||
<slot name="title"></slot>
|
|
||||||
</template>
|
|
||||||
<template #action>
|
|
||||||
<slot name="action"></slot>
|
|
||||||
</template>
|
|
||||||
</CollapseHeader>
|
|
||||||
|
|
||||||
<div class="p-2">
|
|
||||||
<CollapseTransition :enable="canExpan">
|
|
||||||
<Skeleton v-if="loading" :active="loading" />
|
|
||||||
<div :class="`${prefixCls}__body`" v-else v-show="show">
|
|
||||||
<slot></slot>
|
|
||||||
</div>
|
|
||||||
</CollapseTransition>
|
|
||||||
</div>
|
|
||||||
<div :class="`${prefixCls}__footer`" v-if="$slots.footer">
|
|
||||||
<slot name="footer"></slot>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import type { PropType } from 'vue';
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
// component
|
|
||||||
import { Skeleton } from 'ant-design-vue';
|
import { Skeleton } from 'ant-design-vue';
|
||||||
import { CollapseTransition } from '/@/components/Transition';
|
import { CollapseTransition } from '/@/components/Transition';
|
||||||
import CollapseHeader from './CollapseHeader.vue';
|
import CollapseHeader from './CollapseHeader.vue';
|
||||||
import { triggerWindowResize } from '/@/utils/event';
|
import { triggerWindowResize } from '/@/utils/event';
|
||||||
// hook
|
|
||||||
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
|
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
|
||||||
import { useDesign } from '/@/hooks/web/useDesign';
|
import { useDesign } from '/@/hooks/web/useDesign';
|
||||||
|
|
||||||
const props = defineProps({
|
const collapseContainerProps = {
|
||||||
title: { type: String, default: '' },
|
title: { type: String, default: '' },
|
||||||
loading: { type: Boolean },
|
loading: { type: Boolean },
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,27 +31,60 @@
|
||||||
* Delayed loading time
|
* Delayed loading time
|
||||||
*/
|
*/
|
||||||
lazyTime: { type: Number, default: 0 },
|
lazyTime: { type: Number, default: 0 },
|
||||||
});
|
};
|
||||||
|
|
||||||
const show = ref(true);
|
export type CollapseContainerProps = ExtractPropTypes<typeof collapseContainerProps>;
|
||||||
|
|
||||||
const { prefixCls } = useDesign('collapse-container');
|
export default defineComponent({
|
||||||
|
name: 'CollapseContainer',
|
||||||
|
|
||||||
/**
|
props: collapseContainerProps,
|
||||||
* @description: Handling development events
|
|
||||||
*/
|
|
||||||
function handleExpand(val: boolean) {
|
|
||||||
show.value = isNil(val) ? !show.value : val;
|
|
||||||
if (props.triggerWindowResize) {
|
|
||||||
// 200 milliseconds here is because the expansion has animation,
|
|
||||||
useTimeoutFn(triggerWindowResize, 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defineExpose({
|
setup(props, { expose, slots }) {
|
||||||
handleExpand,
|
const { prefixCls } = useDesign('collapse-container');
|
||||||
|
|
||||||
|
const show = ref(true);
|
||||||
|
|
||||||
|
const handleExpand = (val: boolean) => {
|
||||||
|
show.value = isNil(val) ? !show.value : val;
|
||||||
|
if (props.triggerWindowResize) {
|
||||||
|
// 200 milliseconds here is because the expansion has animation,
|
||||||
|
useTimeoutFn(triggerWindowResize, 200);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expose({ handleExpand });
|
||||||
|
|
||||||
|
return () => (
|
||||||
|
<div class={unref(prefixCls)}>
|
||||||
|
<CollapseHeader
|
||||||
|
{...props}
|
||||||
|
prefixCls={unref(prefixCls)}
|
||||||
|
onExpand={handleExpand}
|
||||||
|
show={show.value}
|
||||||
|
v-slots={{
|
||||||
|
title: slots.title,
|
||||||
|
action: slots.action,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="p-2">
|
||||||
|
<CollapseTransition enable={props.canExpan}>
|
||||||
|
{props.loading ? (
|
||||||
|
<Skeleton active={props.loading} />
|
||||||
|
) : (
|
||||||
|
show.value && <div class={`${prefixCls}__body`}>{slots.default?.()}</div>
|
||||||
|
)}
|
||||||
|
</CollapseTransition>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{slots.footer && <div class={`${prefixCls}__footer`}>{slots.footer()}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@prefix-cls: ~'@{namespace}-collapse-container';
|
@prefix-cls: ~'@{namespace}-collapse-container';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue