2017-12-13 23:23:38 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import RcCollapse from 'rc-collapse';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../_util/warning';
|
2023-05-25 10:19:56 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2020-11-30 15:20:42 +08:00
|
|
|
|
2022-09-20 19:32:18 +08:00
|
|
|
export type CollapsibleType = 'header' | 'icon' | 'disabled';
|
2017-12-13 23:23:38 +08:00
|
|
|
|
|
|
|
export interface CollapsePanelProps {
|
2019-07-13 10:31:56 +08:00
|
|
|
key: string | number;
|
2017-12-13 23:23:38 +08:00
|
|
|
header: React.ReactNode;
|
2020-11-30 15:20:42 +08:00
|
|
|
/** @deprecated Use `collapsible="disabled"` instead */
|
2017-12-13 23:23:38 +08:00
|
|
|
disabled?: boolean;
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
showArrow?: boolean;
|
|
|
|
prefixCls?: string;
|
2018-01-31 10:44:33 +08:00
|
|
|
forceRender?: boolean;
|
2018-11-04 16:09:51 +08:00
|
|
|
id?: string;
|
2019-02-13 19:32:49 +08:00
|
|
|
extra?: React.ReactNode;
|
2020-12-01 09:40:35 +08:00
|
|
|
collapsible?: CollapsibleType;
|
2022-04-18 18:39:23 +08:00
|
|
|
children?: React.ReactNode;
|
2017-12-13 23:23:38 +08:00
|
|
|
}
|
2023-05-25 10:19:56 +08:00
|
|
|
|
2023-02-01 22:55:41 +08:00
|
|
|
const CollapsePanel = React.forwardRef<HTMLDivElement, CollapsePanelProps>((props, ref) => {
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2020-11-30 15:20:42 +08:00
|
|
|
!('disabled' in props),
|
|
|
|
'Collapse.Panel',
|
|
|
|
'`disabled` is deprecated. Please use `collapsible="disabled"` instead.',
|
|
|
|
);
|
|
|
|
|
2020-05-26 20:55:39 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const { prefixCls: customizePrefixCls, className = '', showArrow = true } = props;
|
|
|
|
const prefixCls = getPrefixCls('collapse', customizePrefixCls);
|
|
|
|
const collapsePanelClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-no-arrow`]: !showArrow,
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2023-02-01 22:55:41 +08:00
|
|
|
return (
|
|
|
|
<RcCollapse.Panel
|
|
|
|
ref={ref}
|
|
|
|
{...props}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
className={collapsePanelClassName}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2020-05-26 20:55:39 +08:00
|
|
|
export default CollapsePanel;
|