index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { TinyColor } from '@ctrl/tinycolor';
  3. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  4. import { resetComponent } from '../../style';
  5. import getArrowStyle, { MAX_VERTICAL_CONTENT_RADIUS } from '../../style/placementArrow';
  6. // =============================== Base ===============================
  7. const genBaseStyle = token => {
  8. const {
  9. componentCls,
  10. lineHeight,
  11. padding,
  12. paddingXS,
  13. borderRadius,
  14. borderRadiusXS,
  15. colorPrimary,
  16. colorText,
  17. colorFill,
  18. indicatorHeight,
  19. indicatorWidth,
  20. boxShadowTertiary,
  21. tourZIndexPopup,
  22. fontSize,
  23. colorBgContainer,
  24. fontWeightStrong,
  25. marginXS,
  26. colorTextLightSolid,
  27. tourBorderRadius,
  28. colorWhite,
  29. colorBgTextHover,
  30. tourCloseSize,
  31. motionDurationSlow,
  32. antCls
  33. } = token;
  34. return [{
  35. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  36. color: colorText,
  37. position: 'absolute',
  38. zIndex: tourZIndexPopup,
  39. display: 'block',
  40. visibility: 'visible',
  41. fontSize,
  42. lineHeight,
  43. width: 520,
  44. '--antd-arrow-background-color': colorBgContainer,
  45. '&-pure': {
  46. maxWidth: '100%',
  47. position: 'relative'
  48. },
  49. [`&${componentCls}-hidden`]: {
  50. display: 'none'
  51. },
  52. // ============================= panel content ============================
  53. [`${componentCls}-content`]: {
  54. position: 'relative'
  55. },
  56. [`${componentCls}-inner`]: {
  57. textAlign: 'start',
  58. textDecoration: 'none',
  59. borderRadius: tourBorderRadius,
  60. boxShadow: boxShadowTertiary,
  61. position: 'relative',
  62. backgroundColor: colorBgContainer,
  63. border: 'none',
  64. backgroundClip: 'padding-box',
  65. [`${componentCls}-close`]: {
  66. position: 'absolute',
  67. top: padding,
  68. insetInlineEnd: padding,
  69. color: token.colorIcon,
  70. outline: 'none',
  71. width: tourCloseSize,
  72. height: tourCloseSize,
  73. borderRadius: token.borderRadiusSM,
  74. transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
  75. display: 'flex',
  76. alignItems: 'center',
  77. justifyContent: 'center',
  78. '&:hover': {
  79. color: token.colorIconHover,
  80. backgroundColor: token.wireframe ? 'transparent' : token.colorFillContent
  81. }
  82. },
  83. [`${componentCls}-cover`]: {
  84. textAlign: 'center',
  85. padding: `${padding + tourCloseSize + paddingXS}px ${padding}px 0`,
  86. img: {
  87. width: '100%'
  88. }
  89. },
  90. [`${componentCls}-header`]: {
  91. padding: `${padding}px ${padding}px ${paddingXS}px`,
  92. [`${componentCls}-title`]: {
  93. lineHeight,
  94. fontSize,
  95. fontWeight: fontWeightStrong
  96. }
  97. },
  98. [`${componentCls}-description`]: {
  99. padding: `0 ${padding}px`,
  100. lineHeight,
  101. wordWrap: 'break-word'
  102. },
  103. [`${componentCls}-footer`]: {
  104. padding: `${paddingXS}px ${padding}px ${padding}px`,
  105. textAlign: 'end',
  106. borderRadius: `0 0 ${borderRadiusXS}px ${borderRadiusXS}px`,
  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: new TinyColor(colorTextLightSolid).setAlpha(0.15).toRgbString(),
  149. '&-active': {
  150. background: colorTextLightSolid
  151. }
  152. }
  153. },
  154. [`${componentCls}-prev-btn`]: {
  155. color: colorTextLightSolid,
  156. borderColor: new TinyColor(colorTextLightSolid).setAlpha(0.15).toRgbString(),
  157. backgroundColor: colorPrimary,
  158. '&:hover': {
  159. backgroundColor: new TinyColor(colorTextLightSolid).setAlpha(0.15).toRgbString(),
  160. borderColor: 'transparent'
  161. }
  162. },
  163. [`${componentCls}-next-btn`]: {
  164. color: colorPrimary,
  165. borderColor: 'transparent',
  166. background: colorWhite,
  167. '&:hover': {
  168. background: new TinyColor(colorBgTextHover).onBackground(colorWhite).toRgbString()
  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: Math.min(tourBorderRadius, MAX_VERTICAL_CONTENT_RADIUS)
  184. }
  185. }
  186. },
  187. // ============================= Arrow ===========================
  188. getArrowStyle(token, {
  189. colorBg: 'var(--antd-arrow-background-color)',
  190. contentRadius: tourBorderRadius,
  191. limitVerticalRadius: true
  192. })];
  193. };
  194. // ============================== Export ==============================
  195. export default genComponentStyleHook('Tour', token => {
  196. const {
  197. borderRadiusLG,
  198. fontSize,
  199. lineHeight
  200. } = token;
  201. const TourToken = mergeToken(token, {
  202. tourZIndexPopup: token.zIndexPopupBase + 70,
  203. indicatorWidth: 6,
  204. indicatorHeight: 6,
  205. tourBorderRadius: borderRadiusLG,
  206. tourCloseSize: fontSize * lineHeight
  207. });
  208. return [genBaseStyle(TourToken)];
  209. });