-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathPager.tsx
68 lines (66 loc) · 1.72 KB
/
Pager.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
import type { CSSProperties } from 'vue';
import { defineComponent } from 'vue';
import classNames from '../_util/classNames';
import PropTypes from '../_util/vue-types';
export default defineComponent({
compatConfig: { MODE: 3 },
name: 'Pager',
inheritAttrs: false,
props: {
rootPrefixCls: String,
page: Number,
active: { type: Boolean, default: undefined },
last: { type: Boolean, default: undefined },
locale: PropTypes.object,
showTitle: { type: Boolean, default: undefined },
itemRender: {
type: Function,
default: () => {},
},
onClick: {
type: Function,
},
onKeypress: {
type: Function,
},
},
emits: ['click', 'keypress'],
setup(props, { emit, attrs }) {
const handleClick = () => {
emit('click', props.page);
};
const handleKeyPress = (event: KeyboardEvent) => {
emit('keypress', event, handleClick, props.page);
};
return () => {
const { showTitle, page, itemRender } = props;
const { class: _cls, style } = attrs;
const prefixCls = `${props.rootPrefixCls}-item`;
const cls = classNames(
prefixCls,
`${prefixCls}-${props.page}`,
{
[`${prefixCls}-active`]: props.active,
[`${prefixCls}-disabled`]: !props.page,
},
_cls,
);
return (
<li
onClick={handleClick}
onKeypress={handleKeyPress}
title={showTitle ? String(page) : null}
tabindex="0"
class={cls}
style={style as CSSProperties}
>
{itemRender({
page,
type: 'page',
originalElement: <a rel="nofollow">{page}</a>,
})}
</li>
);
};
},
});