2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2024-08-11 10:58:13 +08:00
|
|
|
import type { AnyObject } from '../_util/type';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { TableLocale } from './interface';
|
2019-11-15 14:35:25 +08:00
|
|
|
|
2024-08-13 10:34:52 +08:00
|
|
|
interface DefaultExpandIconProps<RecordType = AnyObject> {
|
2019-11-15 14:35:25 +08:00
|
|
|
prefixCls: string;
|
|
|
|
record: RecordType;
|
|
|
|
expanded: boolean;
|
|
|
|
expandable: boolean;
|
2024-08-11 10:58:13 +08:00
|
|
|
onExpand: (record: RecordType, e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
2019-11-15 14:35:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderExpandIcon(locale: TableLocale) {
|
2024-08-11 10:58:13 +08:00
|
|
|
return <RecordType extends AnyObject = AnyObject>(props: DefaultExpandIconProps<RecordType>) => {
|
|
|
|
const { prefixCls, onExpand, record, expanded, expandable } = props;
|
2019-11-15 14:35:25 +08:00
|
|
|
const iconPrefix = `${prefixCls}-row-expand-icon`;
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2022-11-19 13:47:33 +08:00
|
|
|
onClick={(e) => {
|
2020-01-09 22:44:31 +08:00
|
|
|
onExpand(record, e!);
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
2019-11-15 14:35:25 +08:00
|
|
|
className={classNames(iconPrefix, {
|
|
|
|
[`${iconPrefix}-spaced`]: !expandable,
|
|
|
|
[`${iconPrefix}-expanded`]: expandable && expanded,
|
|
|
|
[`${iconPrefix}-collapsed`]: expandable && !expanded,
|
|
|
|
})}
|
|
|
|
aria-label={expanded ? locale.collapse : locale.expand}
|
2022-08-17 12:28:37 +08:00
|
|
|
aria-expanded={expanded}
|
2019-11-15 14:35:25 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default renderExpandIcon;
|