index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { unit } from '@ant-design/cssinjs';
  2. import { resetComponent, textEllipsis } from '../../style';
  3. import { genStyleHooks, mergeToken } from '../../theme/internal';
  4. const genBorderedStyle = token => {
  5. const {
  6. componentCls,
  7. labelBg
  8. } = token;
  9. return {
  10. [`&${componentCls}-bordered`]: {
  11. [`> ${componentCls}-view`]: {
  12. border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
  13. '> table': {
  14. tableLayout: 'auto'
  15. },
  16. [`${componentCls}-row`]: {
  17. borderBottom: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
  18. '&:first-child': {
  19. '> th:first-child, > td:first-child': {
  20. borderStartStartRadius: token.borderRadiusLG
  21. }
  22. },
  23. '&:last-child': {
  24. borderBottom: 'none',
  25. '> th:first-child, > td:first-child': {
  26. borderEndStartRadius: token.borderRadiusLG
  27. }
  28. },
  29. [`> ${componentCls}-item-label, > ${componentCls}-item-content`]: {
  30. padding: `${unit(token.padding)} ${unit(token.paddingLG)}`,
  31. borderInlineEnd: `${unit(token.lineWidth)} ${token.lineType} ${token.colorSplit}`,
  32. '&:last-child': {
  33. borderInlineEnd: 'none'
  34. }
  35. },
  36. [`> ${componentCls}-item-label`]: {
  37. color: token.colorTextSecondary,
  38. backgroundColor: labelBg,
  39. '&::after': {
  40. display: 'none'
  41. }
  42. }
  43. }
  44. },
  45. [`&${componentCls}-middle`]: {
  46. [`${componentCls}-row`]: {
  47. [`> ${componentCls}-item-label, > ${componentCls}-item-content`]: {
  48. padding: `${unit(token.paddingSM)} ${unit(token.paddingLG)}`
  49. }
  50. }
  51. },
  52. [`&${componentCls}-small`]: {
  53. [`${componentCls}-row`]: {
  54. [`> ${componentCls}-item-label, > ${componentCls}-item-content`]: {
  55. padding: `${unit(token.paddingXS)} ${unit(token.padding)}`
  56. }
  57. }
  58. }
  59. }
  60. };
  61. };
  62. const genDescriptionStyles = token => {
  63. const {
  64. componentCls,
  65. extraColor,
  66. itemPaddingBottom,
  67. itemPaddingEnd,
  68. colonMarginRight,
  69. colonMarginLeft,
  70. titleMarginBottom
  71. } = token;
  72. return {
  73. [componentCls]: Object.assign(Object.assign(Object.assign({}, resetComponent(token)), genBorderedStyle(token)), {
  74. '&-rtl': {
  75. direction: 'rtl'
  76. },
  77. [`${componentCls}-header`]: {
  78. display: 'flex',
  79. alignItems: 'center',
  80. marginBottom: titleMarginBottom
  81. },
  82. [`${componentCls}-title`]: Object.assign(Object.assign({}, textEllipsis), {
  83. flex: 'auto',
  84. color: token.titleColor,
  85. fontWeight: token.fontWeightStrong,
  86. fontSize: token.fontSizeLG,
  87. lineHeight: token.lineHeightLG
  88. }),
  89. [`${componentCls}-extra`]: {
  90. marginInlineStart: 'auto',
  91. color: extraColor,
  92. fontSize: token.fontSize
  93. },
  94. [`${componentCls}-view`]: {
  95. width: '100%',
  96. borderRadius: token.borderRadiusLG,
  97. table: {
  98. width: '100%',
  99. tableLayout: 'fixed',
  100. borderCollapse: 'collapse'
  101. }
  102. },
  103. [`${componentCls}-row`]: {
  104. '> th, > td': {
  105. paddingBottom: itemPaddingBottom,
  106. paddingInlineEnd: itemPaddingEnd
  107. },
  108. '> th:last-child, > td:last-child': {
  109. paddingInlineEnd: 0
  110. },
  111. '&:last-child': {
  112. borderBottom: 'none',
  113. '> th, > td': {
  114. paddingBottom: 0
  115. }
  116. }
  117. },
  118. [`${componentCls}-item-label`]: {
  119. color: token.labelColor,
  120. fontWeight: 'normal',
  121. fontSize: token.fontSize,
  122. lineHeight: token.lineHeight,
  123. textAlign: 'start',
  124. '&::after': {
  125. content: '":"',
  126. position: 'relative',
  127. top: -0.5,
  128. // magic for position
  129. marginInline: `${unit(colonMarginLeft)} ${unit(colonMarginRight)}`
  130. },
  131. [`&${componentCls}-item-no-colon::after`]: {
  132. content: '""'
  133. }
  134. },
  135. [`${componentCls}-item-no-label`]: {
  136. '&::after': {
  137. margin: 0,
  138. content: '""'
  139. }
  140. },
  141. [`${componentCls}-item-content`]: {
  142. display: 'table-cell',
  143. flex: 1,
  144. color: token.contentColor,
  145. fontSize: token.fontSize,
  146. lineHeight: token.lineHeight,
  147. wordBreak: 'break-word',
  148. overflowWrap: 'break-word'
  149. },
  150. [`${componentCls}-item`]: {
  151. paddingBottom: 0,
  152. verticalAlign: 'top',
  153. '&-container': {
  154. display: 'flex',
  155. [`${componentCls}-item-label`]: {
  156. display: 'inline-flex',
  157. alignItems: 'baseline'
  158. },
  159. [`${componentCls}-item-content`]: {
  160. display: 'inline-flex',
  161. alignItems: 'baseline',
  162. minWidth: '1em'
  163. }
  164. }
  165. },
  166. '&-middle': {
  167. [`${componentCls}-row`]: {
  168. '> th, > td': {
  169. paddingBottom: token.paddingSM
  170. }
  171. }
  172. },
  173. '&-small': {
  174. [`${componentCls}-row`]: {
  175. '> th, > td': {
  176. paddingBottom: token.paddingXS
  177. }
  178. }
  179. }
  180. })
  181. };
  182. };
  183. export const prepareComponentToken = token => ({
  184. labelBg: token.colorFillAlter,
  185. labelColor: token.colorTextTertiary,
  186. titleColor: token.colorText,
  187. titleMarginBottom: token.fontSizeSM * token.lineHeightSM,
  188. itemPaddingBottom: token.padding,
  189. itemPaddingEnd: token.padding,
  190. colonMarginRight: token.marginXS,
  191. colonMarginLeft: token.marginXXS / 2,
  192. contentColor: token.colorText,
  193. extraColor: token.colorText
  194. });
  195. // ============================== Export ==============================
  196. export default genStyleHooks('Descriptions', token => {
  197. const descriptionToken = mergeToken(token, {});
  198. return genDescriptionStyles(descriptionToken);
  199. }, prepareComponentToken);