index.js 10 KB

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