Skip to content

Commit bc75ea9

Browse files
committed
chore(Pagination): Add renderPages, onCurrent, borderColor, color of Pagination
1 parent 247766a commit bc75ea9

File tree

5 files changed

+88
-25
lines changed

5 files changed

+88
-25
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component} from 'react';
2-
import {StyleSheet, View} from 'react-native';
2+
import {StyleSheet, View, Text} from 'react-native';
33
import Layout, {Container} from '../../Layout';
44
import {Pagination} from '@uiw/react-native';
55
import {ComProps} from '../../routes';
@@ -47,6 +47,8 @@ export default class Index extends Component<IndexProps, IndexState> {
4747
<View style={{paddingHorizontal: 20}}>
4848
<Pagination
4949
icon
50+
borderColor="red"
51+
color="red"
5052
current={this.state.current1}
5153
total={50}
5254
pageSize={20}

packages/core/src/Pagination/DirText.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useRef, useState, useEffect } from 'react';
2-
import { View, ViewStyle, StyleSheet, Text, TouchableOpacity, Modal, ModalProps, Animated } from 'react-native';
2+
import { View, ViewStyle, StyleSheet, Text } from 'react-native';
33
import Icon from '../Icon';
44
import Button from '../Button';
55
import { size } from './index';
@@ -20,18 +20,29 @@ export interface DirTextProps {
2020
disabled: boolean;
2121
icon: boolean;
2222
onPageChange: (type: 'prev' | 'next') => void;
23+
borderColor?: string;
24+
color?: string;
2325
}
2426

