index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { unit } from '@ant-design/cssinjs';
  2. import { FastColor } from '@ant-design/fast-color';
  3. import { genFocusStyle, resetComponent } from '../../style';
  4. import getArrowStyle, { getArrowOffsetToken, MAX_VERTICAL_CONTENT_RADIUS } from '../../style/placementArrow';
  5. import { getArrowToken } from '../../style/roundedArrow';
  6. import { genStyleHooks, mergeToken } from '../../theme/internal';
  7. // =============================== Base ===============================
  8. const genBaseStyle = token => {
  9. const {
  10. componentCls,
  11. padding,
  12. paddingXS,
  13. borderRadius,
  14. borderRadiusXS,
  15. colorPrimary,
  16. colorFill,
  17. indicatorHeight,
  18. indicatorWidth,
  19. boxShadowTertiary,
  20. zIndexPopup,
  21. colorBgElevated,
  22. fontWeightStrong,
  23. marginXS,
  24. colorTextLightSolid,
  25. tourBorderRadius,
  26. colorWhite,
  27. primaryNextBtnHoverBg,
  28. closeBtnSize,
  29. motionDurationSlow,
  30. antCls,
  31. primaryPrevBtnBg
  32. } = token;
  33. return [{
  34. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  35. position: 'absolute',
  36. zIndex: zIndexPopup,
  37. maxWidth: 'fit-content',
  38. visibility: 'visible',
  39. width: 520,
  40. '--antd-arrow-background-color': colorBgElevated,
  41. '&-pure': {
  42. maxWidth: '100%',
  43. position: 'relative'
  44. },
  45. [`&${componentCls}-hidden`]: {
  46. display: 'none'
  47. },
  48. // ============================= panel content ============================
  49. [`${componentCls}-content`]: {
  50. position: 'relative'
  51. },
  52. [`${componentCls}-inner`]: {
  53. textAlign: 'start',
  54. textDecoration: 'none',
  55. borderRadius: tourBorderRadius,
  56. boxShadow: boxShadowTertiary,
  57. position: 'relative',
  58. backgroundColor: colorBgElevated,
  59. border: 'none',
  60. backgroundClip: 'padding-box',
  61. [`${componentCls}-close`]: Object.assign({
  62. position: 'absolute',
  63. top: padding,
  64. insetInlineEnd: padding,
  65. color: token.colorIcon,
  66. background: 'none',
  67. border: 'none',
  68. width: closeBtnSize,
  69. height: closeBtnSize,
  70. borderRadius: token.borderRadiusSM,
  71. transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
  72. display: 'flex',
  73. alignItems: 'center',
  74. justifyContent: 'center',
  75. cursor: 'pointer',
  76. '&:hover': {
  77. color: token.colorIconHover,
  78. backgroundColor: token.colorBgTextHover
  79. },
  80. '&:active': {
  81. backgroundColor: token.colorBgTextActive
  82. }
  83. }, genFocusStyle(token)),
  84. [`${componentCls}-cover`]: {
  85. textAlign: 'center',
  86. padding: `${unit(token.calc(padding).add(closeBtnSize).add(paddingXS).equal())} ${unit(padding)} 0`,
  87. img: {
  88. width: '100%'
  89. }
  90. },
  91. [`${componentCls}-header`]: {
  92. padding: `${unit(padding)} ${unit(padding)} ${unit(paddingXS)}`,
  93. width: `calc(100% - ${unit(closeBtnSize)})`,
  94. wordBreak: 'break-word',
  95. [`${componentCls}-title`]: {
  96. fontWeight: fontWeightStrong
  97. }
  98. },
  99. [`${componentCls}-description`]: {
  100. padding: `0 ${unit(padding)}`,
  101. wordWrap: 'break-word'
  102. },
  103. [`${componentCls}-footer`]: {
  104. padding: `${unit(paddingXS)} ${unit(padding)} ${unit(padding)}`,
  105. textAlign: 'end',
  106. borderRadius: `0 0 ${unit(borderRadiusXS)} ${unit(borderRadiusXS)}`,
  107. display: 'flex',
  108. [`${componentCls}-indicators`]: {
  109. display: 'inline-block',
  110. [`${componentCls}-indicator`]: {
  111. width: indicatorWidth,
  112. height: indicatorHeight,
  113. display: 'inline-block',
  114. borderRadius: '50%',
  115. background: colorFill,
  116. '&:not(:last-child)': {
  117. marginInlineEnd: indicatorHeight
  118. },
  119. '&-active': {
  120. background: colorPrimary
  121. }
  122. }
  123. },
  124. [`${componentCls}-buttons`]: {
  125. marginInlineStart: 'auto',
  126. [`${antCls}-btn`]: {
  127. marginInlineStart: marginXS
  128. }
  129. }
  130. }
  131. },
  132. // ============================= primary type ===========================
  133. // `$` for panel, `&$` for pure panel
  134. [`${componentCls}-primary, &${componentCls}-primary`]: {
  135. '--antd-arrow-background-color': colorPrimary,
  136. [`${componentCls}-inner`]: {
  137. color: colorTextLightSolid,
  138. textAlign: 'start',
  139. textDecoration: 'none',
  140. backgroundColor: colorPrimary,
  141. borderRadius,
  142. boxShadow: boxShadowTertiary,
  143. [`${componentCls}-close`]: {
  144. color: colorTextLightSolid
  145. },
  146. [`${componentCls}-indicators`]: {
  147. [`${componentCls}-indicator`]: {
  148. background: primaryPrevBtnBg,
  149. '&-active': {
  150. background: colorTextLightSolid
  151. }
  152. }
  153. },
  154. [`${componentCls}-prev-btn`]: {
  155. color: colorTextLightSolid,
  156. borderColor: primaryPrevBtnBg,
  157. backgroundColor: colorPrimary,
  158. '&:hover': {
  159. backgroundColor: primaryPrevBtnBg,
  160. borderColor: 'transparent'
  161. }
  162. },
  163. [`${componentCls}-next-btn`]: {
  164. color: colorPrimary,
  165. borderColor: 'transparent',
  166. background: colorWhite,
  167. '&:hover': {
  168. background: primaryNextBtnHoverBg
  169. }
  170. }
  171. }
  172. }
  173. }),
  174. // ============================= mask ===========================
  175. [`${componentCls}-mask`]: {
  176. [`${componentCls}-placeholder-animated`]: {
  177. transition: `all ${motionDurationSlow}`
  178. }
  179. },
  180. // =========== Limit left and right placement radius ==============
  181. [['&-placement-left', '&-placement-leftTop', '&-placement-leftBottom', '&-placement-right', '&-placement-rightTop', '&-placement-rightBottom'].join(',')]: {
  182. [`${componentCls}-inner`]: {
  183. borderRadius: token.min(tourBorderRadius, MAX_VERTICAL_CONTENT_RADIUS)
  184. }
  185. }
  186. },
  187. // ============================= Arrow ===========================
  188. getArrowStyle(token, 'var(--antd-arrow-background-color)')];
  189. };
  190. // ============================== Export ==============================
  191. export const prepareComponentToken = token => Object.assign(Object.assign({
  192. zIndexPopup: token.zIndexPopupBase + 70,
  193. closeBtnSize: token.fontSize * token.lineHeight,
  194. primaryPrevBtnBg: new FastColor(token.colorTextLightSolid).setA(0.15).toRgbString(),
  195. primaryNextBtnHoverBg: new FastColor(token.colorBgTextHover).onBackground(token.colorWhite).toRgbString()
  196. }, getArrowOffsetToken({
  197. contentRadius: token.borderRadiusLG,
  198. limitVerticalRadius: true
  199. })), getArrowToken(token));
  200. export default genStyleHooks('Tour', token => {
  201. const {
  202. borderRadiusLG
  203. } = token;
  204. const TourToken = mergeToken(token, {
  205. indicatorWidth: 6,
  206. indicatorHeight: 6,
  207. tourBorderRadius: borderRadiusLG
  208. });
  209. return genBaseStyle(TourToken);
  210. }, prepareComponentToken);