table.scss 14 KB

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