index.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { TinyColor } from '@ctrl/tinycolor';
  3. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  4. import genBorderedStyle from './bordered';
  5. import genEllipsisStyle from './ellipsis';
  6. import genEmptyStyle from './empty';
  7. import genExpandStyle from './expand';
  8. import genFilterStyle from './filter';
  9. import genFixedStyle from './fixed';
  10. import genPaginationStyle from './pagination';
  11. import genRadiusStyle from './radius';
  12. import genRtlStyle from './rtl';
  13. import genSelectionStyle from './selection';
  14. import genSizeStyle from './size';
  15. import genResizeStyle from './resize';
  16. import genSorterStyle from './sorter';
  17. import genStickyStyle from './sticky';
  18. import genSummaryStyle from './summary';
  19. import { clearFix, resetComponent } from '../../style';
  20. const genTableStyle = token => {
  21. const {
  22. componentCls,
  23. fontWeightStrong,
  24. tablePaddingVertical,
  25. tablePaddingHorizontal,
  26. lineWidth,
  27. lineType,
  28. tableBorderColor,
  29. tableFontSize,
  30. tableBg,
  31. tableRadius,
  32. tableHeaderTextColor,
  33. motionDurationMid,
  34. tableHeaderBg,
  35. tableHeaderCellSplitColor,
  36. tableRowHoverBg,
  37. tableSelectedRowBg,
  38. tableSelectedRowHoverBg,
  39. tableFooterTextColor,
  40. tableFooterBg,
  41. paddingContentVerticalLG
  42. } = token;
  43. const tableBorder = `${lineWidth}px ${lineType} ${tableBorderColor}`;
  44. return {
  45. [`${componentCls}-wrapper`]: _extends(_extends({
  46. clear: 'both',
  47. maxWidth: '100%'
  48. }, clearFix()), {
  49. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  50. fontSize: tableFontSize,
  51. background: tableBg,
  52. borderRadius: `${tableRadius}px ${tableRadius}px 0 0`
  53. }),
  54. // https://github.com/ant-design/ant-design/issues/17611
  55. table: {
  56. width: '100%',
  57. textAlign: 'start',
  58. borderRadius: `${tableRadius}px ${tableRadius}px 0 0`,
  59. borderCollapse: 'separate',
  60. borderSpacing: 0
  61. },
  62. // ============================= Cell =============================
  63. [`
  64. ${componentCls}-thead > tr > th,
  65. ${componentCls}-tbody > tr > td,
  66. tfoot > tr > th,
  67. tfoot > tr > td
  68. `]: {
  69. position: 'relative',
  70. padding: `${paddingContentVerticalLG}px ${tablePaddingHorizontal}px`,
  71. overflowWrap: 'break-word'
  72. },
  73. // ============================ Title =============================
  74. [`${componentCls}-title`]: {
  75. padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`
  76. },
  77. // ============================ Header ============================
  78. [`${componentCls}-thead`]: {
  79. [`
  80. > tr > th,
  81. > tr > td
  82. `]: {
  83. position: 'relative',
  84. color: tableHeaderTextColor,
  85. fontWeight: fontWeightStrong,
  86. textAlign: 'start',
  87. background: tableHeaderBg,
  88. borderBottom: tableBorder,
  89. transition: `background ${motionDurationMid} ease`,
  90. "&[colspan]:not([colspan='1'])": {
  91. textAlign: 'center'
  92. },
  93. [`&:not(:last-child):not(${componentCls}-selection-column):not(${componentCls}-row-expand-icon-cell):not([colspan])::before`]: {
  94. position: 'absolute',
  95. top: '50%',
  96. insetInlineEnd: 0,
  97. width: 1,
  98. height: '1.6em',
  99. backgroundColor: tableHeaderCellSplitColor,
  100. transform: 'translateY(-50%)',
  101. transition: `background-color ${motionDurationMid}`,
  102. content: '""'
  103. }
  104. },
  105. '> tr:not(:last-child) > th[colspan]': {
  106. borderBottom: 0
  107. }
  108. },
  109. // ============================ Body ============================
  110. // Borderless Table has unique hover style, which would be implemented with `borderTop`.
  111. [`${componentCls}:not(${componentCls}-bordered)`]: {
  112. [`${componentCls}-tbody`]: {
  113. '> tr': {
  114. '> td': {
  115. borderTop: tableBorder,
  116. borderBottom: 'transparent'
  117. },
  118. '&:last-child > td': {
  119. borderBottom: tableBorder
  120. },
  121. [`&:first-child > td,
  122. &${componentCls}-measure-row + tr > td`]: {
  123. borderTop: 'none',
  124. borderTopColor: 'transparent'
  125. }
  126. }
  127. }
  128. },
  129. // Bordered Table remains simple `borderBottom`.
  130. // Ref issue: https://github.com/ant-design/ant-design/issues/38724
  131. [`${componentCls}${componentCls}-bordered`]: {
  132. [`${componentCls}-tbody`]: {
  133. '> tr': {
  134. '> td': {
  135. borderBottom: tableBorder
  136. }
  137. }
  138. }
  139. },
  140. [`${componentCls}-tbody`]: {
  141. '> tr': {
  142. '> td': {
  143. transition: `background ${motionDurationMid}, border-color ${motionDurationMid}`,
  144. // ========================= Nest Table ===========================
  145. [`
  146. > ${componentCls}-wrapper:only-child,
  147. > ${componentCls}-expanded-row-fixed > ${componentCls}-wrapper:only-child
  148. `]: {
  149. [componentCls]: {
  150. marginBlock: `-${tablePaddingVertical}px`,
  151. marginInline: `${token.tableExpandColumnWidth - tablePaddingHorizontal}px -${tablePaddingHorizontal}px`,
  152. [`${componentCls}-tbody > tr:last-child > td`]: {
  153. borderBottom: 0,
  154. '&:first-child, &:last-child': {
  155. borderRadius: 0
  156. }
  157. }
  158. }
  159. }
  160. },
  161. [`
  162. &${componentCls}-row:hover > td,
  163. > td${componentCls}-cell-row-hover
  164. `]: {
  165. background: tableRowHoverBg
  166. },
  167. [`&${componentCls}-row-selected`]: {
  168. '> td': {
  169. background: tableSelectedRowBg
  170. },
  171. '&:hover > td': {
  172. background: tableSelectedRowHoverBg
  173. }
  174. }
  175. }
  176. },
  177. // ============================ Footer ============================
  178. [`${componentCls}-footer`]: {
  179. padding: `${tablePaddingVertical}px ${tablePaddingHorizontal}px`,
  180. color: tableFooterTextColor,
  181. background: tableFooterBg
  182. }
  183. })
  184. };
  185. };
  186. // ============================== Export ==============================
  187. export default genComponentStyleHook('Table', token => {
  188. const {
  189. controlItemBgActive,
  190. controlItemBgActiveHover,
  191. colorTextPlaceholder,
  192. colorTextHeading,
  193. colorSplit,
  194. colorBorderSecondary,
  195. fontSize,
  196. padding,
  197. paddingXS,
  198. paddingSM,
  199. controlHeight,
  200. colorFillAlter,
  201. colorIcon,
  202. colorIconHover,
  203. opacityLoading,
  204. colorBgContainer,
  205. borderRadiusLG,
  206. colorFillContent,
  207. colorFillSecondary,
  208. controlInteractiveSize: checkboxSize
  209. } = token;
  210. const baseColorAction = new TinyColor(colorIcon);
  211. const baseColorActionHover = new TinyColor(colorIconHover);
  212. const tableSelectedRowBg = controlItemBgActive;
  213. const zIndexTableFixed = 2;
  214. const colorFillSecondarySolid = new TinyColor(colorFillSecondary).onBackground(colorBgContainer).toHexString();
  215. const colorFillContentSolid = new TinyColor(colorFillContent).onBackground(colorBgContainer).toHexString();
  216. const colorFillAlterSolid = new TinyColor(colorFillAlter).onBackground(colorBgContainer).toHexString();
  217. const tableToken = mergeToken(token, {
  218. tableFontSize: fontSize,
  219. tableBg: colorBgContainer,
  220. tableRadius: borderRadiusLG,
  221. tablePaddingVertical: padding,
  222. tablePaddingHorizontal: padding,
  223. tablePaddingVerticalMiddle: paddingSM,
  224. tablePaddingHorizontalMiddle: paddingXS,
  225. tablePaddingVerticalSmall: paddingXS,
  226. tablePaddingHorizontalSmall: paddingXS,
  227. tableBorderColor: colorBorderSecondary,
  228. tableHeaderTextColor: colorTextHeading,
  229. tableHeaderBg: colorFillAlterSolid,
  230. tableFooterTextColor: colorTextHeading,
  231. tableFooterBg: colorFillAlterSolid,
  232. tableHeaderCellSplitColor: colorBorderSecondary,
  233. tableHeaderSortBg: colorFillSecondarySolid,
  234. tableHeaderSortHoverBg: colorFillContentSolid,
  235. tableHeaderIconColor: baseColorAction.clone().setAlpha(baseColorAction.getAlpha() * opacityLoading).toRgbString(),
  236. tableHeaderIconColorHover: baseColorActionHover.clone().setAlpha(baseColorActionHover.getAlpha() * opacityLoading).toRgbString(),
  237. tableBodySortBg: colorFillAlterSolid,
  238. tableFixedHeaderSortActiveBg: colorFillSecondarySolid,
  239. tableHeaderFilterActiveBg: colorFillContent,
  240. tableFilterDropdownBg: colorBgContainer,
  241. tableRowHoverBg: colorFillAlterSolid,
  242. tableSelectedRowBg,
  243. tableSelectedRowHoverBg: controlItemBgActiveHover,
  244. zIndexTableFixed,
  245. zIndexTableSticky: zIndexTableFixed + 1,
  246. tableFontSizeMiddle: fontSize,
  247. tableFontSizeSmall: fontSize,
  248. tableSelectionColumnWidth: controlHeight,
  249. tableExpandIconBg: colorBgContainer,
  250. tableExpandColumnWidth: checkboxSize + 2 * token.padding,
  251. tableExpandedRowBg: colorFillAlter,
  252. // Dropdown
  253. tableFilterDropdownWidth: 120,
  254. tableFilterDropdownHeight: 264,
  255. tableFilterDropdownSearchWidth: 140,
  256. // Virtual Scroll Bar
  257. tableScrollThumbSize: 8,
  258. tableScrollThumbBg: colorTextPlaceholder,
  259. tableScrollThumbBgHover: colorTextHeading,
  260. tableScrollBg: colorSplit
  261. });
  262. return [genTableStyle(tableToken), genPaginationStyle(tableToken), genSummaryStyle(tableToken), genSorterStyle(tableToken), genFilterStyle(tableToken), genBorderedStyle(tableToken), genRadiusStyle(tableToken), genExpandStyle(tableToken), genSummaryStyle(tableToken), genEmptyStyle(tableToken), genSelectionStyle(tableToken), genFixedStyle(tableToken), genStickyStyle(tableToken), genEllipsisStyle(tableToken), genSizeStyle(tableToken), genResizeStyle(tableToken), genRtlStyle(tableToken)];
  263. });