Skip to content

Commit

Permalink
feat: pagination support cssVar (ant-design#45800)
Browse files Browse the repository at this point in the history
* feat: pagination support cssVar

* feat: optimize code

* Update check-cssinjs.tsx

Signed-off-by: lijianan <[email protected]>

* feat: pagination css var

* chore: code clean

* chore: update snapshot

---------

Signed-off-by: lijianan <[email protected]>
Co-authored-by: lijianan <[email protected]>
Co-authored-by: MadCcc <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2023
1 parent 682904a commit f67abe4
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 176 deletions.
35 changes: 22 additions & 13 deletions components/pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import useBreakpoint from '../grid/hooks/useBreakpoint';
import { useLocale } from '../locale';
import { MiddleSelect, MiniSelect } from './Select';
import useStyle from './style';
import useCSSVar from './style/cssVar';
import { useToken } from '../theme/internal';
import BorderedStyle from './style/bordered';

export interface PaginationProps extends RcPaginationProps {
showQuickJumper?: boolean | { goButton?: React.ReactNode };
Expand Down Expand Up @@ -49,12 +52,14 @@ const Pagination: React.FC<PaginationProps> = (props) => {
...restProps
} = props;
const { xs } = useBreakpoint(responsive);
const [, token] = useToken();

const { getPrefixCls, direction, pagination = {} } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('pagination', customizePrefixCls);

// Style
const [wrapSSR, hashId] = useStyle(prefixCls);
const [, hashId] = useStyle(prefixCls);
const wrapCSSVar = useCSSVar(prefixCls);

const mergedShowSizeChanger = showSizeChanger ?? pagination.showSizeChanger;

Expand Down Expand Up @@ -111,6 +116,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
{
[`${prefixCls}-mini`]: isSmall,
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-bordered`]: token.wireframe,
},
pagination?.className,
className,
Expand All @@ -120,18 +126,21 @@ const Pagination: React.FC<PaginationProps> = (props) => {

const mergedStyle: React.CSSProperties = { ...pagination?.style, ...style };

return wrapSSR(
<RcPagination
{...iconsProps}
{...restProps}
style={mergedStyle}
prefixCls={prefixCls}
selectPrefixCls={selectPrefixCls}
className={extendedClassName}
selectComponentClass={selectComponentClass || (isSmall ? MiniSelect : MiddleSelect)}
locale={locale}
showSizeChanger={mergedShowSizeChanger}
/>,
return wrapCSSVar(
<>
{token.wireframe && <BorderedStyle prefixCls={prefixCls} />}
<RcPagination
{...iconsProps}
{...restProps}
style={mergedStyle}
prefixCls={prefixCls}
selectPrefixCls={selectPrefixCls}
className={extendedClassName}
selectComponentClass={selectComponentClass || (isSmall ? MiniSelect : MiddleSelect)}
locale={locale}
showSizeChanger={mergedShowSizeChanger}
/>
</>,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4985,7 +4985,7 @@ exports[`renders components/pagination/demo/total.tsx extend context correctly 2
exports[`renders components/pagination/demo/wireframe.tsx extend context correctly 1`] = `
Array [
<ul
class="ant-pagination"
class="ant-pagination ant-pagination-bordered"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -5323,7 +5323,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-disabled"
class="ant-pagination ant-pagination-bordered ant-pagination-disabled"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -5662,7 +5662,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini ant-pagination-bordered"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -6000,7 +6000,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-mini ant-pagination-disabled"
class="ant-pagination ant-pagination-mini ant-pagination-bordered ant-pagination-disabled"
>
<li
aria-disabled="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3624,7 +3624,7 @@ Array [
exports[`renders components/pagination/demo/wireframe.tsx correctly 1`] = `
Array [
<ul
class="ant-pagination"
class="ant-pagination ant-pagination-bordered"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -3859,7 +3859,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-disabled"
class="ant-pagination ant-pagination-bordered ant-pagination-disabled"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -4095,7 +4095,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-mini"
class="ant-pagination ant-pagination-mini ant-pagination-bordered"
>
<li
aria-disabled="false"
Expand Down Expand Up @@ -4330,7 +4330,7 @@ Array [
</ul>,
<br />,
<ul
class="ant-pagination ant-pagination-mini ant-pagination-disabled"
class="ant-pagination ant-pagination-mini ant-pagination-bordered ant-pagination-disabled"
>
<li
aria-disabled="false"
Expand Down
111 changes: 111 additions & 0 deletions components/pagination/style/bordered.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { genSubStyleComponent } from '../../theme/util/genComponentStyleHook';
import type { PaginationToken } from '.';
import { prepareComponentToken, prepareToken } from '.';
import type { GenerateStyle } from '../../theme/interface';
import { unit } from '@ant-design/cssinjs';

const genBorderedStyle: GenerateStyle<PaginationToken> = (token) => {
const { componentCls } = token;

return {
[`${componentCls}${componentCls}-bordered${componentCls}-disabled:not(${componentCls}-mini)`]: {
'&, &:hover': {
[`${componentCls}-item-link`]: {
borderColor: token.colorBorder,
},
},

'&:focus-visible': {
[`${componentCls}-item-link`]: {
borderColor: token.colorBorder,
},
},

[`${componentCls}-item, ${componentCls}-item-link`]: {
backgroundColor: token.colorBgContainerDisabled,
borderColor: token.colorBorder,

[`&:hover:not(${componentCls}-item-active)`]: {
backgroundColor: token.colorBgContainerDisabled,
borderColor: token.colorBorder,

a: {
color: token.colorTextDisabled,
},
},

[`&${componentCls}-item-active`]: {
backgroundColor: token.itemActiveBgDisabled,
},
},

[`${componentCls}-prev, ${componentCls}-next`]: {
'&:hover button': {
backgroundColor: token.colorBgContainerDisabled,
borderColor: token.colorBorder,
color: token.colorTextDisabled,
},

[`${componentCls}-item-link`]: {
backgroundColor: token.colorBgContainerDisabled,
borderColor: token.colorBorder,
},
},
},

[`${componentCls}${componentCls}-bordered:not(${componentCls}-mini)`]: {
[`${componentCls}-prev, ${componentCls}-next`]: {
'&:hover button': {
borderColor: token.colorPrimaryHover,
backgroundColor: token.itemBg,
},

[`${componentCls}-item-link`]: {
backgroundColor: token.itemLinkBg,
borderColor: token.colorBorder,
},

[`&:hover ${componentCls}-item-link`]: {
borderColor: token.colorPrimary,
backgroundColor: token.itemBg,
color: token.colorPrimary,
},

[`&${componentCls}-disabled`]: {
[`${componentCls}-item-link`]: {
borderColor: token.colorBorder,
color: token.colorTextDisabled,
},
},
},

[`${componentCls}-item`]: {
backgroundColor: token.itemBg,
border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,

[`&:hover:not(${componentCls}-item-active)`]: {
borderColor: token.colorPrimary,
backgroundColor: token.itemBg,

a: {
color: token.colorPrimary,
},
},

'&-active': {
borderColor: token.colorPrimary,
},
},
},
};
};

export default genSubStyleComponent(
['Pagination', 'bordered'],
(token) => {
const paginationToken = prepareToken(token);

return [genBorderedStyle(paginationToken)];
},
prepareComponentToken,
);
4 changes: 4 additions & 0 deletions components/pagination/style/cssVar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { genCSSVarRegister } from '../../theme/internal';
import { prepareComponentToken } from '.';

export default genCSSVarRegister('Pagination', prepareComponentToken);
Loading

0 comments on commit f67abe4

Please sign in to comment.