diff --git a/src/components/table/partial-styles/tabulator-custom-styles.scss b/src/components/table/partial-styles/tabulator-custom-styles.scss index da6c2a3464..f7c018dc17 100644 --- a/src/components/table/partial-styles/tabulator-custom-styles.scss +++ b/src/components/table/partial-styles/tabulator-custom-styles.scss @@ -1,6 +1,22 @@ @use '../../../style/mixins'; @use '../../../style/functions'; - +@use '../../../style/theme-color-variables'; +@use '../../../style/color-palette-extended'; + +@mixin table-row-selected-indicator($border-color, $z-index) { + &:before { + $width-of-selected-row-indicator: 0.2rem; + content: ''; + display: inline-block; + box-sizing: border-box; + position: sticky; + z-index: $z-index; + inset: 0 0 auto 0; + border: $width-of-selected-row-indicator solid $border-color; + border-radius: 1rem; + margin-right: -$width-of-selected-row-indicator * 2; + } +} .interactive-feedback { // This is a div, injected by us into all rows. // We use it to visualize interactive feedback. @@ -45,19 +61,10 @@ box-shadow: var(--button-shadow-inset-pressed); } - &:before { - $width-of-selected-row-indicator: 0.2rem; - content: ''; - display: inline-block; - box-sizing: border-box; - position: sticky; - z-index: $table--has-interactive-rows--selectable-row--hover + 1; - inset: 0 0 auto 0; - border: $width-of-selected-row-indicator solid - var(--mdc-theme-primary); - border-radius: 1rem; - margin-right: -$width-of-selected-row-indicator * 2; - } + @include table-row-selected-indicator( + var(--mdc-theme-primary), + $table--has-interactive-rows--selectable-row--hover + 1 + ); } } } @@ -89,6 +96,12 @@ } } } + .recent-active { + @include table-row-selected-indicator( + rgb(var(--contrast-700)), + $table--has-interactive-rows--selectable-row--hover + 1 + ); + } } :host(.has-low-density) { diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index fcc6bea9b3..a3299c1e39 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -41,11 +41,7 @@ const FIRST_PAGE = 1; * @exampleComponent limel-example-table-layout-low-density * @exampleComponent limel-example-table-interactive-rows */ -@Component({ - tag: 'limel-table', - styleUrl: 'table.scss', - shadow: true, -}) +@Component({ tag: 'limel-table', styleUrl: 'table.scss', shadow: true }) export class Table { /** * Data to be displayed in the table @@ -103,6 +99,16 @@ export class Table { @Prop({ mutable: true }) public activeRow: RowData; + /** + * Array of rows that have been active + */ + private activeRowHistory: Tabulator.RowComponent[] = []; + + /** + * Maximum number of rows to keep in the active row history + */ + private static readonly MAX_ACTIVE_ROW_HISTORY = 2; + /** * Set to `true` to enable reordering of the columns by dragging them */ @@ -638,10 +644,7 @@ export class Table { const columnSorters = sorters.map(createColumnSorter(this.columns)); - const load = { - page: currentPage, - sorters: columnSorters, - }; + const load = { page: currentPage, sorters: columnSorters }; // In order to make limel-table behave more like a controlled component, // we always return the existing data from this function, therefore @@ -705,7 +708,16 @@ export class Table { this.activeRow = row.getData(); } + const clickedRow = this.tabulator.getRow(row.getData().id); + this.activeRowHistory.push(clickedRow); + + // Keep the history array limited to the last two rows + if (this.activeRowHistory.length > Table.MAX_ACTIVE_ROW_HISTORY) { + this.activeRowHistory.shift(); + } + this.activate.emit(this.activeRow); + this.formatRows(); } private getActiveRows: () => Tabulator.RowComponent[] = () => { @@ -746,6 +758,15 @@ export class Table { row.getElement().classList.remove('active'); } + const previousActiveRow = + this.activeRowHistory.length > 1 ? this.activeRowHistory[0] : null; + + if (previousActiveRow === row) { + row.getElement().classList.add('recent-active'); + } else { + row.getElement().classList.remove('recent-active'); + } + const interactiveFeedbackElement = row .getElement() .getElementsByClassName('interactive-feedback'); @@ -788,10 +809,7 @@ export class Table { return {}; } - return { - movableColumns: true, - columnMoved: this.handleMoveColumn, - }; + return { movableColumns: true, columnMoved: this.handleMoveColumn }; }; private handleMoveColumn = (_, components: Tabulator.ColumnComponent[]) => { @@ -810,11 +828,7 @@ export class Table { render() { return ( - +