@fluid-topics/ft-table 1.2.33 → 1.2.35

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.
@@ -1,15 +1,14 @@
1
1
  import { nothing, PropertyValues, TemplateResult } from "lit";
2
2
  import "@fluid-topics/ft-button";
3
3
  import "@fluid-topics/ft-typography";
4
- import { FtdsTableProperties, Sort } from "./ftds-table.properties";
5
- import { ColumnConfiguration } from "./ftds-table.properties";
4
+ import { ColumnConfiguration, EmptyStateConfiguration, FtdsTableProperties, Sort } from "./ftds-table.properties";
6
5
  import { FtLitElement } from "@fluid-topics/ft-wc-utils";
7
6
  export declare class FtdsTable<T extends Record<string, any>> extends FtLitElement implements FtdsTableProperties<T> {
8
- static DEFAULT_RENDER: (v: any) => TemplateResult<1>;
9
- static DEFAULT_COMPARATOR: (a: any, b: any) => number;
7
+ static styles: import("lit").CSSResult;
10
8
  data: Array<T>;
11
9
  columns: Array<ColumnConfiguration<T>>;
12
10
  sort?: Sort;
11
+ emptyState?: EmptyStateConfiguration;
13
12
  stickyHeaders: boolean;
14
13
  disableDataManipulation: boolean;
15
14
  currentSort?: Sort;
@@ -17,7 +16,9 @@ export declare class FtdsTable<T extends Record<string, any>> extends FtLitEleme
17
16
  clickableRows: boolean;
18
17
  private activeRowIndex;
19
18
  private rows?;
20
- static styles: import("lit").CSSResult;
19
+ static DEFAULT_RENDER: (v: any) => TemplateResult<1>;
20
+ static DEFAULT_COMPARATOR: (a: any, b: any) => number;
21
+ focusRow(rowIndex: number): void;
21
22
  protected render(): TemplateResult<1>;
22
23
  protected renderHeader(column: ColumnConfiguration<T>, index: number): TemplateResult<1>;
23
24
  protected renderHeaderRow(): TemplateResult<1>;
@@ -25,18 +26,18 @@ export declare class FtdsTable<T extends Record<string, any>> extends FtLitEleme
25
26
  protected renderTable(data: T[]): TemplateResult<1>;
26
27
  protected renderSortButton(sortIcon: string, label: string, sort: () => void, index: number): TemplateResult<1>;
27
28
  protected renderCell(column: ColumnConfiguration<T>, columnIndex: number, row: T, rowIndex: number): TemplateResult<1>;
28
- protected renderColumnSort(column: ColumnConfiguration<T>, index: number): typeof nothing | TemplateResult<1>;
29
+ protected renderColumnSort(column: ColumnConfiguration<T>, index: number): TemplateResult<1> | typeof nothing;
30
+ private renderEmptyStateTable;
29
31
  protected getSortIcon(isSorted: boolean | undefined): string;
30
- private sortData;
31
32
  protected update(props: PropertyValues): void;
33
+ protected columnPart(prefix: string, index: number): string;
34
+ protected getValue(column: ColumnConfiguration<T>, row: T): any;
35
+ private sortData;
32
36
  private getOppositeSortOrder;
33
37
  private getSortOrderText;
34
38
  private dispatchChangeEvent;
35
- protected columnPart(prefix: string, index: number): string;
36
- protected getValue(column: ColumnConfiguration<T>, row: T): any;
37
39
  private handleRowKeyDown;
38
40
  private dispatchRowClickEvent;
39
41
  private handleRowMouseDown;
40
42
  private handleRowMouseUp;
41
- focusRow(rowIndex: number): void;
42
43
  }
@@ -8,15 +8,15 @@ import { html, nothing } from "lit";
8
8
  import { repeat } from "lit/directives/repeat.js";
9
9
  import "@fluid-topics/ft-button";
10
10
  import "@fluid-topics/ft-typography";
11
- import { FtdsTableChangeEvent } from "./ftds-table.properties";
12
- import { property } from "lit/decorators.js";
13
- import { RowClickEvent } from "./ftds-table.properties";
11
+ import { FtTypographyVariants } from "@fluid-topics/ft-typography";
12
+ import { FtdsTableChangeEvent, RowClickEvent } from "./ftds-table.properties";
13
+ import { property, queryAll, state } from "lit/decorators.js";
14
14
  import { DesignSystemFamily } from "@fluid-topics/design-system-variables";
15
15
  import { designSystemStyles } from "./ftds-table.styles";
16
16
  import { classMap } from "lit/directives/class-map.js";
17
17
  import { unsafeHTML } from "lit/directives/unsafe-html.js";
18
18
  import { FtLitElement, jsonProperty } from "@fluid-topics/ft-wc-utils";
