index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { resetComponent, textEllipsis } from '../../style';
  4. // ============================== Shared ==============================
  5. const genSharedAnchorStyle = token => {
  6. const {
  7. componentCls,
  8. holderOffsetBlock,
  9. motionDurationSlow,
  10. lineWidthBold,
  11. colorPrimary,
  12. lineType,
  13. colorSplit
  14. } = token;
  15. return {
  16. [`${componentCls}-wrapper`]: {
  17. marginBlockStart: -holderOffsetBlock,
  18. paddingBlockStart: holderOffsetBlock,
  19. // delete overflow: auto
  20. // overflow: 'auto',
  21. backgroundColor: 'transparent',
  22. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  23. position: 'relative',
  24. paddingInlineStart: lineWidthBold,
  25. [`${componentCls}-link`]: {
  26. paddingBlock: token.anchorPaddingBlock,
  27. paddingInline: `${token.anchorPaddingInline}px 0`,
  28. '&-title': _extends(_extends({}, 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. left: {
  52. _skip_check_: true,
  53. value: 0
  54. },
  55. top: 0,
  56. height: '100%',
  57. borderInlineStart: `${lineWidthBold}px ${lineType} ${colorSplit}`,
  58. content: '" "'
  59. },
  60. [`${componentCls}-ink`]: {
  61. position: 'absolute',
  62. left: {
  63. _skip_check_: true,
  64. value: 0
  65. },
  66. display: 'none',
  67. transform: 'translateY(-50%)',
  68. transition: `top ${motionDurationSlow} ease-in-out`,
  69. width: lineWidthBold,
  70. backgroundColor: colorPrimary,
  71. [`&${componentCls}-ink-visible`]: {
  72. display: 'inline-block'
  73. }
  74. }
  75. }
  76. },
  77. [`${componentCls}-fixed ${componentCls}-ink ${componentCls}-ink`]: {
  78. display: 'none'
  79. }
  80. }
  81. };
  82. };
  83. const genSharedAnchorHorizontalStyle = token => {
  84. const {
  85. componentCls,
  86. motionDurationSlow,
  87. lineWidthBold,
  88. colorPrimary
  89. } = token;
  90. return {
  91. [`${componentCls}-wrapper-horizontal`]: {
  92. position: 'relative',
  93. '&::before': {
  94. position: 'absolute',
  95. left: {
  96. _skip_check_: true,
  97. value: 0
  98. },
  99. right: {
  100. _skip_check_: true,
  101. value: 0
  102. },
  103. bottom: 0,
  104. borderBottom: `1px ${token.lineType} ${token.colorSplit}`,
  105. content: '" "'
  106. },
  107. [componentCls]: {
  108. overflowX: 'scroll',
  109. position: 'relative',
  110. display: 'flex',
  111. scrollbarWidth: 'none' /* Firefox */,
  112. '&::-webkit-scrollbar': {
  113. display: 'none' /* Safari and Chrome */
  114. },
  115. [`${componentCls}-link:first-of-type`]: {
  116. paddingInline: 0
  117. },
  118. [`${componentCls}-ink`]: {
  119. position: 'absolute',
  120. bottom: 0,
  121. transition: `left ${motionDurationSlow} ease-in-out, width ${motionDurationSlow} ease-in-out`,
  122. height: lineWidthBold,
  123. backgroundColor: colorPrimary
  124. }
  125. }
  126. }
  127. };
  128. };
  129. // ============================== Export ==============================
  130. export default genComponentStyleHook('Anchor', token => {
  131. const {
  132. fontSize,
  133. fontSizeLG,
  134. padding,
  135. paddingXXS
  136. } = token;
  137. const anchorToken = mergeToken(token, {
  138. holderOffsetBlock: paddingXXS,
  139. anchorPaddingBlock: paddingXXS,
  140. anchorPaddingBlockSecondary: paddingXXS / 2,
  141. anchorPaddingInline: padding,
  142. anchorTitleBlock: fontSize / 14 * 3,
  143. anchorBallSize: fontSizeLG / 2
  144. });
  145. return [genSharedAnchorStyle(anchorToken), genSharedAnchorHorizontalStyle(anchorToken)];
  146. });