_data-table-theme.scss 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. //
  2. // Copyright 2020 Google Inc.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // stylelint-disable selector-class-pattern --
  23. // NOTE: We disable `selector-class-pattern` above to allow using `mdc-` class
  24. // selectors.
  25. @use 'sass:map';
  26. @use 'sass:math';
  27. @use 'sass:list';
  28. @use 'sass:meta';
  29. @use '@material/animation/functions';
  30. @use '@material/checkbox/checkbox-theme';
  31. @use '@material/density/density';
  32. @use '@material/elevation/mixins';
  33. @use '@material/feature-targeting/feature-targeting';
  34. @use '@material/icon-button/icon-button-theme';
  35. @use '@material/list/evolution-mixins' as list-theme;
  36. @use '@material/rtl/rtl';
  37. @use '@material/select/select-theme';
  38. @use '@material/shape/functions' as shape-functions;
  39. @use '@material/shape/mixins' as shape-mixins;
  40. @use '@material/theme/keys';
  41. @use '@material/theme/theme';
  42. @use '@material/theme/theme-color';
  43. @use '@material/tokens/v0_132' as tokens;
  44. @use '@material/touch-target/touch-target';
  45. @use '@material/typography/typography';
  46. $fill-color: surface !default;
  47. $header-row-fill-color: surface !default;
  48. $row-fill-color: inherit !default;
  49. $selected-row-fill-color: rgba(theme-color.prop-value(primary), 0.04) !default;
  50. $checked-icon-color: primary !default;
  51. $divider-color: rgba(theme-color.prop-value(on-surface), 0.12) !default;
  52. $divider-size: 1px !default;
  53. $row-hover-fill-color: rgba(theme-color.prop-value(on-surface), 0.04) !default;
  54. $header-row-text-color: rgba(theme-color.prop-value(on-surface), 0.87) !default;
  55. $row-text-color: rgba(theme-color.prop-value(on-surface), 0.87) !default;
  56. $sort-icon-color: rgba(theme-color.prop-value(on-surface), 0.6) !default;
  57. $sort-icon-active-color: rgba(
  58. theme-color.prop-value(on-surface),
  59. 0.87
  60. ) !default;
  61. $sort-icon-density-scale: -5 !default;
  62. $shape-radius: medium !default;
  63. $stroke-size: 1px !default;
  64. $stroke-color: rgba(theme-color.prop-value(on-surface), 0.12) !default;
  65. $row-height: 52px !default;
  66. $header-row-height: get-header-row-height($row-height) !default;
  67. $cell-leading-padding: 16px !default;
  68. $cell-trailing-padding: 16px !default;
  69. $minimum-row-height: 36px !default;
  70. $maximum-row-height: $row-height !default;
  71. $default-density-scale: density.$default-scale !default;
  72. $density-config: (
  73. height: (
  74. maximum: $row-height,
  75. default: $row-height,
  76. minimum: $minimum-row-height,
  77. ),
  78. );
  79. $pagination-rows-per-page-select-height: 36px;
  80. $light-theme: tokens.md-comp-data-table-values();
  81. @function remove-unsupported-keys($theme) {
  82. $theme: map.remove(
  83. $theme,
  84. (
  85. // TODO(b/254356584): We don't set pagination background-color.
  86. 'footer-container-color',
  87. // TODO(b/254356584): Select doesn't have Theming API support yet.
  88. 'footer-outlined-select-text-field-container-height',
  89. // TODO(b/254356584): We don't add hover styles on header.
  90. 'header-hover-headline-color',
  91. // TODO(b/254356584): We don't add hover styles on header.
  92. 'header-hover-sorting-icon-button-color',
  93. // TODO(b/254356584): We don't support disabled rows.
  94. 'row-item-disabled-label-text-color',
  95. // TODO(b/254356584): We don't support disabled rows.
  96. 'row-item-disabled-label-text-opacity',
  97. // TODO(b/254356584): We don't add hover styles on selected rows.
  98. 'row-item-selected-hover-state-layer-color',
  99. // TODO(b/254356584): We don't add hover styles on selected rows.
  100. 'row-item-selected-hover-state-layer-opacity',
  101. // TODO(b/254356584): We don't have state layers on rows.
  102. 'row-item-unselected-hover-state-layer-color'
  103. // TODO(b/254356584): We don't have state layers on rows.
  104. 'row-item-unselected-hover-state-layer-opacity'
  105. )
  106. );
  107. @return $theme;
  108. }
  109. $_validation-theme: remove-unsupported-keys($light-theme);
  110. $custom-property-prefix: 'data-table';
  111. @mixin theme($theme) {
  112. @include theme.validate-theme($_validation-theme, $theme);
  113. @include keys.declare-custom-properties($theme, $custom-property-prefix);
  114. }
  115. @mixin theme-styles($theme, $query: feature-targeting.all()) {
  116. $feat-color: feature-targeting.create-target($query, color);
  117. $feat-structure: feature-targeting.create-target($query, structure);
  118. $feat-typography: feature-targeting.create-target($query, typography);
  119. @include theme.validate-theme-styles($_validation-theme, $theme);
  120. $theme: keys.create-theme-properties($theme, $custom-property-prefix);
  121. ///////////
  122. // Table //
  123. ///////////
  124. @include shape-radius(map.get($theme, 'container-shape'), $query: $query);
  125. @include stroke-color(map.get($theme, 'outline-color'), $query: $query);
  126. @include stroke-size(map.get($theme, 'outline-width'), $query: $query);
  127. ////////////
  128. // Header //
  129. ////////////
  130. @include header-row-fill-color(
  131. map.get($theme, 'header-container-color'),
  132. $query: $query
  133. );
  134. @include header-row-height(
  135. map.get($theme, 'header-container-height'),
  136. $query: $query
  137. );
  138. @include header-row-text-color(
  139. map.get($theme, 'header-headline-color'),
  140. $query: $query
  141. );
  142. .mdc-data-table__header-cell {
  143. @include feature-targeting.targets($feat-typography) {
  144. $font: map.get($theme, 'header-headline-font');
  145. $line-height: map.get($theme, 'header-headline-line-height');
  146. $size: map.get($theme, 'header-headline-size');
  147. $tracking: map.get($theme, 'header-headline-tracking');
  148. $weight: map.get($theme, 'header-headline-weight');
  149. @include theme.property('font-family', $font);
  150. @include theme.property('line-height', $line-height);
  151. @include theme.property('font-size', $size);
  152. @include theme.property('letter-spacing', $tracking);
  153. @include theme.property('font-weight', $weight);
  154. }
  155. }
  156. //////////
  157. // Rows //
  158. //////////
  159. // Separated because row-height() sets min-height on pagination
  160. .mdc-data-table__row {
  161. @include feature-targeting.targets($feat-structure) {
  162. @include theme.property(
  163. 'height',
  164. map.get($theme, 'row-item-container-height')
  165. );
  166. }
  167. }
  168. .mdc-data-table__cell {
  169. @include feature-targeting.targets($feat-typography) {
  170. $font: map.get($theme, 'row-item-label-text-font');
  171. $line-height: map.get($theme, 'row-item-label-text-line-height');
  172. $size: map.get($theme, 'row-item-label-text-size');
  173. $tracking: map.get($theme, 'row-item-label-text-tracking');
  174. $weight: map.get($theme, 'row-item-label-text-weight');
  175. @include theme.property('font-family', $font);
  176. @include theme.property('line-height', $line-height);
  177. @include theme.property('font-size', $size);
  178. @include theme.property('letter-spacing', $tracking);
  179. @include theme.property('font-weight', $weight);
  180. }
  181. @include feature-targeting.targets($feat-color) {
  182. // Separated because row-text-color() also sets color on pagination text
  183. @include theme.property(
  184. 'color',
  185. map.get($theme, 'row-item-label-text-color')
  186. );
  187. }
  188. }
  189. .mdc-data-table__cell,
  190. .mdc-data-table__header-cell {
  191. @include feature-targeting.targets($feat-color) {
  192. // Separated because divider-color() also sets color on pagination select
  193. @include theme.property(
  194. 'border-bottom-color',
  195. map.get($theme, 'row-item-outline-color')
  196. );
  197. }
  198. }
  199. .mdc-data-table__pagination {
  200. @include feature-targeting.targets($feat-color) {
  201. // Separated because divider-color() also sets color on pagination select
  202. @include theme.property(
  203. 'border-top-color',
  204. map.get($theme, 'row-item-outline-color')
  205. );
  206. }
  207. }
  208. @include divider-size(
  209. map.get($theme, 'row-item-outline-width'),
  210. $query: $query
  211. );
  212. @include row-fill-color(
  213. map.get($theme, 'row-item-unselected-container-color'),
  214. $query: $query
  215. );
  216. @include selected-row-fill-color(
  217. map.get($theme, 'row-item-selected-container-color'),
  218. $query: $query
  219. );
  220. ////////////
  221. // Footer //
  222. ////////////
  223. .mdc-data-table__pagination {
  224. @include feature-targeting.targets($feat-typography) {
  225. $font: map.get($theme, 'footer-supporting-text-font');
  226. $line-height: map.get($theme, 'footer-supporting-text-line-height');
  227. $size: map.get($theme, 'footer-supporting-text-size');
  228. $tracking: map.get($theme, 'footer-supporting-text-tracking');
  229. $weight: map.get($theme, 'footer-supporting-text-weight');
  230. @include theme.property('font-family', $font);
  231. @include theme.property('line-height', $line-height);
  232. @include theme.property('font-size', $size);
  233. @include theme.property('letter-spacing', $tracking);
  234. @include theme.property('font-weight', $weight);
  235. }
  236. @include feature-targeting.targets($feat-structure) {
  237. // Separated because row-height() also sets height on row
  238. @include theme.property(
  239. 'min-height',
  240. map.get($theme, 'footer-container-height')
  241. );
  242. }
  243. }
  244. .mdc-data-table__pagination-total,
  245. .mdc-data-table__pagination-rows-per-page-label {
  246. @include feature-targeting.targets($feat-color) {
  247. // Separated because row-text-color() also sets color on row text
  248. @include theme.property(
  249. 'color',
  250. map.get($theme, 'footer-supporting-text-color')
  251. );
  252. }
  253. }
  254. }
  255. @function get-header-row-height($height) {
  256. @return $height + 4px;
  257. }
  258. /// Sets the color of sort icon button when it is in idle state.
  259. /// (icon showed on header cell focus)
  260. /// @param {String} $color - Color of sort icon button
  261. @mixin sort-icon-color($color, $query: feature-targeting.all()) {
  262. $feat-color: feature-targeting.create-target($query, color);
  263. .mdc-data-table__sort-icon-button {
  264. @include icon-button-theme.ink-color($color, $query: $query);
  265. }
  266. }
  267. /// Sets the color of sort icon button when it is activated (sorted).
  268. /// @param {String} $color - Color of sort icon button
  269. @mixin sort-icon-active-color($color, $query: feature-targeting.all()) {
  270. $feat-color: feature-targeting.create-target($query, color);
  271. .mdc-data-table__header-cell--sorted .mdc-data-table__sort-icon-button {
  272. @include icon-button-theme.ink-color($color, $query: $query);
  273. }
  274. }
  275. @mixin fill-color($color, $query: feature-targeting.all()) {
  276. $feat-color: feature-targeting.create-target($query, color);
  277. @include feature-targeting.targets($feat-color) {
  278. @include theme.property('background-color', $color);
  279. }
  280. }
  281. @mixin header-row-fill-color($color, $query: feature-targeting.all()) {
  282. $feat-color: feature-targeting.create-target($query, color);
  283. // Set background color to cell instead of row to support sticky header.
  284. .mdc-data-table__header-cell {
  285. @include feature-targeting.targets($feat-color) {
  286. @include theme.property('background-color', $color);
  287. }
  288. }
  289. }
  290. @mixin row-fill-color($color, $query: feature-targeting.all()) {
  291. $feat-color: feature-targeting.create-target($query, color);
  292. .mdc-data-table__row {
  293. @include feature-targeting.targets($feat-color) {
  294. @include theme.property('background-color', $color);
  295. }
  296. }
  297. }
  298. @mixin selected-row-fill-color($color, $query: feature-targeting.all()) {
  299. $feat-color: feature-targeting.create-target($query, color);
  300. .mdc-data-table__row--selected {
  301. @include feature-targeting.targets($feat-color) {
  302. @include theme.property('background-color', $color);
  303. }
  304. }
  305. }
  306. @mixin checked-icon-color($color, $query: feature-targeting.all()) {
  307. .mdc-data-table__header-row-checkbox,
  308. .mdc-data-table__row-checkbox {
  309. @include checkbox-theme.focus-indicator-color($color, $query: $query);
  310. @include checkbox-theme.container-colors(
  311. $marked-stroke-color: $color,
  312. $marked-fill-color: $color,
  313. $query: $query
  314. );
  315. }
  316. }
  317. ///
  318. /// Sets divider color of data table (including outline color of rows per page
  319. /// select). Use `stroke-color()` to set table border color.
  320. /// @param {Color} $color Divider color.
  321. ///
  322. @mixin divider-color($color, $query: feature-targeting.all()) {
  323. $feat-color: feature-targeting.create-target($query, color);
  324. .mdc-data-table__pagination-rows-per-page-select--outlined {
  325. @include select-theme.outline-color($color, $query: $query);
  326. }
  327. .mdc-data-table__cell,
  328. .mdc-data-table__header-cell {
  329. @include feature-targeting.targets($feat-color) {
  330. @include theme.property('border-bottom-color', $color);
  331. }
  332. }
  333. .mdc-data-table__pagination {
  334. @include feature-targeting.targets($feat-color) {
  335. @include theme.property('border-top-color', $color);
  336. }
  337. }
  338. }
  339. @mixin divider-size($size, $query: feature-targeting.all()) {
  340. $feat-structure: feature-targeting.create-target($query, structure);
  341. .mdc-data-table__cell,
  342. .mdc-data-table__header-cell {
  343. @include feature-targeting.targets($feat-structure) {
  344. @include theme.property('border-bottom-width', $size);
  345. border-bottom-style: solid;
  346. }
  347. }
  348. .mdc-data-table__pagination {
  349. @include feature-targeting.targets($feat-structure) {
  350. @include theme.property('border-top-width', $size);
  351. border-top-style: solid;
  352. }
  353. }
  354. .mdc-data-table__row:last-child .mdc-data-table__cell {
  355. @include feature-targeting.targets($feat-structure) {
  356. border-bottom: none;
  357. }
  358. }
  359. }
  360. @mixin row-hover-fill-color($color, $query: feature-targeting.all()) {
  361. $feat-color: feature-targeting.create-target($query, color);
  362. .mdc-data-table__row:not(.mdc-data-table__row--selected):hover {
  363. @include feature-targeting.targets($feat-color) {
  364. @include theme.property('background-color', $color);
  365. }
  366. }
  367. }
  368. @mixin header-row-text-color($color, $query: feature-targeting.all()) {
  369. $feat-color: feature-targeting.create-target($query, color);
  370. .mdc-data-table__header-cell {
  371. @include feature-targeting.targets($feat-color) {
  372. @include theme.property('color', $color);
  373. }
  374. }
  375. }
  376. ///
  377. /// Sets row text color (including pagination row text).
  378. /// @param {Color} $color Row text color
  379. ///
  380. @mixin row-text-color($color, $query: feature-targeting.all()) {
  381. $feat-color: feature-targeting.create-target($query, color);
  382. .mdc-data-table__pagination-total,
  383. .mdc-data-table__pagination-rows-per-page-label,
  384. .mdc-data-table__cell {
  385. @include feature-targeting.targets($feat-color) {
  386. @include theme.property('color', $color);
  387. }
  388. }
  389. }
  390. ///
  391. /// Sets rounded shape radius to data table.
  392. /// @param {Number|List} $radius - Shape radius in `border-radius` CSS format.
  393. /// @param {Boolean} $rtl-reflexive - Set to `true` to flip radius corners in
  394. /// RTL context.
  395. ///
  396. @mixin shape-radius(
  397. $radius,
  398. $rtl-reflexive: false,
  399. $query: feature-targeting.all()
  400. ) {
  401. $feat-structure: feature-targeting.create-target($query, structure);
  402. @include shape-mixins.radius($radius, $rtl-reflexive, $query: $query);
  403. // Apply same border radius as parent to leading/trailing header cells,
  404. // and leading/trailing cells of last row.
  405. // Cells that have explicit background color applied require border
  406. // radius to take the parents' rounded shape.
  407. $border-radius: shape-functions.unpack-radius($radius);
  408. $top-left-radius: shape-functions.resolve-radius(list.nth($border-radius, 1));
  409. $top-right-radius: shape-functions.resolve-radius(
  410. list.nth($border-radius, 2)
  411. );
  412. $bottom-right-radius: shape-functions.resolve-radius(
  413. list.nth($border-radius, 3)
  414. );
  415. $bottom-left-radius: shape-functions.resolve-radius(
  416. list.nth($border-radius, 4)
  417. );
  418. .mdc-data-table__header-cell:first-child {
  419. @include feature-targeting.targets($feat-structure) {
  420. @include theme.property(border-top-left-radius, $top-left-radius);
  421. @include rtl.rtl {
  422. @include theme.property(
  423. border-top-right-radius,
  424. if($rtl-reflexive, $top-left-radius, $top-right-radius)
  425. );
  426. border-top-left-radius: 0;
  427. }
  428. }
  429. }
  430. .mdc-data-table__header-cell:last-child {
  431. @include feature-targeting.targets($feat-structure) {
  432. @include theme.property(border-top-right-radius, $top-right-radius);
  433. @include rtl.rtl {
  434. @include theme.property(
  435. border-top-left-radius,
  436. if($rtl-reflexive, $top-right-radius, $top-left-radius)
  437. );
  438. border-top-right-radius: 0;
  439. }
  440. }
  441. }
  442. &.mdc-data-table--without-footer
  443. .mdc-data-table__row:last-child
  444. .mdc-data-table__cell:first-child {
  445. @include feature-targeting.targets($feat-structure) {
  446. @include theme.property(border-bottom-left-radius, $bottom-left-radius);
  447. @include rtl.rtl {
  448. @include theme.property(
  449. border-bottom-right-radius,
  450. if($rtl-reflexive, $bottom-left-radius, $bottom-right-radius)
  451. );
  452. border-bottom-left-radius: 0;
  453. }
  454. }
  455. }
  456. &.mdc-data-table--without-footer
  457. .mdc-data-table__row:last-child
  458. .mdc-data-table__cell:last-child {
  459. @include feature-targeting.targets($feat-structure) {
  460. @include theme.property(border-bottom-right-radius, $bottom-right-radius);
  461. @include rtl.rtl {
  462. @include theme.property(
  463. border-bottom-left-radius,
  464. if($rtl-reflexive, $bottom-right-radius, $bottom-left-radius)
  465. );
  466. border-bottom-right-radius: 0;
  467. }
  468. }
  469. }
  470. }
  471. @mixin stroke-size($size, $query: feature-targeting.all()) {
  472. $feat-structure: feature-targeting.create-target($query, structure);
  473. @include feature-targeting.targets($feat-structure) {
  474. @include theme.property('border-width', $size);
  475. border-style: solid;
  476. }
  477. }
  478. @mixin stroke-color($color, $query: feature-targeting.all()) {
  479. $feat-color: feature-targeting.create-target($query, color);
  480. @include feature-targeting.targets($feat-color) {
  481. @include theme.property('border-color', $color);
  482. }
  483. }
  484. @mixin header-row-height($height, $query: feature-targeting.all()) {
  485. $feat-structure: feature-targeting.create-target($query, structure);
  486. .mdc-data-table__header-row {
  487. @include feature-targeting.targets($feat-structure) {
  488. @include theme.property('height', $height);
  489. }
  490. }
  491. }
  492. @mixin row-height($height, $query: feature-targeting.all()) {
  493. $feat-structure: feature-targeting.create-target($query, structure);
  494. .mdc-data-table__row {
  495. @include feature-targeting.targets($feat-structure) {
  496. @include theme.property('height', $height);
  497. }
  498. }
  499. .mdc-data-table__pagination {
  500. @include feature-targeting.targets($feat-structure) {
  501. @include theme.property('min-height', $height);
  502. }
  503. }
  504. }
  505. ///
  506. /// Sets cell padding including cell, header cell, row checkbox cell and header
  507. /// row checkbox cell.
  508. /// @param {Number} $leading-padding [$cell-leading-padding] Leading padding.
  509. /// @param {Number} $trailing-padding [$cell-trailing-padding] Trailing padding.
  510. /// @param {Number} $checkbox-touch-size [$checkbox-touch-size] Checkbox Touch
  511. /// Size. Use this to adjust row checkbox cell leading padding based on
  512. /// checkbox density scale.
  513. /// @param {Number} $row-checkbox-density-scale [null] Density scale of row
  514. /// checkbox. Use this to adjust alignment of row checkbox within a cell.
  515. /// Ignore if data table's density scale is 0.
  516. /// See `checkbox-theme.density()` mixin for supported density scales.
  517. ///
  518. @mixin cell-padding(
  519. $leading-padding: $cell-leading-padding,
  520. $trailing-padding: $cell-trailing-padding,
  521. $row-checkbox-density-scale: null,
  522. $query: feature-targeting.all()
  523. ) {
  524. $feat-structure: feature-targeting.create-target($query, structure);
  525. .mdc-data-table__cell,
  526. .mdc-data-table__header-cell {
  527. @include feature-targeting.targets($feat-structure) {
  528. padding: 0 $trailing-padding 0 $leading-padding;
  529. }
  530. }
  531. @include checkbox-cell-padding(
  532. $leading-padding: $leading-padding,
  533. $row-checkbox-density-scale: $row-checkbox-density-scale,
  534. $query: $query
  535. );
  536. }
  537. ///
  538. /// Sets only row checkbox cell and header row checkbox cell leading padding.
  539. /// Use `cell-padding()` to set all cell's padding.
  540. /// @param {Number} $leading-padding [$cell-leading-padding] Leading padding.
  541. /// @param {Number} $checkbox-touch-size [$checkbox-touch-size] Checkbox Touch
  542. /// Size. Use this to adjust row checkbox cell leading padding based on
  543. /// checkbox density scale.
  544. /// @param {Number} $row-checkbox-density-scale [null] Density scale of row
  545. /// checkbox. Use this to adjust alignment of row checkbox within a cell.
  546. /// Ignore if data table's density scale is 0.
  547. /// See `checkbox-theme.density()` mixin for supported density scales.
  548. ///
  549. @mixin checkbox-cell-padding(
  550. $leading-padding: $cell-leading-padding,
  551. $row-checkbox-density-scale: null,
  552. $query: feature-targeting.all()
  553. ) {
  554. $feat-structure: feature-targeting.create-target($query, structure);
  555. .mdc-data-table__header-cell--checkbox,
  556. .mdc-data-table__cell--checkbox {
  557. @include feature-targeting.targets($feat-structure) {
  558. // Distance from leading cell bound to checkbox's icon bound should be
  559. // 16dp (`$leading-padding`). Calculate required padding excluding
  560. // checkbox bounds.
  561. $checkbox-icon-size: 24px;
  562. $checkbox-touch-size: touch-target.$height;
  563. @if $row-checkbox-density-scale and $row-checkbox-density-scale < 0 {
  564. $checkbox-touch-size: checkbox-theme.get-ripple-size(
  565. $row-checkbox-density-scale
  566. );
  567. }
  568. $leading-padding: $leading-padding -
  569. math.div($checkbox-touch-size - $checkbox-icon-size, 2);
  570. @include rtl.reflexive-property(padding, $leading-padding, 0);
  571. }
  572. }
  573. }
  574. @mixin column-widths($width-list, $query: feature-targeting.all()) {
  575. $feat-structure: feature-targeting.create-target($query, structure);
  576. @for $i from 1 through list.length($width-list) {
  577. .mdc-data-table__row > :nth-child(#{$i}) {
  578. @include feature-targeting.targets($feat-structure) {
  579. width: list.nth($width-list, $i);
  580. }
  581. }
  582. }
  583. }
  584. ///
  585. /// Sets density scale for data table. Use corresponding density mixins of child components (such as Checkbox) to apply
  586. /// density scales which will be rendered inside data table.
  587. ///
  588. /// @param {Number | String} $density-scale - Density scale value for component. Supported density scale values `-4`,
  589. /// `-3`, `-2`, `-1`, `0`.
  590. /// @param {Number} $row-checkbox-density-scale [null] Density scale of row
  591. /// checkbox. Use this to set density of row checkbox and also
  592. /// automatically adjust the alignment of row checkbox within a cell.
  593. /// See `checkbox.density()` mixin for supported density scales.
  594. ///
  595. @mixin density(
  596. $density-scale,
  597. $row-checkbox-density-scale: null,
  598. $pagination-select-density-scale: null,
  599. $query: feature-targeting.all()
  600. ) {
  601. $height: density.prop-value(
  602. $density-config: $density-config,
  603. $density-scale: $density-scale,
  604. $property-name: height,
  605. );
  606. @include row-height($height, $query: $query);
  607. @include header-row-height(get-header-row-height($height), $query: $query);
  608. @if $row-checkbox-density-scale {
  609. @include checkbox-cell-padding(
  610. $leading-padding: $cell-leading-padding,
  611. $row-checkbox-density-scale: $row-checkbox-density-scale,
  612. $query: $query
  613. );
  614. .mdc-data-table__header-row-checkbox,
  615. .mdc-data-table__row-checkbox {
  616. @include checkbox-theme.density($row-checkbox-density-scale);
  617. }
  618. }
  619. @if $pagination-select-density-scale {
  620. @include select-density($pagination-select-density-scale);
  621. }
  622. }
  623. @mixin select-density($density-scale) {
  624. @include select-theme.outlined-height(
  625. select-theme.$height + density.$interval * $density-scale
  626. );
  627. .mdc-list-item {
  628. @include list-theme.one-line-item-density(
  629. $density-scale + 2,
  630. $exclude-variants: true
  631. );
  632. }
  633. margin: 0;
  634. }
  635. ///
  636. /// Sets maximum height of data table. Use this to make table vertically
  637. /// scrollable.
  638. /// @param {Number} $height
  639. ///
  640. @mixin max-height($height, $query: feature-targeting.all()) {
  641. $feat-structure: feature-targeting.create-target($query, structure);
  642. .mdc-data-table__table-container {
  643. @include feature-targeting.targets($feat-structure) {
  644. max-height: $height;
  645. }
  646. }
  647. }