Skip to content

Commit 47c07ce

Browse files
authored
feat: support classnames and styles (#641)
1 parent eb2b65e commit 47c07ce

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/Pager.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
88
page: number;
99
active?: boolean;
1010
className?: string;
11+
style?: React.CSSProperties;
1112
showTitle: boolean;
1213
onClick?: (page: number) => void;
1314
onKeyPress?: (
@@ -23,6 +24,7 @@ const Pager: React.FC<PagerProps> = (props) => {
2324
page,
2425
active,
2526
className,
27+
style,
2628
showTitle,
2729
onClick,
2830
onKeyPress,
@@ -54,6 +56,7 @@ const Pager: React.FC<PagerProps> = (props) => {
5456
<li
5557
title={showTitle ? String(page) : null}
5658
className={cls}
59+
style={style}
5760
onClick={handleClick}
5861
onKeyDown={handleKeyPress}
5962
tabIndex={0}

src/Pagination.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const Pagination: React.FC<PaginationProps> = (props) => {
3636
prefixCls = 'rc-pagination',
3737
selectPrefixCls = 'rc-select',
3838
className,
39+
classNames: paginationClassNames,
40+
styles,
3941

4042
// control
4143
current: currentProp,
@@ -332,6 +334,8 @@ const Pagination: React.FC<PaginationProps> = (props) => {
332334
showTitle,
333335
itemRender,
334336
page: -1,
337+
className: paginationClassNames?.item,
338+
style: styles?.item,
335339
};
336340

337341
const prevPage = current - 1 > 0 ? current - 1 : 0;

src/interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export interface PaginationLocale {
1818
page_size?: string;
1919
}
2020

21+
type SemanticName = 'item';
22+
2123
export interface PaginationData {
24+
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
25+
classNames?: Partial<Record<SemanticName, string>>;
2226
className: string;
2327
selectPrefixCls: string;
2428
prefixCls: string;

tests/index.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ describe('Controlled Pagination', () => {
241241
});
242242

243243
describe('Other props', () => {
244+
it('support classnames and styles', () => {
245+
const { container } = render(
246+
<Pagination
247+
total={1000}
248+
current={12}
249+
classNames={{ item: 'custom-test' }}
250+
styles={{ item: { color: 'red' } }}
251+
/>,
252+
);
253+
const item = container.querySelector('.rc-pagination-item');
254+
expect(item).toHaveClass('custom-test');
255+
expect(item).toHaveStyle('color: red');
256+
});
244257
it('should support custom default icon', () => {
245258
const nextIcon = () => <span>nextIcon</span>;
246259
const prevIcon = () => <span>prevIcon</span>;

0 commit comments

Comments
 (0)