table.scss 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. @use 'sass:map';
  2. @use 'mixins/mixins' as *;
  3. @use 'mixins/var' as *;
  4. @use 'common/var' as *;
  5. @include b(table) {
  6. @include set-component-css-var('table', $table);
  7. }
  8. @include b(table) {
  9. position: relative;
  10. overflow: hidden;
  11. box-sizing: border-box;
  12. height: fit-content;
  13. width: 100%;
  14. max-width: 100%;
  15. background-color: getCssVar('table-bg-color');
  16. font-size: 14px;
  17. color: getCssVar('table-text-color');
  18. @include e(inner-wrapper) {
  19. position: relative;
  20. display: flex;
  21. flex-direction: column;
  22. height: 100%;
  23. // 表格底部伪 border,总是有的
  24. &::before {
  25. @include extend-rule(border-pseudo);
  26. left: 0;
  27. bottom: 0px;
  28. width: 100%;
  29. height: 1px;
  30. }
  31. }
  32. &.has-footer {
  33. &.#{$namespace}-table--scrollable-y,
  34. &.#{$namespace}-table--fluid-height {
  35. tr:last-child td.#{$namespace}-table__cell {
  36. border-bottom-color: transparent;
  37. }
  38. }
  39. }
  40. // when data is empty
  41. @include e(empty-block) {
  42. position: sticky;
  43. left: 0;
  44. min-height: 60px;
  45. text-align: center;
  46. width: 100%;
  47. display: flex;
  48. justify-content: center;
  49. align-items: center;
  50. }
  51. @include e(empty-text) {
  52. // min-height doesn't work in IE10 and IE11 https://github.com/philipwalton/flexbugs#3-min-height-on-a-flex-container-wont-apply-to-its-flex-items
  53. // set empty text line height up to contrainer min-height as workaround.
  54. line-height: 60px;
  55. width: 50%;
  56. color: getCssVar('text-color', 'secondary');
  57. }
  58. // expand the row
  59. @include e(expand-column) {
  60. .cell {
  61. padding: 0;
  62. text-align: center;
  63. user-select: none;
  64. }
  65. }
  66. @include e(expand-icon) {
  67. position: relative;
  68. cursor: pointer;
  69. color: getCssVar('text-color', 'regular');
  70. font-size: 12px;
  71. transition: transform getCssVar('transition-duration-fast') ease-in-out;
  72. height: 20px;
  73. @include m(expanded) {
  74. transform: rotate(90deg);
  75. }
  76. > .#{$namespace}-icon {
  77. font-size: 12px;
  78. }
  79. }
  80. @include e(expanded-cell) {
  81. background-color: getCssVar('table-expanded-cell-bg-color');
  82. // increase the weight purely
  83. &[class*='cell'] {
  84. padding: 20px 50px;
  85. }
  86. &:hover {
  87. background-color: transparent !important;
  88. }
  89. }
  90. @include e(placeholder) {
  91. display: inline-block;
  92. width: 20px;
  93. }
  94. @include e(append-wrapper) {
  95. // avoid overlapping margin https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing
  96. overflow: hidden;
  97. }
  98. @include m(fit) {
  99. border-right: 0;
  100. border-bottom: 0;
  101. .#{$namespace}-table__cell.gutter {
  102. border-right-width: 1px;
  103. }
  104. }
  105. thead {
  106. color: getCssVar('table-header-text-color');
  107. th {
  108. font-weight: 600;
  109. }
  110. &.is-group {
  111. th.#{$namespace}-table__cell {
  112. background: getCssVar('fill-color', 'light');
  113. }
  114. }
  115. }
  116. .#{$namespace}-table__cell {
  117. padding: map.get($table-padding, 'default');
  118. min-width: 0;
  119. box-sizing: border-box;
  120. text-overflow: ellipsis;
  121. vertical-align: middle;
  122. position: relative;
  123. text-align: left;
  124. z-index: 1;
  125. @include when(center) {
  126. text-align: center;
  127. }
  128. @include when(right) {
  129. text-align: right;
  130. }
  131. &.gutter {
  132. width: 15px;
  133. border-right-width: 0;
  134. border-bottom-width: 0;
  135. padding: 0;
  136. }
  137. &.is-hidden {
  138. > * {
  139. visibility: hidden;
  140. }
  141. }
  142. }
  143. .cell {
  144. box-sizing: border-box;
  145. overflow: hidden;
  146. text-overflow: ellipsis;
  147. white-space: normal;
  148. word-break: break-all;
  149. line-height: 23px;
  150. padding: 0 12px;
  151. &.#{$namespace}-tooltip {
  152. white-space: nowrap;
  153. min-width: 50px;
  154. }
  155. }
  156. @each $size in (large, default, small) {
  157. @include m($size) {
  158. font-size: map.get($table-font-size, $size);
  159. .#{$namespace}-table__cell {
  160. padding: map.get($table-padding, $size);
  161. }
  162. .cell {
  163. padding: map.get($table-cell-padding, $size);
  164. }
  165. }
  166. }
  167. tr {
  168. background-color: getCssVar('table-tr-bg-color');
  169. input[type='checkbox'] {
  170. margin: 0;
  171. }
  172. }
  173. th.#{$namespace}-table__cell.is-leaf,
  174. td.#{$namespace}-table__cell {
  175. border-bottom: getCssVar('table-border');
  176. }
  177. th.#{$namespace}-table__cell.is-sortable {
  178. cursor: pointer;
  179. }
  180. th.#{$namespace}-table__cell {
  181. user-select: none;
  182. background-color: getCssVar('table-header-bg-color');
  183. > .cell.highlight {
  184. color: getCssVar('color-primary');
  185. }
  186. &.required > div::before {
  187. display: inline-block;
  188. content: '';
  189. width: 8px;
  190. height: 8px;
  191. border-radius: 50%;
  192. background: #ff4d51;
  193. margin-right: 5px;
  194. vertical-align: middle;
  195. }
  196. }
  197. td.#{$namespace}-table__cell {
  198. div {
  199. box-sizing: border-box;
  200. }
  201. &.gutter {
  202. width: 0;
  203. }
  204. }
  205. @include e((footer-wrapper)) {
  206. border-top: getCssVar('table-border');
  207. }
  208. // 拥有多级表头
  209. @include m((group, border)) {
  210. @include share-rule(border-pseudo) {
  211. content: '';
  212. position: absolute;
  213. background-color: getCssVar('table-border-color');
  214. z-index: 3;
  215. }
  216. }
  217. // table--border
  218. @include m(border) {
  219. @include e(inner-wrapper) {
  220. &::after {
  221. @include extend-rule(border-pseudo);
  222. left: 0;
  223. top: 0;
  224. width: 100%;
  225. height: 1px;
  226. }
  227. }
  228. &::before {
  229. @include extend-rule(border-pseudo);
  230. top: -1px;
  231. left: 0;
  232. width: 1px;
  233. height: 100%;
  234. }
  235. &::after {
  236. @include extend-rule(border-pseudo);
  237. top: -1px;
  238. right: 0;
  239. width: 1px;
  240. height: 100%;
  241. }
  242. @include e(inner-wrapper) {
  243. border-right: none;
  244. border-bottom: none;
  245. }
  246. @include e(footer-wrapper) {
  247. position: relative;
  248. flex-shrink: 0;
  249. }
  250. .#{$namespace}-table__cell {
  251. border-right: getCssVar('table-border');
  252. }
  253. th.#{$namespace}-table__cell.gutter:last-of-type {
  254. border-bottom: getCssVar('table-border');
  255. border-bottom-width: 1px;
  256. }
  257. & th.#{$namespace}-table__cell {
  258. border-bottom: getCssVar('table-border');
  259. }
  260. }
  261. @include m(hidden) {
  262. visibility: hidden;
  263. }
  264. @include e((header-wrapper, body-wrapper, footer-wrapper)) {
  265. width: 100%;
  266. tr {
  267. td,
  268. th {
  269. &.#{$namespace}-table-fixed-column--left,
  270. &.#{$namespace}-table-fixed-column--right {
  271. position: sticky !important;
  272. z-index: 2;
  273. background: getCssVar('bg-color');
  274. &.is-last-column,
  275. &.is-first-column {
  276. &::before {
  277. content: '';
  278. position: absolute;
  279. top: 0px;
  280. width: 10px;
  281. bottom: -1px;
  282. overflow-x: hidden;
  283. overflow-y: hidden;
  284. box-shadow: none;
  285. touch-action: none;
  286. pointer-events: none;
  287. }
  288. }
  289. &.is-first-column {
  290. &::before {
  291. left: -10px;
  292. }
  293. }
  294. &.is-last-column {
  295. &::before {
  296. right: -10px;
  297. box-shadow: none;
  298. }
  299. }
  300. }
  301. &.#{$namespace}-table__fixed-right-patch {
  302. position: sticky !important;
  303. z-index: 2;
  304. background: #fff;
  305. right: 0;
  306. }
  307. }
  308. }
  309. }
  310. @include e(header-wrapper) {
  311. flex-shrink: 0;
  312. tr {
  313. th {
  314. &.#{$namespace}-table-fixed-column--left,
  315. &.#{$namespace}-table-fixed-column--right {
  316. background-color: getCssVar('table-header-bg-color');
  317. }
  318. }
  319. }
  320. }
  321. @include e((header, body, footer)) {
  322. table-layout: fixed;
  323. border-collapse: separate;
  324. }
  325. @include e((header-wrapper, footer-wrapper)) {
  326. overflow: hidden;
  327. & tbody td.#{$namespace}-table__cell {
  328. background-color: getCssVar('table-row-hover-bg-color');
  329. color: getCssVar('table-text-color');
  330. }
  331. }
  332. @include e((header-wrapper, body-wrapper)) {
  333. .#{$namespace}-table-column--selection {
  334. > .cell {
  335. display: inline-flex;
  336. align-items: center;
  337. height: 23px;
  338. }
  339. .#{$namespace}-checkbox {
  340. height: unset;
  341. }
  342. }
  343. }
  344. @include when(scrolling-left) {
  345. .#{$namespace}-table-fixed-column--right.is-first-column {
  346. &::before {
  347. box-shadow: getCssVar('table-fixed-right-column');
  348. }
  349. }
  350. &.#{$namespace}-table--border {
  351. .#{$namespace}-table-fixed-column--left {
  352. &.is-last-column {
  353. &.#{$namespace}-table__cell {
  354. border-right: getCssVar('table-border');
  355. }
  356. }
  357. }
  358. }
  359. th.#{$namespace}-table-fixed-column--left {
  360. background-color: getCssVar('table-header-bg-color');
  361. }
  362. }
  363. @include when(scrolling-right) {
  364. .#{$namespace}-table-fixed-column--left.is-last-column {
  365. &::before {
  366. box-shadow: getCssVar('table-fixed-left-column');
  367. }
  368. }
  369. .#{$namespace}-table-fixed-column--left.is-last-column.#{$namespace}-table__cell {
  370. border-right: none;
  371. }
  372. th.#{$namespace}-table-fixed-column--right {
  373. background-color: getCssVar('table-header-bg-color');
  374. }
  375. }
  376. @include when(scrolling-middle) {
  377. .#{$namespace}-table-fixed-column--left.is-last-column.#{$namespace}-table__cell {
  378. border-right: none;
  379. }
  380. .#{$namespace}-table-fixed-column--right.is-first-column {
  381. &::before {
  382. box-shadow: getCssVar('table-fixed-right-column');
  383. }
  384. }
  385. .#{$namespace}-table-fixed-column--left.is-last-column {
  386. &::before {
  387. box-shadow: getCssVar('table-fixed-left-column');
  388. }
  389. }
  390. }
  391. @include when(scrolling-none) {
  392. .#{$namespace}-table-fixed-column--left,
  393. .#{$namespace}-table-fixed-column--right {
  394. &.is-first-column,
  395. &.is-last-column {
  396. &::before {
  397. box-shadow: none;
  398. }
  399. }
  400. }
  401. th.#{$namespace}-table-fixed-column--left,
  402. th.#{$namespace}-table-fixed-column--right {
  403. background-color: getCssVar('table-header-bg-color');
  404. }
  405. }
  406. @include e(body-wrapper) {
  407. overflow: hidden;
  408. position: relative;
  409. flex: 1;
  410. .#{$namespace}-scrollbar__bar {
  411. z-index: 2;
  412. }
  413. }
  414. .caret-wrapper {
  415. display: inline-flex;
  416. flex-direction: column;
  417. align-items: center;
  418. height: 14px;
  419. width: 24px;
  420. vertical-align: middle;
  421. cursor: pointer;
  422. overflow: initial;
  423. position: relative;
  424. }
  425. .sort-caret {
  426. width: 0;
  427. height: 0;
  428. border: solid 5px transparent;
  429. position: absolute;
  430. left: 7px;
  431. &.ascending {
  432. border-bottom-color: getCssVar('text-color', 'placeholder');
  433. top: -5px;
  434. }
  435. &.descending {
  436. border-top-color: getCssVar('text-color', 'placeholder');
  437. bottom: -3px;
  438. }
  439. }
  440. .ascending .sort-caret.ascending {
  441. border-bottom-color: getCssVar('color-primary');
  442. }
  443. .descending .sort-caret.descending {
  444. border-top-color: getCssVar('color-primary');
  445. }
  446. .hidden-columns {
  447. visibility: hidden;
  448. position: absolute;
  449. z-index: -1;
  450. }
  451. @include m(striped) {
  452. & .#{$namespace}-table__body {
  453. & tr.#{$namespace}-table__row--striped {
  454. td.#{$namespace}-table__cell {
  455. background: getCssVar('fill-color', 'lighter');
  456. }
  457. &.current-row td.#{$namespace}-table__cell {
  458. background-color: getCssVar('table-current-row-bg-color');
  459. }
  460. }
  461. }
  462. }
  463. @include e(body) {
  464. tr.hover-row {
  465. &,
  466. &.#{$namespace}-table__row--striped {
  467. &,
  468. &.current-row {
  469. > td.#{$namespace}-table__cell {
  470. background-color: getCssVar('table-row-hover-bg-color');
  471. }
  472. }
  473. }
  474. }
  475. tr.current-row > td.#{$namespace}-table__cell {
  476. background-color: getCssVar('table-current-row-bg-color');
  477. }
  478. }
  479. @include e(column-resize-proxy) {
  480. position: absolute;
  481. left: 200px;
  482. top: 0;
  483. bottom: 0;
  484. width: 0;
  485. border-left: getCssVar('table-border');
  486. z-index: 10;
  487. }
  488. @include e(column-filter-trigger) {
  489. display: inline-block;
  490. cursor: pointer;
  491. & i {
  492. color: getCssVar('color-info');
  493. font-size: 14px;
  494. vertical-align: middle;
  495. }
  496. }
  497. @include e(border-left-patch) {
  498. top: 0;
  499. left: 0;
  500. width: 1px;
  501. height: 100%;
  502. z-index: 3;
  503. position: absolute;
  504. background-color: getCssVar('table-border-color');
  505. }
  506. @include e(border-bottom-patch) {
  507. left: 0;
  508. height: 1px;
  509. z-index: 3;
  510. position: absolute;
  511. background-color: getCssVar('table-border-color');
  512. }
  513. @include e(border-right-patch) {
  514. top: 0;
  515. height: 100%;
  516. width: 1px;
  517. z-index: 3;
  518. position: absolute;
  519. background-color: getCssVar('table-border-color');
  520. }
  521. @include m(enable-row-transition) {
  522. .#{$namespace}-table__body td.#{$namespace}-table__cell {
  523. transition: background-color 0.25s ease;
  524. }
  525. }
  526. @include m(enable-row-hover) {
  527. .#{$namespace}-table__body tr:hover > td.#{$namespace}-table__cell {
  528. background-color: getCssVar('table-row-hover-bg-color');
  529. }
  530. }
  531. [class*='#{$namespace}-table__row--level'] {
  532. .#{$namespace}-table__expand-icon {
  533. display: inline-block;
  534. width: 12px;
  535. line-height: 12px;
  536. height: 12px;
  537. text-align: center;
  538. margin-right: 8px;
  539. }
  540. }
  541. @include b(table) {
  542. &.#{$namespace}-table--border {
  543. .#{$namespace}-table__cell {
  544. border-right: getCssVar('table-border');
  545. }
  546. }
  547. }
  548. &:not(.#{$namespace}-table--border) {
  549. .#{$namespace}-table__cell {
  550. border-right: none;
  551. }
  552. > .#{$namespace}-table__inner-wrapper {
  553. &::after {
  554. content: none;
  555. }
  556. }
  557. }
  558. }