index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { unit } from '@ant-design/cssinjs';
  2. import { resetComponent } from '../../style';
  3. import { genStyleHooks, mergeToken } from '../../theme/internal';
  4. const genTimelineStyle = token => {
  5. const {
  6. componentCls,
  7. calc
  8. } = token;
  9. return {
  10. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  11. margin: 0,
  12. padding: 0,
  13. listStyle: 'none',
  14. [`${componentCls}-item`]: {
  15. position: 'relative',
  16. margin: 0,
  17. paddingBottom: token.itemPaddingBottom,
  18. fontSize: token.fontSize,
  19. listStyle: 'none',
  20. '&-tail': {
  21. position: 'absolute',
  22. insetBlockStart: token.itemHeadSize,
  23. insetInlineStart: calc(calc(token.itemHeadSize).sub(token.tailWidth)).div(2).equal(),
  24. height: `calc(100% - ${unit(token.itemHeadSize)})`,
  25. borderInlineStart: `${unit(token.tailWidth)} ${token.lineType} ${token.tailColor}`
  26. },
  27. '&-pending': {
  28. [`${componentCls}-item-head`]: {
  29. fontSize: token.fontSizeSM,
  30. backgroundColor: 'transparent'
  31. },
  32. [`${componentCls}-item-tail`]: {
  33. display: 'none'
  34. }
  35. },
  36. '&-head': {
  37. position: 'absolute',
  38. width: token.itemHeadSize,
  39. height: token.itemHeadSize,
  40. backgroundColor: token.dotBg,
  41. border: `${unit(token.dotBorderWidth)} ${token.lineType} transparent`,
  42. borderRadius: '50%',
  43. '&-blue': {
  44. color: token.colorPrimary,
  45. borderColor: token.colorPrimary
  46. },
  47. '&-red': {
  48. color: token.colorError,
  49. borderColor: token.colorError
  50. },
  51. '&-green': {
  52. color: token.colorSuccess,
  53. borderColor: token.colorSuccess
  54. },
  55. '&-gray': {
  56. color: token.colorTextDisabled,
  57. borderColor: token.colorTextDisabled
  58. }
  59. },
  60. '&-head-custom': {
  61. position: 'absolute',
  62. insetBlockStart: calc(token.itemHeadSize).div(2).equal(),
  63. insetInlineStart: calc(token.itemHeadSize).div(2).equal(),
  64. width: 'auto',
  65. height: 'auto',
  66. marginBlockStart: 0,
  67. paddingBlock: token.customHeadPaddingVertical,
  68. lineHeight: 1,
  69. textAlign: 'center',
  70. border: 0,
  71. borderRadius: 0,
  72. transform: 'translate(-50%, -50%)'
  73. },
  74. '&-content': {
  75. position: 'relative',
  76. insetBlockStart: calc(calc(token.fontSize).mul(token.lineHeight).sub(token.fontSize)).mul(-1).add(token.lineWidth).equal(),
  77. marginInlineStart: calc(token.margin).add(token.itemHeadSize).equal(),
  78. marginInlineEnd: 0,
  79. marginBlockStart: 0,
  80. marginBlockEnd: 0,
  81. wordBreak: 'break-word'
  82. },
  83. '&-last': {
  84. [`> ${componentCls}-item-tail`]: {
  85. display: 'none'
  86. },
  87. [`> ${componentCls}-item-content`]: {
  88. minHeight: calc(token.controlHeightLG).mul(1.2).equal()
  89. }
  90. }
  91. },
  92. [`&${componentCls}-alternate,
  93. &${componentCls}-right,
  94. &${componentCls}-label`]: {
  95. [`${componentCls}-item`]: {
  96. '&-tail, &-head, &-head-custom': {
  97. insetInlineStart: '50%'
  98. },
  99. '&-head': {
  100. marginInlineStart: calc(token.marginXXS).mul(-1).equal(),
  101. '&-custom': {
  102. marginInlineStart: calc(token.tailWidth).div(2).equal()
  103. }
  104. },
  105. '&-left': {
  106. [`${componentCls}-item-content`]: {
  107. insetInlineStart: `calc(50% - ${unit(token.marginXXS)})`,
  108. width: `calc(50% - ${unit(token.marginSM)})`,
  109. textAlign: 'start'
  110. }
  111. },
  112. '&-right': {
  113. [`${componentCls}-item-content`]: {
  114. width: `calc(50% - ${unit(token.marginSM)})`,
  115. margin: 0,
  116. textAlign: 'end'
  117. }
  118. }
  119. }
  120. },
  121. [`&${componentCls}-right`]: {
  122. [`${componentCls}-item-right`]: {
  123. [`${componentCls}-item-tail,
  124. ${componentCls}-item-head,
  125. ${componentCls}-item-head-custom`]: {
  126. insetInlineStart: `calc(100% - ${unit(calc(calc(token.itemHeadSize).add(token.tailWidth)).div(2).equal())})`
  127. },
  128. [`${componentCls}-item-content`]: {
  129. width: `calc(100% - ${unit(calc(token.itemHeadSize).add(token.marginXS).equal())})`
  130. }
  131. }
  132. },
  133. [`&${componentCls}-pending
  134. ${componentCls}-item-last
  135. ${componentCls}-item-tail`]: {
  136. display: 'block',
  137. height: `calc(100% - ${unit(token.margin)})`,
  138. borderInlineStart: `${unit(token.tailWidth)} dotted ${token.tailColor}`
  139. },
  140. [`&${componentCls}-reverse
  141. ${componentCls}-item-last
  142. ${componentCls}-item-tail`]: {
  143. display: 'none'
  144. },
  145. [`&${componentCls}-reverse ${componentCls}-item-pending`]: {
  146. [`${componentCls}-item-tail`]: {
  147. insetBlockStart: token.margin,
  148. display: 'block',
  149. height: `calc(100% - ${unit(token.margin)})`,
  150. borderInlineStart: `${unit(token.tailWidth)} dotted ${token.tailColor}`
  151. },
  152. [`${componentCls}-item-content`]: {
  153. minHeight: calc(token.controlHeightLG).mul(1.2).equal()
  154. }
  155. },
  156. [`&${componentCls}-label`]: {
  157. [`${componentCls}-item-label`]: {
  158. position: 'absolute',
  159. insetBlockStart: calc(calc(token.fontSize).mul(token.lineHeight).sub(token.fontSize)).mul(-1).add(token.tailWidth).equal(),
  160. width: `calc(50% - ${unit(token.marginSM)})`,
  161. textAlign: 'end'
  162. },
  163. [`${componentCls}-item-right`]: {
  164. [`${componentCls}-item-label`]: {
  165. insetInlineStart: `calc(50% + ${unit(token.marginSM)})`,
  166. width: `calc(50% - ${unit(token.marginSM)})`,
  167. textAlign: 'start'
  168. }
  169. }
  170. },
  171. // ====================== RTL =======================
  172. '&-rtl': {
  173. direction: 'rtl',
  174. [`${componentCls}-item-head-custom`]: {
  175. transform: `translate(50%, -50%)`
  176. }
  177. }
  178. })
  179. };
  180. };
  181. // ============================== Export ==============================
  182. export const prepareComponentToken = token => ({
  183. tailColor: token.colorSplit,
  184. tailWidth: token.lineWidthBold,
  185. dotBorderWidth: token.wireframe ? token.lineWidthBold : token.lineWidth * 3,
  186. dotBg: token.colorBgContainer,
  187. itemPaddingBottom: token.padding * 1.25
  188. });
  189. export default genStyleHooks('Timeline', token => {
  190. const timeLineToken = mergeToken(token, {
  191. itemHeadSize: 10,
  192. customHeadPaddingVertical: token.paddingXXS,
  193. paddingInlineEnd: 2
  194. });
  195. return genTimelineStyle(timeLineToken);
  196. }, prepareComponentToken);