vira 26.0.2 → 26.1.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,8 +6,6 @@ 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/create-table.js';
10
- export * from './table/vira-table.element.js';
11
9
  export * from './vira-bold-text.element.js';
12
10
  export * from './vira-button.element.js';
13
11
  export * from './vira-collapsible-wrapper.element.js';
@@ -6,8 +6,6 @@ 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/create-table.js';
10
- export * from './table/vira-table.element.js';
11
9
  export * from './vira-bold-text.element.js';
12
10
  export * from './vira-button.element.js';
13
11
  export * from './vira-collapsible-wrapper.element.js';
@@ -0,0 +1,92 @@
1
+ import { type ArrayElement, type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type HtmlInterpolation } from 'element-vir';
3
+ /**
4
+ * An individual key definition in {@link ViraTableHeaders}.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export type ViraTableKey = Readonly<{
9
+ /** The key that cells must set a value to. */
10
+ key: string | number;
11
+ } & PartialWithUndefined<{
12
+ /** If this is not provided, `key` will be used directly. */
13
+ content: HtmlInterpolation;
14
+ }>>;
15
+ /**
16
+ * All header definitions for a {@link ViraTable} instance.
17
+ *
18
+ * @category Internal
19
+ */
20
+ export type ViraTableHeaders = ReadonlyArray<ViraTableKey>;
21
+ /**
22
+ * An individual entry in {@link ViraTable}. In default table orientation, this will be a row. In
23
+ * horizontal orientation, this will be a column.
24
+ *
25
+ * @category Internal
26
+ */
27
+ export type ViraTableEntry<Headers extends ViraTableHeaders | undefined = undefined> = Record<HeaderKey<Headers>, HtmlInterpolation>;
28
+ /**
29
+ * An individual cell in {@link ViraTable}.
30
+ *
31
+ * @category Internal
32
+ */
33
+ export type ViraTableCell<Headers extends ViraTableHeaders | undefined = undefined> = {
34
+ content: HtmlInterpolation;
35
+ key: HeaderKey<Headers>;
36
+ };
37
+ /**
38
+ * All keys for the given headers.
39
+ *
40
+ * @category Internal
41
+ */
42
+ export type HeaderKey<Headers extends ViraTableHeaders | undefined = undefined> = undefined extends Headers ? string | number : ArrayElement<Exclude<Headers, undefined>>['key'];
43
+ /**
44
+ * Table information that can easily be mapped into a `<table>` element.
45
+ *
46
+ * @category Internal
47
+ */
48
+ export type ViraTable<Headers extends ViraTableHeaders | undefined = undefined, Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical> = (Orientation extends ViraTableOrientation.Horizontal ? {
49
+ headerRow: undefined;
50
+ orientation: Orientation;
51
+ } : {
52
+ headerRow: ViraTableCell<Headers>[];
53
+ orientation: Orientation;
54
+ }) & {
55
+ rows: ViraTableCell<Headers>[][];
56
+ };
57
+ /**
58
+ * Orientation options for {@link ViraTable}.
59
+ *
60
+ * @category Internal
61
+ */
62
+ export declare enum ViraTableOrientation {
63
+ /**
64
+ * This is the default table layout. Each entry becomes a new row. Headers are a row at the top
65
+ * of the table.
66
+ */
67
+ Vertical = "vertical",
68
+ /**
69
+ * This is a pivoted table layout. Each entry becomes a column. Headers are the left most
70
+ * column.
71
+ */
72
+ Horizontal = "horizontal"
73
+ }
74
+ /**
75
+ * Options for {@link defineTable}.
76
+ *
77
+ * @category Internal
78
+ */
79
+ export type ViraTableOptions<Orientation extends ViraTableOrientation = ViraTableOrientation> = PartialWithUndefined<{
80
+ orientation: Orientation;
81
+ hideHeaders: boolean;
82
+ }>;
83
+ /**
84
+ * Accepts headers and entries and lays them out into rows according to the given
85
+ * `options.orientation` (defaulting to vertical). This does not itself create a `<table>` element,
86
+ * but makes it easy to loop over rows to (with `.map()`) to generate rows in a table.
87
+ *
88
+ * @category Table
89
+ */
90
+ export declare function defineTable<const Headers extends ViraTableHeaders, const Orientation extends ViraTableOrientation = ViraTableOrientation.Vertical>(
91
+ /** The order of these keys determines the order that they render in. */
92
+ headers: Readonly<Headers>, entries: ReadonlyArray<Readonly<ViraTableEntry<Headers>>>, options?: ViraTableOptions<Orientation>): ViraTable<Headers, Orientation>;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Orientation options for {@link ViraTable}.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export var ViraTableOrientation;
7
+ (function (ViraTableOrientation) {
8
+ /**
9
+ * This is the default table layout. Each entry becomes a new row. Headers are a row at the top
10
+ * of the table.
11
+ */
12
+ ViraTableOrientation["Vertical"] = "vertical";
13
+ /**
14
+ * This is a pivoted table layout. Each entry becomes a column. Headers are the left most
15
+ * column.
16
+ */
17
+ ViraTableOrientation["Horizontal"] = "horizontal";
18
+ })(ViraTableOrientation || (ViraTableOrientation = {}));
19
+ /**
20
+ * Accepts headers and entries and lays them out into rows according to the given
21
+ * `options.orientation` (defaulting to vertical). This does not itself create a `<table>` element,
22
+ * but makes it easy to loop over rows to (with `.map()`) to generate rows in a table.
23
+ *
24
+ * @category Table
25
+ */
26
+ export function defineTable(
27
+ /** The order of these keys determines the order that they render in. */
28
+ headers, entries, options = {}) {
29
+ if (options.orientation === ViraTableOrientation.Horizontal) {
30
+ const rows = headers.map((header) => {
31
+ const headerCellArray = options.hideHeaders
32
+ ? []
33
+ : [
34
+ {
35
+ content: header.content ?? header.key,
36
+ key: header.key,
37
+ },
38
+ ];
39
+ const cells = entries.map((entry) => {
40
+ return {
41
+ content: entry[header.key],
42
+ key: header.key,
43
+ };
44
+ });
45
+ return [
46
+ ...headerCellArray,
47
+ ...cells,
48
+ ];
49
+ });
50
+ return {
51
+ headerRow: undefined,
52
+ rows,
53
+ orientation: ViraTableOrientation.Horizontal,
54
+ };
55
+ }
56
+ else {
57
+ const headerRow = options.hideHeaders
58
+ ? []
59
+ : headers.map((header) => {
60
+ return {
61
+ content: header.content ?? header.key,
62
+ key: header.key,
63
+ };
64
+ });
65
+ const rows = entries.map((entry) => {
66
+ return headers.map((header) => {
67
+ return {
68
+ content: entry[header.key],
69
+ key: header.key,
70
+ };
71
+ });
72
+ });
73
+ return {
74
+ headerRow,
75
+ rows,
76
+ orientation: ViraTableOrientation.Vertical,
77
+ };
78
+ }
79
+ }
@@ -1 +1,2 @@
1
+ export * from './define-table.js';
1
2
  export * from './pop-up-manager.js';
