mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 19:39:51 +08:00
a3320dde29
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import * as React from 'react';
|
|
import DeleteOutlined from '@ant-design/icons/DeleteOutlined';
|
|
import classNames from 'classnames';
|
|
|
|
import type { KeyWiseTransferItem } from '.';
|
|
import Checkbox from '../checkbox';
|
|
import { useLocale } from '../locale';
|
|
import defaultLocale from '../locale/en_US';
|
|
|
|
type ListItemProps<RecordType> = {
|
|
renderedText?: string | number;
|
|
renderedEl: React.ReactNode;
|
|
disabled?: boolean;
|
|
checked?: boolean;
|
|
prefixCls: string;
|
|
onClick: (item: RecordType, e: React.MouseEvent<HTMLLIElement, MouseEvent>) => void;
|
|
onRemove?: (item: RecordType) => void;
|
|
item: RecordType;
|
|
showRemove?: boolean;
|
|
};
|
|
|
|
const ListItem = <RecordType extends KeyWiseTransferItem>(props: ListItemProps<RecordType>) => {
|
|
const {
|
|
renderedText,
|
|
renderedEl,
|
|
item,
|
|
checked,
|
|
disabled,
|
|
prefixCls,
|
|
onClick,
|
|
onRemove,
|
|
showRemove,
|
|
} = props;
|
|
|
|
const className = classNames(`${prefixCls}-content-item`, {
|
|
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
|
|
[`${prefixCls}-content-item-checked`]: checked && !item.disabled,
|
|
});
|
|
|
|
let title: string | undefined;
|
|
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
|
|
title = String(renderedText);
|
|
}
|
|
|
|
const [contextLocale] = useLocale('Transfer', defaultLocale.Transfer);
|
|
|
|
const liProps: React.HTMLAttributes<HTMLLIElement> = { className, title };
|
|
|
|
const labelNode = <span className={`${prefixCls}-content-item-text`}>{renderedEl}</span>;
|
|
|
|
if (showRemove) {
|
|
return (
|
|
<li {...liProps}>
|
|
{labelNode}
|
|
<button
|
|
type="button"
|
|
disabled={disabled || item.disabled}
|
|
className={`${prefixCls}-content-item-remove`}
|
|
aria-label={contextLocale?.remove}
|
|
onClick={() => onRemove?.(item)}
|
|
>
|
|
<DeleteOutlined />
|
|
</button>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
// Default click to select
|
|
liProps.onClick = disabled || item.disabled ? undefined : (event) => onClick(item, event);
|
|
|
|
return (
|
|
<li {...liProps}>
|
|
<Checkbox
|
|
className={`${prefixCls}-checkbox`}
|
|
checked={checked}
|
|
disabled={disabled || item.disabled}
|
|
/>
|
|
{labelNode}
|
|
</li>
|
|
);
|
|
};
|
|
|
|
export default React.memo(ListItem);
|