@oicl/openbridge-webcomponents-full-bundle 2.1.0-next.1 → 2.1.0-next.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/.storybook/main.ts +2 -0
- package/bundle/openbridge-webcomponents.bundle.js +390 -301
- package/bundle/openbridge-webcomponents.bundle.js.map +1 -1
- package/custom-elements.json +1066 -102
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.d.ts +21 -0
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.d.ts.map +1 -1
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.js +39 -58
- package/dist/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.js.map +1 -1
- package/dist/building-blocks/alert-list/alert-list-base.d.ts +60 -0
- package/dist/building-blocks/alert-list/alert-list-base.d.ts.map +1 -0
- package/dist/building-blocks/alert-list/alert-list-base.js +191 -0
- package/dist/building-blocks/alert-list/alert-list-base.js.map +1 -0
- package/dist/building-blocks/alert-list/alert-list.css.js.map +1 -1
- package/dist/building-blocks/alert-list/alert-list.d.ts +13 -26
- package/dist/building-blocks/alert-list/alert-list.d.ts.map +1 -1
- package/dist/building-blocks/alert-list/alert-list.js +7 -142
- package/dist/building-blocks/alert-list/alert-list.js.map +1 -1
- package/dist/components/alert-icon/alert-icon.d.ts.map +1 -1
- package/dist/components/alert-icon/alert-icon.js +6 -5
- package/dist/components/alert-icon/alert-icon.js.map +1 -1
- package/dist/components/alert-list-details/alert-list-details.css.js +4 -1
- package/dist/components/alert-list-details/alert-list-details.css.js.map +1 -1
- package/dist/components/alert-menu/alert-menu.css.js +3 -42
- package/dist/components/alert-menu/alert-menu.css.js.map +1 -1
- package/dist/components/alert-menu/alert-menu.d.ts +28 -6
- package/dist/components/alert-menu/alert-menu.d.ts.map +1 -1
- package/dist/components/alert-menu/alert-menu.js +81 -60
- package/dist/components/alert-menu/alert-menu.js.map +1 -1
- package/dist/components/alert-menu-item/alert-menu-item.d.ts +16 -6
- package/dist/components/alert-menu-item/alert-menu-item.d.ts.map +1 -1
- package/dist/components/alert-menu-item/alert-menu-item.js +11 -2
- package/dist/components/alert-menu-item/alert-menu-item.js.map +1 -1
- package/dist/components/number-input-field/number-input-field.css.js +8 -2
- package/dist/components/number-input-field/number-input-field.css.js.map +1 -1
- package/dist/components/number-input-field/number-input-field.d.ts +15 -1
- package/dist/components/number-input-field/number-input-field.d.ts.map +1 -1
- package/dist/components/number-input-field/number-input-field.js +38 -44
- package/dist/components/number-input-field/number-input-field.js.map +1 -1
- package/dist/components/textbox/textbox.css.js +3 -9
- package/dist/components/textbox/textbox.css.js.map +1 -1
- package/dist/components/textbox/textbox.d.ts +3 -0
- package/dist/components/textbox/textbox.d.ts.map +1 -1
- package/dist/components/textbox/textbox.js.map +1 -1
- package/dist/generated/locales/es-419.d.ts +1 -1
- package/dist/generated/locales/es-419.js +1 -1
- package/dist/generated/locales/es-419.js.map +1 -1
- package/dist/navigation-instruments/readout-list-item/readout-list-item.css.js +2 -1
- package/dist/navigation-instruments/readout-list-item/readout-list-item.css.js.map +1 -1
- package/dist/pages/alert-detail-page/alert-detail-page.js +1 -1
- package/dist/pages/alert-detail-page/alert-detail-page.js.map +1 -1
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.d.ts +59 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.d.ts.map +1 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.js +126 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small-base.js.map +1 -0
- package/dist/pages/alert-list-page-small/alert-list-page-small.d.ts +12 -15
- package/dist/pages/alert-list-page-small/alert-list-page-small.d.ts.map +1 -1
- package/dist/pages/alert-list-page-small/alert-list-page-small.js +41 -92
- package/dist/pages/alert-list-page-small/alert-list-page-small.js.map +1 -1
- package/docs/GettingStarted.mdx +1 -0
- package/docs/MigrationGuide.mdx +2 -0
- package/package.json +1 -1
- package/src/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.stories.ts +63 -0
- package/src/automation/valve-analoge-two-way-icon/valve-analog-two-way-icon.ts +58 -60
- package/src/building-blocks/alert-list/alert-list-base.ts +266 -0
- package/src/building-blocks/alert-list/alert-list.css +1 -23
- package/src/building-blocks/alert-list/alert-list.spec.ts +22 -0
- package/src/building-blocks/alert-list/alert-list.ts +15 -207
- package/src/components/alert-icon/alert-icon.spec.ts +39 -0
- package/src/components/alert-icon/alert-icon.ts +11 -7
- package/src/components/alert-list-details/alert-list-details.css +1 -20
- package/src/components/alert-menu/alert-menu.css +5 -28
- package/src/components/alert-menu/alert-menu.spec.ts +113 -0
- package/src/components/alert-menu/alert-menu.ts +142 -79
- package/src/components/alert-menu-item/alert-menu-item.spec.ts +39 -0
- package/src/components/alert-menu-item/alert-menu-item.stories.ts +22 -0
- package/src/components/alert-menu-item/alert-menu-item.ts +22 -6
- package/src/components/number-input-field/number-input-field.css +8 -2
- package/src/components/number-input-field/number-input-field.spec.ts +260 -2
- package/src/components/number-input-field/number-input-field.stories.ts +74 -0
- package/src/components/number-input-field/number-input-field.ts +45 -74
- package/src/components/textbox/textbox.css +3 -9
- package/src/components/textbox/textbox.stories.ts +24 -0
- package/src/components/textbox/textbox.ts +3 -0
- package/src/generated/locales/es-419.ts +1 -1
- package/src/mixins/alert-list-empty.css +32 -0
- package/src/navigation-instruments/readout-list-item/readout-list-item.css +2 -1
- package/src/pages/alert-detail-page/alert-detail-page.spec.ts +41 -0
- package/src/pages/alert-detail-page/alert-detail-page.ts +1 -1
- package/src/pages/alert-list-page-small/alert-list-page-small-base.ts +152 -0
- package/src/pages/alert-list-page-small/alert-list-page-small.spec.ts +84 -0
- package/src/pages/alert-list-page-small/alert-list-page-small.ts +43 -112
|
@@ -1,9 +1,56 @@
|
|
|
1
|
-
import {describe, it, expect, beforeEach, vi} from 'vitest';
|
|
1
|
+
import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
|
|
2
|
+
import {userEvent} from '@vitest/browser/context';
|
|
3
|
+
import '../../main.css';
|
|
2
4
|
import './number-input-field.js';
|
|
3
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ObcNumberInputField,
|
|
7
|
+
ObcNumberInputFieldChangeEvent,
|
|
8
|
+
ObcNumberInputFieldTextAlign,
|
|
9
|
+
} from './number-input-field.js';
|
|
4
10
|
import {render} from 'vitest-browser-lit';
|
|
5
11
|
import {html} from 'lit';
|
|
6
12
|
|
|
13
|
+
const FONT_PROPS = [
|
|
14
|
+
'fontFamily',
|
|
15
|
+
'fontSize',
|
|
16
|
+
'fontWeight',
|
|
17
|
+
'fontStyle',
|
|
18
|
+
'fontStretch',
|
|
19
|
+
'fontFeatureSettings',
|
|
20
|
+
'fontVariantNumeric',
|
|
21
|
+
'fontVariationSettings',
|
|
22
|
+
'fontKerning',
|
|
23
|
+
'letterSpacing',
|
|
24
|
+
'wordSpacing',
|
|
25
|
+
'textTransform',
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Cumulative advance of `text` after each of its characters, measured on a
|
|
30
|
+
* mirror span carrying `reference`'s computed font, so a test can aim a click
|
|
31
|
+
* at a character or check a width without guessing glyph metrics.
|
|
32
|
+
*/
|
|
33
|
+
function textAdvances(reference: Element, text: string): number[] {
|
|
34
|
+
if (!text) return [0];
|
|
35
|
+
const font = getComputedStyle(reference);
|
|
36
|
+
const mirror = document.createElement('span');
|
|
37
|
+
for (const prop of FONT_PROPS) mirror.style[prop] = font[prop];
|
|
38
|
+
mirror.style.position = 'absolute';
|
|
39
|
+
mirror.style.visibility = 'hidden';
|
|
40
|
+
mirror.style.whiteSpace = 'pre';
|
|
41
|
+
mirror.textContent = text;
|
|
42
|
+
document.body.appendChild(mirror);
|
|
43
|
+
const node = mirror.firstChild as Text;
|
|
44
|
+
const range = document.createRange();
|
|
45
|
+
const advances = Array.from({length: text.length + 1}, (_, end) => {
|
|
46
|
+
range.setStart(node, 0);
|
|
47
|
+
range.setEnd(node, end);
|
|
48
|
+
return range.getBoundingClientRect().width;
|
|
49
|
+
});
|
|
50
|
+
mirror.remove();
|
|
51
|
+
return advances;
|
|
52
|
+
}
|
|
53
|
+
|
|
7
54
|
describe('obc-number-input-field', () => {
|
|
8
55
|
let el: ObcNumberInputField;
|
|
9
56
|
let input: HTMLInputElement;
|
|
@@ -389,4 +436,215 @@ describe('obc-number-input-field', () => {
|
|
|
389
436
|
expect(el.value).toBe(1234.5);
|
|
390
437
|
});
|
|
391
438
|
});
|
|
439
|
+
describe('caret placement', () => {
|
|
440
|
+
const query = <T extends Element>(selector: string): T =>
|
|
441
|
+
el.shadowRoot!.querySelector(selector) as T;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Focusing reformats the value in a follow-up render, a frame later when
|
|
445
|
+
* the focus came from a click on the value.
|
|
446
|
+
*/
|
|
447
|
+
const settle = async () => {
|
|
448
|
+
await new Promise(requestAnimationFrame);
|
|
449
|
+
await el.updateComplete;
|
|
450
|
+
await el.updateComplete;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A real click `fraction` of the way into character `index`, so the
|
|
455
|
+
* nearest caret boundary is `index` below a half and `index + 1` above.
|
|
456
|
+
* The text is right-aligned and unpadded, so its last boundary is the
|
|
457
|
+
* input's right edge.
|
|
458
|
+
*/
|
|
459
|
+
const clickIntoChar = async (index: number, fraction = 1 / 4) => {
|
|
460
|
+
const box = input.getBoundingClientRect();
|
|
461
|
+
const advances = textAdvances(input, input.value);
|
|
462
|
+
const textLeft = box.right - advances[advances.length - 1];
|
|
463
|
+
const from = textLeft + advances[index];
|
|
464
|
+
const to = textLeft + advances[index + 1];
|
|
465
|
+
await userEvent.click(input, {
|
|
466
|
+
position: {
|
|
467
|
+
x: from + (to - from) * fraction - box.left,
|
|
468
|
+
y: box.height / 2,
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
await settle();
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
beforeEach(async () => {
|
|
475
|
+
// A fixed-width inline-block host keeps the label above the value, so
|
|
476
|
+
// the geometry is the same in every run.
|
|
477
|
+
document.body.classList.add('obc-component-size-regular');
|
|
478
|
+
el.style.cssText = 'display:inline-block;width:320px;';
|
|
479
|
+
el.label = 'SV';
|
|
480
|
+
el.unit = 'm/s';
|
|
481
|
+
el.groupSeparator = '';
|
|
482
|
+
el.decimalSeparator = '.';
|
|
483
|
+
el.value = 1234567.89;
|
|
484
|
+
await document.fonts.ready;
|
|
485
|
+
await settle();
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
afterEach(() => {
|
|
489
|
+
document.documentElement.style.removeProperty('zoom');
|
|
490
|
+
document.body.classList.remove('obc-component-size-regular');
|
|
491
|
+
document.body.classList.remove('obc-component-size-large');
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('lands on the clicked character', async () => {
|
|
495
|
+
const landed: number[] = [];
|
|
496
|
+
for (const index of [0, 4, 9]) {
|
|
497
|
+
await clickIntoChar(index);
|
|
498
|
+
landed.push(input.selectionStart ?? -1);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
expect(input.value).toBe('1234567.89');
|
|
502
|
+
expect(landed).toEqual([0, 4, 9]);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
for (const zoom of [0.75, 1.25]) {
|
|
506
|
+
it(`lands on the clicked character under CSS zoom ${zoom}`, async () => {
|
|
507
|
+
document.documentElement.style.zoom = String(zoom);
|
|
508
|
+
|
|
509
|
+
await clickIntoChar(4);
|
|
510
|
+
|
|
511
|
+
expect(input.selectionStart).toBe(4);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
it('lands on the clicked character in the large size class', async () => {
|
|
516
|
+
document.body.classList.replace(
|
|
517
|
+
'obc-component-size-regular',
|
|
518
|
+
'obc-component-size-large'
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
await clickIntoChar(4);
|
|
522
|
+
|
|
523
|
+
expect(input.selectionStart).toBe(4);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
for (const textAlign of [
|
|
527
|
+
ObcNumberInputFieldTextAlign.Right,
|
|
528
|
+
ObcNumberInputFieldTextAlign.Center,
|
|
529
|
+
]) {
|
|
530
|
+
it(`keeps the clicked character through the ungrouping that focus applies (${textAlign})`, async () => {
|
|
531
|
+
el.textAlign = textAlign;
|
|
532
|
+
el.groupSeparator = ',';
|
|
533
|
+
await settle();
|
|
534
|
+
const grouped = input.value;
|
|
535
|
+
expect(grouped).toBe('1,234,567.89');
|
|
536
|
+
|
|
537
|
+
const missed: string[] = [];
|
|
538
|
+
for (let index = 0; index < grouped.length; index++) {
|
|
539
|
+
for (const fraction of [1 / 4, 3 / 4]) {
|
|
540
|
+
input.blur();
|
|
541
|
+
await settle();
|
|
542
|
+
await clickIntoChar(index, fraction);
|
|
543
|
+
const boundary = index + (fraction > 1 / 2 ? 1 : 0);
|
|
544
|
+
const expected = grouped.slice(0, boundary).replaceAll(',', '');
|
|
545
|
+
if (input.selectionStart !== expected.length) {
|
|
546
|
+
missed.push(`${boundary} → ${input.selectionStart}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
expect(input.value).toBe('1234567.89');
|
|
552
|
+
expect(missed).toEqual([]);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
it('keeps focus and the unfinished edit when the unit is clicked mid-edit', async () => {
|
|
557
|
+
const changes: number[] = [];
|
|
558
|
+
el.addEventListener('change', (e) =>
|
|
559
|
+
changes.push((e as ObcNumberInputFieldChangeEvent).detail.value)
|
|
560
|
+
);
|
|
561
|
+
el.value = 12;
|
|
562
|
+
await settle();
|
|
563
|
+
await userEvent.click(input);
|
|
564
|
+
await userEvent.keyboard('{End}.');
|
|
565
|
+
await settle();
|
|
566
|
+
expect(input.value).toBe('12.');
|
|
567
|
+
|
|
568
|
+
await userEvent.click(query('.unit-text'));
|
|
569
|
+
await settle();
|
|
570
|
+
|
|
571
|
+
expect(el.shadowRoot!.activeElement).toBe(input);
|
|
572
|
+
expect(input.value).toBe('12.');
|
|
573
|
+
expect(changes).toEqual([]);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it('focuses the input when the label is clicked', async () => {
|
|
577
|
+
await userEvent.click(query('.label-text'));
|
|
578
|
+
await settle();
|
|
579
|
+
|
|
580
|
+
expect(el.shadowRoot!.activeElement).toBe(input);
|
|
581
|
+
expect(input.selectionStart).toBe(input.value.length);
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('leaves a disabled field unfocused when its unit is clicked', async () => {
|
|
585
|
+
el.disabled = true;
|
|
586
|
+
await settle();
|
|
587
|
+
|
|
588
|
+
// Playwright follows the label to its disabled control and would wait.
|
|
589
|
+
await userEvent.click(query('.unit-text'), {force: true});
|
|
590
|
+
await settle();
|
|
591
|
+
|
|
592
|
+
expect(el.shadowRoot!.activeElement).toBeNull();
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it('is reached with Tab', async () => {
|
|
596
|
+
await userEvent.tab();
|
|
597
|
+
|
|
598
|
+
expect(el.shadowRoot!.activeElement).toBe(input);
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
describe('center-aligned width', () => {
|
|
603
|
+
const settle = async () => {
|
|
604
|
+
await el.updateComplete;
|
|
605
|
+
await el.updateComplete;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
beforeEach(async () => {
|
|
609
|
+
document.body.classList.add('obc-component-size-regular');
|
|
610
|
+
el.style.cssText = 'display:inline-block;width:320px;';
|
|
611
|
+
el.textAlign = ObcNumberInputFieldTextAlign.Center;
|
|
612
|
+
el.unit = 'm/s';
|
|
613
|
+
await document.fonts.ready;
|
|
614
|
+
await settle();
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
afterEach(() => {
|
|
618
|
+
document.body.classList.remove('obc-component-size-regular');
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('follows the value in the font it is rendered with', async () => {
|
|
622
|
+
el.style.setProperty('--global-typography-font-family', 'serif');
|
|
623
|
+
el.value = 1234567.89;
|
|
624
|
+
await settle();
|
|
625
|
+
|
|
626
|
+
const advances = textAdvances(input, input.value);
|
|
627
|
+
const width = advances[advances.length - 1];
|
|
628
|
+
expect(Math.abs(input.offsetWidth - width)).toBeLessThanOrEqual(1);
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it('hugs a short value, so the value and unit stay centred', async () => {
|
|
632
|
+
el.value = 1;
|
|
633
|
+
await settle();
|
|
634
|
+
|
|
635
|
+
const advances = textAdvances(input, input.value);
|
|
636
|
+
const width = advances[advances.length - 1];
|
|
637
|
+
expect(Math.abs(input.offsetWidth - width)).toBeLessThanOrEqual(1);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it('is as wide as its placeholder when empty', async () => {
|
|
641
|
+
el.placeholder = '000.000';
|
|
642
|
+
el.value = NaN;
|
|
643
|
+
await settle();
|
|
644
|
+
|
|
645
|
+
const advances = textAdvances(input, '000.000');
|
|
646
|
+
const width = advances[advances.length - 1];
|
|
647
|
+
expect(Math.abs(input.offsetWidth - width)).toBeLessThanOrEqual(1);
|
|
648
|
+
});
|
|
649
|
+
});
|
|
392
650
|
});
|
|
@@ -211,6 +211,80 @@ export const AlignRightUnitOutside: Story = {
|
|
|
211
211
|
},
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
+
export const AlignCenterEmpty: Story = {
|
|
215
|
+
args: {
|
|
216
|
+
placeholder: '00.0',
|
|
217
|
+
unit: '°C',
|
|
218
|
+
textAlign: ObcNumberInputFieldTextAlign.Center,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// =============================================================================
|
|
223
|
+
// CARET UNDER ZOOM
|
|
224
|
+
// =============================================================================
|
|
225
|
+
|
|
226
|
+
/** Prints where the caret landed beside the field that was clicked. */
|
|
227
|
+
const reportCaret = (event: Event) => {
|
|
228
|
+
const row = event.currentTarget as HTMLElement;
|
|
229
|
+
const field = row.querySelector('obc-number-input-field');
|
|
230
|
+
const readout = row.querySelector('.caret-readout');
|
|
231
|
+
if (!field || !readout) return;
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
const input = field.shadowRoot?.querySelector('input');
|
|
234
|
+
readout.textContent = input
|
|
235
|
+
? `caret ${input.selectionStart} of ${input.value.length}`
|
|
236
|
+
: '';
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const caretRow = (
|
|
241
|
+
zoom: number,
|
|
242
|
+
textAlign: ObcNumberInputFieldTextAlign
|
|
243
|
+
) => html`
|
|
244
|
+
<div
|
|
245
|
+
style="display:flex; align-items:center; gap:16px; margin-bottom:16px;"
|
|
246
|
+
@click=${reportCaret}
|
|
247
|
+
>
|
|
248
|
+
<span style="width:120px; font:12px sans-serif;"
|
|
249
|
+
>zoom ${zoom} · ${textAlign}</span
|
|
250
|
+
>
|
|
251
|
+
<div style="width:320px;">
|
|
252
|
+
<obc-number-input-field
|
|
253
|
+
label="SV"
|
|
254
|
+
unit="m/s"
|
|
255
|
+
.value=${1234567.89}
|
|
256
|
+
.textAlign=${textAlign}
|
|
257
|
+
></obc-number-input-field>
|
|
258
|
+
</div>
|
|
259
|
+
<code class="caret-readout" style="font:12px monospace; min-width:120px;"
|
|
260
|
+
>click a digit</code
|
|
261
|
+
>
|
|
262
|
+
</div>
|
|
263
|
+
`;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Hosts scale the page with CSS `zoom`, so the same fields repeat at four
|
|
267
|
+
* levels; a click on a digit must put the caret on that digit at every one.
|
|
268
|
+
* A live check rather than a snapshot: the readout prints where it landed.
|
|
269
|
+
*/
|
|
270
|
+
export const CaretUnderZoom: Story = {
|
|
271
|
+
tags: ['skip-test'],
|
|
272
|
+
render: () => html`
|
|
273
|
+
<div style="padding:8px;">
|
|
274
|
+
${[0.5, 0.75, 1, 1.25].map(
|
|
275
|
+
(zoom) => html`
|
|
276
|
+
<div
|
|
277
|
+
style="zoom:${zoom}; border-bottom:1px dashed currentColor; padding:8px 0;"
|
|
278
|
+
>
|
|
279
|
+
${caretRow(zoom, ObcNumberInputFieldTextAlign.Right)}
|
|
280
|
+
${caretRow(zoom, ObcNumberInputFieldTextAlign.Center)}
|
|
281
|
+
</div>
|
|
282
|
+
`
|
|
283
|
+
)}
|
|
284
|
+
</div>
|
|
285
|
+
`,
|
|
286
|
+
};
|
|
287
|
+
|
|
214
288
|
// =============================================================================
|
|
215
289
|
// DECIMAL SEPARATOR
|
|
216
290
|
// =============================================================================
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
removeGroupingFromDisplay,
|
|
20
20
|
valuesEqual,
|
|
21
21
|
} from './number-input-format.js';
|
|
22
|
-
import {getCssVariableValue} from '../../charthelpers/colors.js';
|
|
23
22
|
|
|
24
23
|
export type ObcNumberInputFieldInputEvent = CustomEvent<{value: number}>;
|
|
25
24
|
export type ObcNumberInputFieldChangeEvent = CustomEvent<{value: number}>;
|
|
@@ -41,9 +40,6 @@ export enum ObcNumberInputFieldPlacement {
|
|
|
41
40
|
Right = 'right',
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
const characterWidth = 9.15199279785156;
|
|
45
|
-
const symbolWidth = 4.287994384765653;
|
|
46
|
-
const baseFontSize = 16;
|
|
47
43
|
/**
|
|
48
44
|
* `<obc-number-input-field>` – A specialized input field for numerical values with optional unit display.
|
|
49
45
|
*
|
|
@@ -129,6 +125,8 @@ export class ObcNumberInputField extends LitElement {
|
|
|
129
125
|
@state() private previousDisplayText = '';
|
|
130
126
|
@state() private lastCommittedValue = NaN;
|
|
131
127
|
|
|
128
|
+
private focusFromValueClick = false;
|
|
129
|
+
|
|
132
130
|
@query('.value-input') private inputElement?: HTMLInputElement;
|
|
133
131
|
|
|
134
132
|
get displayValue(): string {
|
|
@@ -156,7 +154,6 @@ export class ObcNumberInputField extends LitElement {
|
|
|
156
154
|
const parsed = parseNumberInput(raw);
|
|
157
155
|
this.value = parsed;
|
|
158
156
|
this.previousDisplayText = raw;
|
|
159
|
-
this.updateCenterAlignedInputWidth(raw);
|
|
160
157
|
this.dispatchInput();
|
|
161
158
|
}
|
|
162
159
|
|
|
@@ -202,6 +199,37 @@ export class ObcNumberInputField extends LitElement {
|
|
|
202
199
|
// A read-only field has nothing to edit, so it keeps its formatted display
|
|
203
200
|
// instead of switching to the ungrouped editing representation.
|
|
204
201
|
if (this.readonly) return;
|
|
202
|
+
if (this.focusFromValueClick) {
|
|
203
|
+
this.focusFromValueClick = false;
|
|
204
|
+
requestAnimationFrame(() => void this.ungroupKeepingSelection());
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this.ungroupDisplay();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Ungroups a value the user clicked into, once the browser has placed the
|
|
212
|
+
* caret, and moves the caret with its digits. Ungrouping before that shifts
|
|
213
|
+
* the text under the pointer and the caret lands beside the clicked digit.
|
|
214
|
+
*/
|
|
215
|
+
private async ungroupKeepingSelection() {
|
|
216
|
+
const input = this.inputElement;
|
|
217
|
+
if (!input || !this.hasFocus) return;
|
|
218
|
+
const grouped = input.value;
|
|
219
|
+
const offsetWithoutGrouping = (offset: number | null) =>
|
|
220
|
+
removeGroupingFromDisplay(
|
|
221
|
+
grouped.slice(0, offset ?? grouped.length),
|
|
222
|
+
this.getFormatOptions()
|
|
223
|
+
).length;
|
|
224
|
+
const start = offsetWithoutGrouping(input.selectionStart);
|
|
225
|
+
const end = offsetWithoutGrouping(input.selectionEnd);
|
|
226
|
+
const direction = input.selectionDirection ?? undefined;
|
|
227
|
+
this.ungroupDisplay();
|
|
228
|
+
await this.updateComplete;
|
|
229
|
+
input.setSelectionRange(start, end, direction);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private ungroupDisplay() {
|
|
205
233
|
const source = this.displayOverride || this.displayText;
|
|
206
234
|
this.displayText = removeGroupingFromDisplay(
|
|
207
235
|
source,
|
|
@@ -279,41 +307,11 @@ export class ObcNumberInputField extends LitElement {
|
|
|
279
307
|
return this.displayText;
|
|
280
308
|
}
|
|
281
309
|
|
|
282
|
-
private updateCenterAlignedInputWidth(value: string) {
|
|
283
|
-
if (this.textAlign !== ObcNumberInputFieldTextAlign.Center) {
|
|
284
|
-
this.style.removeProperty('--obc-number-input-center-width');
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const fontSize = Number.parseFloat(
|
|
289
|
-
getCssVariableValue(
|
|
290
|
-
this,
|
|
291
|
-
'--global-typography-instrument-value-regular-font-size'
|
|
292
|
-
)
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const characters = value.replaceAll(/[.,]/g, '');
|
|
296
|
-
const symbols = value.length - characters.length;
|
|
297
|
-
// These values are based on the font size of 16px
|
|
298
|
-
|
|
299
|
-
const calculatedWidth =
|
|
300
|
-
characters.length * characterWidth + symbols * symbolWidth;
|
|
301
|
-
|
|
302
|
-
const measuredWidth = Math.ceil(
|
|
303
|
-
(calculatedWidth * fontSize) / baseFontSize
|
|
304
|
-
);
|
|
305
|
-
this.style.setProperty(
|
|
306
|
-
'--obc-number-input-center-width',
|
|
307
|
-
`${measuredWidth}px`
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
310
|
override firstUpdated() {
|
|
312
311
|
if (!this.displayText && !this.displayOverride) {
|
|
313
312
|
this.displayText = this.formatValueForDisplay(this.value);
|
|
314
313
|
}
|
|
315
314
|
this.lastCommittedValue = this.value;
|
|
316
|
-
this.updateCenterAlignedInputWidth(this.getEffectiveDisplay());
|
|
317
315
|
}
|
|
318
316
|
|
|
319
317
|
private get isEmpty(): boolean {
|
|
@@ -358,8 +356,6 @@ export class ObcNumberInputField extends LitElement {
|
|
|
358
356
|
) {
|
|
359
357
|
this.previousValue = this.value;
|
|
360
358
|
}
|
|
361
|
-
|
|
362
|
-
this.updateCenterAlignedInputWidth(this.getEffectiveDisplay());
|
|
363
359
|
}
|
|
364
360
|
|
|
365
361
|
private renderFooterText(
|
|
@@ -385,45 +381,20 @@ export class ObcNumberInputField extends LitElement {
|
|
|
385
381
|
</div>`;
|
|
386
382
|
}
|
|
387
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Keeps focus where it is while the chrome around the value is clicked.
|
|
386
|
+
* The wrapper is a `<label>`, so the click itself focuses the input; without
|
|
387
|
+
* this the pointerdown would blur it first and commit an unfinished edit.
|
|
388
|
+
* A click on the value itself is the browser's; it is only noted, so the
|
|
389
|
+
* focus it causes ungroups the value without moving the caret.
|
|
390
|
+
*/
|
|
388
391
|
private onPointerDown(e: PointerEvent) {
|
|
389
|
-
if (this.disabled) return;
|
|
390
|
-
if (this.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
e.preventDefault();
|
|
394
|
-
this.inputElement.focus();
|
|
395
|
-
const inputBox = this.inputElement.getBoundingClientRect();
|
|
396
|
-
let selectionStart: number | undefined;
|
|
397
|
-
if (e.clientX < inputBox.left) {
|
|
398
|
-
// set marker at the left edge of the input
|
|
399
|
-
selectionStart = 0;
|
|
400
|
-
} else if (e.clientX > inputBox.right) {
|
|
401
|
-
// set marker at the right edge of the input
|
|
402
|
-
selectionStart = this.inputElement.value.length;
|
|
403
|
-
} else {
|
|
404
|
-
// set marker at the mouse position
|
|
405
|
-
// Start from the right side of the input and move left until the mouse position is found
|
|
406
|
-
// This is done to set the marker also at label touch.
|
|
407
|
-
// Starts from the right since the label is right aligned.
|
|
408
|
-
const mouseX = e.clientX;
|
|
409
|
-
let inputX = inputBox.right;
|
|
410
|
-
const text = this.inputElement.value;
|
|
411
|
-
for (let i = text.length - 1; i >= 0; i--) {
|
|
412
|
-
const char = text[i];
|
|
413
|
-
const isSymbol = char.match(/[.,]/);
|
|
414
|
-
const width = isSymbol ? symbolWidth : characterWidth;
|
|
415
|
-
if (mouseX > inputX - width / 2) {
|
|
416
|
-
selectionStart = i + 1;
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
inputX -= width;
|
|
420
|
-
}
|
|
421
|
-
if (selectionStart === undefined) {
|
|
422
|
-
selectionStart = 0;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
this.inputElement.setSelectionRange(selectionStart, selectionStart);
|
|
392
|
+
if (this.disabled || this.readonly) return;
|
|
393
|
+
if (e.target === this.inputElement) {
|
|
394
|
+
this.focusFromValueClick = !this.hasFocus;
|
|
395
|
+
return;
|
|
426
396
|
}
|
|
397
|
+
e.preventDefault();
|
|
427
398
|
}
|
|
428
399
|
|
|
429
400
|
override render() {
|
|
@@ -13,21 +13,15 @@
|
|
|
13
13
|
letter-spacing: var(--global-typography-generic-l-letter-spacing);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/* The
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
below. In engines that support text-box-trim the content box collapses to
|
|
20
|
-
the cap height exactly; in Firefox (no text-box-trim) the content keeps its
|
|
21
|
-
natural line box, so align-items:center + overflow:hidden crops it to the
|
|
22
|
-
same height instead. No padding here – the centering provides it.
|
|
23
|
-
(A small top padding could be added later to nudge the text up in Firefox.) */
|
|
16
|
+
/* The box, never clipped: descenders and diacritics paint past its edges. The
|
|
17
|
+
centred content leaves equal padding above and below; without text-box-trim
|
|
18
|
+
the host's zero line-height keeps it centred to within about a pixel. */
|
|
24
19
|
.inner-wrapper {
|
|
25
20
|
box-sizing: border-box;
|
|
26
21
|
display: flex;
|
|
27
22
|
align-items: center;
|
|
28
23
|
justify-content: var(--alignment-justify, flex-end);
|
|
29
24
|
height: var(--height);
|
|
30
|
-
overflow: hidden;
|
|
31
25
|
/* Opt-in: animate a `size` change (height + font-size below). Defaults to 0s
|
|
32
26
|
(instant, current behavior) so existing usages and snapshots are unchanged;
|
|
33
27
|
a consumer sets `--obc-textbox-size-transition` (e.g. 300ms) to animate the
|
|
@@ -163,3 +163,27 @@ export const ReserveSpace: Story = {
|
|
|
163
163
|
</div>
|
|
164
164
|
`,
|
|
165
165
|
};
|
|
166
|
+
|
|
167
|
+
export const DescendersAndDiacritics: Story = {
|
|
168
|
+
parameters: {
|
|
169
|
+
docs: {
|
|
170
|
+
description: {
|
|
171
|
+
story:
|
|
172
|
+
'The box is a cap-to-baseline frame, not a clip: descenders (g, j, p) and diacritics (Å) paint past its edges at every size. An ancestor that clips must leave room for them.',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
render: () => html`
|
|
177
|
+
<div
|
|
178
|
+
style="display: flex; flex-direction: column; align-items: flex-start; gap: 24px;"
|
|
179
|
+
>
|
|
180
|
+
${Object.values(ObcTextboxSize).map(
|
|
181
|
+
(size) => html`
|
|
182
|
+
<obc-textbox .size=${size} style=${boxOutline}>
|
|
183
|
+
<div>${size.toUpperCase()} – Ågjp 123</div>
|
|
184
|
+
</obc-textbox>
|
|
185
|
+
`
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
`,
|
|
189
|
+
};
|
|
@@ -50,6 +50,9 @@ export enum ObcTextboxFontWeight {
|
|
|
50
50
|
* - **Reserved width:** content placed in the `length` slot reserves a minimum
|
|
51
51
|
* width invisibly, so the box does not resize as the visible text changes.
|
|
52
52
|
* The box always shows all content – it never crops.
|
|
53
|
+
* - **Cap-to-baseline frame:** the box spans the cap top to the baseline plus
|
|
54
|
+
* the padding; descenders and diacritics paint past its edges, so an
|
|
55
|
+
* ancestor that clips must leave room for them.
|
|
53
56
|
*
|
|
54
57
|
* ## Usage Guidelines
|
|
55
58
|
* - Pass the longest expected string to the `length` slot (e.g. `"888.8"` or
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
's16fccc311f4779f6': `Rectified`,
|
|
35
35
|
'seb27af82aef6a03e': `No rectified alerts`,
|
|
36
36
|
'sfa32c219a0764262': `ACK`,
|
|
37
|
-
's5ba9818f6a39054c': `Go to the 'Alert list' for more details or to manage existing alerts.`,
|
|
38
37
|
'sa45a194b58837e4f': `Active`,
|
|
38
|
+
's5ba9818f6a39054c': `Go to the 'Alert list' for more details or to manage existing alerts.`,
|
|
39
39
|
'sa6ef04345891fb38': `ACK visible`,
|
|
40
40
|
's3cf89cb47fdde7e9': `Link`,
|
|
41
41
|
's47278872f6826da8': `Dusk`,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* The empty state of an alert list: an icon, a title and an optional
|
|
2
|
+
* description, centred in the space the list would fill.
|
|
3
|
+
*
|
|
4
|
+
* Every alert list shows the same empty state, so it is defined once here.
|
|
5
|
+
* Apply it to the element that wraps the three parts; it styles the
|
|
6
|
+
* `.icon`, `.empty-title` and `.empty-description` children inside it. The
|
|
7
|
+
* icon's colour is left to each list. */
|
|
8
|
+
@define-mixin alert-list-empty {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
height: 100%;
|
|
14
|
+
gap: var(--app-components-alert-menu-button-spacing);
|
|
15
|
+
|
|
16
|
+
.icon {
|
|
17
|
+
height: 96px;
|
|
18
|
+
width: 96px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.empty-title {
|
|
22
|
+
color: var(--element-active-color);
|
|
23
|
+
@mixin font-body-active;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.empty-description {
|
|
27
|
+
color: var(--element-neutral-color);
|
|
28
|
+
@mixin font-body;
|
|
29
|
+
max-width: 344px;
|
|
30
|
+
text-align: center;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -116,7 +116,8 @@ obc-readout-block {
|
|
|
116
116
|
gap: var(--global-size-spacing-target-padding);
|
|
117
117
|
flex: 1 1 auto;
|
|
118
118
|
min-inline-size: 0;
|
|
119
|
-
overflow: clip;
|
|
119
|
+
overflow-x: clip;
|
|
120
|
+
overflow-y: visible; /* a label's descenders and diacritics paint past its cap-to-baseline box */
|
|
120
121
|
/* a leading-src chip's 1px outline is drawn outside its box at the container edge */
|
|
121
122
|
overflow-clip-margin: 1px;
|
|
122
123
|
}
|