Skip to content

Commit

Permalink
No issue - introduced alerts for the cba-table (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manvel authored Jan 2, 2024
1 parent f41f61c commit ed5611b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/cba-table/cba-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ const constructableCSS = new ConstructableCSS(shadowCSS);


/**
* @typedef {{[key: string]: string}} TableItemTexts
* @typedef {{[key: string]: string}} TableItemTexts
*/

/**
* @typedef {object} Alert - alert object.
* @property {string} [text] - alert text.
* @property {"error"} [type] - alert type.
*/

/**
* @typedef {object} TableItem
* @property {string} [id] - unique id of the row.
* @property {TableItemTexts} texts - texts for each cell. Key is column name.
* @property {any} data - payload.
* @property {Alert} alert - highlight row.
*/

export class Table extends HTMLElement
Expand Down Expand Up @@ -514,14 +521,22 @@ export class Table extends HTMLElement
*/
_renderBody()
{
/**
* @param {TableItem} rowData - row data.
*/
const createRow = (rowData) =>
{
const {id, selected} = rowData;
const selectedClass = selected ? "highlight" : undefined;
return html`<tr data-id="${id}" class=${ifDefined(selectedClass)} draggable="${ifDefined(this.reorder)}" tabindex=${selected ? 0 : -1}>${this.columns.map((name) =>
const {id, selected, alert} = rowData;
const classes = [];
if (selected)
classes.push("highlight");
if (alert && alert.type === "error")
classes.push("alert");
const alertText = alert && alert.text ? alert.text : "";
return html`<tr data-id="${id}" class=${ifDefined(classes.join(" "))} draggable="${ifDefined(this.reorder)}" tabindex=${selected ? 0 : -1}>${this.columns.map((name) =>
{
const text = this._getText(rowData, name);
return html`<td data-id="${name}" title="${text}">${text}</td>`;
return html`<td data-id="${name}" title="${alertText || text}">${text}</td>`;
})}</tr>`;
};
render(html`${this._data.map(createRow)}`, this.tableBodyElem);
Expand Down
8 changes: 7 additions & 1 deletion src/cba-table/shadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
--hover-primary: #eaeaea;
--hover-secondary: #e4e4e4;
--color-alert: #f57777b3;
--color-primary: #222222;
--color-border: #aaaaaa;
--color-selected: #cccccc;
Expand Down Expand Up @@ -118,6 +119,11 @@ tbody tr.highlight
outline: none;
}

tbody tr.alert
{
background-color: var(--color-alert);
}

tbody tr
{
outline: none;
Expand All @@ -129,7 +135,7 @@ tbody tr:focus
filter: drop-shadow(0 0 4px var(--color-focus));
}

tbody tr:not(.highlight):hover
tbody tr:not(.highlight):not(.alert):hover
{
background: linear-gradient(var(--hover-primary) 0%,
var(--hover-primary) 50%,
Expand Down
10 changes: 10 additions & 0 deletions tests/smoke/cba-table/smoke.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const cbaTable = document.querySelector("cba-table");
/**
* @type {import("../../../src/cba-table/cba-table").TableItem[]}
*/
const items = [];

items.push({
Expand All @@ -8,6 +11,13 @@ items.push({
type: "Event"
});

items.push({
id: "alert-item",
values: ["Alert", "Value alert"],
type: "Event alert",
alert: {type: "error", text: "This is an alert"},
});

for (let index = 0; index < 30; index++)
{
items.push({
Expand Down

0 comments on commit ed5611b

Please sign in to comment.