2527
const DirText = (props: DirTextProps) => {
26-
const { size, direction, disabled, icon, onPageChange } = props;
28+
const { size, direction, disabled, icon, onPageChange, borderColor = '#8d8d8d', color } = props;
2729
const dirText: '上一页' | '下一页' = useRef<'上一页' | '下一页'>(direction === 'left' ? '上一页' : '下一页').current;
28-
const [disabledStyle, setDisabledStyle] = useState<'#d9d9d9' | '#3d3d3d'>('#3d3d3d');
30+
const [disabledStyle, setDisabledStyle] = useState(1);
2931
useEffect(() => {
30-
setDisabledStyle(disabled ? '#d9d9d9' : '#3d3d3d');
32+
setDisabledStyle(disabled ? 0.4 : 1);
3133
}, [disabled]);
32-
3334
return (
34-
<View style={[styles.containerStyle, { minWidth: containerSize[size], paddingHorizontal: icon ? 0 : 5 }]}>
35+
<View
36+
style={[
37+
styles.containerStyle,
38+
{
39+
minWidth: containerSize[size],
40+
borderColor: borderColor,
41+
paddingHorizontal: icon ? 0 : 5,
42+
opacity: disabled ? disabledStyle : disabledStyle - 0.2,
43+
},
44+
]}
45+
>
3546
<Button
3647
bordered={false}
3748
disabled={disabled}
@@ -41,9 +52,9 @@ const DirText = (props: DirTextProps) => {
4152
}}
4253
>
4354
{icon ? (
44-
<Icon name={direction} size={contentSize[size]} color={disabledStyle} />
55+
<Icon name={direction} size={contentSize[size]} color={color || '#3d3d3d'} />
4556
) : (
46-
<Text style={{ color: disabledStyle }}>{dirText}</Text>
57+
<Text style={{ color: color || '#3d3d3d' }}>{dirText}</Text>
4758
)}
4859
</Button>
4960
</View>
@@ -53,7 +64,6 @@ const DirText = (props: DirTextProps) => {
5364
export const containerStyle: ViewStyle = {
5465
borderStyle: 'solid',
5566
borderWidth: 1,
56-
borderColor: '#d9d9d9',
5767
borderRadius: 2,
5868
display: 'flex',
5969
flexDirection: 'row',

packages/core/src/Pagination/Page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { View, StyleSheet, Text } from 'react-native';
2+
import { View, StyleSheet, Text, TouchableHighlight } from 'react-native';
33
import { containerStyle, containerSize, contentSize } from './DirText';
44
import { size } from './index';
55
import Button from '../Button';
@@ -9,12 +9,20 @@ export interface PageProps {
99
current: number;
1010
currentColor?: string;
1111
totalPage: number;
12+
renderPages?: (current: number, totalPage: number) => React.ReactNode;
13+
onCurrent?: (current: number, totalPage?: number) => unknown;
1214
}
1315

1416
const Page = (props: PageProps) => {
15-
const { size, currentColor, current, totalPage } = props;
17+
const { size, currentColor, current, totalPage, renderPages, onCurrent } = props;
1618
const textSize = size === 'small' ? 1 : 2;
17-
19+
if (renderPages) {
20+
return (
21+
<TouchableHighlight activeOpacity={1} underlayColor="#f1f1f1" onPress={() => onCurrent?.(current)}>
22+
{renderPages(current, totalPage)}
23+
</TouchableHighlight>
24+
);
25+
}
1826
return (
1927
<View
2028
style={[

packages/core/src/Pagination/README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ function Demo() {
5656
```ts
5757
export interface PaginationProps {
5858
/** 尺寸 */
59-
size?: 'small' | 'default' | 'large';
59+
size?: size;
6060
/** 当前页 */
61-
current?: number,
61+
current?: number;
6262
/** 当前页的颜色 */
63-
currentColor?: string
64-
/** 数据总量 */
65-
total: number,
63+
currentColor?: string;
64+
/** 自定义当前页与总页数元素 */
65+
renderPages?: (current: number,totalPage: number)=>React.ReactNode;
66+
/** 点击当前页触发 */
67+
onCurrent?: (current: number,totalPage?: number)=>unknown;
68+
/** 数据总量 */
69+
total: number;
6670
/** 每页数据量 */
67-
pageSize?: number,
71+
pageSize?: number;
6872
/** 是否以 icon 形式展示按钮 */
69-
icon?: boolean,
73+
icon?: boolean;
7074
/** 点击页码按钮时触发 */
71-
onPageChange?: (type: 'prev' | 'next', current: number) => void,
75+
onPageChange?: (type: 'prev' | 'next', current: number) => void;
76+
/** 边框颜色 */
77+
borderColor?: string
78+
/** 按钮中的颜色 */
79+
color?: string
7280
}
7381
```

packages/core/src/Pagination/index.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,36 @@ export interface PaginationProps {
1212
current?: number;
1313
/** 当前页的颜色 */
1414
currentColor?: string;
15-
/** 数据总量 */
15+
/** 自定义当前页与总页数元素 */
16+
renderPages?: (current: number, totalPage: number) => React.ReactNode;
17+
/** 点击当前页触发 */
18+
onCurrent?: (current: number, totalPage?: number) => unknown;
19+
/** 数据总量 */
1620
total: number;
1721
/** 每页数据量 */
1822
pageSize?: number;
1923
/** 是否以 icon 形式展示按钮 */
2024
icon?: boolean;
2125
/** 点击页码按钮时触发 */
2226
onPageChange?: (type: 'prev' | 'next', current: number) => void;
27+
/** 边框颜色 */
28+
borderColor?: string;
29+
/** 按钮中的颜色 */
30+
color?: string;
2331
}
2432

2533
const Pagination = (props: PaginationProps) => {
26-
const { size = 'default', icon = false, currentColor, total, pageSize = 10 } = props;
34+
const {
35+
size = 'default',
36+
icon = false,
37+
currentColor,
38+
total,
39+
pageSize = 10,
40+
borderColor,
41+
color,
42+
renderPages,
43+
onCurrent,
44+
} = props;
2745
const [current, setCurrent] = useState<number>(1);
2846
useEffect(() => {
2947
setCurrent(props.current || 1);
@@ -46,14 +64,31 @@ const Pagination = (props: PaginationProps) => {
4664

4765
return (
4866
<View style={styles.pagination}>
49-
<DirText size={size} direction="left" disabled={current === 1} icon={icon} onPageChange={onPageChange} />
50-
<Page size={size} current={current} totalPage={Math.ceil(total / pageSize)} currentColor={currentColor} />
67+
<DirText
68+
size={size}
69+
direction="left"
70+
disabled={current === 1}
71+
icon={icon}
72+
onPageChange={onPageChange}
73+
borderColor={borderColor}
74+
color={color}
75+
/>
76+
<Page
77+
renderPages={renderPages}
78+
onCurrent={onCurrent}
79+
size={size}
80+
current={current}
81+
totalPage={Math.ceil(total / pageSize)}
82+
currentColor={currentColor}
83+
/>
5184
<DirText
5285
onPageChange={onPageChange}
5386
size={size}
5487
direction="right"
5588
disabled={current === Math.ceil(total / pageSize)}
5689
icon={icon}
90+
borderColor={borderColor}
91+
color={color}
5792
/>
5893
</View>
5994
);

0 commit comments

Comments
 (0)