table.scss 14 KB

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