@fluid-topics/ft-filterable-table 0.1.17 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import { css, html } from "lit";
8
8
  import { property, state } from "lit/decorators.js";
9
9
  import { repeat } from "lit/directives/repeat.js";
10
10
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
11
- import { customElement, designSystemVariables, FtCssVariable, FtLitElement, setVariable } from "@fluid-topics/ft-wc-utils";
11
+ import { designSystemVariables, FtCssVariable, FtLitElement, setVariable } from "@fluid-topics/ft-wc-utils";
12
12
  import "@fluid-topics/ft-select";
13
13
  import "@fluid-topics/ft-text-field";
14
14
  import "@fluid-topics/ft-button";
@@ -30,7 +30,7 @@ export const FtFilterableTableCssVariables = {
30
30
  const DEFAULT_RENDER = (v) => html `${v}`;
31
31
  const DEFAULT_COMPARATOR = (a, b) => a - b;
32
32
  const DEFAULT_STRINGIFY = (v) => "" + v;
33
- let FtFilterableTable = class FtFilterableTable extends FtLitElement {
33
+ export class FtFilterableTable extends FtLitElement {
34
34
  constructor() {
35
35
  // Don't scope components here or web components cannot be used in columns render method
36
36
  // static elementDefinitions: ElementDefinitionsMap = {}
@@ -40,118 +40,19 @@ let FtFilterableTable = class FtFilterableTable extends FtLitElement {
40
40
  this.filters = [];
41
41
  this.selectData = [];
42
42
  }
43
- //language=css
44
- getStyles() {
45
- return css `
46
- :host {
47
- display: block;
48
- }
49
-
50
- .table {
51
- display: grid;
52
- grid-template-columns: repeat(${this.columns.length}, minmax(min-content, auto));
53
- }
54
-
55
- .header, .row {
56
- display: contents;
57
- }
58
-
59
- .header-cell {
60
- display: flex;
61
- flex-direction: column;
62
- background: ${FtFilterableTableCssVariables.headerBackground};
63
- color: ${FtFilterableTableCssVariables.colorOnSurfaceHigh};
64
- padding: .5rem 1rem;
65
- font-family: ${FtFilterableTableCssVariables.titleFont};
66
- }
67
-
68
- .header-cell:first-of-type {
69
- border-radius: .5rem 0 0 0;
70
- }
71
-
72
- .header-cell:last-of-type {
73
- border-radius: 0 .5rem 0 0;
74
- }
75
-
76
- .column-title-container {
77
- display: flex;
78
- align-items: center;
79
- }
80
-
81
- .column-title-container ft-button {
82
- ${setVariable(FtButtonCssVariables.backgroundColor, FtFilterableTableCssVariables.headerBackground)};
83
- ${setVariable(FtButtonCssVariables.color, FtFilterableTableCssVariables.colorOnSurfaceHigh)};
84
- }
85
-
86
- .column-title {
87
- white-space: nowrap;
88
- text-transform: uppercase;
89
- margin-right: .5rem;
90
- }
91
-
92
- .column-filter {
93
- flex-grow: 1;
94
- flex-shrink: 0;
95
- }
96
-
97
- .column-filter:not(:empty) {
98
- padding-top: .5rem;
99
- }
100
-
101
- .column-filter ft-text-field,
102
- .column-filter ft-select {
103
- width: 150px;
104
- min-width: 100%;
105
- }
106
-
107
- .cell {
108
- padding: 1rem;
109
- border-left: 1px solid ${FtFilterableTableCssVariables.headerBackground};
110
- border-bottom: 1px solid ${FtFilterableTableCssVariables.headerBackground};
111
- overflow-x: auto;
112
- display: flex;
113
- align-items: center;
114
- font-family: ${FtFilterableTableCssVariables.contentFont};
115
- }
116
-
117
- /* Even is 2n+1 and odd is 2n because of the header */
118
- .row:nth-child(2n) > .cell {
119
- background: ${FtFilterableTableCssVariables.oddRowBackground};
120
- }
121
-
122
- .row:nth-child(2n + 1) > .cell {
123
- background: ${FtFilterableTableCssVariables.evenRowBackground};
124
- }
125
-
126
- .row:hover > .cell {
127
- background: ${FtFilterableTableCssVariables.rowHoverBackground};
128
- }
129
-
130
- .cell:last-of-type {
131
- border-right: 1px solid ${FtFilterableTableCssVariables.headerBackground};
132
- }
133
-
134
- .row:last-of-type .cell:first-of-type {
135
- border-radius: 0 0 0 .5rem;
136
- }
137
-
138
- .row:last-of-type .cell:last-of-type {
139
- border-radius: 0 0 .5rem 0;
140
- }
141
-
142
- .hidden {
143
- visibility: hidden;
144
- }
145
- `;
146
- }
147
43
  init(data, columns, sort) {
148
44
  this.data = data;
149
45
  this.columns = columns;
150
46
  this.sort = sort;
151
47
  }
152
- getTemplate() {
48
+ render() {
153
49
  let data = this.sortData(this.filterData());
154
50
  return html `
51
+ <style>
52
+ .table {
53
+ grid-template-columns: repeat(${this.columns.length}, minmax(min-content, auto));
54
+ }
55
+ </style>
155
56
  <div class="table">
156
57
  <div class="header">
157
58
  ${repeat(this.columns, (_, index) => "header-cell-" + index, (column, index) => this.renderHeader(column, index))}
@@ -314,7 +215,108 @@ let FtFilterableTable = class FtFilterableTable extends FtLitElement {
314
215
  const value = this.getValue(column, row);
315
216
  return typeof column.stringify === "function" ? column.stringify(value, index) : DEFAULT_STRINGIFY(value);
316
217
  }
317
- };
218
+ }
219
+ //language=css
220
+ FtFilterableTable.styles = css `
221
+ :host {
222
+ display: block;
223
+ }
224
+
225
+ .table {
226
+ display: grid;
227
+ }
228
+
229
+ .header, .row {
230
+ display: contents;
231
+ }
232
+
233
+ .header-cell {
234
+ display: flex;
235
+ flex-direction: column;
236
+ background: ${FtFilterableTableCssVariables.headerBackground};
237
+ color: ${FtFilterableTableCssVariables.colorOnSurfaceHigh};
238
+ padding: .5rem 1rem;
239
+ font-family: ${FtFilterableTableCssVariables.titleFont};
240
+ }
241
+
242
+ .header-cell:first-of-type {
243
+ border-radius: .5rem 0 0 0;
244
+ }
245
+
246
+ .header-cell:last-of-type {
247
+ border-radius: 0 .5rem 0 0;
248
+ }
249
+
250
+ .column-title-container {
251
+ display: flex;
252
+ align-items: center;
253
+ }
254
+
255
+ .column-title-container ft-button {
256
+ ${setVariable(FtButtonCssVariables.backgroundColor, FtFilterableTableCssVariables.headerBackground)};
257
+ ${setVariable(FtButtonCssVariables.color, FtFilterableTableCssVariables.colorOnSurfaceHigh)};
258
+ }
259
+
260
+ .column-title {
261
+ white-space: nowrap;
262
+ text-transform: uppercase;
263
+ margin-right: .5rem;
264
+ }
265
+
266
+ .column-filter {
267
+ flex-grow: 1;
268
+ flex-shrink: 0;
269
+ }
270
+
271
+ .column-filter:not(:empty) {
272
+ padding-top: .5rem;
273
+ }
274
+
275
+ .column-filter ft-text-field,
276
+ .column-filter ft-select {
277
+ width: 150px;
278
+ min-width: 100%;
279
+ }
280
+
281
+ .cell {
282
+ padding: 1rem;
283
+ border-left: 1px solid ${FtFilterableTableCssVariables.headerBackground};
284
+ border-bottom: 1px solid ${FtFilterableTableCssVariables.headerBackground};
285
+ overflow-x: auto;
286
+ display: flex;
287
+ align-items: center;
288
+ font-family: ${FtFilterableTableCssVariables.contentFont};
289
+ }
290
+
291
+ /* Even is 2n+1 and odd is 2n because of the header */
292
+ .row:nth-child(2n) > .cell {
293
+ background: ${FtFilterableTableCssVariables.oddRowBackground};
294
+ }
295
+
296
+ .row:nth-child(2n + 1) > .cell {
297
+ background: ${FtFilterableTableCssVariables.evenRowBackground};
298
+ }
299
+
300
+ .row:hover > .cell {
301
+ background: ${FtFilterableTableCssVariables.rowHoverBackground};
302
+ }
303
+
304
+ .cell:last-of-type {
305
+ border-right: 1px solid ${FtFilterableTableCssVariables.headerBackground};
306
+ }
307
+
308
+ .row:last-of-type .cell:first-of-type {
309
+ border-radius: 0 0 0 .5rem;
310
+ }
311
+
312
+ .row:last-of-type .cell:last-of-type {
313
+ border-radius: 0 0 .5rem 0;
314
+ }
315
+
316
+ .hidden {
317
+ visibility: hidden;
318
+ }
319
+ `;
318
320
  __decorate([
319
321
  property({ attribute: false })
320
322
  ], FtFilterableTable.prototype, "data", void 0);
@@ -327,8 +329,4 @@ __decorate([
327
329
  __decorate([
328
330
  state()
329
331
  ], FtFilterableTable.prototype, "currentSort", void 0);
330
- FtFilterableTable = __decorate([
331
- customElement("ft-filterable-table")
332
- ], FtFilterableTable);
333
- export { FtFilterableTable };
334
332
  //# sourceMappingURL=ft-filterable-table.js.map