@@ -1 +1,2 @@
1
+ export * from './define-table.js';
1
2
  export * from './pop-up-manager.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "26.0.2",
3
+ "version": "26.1.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": "^26.0.2"
70
+ "element-vir": "^26.1.1"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=22"
@@ -1,74 +0,0 @@
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 ViraTableCells<Keys extends ViraTableKeys | undefined = undefined> = undefined extends Keys ? Record<PropertyKey, HtmlInterpolation> : Record<ArrayElement<Exclude<Keys, undefined>>['key'], HtmlInterpolation>;
9
- /**
10
- * An individual key definition in {@link ViraTableKeys}. In default table orientation, this will
11
- * define each column's key. In horizontal orientation, this will define each row's key.
12
- *
13
- * @category Internal
14
- */
15
- export type ViraTableKey = Readonly<{
16
- /** The key that cells must set a value to. */
17
- key: PropertyKey;
18
- } & PartialWithUndefined<{
19
- /**
20
- * This will be displayed in the header for this key. If no `label` is provided, the `key`
21
- * will be used.
22
- */
23
- label: HtmlInterpolation;
24
- /** If set to `true`, all cells for this key will not be rendered. */
25
- hide: boolean;
26
- /** In horizontal table orientation, this prevents this key's row from being clicked. */
27
- disabled: boolean;
28
- /** If true, will be rendered as headers. */
29
- isHeader: boolean;
30
- }>>;
31
- /**
32
- * All key definitions for a {@link ViraTableSetup} instance. In default table orientation, these
33
- * will define each column. In horizontal orientation, this will define each row header.
34
- *
35
- * @category Internal
36
- */
37
- export type ViraTableKeys = ReadonlyArray<ViraTableKey>;
38
- /**
39
- * An individual entry in {@link ViraTableSetup}. In default table orientation, this will be a row.
40
- * In horizontal orientation, this will be a column.
41
- *
42
- * @category Internal
43
- */
44
- export type ViraTableEntry<Keys extends ViraTableKeys | undefined = undefined> = {
45
- cells: ViraTableCells<Keys>;
46
- } & PartialWithUndefined<{
47
- /**
48
- * If `true`, no actions will be fired from this entry (like clicks). No disable styles are
49
- * applied.
50
- *
51
- * @default false
52
- */
53
- disabled: boolean;
54
- /** Optional: keep track of which entry is which by attaching an id to it. */
55
- id: PropertyKey;
56
- }>;
57
- /**
58
- * Table information input for `ViraTable`.
59
- *
60
- * @category Internal
61
- */
62
- export type ViraTableSetup = Readonly<{
63
- /** The order of these keys determines the order that they render in. */
64
- keys: ViraTableKeys;
65
- entries: ReadonlyArray<Readonly<ViraTableEntry>>;
66
- }>;
67
- /**
68
- * Create a type-safe {@link ViraTableSetup} object to be used with the `ViraTable` element.
69
- *
70
- * @category Internal
71
- */
72
- export declare function createTable<const Keys extends ViraTableKeys>(
73
- /** The order of these keys determines the order that they render in. */
74
- keys: Readonly<Keys>, entries: ReadonlyArray<Readonly<ViraTableEntry<Keys>>>): ViraTableSetup;
@@ -1,13 +0,0 @@
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 keys determines the order that they render in. */
8
- keys, entries) {
9
- return {
10
- keys,
11
- entries,
12
- };
13
- }
@@ -1,64 +0,0 @@
1
- import { type PartialWithUndefined } from '@augment-vir/common';
2
- import { type AttributeValues, type CSSResult } from 'element-vir';
3
- import { type ViraTableEntry, type ViraTableSetup } from './create-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
- * Key headers are rendered on the left, rows become columns.
26
- *
27
- * @default false
28
- */
29
- horizontalOrientation: boolean;
30
- /**
31
- * Allow all rows to be clickable. Each row can override this for itself.
32
- *
33
- * @default false
34
- */
35
- allowRowClicks: boolean;
36
- /**
37
- * Block the sticky table header.
38
- *
39
- * @default false
40
- */
41
- preventStickyHeader: boolean;
42
- /**
43
- * Hide header row (in default orientation) or column (in horizontal orientation)
44
- * entirely.
45
- *
46
- * @default false
47
- */
48
- hideKeyHeaders: boolean;
49
- /**
50
- * Pixel value of the header's sticky offset.
51
- *
52
- * @default 0
53
- */
54
- stickyOffset: number;
55
- /** Attributes that will be applied directly to the inner elements. */
56
- attributePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, AttributeValues>>>;
57
- /** Styles that will be applied directly to the inner elements. */
58
- stylePassthrough: Readonly<PartialWithUndefined<Record<ViraTableElementsForPassthrough, CSSResult>>>;
59
- }>>, {}, {
60
- rowClick: import("element-vir").DefineEvent<{
61
- entry: ViraTableEntry;
62
- originalEvent: MouseEvent;
63
- }>;
64
- }, "vira-table-", "vira-table-", readonly []>;
@@ -1,220 +0,0 @@
1
- import { attributes, classMap, css, defineElementEvent, html, ifDefined, listen, nothing, } from 'element-vir';
2
- import { viraFormCssVars } from '../../styles/form-themes.js';
3
- import { defineViraElement } from '../define-vira-element.js';
4
- /**
5
- * A flexible table element with automatic header pinning. Use {@link createTable} to create a
6
- * type-safe table input.
7
- *
8
- * @category Elements
9
- */
10
- export const ViraTable = defineViraElement()({
11
- tagName: 'vira-table',
12
- styles: css `
13
- :host {
14
- background: ${viraFormCssVars['vira-form-background-color'].value};
15
- display: block;
16
- position: relative;
17
- }
18
-
19
- table,
20
- thead {
21
- background: inherit;
22
- }
23
-
24
- th,
25
- td {
26
- padding: 0;
27
- }
28
-
29
- table {
30
- border-collapse: collapse;
31
- }
32
-
33
- thead {
34
- z-index: 10;
35
- /* Other important thead styles are directly attached to the HTML element. */
36
- }
37
-
38
- .clickable {
39
- cursor: pointer;
40
-
41
- &:hover {
42
- color: ${viraFormCssVars['vira-form-selection-hover-foreground-color'].value};
43
- background-color: ${viraFormCssVars['vira-form-selection-hover-background-color']
44
- .value};
45
- }
46
- &:active {
47
- color: ${viraFormCssVars['vira-form-selection-active-foreground-color'].value};
48
- background-color: ${viraFormCssVars['vira-form-selection-active-background-color']
49
- .value};
50
- }
51
- }
52
- `,
53
- events: {
54
- rowClick: defineElementEvent(),
55
- },
56
- render({ inputs, events, dispatch }) {
57
- const rowTemplates = inputs.horizontalOrientation
58
- ? inputs.table.keys.map((key) => {
59
- if (key.hide) {
60
- return nothing;
61
- }
62
- const cells = inputs.table.entries.map((entry) => {
63
- const cellElement = key.isHeader ? 'th' : 'td';
64
- return html `
65
- <${cellElement}
66
- ${listen('click', (event) => {
67
- if (isClickable) {
68
- dispatch(new events.rowClick({ originalEvent: event, entry: entry }));
69
- }
70
- })}
71
- ${key.isHeader
72
- ? inputs.attributePassthrough?.th
73
- ? attributes(inputs.attributePassthrough.th)
74
- : nothing
75
- : inputs.attributePassthrough?.td
76
- ? attributes(inputs.attributePassthrough.td)
77
- : nothing}
78
- style=${key.isHeader
79
- ? ifDefined(inputs.stylePassthrough?.th)
80
- : ifDefined(inputs.stylePassthrough?.td)}
81
- >
82
- ${entry.cells[key.key]}
83
- </${cellElement}>
84
- `;
85
- });
86
- const isClickable = !!inputs.allowRowClicks && !key.disabled;
87
- return html `
88
- <tr
89
- class=${classMap({
90
- clickable: isClickable,
91
- })}
92
- ${inputs.attributePassthrough?.tr
93
- ? attributes(inputs.attributePassthrough.tr)
94
- : nothing}
95
- style=${ifDefined(inputs.stylePassthrough?.tr)}
96
- >
97
- <th
98
- ${inputs.attributePassthrough?.th
99
- ? attributes(inputs.attributePassthrough.th)
100
- : nothing}
101
- style=${ifDefined(inputs.stylePassthrough?.th)}
102
- >
103
- ${key.label}
104
- </th>
105
- ${cells}
106
- </tr>
107
- `;
108
- })
109
- : inputs.table.entries.map((entry) => {
110
- const cells = inputs.table.keys.map((key) => {
111
- if (key.hide) {
112
- return nothing;
113
- }
114
- const cellElement = key.isHeader ? 'th' : 'td';
115
- return html `
116
- <${cellElement}
117
- ${key.isHeader
118
- ? inputs.attributePassthrough?.th
119
- ? attributes(inputs.attributePassthrough.th)
120
- : nothing
121
- : inputs.attributePassthrough?.td
122
- ? attributes(inputs.attributePassthrough.td)
123
- : nothing}
124
- style=${key.isHeader
125
- ? ifDefined(inputs.stylePassthrough?.th)
126
- : ifDefined(inputs.stylePassthrough?.td)}
127
- >
128
- ${entry.cells[key.key]}
129
- </${cellElement}>
130
- `;
131
- });
132
- const isClickable = !!inputs.allowRowClicks && !entry.disabled;
133
- return html `
134
- <tr
135
- class=${classMap({
136
- clickable: isClickable,
137
- })}
138
- ${inputs.attributePassthrough?.tr
139
- ? attributes(inputs.attributePassthrough.tr)
140
- : nothing}
141
- style=${ifDefined(inputs.stylePassthrough?.tr)}
142
- ${listen('click', (event) => {
143
- if (isClickable) {
144
- dispatch(new events.rowClick({ originalEvent: event, entry: entry }));
145
- }
146
- })}
147
- >
148
- ${cells}
149
- </tr>
150
- `;
151
- });
152
- const headerCells = inputs.hideKeyHeaders || inputs.horizontalOrientation
153
- ? undefined
154
- : inputs.table.keys.map((key) => {
155
- if (key.hide) {
156
- return nothing;
157
- }
158
- return html `
159
- <th
160
- ${inputs.attributePassthrough?.th
161
- ? attributes(inputs.attributePassthrough.th)
162
- : nothing}
163
- style=${ifDefined(inputs.stylePassthrough?.th)}
164
- >
165
- ${key.label}
166
- </th>
167
- `;
168
- });
169
- const headerRow = headerCells
170
- ? html `
171
- <tr
172
- ${inputs.attributePassthrough?.tr
173
- ? attributes(inputs.attributePassthrough.tr)
174
- : nothing}
175
- style=${ifDefined(inputs.stylePassthrough?.tr)}
176
- >
177
- ${headerCells}
178
- </tr>
179
- `
180
- : undefined;
181
- const theadStyles = css `
182
- ${inputs.stylePassthrough?.thead || css ``}
183
- top: ${inputs.stickyOffset || 0}px;
184
- ${inputs.preventStickyHeader || inputs.hideKeyHeaders
185
- ? css ``
186
- : css `
187
- position: sticky;
188
- `}
189
- `;
190
- return html `
191
- <table
192
- ${inputs.attributePassthrough?.table
193
- ? attributes(inputs.attributePassthrough.table)
194
- : nothing}
195
- style=${ifDefined(inputs.stylePassthrough?.table)}
196
- >
197
- ${headerRow
198
- ? html `
199
- <thead
200
- ${inputs.attributePassthrough?.thead
201
- ? attributes(inputs.attributePassthrough.thead)
202
- : nothing}
203
- style=${theadStyles}
204
- >
205
- ${headerRow}
206
- </thead>
207
- `
208
- : nothing}
209
- <tbody
210
- ${inputs.attributePassthrough?.tbody
211
- ? attributes(inputs.attributePassthrough.tbody)
212
- : nothing}
213
- style=${ifDefined(inputs.stylePassthrough?.tbody)}
214
- >
215
- ${rowTemplates}
216
- </tbody>
217
- </table>
218
- `;
219
- },
220
- });