index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { unit } from '@ant-design/cssinjs';
  2. import { resetComponent } from '../../style';
  3. import { genStyleHooks, mergeToken } from '../../theme/internal';
  4. // ============================== Size ================================
  5. const genSizeDividerStyle = token => {
  6. const {
  7. componentCls
  8. } = token;
  9. return {
  10. [componentCls]: {
  11. '&-horizontal': {
  12. [`&${componentCls}`]: {
  13. '&-sm': {
  14. marginBlock: token.marginXS
  15. },
  16. '&-md': {
  17. marginBlock: token.margin
  18. }
  19. }
  20. }
  21. }
  22. };
  23. };
  24. // ============================== Shared ==============================
  25. const genSharedDividerStyle = token => {
  26. const {
  27. componentCls,
  28. sizePaddingEdgeHorizontal,
  29. colorSplit,
  30. lineWidth,
  31. textPaddingInline,
  32. orientationMargin,
  33. verticalMarginInline
  34. } = token;
  35. return {
  36. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  37. borderBlockStart: `${unit(lineWidth)} solid ${colorSplit}`,
  38. // vertical
  39. '&-vertical': {
  40. position: 'relative',
  41. top: '-0.06em',
  42. display: 'inline-block',
  43. height: '0.9em',
  44. marginInline: verticalMarginInline,
  45. marginBlock: 0,
  46. verticalAlign: 'middle',
  47. borderTop: 0,
  48. borderInlineStart: `${unit(lineWidth)} solid ${colorSplit}`
  49. },
  50. '&-horizontal': {
  51. display: 'flex',
  52. clear: 'both',
  53. width: '100%',
  54. minWidth: '100%',
  55. // Fix https://github.com/ant-design/ant-design/issues/10914
  56. margin: `${unit(token.marginLG)} 0`
  57. },
  58. [`&-horizontal${componentCls}-with-text`]: {
  59. display: 'flex',
  60. alignItems: 'center',
  61. margin: `${unit(token.dividerHorizontalWithTextGutterMargin)} 0`,
  62. color: token.colorTextHeading,
  63. fontWeight: 500,
  64. fontSize: token.fontSizeLG,
  65. whiteSpace: 'nowrap',
  66. textAlign: 'center',
  67. borderBlockStart: `0 ${colorSplit}`,
  68. '&::before, &::after': {
  69. position: 'relative',
  70. width: '50%',
  71. borderBlockStart: `${unit(lineWidth)} solid transparent`,
  72. // Chrome not accept `inherit` in `border-top`
  73. borderBlockStartColor: 'inherit',
  74. borderBlockEnd: 0,
  75. transform: 'translateY(50%)',
  76. content: "''"
  77. }
  78. },
  79. [`&-horizontal${componentCls}-with-text-start`]: {
  80. '&::before': {
  81. width: `calc(${orientationMargin} * 100%)`
  82. },
  83. '&::after': {
  84. width: `calc(100% - ${orientationMargin} * 100%)`
  85. }
  86. },
  87. [`&-horizontal${componentCls}-with-text-end`]: {
  88. '&::before': {
  89. width: `calc(100% - ${orientationMargin} * 100%)`
  90. },
  91. '&::after': {
  92. width: `calc(${orientationMargin} * 100%)`
  93. }
  94. },
  95. [`${componentCls}-inner-text`]: {
  96. display: 'inline-block',
  97. paddingBlock: 0,
  98. paddingInline: textPaddingInline
  99. },
  100. '&-dashed': {
  101. background: 'none',
  102. borderColor: colorSplit,
  103. borderStyle: 'dashed',
  104. borderWidth: `${unit(lineWidth)} 0 0`
  105. },
  106. [`&-horizontal${componentCls}-with-text${componentCls}-dashed`]: {
  107. '&::before, &::after': {
  108. borderStyle: 'dashed none none'
  109. }
  110. },
  111. [`&-vertical${componentCls}-dashed`]: {
  112. borderInlineStartWidth: lineWidth,
  113. borderInlineEnd: 0,
  114. borderBlockStart: 0,
  115. borderBlockEnd: 0
  116. },
  117. '&-dotted': {
  118. background: 'none',
  119. borderColor: colorSplit,
  120. borderStyle: 'dotted',
  121. borderWidth: `${unit(lineWidth)} 0 0`
  122. },
  123. [`&-horizontal${componentCls}-with-text${componentCls}-dotted`]: {
  124. '&::before, &::after': {
  125. borderStyle: 'dotted none none'
  126. }
  127. },
  128. [`&-vertical${componentCls}-dotted`]: {
  129. borderInlineStartWidth: lineWidth,
  130. borderInlineEnd: 0,
  131. borderBlockStart: 0,
  132. borderBlockEnd: 0
  133. },
  134. [`&-plain${componentCls}-with-text`]: {
  135. color: token.colorText,
  136. fontWeight: 'normal',
  137. fontSize: token.fontSize
  138. },
  139. [`&-horizontal${componentCls}-with-text-start${componentCls}-no-default-orientation-margin-start`]: {
  140. '&::before': {
  141. width: 0
  142. },
  143. '&::after': {
  144. width: '100%'
  145. },
  146. [`${componentCls}-inner-text`]: {
  147. paddingInlineStart: sizePaddingEdgeHorizontal
  148. }
  149. },
  150. [`&-horizontal${componentCls}-with-text-end${componentCls}-no-default-orientation-margin-end`]: {
  151. '&::before': {
  152. width: '100%'
  153. },
  154. '&::after': {
  155. width: 0
  156. },
  157. [`${componentCls}-inner-text`]: {
  158. paddingInlineEnd: sizePaddingEdgeHorizontal
  159. }
  160. }
  161. })
  162. };
  163. };
  164. export const prepareComponentToken = token => ({
  165. textPaddingInline: '1em',
  166. orientationMargin: 0.05,
  167. verticalMarginInline: token.marginXS
  168. });
  169. // ============================== Export ==============================
  170. export default genStyleHooks('Divider', token => {
  171. const dividerToken = mergeToken(token, {
  172. dividerHorizontalWithTextGutterMargin: token.margin,
  173. sizePaddingEdgeHorizontal: 0
  174. });
  175. return [genSharedDividerStyle(dividerToken), genSizeDividerStyle(dividerToken)];
  176. }, prepareComponentToken, {
  177. unitless: {
  178. orientationMargin: true
  179. }
  180. });