-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathListItem.tsx
117 lines (110 loc) · 3.46 KB
/
ListItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import PropTypes, { withUndefined } from '../_util/vue-types';
import classNames from '../_util/classNames';
import { TransferLocale } from '.';
import DeleteOutlined from '@ant-design/icons-vue/DeleteOutlined';
import defaultLocale from '../locale/default';
import Lazyload from '../vc-lazy-load';
import Checkbox from '../checkbox';
import TransButton from '../_util/transButton';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { defineComponent, ExtractPropTypes } from 'vue';
function noop() {}
export const transferListItemProps = {
renderedText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
renderedEl: PropTypes.any,
item: PropTypes.any,
lazy: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object])),
checked: PropTypes.looseBool,
prefixCls: PropTypes.string,
disabled: PropTypes.looseBool,
showRemove: PropTypes.looseBool,
onClick: PropTypes.func,
onRemove: PropTypes.func,
};
export type TransferListItemProps = Partial<ExtractPropTypes<typeof transferListItemProps>>;
export default defineComponent({
name: 'ListItem',
inheritAttrs: false,
props: transferListItemProps,
emits: ['click'],
setup(props, { emit }) {
return () => {
const {
renderedText,
renderedEl,
item,
lazy,
checked,
disabled,
prefixCls,
showRemove,
onRemove,
} = props;
const className = classNames({
[`${prefixCls}-content-item`]: true,
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
});
let title: string;
if (typeof renderedText === 'string' || typeof renderedText === 'number') {
title = String(renderedText);
}
const listItem = (
<LocaleReceiver componentName="Transfer" defaultLocale={defaultLocale.Transfer}>
{(transferLocale: TransferLocale) => {
const labelNode = <span class={`${prefixCls}-content-item-text`}>{renderedEl}</span>;
if (showRemove) {
return (
<li
class={className}
title={title}
onClick={() => {
onRemove?.(item);
}}
>
{labelNode}
<TransButton
disabled={disabled || item.disabled}
class={`${prefixCls}-content-item-remove`}
aria-label={transferLocale.remove}
>
<DeleteOutlined />
</TransButton>
</li>
);
}
return (
<li
class={className}
title={title}
onClick={
disabled || item.disabled
? noop
: () => {
emit('click', item);
}
}
>
<Checkbox checked={checked} disabled={disabled || item.disabled} />
{labelNode}
</li>
);
}}
</LocaleReceiver>
);
let children = null;
if (lazy) {
const lazyProps = {
height: 32,
offset: 500,
throttle: 0,
debounce: false,
...(lazy as any),
};
children = <Lazyload {...lazyProps}>{listItem}</Lazyload>;
} else {
children = listItem;
}
return children;
};
},
});