From 56d9d4dfa3fb080bf4de340a88aa7e2437f6942f Mon Sep 17 00:00:00 2001 From: Michel Binder <37824907+cubmic@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:47:40 +0100 Subject: [PATCH] feat(table): add align prop for columns and hover effect (#254) Co-authored-by: Michel Binder --- src/components/table/Table.js | 48 +++++++++++++++++++++++----------- src/components/table/table.css | 22 +++++++++++----- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/components/table/Table.js b/src/components/table/Table.js index db8c75c..19106f3 100644 --- a/src/components/table/Table.js +++ b/src/components/table/Table.js @@ -115,7 +115,7 @@ export class LeuTable extends LeuElement { this.sortOrderAsc = !this.sortOrderAsc } else { this.sortIndex = index - this.sortOrder = "asc" + this.sortOrderAsc = false } } @@ -125,10 +125,6 @@ export class LeuTable extends LeuElement { >` } - sortArrow(col) { - return html` ${this.isSorted(col) ? this.sortArrowIcon() : nothing} ` - } - get _columns() { return this.columns } @@ -172,6 +168,26 @@ export class LeuTable extends LeuElement { sticky: this.firstColumnSticky, } + function headerStyle(col) { + if (col.headerStyle) { + return styleMap({ + ...col.headerStyle(), + textAlign: col.align === "right" ? "right" : undefined, + }) + } + return col.align === "right" ? styleMap({ textAlign: "right" }) : nothing + } + + function bodyStyle(col, row) { + if (col.style) { + return styleMap({ + ...col.style(row), + textAlign: col.align === "right" ? "right" : undefined, + }) + } + return col.align === "right" ? styleMap({ textAlign: "right" }) : nothing + } + return html`
${this._columns.map( (col) => - html` + html` ${col.sort - ? html`` : col.name} ` @@ -204,9 +224,7 @@ export class LeuTable extends LeuElement { html` ${this._columns.map( (col) => - html` + html` ${col.value(row)} ` )} diff --git a/src/components/table/table.css b/src/components/table/table.css index fa107b3..0d734b0 100644 --- a/src/components/table/table.css +++ b/src/components/table/table.css @@ -66,20 +66,30 @@ button { line-height: 1.5; padding: 0; border: 0; - width: 100%; - display: flex; - align-items: flex-center; font-size: inherit; font-family: inherit; color: inherit; } -thead leu-icon { - --leu-icon-size: 1.25rem; +button span { + vertical-align: bottom; +} +button leu-icon { + --leu-icon-size: 1.25rem; display: inline-block; - color: var(--leu-color-accent-blue); padding: 0; + opacity: 0; + vertical-align: bottom; +} + +button:hover leu-icon { + opacity: 1; +} + +button.active leu-icon { + color: var(--leu-color-accent-blue); + opacity: 1; } table.sticky td:first-child,