@@ -57,10 +57,12 @@ export class DataGrid extends TailwindElement {
57
57
items ?: GridItem [ ] ;
58
58
59
59
/**
60
- * Stick header row to the top of the viewport.
60
+ * Stick header row to the top of the table or the viewport.
61
+ *
62
+ * Horizontal scroll will be disabled if the header sticks to the viewport.
61
63
*/
62
- @property ( { type : Boolean } )
63
- stickyHeader = false ;
64
+ @property ( { type : String } )
65
+ stickyHeader ?: "table" | "viewport" ;
64
66
65
67
/**
66
68
* Item key to use as the row key, like an ID.
@@ -134,20 +136,43 @@ export class DataGrid extends TailwindElement {
134
136
render ( ) {
135
137
if ( ! this . columns ?. length ) return ;
136
138
137
- const cssWidths = this . columns . map ( ( col ) => col . width ?? "1fr" ) ;
138
-
139
139
return html `
140
140
< slot name ="label ">
141
141
< label id =${ this . formControlLabelId } class ="form-label text-xs">
142
142
${ this . formControlLabel }
143
143
</ label >
144
144
</ slot >
145
+ < div
146
+ class =${ clsx (
147
+ this . stickyHeader === "table" && tw `overflow-x-auto overscroll-none` ,
148
+ this . stickyHeader && tw `rounded border ` ,
149
+ ) }
150
+ >
151
+ ${ this . renderTable ( ) }
152
+ </ div >
145
153
154
+ ${ this . addRows && ! this . addRowsInputValue
155
+ ? this . renderAddButton ( )
156
+ : nothing }
157
+ ` ;
158
+ }
159
+
160
+ private renderTable ( ) {
161
+ if ( ! this . columns ?. length ) return ;
162
+
163
+ const cssWidths = this . columns . map ( ( col ) => col . width ?? "1fr" ) ;
164
+ const showFooter = this . addRows && this . addRowsInputValue ;
165
+
166
+ return html `
146
167
< btrix-table
147
168
role ="grid "
148
169
class =${ clsx (
149
- tw `relative size-full overflow-auto` ,
150
- this . stickyHeader && tw `rounded border ` ,
170
+ tw `relative size-full min-w-0` ,
171
+ // Add background color for overscroll:
172
+ this . stickyHeader && tw `rounded bg-neutral-50` ,
173
+ // Height is required for sticky + horizontal scrolling to work:
174
+ this . stickyHeader === "table" &&
175
+ tw `max-h-[calc(100vh-4rem)] overflow-y-auto ` ,
151
176
) }
152
177
style ="--btrix-table-grid-template-columns: ${ cssWidths . join ( " " ) } ${ this
153
178
. removeRows
@@ -168,14 +193,16 @@ export class DataGrid extends TailwindElement {
168
193
>
169
194
${ this . columns . map (
170
195
( col ) => html `
171
- < btrix-table-header-cell >
196
+ < btrix-table-header-cell
197
+ class =${ clsx ( col . description && tw `flex-wrap ` ) }
198
+ >
172
199
${ col . label }
173
200
${ col . description
174
201
? html `
175
202
< sl-tooltip content =${ col . description } >
176
203
< sl-icon
177
204
name ="info-circle "
178
- class ="ml-1.5 align-[-.175em] text-sm text-slate-500 "
205
+ class ="ml-1.5 flex-shrink-0 align-[-.175em] text-sm text-slate-500 "
179
206
> </ sl-icon >
180
207
</ sl-tooltip >
181
208
`
@@ -192,8 +219,11 @@ export class DataGrid extends TailwindElement {
192
219
< btrix-table-body
193
220
class =${ clsx (
194
221
tw `[--btrix-table-cell-padding:var(--sl-spacing-x-small)]` ,
195
- tw `leading-none` ,
196
- ! this . stickyHeader && tw `rounded border ` ,
222
+ tw `bg-[var(--sl-panel-background-color)] leading-none` ,
223
+ ! this . stickyHeader && [
224
+ tw `border` ,
225
+ showFooter ? tw `rounded-t` : tw `rounded ` ,
226
+ ] ,
197
227
) }
198
228
@btrix-remove =${ ( e : CustomEvent < RowRemoveEventDetail > ) => {
199
229
const { key } = e . detail ;
@@ -206,10 +236,21 @@ export class DataGrid extends TailwindElement {
206
236
} }
207
237
>
208
238
${ this . renderRows ( ) }
209
- ${ this . addRows && this . addRowsInputValue
210
- ? html `
211
- < btrix-table-row class ="border-t ">
212
- < btrix-table-cell class ="col-span-full px-1 ">
239
+ </ btrix-table-body >
240
+
241
+ ${ showFooter
242
+ ? html `
243
+ < btrix-table-footer
244
+ class =${ clsx (
245
+ tw `[--btrix-table-cell-padding-x:var(--sl-spacing-2x-small)] [--btrix-table-cell-padding-y:var(--sl-spacing-x-small)]` ,
246
+ tw `bg-[var(--sl-panel-background-color)]` ,
247
+ this . stickyHeader
248
+ ? tw `border-t`
249
+ : tw `rounded-b border-x border-b ` ,
250
+ ) }
251
+ >
252
+ < btrix-table-row >
253
+ < btrix-table-cell class ="col-span-full ">
213
254
<!-- TODO Replace navigation button -->
214
255
< btrix-navigation-button
215
256
size ="small "
@@ -242,14 +283,10 @@ export class DataGrid extends TailwindElement {
242
283
</ span >
243
284
</ btrix-table-cell >
244
285
</ btrix-table-row >
245
- `
246
- : nothing }
247
- </ btrix-table-body >
286
+ </ btrix-table-footer >
287
+ `
288
+ : nothing }
248
289
</ btrix-table >
249
-
250
- ${ this . addRows && ! this . addRowsInputValue
251
- ? this . renderAddButton ( )
252
- : nothing }
253
290
` ;
254
291
}
255
292
0 commit comments