@aquera/nile-elements 2.0.2 → 2.0.3
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.
- package/README.md +3 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +949 -640
- package/dist/nile-segmented-progress-bar/index.cjs.js +2 -0
- package/dist/nile-segmented-progress-bar/index.cjs.js.map +1 -0
- package/dist/nile-segmented-progress-bar/index.esm.js +1 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.cjs.js +2 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.cjs.js.map +1 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.css.cjs.js +2 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.css.cjs.js.map +1 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.css.esm.js +243 -0
- package/dist/nile-segmented-progress-bar/nile-segmented-progress-bar.esm.js +69 -0
- package/dist/nile-wysiwyg-editor/engine/commands.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/engine/commands.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/engine/commands.esm.js +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/nile-segmented-progress-bar/index.d.ts +2 -0
- package/dist/src/nile-segmented-progress-bar/index.js +2 -0
- package/dist/src/nile-segmented-progress-bar/index.js.map +1 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.css.d.ts +9 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.css.js +252 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.css.js.map +1 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.d.ts +135 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.js +373 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.js.map +1 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.test.d.ts +1 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.test.js +961 -0
- package/dist/src/nile-segmented-progress-bar/nile-segmented-progress-bar.test.js.map +1 -0
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/index.ts +5 -0
- package/src/nile-segmented-progress-bar/index.ts +5 -0
- package/src/nile-segmented-progress-bar/nile-segmented-progress-bar.css.ts +254 -0
- package/src/nile-segmented-progress-bar/nile-segmented-progress-bar.test.ts +1298 -0
- package/src/nile-segmented-progress-bar/nile-segmented-progress-bar.ts +437 -0
- package/vscode-html-custom-data.json +113 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Aquera Inc 2026
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import NileElement from '../internal/nile-element';
|
|
8
|
+
import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
|
|
9
|
+
import '../nile-lite-tooltip/index';
|
|
10
|
+
/** A single slice of the distribution rendered by `nile-segmented-progress-bar`. */
|
|
11
|
+
export interface NileProgressSegment {
|
|
12
|
+
/** Legend label, also used in the default tooltip text. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Raw magnitude of this segment. */
|
|
15
|
+
value: number;
|
|
16
|
+
/** Any CSS color; falls back to the palette rotation when omitted. */
|
|
17
|
+
color?: string;
|
|
18
|
+
/** Overrides the default tooltip content for this segment. */
|
|
19
|
+
tooltip?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Placement values forwarded to `nile-lite-tooltip`. */
|
|
22
|
+
export type NileSegmentTooltipPlacement = 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'auto' | 'auto-start' | 'auto-end';
|
|
23
|
+
/**
|
|
24
|
+
* Nile segmented progress bar component.
|
|
25
|
+
*
|
|
26
|
+
* @tag nile-segmented-progress-bar
|
|
27
|
+
*
|
|
28
|
+
* @summary A config-driven, responsive multi-segment progress / distribution bar
|
|
29
|
+
* with an optional wrapping legend — a single rounded track split into colored
|
|
30
|
+
* proportional segments (for example Success / Failure / Errors / Running / Other).
|
|
31
|
+
* @status experimental
|
|
32
|
+
*
|
|
33
|
+
* @event nile-segment-click - Emitted when a segment or its legend entry is activated by click,
|
|
34
|
+
* `Enter` or `Space`. The `detail` contains `{ segment, index, percentage }`.
|
|
35
|
+
*
|
|
36
|
+
* @csspart container - The component's base wrapper.
|
|
37
|
+
* @csspart label - The optional heading above the bar.
|
|
38
|
+
* @csspart bar - The bar/track element (also exposed as `track`).
|
|
39
|
+
* @csspart track - The bar/track element (also exposed as `bar`).
|
|
40
|
+
* @csspart segment - An individual colored segment inside the track.
|
|
41
|
+
* @csspart legend - The wrapping legend row.
|
|
42
|
+
* @csspart legend-item - A single legend entry (swatch + label + value).
|
|
43
|
+
* @csspart legend-swatch - The small rounded square in the segment color.
|
|
44
|
+
* @csspart legend-label - The legend entry's label text.
|
|
45
|
+
* @csspart legend-value - The legend entry's bold value.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* <nile-segmented-progress-bar
|
|
49
|
+
* label="Run outcomes"
|
|
50
|
+
* .segments=${[
|
|
51
|
+
* { label: 'Success', value: 45623 },
|
|
52
|
+
* { label: 'Failure', value: 50342 },
|
|
53
|
+
* { label: 'Errors', value: 682 },
|
|
54
|
+
* { label: 'Running', value: 166 },
|
|
55
|
+
* { label: 'Other', value: 1552 },
|
|
56
|
+
* ]}
|
|
57
|
+
* ></nile-segmented-progress-bar>
|
|
58
|
+
*/
|
|
59
|
+
export declare class NileSegmentedProgressBar extends NileElement {
|
|
60
|
+
static styles: CSSResultGroup;
|
|
61
|
+
/** The segments to distribute across the bar. This is the component's config. */
|
|
62
|
+
segments: NileProgressSegment[];
|
|
63
|
+
/** Optional heading rendered above the bar. Nothing renders when empty. */
|
|
64
|
+
label: string;
|
|
65
|
+
/** Renders the legend below the bar. */
|
|
66
|
+
showLegend: boolean;
|
|
67
|
+
/** Wraps every segment in a `nile-lite-tooltip`. */
|
|
68
|
+
showTooltip: boolean;
|
|
69
|
+
/** Renders the bold value alongside each legend label. */
|
|
70
|
+
showValues: boolean;
|
|
71
|
+
/** The thickness of the bar. */
|
|
72
|
+
size: 'small' | 'medium' | 'large';
|
|
73
|
+
/**
|
|
74
|
+
* Optional denominator. When omitted the denominator is the sum of the segment
|
|
75
|
+
* values, so the segments always fill 100%. When larger than the sum, the
|
|
76
|
+
* remainder renders as an unfilled track.
|
|
77
|
+
*/
|
|
78
|
+
total?: number;
|
|
79
|
+
/** Rounds the bar's outer ends. */
|
|
80
|
+
rounded: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Minimum rendered width, in pixels, of a non-zero segment. Guarantees sub-1%
|
|
83
|
+
* segments stay a discernible sliver. The largest segment absorbs whatever
|
|
84
|
+
* overflow this introduces, so the row still totals exactly 100%.
|
|
85
|
+
*/
|
|
86
|
+
minSegmentWidth: number;
|
|
87
|
+
/** Passed straight through to `nile-lite-tooltip`'s `placement`. */
|
|
88
|
+
tooltipPlacement: NileSegmentTooltipPlacement;
|
|
89
|
+
/** Coerces a configured value into a usable, non-negative, finite number. */
|
|
90
|
+
private sanitizeValue;
|
|
91
|
+
/** The sanitized magnitude of every configured segment, in config order. */
|
|
92
|
+
private get values();
|
|
93
|
+
/** The sum of every sanitized segment value. */
|
|
94
|
+
private get sum();
|
|
95
|
+
/** The denominator the percentages are computed against. */
|
|
96
|
+
private get denominator();
|
|
97
|
+
/** Each segment's share of the denominator, in config order. */
|
|
98
|
+
private get percentages();
|
|
99
|
+
/**
|
|
100
|
+
* The index of the widest rendered segment. That segment is the one allowed to
|
|
101
|
+
* shrink, so it absorbs the overflow introduced by `minSegmentWidth` on the
|
|
102
|
+
* tiny ones and the row still adds up to exactly 100% of the track.
|
|
103
|
+
*/
|
|
104
|
+
private get largestIndex();
|
|
105
|
+
/** Formats a percentage to one decimal, trimming a trailing `.0`. */
|
|
106
|
+
private formatPercentage;
|
|
107
|
+
/** The default tooltip / aria text for a segment. */
|
|
108
|
+
private describeSegment;
|
|
109
|
+
/** The tooltip content for a segment, honouring a per-segment override. */
|
|
110
|
+
private tooltipFor;
|
|
111
|
+
/**
|
|
112
|
+
* A single sentence describing the whole distribution, used as the track's
|
|
113
|
+
* accessible name so screen readers get the breakdown without tabbing it.
|
|
114
|
+
*/
|
|
115
|
+
private get accessibleSummary();
|
|
116
|
+
updated(changedProperties: PropertyValues): void;
|
|
117
|
+
/** Logs invalid config the way `nile-progress-bar` reports out-of-range values. */
|
|
118
|
+
private validateConfig;
|
|
119
|
+
private activate;
|
|
120
|
+
/**
|
|
121
|
+
* `Enter` and `Space` activate a segment or legend entry. The affordances are
|
|
122
|
+
* `role="button"` elements rather than native buttons, so activation is wired
|
|
123
|
+
* up explicitly and a key press never double-fires alongside a synthetic click.
|
|
124
|
+
*/
|
|
125
|
+
private handleKeyDown;
|
|
126
|
+
private renderSegment;
|
|
127
|
+
private renderLegendItem;
|
|
128
|
+
render(): TemplateResult;
|
|
129
|
+
}
|
|
130
|
+
export default NileSegmentedProgressBar;
|
|
131
|
+
declare global {
|
|
132
|
+
interface HTMLElementTagNameMap {
|
|
133
|
+
'nile-segmented-progress-bar': NileSegmentedProgressBar;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Aquera Inc 2026
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the BSD-3-Clause license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { __decorate } from "tslib";
|
|
8
|
+
import { html, nothing } from 'lit';
|
|
9
|
+
import { styles } from './nile-segmented-progress-bar.css';
|
|
10
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
11
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
12
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
13
|
+
import NileElement from '../internal/nile-element';
|
|
14
|
+
import '../nile-lite-tooltip/index';
|
|
15
|
+
/** The number of palette classes declared in the stylesheet. */
|
|
16
|
+
const PALETTE_LENGTH = 10;
|
|
17
|
+
/**
|
|
18
|
+
* Nile segmented progress bar component.
|
|
19
|
+
*
|
|
20
|
+
* @tag nile-segmented-progress-bar
|
|
21
|
+
*
|
|
22
|
+
* @summary A config-driven, responsive multi-segment progress / distribution bar
|
|
23
|
+
* with an optional wrapping legend — a single rounded track split into colored
|
|
24
|
+
* proportional segments (for example Success / Failure / Errors / Running / Other).
|
|
25
|
+
* @status experimental
|
|
26
|
+
*
|
|
27
|
+
* @event nile-segment-click - Emitted when a segment or its legend entry is activated by click,
|
|
28
|
+
* `Enter` or `Space`. The `detail` contains `{ segment, index, percentage }`.
|
|
29
|
+
*
|
|
30
|
+
* @csspart container - The component's base wrapper.
|
|
31
|
+
* @csspart label - The optional heading above the bar.
|
|
32
|
+
* @csspart bar - The bar/track element (also exposed as `track`).
|
|
33
|
+
* @csspart track - The bar/track element (also exposed as `bar`).
|
|
34
|
+
* @csspart segment - An individual colored segment inside the track.
|
|
35
|
+
* @csspart legend - The wrapping legend row.
|
|
36
|
+
* @csspart legend-item - A single legend entry (swatch + label + value).
|
|
37
|
+
* @csspart legend-swatch - The small rounded square in the segment color.
|
|
38
|
+
* @csspart legend-label - The legend entry's label text.
|
|
39
|
+
* @csspart legend-value - The legend entry's bold value.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* <nile-segmented-progress-bar
|
|
43
|
+
* label="Run outcomes"
|
|
44
|
+
* .segments=${[
|
|
45
|
+
* { label: 'Success', value: 45623 },
|
|
46
|
+
* { label: 'Failure', value: 50342 },
|
|
47
|
+
* { label: 'Errors', value: 682 },
|
|
48
|
+
* { label: 'Running', value: 166 },
|
|
49
|
+
* { label: 'Other', value: 1552 },
|
|
50
|
+
* ]}
|
|
51
|
+
* ></nile-segmented-progress-bar>
|
|
52
|
+
*/
|
|
53
|
+
let NileSegmentedProgressBar = class NileSegmentedProgressBar extends NileElement {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
/** The segments to distribute across the bar. This is the component's config. */
|
|
57
|
+
this.segments = [];
|
|
58
|
+
/** Optional heading rendered above the bar. Nothing renders when empty. */
|
|
59
|
+
this.label = '';
|
|
60
|
+
/** Renders the legend below the bar. */
|
|
61
|
+
this.showLegend = true;
|
|
62
|
+
/** Wraps every segment in a `nile-lite-tooltip`. */
|
|
63
|
+
this.showTooltip = true;
|
|
64
|
+
/** Renders the bold value alongside each legend label. */
|
|
65
|
+
this.showValues = true;
|
|
66
|
+
/** The thickness of the bar. */
|
|
67
|
+
this.size = 'medium';
|
|
68
|
+
/** Rounds the bar's outer ends. */
|
|
69
|
+
this.rounded = true;
|
|
70
|
+
/**
|
|
71
|
+
* Minimum rendered width, in pixels, of a non-zero segment. Guarantees sub-1%
|
|
72
|
+
* segments stay a discernible sliver. The largest segment absorbs whatever
|
|
73
|
+
* overflow this introduces, so the row still totals exactly 100%.
|
|
74
|
+
*/
|
|
75
|
+
this.minSegmentWidth = 2;
|
|
76
|
+
/** Passed straight through to `nile-lite-tooltip`'s `placement`. */
|
|
77
|
+
this.tooltipPlacement = 'top';
|
|
78
|
+
/* #endregion */
|
|
79
|
+
}
|
|
80
|
+
/* #region Math */
|
|
81
|
+
/** Coerces a configured value into a usable, non-negative, finite number. */
|
|
82
|
+
sanitizeValue(value) {
|
|
83
|
+
const numeric = Number(value);
|
|
84
|
+
if (!Number.isFinite(numeric) || numeric < 0)
|
|
85
|
+
return 0;
|
|
86
|
+
return numeric;
|
|
87
|
+
}
|
|
88
|
+
/** The sanitized magnitude of every configured segment, in config order. */
|
|
89
|
+
get values() {
|
|
90
|
+
const list = Array.isArray(this.segments) ? this.segments : [];
|
|
91
|
+
return list.map(segment => this.sanitizeValue(segment?.value));
|
|
92
|
+
}
|
|
93
|
+
/** The sum of every sanitized segment value. */
|
|
94
|
+
get sum() {
|
|
95
|
+
return this.values.reduce((runningTotal, value) => runningTotal + value, 0);
|
|
96
|
+
}
|
|
97
|
+
/** The denominator the percentages are computed against. */
|
|
98
|
+
get denominator() {
|
|
99
|
+
const sum = this.sum;
|
|
100
|
+
const total = Number(this.total);
|
|
101
|
+
if (Number.isFinite(total) && total > sum)
|
|
102
|
+
return total;
|
|
103
|
+
return sum;
|
|
104
|
+
}
|
|
105
|
+
/** Each segment's share of the denominator, in config order. */
|
|
106
|
+
get percentages() {
|
|
107
|
+
const denominator = this.denominator;
|
|
108
|
+
if (denominator <= 0)
|
|
109
|
+
return this.values.map(() => 0);
|
|
110
|
+
return this.values.map(value => (value / denominator) * 100);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The index of the widest rendered segment. That segment is the one allowed to
|
|
114
|
+
* shrink, so it absorbs the overflow introduced by `minSegmentWidth` on the
|
|
115
|
+
* tiny ones and the row still adds up to exactly 100% of the track.
|
|
116
|
+
*/
|
|
117
|
+
get largestIndex() {
|
|
118
|
+
const values = this.values;
|
|
119
|
+
let largest = -1;
|
|
120
|
+
let largestValue = 0;
|
|
121
|
+
values.forEach((value, index) => {
|
|
122
|
+
if (value > largestValue) {
|
|
123
|
+
largestValue = value;
|
|
124
|
+
largest = index;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return largest;
|
|
128
|
+
}
|
|
129
|
+
/** Formats a percentage to one decimal, trimming a trailing `.0`. */
|
|
130
|
+
formatPercentage(percentage) {
|
|
131
|
+
if (!Number.isFinite(percentage))
|
|
132
|
+
return '0';
|
|
133
|
+
const rounded = Math.round(percentage * 10) / 10;
|
|
134
|
+
return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
|
|
135
|
+
}
|
|
136
|
+
/* #endregion */
|
|
137
|
+
/* #region Text */
|
|
138
|
+
/** The default tooltip / aria text for a segment. */
|
|
139
|
+
describeSegment(index) {
|
|
140
|
+
const segment = this.segments?.[index];
|
|
141
|
+
const value = this.values[index] ?? 0;
|
|
142
|
+
const percentage = this.formatPercentage(this.percentages[index] ?? 0);
|
|
143
|
+
return `${segment?.label ?? ''}: ${value} (${percentage}%)`;
|
|
144
|
+
}
|
|
145
|
+
/** The tooltip content for a segment, honouring a per-segment override. */
|
|
146
|
+
tooltipFor(index) {
|
|
147
|
+
const override = this.segments?.[index]?.tooltip;
|
|
148
|
+
return override && override.length > 0
|
|
149
|
+
? override
|
|
150
|
+
: this.describeSegment(index);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A single sentence describing the whole distribution, used as the track's
|
|
154
|
+
* accessible name so screen readers get the breakdown without tabbing it.
|
|
155
|
+
*/
|
|
156
|
+
get accessibleSummary() {
|
|
157
|
+
const list = Array.isArray(this.segments) ? this.segments : [];
|
|
158
|
+
const parts = list.map((_, index) => this.describeSegment(index));
|
|
159
|
+
const body = parts.length > 0 ? parts.join(', ') : 'No data';
|
|
160
|
+
return this.label ? `${this.label}: ${body}` : body;
|
|
161
|
+
}
|
|
162
|
+
/* #endregion */
|
|
163
|
+
/* #region Validation */
|
|
164
|
+
updated(changedProperties) {
|
|
165
|
+
super.updated(changedProperties);
|
|
166
|
+
if (changedProperties.has('segments') || changedProperties.has('total')) {
|
|
167
|
+
this.validateConfig();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** Logs invalid config the way `nile-progress-bar` reports out-of-range values. */
|
|
171
|
+
validateConfig() {
|
|
172
|
+
const list = Array.isArray(this.segments) ? this.segments : [];
|
|
173
|
+
list.forEach((segment, index) => {
|
|
174
|
+
const numeric = Number(segment?.value);
|
|
175
|
+
if (!Number.isFinite(numeric)) {
|
|
176
|
+
console.error(`[NileSegmentedProgressBar]: Invalid value (${String(segment?.value)}) detected at segment index ${index}. Value must be a finite number. Falling back to 0.`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (numeric < 0) {
|
|
180
|
+
console.error(`[NileSegmentedProgressBar]: Invalid value (${numeric}) detected at segment index ${index}. Value must be greater than or equal to 0. Falling back to 0.`);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
const total = Number(this.total);
|
|
184
|
+
if (this.total !== undefined && this.total !== null) {
|
|
185
|
+
if (!Number.isFinite(total) || total < 0) {
|
|
186
|
+
console.error(`[NileSegmentedProgressBar]: Invalid total (${String(this.total)}) detected. Total must be a finite number greater than or equal to 0. Falling back to the sum of the segment values.`);
|
|
187
|
+
}
|
|
188
|
+
else if (total < this.sum) {
|
|
189
|
+
console.error(`[NileSegmentedProgressBar]: Invalid total (${total}) detected. Total must be greater than or equal to the sum of the segment values (${this.sum}). Falling back to the sum.`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/* #endregion */
|
|
194
|
+
/* #region Interaction */
|
|
195
|
+
activate(index) {
|
|
196
|
+
const segment = this.segments?.[index];
|
|
197
|
+
if (!segment)
|
|
198
|
+
return;
|
|
199
|
+
this.emit('nile-segment-click', {
|
|
200
|
+
segment,
|
|
201
|
+
index,
|
|
202
|
+
percentage: this.percentages[index] ?? 0,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* `Enter` and `Space` activate a segment or legend entry. The affordances are
|
|
207
|
+
* `role="button"` elements rather than native buttons, so activation is wired
|
|
208
|
+
* up explicitly and a key press never double-fires alongside a synthetic click.
|
|
209
|
+
*/
|
|
210
|
+
handleKeyDown(event, index) {
|
|
211
|
+
if (event.key !== 'Enter' &&
|
|
212
|
+
event.key !== ' ' &&
|
|
213
|
+
event.key !== 'Spacebar') {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
this.activate(index);
|
|
218
|
+
}
|
|
219
|
+
/* #endregion */
|
|
220
|
+
/* #region Render */
|
|
221
|
+
renderSegment(index) {
|
|
222
|
+
const segment = this.segments[index];
|
|
223
|
+
const percentage = this.percentages[index] ?? 0;
|
|
224
|
+
if (percentage <= 0)
|
|
225
|
+
return nothing;
|
|
226
|
+
const isLargest = index === this.largestIndex;
|
|
227
|
+
const minWidth = Math.max(0, Number(this.minSegmentWidth) || 0);
|
|
228
|
+
const description = this.describeSegment(index);
|
|
229
|
+
const bar = html `
|
|
230
|
+
<div
|
|
231
|
+
part="segment"
|
|
232
|
+
role="button"
|
|
233
|
+
tabindex="0"
|
|
234
|
+
data-index=${index}
|
|
235
|
+
class=${classMap({
|
|
236
|
+
'segmented-progress-bar__segment': true,
|
|
237
|
+
[`segmented-progress-bar__palette-${index % PALETTE_LENGTH}`]: !segment.color,
|
|
238
|
+
})}
|
|
239
|
+
style=${styleMap({
|
|
240
|
+
flexBasis: `${percentage}%`,
|
|
241
|
+
// Only the widest segment may shrink, so it soaks up every pixel the
|
|
242
|
+
// min-width floors add to the row and the total stays at 100%.
|
|
243
|
+
flexShrink: isLargest ? '1' : '0',
|
|
244
|
+
minWidth: isLargest ? '0px' : `${minWidth}px`,
|
|
245
|
+
backgroundColor: segment.color || undefined,
|
|
246
|
+
})}
|
|
247
|
+
aria-label=${description}
|
|
248
|
+
@click=${() => this.activate(index)}
|
|
249
|
+
@keydown=${(event) => this.handleKeyDown(event, index)}
|
|
250
|
+
></div>
|
|
251
|
+
`;
|
|
252
|
+
if (!this.showTooltip)
|
|
253
|
+
return bar;
|
|
254
|
+
return html `
|
|
255
|
+
<nile-lite-tooltip
|
|
256
|
+
size="small"
|
|
257
|
+
content=${this.tooltipFor(index)}
|
|
258
|
+
placement=${this.tooltipPlacement}
|
|
259
|
+
>
|
|
260
|
+
${bar}
|
|
261
|
+
</nile-lite-tooltip>
|
|
262
|
+
`;
|
|
263
|
+
}
|
|
264
|
+
renderLegendItem(index) {
|
|
265
|
+
const segment = this.segments[index];
|
|
266
|
+
const value = this.values[index] ?? 0;
|
|
267
|
+
return html `
|
|
268
|
+
<div
|
|
269
|
+
part="legend-item"
|
|
270
|
+
role="button"
|
|
271
|
+
tabindex="0"
|
|
272
|
+
data-index=${index}
|
|
273
|
+
class="segmented-progress-bar__legend-item"
|
|
274
|
+
aria-label=${this.describeSegment(index)}
|
|
275
|
+
@click=${() => this.activate(index)}
|
|
276
|
+
@keydown=${(event) => this.handleKeyDown(event, index)}
|
|
277
|
+
>
|
|
278
|
+
<span
|
|
279
|
+
part="legend-swatch"
|
|
280
|
+
aria-hidden="true"
|
|
281
|
+
class=${classMap({
|
|
282
|
+
'segmented-progress-bar__legend-swatch': true,
|
|
283
|
+
[`segmented-progress-bar__palette-${index % PALETTE_LENGTH}`]: !segment.color,
|
|
284
|
+
})}
|
|
285
|
+
style=${styleMap({ backgroundColor: segment.color || undefined })}
|
|
286
|
+
></span>
|
|
287
|
+
<span part="legend-label" class="segmented-progress-bar__legend-label"
|
|
288
|
+
>${segment.label}</span
|
|
289
|
+
>
|
|
290
|
+
${this.showValues
|
|
291
|
+
? html `<span
|
|
292
|
+
part="legend-value"
|
|
293
|
+
class="segmented-progress-bar__legend-value"
|
|
294
|
+
>${value}</span
|
|
295
|
+
>`
|
|
296
|
+
: nothing}
|
|
297
|
+
</div>
|
|
298
|
+
`;
|
|
299
|
+
}
|
|
300
|
+
render() {
|
|
301
|
+
const segments = Array.isArray(this.segments) ? this.segments : [];
|
|
302
|
+
return html `
|
|
303
|
+
<div
|
|
304
|
+
part="container"
|
|
305
|
+
class=${classMap({
|
|
306
|
+
'segmented-progress-bar': true,
|
|
307
|
+
'segmented-progress-bar--small': this.size === 'small',
|
|
308
|
+
'segmented-progress-bar--medium': this.size === 'medium',
|
|
309
|
+
'segmented-progress-bar--large': this.size === 'large',
|
|
310
|
+
'segmented-progress-bar--rounded': this.rounded,
|
|
311
|
+
})}
|
|
312
|
+
>
|
|
313
|
+
${this.label
|
|
314
|
+
? html `<div part="label" class="segmented-progress-bar__label">
|
|
315
|
+
${this.label}
|
|
316
|
+
</div>`
|
|
317
|
+
: nothing}
|
|
318
|
+
|
|
319
|
+
<div
|
|
320
|
+
part="bar track"
|
|
321
|
+
class="segmented-progress-bar__track"
|
|
322
|
+
role="group"
|
|
323
|
+
aria-label=${this.accessibleSummary}
|
|
324
|
+
>
|
|
325
|
+
${segments.map((_, index) => this.renderSegment(index))}
|
|
326
|
+
</div>
|
|
327
|
+
|
|
328
|
+
${this.showLegend
|
|
329
|
+
? html `<div part="legend" class="segmented-progress-bar__legend">
|
|
330
|
+
${segments.map((_, index) => this.renderLegendItem(index))}
|
|
331
|
+
</div>`
|
|
332
|
+
: nothing}
|
|
333
|
+
</div>
|
|
334
|
+
`;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
NileSegmentedProgressBar.styles = styles;
|
|
338
|
+
__decorate([
|
|
339
|
+
property({ type: Array })
|
|
340
|
+
], NileSegmentedProgressBar.prototype, "segments", void 0);
|
|
341
|
+
__decorate([
|
|
342
|
+
property({ type: String, reflect: true })
|
|
343
|
+
], NileSegmentedProgressBar.prototype, "label", void 0);
|
|
344
|
+
__decorate([
|
|
345
|
+
property({ type: Boolean, attribute: 'show-legend' })
|
|
346
|
+
], NileSegmentedProgressBar.prototype, "showLegend", void 0);
|
|
347
|
+
__decorate([
|
|
348
|
+
property({ type: Boolean, attribute: 'show-tooltip' })
|
|
349
|
+
], NileSegmentedProgressBar.prototype, "showTooltip", void 0);
|
|
350
|
+
__decorate([
|
|
351
|
+
property({ type: Boolean, attribute: 'show-values' })
|
|
352
|
+
], NileSegmentedProgressBar.prototype, "showValues", void 0);
|
|
353
|
+
__decorate([
|
|
354
|
+
property({ reflect: true })
|
|
355
|
+
], NileSegmentedProgressBar.prototype, "size", void 0);
|
|
356
|
+
__decorate([
|
|
357
|
+
property({ type: Number })
|
|
358
|
+
], NileSegmentedProgressBar.prototype, "total", void 0);
|
|
359
|
+
__decorate([
|
|
360
|
+
property({ type: Boolean })
|
|
361
|
+
], NileSegmentedProgressBar.prototype, "rounded", void 0);
|
|
362
|
+
__decorate([
|
|
363
|
+
property({ type: Number, attribute: 'min-segment-width' })
|
|
364
|
+
], NileSegmentedProgressBar.prototype, "minSegmentWidth", void 0);
|
|
365
|
+
__decorate([
|
|
366
|
+
property({ attribute: 'tooltip-placement' })
|
|
367
|
+
], NileSegmentedProgressBar.prototype, "tooltipPlacement", void 0);
|
|
368
|
+
NileSegmentedProgressBar = __decorate([
|
|
369
|
+
customElement('nile-segmented-progress-bar')
|
|
370
|
+
], NileSegmentedProgressBar);
|
|
371
|
+
export { NileSegmentedProgressBar };
|
|
372
|
+
export default NileSegmentedProgressBar;
|
|
373
|
+
//# sourceMappingURL=nile-segmented-progress-bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nile-segmented-progress-bar.js","sourceRoot":"","sources":["../../../src/nile-segmented-progress-bar/nile-segmented-progress-bar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AAEnD,OAAO,4BAA4B,CAAC;AAgCpC,gEAAgE;AAChE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,WAAW;IAAlD;;QAGL,iFAAiF;QACtD,aAAQ,GAA0B,EAAE,CAAC;QAEh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S;AAzC3C,wBAAwB;IADpC,aAAa,CAAC,6BAA6B,CAAC;GAChC,wBAAwB,CAsVpC;;AAED,eAAe,wBAAwB,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2026\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { html, nothing } from 'lit';\nimport { styles } from './nile-segmented-progress-bar.css';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { customElement, property } from 'lit/decorators.js';\nimport NileElement from '../internal/nile-element';\nimport type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';\nimport '../nile-lite-tooltip/index';\n\n/** A single slice of the distribution rendered by `nile-segmented-progress-bar`. */\nexport interface NileProgressSegment {\n /** Legend label, also used in the default tooltip text. */\n label: string;\n /** Raw magnitude of this segment. */\n value: number;\n /** Any CSS color; falls back to the palette rotation when omitted. */\n color?: string;\n /** Overrides the default tooltip content for this segment. */\n tooltip?: string;\n}\n\n/** Placement values forwarded to `nile-lite-tooltip`. */\nexport type NileSegmentTooltipPlacement =\n | 'top'\n | 'top-start'\n | 'top-end'\n | 'right'\n | 'right-start'\n | 'right-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n | 'left'\n | 'left-start'\n | 'left-end'\n | 'auto'\n | 'auto-start'\n | 'auto-end';\n\n/** The number of palette classes declared in the stylesheet. */\nconst PALETTE_LENGTH = 10;\n\n/**\n * Nile segmented progress bar component.\n *\n * @tag nile-segmented-progress-bar\n *\n * @summary A config-driven, responsive multi-segment progress / distribution bar\n * with an optional wrapping legend — a single rounded track split into colored\n * proportional segments (for example Success / Failure / Errors / Running / Other).\n * @status experimental\n *\n * @event nile-segment-click - Emitted when a segment or its legend entry is activated by click,\n * `Enter` or `Space`. The `detail` contains `{ segment, index, percentage }`.\n *\n * @csspart container - The component's base wrapper.\n * @csspart label - The optional heading above the bar.\n * @csspart bar - The bar/track element (also exposed as `track`).\n * @csspart track - The bar/track element (also exposed as `bar`).\n * @csspart segment - An individual colored segment inside the track.\n * @csspart legend - The wrapping legend row.\n * @csspart legend-item - A single legend entry (swatch + label + value).\n * @csspart legend-swatch - The small rounded square in the segment color.\n * @csspart legend-label - The legend entry's label text.\n * @csspart legend-value - The legend entry's bold value.\n *\n * @example\n * <nile-segmented-progress-bar\n * label=\"Run outcomes\"\n * .segments=${[\n * { label: 'Success', value: 45623 },\n * { label: 'Failure', value: 50342 },\n * { label: 'Errors', value: 682 },\n * { label: 'Running', value: 166 },\n * { label: 'Other', value: 1552 },\n * ]}\n * ></nile-segmented-progress-bar>\n */\n@customElement('nile-segmented-progress-bar')\nexport class NileSegmentedProgressBar extends NileElement {\n static styles: CSSResultGroup = styles;\n\n /** The segments to distribute across the bar. This is the component's config. */\n @property({ type: Array }) segments: NileProgressSegment[] = [];\n\n /** Optional heading rendered above the bar. Nothing renders when empty. */\n @property({ type: String, reflect: true }) label = '';\n\n /** Renders the legend below the bar. */\n @property({ type: Boolean, attribute: 'show-legend' }) showLegend = true;\n\n /** Wraps every segment in a `nile-lite-tooltip`. */\n @property({ type: Boolean, attribute: 'show-tooltip' }) showTooltip = true;\n\n /** Renders the bold value alongside each legend label. */\n @property({ type: Boolean, attribute: 'show-values' }) showValues = true;\n\n /** The thickness of the bar. */\n @property({ reflect: true }) size: 'small' | 'medium' | 'large' = 'medium';\n\n /**\n * Optional denominator. When omitted the denominator is the sum of the segment\n * values, so the segments always fill 100%. When larger than the sum, the\n * remainder renders as an unfilled track.\n */\n @property({ type: Number }) total?: number;\n\n /** Rounds the bar's outer ends. */\n @property({ type: Boolean }) rounded = true;\n\n /**\n * Minimum rendered width, in pixels, of a non-zero segment. Guarantees sub-1%\n * segments stay a discernible sliver. The largest segment absorbs whatever\n * overflow this introduces, so the row still totals exactly 100%.\n */\n @property({ type: Number, attribute: 'min-segment-width' })\n minSegmentWidth = 2;\n\n /** Passed straight through to `nile-lite-tooltip`'s `placement`. */\n @property({ attribute: 'tooltip-placement' })\n tooltipPlacement: NileSegmentTooltipPlacement = 'top';\n\n /* #region Math */\n\n /** Coerces a configured value into a usable, non-negative, finite number. */\n private sanitizeValue(value: unknown): number {\n const numeric = Number(value);\n if (!Number.isFinite(numeric) || numeric < 0) return 0;\n return numeric;\n }\n\n /** The sanitized magnitude of every configured segment, in config order. */\n private get values(): number[] {\n const list = Array.isArray(this.segments) ? this.segments : [];\n return list.map(segment => this.sanitizeValue(segment?.value));\n }\n\n /** The sum of every sanitized segment value. */\n private get sum(): number {\n return this.values.reduce((runningTotal, value) => runningTotal + value, 0);\n }\n\n /** The denominator the percentages are computed against. */\n private get denominator(): number {\n const sum = this.sum;\n const total = Number(this.total);\n if (Number.isFinite(total) && total > sum) return total;\n return sum;\n }\n\n /** Each segment's share of the denominator, in config order. */\n private get percentages(): number[] {\n const denominator = this.denominator;\n if (denominator <= 0) return this.values.map(() => 0);\n return this.values.map(value => (value / denominator) * 100);\n }\n\n /**\n * The index of the widest rendered segment. That segment is the one allowed to\n * shrink, so it absorbs the overflow introduced by `minSegmentWidth` on the\n * tiny ones and the row still adds up to exactly 100% of the track.\n */\n private get largestIndex(): number {\n const values = this.values;\n let largest = -1;\n let largestValue = 0;\n values.forEach((value, index) => {\n if (value > largestValue) {\n largestValue = value;\n largest = index;\n }\n });\n return largest;\n }\n\n /** Formats a percentage to one decimal, trimming a trailing `.0`. */\n private formatPercentage(percentage: number): string {\n if (!Number.isFinite(percentage)) return '0';\n const rounded = Math.round(percentage * 10) / 10;\n return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);\n }\n\n /* #endregion */\n\n /* #region Text */\n\n /** The default tooltip / aria text for a segment. */\n private describeSegment(index: number): string {\n const segment = this.segments?.[index];\n const value = this.values[index] ?? 0;\n const percentage = this.formatPercentage(this.percentages[index] ?? 0);\n return `${segment?.label ?? ''}: ${value} (${percentage}%)`;\n }\n\n /** The tooltip content for a segment, honouring a per-segment override. */\n private tooltipFor(index: number): string {\n const override = this.segments?.[index]?.tooltip;\n return override && override.length > 0\n ? override\n : this.describeSegment(index);\n }\n\n /**\n * A single sentence describing the whole distribution, used as the track's\n * accessible name so screen readers get the breakdown without tabbing it.\n */\n private get accessibleSummary(): string {\n const list = Array.isArray(this.segments) ? this.segments : [];\n const parts = list.map((_, index) => this.describeSegment(index));\n const body = parts.length > 0 ? parts.join(', ') : 'No data';\n return this.label ? `${this.label}: ${body}` : body;\n }\n\n /* #endregion */\n\n /* #region Validation */\n\n override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n if (changedProperties.has('segments') || changedProperties.has('total')) {\n this.validateConfig();\n }\n }\n\n /** Logs invalid config the way `nile-progress-bar` reports out-of-range values. */\n private validateConfig(): void {\n const list = Array.isArray(this.segments) ? this.segments : [];\n\n list.forEach((segment, index) => {\n const numeric = Number(segment?.value);\n if (!Number.isFinite(numeric)) {\n console.error(\n `[NileSegmentedProgressBar]: Invalid value (${String(\n segment?.value\n )}) detected at segment index ${index}. Value must be a finite number. Falling back to 0.`\n );\n return;\n }\n if (numeric < 0) {\n console.error(\n `[NileSegmentedProgressBar]: Invalid value (${numeric}) detected at segment index ${index}. Value must be greater than or equal to 0. Falling back to 0.`\n );\n }\n });\n\n const total = Number(this.total);\n if (this.total !== undefined && this.total !== null) {\n if (!Number.isFinite(total) || total < 0) {\n console.error(\n `[NileSegmentedProgressBar]: Invalid total (${String(\n this.total\n )}) detected. Total must be a finite number greater than or equal to 0. Falling back to the sum of the segment values.`\n );\n } else if (total < this.sum) {\n console.error(\n `[NileSegmentedProgressBar]: Invalid total (${total}) detected. Total must be greater than or equal to the sum of the segment values (${this.sum}). Falling back to the sum.`\n );\n }\n }\n }\n\n /* #endregion */\n\n /* #region Interaction */\n\n private activate(index: number): void {\n const segment = this.segments?.[index];\n if (!segment) return;\n this.emit('nile-segment-click', {\n segment,\n index,\n percentage: this.percentages[index] ?? 0,\n });\n }\n\n /**\n * `Enter` and `Space` activate a segment or legend entry. The affordances are\n * `role=\"button\"` elements rather than native buttons, so activation is wired\n * up explicitly and a key press never double-fires alongside a synthetic click.\n */\n private handleKeyDown(event: KeyboardEvent, index: number): void {\n if (\n event.key !== 'Enter' &&\n event.key !== ' ' &&\n event.key !== 'Spacebar'\n ) {\n return;\n }\n event.preventDefault();\n this.activate(index);\n }\n\n /* #endregion */\n\n /* #region Render */\n\n private renderSegment(index: number): TemplateResult | typeof nothing {\n const segment = this.segments[index];\n const percentage = this.percentages[index] ?? 0;\n if (percentage <= 0) return nothing;\n\n const isLargest = index === this.largestIndex;\n const minWidth = Math.max(0, Number(this.minSegmentWidth) || 0);\n const description = this.describeSegment(index);\n\n const bar = html`\n <div\n part=\"segment\"\n role=\"button\"\n tabindex=\"0\"\n data-index=${index}\n class=${classMap({\n 'segmented-progress-bar__segment': true,\n [`segmented-progress-bar__palette-${index % PALETTE_LENGTH}`]:\n !segment.color,\n })}\n style=${styleMap({\n flexBasis: `${percentage}%`,\n // Only the widest segment may shrink, so it soaks up every pixel the\n // min-width floors add to the row and the total stays at 100%.\n flexShrink: isLargest ? '1' : '0',\n minWidth: isLargest ? '0px' : `${minWidth}px`,\n backgroundColor: segment.color || undefined,\n })}\n aria-label=${description}\n @click=${() => this.activate(index)}\n @keydown=${(event: KeyboardEvent) => this.handleKeyDown(event, index)}\n ></div>\n `;\n\n if (!this.showTooltip) return bar;\n\n return html`\n <nile-lite-tooltip\n size=\"small\"\n content=${this.tooltipFor(index)}\n placement=${this.tooltipPlacement}\n >\n ${bar}\n </nile-lite-tooltip>\n `;\n }\n\n private renderLegendItem(index: number): TemplateResult {\n const segment = this.segments[index];\n const value = this.values[index] ?? 0;\n\n return html`\n <div\n part=\"legend-item\"\n role=\"button\"\n tabindex=\"0\"\n data-index=${index}\n class=\"segmented-progress-bar__legend-item\"\n aria-label=${this.describeSegment(index)}\n @click=${() => this.activate(index)}\n @keydown=${(event: KeyboardEvent) => this.handleKeyDown(event, index)}\n >\n <span\n part=\"legend-swatch\"\n aria-hidden=\"true\"\n class=${classMap({\n 'segmented-progress-bar__legend-swatch': true,\n [`segmented-progress-bar__palette-${index % PALETTE_LENGTH}`]:\n !segment.color,\n })}\n style=${styleMap({ backgroundColor: segment.color || undefined })}\n ></span>\n <span part=\"legend-label\" class=\"segmented-progress-bar__legend-label\"\n >${segment.label}</span\n >\n ${this.showValues\n ? html`<span\n part=\"legend-value\"\n class=\"segmented-progress-bar__legend-value\"\n >${value}</span\n >`\n : nothing}\n </div>\n `;\n }\n\n render(): TemplateResult {\n const segments = Array.isArray(this.segments) ? this.segments : [];\n\n return html`\n <div\n part=\"container\"\n class=${classMap({\n 'segmented-progress-bar': true,\n 'segmented-progress-bar--small': this.size === 'small',\n 'segmented-progress-bar--medium': this.size === 'medium',\n 'segmented-progress-bar--large': this.size === 'large',\n 'segmented-progress-bar--rounded': this.rounded,\n })}\n >\n ${this.label\n ? html`<div part=\"label\" class=\"segmented-progress-bar__label\">\n ${this.label}\n </div>`\n : nothing}\n\n <div\n part=\"bar track\"\n class=\"segmented-progress-bar__track\"\n role=\"group\"\n aria-label=${this.accessibleSummary}\n >\n ${segments.map((_, index) => this.renderSegment(index))}\n </div>\n\n ${this.showLegend\n ? html`<div part=\"legend\" class=\"segmented-progress-bar__legend\">\n ${segments.map((_, index) => this.renderLegendItem(index))}\n </div>`\n : nothing}\n </div>\n `;\n }\n\n /* #endregion */\n}\n\nexport default NileSegmentedProgressBar;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-segmented-progress-bar': NileSegmentedProgressBar;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './nile-segmented-progress-bar';
|