index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { unit } from '@ant-design/cssinjs';
  2. import { resetComponent, textEllipsis } from '../../style';
  3. import { genStyleHooks, mergeToken } from '../../theme/internal';
  4. // ============================== Shared ==============================
  5. const genSharedAnchorStyle = token => {
  6. const {
  7. componentCls,
  8. holderOffsetBlock,
  9. motionDurationSlow,
  10. lineWidthBold,
  11. colorPrimary,
  12. lineType,
  13. colorSplit,
  14. calc
  15. } = token;
  16. return {
  17. [`${componentCls}-wrapper`]: {
  18. marginBlockStart: calc(holderOffsetBlock).mul(-1).equal(),
  19. paddingBlockStart: holderOffsetBlock,
  20. // delete overflow: auto
  21. // overflow: 'auto',
  22. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  23. position: 'relative',
  24. paddingInlineStart: lineWidthBold,
  25. [`${componentCls}-link`]: {
  26. paddingBlock: token.linkPaddingBlock,
  27. paddingInline: `${unit(token.linkPaddingInlineStart)} 0`,
  28. '&-title': Object.assign(Object.assign({}, textEllipsis), {
  29. position: 'relative',
  30. display: 'block',
  31. marginBlockEnd: token.anchorTitleBlock,
  32. color: token.colorText,
  33. transition: `all ${token.motionDurationSlow}`,
  34. '&:only-child': {
  35. marginBlockEnd: 0
  36. }
  37. }),
  38. [`&-active > ${componentCls}-link-title`]: {
  39. color: token.colorPrimary
  40. },
  41. // link link
  42. [`${componentCls}-link`]: {
  43. paddingBlock: token.anchorPaddingBlockSecondary
  44. }
  45. }
  46. }),
  47. [`&:not(${componentCls}-wrapper-horizontal)`]: {
  48. [componentCls]: {
  49. '&::before': {
  50. position: 'absolute',
  51. insetInlineStart: 0,
  52. top: 0,
  53. height: '100%',
  54. borderInlineStart: `${unit(lineWidthBold)} ${lineType} ${colorSplit}`,
  55. content: '" "'
  56. },
  57. [`${componentCls}-ink`]: {
  58. position: 'absolute',
  59. insetInlineStart: 0,
  60. display: 'none',
  61. transform: 'translateY(-50%)',
  62. transition: `top ${motionDurationSlow} ease-in-out`,
  63. width: lineWidthBold,
  64. backgroundColor: colorPrimary,
  65. [`&${componentCls}-ink-visible`]: {
  66. display: 'inline-block'
  67. }
  68. }
  69. }
  70. },
  71. [`${componentCls}-fixed ${componentCls}-ink ${componentCls}-ink`]: {
  72. display: 'none'
  73. }
  74. }
  75. };
  76. };
  77. const genSharedAnchorHorizontalStyle = token => {
  78. const {
  79. componentCls,
  80. motionDurationSlow,
  81. lineWidthBold,
  82. colorPrimary
  83. } = token;
  84. return {
  85. [`${componentCls}-wrapper-horizontal`]: {
  86. position: 'relative',
  87. '&::before': {
  88. position: 'absolute',
  89. left: {
  90. _skip_check_: true,
  91. value: 0
  92. },
  93. right: {
  94. _skip_check_: true,
  95. value: 0
  96. },
  97. bottom: 0,
  98. borderBottom: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
  99. content: '" "'
  100. },
  101. [componentCls]: {
  102. overflowX: 'scroll',
  103. position: 'relative',
  104. display: 'flex',
  105. scrollbarWidth: 'none' /* Firefox */,
  106. '&::-webkit-scrollbar': {
  107. display: 'none' /* Safari and Chrome */
  108. },
  109. [`${componentCls}-link:first-of-type`]: {
  110. paddingInline: 0
  111. },
  112. [`${componentCls}-ink`]: {
  113. position: 'absolute',
  114. bottom: 0,
  115. transition: `left ${motionDurationSlow} ease-in-out, width ${motionDurationSlow} ease-in-out`,
  116. height: lineWidthBold,
  117. backgroundColor: colorPrimary
  118. }
  119. }
  120. }
  121. };
  122. };
  123. export const prepareComponentToken = token => ({
  124. linkPaddingBlock: token.paddingXXS,
  125. linkPaddingInlineStart: token.padding
  126. });
  127. // ============================== Export ==============================
  128. export default genStyleHooks('Anchor', token => {
  129. const {
  130. fontSize,
  131. fontSizeLG,
  132. paddingXXS,
  133. calc
  134. } = token;
  135. const anchorToken = mergeToken(token, {
  136. holderOffsetBlock: paddingXXS,
  137. anchorPaddingBlockSecondary: calc(paddingXXS).div(2).equal(),
  138. anchorTitleBlock: calc(fontSize).div(14).mul(3).equal(),
  139. anchorBallSize: calc(fontSizeLG).div(2).equal()
  140. });
  141. return [genSharedAnchorStyle(anchorToken), genSharedAnchorHorizontalStyle(anchorToken)];
  142. }, prepareComponentToken);