Skip to content

feat: support classnames and styles #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Pager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
page: number;
active?: boolean;
className?: string;
style?: React.CSSProperties;
showTitle: boolean;
onClick?: (page: number) => void;
onKeyPress?: (
Expand All @@ -23,6 +24,7 @@ const Pager: React.FC<PagerProps> = (props) => {
page,
active,
className,
style,
showTitle,
onClick,
onKeyPress,
Expand Down Expand Up @@ -54,6 +56,7 @@ const Pager: React.FC<PagerProps> = (props) => {
<li
title={showTitle ? String(page) : null}
className={cls}
style={style}
onClick={handleClick}
onKeyDown={handleKeyPress}
tabIndex={0}
Expand Down
4 changes: 4 additions & 0 deletions src/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const Pagination: React.FC<PaginationProps> = (props) => {
prefixCls = 'rc-pagination',
selectPrefixCls = 'rc-select',
className,
classNames: paginationClassNames,
styles,

// control
current: currentProp,
Expand Down Expand Up @@ -332,6 +334,8 @@ const Pagination: React.FC<PaginationProps> = (props) => {
showTitle,
itemRender,
page: -1,
className: paginationClassNames?.item,
style: styles?.item,
};

const prevPage = current - 1 > 0 ? current - 1 : 0;
Expand Down
4 changes: 4 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export interface PaginationLocale {
page_size?: string;
}

type SemanticName = 'item';

export interface PaginationData {
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
classNames?: Partial<Record<SemanticName, string>>;
className: string;
selectPrefixCls: string;
prefixCls: string;
Expand Down
13 changes: 13 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ describe('Controlled Pagination', () => {
});

describe('Other props', () => {
it('support classnames and styles', () => {
const { container } = render(
<Pagination
total={1000}
current={12}
classNames={{ item: 'custom-test' }}
styles={{ item: { color: 'red' } }}
/>,
);
const item = container.querySelector('.rc-pagination-item');
expect(item).toHaveClass('custom-test');
expect(item).toHaveStyle('color: red');
});
it('should support custom default icon', () => {
const nextIcon = () => <span>nextIcon</span>;
const prevIcon = () => <span>prevIcon</span>;
Expand Down
Loading