Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ba6f7c2

Browse files
abhiomkarcopybara-github
authored andcommitted
refactor(data-table): Organize data table sass files to match style guide.
Created following Sass modules to organize files by feature: - Core style module (_data-table.scss) - Theme style module (_data-table-theme.scss) - CSS style module (styles.scss) Only theme style modules (always ends with `*-theme.scss`) contain user-facing theme APIs. Theme modules are forwarded in index modules (`_index.scss`). Example usage before and after refactor (Existing usage will be supported for backward compatibility). #### Before ```scss @use '@material/data-table/mdc-data-table'; // Emits CSS @use '@material/data-table/mixins'; .custom-data-table { @include mixins.fill-color(black); } ``` #### After ```scss // Emits CSS @use '@material/data-table/styles'; // Emits CSS @use '@material/data-table'; .custom-data-table { @include data-table.fill-color(black); } ``` PiperOrigin-RevId: 314350425
1 parent 5a02296 commit ba6f7c2

File tree

11 files changed

+760
-569
lines changed

11 files changed

+760
-569
lines changed
Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
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+
23+
// stylelint-disable selector-class-pattern
24+
// NOTE: We disable `selector-class-pattern` above to allow using `mdc-` class
25+
// selectors.
26+
27+
@use 'sass:list';
28+
@use '@material/animation/functions';
29+
@use '@material/checkbox/mixins' as checkbox-mixins;
30+
@use '@material/density/functions' as density-functions;
31+
@use '@material/elevation/mixins';
32+
@use '@material/feature-targeting/functions' as feature-targeting-functions;
33+
@use '@material/feature-targeting/mixins' as feature-targeting-mixins;
34+
@use '@material/icon-button/mixins' as icon-button-mixins;
35+
@use '@material/rtl/mixins' as rtl-mixins;
36+
@use '@material/shape/mixins' as shape-mixins;
37+
@use '@material/theme/mixins' as theme-mixins;
38+
@use '@material/theme/variables' as variables2; // for mdc-theme-prop-value.
39+
@use '@material/typography/mixins' as typography-mixins;
40+
@use '@material/theme/variables' as theme-variables;
41+
@use '@material/density/variables' as density-variables;
42+
43+
$fill-color: surface !default;
44+
$header-row-fill-color: inherit !default;
45+
$row-fill-color: inherit !default;
46+
$selected-row-fill-color: rgba(
47+
theme-variables.prop-value(primary),
48+
0.04
49+
) !default;
50+
$checked-icon-color: primary !default;
51+
$divider-color: rgba(theme-variables.prop-value(on-surface), 0.12) !default;
52+
$divider-size: 1px !default;
53+
$row-hover-fill-color: rgba(
54+
theme-variables.prop-value(on-surface),
55+
0.04
56+
) !default;
57+
$checkbox-touch-dimension: 48px !default;
58+
59+
$header-row-text-color: rgba(
60+
theme-variables.prop-value(on-surface),
61+
0.87
62+
) !default;
63+
$row-text-color: rgba(theme-variables.prop-value(on-surface), 0.87) !default;
64+
65+
$sort-icon-color: rgba(theme-variables.prop-value(on-surface), 0.6) !default;
66+
$sort-icon-active-color: rgba(
67+
theme-variables.prop-value(on-surface),
68+
0.87
69+
) !default;
70+
$sort-icon-density-scale: -5 !default;
71+
72+
$shape-radius: medium !default;
73+
$stroke-size: 1px !default;
74+
$stroke-color: rgba(theme-variables.prop-value(on-surface), 0.12) !default;
75+
76+
$cell-height: 52px !default;
77+
$header-cell-height: get-header-cell-height($cell-height) !default;
78+
$cell-leading-padding: 16px !default;
79+
$cell-trailing-padding: 16px !default;
80+
81+
$minimum-cell-height: 36px !default;
82+
$maximum-cell-height: $cell-height !default;
83+
$default-density-scale: density-variables.$default-scale !default;
84+
$density-config: (
85+
height: (
86+
maximum: $cell-height,
87+
default: $cell-height,
88+
minimum: $minimum-cell-height,
89+
),
90+
);
91+
92+
@function get-header-cell-height($height) {
93+
@return $height + 4px;
94+
}
95+
96+
/// Sets the color of sort icon button when it is in idle state.
97+
/// (icon showed on header cell focus)
98+
/// @param {String} $color - Color of sort icon button
99+
@mixin sort-icon-color($color, $query: feature-targeting-functions.all()) {
100+
$feat-color: feature-targeting-functions.create-target($query, color);
101+
102+
.mdc-data-table__sort-icon-button {
103+
@include icon-button-mixins.ink-color($color, $query: $query);
104+
}
105+
}
106+
107+
/// Sets the color of sort icon button when it is activated (sorted).
108+
/// @param {String} $color - Color of sort icon button
109+
@mixin sort-icon-active-color(
110+
$color,
111+
$query: feature-targeting-functions.all()
112+
) {
113+
$feat-color: feature-targeting-functions.create-target($query, color);
114+
115+
.mdc-data-table__header-cell--sorted .mdc-data-table__sort-icon-button {
116+
@include icon-button-mixins.ink-color($color, $query: $query);
117+
}
118+
}
119+
120+
@mixin fill-color($color, $query: feature-targeting-functions.all()) {
121+
$feat-color: feature-targeting-functions.create-target($query, color);
122+
123+
@include feature-targeting-mixins.targets($feat-color) {
124+
@include theme-mixins.prop('background-color', $color);
125+
}
126+
}
127+
128+
@mixin header-row-fill-color(
129+
$color,
130+
$query: feature-targeting-functions.all()
131+
) {
132+
$feat-color: feature-targeting-functions.create-target($query, color);
133+
134+
.mdc-data-table__header-row {
135+
@include feature-targeting-mixins.targets($feat-color) {
136+
@include theme-mixins.prop('background-color', $color);
137+
}
138+
}
139+
}
140+
141+
@mixin row-fill-color($color, $query: feature-targeting-functions.all()) {
142+
$feat-color: feature-targeting-functions.create-target($query, color);
143+
144+
.mdc-data-table__row {
145+
@include feature-targeting-mixins.targets($feat-color) {
146+
@include theme-mixins.prop('background-color', $color);
147+
}
148+
}
149+
}
150+
151+
@mixin selected-row-fill-color(
152+
$color,
153+
$query: feature-targeting-functions.all()
154+
) {
155+
$feat-color: feature-targeting-functions.create-target($query, color);
156+
157+
.mdc-data-table__row--selected {
158+
@include feature-targeting-mixins.targets($feat-color) {
159+
@include theme-mixins.prop('background-color', $color);
160+
}
161+
}
162+
}
163+
164+
@mixin checked-icon-color($color, $query: feature-targeting-functions.all()) {
165+
.mdc-data-table__header-row-checkbox,
166+
.mdc-data-table__row-checkbox {
167+
@include checkbox-mixins.focus-indicator-color($color, $query: $query);
168+
@include checkbox-mixins.container-colors(
169+
$marked-stroke-color: $color,
170+
$marked-fill-color: $color,
171+
$query: $query
172+
);
173+
}
174+
}
175+
176+
@mixin divider-color($color, $query: feature-targeting-functions.all()) {
177+
$feat-color: feature-targeting-functions.create-target($query, color);
178+
179+
.mdc-data-table__row,
180+
.mdc-data-table__pagination {
181+
@include feature-targeting-mixins.targets($feat-color) {
182+
border-top-color: $color;
183+
}
184+
}
185+
}
186+
187+
@mixin divider-size($size, $query: feature-targeting-functions.all()) {
188+
$feat-structure: feature-targeting-functions.create-target($query, structure);
189+
190+
.mdc-data-table__row,
191+
.mdc-data-table__pagination {
192+
@include feature-targeting-mixins.targets($feat-structure) {
193+
border-top-width: $size;
194+
border-top-style: solid;
195+
}
196+
}
197+
}
198+
199+
@mixin row-hover-fill-color($color, $query: feature-targeting-functions.all()) {
200+
$feat-color: feature-targeting-functions.create-target($query, color);
201+
202+
.mdc-data-table__row:not(.mdc-data-table__row--selected):hover {
203+
@include feature-targeting-mixins.targets($feat-color) {
204+
@include theme-mixins.prop('background-color', $color);
205+
}
206+
}
207+
}
208+
209+
@mixin header-row-text-color(
210+
$color,
211+
$query: feature-targeting-functions.all()
212+
) {
213+
$feat-color: feature-targeting-functions.create-target($query, color);
214+
215+
.mdc-data-table__header-cell {
216+
@include feature-targeting-mixins.targets($feat-color) {
217+
@include theme-mixins.prop('color', $color);
218+
}
219+
}
220+
}
221+
222+
@mixin row-text-color($color, $query: feature-targeting-functions.all()) {
223+
$feat-color: feature-targeting-functions.create-target($query, color);
224+
225+
.mdc-data-table__cell {
226+
@include feature-targeting-mixins.targets($feat-color) {
227+
@include theme-mixins.prop('color', $color);
228+
}
229+
}
230+
}
231+
232+
@mixin shape-radius(
233+
$radius,
234+
$rtl-reflexive: false,
235+
$query: feature-targeting-functions.all()
236+
) {
237+
@include shape-mixins.radius($radius, $rtl-reflexive, $query: $query);
238+
}
239+
240+
@mixin stroke-size($size, $query: feature-targeting-functions.all()) {
241+
$feat-structure: feature-targeting-functions.create-target($query, structure);
242+
243+
@include feature-targeting-mixins.targets($feat-structure) {
244+
border-width: $size;
245+
border-style: solid;
246+
}
247+
}
248+
249+
@mixin stroke-color($color, $query: feature-targeting-functions.all()) {
250+
$feat-color: feature-targeting-functions.create-target($query, color);
251+
252+
@include feature-targeting-mixins.targets($feat-color) {
253+
border-color: $color;
254+
}
255+
}
256+
257+
@mixin header-cell-height($height, $query: feature-targeting-functions.all()) {
258+
$feat-structure: feature-targeting-functions.create-target($query, structure);
259+
260+
.mdc-data-table__header-cell {
261+
@include feature-targeting-mixins.targets($feat-structure) {
262+
height: $height;
263+
}
264+
}
265+
}
266+
267+
@mixin cell-height($height, $query: feature-targeting-functions.all()) {
268+
$feat-structure: feature-targeting-functions.create-target($query, structure);
269+
270+
.mdc-data-table__cell,
271+
.mdc-data-table__pagination {
272+
@include feature-targeting-mixins.targets($feat-structure) {
273+
height: $height;
274+
}
275+
}
276+
}
277+
278+
@mixin cell-padding(
279+
$leading-padding: $cell-leading-padding,
280+
$trailing-padding: $cell-trailing-padding,
281+
$query: feature-targeting-functions.all()
282+
) {
283+
$feat-structure: feature-targeting-functions.create-target($query, structure);
284+
285+
.mdc-data-table__cell,
286+
.mdc-data-table__header-cell {
287+
@include feature-targeting-mixins.targets($feat-structure) {
288+
padding-right: $trailing-padding;
289+
padding-left: $leading-padding;
290+
}
291+
}
292+
293+
.mdc-data-table__header-cell--checkbox,
294+
.mdc-data-table__cell--checkbox {
295+
@include feature-targeting-mixins.targets($feat-structure) {
296+
@include rtl-mixins.reflexive-property(padding, $leading-padding, 0);
297+
}
298+
}
299+
}
300+
301+
@mixin column-widths($width-list, $query: feature-targeting-functions.all()) {
302+
$feat-structure: feature-targeting-functions.create-target($query, structure);
303+
304+
@for $i from 1 through list.length($width-list) {
305+
.mdc-data-table__row > :nth-child(#{$i}) {
306+
@include feature-targeting-mixins.targets($feat-structure) {
307+
width: list.nth($width-list, $i);
308+
}
309+
}
310+
}
311+
}
312+
313+
///
314+
/// Sets density scale for data table. Use corresponding density mixins of child components (such as Checkbox) to apply
315+
/// density scales which will be rendered inside data table.
316+
///
317+
/// @param {Number | String} $density-scale - Density scale value for component. Supported density scale values `-4`,
318+
/// `-3`, `-2`, `-1`, `0`.
319+
///
320+
@mixin density($density-scale, $query: feature-targeting-functions.all()) {
321+
$height: density-functions.prop-value(
322+
$density-config: $density-config,
323+
$density-scale: $density-scale,
324+
$property-name: height,
325+
);
326+
327+
@include cell-height($height, $query: $query);
328+
@include header-cell-height(get-header-cell-height($height), $query: $query);
329+
}

0 commit comments

Comments
 (0)