19
- import { queryAll, state } from "lit/decorators.js";
19
+ import { cactusSvg } from "./cactus";
20
20
  class FtdsTable extends FtLitElement {
21
21
  constructor() {
22
22
  super(...arguments);
@@ -28,6 +28,11 @@ class FtdsTable extends FtLitElement {
28
28
  this.clickableRows = false;
29
29
  this.activeRowIndex = -1;
30
30
  }
31
+ focusRow(rowIndex) {
32
+ if (this.rows) {
33
+ this.rows[rowIndex].focus();
34
+ }
35
+ }
31
36
  render() {
32
37
  let data = this.sortData(this.data);
33
38
  return html `
@@ -60,9 +65,9 @@ class FtdsTable extends FtLitElement {
60
65
  }
61
66
  return html `
62
67
  <th class="${classMap(headerCellClasses)}" role="columnheader" scope="col" aria-sort=${ariaSort !== null && ariaSort !== void 0 ? ariaSort : nothing}
63
- part="${this.columnPart("header-cell", index)}">
68
+ part="${this.columnPart("header-cell", index)}">
64
69
  <div class="${classMap(columnTitleContainerClasses)}"
65
- part="${this.columnPart("title-container", index)}">
70
+ part="${this.columnPart("title-container", index)}">
66
71
  <span class="column-title"
67
72
  part="${this.columnPart("title", index)}">
68
73
  <ft-typography variant="caption-1-semibold">
@@ -110,12 +115,13 @@ class FtdsTable extends FtLitElement {
110
115
  var _a;
111
116
  return html `
112
117
  <table class="table"
113
- role="table"
114
- aria-label=${(_a = this.ariaLabel) !== null && _a !== void 0 ? _a : nothing}
118
+ role="table"
119
+ aria-label=${(_a = this.ariaLabel) !== null && _a !== void 0 ? _a : nothing}
115
120
  >
116
121
  ${this.renderHeaderRow()}
117
122
  <tbody>
118
- ${repeat(data, (_, rowIndex) => "row-" + rowIndex, (row, rowIndex) => this.renderRow(row, rowIndex))}
123
+ ${data.length > 0 ? html `
124
+ ${repeat(data, (_, rowIndex) => "row-" + rowIndex, (row, rowIndex) => this.renderRow(row, rowIndex))}` : this.renderEmptyStateTable()}
119
125
  </tbody>
120
126
  </table>
121
127
  `;
@@ -144,7 +150,7 @@ class FtdsTable extends FtLitElement {
144
150
  };
145
151
  return html `
146
152
  <td class="${classMap(classes)}" role="cell"
147
- part="${this.columnPart("cell", columnIndex)} cell-row-${rowIndex} cell-column-${columnIndex}-row-${rowIndex}">
153
+ part="${this.columnPart("cell", columnIndex)} cell-row-${rowIndex} cell-column-${columnIndex}-row-${rowIndex}">
148
154
  <ft-typography variant="caption-1-medium">${render(this.getValue(column, row))}</ft-typography>
149
155
  </td>
150
156
  `;
@@ -166,9 +172,34 @@ class FtdsTable extends FtLitElement {
166
172
  const label = `Sort ${column.title} in ${sortOrderText} order`;
167
173
  return ((_b = column.sortable) !== null && _b !== void 0 ? _b : true) ? this.renderSortButton(sortIcon, label, sort, index) : nothing;
168
174
  }
175
+ renderEmptyStateTable() {
176
+ var _a, _b;
177
+ return html `
178
+ <tr class="row" role="row">
179
+ <td colspan=${this.columns.length} class="cell no-content" role="cell">
180
+ ${((_a = this.emptyState) === null || _a === void 0 ? void 0 : _a.noImage) ? nothing : cactusSvg}
181
+ <ft-typography variant="${FtTypographyVariants.body2medium}">
182
+ ${(_b = this.emptyState) === null || _b === void 0 ? void 0 : _b.content}
183
+ </ft-typography>
184
+ </td>
185
+ </tr>
186
+ `;
187
+ }
169
188
  getSortIcon(isSorted) {
170
189
  return isSorted ? (this.currentSort.order === "asc" ? "sort_up" : "sort_down") : "sort_unsorted";
171
190
  }
191
+ update(props) {
192
+ super.update(props);
193
+ if (props.has("sort")) {
194
+ this.currentSort = this.sort;
195
+ }
196
+ }
197
+ columnPart(prefix, index) {
198
+ return `${prefix} ${prefix}-column-${index}`;
199
+ }
200
+ getValue(column, row) {
201
+ return typeof column.getter === "string" ? row[column.getter] : column.getter(row);
202
+ }
172
203
  sortData(data) {
173
204
  var _a;
174
205
  if (this.currentSort && !this.disableDataManipulation) {
@@ -179,12 +210,6 @@ class FtdsTable extends FtLitElement {
179
210
  }
180
211
  return data;
181
212
  }
182
- update(props) {
183
- super.update(props);
184
- if (props.has("sort")) {
185
- this.currentSort = this.sort;
186
- }
187
- }
188
213
  getOppositeSortOrder(sortOrder) {
189
214
  return sortOrder === "asc" ? "desc" : "asc";
190
215
  }
@@ -201,12 +226,6 @@ class FtdsTable extends FtLitElement {
201
226
  sort: this.currentSort
202
227
  }));
203
228
  }
204
- columnPart(prefix, index) {
205
- return `${prefix} ${prefix}-column-${index}`;
206
- }
207
- getValue(column, row) {
208
- return typeof column.getter === "string" ? row[column.getter] : column.getter(row);
209
- }
210
229
  handleRowKeyDown(e, row) {
211
230
  if (e.key === "Enter" || e.key === " ") {
212
231
  this.dispatchRowClickEvent(row);
@@ -221,15 +240,10 @@ class FtdsTable extends FtLitElement {
221
240
  handleRowMouseUp() {
222
241
  this.activeRowIndex = -1;
223
242
  }
224
- focusRow(rowIndex) {
225
- if (this.rows) {
226
- this.rows[rowIndex].focus();
227
- }
228
- }
229
243
  }
244
+ FtdsTable.styles = designSystemStyles;
230
245
  FtdsTable.DEFAULT_RENDER = (v) => html `${v}`;
231
246
  FtdsTable.DEFAULT_COMPARATOR = (a, b) => a - b;
232
- FtdsTable.styles = designSystemStyles;
233
247
  __decorate([
234
248
  jsonProperty([])
235
249
  ], FtdsTable.prototype, "data", void 0);
@@ -239,6 +253,9 @@ __decorate([
239
253
  __decorate([
240
254
  jsonProperty(undefined)
241
255
  ], FtdsTable.prototype, "sort", void 0);
256
+ __decorate([
257
+ jsonProperty([])
258
+ ], FtdsTable.prototype, "emptyState", void 0);
242
259
  __decorate([
243
260
  property({ type: Boolean })
244
261
  ], FtdsTable.prototype, "stickyHeaders", void 0);
@@ -15,6 +15,10 @@ export interface ColumnConfiguration<T> {
15
15
  gridTemplateColumn?: string;
16
16
  textAlign?: FtColumnAlignment;
17
17
  }
18
+ export interface EmptyStateConfiguration {
19
+ noImage: boolean;
20
+ content: string | TemplateResult;
21
+ }
18
22
  export interface Sort {
19
23
  column: number;
20
24
  order: "asc" | "desc";
@@ -116,7 +116,7 @@ export const designSystemStyles = css `
116
116
  position: relative;
117
117
  }
118
118
 
119
- .cell ft-typography {
119
+ .cell:not(.no-content) ft-typography {
120
120
  display: flex;
121
121
  column-gap: ${table.dataCellVerticalGap};
122
122
  }
@@ -140,4 +140,19 @@ export const designSystemStyles = css `
140
140
  .row > .cell:last-of-type {
141
141
  border-right: ${table.dataRowBorderWidth} solid ${table.dataRowBorderColor};
142
142
  }
143
+
144
+ .no-content svg {
145
+ margin-bottom: 24px;
146
+ }
147
+
148
+ .no-content {
149
+ width: 100%;
150
+ text-align: center;
151
+ padding: 24px;
152
+ }
153
+
154
+ td.no-content > ft-typography {
155
+ display: flex;
156
+ justify-content: center;
157
+ }
143
158
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-table",
3
- "version": "1.2.33",
3
+ "version": "1.2.35",
4
4
  "description": "A dynamic table",
5
5
  "keywords": [
6
6
  "Lit"
@@ -23,10 +23,10 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@fluid-topics/design-system-variables": "0.1.92",
26
- "@fluid-topics/ft-button": "1.2.33",
27
- "@fluid-topics/ft-typography": "1.2.33",
28
- "@fluid-topics/ft-wc-utils": "1.2.33",
26
+ "@fluid-topics/ft-button": "1.2.35",
27
+ "@fluid-topics/ft-typography": "1.2.35",
28
+ "@fluid-topics/ft-wc-utils": "1.2.35",
29
29
  "lit": "3.1.0"
30
30
  },
31
- "gitHead": "3ef5016fcb5fb4c18a05c044f178cfd14f13f42c"
31
+ "gitHead": "b0a09494d663cabc67bc485bc4e733cdbb4e6472"
32
32
  }