index.js 5.7 KB

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