table.scss 14 KB

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