vira 25.12.1 → 25.12.2

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.
@@ -26,8 +26,18 @@ export type ViraTableColumns = ReadonlyArray<Readonly<{
26
26
  * @category Internal
27
27
  */
28
28
  export type ViraTableRow<Columns extends ViraTableColumns | undefined = undefined> = {
29
- value: ViraTableCell<Columns>;
30
- };
29
+ cells: ViraTableCell<Columns>;
30
+ } & PartialWithUndefined<{
31
+ /**
32
+ * If `true`, no actions will be fired from this row (like row clicks). No disable styles are
33
+ * applied.
34
+ *
35
+ * @default false
36
+ */
37
+ disabled: boolean;
38
+ /** Optional: keep track of which row is which by attaching an id to it. */
39
+ id: PropertyKey;
40
+ }>;
31
41
  /**
32
42
  * Table information input for `ViraTable`.
33
43
  *
@@ -1,6 +1,6 @@
1
1
  import { type PartialWithUndefined } from '@augment-vir/common';
2
2
  import { type AttributeValues, type CSSResult } from 'element-vir';
3
- import { type ViraTableSetup } from './define-table.js';
3
+ import { type ViraTableRow, type ViraTableSetup } from './define-table.js';
4
4
  /**
5
5
  * Element tagnames that have passthroughs setup for them in {@link ViraTable}.
6
6
  *
@@ -21,6 +21,12 @@ export declare const ViraTable: import("element-vir").DeclarativeElementDefiniti
21
21
  */
22
22
  table: ViraTableSetup;
23
23
  } & PartialWithUndefined<{
24
+ /**
25
+ * Block all rows from being clickable.
26
+ *
27
+ * @default false
28
+ */
29
+ preventRowClicks: boolean;
24
30
  /**
25
31
  * Block the sticky table header.
26
32
  *
@@ -43,4 +49,9 @@ export declare const ViraTable: import("element-vir").DeclarativeElementDefiniti
43
49
  attributePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, AttributeValues>>>;
44
50
  /** Styles that will be applied directly to the inner elements. */
45
51
  stylePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, CSSResult>>>;
46
- }>>, {}, {}, "vira-table-", "vira-table-", readonly []>;
52
+ }>>, {}, {
53
+ rowClick: import("element-vir").DefineEvent<{
54
+ row: ViraTableRow;
55
+ originalEvent: MouseEvent;
56
+ }>;
57
+ }, "vira-table-", "vira-table-row-hover" | "vira-table-row-active" | "vira-table-background", readonly []>;
@@ -1,4 +1,4 @@
1
- import { attributes, css, html, ifDefined, nothing, } from 'element-vir';
1
+ import { attributes, classMap, css, defineElementEvent, html, ifDefined, listen, nothing, } from 'element-vir';
2
2
  import { defineViraElement } from '../define-vira-element.js';
3
3
  /**
4
4
  * A flexible table element with automatic header pinning. Use {@link createTable} to create a
@@ -8,16 +8,26 @@ import { defineViraElement } from '../define-vira-element.js';
8
8
  */
9
9
  export const ViraTable = defineViraElement()({
10
10
  tagName: 'vira-table',
11
- styles: css `
11
+ cssVars: {
12
+ 'vira-table-row-hover': '#cfe9ff',
13
+ 'vira-table-row-active': '#cfe9ff',
14
+ 'vira-table-background': 'white',
15
+ },
16
+ styles: ({ cssVars }) => css `
12
17
  :host {
13
- background-color: white;
18
+ background: ${cssVars['vira-table-background'].value};
14
19
  display: block;
15
20
  position: relative;
16
21
  }
17
22
 
18
23
  table,
19
24
  thead {
20
- background-color: inherit;
25
+ background: inherit;
26
+ }
27
+
28
+ th,
29
+ td {
30
+ padding: 0;
21
31
  }
22
32
 
23
33
  table {
@@ -26,10 +36,24 @@ export const ViraTable = defineViraElement()({
26
36
 
27
37
  thead {
28
38
  z-index: 10;
29
- /* Note that important thead styles are also directly attached to the element. */
39
+ /* Other important thead styles are directly attached to the HTML element. */
40
+ }
41
+
42
+ .clickable {
43
+ cursor: pointer;
44
+
45
+ &:hover {
46
+ background-color: ${cssVars['vira-table-row-hover'].value};
47
+ }
48
+ &:active {
49
+ background-color: ${cssVars['vira-table-row-active'].value};
50
+ }
30
51
  }
31
52
  `,
32
- render({ inputs }) {
53
+ events: {
54
+ rowClick: defineElementEvent(),
55
+ },
56
+ render({ inputs, events, dispatch }) {
33
57
  const rows = inputs.table.rows.map((row) => {
34
58
  const cells = inputs.table.columns.map((column) => {
35
59
  if (column.hide) {
@@ -42,16 +66,25 @@ export const ViraTable = defineViraElement()({
42
66
  : nothing}
43
67
  style=${ifDefined(inputs.stylePassthrough?.td)}
44
68
  >
45
- ${row.value[column.key]}
69
+ ${row.cells[column.key]}
46
70
  </td>
47
71
  `;
48
72
  });
73
+ const isClickable = !inputs.preventRowClicks && !row.disabled;
49
74
  return html `
50
75
  <tr
76
+ class=${classMap({
77
+ clickable: isClickable,
78
+ })}
51
79
  ${inputs.attributePassthrough?.tr
52
80
  ? attributes(inputs.attributePassthrough.tr)
53
81
  : nothing}
54
82
  style=${ifDefined(inputs.stylePassthrough?.tr)}
83
+ ${listen('click', (event) => {
84
+ if (isClickable) {
85
+ dispatch(new events.rowClick({ originalEvent: event, row }));
86
+ }
87
+ })}
55
88
  >
56
89
  ${cells}
57
90
  </tr>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "25.12.1",
3
+ "version": "25.12.2",
4
4
  "description": "A simple and highly versatile design system using element-vir.",
5
5
  "keywords": [
6
6
  "design",
@@ -67,7 +67,7 @@
67
67
  "vite-tsconfig-paths": "^5.1.4"
68
68
  },
69
69
  "peerDependencies": {
70
- "element-vir": "^25.12.1"
70
+ "element-vir": "^25.12.2"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=22"