Skip to content

Commit d7db286

Browse files
author
杨楠
committed
feat:Pagination 增加页码跳转功能
1 parent a9dce06 commit d7db286

File tree

4 files changed

+118
-10
lines changed

4 files changed

+118
-10
lines changed

example/examples/src/routes/Pagination/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ export default class Index extends Component<IndexProps, IndexState> {
4343
/>
4444
</View>
4545
</Card>
46+
<Card title="使用跳转页码">
47+
<View style={{paddingHorizontal: 20}}>
48+
<Pagination
49+
icon
50+
jumpBtn={true}
51+
current={this.state.current1}
52+
total={50}
53+
pageSize={20}
54+
onPageChange={(type, current1) => {
55+
this.setState({current1});
56+
}}
57+
/>
58+
</View>
59+
</Card>
4660
<Card title="使用icon">
4761
<View style={{paddingHorizontal: 20}}>
4862
<Pagination
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { useRef, useState, useEffect } from 'react';
2+
import { View, ViewStyle, TextStyle, StyleSheet, Text, TextInput } from 'react-native';
3+
import Icon from '../Icon';
4+
import Button from '../Button';
5+
import { size } from './index';
6+
import { number } from 'prop-types';
7+
8+
export enum containerSize {
9+
small = 30,
10+
default = 36,
11+
large = 44,
12+
}
13+
export enum contentSize {
14+
small = 12,
15+
default = 18,
16+
large = 26,
17+
}
18+
export interface MoreDirProps {
19+
size: size;
20+
borderColor?: string;
21+
color?: string;
22+
setCurrent: React.Dispatch<React.SetStateAction<number>>;
23+
current: number;
24+
}
25+
26+
const MoreDir = (props: MoreDirProps) => {
27+
const { size, borderColor = '#8d8d8d', color, setCurrent, current } = props;
28+
const [jumpCurrent, setJumpCurrent] = useState(1);
29+
30+
return (
31+
<View style={styles.containerStyle}>
32+
<Text>跳至</Text>
33+
<TextInput
34+
keyboardType="numeric"
35+
onSubmitEditing={() => {
36+
setCurrent(Number(jumpCurrent));
37+
}}
38+
onBlur={() => {
39+
setCurrent(Number(jumpCurrent));
40+
}}
41+
blurOnSubmit={true}
42+
onChangeText={(text) => {
43+
let textCurrent: number = Number(text);
44+
if (textCurrent >= current) {
45+
setJumpCurrent(current);
46+
} else if (textCurrent < current) {
47+
setJumpCurrent(textCurrent);
48+
}
49+
}}
50+
style={styles.inputStyle}
51+
/>
52+
<Text></Text>
53+
</View>
54+
);
55+
};
56+
57+
export const containerStyle: ViewStyle = {
58+
flexDirection: 'row',
59+
justifyContent: 'center',
60+
alignItems: 'center',
61+
marginLeft: 5,
62+
};
63+
export const inputStyle: ViewStyle | TextStyle = {
64+
height: 27,
65+
width: 33,
66+
borderColor: 'gray',
67+
borderWidth: 0.5,
68+
textAlign: 'center',
69+
padding: 2,
70+
marginHorizontal: 3,
71+
};
72+
const styles = StyleSheet.create({
73+
containerStyle,
74+
inputStyle,
75+
});
76+
export default MoreDir;

packages/core/src/Pagination/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Demo() {
2828
}
2929
```
3030

31-
### 使用icon && 修改大小
31+
### 使用icon && 修改大小 && 页码跳转
3232

3333
```jsx
3434
import { Fragment, useState } from 'react';
@@ -43,6 +43,7 @@ function Demo() {
4343
current={current}
4444
total={60}
4545
pageSize={8}
46+
jumpBtn={true}
4647
onPageChange={(type, current) => {
4748
setCurrent(current)
4849
console.log('type, current: ', type, current);
@@ -79,5 +80,7 @@ export interface PaginationProps {
7980
borderColor?: string
8081
/** 按钮中的颜色 */
8182
color?: string
83+
/** 页码跳转 */
84+
jumpBtn?: boolean;
8285
}
8386
```

packages/core/src/Pagination/index.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { View, StyleSheet } from 'react-native';
33
import DirText from './DirText';
4+
import MoreDir from './MoreDir';
45
import Page from './Page';
56

67
export type size = 'small' | 'default' | 'large';
@@ -28,12 +29,15 @@ export interface PaginationProps {
2829
borderColor?: string;
2930
/** 按钮中的颜色 */
3031
color?: string;
32+
/** 页码跳转 */
33+
jumpBtn?: boolean;
3134
}
3235

3336
const Pagination = (props: PaginationProps) => {
3437
const {
3538
size = 'default',
3639
icon = false,
40+
jumpBtn = false,
3741
currentColor,
3842
total,
3943
pageSize = 10,
@@ -81,15 +85,26 @@ const Pagination = (props: PaginationProps) => {
8185
totalPage={Math.ceil(total / pageSize)}
8286
currentColor={currentColor}
8387
/>
84-
<DirText
85-
onPageChange={onPageChange}
86-
size={size}
87-
direction="right"
88-
disabled={current === Math.ceil(total / pageSize)}
89-
icon={icon}
90-
borderColor={borderColor}
91-
color={color}
92-
/>
88+
<View style={{ flexDirection: 'row' }}>
89+
<DirText
90+
onPageChange={onPageChange}
91+
size={size}
92+
direction="right"
93+
disabled={current === Math.ceil(total / pageSize)}
94+
icon={icon}
95+
borderColor={borderColor}
96+
color={color}
97+
/>
98+
{jumpBtn === true && (
99+
<MoreDir
100+
setCurrent={setCurrent}
101+
size={size}
102+
current={Math.ceil(total / pageSize)}
103+
borderColor={borderColor}
104+
color={color}
105+
/>
106+
)}
107+
</View>
93108
</View>
94109
);
95110
};

0 commit comments

Comments
 (0)