table.scss 13 KB

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