vira 25.11.0 → 25.12.1

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.
@@ -6,6 +6,8 @@ export * from './pop-up/vira-menu-trigger.element.js';
6
6
  export * from './pop-up/vira-menu.element.js';
7
7
  export * from './pop-up/vira-pop-up-menu.element.js';
8
8
  export * from './pop-up/vira-pop-up-trigger.element.js';
9
+ export * from './table/define-table.js';
10
+ export * from './table/vira-table.element.js';
9
11
  export * from './vira-bold-text.element.js';
10
12
  export * from './vira-button.element.js';
11
13
  export * from './vira-collapsible-wrapper.element.js';
@@ -6,6 +6,8 @@ export * from './pop-up/vira-menu-trigger.element.js';
6
6
  export * from './pop-up/vira-menu.element.js';
7
7
  export * from './pop-up/vira-pop-up-menu.element.js';
8
8
  export * from './pop-up/vira-pop-up-trigger.element.js';
9
+ export * from './table/define-table.js';
10
+ export * from './table/vira-table.element.js';
9
11
  export * from './vira-bold-text.element.js';
10
12
  export * from './vira-button.element.js';
11
13
  export * from './vira-collapsible-wrapper.element.js';
@@ -0,0 +1,48 @@
1
+ import { type ArrayElement, type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type HtmlInterpolation } from 'element-vir';
3
+ /**
4
+ * An individual cell for {@link ViraTableSetup}.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export type ViraTableCell<Columns extends ViraTableColumns | undefined = undefined> = undefined extends Columns ? Record<PropertyKey, HtmlInterpolation> : Record<ArrayElement<Exclude<Columns, undefined>>['key'], HtmlInterpolation>;
9
+ /**
10
+ * A column definition for {@link ViraTableSetup}.
11
+ *
12
+ * @category Internal
13
+ */
14
+ export type ViraTableColumns = ReadonlyArray<Readonly<{
15
+ /** The key that cells must use to set a value for this column. */
16
+ key: PropertyKey;
17
+ /** This will be displayed in the header for this column. */
18
+ label: HtmlInterpolation;
19
+ } & PartialWithUndefined<{
20
+ /** If set to `true`, this column will not be rendered. */
21
+ hide: boolean;
22
+ }>>>;
23
+ /**
24
+ * An individual row in {@link ViraTableSetup}.
25
+ *
26
+ * @category Internal
27
+ */
28
+ export type ViraTableRow<Columns extends ViraTableColumns | undefined = undefined> = {
29
+ value: ViraTableCell<Columns>;
30
+ };
31
+ /**
32
+ * Table information input for `ViraTable`.
33
+ *
34
+ * @category Internal
35
+ */
36
+ export type ViraTableSetup = Readonly<{
37
+ /** The order of these columns determines the order that they render in. */
38
+ columns: ViraTableColumns;
39
+ rows: ReadonlyArray<Readonly<ViraTableRow>>;
40
+ }>;
41
+ /**
42
+ * Create a type-safe {@link ViraTableSetup} object to be used with the `ViraTable` element.
43
+ *
44
+ * @category Internal
45
+ */
46
+ export declare function createTable<const Columns extends ViraTableColumns>(
47
+ /** The order of these columns determines the order that they render in. */
48
+ columns: Readonly<Columns>, rows: ReadonlyArray<Readonly<ViraTableRow<Columns>>>): ViraTableSetup;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Create a type-safe {@link ViraTableSetup} object to be used with the `ViraTable` element.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export function createTable(
7
+ /** The order of these columns determines the order that they render in. */
8
+ columns, rows) {
9
+ return {
10
+ columns,
11
+ rows,
12
+ };
13
+ }
@@ -0,0 +1,46 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type AttributeValues, type CSSResult } from 'element-vir';
3
+ import { type ViraTableSetup } from './define-table.js';
4
+ /**
5
+ * Element tagnames that have passthroughs setup for them in {@link ViraTable}.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export type ViraTableElementsForPassthrough = 'table' | 'tr' | 'th' | 'td' | 'tbody' | 'thead';
10
+ /**
11
+ * A flexible table element with automatic header pinning. Use {@link createTable} to create a
12
+ * type-safe table input.
13
+ *
14
+ * @category Elements
15
+ */
16
+ export declare const ViraTable: import("element-vir").DeclarativeElementDefinition<"vira-table", Readonly<{
17
+ /**
18
+ * The table information.
19
+ *
20
+ * Use {@link createTable} to form a type-safe value for this.
21
+ */
22
+ table: ViraTableSetup;
23
+ } & PartialWithUndefined<{
24
+ /**
25
+ * Block the sticky table header.
26
+ *
27
+ * @default false
28
+ */
29
+ preventStickyHeader: boolean;
30
+ /**
31
+ * Hide header row entirely.
32
+ *
33
+ * @default false
34
+ */
35
+ hideHeaderRow: boolean;
36
+ /**
37
+ * Pixel value of the header row sticky offset.
38
+ *
39
+ * @default 0
40
+ */
41
+ stickyOffset: number;
42
+ /** Attributes that will be applied directly to the inner elements. */
43
+ attributePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, AttributeValues>>>;
44
+ /** Styles that will be applied directly to the inner elements. */
45
+ stylePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, CSSResult>>>;
46
+ }>>, {}, {}, "vira-table-", "vira-table-", readonly []>;
@@ -0,0 +1,124 @@
1
+ import { attributes, css, html, ifDefined, nothing, } from 'element-vir';
2
+ import { defineViraElement } from '../define-vira-element.js';
3
+ /**
4
+ * A flexible table element with automatic header pinning. Use {@link createTable} to create a
5
+ * type-safe table input.
6
+ *
7
+ * @category Elements
8
+ */
9
+ export const ViraTable = defineViraElement()({
10
+ tagName: 'vira-table',
11
+ styles: css `
12
+ :host {
13
+ background-color: white;
14
+ display: block;
15
+ position: relative;
16
+ }
17
+
18
+ table,
19
+ thead {
20
+ background-color: inherit;
21
+ }
22
+
23
+ table {
24
+ border-collapse: collapse;
25
+ }
26
+
27
+ thead {
28
+ z-index: 10;
29
+ /* Note that important thead styles are also directly attached to the element. */
30
+ }
31
+ `,
32
+ render({ inputs }) {
33
+ const rows = inputs.table.rows.map((row) => {
34
+ const cells = inputs.table.columns.map((column) => {
35
+ if (column.hide) {
36
+ return nothing;
37
+ }
38
+ return html `
39
+ <td
40
+ ${inputs.attributePassthrough?.td
41
+ ? attributes(inputs.attributePassthrough.td)
42
+ : nothing}
43
+ style=${ifDefined(inputs.stylePassthrough?.td)}
44
+ >
45
+ ${row.value[column.key]}
46
+ </td>
47
+ `;
48
+ });
49
+ return html `
50
+ <tr
51
+ ${inputs.attributePassthrough?.tr
52
+ ? attributes(inputs.attributePassthrough.tr)
53
+ : nothing}
54
+ style=${ifDefined(inputs.stylePassthrough?.tr)}
55
+ >
56
+ ${cells}
57
+ </tr>
58
+ `;
59
+ });
60
+ const headerCells = inputs.hideHeaderRow
61
+ ? undefined
62
+ : inputs.table.columns.map((column) => {
63
+ if (column.hide) {
64
+ return nothing;
65
+ }
66
+ return html `
67
+ <th
68
+ ${inputs.attributePassthrough?.th
69
+ ? attributes(inputs.attributePassthrough.th)
70
+ : nothing}
71
+ style=${ifDefined(inputs.stylePassthrough?.th)}
72
+ >
73
+ ${column.label}
74
+ </th>
75
+ `;
76
+ });
77
+ const headerRow = headerCells
78
+ ? html `
79
+ <tr
80
+ ${inputs.attributePassthrough?.tr
81
+ ? attributes(inputs.attributePassthrough.tr)
82
+ : nothing}
83
+ style=${ifDefined(inputs.stylePassthrough?.tr)}
84
+ >
85
+ ${headerCells}
86
+ </tr>
87
+ `
88
+ : nothing;
89
+ const theadStyles = css `
90
+ ${inputs.stylePassthrough?.thead || css ``}
91
+ top: ${inputs.stickyOffset || 0}px;
92
+ ${inputs.preventStickyHeader || inputs.hideHeaderRow
93
+ ? css ``
94
+ : css `
95
+ position: sticky;
96
+ `}
97
+ `;
98
+ return html `
99
+ <table
100
+ ${inputs.attributePassthrough?.table
101
+ ? attributes(inputs.attributePassthrough.table)
102
+ : nothing}
103
+ style=${ifDefined(inputs.stylePassthrough?.table)}
104
+ >
105
+ <thead
106
+ ${inputs.attributePassthrough?.thead
107
+ ? attributes(inputs.attributePassthrough.thead)
108
+ : nothing}
109
+ style=${theadStyles}
110
+ >
111
+ ${headerRow}
112
+ </thead>
113
+ <tbody
114
+ ${inputs.attributePassthrough?.tbody
115
+ ? attributes(inputs.attributePassthrough.tbody)
116
+ : nothing}
117
+ style=${ifDefined(inputs.stylePassthrough?.tbody)}
118
+ >
119
+ ${rows}
120
+ </tbody>
121
+ </table>
122
+ `;
123
+ },
124
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "25.11.0",
3
+ "version": "25.12.1",
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.11.0"
70
+ "element-vir": "^25.12.1"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=22"