index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. import { unit } from '@ant-design/cssinjs';
  2. import { genBasicInputStyle, genInputSmallStyle, initComponentToken, initInputToken } from '../../input/style';
  3. import { genBaseOutlinedStyle, genDisabledStyle } from '../../input/style/variants';
  4. import { genFocusOutline, genFocusStyle, resetComponent } from '../../style';
  5. import { genStyleHooks, mergeToken } from '../../theme/internal';
  6. const genPaginationDisabledStyle = token => {
  7. const {
  8. componentCls
  9. } = token;
  10. return {
  11. [`${componentCls}-disabled`]: {
  12. '&, &:hover': {
  13. cursor: 'not-allowed',
  14. [`${componentCls}-item-link`]: {
  15. color: token.colorTextDisabled,
  16. cursor: 'not-allowed'
  17. }
  18. },
  19. '&:focus-visible': {
  20. cursor: 'not-allowed',
  21. [`${componentCls}-item-link`]: {
  22. color: token.colorTextDisabled,
  23. cursor: 'not-allowed'
  24. }
  25. }
  26. },
  27. [`&${componentCls}-disabled`]: {
  28. cursor: 'not-allowed',
  29. [`${componentCls}-item`]: {
  30. cursor: 'not-allowed',
  31. backgroundColor: 'transparent',
  32. '&:hover, &:active': {
  33. backgroundColor: 'transparent'
  34. },
  35. a: {
  36. color: token.colorTextDisabled,
  37. backgroundColor: 'transparent',
  38. border: 'none',
  39. cursor: 'not-allowed'
  40. },
  41. '&-active': {
  42. borderColor: token.colorBorder,
  43. backgroundColor: token.itemActiveBgDisabled,
  44. '&:hover, &:active': {
  45. backgroundColor: token.itemActiveBgDisabled
  46. },
  47. a: {
  48. color: token.itemActiveColorDisabled
  49. }
  50. }
  51. },
  52. [`${componentCls}-item-link`]: {
  53. color: token.colorTextDisabled,
  54. cursor: 'not-allowed',
  55. '&:hover, &:active': {
  56. backgroundColor: 'transparent'
  57. },
  58. [`${componentCls}-simple&`]: {
  59. backgroundColor: 'transparent',
  60. '&:hover, &:active': {
  61. backgroundColor: 'transparent'
  62. }
  63. }
  64. },
  65. [`${componentCls}-simple-pager`]: {
  66. color: token.colorTextDisabled
  67. },
  68. [`${componentCls}-jump-prev, ${componentCls}-jump-next`]: {
  69. [`${componentCls}-item-link-icon`]: {
  70. opacity: 0
  71. },
  72. [`${componentCls}-item-ellipsis`]: {
  73. opacity: 1
  74. }
  75. }
  76. }
  77. };
  78. };
  79. const genPaginationMiniStyle = token => {
  80. const {
  81. componentCls
  82. } = token;
  83. return {
  84. [`&${componentCls}-mini ${componentCls}-total-text, &${componentCls}-mini ${componentCls}-simple-pager`]: {
  85. height: token.itemSizeSM,
  86. lineHeight: unit(token.itemSizeSM)
  87. },
  88. [`&${componentCls}-mini ${componentCls}-item`]: {
  89. minWidth: token.itemSizeSM,
  90. height: token.itemSizeSM,
  91. margin: 0,
  92. lineHeight: unit(token.calc(token.itemSizeSM).sub(2).equal())
  93. },
  94. [`&${componentCls}-mini ${componentCls}-prev, &${componentCls}-mini ${componentCls}-next`]: {
  95. minWidth: token.itemSizeSM,
  96. height: token.itemSizeSM,
  97. margin: 0,
  98. lineHeight: unit(token.itemSizeSM)
  99. },
  100. [`&${componentCls}-mini:not(${componentCls}-disabled)`]: {
  101. [`${componentCls}-prev, ${componentCls}-next`]: {
  102. [`&:hover ${componentCls}-item-link`]: {
  103. backgroundColor: token.colorBgTextHover
  104. },
  105. [`&:active ${componentCls}-item-link`]: {
  106. backgroundColor: token.colorBgTextActive
  107. },
  108. [`&${componentCls}-disabled:hover ${componentCls}-item-link`]: {
  109. backgroundColor: 'transparent'
  110. }
  111. }
  112. },
  113. [`
  114. &${componentCls}-mini ${componentCls}-prev ${componentCls}-item-link,
  115. &${componentCls}-mini ${componentCls}-next ${componentCls}-item-link
  116. `]: {
  117. backgroundColor: 'transparent',
  118. borderColor: 'transparent',
  119. '&::after': {
  120. height: token.itemSizeSM,
  121. lineHeight: unit(token.itemSizeSM)
  122. }
  123. },
  124. [`&${componentCls}-mini ${componentCls}-jump-prev, &${componentCls}-mini ${componentCls}-jump-next`]: {
  125. height: token.itemSizeSM,
  126. marginInlineEnd: 0,
  127. lineHeight: unit(token.itemSizeSM)
  128. },
  129. [`&${componentCls}-mini ${componentCls}-options`]: {
  130. marginInlineStart: token.paginationMiniOptionsMarginInlineStart,
  131. '&-size-changer': {
  132. top: token.miniOptionsSizeChangerTop
  133. },
  134. '&-quick-jumper': {
  135. height: token.itemSizeSM,
  136. lineHeight: unit(token.itemSizeSM),
  137. input: Object.assign(Object.assign({}, genInputSmallStyle(token)), {
  138. width: token.paginationMiniQuickJumperInputWidth,
  139. height: token.controlHeightSM
  140. })
  141. }
  142. }
  143. };
  144. };
  145. const genPaginationSimpleStyle = token => {
  146. const {
  147. componentCls
  148. } = token;
  149. return {
  150. [`&${componentCls}-simple`]: {
  151. [`${componentCls}-prev, ${componentCls}-next`]: {
  152. height: token.itemSize,
  153. lineHeight: unit(token.itemSize),
  154. verticalAlign: 'top',
  155. [`${componentCls}-item-link`]: {
  156. height: token.itemSize,
  157. backgroundColor: 'transparent',
  158. border: 0,
  159. '&:hover': {
  160. backgroundColor: token.colorBgTextHover
  161. },
  162. '&:active': {
  163. backgroundColor: token.colorBgTextActive
  164. },
  165. '&::after': {
  166. height: token.itemSize,
  167. lineHeight: unit(token.itemSize)
  168. }
  169. }
  170. },
  171. [`${componentCls}-simple-pager`]: {
  172. display: 'inline-flex',
  173. alignItems: 'center',
  174. height: token.itemSize,
  175. marginInlineEnd: token.marginXS,
  176. input: {
  177. boxSizing: 'border-box',
  178. height: '100%',
  179. width: token.quickJumperInputWidth,
  180. padding: `0 ${unit(token.paginationItemPaddingInline)}`,
  181. textAlign: 'center',
  182. backgroundColor: token.itemInputBg,
  183. border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`,
  184. borderRadius: token.borderRadius,
  185. outline: 'none',
  186. transition: `border-color ${token.motionDurationMid}`,
  187. color: 'inherit',
  188. '&:hover': {
  189. borderColor: token.colorPrimary
  190. },
  191. '&:focus': {
  192. borderColor: token.colorPrimaryHover,
  193. boxShadow: `${unit(token.inputOutlineOffset)} 0 ${unit(token.controlOutlineWidth)} ${token.controlOutline}`
  194. },
  195. '&[disabled]': {
  196. color: token.colorTextDisabled,
  197. backgroundColor: token.colorBgContainerDisabled,
  198. borderColor: token.colorBorder,
  199. cursor: 'not-allowed'
  200. }
  201. }
  202. },
  203. [`&${componentCls}-disabled`]: {
  204. [`${componentCls}-prev, ${componentCls}-next`]: {
  205. [`${componentCls}-item-link`]: {
  206. '&:hover, &:active': {
  207. backgroundColor: 'transparent'
  208. }
  209. }
  210. }
  211. },
  212. [`&${componentCls}-mini`]: {
  213. [`${componentCls}-prev, ${componentCls}-next`]: {
  214. height: token.itemSizeSM,
  215. lineHeight: unit(token.itemSizeSM),
  216. [`${componentCls}-item-link`]: {
  217. height: token.itemSizeSM,
  218. '&::after': {
  219. height: token.itemSizeSM,
  220. lineHeight: unit(token.itemSizeSM)
  221. }
  222. }
  223. },
  224. [`${componentCls}-simple-pager`]: {
  225. height: token.itemSizeSM,
  226. input: {
  227. width: token.paginationMiniQuickJumperInputWidth
  228. }
  229. }
  230. }
  231. }
  232. };
  233. };
  234. const genPaginationJumpStyle = token => {
  235. const {
  236. componentCls
  237. } = token;
  238. return {
  239. [`${componentCls}-jump-prev, ${componentCls}-jump-next`]: {
  240. outline: 0,
  241. [`${componentCls}-item-container`]: {
  242. position: 'relative',
  243. [`${componentCls}-item-link-icon`]: {
  244. color: token.colorPrimary,
  245. fontSize: token.fontSizeSM,
  246. opacity: 0,
  247. transition: `all ${token.motionDurationMid}`,
  248. '&-svg': {
  249. top: 0,
  250. insetInlineEnd: 0,
  251. bottom: 0,
  252. insetInlineStart: 0,
  253. margin: 'auto'
  254. }
  255. },
  256. [`${componentCls}-item-ellipsis`]: {
  257. position: 'absolute',
  258. top: 0,
  259. insetInlineEnd: 0,
  260. bottom: 0,
  261. insetInlineStart: 0,
  262. display: 'block',
  263. margin: 'auto',
  264. color: token.colorTextDisabled,
  265. letterSpacing: token.paginationEllipsisLetterSpacing,
  266. textAlign: 'center',
  267. textIndent: token.paginationEllipsisTextIndent,
  268. opacity: 1,
  269. transition: `all ${token.motionDurationMid}`
  270. }
  271. },
  272. '&:hover': {
  273. [`${componentCls}-item-link-icon`]: {
  274. opacity: 1
  275. },
  276. [`${componentCls}-item-ellipsis`]: {
  277. opacity: 0
  278. }
  279. }
  280. },
  281. [`
  282. ${componentCls}-prev,
  283. ${componentCls}-jump-prev,
  284. ${componentCls}-jump-next
  285. `]: {
  286. marginInlineEnd: token.marginXS
  287. },
  288. [`
  289. ${componentCls}-prev,
  290. ${componentCls}-next,
  291. ${componentCls}-jump-prev,
  292. ${componentCls}-jump-next
  293. `]: {
  294. display: 'inline-block',
  295. minWidth: token.itemSize,
  296. height: token.itemSize,
  297. color: token.colorText,
  298. fontFamily: token.fontFamily,
  299. lineHeight: unit(token.itemSize),
  300. textAlign: 'center',
  301. verticalAlign: 'middle',
  302. listStyle: 'none',
  303. borderRadius: token.borderRadius,
  304. cursor: 'pointer',
  305. transition: `all ${token.motionDurationMid}`
  306. },
  307. [`${componentCls}-prev, ${componentCls}-next`]: {
  308. outline: 0,
  309. button: {
  310. color: token.colorText,
  311. cursor: 'pointer',
  312. userSelect: 'none'
  313. },
  314. [`${componentCls}-item-link`]: {
  315. display: 'block',
  316. width: '100%',
  317. height: '100%',
  318. padding: 0,
  319. fontSize: token.fontSizeSM,
  320. textAlign: 'center',
  321. backgroundColor: 'transparent',
  322. border: `${unit(token.lineWidth)} ${token.lineType} transparent`,
  323. borderRadius: token.borderRadius,
  324. outline: 'none',
  325. transition: `all ${token.motionDurationMid}`
  326. },
  327. [`&:hover ${componentCls}-item-link`]: {
  328. backgroundColor: token.colorBgTextHover
  329. },
  330. [`&:active ${componentCls}-item-link`]: {
  331. backgroundColor: token.colorBgTextActive
  332. },
  333. [`&${componentCls}-disabled:hover`]: {
  334. [`${componentCls}-item-link`]: {
  335. backgroundColor: 'transparent'
  336. }
  337. }
  338. },
  339. [`${componentCls}-slash`]: {
  340. marginInlineEnd: token.paginationSlashMarginInlineEnd,
  341. marginInlineStart: token.paginationSlashMarginInlineStart
  342. },
  343. [`${componentCls}-options`]: {
  344. display: 'inline-block',
  345. marginInlineStart: token.margin,
  346. verticalAlign: 'middle',
  347. '&-size-changer': {
  348. display: 'inline-block',
  349. width: 'auto'
  350. },
  351. '&-quick-jumper': {
  352. display: 'inline-block',
  353. height: token.controlHeight,
  354. marginInlineStart: token.marginXS,
  355. lineHeight: unit(token.controlHeight),
  356. verticalAlign: 'top',
  357. input: Object.assign(Object.assign(Object.assign({}, genBasicInputStyle(token)), genBaseOutlinedStyle(token, {
  358. borderColor: token.colorBorder,
  359. hoverBorderColor: token.colorPrimaryHover,
  360. activeBorderColor: token.colorPrimary,
  361. activeShadow: token.activeShadow
  362. })), {
  363. '&[disabled]': Object.assign({}, genDisabledStyle(token)),
  364. width: token.quickJumperInputWidth,
  365. height: token.controlHeight,
  366. boxSizing: 'border-box',
  367. margin: 0,
  368. marginInlineStart: token.marginXS,
  369. marginInlineEnd: token.marginXS
  370. })
  371. }
  372. }
  373. };
  374. };
  375. const genPaginationItemStyle = token => {
  376. const {
  377. componentCls
  378. } = token;
  379. return {
  380. [`${componentCls}-item`]: {
  381. display: 'inline-block',
  382. minWidth: token.itemSize,
  383. height: token.itemSize,
  384. marginInlineEnd: token.marginXS,
  385. fontFamily: token.fontFamily,
  386. lineHeight: unit(token.calc(token.itemSize).sub(2).equal()),
  387. textAlign: 'center',
  388. verticalAlign: 'middle',
  389. listStyle: 'none',
  390. backgroundColor: token.itemBg,
  391. border: `${unit(token.lineWidth)} ${token.lineType} transparent`,
  392. borderRadius: token.borderRadius,
  393. outline: 0,
  394. cursor: 'pointer',
  395. userSelect: 'none',
  396. a: {
  397. display: 'block',
  398. padding: `0 ${unit(token.paginationItemPaddingInline)}`,
  399. color: token.colorText,
  400. '&:hover': {
  401. textDecoration: 'none'
  402. }
  403. },
  404. [`&:not(${componentCls}-item-active)`]: {
  405. '&:hover': {
  406. transition: `all ${token.motionDurationMid}`,
  407. backgroundColor: token.colorBgTextHover
  408. },
  409. '&:active': {
  410. backgroundColor: token.colorBgTextActive
  411. }
  412. },
  413. '&-active': {
  414. fontWeight: token.fontWeightStrong,
  415. backgroundColor: token.itemActiveBg,
  416. borderColor: token.colorPrimary,
  417. a: {
  418. color: token.colorPrimary
  419. },
  420. '&:hover': {
  421. borderColor: token.colorPrimaryHover
  422. },
  423. '&:hover a': {
  424. color: token.colorPrimaryHover
  425. }
  426. }
  427. }
  428. };
  429. };
  430. const genPaginationStyle = token => {
  431. const {
  432. componentCls
  433. } = token;
  434. return {
  435. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, resetComponent(token)), {
  436. display: 'flex',
  437. '&-start': {
  438. justifyContent: 'start'
  439. },
  440. '&-center': {
  441. justifyContent: 'center'
  442. },
  443. '&-end': {
  444. justifyContent: 'end'
  445. },
  446. 'ul, ol': {
  447. margin: 0,
  448. padding: 0,
  449. listStyle: 'none'
  450. },
  451. '&::after': {
  452. display: 'block',
  453. clear: 'both',
  454. height: 0,
  455. overflow: 'hidden',
  456. visibility: 'hidden',
  457. content: '""'
  458. },
  459. [`${componentCls}-total-text`]: {
  460. display: 'inline-block',
  461. height: token.itemSize,
  462. marginInlineEnd: token.marginXS,
  463. lineHeight: unit(token.calc(token.itemSize).sub(2).equal()),
  464. verticalAlign: 'middle'
  465. }
  466. }), genPaginationItemStyle(token)), genPaginationJumpStyle(token)), genPaginationSimpleStyle(token)), genPaginationMiniStyle(token)), genPaginationDisabledStyle(token)), {
  467. // media query style
  468. [`@media only screen and (max-width: ${token.screenLG}px)`]: {
  469. [`${componentCls}-item`]: {
  470. '&-after-jump-prev, &-before-jump-next': {
  471. display: 'none'
  472. }
  473. }
  474. },
  475. [`@media only screen and (max-width: ${token.screenSM}px)`]: {
  476. [`${componentCls}-options`]: {
  477. display: 'none'
  478. }
  479. }
  480. }),
  481. // rtl style
  482. [`&${token.componentCls}-rtl`]: {
  483. direction: 'rtl'
  484. }
  485. };
  486. };
  487. const genPaginationFocusStyle = token => {
  488. const {
  489. componentCls
  490. } = token;
  491. return {
  492. [`${componentCls}:not(${componentCls}-disabled)`]: {
  493. [`${componentCls}-item`]: Object.assign({}, genFocusStyle(token)),
  494. [`${componentCls}-jump-prev, ${componentCls}-jump-next`]: {
  495. '&:focus-visible': Object.assign({
  496. [`${componentCls}-item-link-icon`]: {
  497. opacity: 1
  498. },
  499. [`${componentCls}-item-ellipsis`]: {
  500. opacity: 0
  501. }
  502. }, genFocusOutline(token))
  503. },
  504. [`${componentCls}-prev, ${componentCls}-next`]: {
  505. [`&:focus-visible ${componentCls}-item-link`]: genFocusOutline(token)
  506. }
  507. }
  508. };
  509. };
  510. export const prepareComponentToken = token => Object.assign({
  511. itemBg: token.colorBgContainer,
  512. itemSize: token.controlHeight,
  513. itemSizeSM: token.controlHeightSM,
  514. itemActiveBg: token.colorBgContainer,
  515. itemLinkBg: token.colorBgContainer,
  516. itemActiveColorDisabled: token.colorTextDisabled,
  517. itemActiveBgDisabled: token.controlItemBgActiveDisabled,
  518. itemInputBg: token.colorBgContainer,
  519. miniOptionsSizeChangerTop: 0
  520. }, initComponentToken(token));
  521. export const prepareToken = token => mergeToken(token, {
  522. inputOutlineOffset: 0,
  523. quickJumperInputWidth: token.calc(token.controlHeightLG).mul(1.25).equal(),
  524. paginationMiniOptionsMarginInlineStart: token.calc(token.marginXXS).div(2).equal(),
  525. paginationMiniQuickJumperInputWidth: token.calc(token.controlHeightLG).mul(1.1).equal(),
  526. paginationItemPaddingInline: token.calc(token.marginXXS).mul(1.5).equal(),
  527. paginationEllipsisLetterSpacing: token.calc(token.marginXXS).div(2).equal(),
  528. paginationSlashMarginInlineStart: token.marginSM,
  529. paginationSlashMarginInlineEnd: token.marginSM,
  530. paginationEllipsisTextIndent: '0.13em' // magic for ui experience
  531. }, initInputToken(token));
  532. // ============================== Export ==============================
  533. export default genStyleHooks('Pagination', token => {
  534. const paginationToken = prepareToken(token);
  535. return [genPaginationStyle(paginationToken), genPaginationFocusStyle(paginationToken)];
  536. }, prepareComponentToken);