2021-09-25 08:51:32 +00:00
|
|
|
import PanelContent from './PanelContent';
|
|
|
|
import { initDefaultProps } from '../_util/props-util';
|
|
|
|
import { collapsePanelProps } from './commonProps';
|
2021-06-26 01:35:40 +00:00
|
|
|
import type { ExtractPropTypes } from 'vue';
|
2021-09-25 08:51:32 +00:00
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import Transition from '../_util/transition';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
import devWarning from '../vc-util/devWarning';
|
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
2018-02-01 10:18:05 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
export { collapsePanelProps };
|
|
|
|
export type CollapsePanelProps = Partial<ExtractPropTypes<ReturnType<typeof collapsePanelProps>>>;
|
2020-10-14 09:57:38 +00:00
|
|
|
export default defineComponent({
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ACollapsePanel',
|
2021-09-25 08:51:32 +00:00
|
|
|
props: initDefaultProps(collapsePanelProps(), {
|
|
|
|
showArrow: true,
|
|
|
|
isActive: false,
|
|
|
|
onItemClick() {},
|
|
|
|
headerClass: '',
|
|
|
|
forceRender: false,
|
|
|
|
}),
|
|
|
|
slots: ['expandIcon', 'extra', 'header'],
|
|
|
|
emits: ['itemClick'],
|
|
|
|
setup(props, { slots, emit }) {
|
|
|
|
devWarning(
|
|
|
|
props.disabled === undefined,
|
|
|
|
'Collapse.Panel',
|
|
|
|
'`disabled` is deprecated. Please use `collapsible="disabled"` instead.',
|
|
|
|
);
|
|
|
|
const { prefixCls } = useConfigInject('collapse', props);
|
|
|
|
const handleItemClick = () => {
|
|
|
|
emit('itemClick', props.panelKey);
|
2020-07-15 07:27:35 +00:00
|
|
|
};
|
2021-09-25 08:51:32 +00:00
|
|
|
const handleKeyPress = (e: KeyboardEvent) => {
|
|
|
|
if (e.key === 'Enter' || e.keyCode === 13 || e.which === 13) {
|
|
|
|
handleItemClick();
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2021-09-25 08:51:32 +00:00
|
|
|
return () => {
|
|
|
|
const {
|
|
|
|
header = slots.header?.(),
|
|
|
|
headerClass,
|
|
|
|
isActive,
|
|
|
|
showArrow,
|
|
|
|
destroyInactivePanel,
|
|
|
|
accordion,
|
|
|
|
forceRender,
|
|
|
|
openAnimation,
|
|
|
|
expandIcon = slots.expandIcon,
|
|
|
|
extra = slots.extra?.(),
|
|
|
|
collapsible,
|
|
|
|
} = props;
|
|
|
|
const disabled = collapsible === 'disabled';
|
|
|
|
const prefixClsValue = prefixCls.value;
|
|
|
|
const headerCls = classNames(`${prefixClsValue}-header`, {
|
|
|
|
[headerClass]: headerClass,
|
|
|
|
[`${prefixClsValue}-header-collapsible-only`]: collapsible === 'header',
|
|
|
|
});
|
|
|
|
const itemCls = classNames({
|
|
|
|
[`${prefixClsValue}-item`]: true,
|
|
|
|
[`${prefixClsValue}-item-active`]: isActive,
|
|
|
|
[`${prefixClsValue}-item-disabled`]: disabled,
|
|
|
|
[`${prefixClsValue}-no-arrow`]: !showArrow,
|
|
|
|
});
|
|
|
|
|
|
|
|
let icon = <i class="arrow" />;
|
|
|
|
if (showArrow && typeof expandIcon === 'function') {
|
|
|
|
icon = expandIcon(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
const panelContent = (
|
|
|
|
<PanelContent
|
|
|
|
v-show={isActive}
|
|
|
|
prefixCls={prefixClsValue}
|
|
|
|
isActive={isActive}
|
|
|
|
forceRender={forceRender}
|
|
|
|
role={accordion ? 'tabpanel' : null}
|
|
|
|
v-slots={{ default: slots.default }}
|
|
|
|
></PanelContent>
|
|
|
|
);
|
|
|
|
const transitionProps = {
|
|
|
|
appear: true,
|
|
|
|
css: false,
|
|
|
|
...openAnimation,
|
|
|
|
};
|
2020-07-15 07:27:35 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
return (
|
|
|
|
<div class={itemCls}>
|
|
|
|
<div
|
|
|
|
class={headerCls}
|
|
|
|
onClick={() => collapsible !== 'header' && handleItemClick()}
|
|
|
|
role={accordion ? 'tab' : 'button'}
|
|
|
|
tabindex={disabled ? -1 : 0}
|
|
|
|
aria-expanded={isActive}
|
|
|
|
onKeypress={handleKeyPress}
|
|
|
|
>
|
|
|
|
{showArrow && icon}
|
|
|
|
{collapsible === 'header' ? (
|
|
|
|
<span onClick={handleItemClick} class={`${prefixClsValue}-header-text`}>
|
|
|
|
{header}
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
header
|
|
|
|
)}
|
|
|
|
{extra && <div class={`${prefixClsValue}-extra`}>{extra}</div>}
|
|
|
|
</div>
|
|
|
|
<Transition {...transitionProps}>
|
|
|
|
{!destroyInactivePanel || isActive ? panelContent : null}
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
);
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-02-01 10:18:05 +00:00
|
|
|
},
|
2020-10-14 09:57:38 +00:00
|
|
|
});
|