Skip to content

Commit ca81b3e

Browse files
committed
refactor: re-implement grid base styles to use CSS borders
1 parent 9be020a commit ca81b3e

File tree

1 file changed

+58
-144
lines changed

1 file changed

+58
-144
lines changed

packages/grid/src/styles/vaadin-grid-base-styles.js

Lines changed: 58 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ export const gridStyles = css`
1717
position: relative;
1818
box-sizing: border-box;
1919
-webkit-tap-highlight-color: transparent;
20+
--vaadin-grid-row-background-color: red;
2021
background: var(--vaadin-grid-background, var(--vaadin-background-color));
2122
border: var(--_border-width) solid var(--_border-color);
2223
cursor: default;
2324
--_border-color: var(--vaadin-grid-border-color, var(--vaadin-border-color-secondary));
2425
--_border-width: 0;
25-
--_row-border-width: var(--vaadin-grid-row-border-width, 1px);
26-
--_column-border-width: var(--vaadin-grid-column-border-width, 0px);
26+
--_row-border-width: var(--vaadin-grid-row-border-width, 4px);
27+
--_column-border-width: var(--vaadin-grid-column-border-width, 4px);
2728
border-radius: var(--_border-radius);
2829
--_border-radius: 0;
2930
}
@@ -95,15 +96,16 @@ export const gridStyles = css`
9596
position: sticky;
9697
left: 0;
9798
width: 100%;
99+
z-index: 2;
98100
}
99101
100-
:host([overflow~='top']) #header,
102+
/* :host([overflow~='top']) #header,
101103
:host([overflow~='bottom']) #footer,
102104
:host([navigating]) #header:has(tr:last-child:focus-within),
103105
:host([navigating]) #footer:has(tr:first-child:focus-within),
104106
[empty-state] #header {
105107
z-index: 2;
106-
}
108+
} */
107109
108110
:host([dir='rtl']) #items,
109111
:host([dir='rtl']) #header,
@@ -154,32 +156,23 @@ export const gridStyles = css`
154156
height: 100%;
155157
}
156158
159+
[part~='row'] {
160+
background: var(--vaadin-grid-row-background-color, var(--vaadin-background-color));
161+
}
162+
157163
[part~='cell'] {
164+
--_cell-background-color: var(--vaadin-grid-cell-background-color, transparent);
165+
--_cell-background-image: linear-gradient(var(--_cell-background-color), var(--_cell-background-color));
166+
158167
padding: 0;
159168
box-sizing: border-box;
160-
background: var(--vaadin-grid-cell-background, var(--vaadin-background-color));
161-
border-block: var(--_row-border-width) solid var(--_border-color);
162-
margin-top: calc(var(--_row-border-width) * -1);
163-
164-
/*
165-
Box-shadows are used to create a "fake" border at the end of the cell/row, which is visible when a row/cell ends
166-
before the edge of the grid viewport, as well as frozen columns and rows (header and footer).
167-
If there are frozen columns, we'll make the "fake box-shadow border" on the header and footer opaque by rendering
168-
both the border color and cell background color, so that a semi-transparent border color doesn't "stack" when
169-
scrolling horizontally.
170-
*/
171-
--_fake-border:
172-
0 calc(var(--_top, 0) * var(--_row-border-width) * -1) 0 0 var(--_border-color),
173-
0 calc(var(--_top-opaque, 0) * var(--_row-border-width) * -1) 0 0
174-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color)),
175-
0 calc(var(--_bottom, 0) * var(--_row-border-width)) 0 0 var(--_border-color),
176-
0 calc(var(--_bottom-opaque, 0) * var(--_row-border-width)) 0 0
177-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color)),
178-
calc(var(--_start, 0) * var(--_column-border-width) * -1) 0 0 0 var(--_border-color),
179-
calc(var(--_end, 0) * var(--_column-border-width)) 0 0 0 var(--_border-color),
180-
calc(var(--_end-opaque, 0) * var(--_column-border-width)) 0 0 0
181-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color));
182-
box-shadow: var(--_fake-border);
169+
background-color: inherit;
170+
background-repeat: no-repeat;
171+
background-origin: padding-box;
172+
background-image:
173+
var(--_hover-background-image, none), var(--_selected-background-image, none),
174+
var(--_highlight-background-image, none), var(--_cell-background-image);
175+
border: var(--_row-border-width) var(--_border-color);
183176
}
184177
185178
[part~='cell']:where(:not([part~='details-cell'])) {
@@ -190,87 +183,56 @@ export const gridStyles = css`
190183
position: relative;
191184
align-items: center;
192185
white-space: nowrap;
193-
border-inline-start: var(--_column-border-width) solid var(--_border-color);
194-
}
195-
196-
[part~='first-column-cell'] {
197-
border-inline-start: 0;
198-
}
199-
200-
[part~='first-header-row-cell'],
201-
[part~='first-footer-row-cell'],
202-
[part~='first-row-cell'] {
203-
margin-top: 0;
204-
border-top: 0;
205-
}
206-
207-
table[has-header] [part~='first-row-cell'] {
208-
border-top: var(--_row-border-width) solid var(--_border-color);
209-
}
210-
211-
[part~='last-column-cell'] {
212-
--_end: 1;
213186
}
214187
215-
[part~='last-column-cell']:is([part~='header-cell'], [part~='footer-cell']) {
216-
--_end-opaque: 1;
217-
}
218-
219-
[part~='last-row-cell']:where(:not([part~='details-opened-row-cell'])),
220-
[part~='last-footer-row-cell'] {
221-
border-bottom: 0;
222-
--_bottom: 1;
223-
}
224-
225-
[part~='last-frozen-cell'] {
226-
--_end: 1;
227-
}
228-
229-
[part~='last-frozen-cell'] + [part~='cell'] {
230-
border-inline-start-color: transparent;
188+
[part~='body-cell'] {
189+
--_highlight-background-color: var(--vaadin-grid-row-highlight-background-color, transparent);
190+
--_highlight-background-image: linear-gradient(
191+
var(--_highlight-background-color),
192+
var(--_highlight-background-color)
193+
);
231194
}
232195
233-
[part~='first-frozen-to-end-cell'] {
234-
border-inline-start: 0;
235-
--_start: 1;
196+
#table[has-header] {
197+
[part~='first-row-cell'] {
198+
border-block-start-style: solid;
199+
}
236200
}
237201
238-
[part~='last-header-row-cell'] {
239-
border-bottom: 0;
240-
}
202+
#table[has-footer] {
203+
[part~='last-row-cell'] {
204+
border-block-end-style: solid;
205+
}
241206
242-
:host([overflow~='top']) [part~='last-header-row-cell'],
243-
[empty-state] [part~='last-header-row-cell'] {
244-
--_bottom: 1;
207+
[part~='last-row-cell'] + [part~='details-cell'] {
208+
border-block-end-style: solid;
209+
}
245210
}
246211
247-
#header:has(:is([frozen], [frozen-to-end])) [part~='last-header-row-cell'] {
248-
--_bottom-opaque: 1;
212+
[part~='header-cell']:not([part~='first-header-row-cell']),
213+
[part~='footer-cell']:not([part~='first-footer-row-cell']),
214+
[part~='body-cell']:not([part~='first-row-cell']) {
215+
border-block-start-style: solid;
249216
}
250217
251-
:host([overflow~='bottom']) [part~='first-footer-row-cell'],
252-
[empty-state] [part~='first-footer-row-cell'] {
253-
--_top: 1;
218+
[part~='details-opened-row-cell'] {
219+
border-block-end-style: solid;
254220
}
255221
256-
#footer:has(:is([frozen], [frozen-to-end])) [part~='first-footer-row-cell'] {
257-
--_top-opaque: 1;
222+
[part~='header-cell']:not([part~='first-column-cell']),
223+
[part~='footer-cell']:not([part~='first-column-cell']),
224+
[part~='body-cell']:not([part~='first-column-cell']) {
225+
border-inline-start-style: solid;
258226
}
259227
260-
table[has-footer] [part~='last-row-cell']:not([part~='details-opened-row-cell']) {
261-
border-bottom: var(--_row-border-width) solid var(--_border-color);
262-
--_bottom: 0;
263-
}
228+
[part~='last-frozen-cell'] {
229+
&:not([part~='last-column-cell']) {
230+
border-inline-end-style: solid;
231+
}
264232
265-
[part~='body-cell']:where(:not([part~='details-cell'])) {
266-
--_highlight-background-color: var(--vaadin-grid-row-highlight-background-color, transparent);
267-
--_highlight-background-image: linear-gradient(
268-
var(--_highlight-background-color),
269-
var(--_highlight-background-color)
270-
);
271-
background:
272-
var(--_hover-background-image, none), var(--_selected-background-image, none), var(--_highlight-background-image),
273-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color));
233+
&:not([part~='last-column-cell']) + [part~='cell'] {
234+
border-inline-start-style: none;
235+
}
274236
}
275237
276238
/* Variant: wrap cell contents */
@@ -280,40 +242,16 @@ export const gridStyles = css`
280242
}
281243
282244
/* Variant: row stripes */
283-
[part~='odd-row'] {
284-
--vaadin-grid-cell-background-color: var(--vaadin-grid-row-odd-background-color, var(--vaadin-background-color));
285-
}
286-
287245
:host([theme~='row-stripes']) [part~='odd-row'] {
288246
--vaadin-grid-cell-background-color: var(
289247
--vaadin-grid-row-odd-background-color,
290248
color-mix(in srgb, var(--vaadin-text-color) 4%, var(--vaadin-background-color))
291249
);
292250
}
293251
294-
/* Raise highlighted rows above others */
295-
296-
[part~='row']:focus,
297-
[part~='row']:focus-within,
298-
[part~='body-row']:where([selected]) {
299-
z-index: 3;
300-
}
301-
302-
@container style(--vaadin-grid-row-odd-background-color) {
303-
[part~='odd-row'] {
304-
z-index: 1;
305-
}
306-
}
307-
308252
/* Row hover */
309253
@media (any-hover: hover) {
310-
@container style(--vaadin-grid-row-hover-background-color) {
311-
[part~='body-row']:hover {
312-
z-index: 2;
313-
}
314-
}
315-
316-
[part~='body-row']:hover [part~='cell']:where(:not([part~='details-cell'])) {
254+
[part~='body-row']:hover [part~='body-cell'] {
317255
--_hover-background-color: var(--vaadin-grid-row-hover-background-color, transparent);
318256
--_hover-background-image: linear-gradient(var(--_hover-background-color), var(--_hover-background-color));
319257
}
@@ -323,12 +261,6 @@ export const gridStyles = css`
323261
position: absolute;
324262
bottom: 0;
325263
width: 100%;
326-
margin-top: 0;
327-
border-top: 0;
328-
}
329-
330-
[part~='last-row-cell'] + [part~='details-cell'] {
331-
border-bottom: 0;
332264
}
333265
334266
[part~='cell'] ::slotted(vaadin-grid-cell-content) {
@@ -348,7 +280,7 @@ export const gridStyles = css`
348280
}
349281
350282
/* Selected row */
351-
[part~='body-row'][selected] {
283+
[part~='selected-row-cell'] {
352284
--_selected-background-color: var(
353285
--vaadin-grid-row-selected-background-color,
354286
color-mix(in srgb, currentColor 8%, transparent)
@@ -523,28 +455,10 @@ export const gridStyles = css`
523455
inset-inline-end: 0;
524456
}
525457
526-
#header [part~='row']:first-child::after,
527-
[part~='first-header-row-cell']::after,
528-
[part*='first-row']::after {
529-
top: 0;
530-
}
531-
532458
table[has-header] [part~='first-row-cell']::after {
533459
top: calc(var(--_row-border-width) * -1);
534460
}
535461
536-
#footer [part~='row']:last-child::after,
537-
[part~='last-footer-row-cell']::after,
538-
[part~='last-row']::after,
539-
[part~='last-row-cell']::after {
540-
bottom: 0;
541-
}
542-
543-
#header [part~='row']:last-child::after,
544-
table[has-footer] [part*='last-row']::after {
545-
bottom: calc(var(--_row-border-width) * -1);
546-
}
547-
548462
:host([navigating]) [part~='row']:focus,
549463
:host([navigating]) [part~='cell']:focus {
550464
outline: 0;
@@ -661,7 +575,7 @@ export const gridStyles = css`
661575
content: '-';
662576
}
663577
664-
@media (forced-colors: active) {
578+
/* @media (forced-colors: active) {
665579
:host([overflow~='top']) [part~='last-header-row-cell'] {
666580
border-bottom: var(--_row-border-width) solid;
667581
margin-bottom: calc(var(--_row-border-width) * -1);
@@ -671,5 +585,5 @@ export const gridStyles = css`
671585
border-top: var(--_row-border-width) solid;
672586
margin-top: calc(var(--_row-border-width) * -1);
673587
}
674-
}
588+
} */
675589
`;

0 commit comments

Comments
 (0)