mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-25 00:08:27 +08:00
7d66a8e5cf
* fix: table generic default any * feat: = AnyObject
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
|
|
import type { AnyObject } from '../_util/type';
|
|
import type { TableLocale } from './interface';
|
|
|
|
interface DefaultExpandIconProps<RecordType = AnyObject> {
|
|
prefixCls: string;
|
|
record: RecordType;
|
|
expanded: boolean;
|
|
expandable: boolean;
|
|
onExpand: (record: RecordType, e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
}
|
|
|
|
function renderExpandIcon(locale: TableLocale) {
|
|
return <RecordType extends AnyObject = AnyObject>(props: DefaultExpandIconProps<RecordType>) => {
|
|
const { prefixCls, onExpand, record, expanded, expandable } = props;
|
|
const iconPrefix = `${prefixCls}-row-expand-icon`;
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={(e) => {
|
|
onExpand(record, e!);
|
|
e.stopPropagation();
|
|
}}
|
|
className={classNames(iconPrefix, {
|
|
[`${iconPrefix}-spaced`]: !expandable,
|
|
[`${iconPrefix}-expanded`]: expandable && expanded,
|
|
[`${iconPrefix}-collapsed`]: expandable && !expanded,
|
|
})}
|
|
aria-label={expanded ? locale.collapse : locale.expand}
|
|
aria-expanded={expanded}
|
|
/>
|
|
);
|
|
};
|
|
}
|
|
|
|
export default renderExpandIcon;
|