@kubex/zinc 1.1.154 → 1.1.156
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/dist/custom-elements.json +151 -78
- package/dist/vscode.html-custom-data.json +12 -12
- package/dist/web-types.json +25 -25
- package/dist/zn.d.ts +38 -6
- package/dist/zn.min.js +97 -83
- package/docs/pages/components/select.md +16 -0
- package/package.json +1 -1
- package/src/components/inline-edit/inline-edit.component.ts +2 -2
- package/src/components/inline-edit/inline-edit.scss +11 -1
- package/src/components/inline-edit/inline-edit.test.ts +24 -0
- package/src/components/page-builder/page-builder.component.ts +71 -13
- package/src/components/page-builder/page-builder.test.ts +106 -0
- package/src/components/reveal/reveal.component.ts +14 -0
- package/src/components/reveal/reveal.scss +10 -1
- package/src/components/reveal/reveal.test.ts +36 -0
- package/src/components/select/select.component.ts +21 -2
- package/src/components/select/select.scss +3 -2
- package/src/components/select/select.test.ts +59 -0
|
@@ -117,6 +117,22 @@ Use the `placeholder` attribute to add a placeholder.
|
|
|
117
117
|
</zn-select>
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### Empty State
|
|
121
|
+
|
|
122
|
+
A select with nothing to choose from says so when opened, rather than showing an empty dropdown. The wording distinguishes a list that is empty from one a search has filtered down to nothing: type `zzz` into the second select below to see it.
|
|
123
|
+
|
|
124
|
+
```html:preview
|
|
125
|
+
<zn-select label="No options" placeholder="Select a reason"></zn-select>
|
|
126
|
+
<br />
|
|
127
|
+
<zn-select label="Searched to nothing" search placeholder="Type to search...">
|
|
128
|
+
<zn-option value="au">Australia</zn-option>
|
|
129
|
+
<zn-option value="br">Brazil</zn-option>
|
|
130
|
+
<zn-option value="ca">Canada</zn-option>
|
|
131
|
+
</zn-select>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Options that arrive later — from `data-uri`, a remote search, or appended `zn-option` elements — clear the message as soon as they land, so an empty list at first render is safe.
|
|
135
|
+
|
|
120
136
|
### Clearable
|
|
121
137
|
|
|
122
138
|
Use the `clearable` attribute to make the control clearable. The clear button only appears when an option is selected.
|
package/package.json
CHANGED
|
@@ -368,8 +368,8 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
|
|
|
368
368
|
const hasHelpTextSlot = this.hasSlotController.test('help-text');
|
|
369
369
|
const hasHelpText = this.helpText ? true : hasHelpTextSlot;
|
|
370
370
|
|
|
371
|
-
//
|
|
372
|
-
if (Object.keys(this.options).length > 0) {
|
|
371
|
+
// An options list that renders empty is still a select — never silently fall back to free text
|
|
372
|
+
if (Object.keys(this.options).length > 0 || this.hasAttribute('options')) {
|
|
373
373
|
this.inputType = 'select';
|
|
374
374
|
}
|
|
375
375
|
|
|
@@ -59,6 +59,9 @@
|
|
|
59
59
|
|
|
60
60
|
&__input::part(form-control-input) {
|
|
61
61
|
margin: 0;
|
|
62
|
+
// Block wrapper round an inline-flex base adds baseline strut, leaving the input
|
|
63
|
+
// ~1.4px taller than the reveal that replaces it
|
|
64
|
+
display: flex;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
&__input {
|
|
@@ -133,7 +136,8 @@
|
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
&__reveal {
|
|
136
|
-
|
|
139
|
+
// Matches the height of the input it stands in for, so entering edit mode doesn't resize the row
|
|
140
|
+
line-height: var(--zn-input-height-medium);
|
|
137
141
|
color: rgb(var(--zn-text));
|
|
138
142
|
|
|
139
143
|
// Fill the row so hovering anywhere over the field reveals the value
|
|
@@ -199,4 +203,10 @@ zn-textarea::part(textarea) {
|
|
|
199
203
|
resize: none;
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
:host([size="small"]) .ai__reveal {
|
|
207
|
+
line-height: var(--zn-input-height-small);
|
|
208
|
+
}
|
|
202
209
|
|
|
210
|
+
:host([size="large"]) .ai__reveal {
|
|
211
|
+
line-height: var(--zn-input-height-large);
|
|
212
|
+
}
|
|
@@ -565,4 +565,28 @@ describe('<zn-inline-edit>', () => {
|
|
|
565
565
|
expect(submits, 'Enter belongs to the open menu, not the form').to.equal(0);
|
|
566
566
|
});
|
|
567
567
|
});
|
|
568
|
+
|
|
569
|
+
// The theme stylesheet isn't loaded in tests, so the sizing tokens the reveal and the input both
|
|
570
|
+
// key off have to be supplied for the comparison to mean anything.
|
|
571
|
+
it('should keep the same height whether it shows a reveal or the input it replaces', async () => {
|
|
572
|
+
const tokens = 'display: contents; --zn-input-height-medium: 36px; --zn-line-height-looser: 3;';
|
|
573
|
+
const plain = await fixture<HTMLDivElement>(html`
|
|
574
|
+
<div style="${tokens}">
|
|
575
|
+
<zn-inline-edit name="email" value="alan.jones@example.com"></zn-inline-edit>
|
|
576
|
+
</div>
|
|
577
|
+
`);
|
|
578
|
+
const masked = await fixture<HTMLDivElement>(html`
|
|
579
|
+
<div style="${tokens}">
|
|
580
|
+
<zn-inline-edit name="email" value="alan.jones@example.com"
|
|
581
|
+
display-value="\u2022\u2022\u2022\u2022\u2022@example.com"></zn-inline-edit>
|
|
582
|
+
</div>
|
|
583
|
+
`);
|
|
584
|
+
const [plainEdit, maskedEdit] = [plain, masked].map(el => el.querySelector<ZnInlineEdit>('zn-inline-edit')!);
|
|
585
|
+
await Promise.all([plainEdit.updateComplete, maskedEdit.updateComplete]);
|
|
586
|
+
|
|
587
|
+
const height = (el: ZnInlineEdit) =>
|
|
588
|
+
el.shadowRoot!.querySelector<HTMLElement>('.ai')!.getBoundingClientRect().height;
|
|
589
|
+
|
|
590
|
+
expect(height(maskedEdit)).to.equal(height(plainEdit));
|
|
591
|
+
});
|
|
568
592
|
});
|
|
@@ -24,8 +24,10 @@ import ZincElement from '../../internal/zinc-element';
|
|
|
24
24
|
import ZnCollapsible from '../collapsible';
|
|
25
25
|
import ZnIcon from '../icon';
|
|
26
26
|
import ZnInput from '../input';
|
|
27
|
+
import ZnOption from '../option';
|
|
27
28
|
import ZnPagePaletteItem from './modules/page-palette-item';
|
|
28
29
|
import ZnPageSectionCard from './modules/page-section-card';
|
|
30
|
+
import ZnSelect from '../select';
|
|
29
31
|
|
|
30
32
|
import styles from './page-builder.scss';
|
|
31
33
|
|
|
@@ -96,8 +98,10 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
96
98
|
'zn-collapsible': ZnCollapsible,
|
|
97
99
|
'zn-icon': ZnIcon,
|
|
98
100
|
'zn-input': ZnInput,
|
|
101
|
+
'zn-option': ZnOption,
|
|
99
102
|
'zn-page-palette-item': ZnPagePaletteItem,
|
|
100
103
|
'zn-page-section-card': ZnPageSectionCard,
|
|
104
|
+
'zn-select': ZnSelect,
|
|
101
105
|
};
|
|
102
106
|
|
|
103
107
|
private readonly formControlController = new FormControlController(this);
|
|
@@ -115,10 +119,12 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
115
119
|
@property({ reflect: true }) subheading = '';
|
|
116
120
|
|
|
117
121
|
/**
|
|
118
|
-
* Section type
|
|
119
|
-
*
|
|
120
|
-
* removed, reordered or dragged into a slot, and
|
|
121
|
-
* Its content stays fully editable in the
|
|
122
|
+
* Section type keys that may lead the page, comma separated. The builder hoists an
|
|
123
|
+
* existing section of any of them to the top, or inserts an empty one of the first,
|
|
124
|
+
* and pins it there: it can't be removed, reordered or dragged into a slot, and
|
|
125
|
+
* nothing can be dropped above it. Its content stays fully editable in the
|
|
126
|
+
* inspector, which offers a swap between the allowed types when there is more
|
|
127
|
+
* than one.
|
|
122
128
|
*/
|
|
123
129
|
@property({ attribute: 'required-first', reflect: true }) requiredFirst = '';
|
|
124
130
|
|
|
@@ -520,27 +526,45 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
520
526
|
*/
|
|
521
527
|
private get _pinnedId(): string | null {
|
|
522
528
|
const first = this._state.sections[0];
|
|
523
|
-
|
|
529
|
+
const types = this._requiredFirstTypes;
|
|
530
|
+
return first && types.includes(first.type) ? first.id : null;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** The types `required-first` allows to lead the page, in the order given. */
|
|
534
|
+
private get _requiredFirstTypes(): string[] {
|
|
535
|
+
return this.requiredFirst.split(',').map(t => t.trim()).filter(Boolean);
|
|
524
536
|
}
|
|
525
537
|
|
|
526
538
|
private _isPinned(id: string): boolean {
|
|
527
539
|
return this._pinnedId === id;
|
|
528
540
|
}
|
|
529
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Whether the pinned section may be removed: only while another section can take
|
|
544
|
+
* the lead in its place, so the page is never left without one. It stays undraggable
|
|
545
|
+
* either way — the replacement arrives by removing this one, not by reordering.
|
|
546
|
+
*/
|
|
547
|
+
private get _canUnpin(): boolean {
|
|
548
|
+
const types = this._requiredFirstTypes;
|
|
549
|
+
return this._state.sections.slice(1).some(s => types.includes(s.type));
|
|
550
|
+
}
|
|
551
|
+
|
|
530
552
|
/** Lowest top-level index a section may be added or moved to. */
|
|
531
553
|
private get _firstFreeIndex(): number {
|
|
532
554
|
return this._pinnedId === null ? 0 : 1;
|
|
533
555
|
}
|
|
534
556
|
|
|
535
557
|
/**
|
|
536
|
-
* Sections reordered so `required-first` leads the page: an existing section of
|
|
537
|
-
* type is hoisted to the front, otherwise an empty one
|
|
558
|
+
* Sections reordered so `required-first` leads the page: an existing section of an
|
|
559
|
+
* allowed type is hoisted to the front, otherwise an empty one of the first type is
|
|
560
|
+
* prepended. Returns the
|
|
538
561
|
* argument unchanged when there is nothing to do, so callers can compare by identity.
|
|
539
562
|
*/
|
|
540
563
|
private _requireFirst(sections: PageSection[]): PageSection[] {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
564
|
+
const types = this._requiredFirstTypes;
|
|
565
|
+
if (!types.length || types.includes(sections[0]?.type)) return sections;
|
|
566
|
+
const at = sections.findIndex(s => types.includes(s.type));
|
|
567
|
+
if (at === -1) return [{ id: generateSectionId(), type: types[0], data: {} }, ...sections];
|
|
544
568
|
const hoisted = [...sections];
|
|
545
569
|
hoisted.unshift(...hoisted.splice(at, 1));
|
|
546
570
|
return hoisted;
|
|
@@ -693,7 +717,7 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
693
717
|
}
|
|
694
718
|
|
|
695
719
|
private _removeSection(id: string) {
|
|
696
|
-
if (this._isPinned(id)) return;
|
|
720
|
+
if (this._isPinned(id) && !this._canUnpin) return;
|
|
697
721
|
const [removed, sections] = this._extract(id);
|
|
698
722
|
if (!removed) return;
|
|
699
723
|
this._pushHistory();
|
|
@@ -704,7 +728,8 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
704
728
|
if (this._selectedId === id || removed.children?.some(c => c?.id === this._selectedId)) {
|
|
705
729
|
this._select(null);
|
|
706
730
|
}
|
|
707
|
-
|
|
731
|
+
// Removing the leading section hands the lead to the next one that may hold it.
|
|
732
|
+
this._commit({ sections: this._requireFirst(sections) });
|
|
708
733
|
}
|
|
709
734
|
|
|
710
735
|
private _duplicateSection(id: string) {
|
|
@@ -1139,6 +1164,7 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
1139
1164
|
) {
|
|
1140
1165
|
const type = this.registry.get(section.type);
|
|
1141
1166
|
const pinned = this._isPinned(section.id);
|
|
1167
|
+
const locked = pinned && !this._canUnpin;
|
|
1142
1168
|
return html`
|
|
1143
1169
|
<zn-page-section-card
|
|
1144
1170
|
class="${extraClass} ${this._draggingId === section.id ? 'dragging' : ''}"
|
|
@@ -1152,7 +1178,7 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
1152
1178
|
color="${ifDefined(type?.color)}"
|
|
1153
1179
|
?selected="${this._selectedId === section.id}"
|
|
1154
1180
|
?unknown="${!type}"
|
|
1155
|
-
?locked="${
|
|
1181
|
+
?locked="${locked}"
|
|
1156
1182
|
@click="${(e: Event) => {
|
|
1157
1183
|
e.stopPropagation();
|
|
1158
1184
|
this._select(section.id);
|
|
@@ -1340,6 +1366,21 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
1340
1366
|
this._commit({ sections: this._patchSection(id, s => ({ ...s, data: { ...s.data, ...patch } })) });
|
|
1341
1367
|
}
|
|
1342
1368
|
|
|
1369
|
+
/**
|
|
1370
|
+
* Retypes the pinned section, keeping its id, name and data so the copy shared by
|
|
1371
|
+
* the allowed types survives; keys the new type has no field for stay unread. The
|
|
1372
|
+
* inspector form is stamped from the type's template, so it is rebuilt by hand —
|
|
1373
|
+
* selection has not changed.
|
|
1374
|
+
*/
|
|
1375
|
+
private _swapPinnedType(type: string) {
|
|
1376
|
+
const id = this._pinnedId;
|
|
1377
|
+
const section = this._findSection(id);
|
|
1378
|
+
if (!id || !section || section.type === type || !this._requiredFirstTypes.includes(type)) return;
|
|
1379
|
+
this._pushHistory();
|
|
1380
|
+
this._commit({ sections: this._patchSection(id, s => ({ ...s, type })) });
|
|
1381
|
+
this._buildInspectorForm();
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1343
1384
|
private _renameSection(id: string, label: string) {
|
|
1344
1385
|
this._pushHistory();
|
|
1345
1386
|
this._commit({ sections: this._patchSection(id, s => ({ ...s, label: label || undefined })) });
|
|
@@ -1380,6 +1421,22 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
1380
1421
|
this._inspectorWidth = this._clampInspector((this._inspectorWidth ?? this._inspectorRect()) + step);
|
|
1381
1422
|
};
|
|
1382
1423
|
|
|
1424
|
+
/** Offered on the pinned section alone, and only where there is another type to take. */
|
|
1425
|
+
private _renderSwapControl(section: PageSection) {
|
|
1426
|
+
const types = this._requiredFirstTypes;
|
|
1427
|
+
if (types.length < 2 || !this._isPinned(section.id)) return '';
|
|
1428
|
+
return html`
|
|
1429
|
+
<zn-select
|
|
1430
|
+
class="inspector__swap"
|
|
1431
|
+
label="Section type"
|
|
1432
|
+
help-text="Swaps the section leading the page, keeping the settings both types share."
|
|
1433
|
+
.value="${section.type}"
|
|
1434
|
+
@zn-change="${(e: Event) => this._swapPinnedType(String((e.target as ZnSelect).value ?? ''))}">
|
|
1435
|
+
${types.map(t => html`
|
|
1436
|
+
<zn-option value="${t}">${this.registry.get(t)?.label ?? t}</zn-option>`)}
|
|
1437
|
+
</zn-select>`;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1383
1440
|
private _renderInspector() {
|
|
1384
1441
|
const section = this._selectedSection();
|
|
1385
1442
|
if (!section) return html``;
|
|
@@ -1430,6 +1487,7 @@ export default class ZnPageBuilder extends ZincElement {
|
|
|
1430
1487
|
label="Section name"
|
|
1431
1488
|
.value="${section.label ?? type?.label ?? ''}"
|
|
1432
1489
|
@zn-change="${(e: Event) => this._renameSection(section.id, String((e.target as ZnInput).value ?? ''))}"></zn-input>
|
|
1490
|
+
${this._renderSwapControl(section)}
|
|
1433
1491
|
${type?.slotsMax === undefined ? '' : html`
|
|
1434
1492
|
<zn-input
|
|
1435
1493
|
class="inspector__slots"
|
|
@@ -988,6 +988,112 @@ describe('<zn-page-builder>', () => {
|
|
|
988
988
|
expect(el.state.sections[1].children?.[0] ?? null, 'slot left empty').to.be.null;
|
|
989
989
|
});
|
|
990
990
|
|
|
991
|
+
it('should accept any of several required-first types', async () => {
|
|
992
|
+
const el = await fixture<ZnPageBuilder>(html`
|
|
993
|
+
<zn-page-builder required-first="hero,hero-split"
|
|
994
|
+
config='{"sections":[{"id":"t","type":"rich-text","data":{}},{"id":"h","type":"hero-split","data":{"title":"Help"}}]}'>
|
|
995
|
+
<template type="hero" slot="config" label="Hero"></template>
|
|
996
|
+
<template type="hero-split" slot="config" label="Split Hero"></template>
|
|
997
|
+
<template type="rich-text" slot="config" label="Rich Text"></template>
|
|
998
|
+
</zn-page-builder>`);
|
|
999
|
+
await el.updateComplete;
|
|
1000
|
+
|
|
1001
|
+
expect(el.state.sections.map(s => s.id), 'the alternate type is hoisted too').to.deep.equal(['h', 't']);
|
|
1002
|
+
expect(el.shadowRoot!.querySelector('zn-page-section-card')!.hasAttribute('locked')).to.be.true;
|
|
1003
|
+
|
|
1004
|
+
const empty = await fixture<ZnPageBuilder>(html`
|
|
1005
|
+
<zn-page-builder required-first="hero,hero-split">
|
|
1006
|
+
<template type="hero" slot="config" label="Hero"></template>
|
|
1007
|
+
<template type="hero-split" slot="config" label="Split Hero"></template>
|
|
1008
|
+
</zn-page-builder>`);
|
|
1009
|
+
await empty.updateComplete;
|
|
1010
|
+
expect(empty.state.sections.map(s => s.type), 'an empty page gets the first type').to.deep.equal(['hero']);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
it('should swap the pinned section for another allowed type, keeping its content', async () => {
|
|
1014
|
+
const el = await fixture<ZnPageBuilder>(html`
|
|
1015
|
+
<zn-page-builder required-first="hero,hero-split"
|
|
1016
|
+
config='{"sections":[{"id":"h","type":"hero","label":"Top","data":{"title":"Help","search":true}},{"id":"t","type":"rich-text","data":{}}]}'>
|
|
1017
|
+
<template type="hero" slot="config" label="Hero"></template>
|
|
1018
|
+
<template type="hero-split" slot="config" label="Split Hero">
|
|
1019
|
+
<zn-input name="title"></zn-input>
|
|
1020
|
+
</template>
|
|
1021
|
+
<template type="rich-text" slot="config" label="Rich Text"></template>
|
|
1022
|
+
</zn-page-builder>`);
|
|
1023
|
+
await el.updateComplete;
|
|
1024
|
+
|
|
1025
|
+
el.shadowRoot!.querySelector('zn-page-section-card')!.dispatchEvent(new Event('click'));
|
|
1026
|
+
await el.updateComplete;
|
|
1027
|
+
|
|
1028
|
+
const swap = el.shadowRoot!.querySelector<HTMLElement & { value: string }>('.inspector__swap')!;
|
|
1029
|
+
expect(swap, 'swap control on the pinned section').to.exist;
|
|
1030
|
+
expect([...swap.querySelectorAll('zn-option')].map(o => o.getAttribute('value')))
|
|
1031
|
+
.to.deep.equal(['hero', 'hero-split']);
|
|
1032
|
+
|
|
1033
|
+
swap.value = 'hero-split';
|
|
1034
|
+
swap.dispatchEvent(new CustomEvent('zn-change', {bubbles: true}));
|
|
1035
|
+
await el.updateComplete;
|
|
1036
|
+
|
|
1037
|
+
const [pinned, rest] = el.state.sections;
|
|
1038
|
+
expect(pinned.type, 'type swapped').to.equal('hero-split');
|
|
1039
|
+
expect(pinned.id, 'same section').to.equal('h');
|
|
1040
|
+
expect(pinned.label, 'keeps its name').to.equal('Top');
|
|
1041
|
+
expect(pinned.data, 'keeps its content').to.deep.equal({title: 'Help', search: true});
|
|
1042
|
+
expect(rest.id, 'the rest of the page is untouched').to.equal('t');
|
|
1043
|
+
expect(el.shadowRoot!.querySelector('zn-page-section-card')!.hasAttribute('locked'), 'still pinned').to.be.true;
|
|
1044
|
+
|
|
1045
|
+
// The inspector now stamps the new type's fields, filled from the kept data.
|
|
1046
|
+
const title = el.shadowRoot!.querySelector<HTMLInputElement>('.inspector__form [name="title"]');
|
|
1047
|
+
expect(title?.value, 'inspector rebuilt for the new type').to.equal('Help');
|
|
1048
|
+
|
|
1049
|
+
el.undo();
|
|
1050
|
+
await el.updateComplete;
|
|
1051
|
+
expect(el.state.sections[0].type, 'undo puts the original type back').to.equal('hero');
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
it('should let the pinned section go once another may lead in its place', async () => {
|
|
1055
|
+
const el = await fixture<ZnPageBuilder>(html`
|
|
1056
|
+
<zn-page-builder required-first="hero,hero-split"
|
|
1057
|
+
config='{"sections":[{"id":"h","type":"hero","data":{}},{"id":"t","type":"rich-text","data":{}},{"id":"s","type":"hero-split","data":{}}]}'>
|
|
1058
|
+
<template type="hero" slot="config" label="Hero"></template>
|
|
1059
|
+
<template type="hero-split" slot="config" label="Split Hero"></template>
|
|
1060
|
+
<template type="rich-text" slot="config" label="Rich Text"></template>
|
|
1061
|
+
</zn-page-builder>`);
|
|
1062
|
+
await el.updateComplete;
|
|
1063
|
+
|
|
1064
|
+
const pinnedCard = el.shadowRoot!.querySelector('zn-page-section-card')!;
|
|
1065
|
+
expect(pinnedCard.hasAttribute('locked'), 'a replaceable hero shows no lock').to.be.false;
|
|
1066
|
+
expect(pinnedCard.getAttribute('draggable'), 'but still cannot be dragged').to.equal('false');
|
|
1067
|
+
expect(pinnedCard.shadowRoot!.querySelector('zn-button[title="Remove section"]'), 'remove offered').to.exist;
|
|
1068
|
+
|
|
1069
|
+
pinnedCard.dispatchEvent(new CustomEvent('page-card-remove', {bubbles: true, composed: true}));
|
|
1070
|
+
await el.updateComplete;
|
|
1071
|
+
|
|
1072
|
+
expect(el.state.sections.map(s => s.id), 'the other hero takes the lead').to.deep.equal(['s', 't']);
|
|
1073
|
+
const nowPinned = el.shadowRoot!.querySelector('zn-page-section-card')!;
|
|
1074
|
+
expect(nowPinned.hasAttribute('locked'), 'the last hero locks again').to.be.true;
|
|
1075
|
+
|
|
1076
|
+
nowPinned.dispatchEvent(new CustomEvent('page-card-remove', {bubbles: true, composed: true}));
|
|
1077
|
+
await el.updateComplete;
|
|
1078
|
+
expect(el.state.sections.map(s => s.id), 'the last hero cannot go').to.deep.equal(['s', 't']);
|
|
1079
|
+
|
|
1080
|
+
el.undo();
|
|
1081
|
+
await el.updateComplete;
|
|
1082
|
+
expect(el.state.sections.map(s => s.id), 'undo brings the removed hero back').to.deep.equal(['h', 't', 's']);
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
it('should offer no swap control when only one type may lead', async () => {
|
|
1086
|
+
const el = await fixture<ZnPageBuilder>(html`
|
|
1087
|
+
<zn-page-builder required-first="hero" config='{"sections":[{"id":"h","type":"hero","data":{}}]}'>
|
|
1088
|
+
<template type="hero" slot="config" label="Hero"></template>
|
|
1089
|
+
</zn-page-builder>`);
|
|
1090
|
+
await el.updateComplete;
|
|
1091
|
+
|
|
1092
|
+
el.shadowRoot!.querySelector('zn-page-section-card')!.dispatchEvent(new Event('click'));
|
|
1093
|
+
await el.updateComplete;
|
|
1094
|
+
expect(el.shadowRoot!.querySelector('.inspector__swap')).to.not.exist;
|
|
1095
|
+
});
|
|
1096
|
+
|
|
991
1097
|
it('should leave the page alone without required-first', async () => {
|
|
992
1098
|
const el = await fixture<ZnPageBuilder>(html`
|
|
993
1099
|
<zn-page-builder config='{"sections":[{"id":"t","type":"rich-text","data":{}}]}'>
|
|
@@ -44,6 +44,11 @@ export default class ZnReveal extends ZincElement {
|
|
|
44
44
|
/** Disables click-to-toggle so the value is only revealed on hover. Clicks still bubble to the parent. */
|
|
45
45
|
@property({type: Boolean, attribute: 'no-toggle'}) noToggle: boolean = false;
|
|
46
46
|
|
|
47
|
+
/** Nothing is hidden when the revealed value is what's already on show, so there is nothing to reveal. */
|
|
48
|
+
private get _isMasked(): boolean {
|
|
49
|
+
return this.revealed !== '' && this.revealed !== this.initial;
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
private _isRevealed: boolean = false;
|
|
48
53
|
private _isToggled: boolean = false;
|
|
49
54
|
private _hideTimer?: ReturnType<typeof setTimeout>;
|
|
@@ -102,10 +107,19 @@ export default class ZnReveal extends ZincElement {
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
render() {
|
|
110
|
+
if (!this._isMasked) {
|
|
111
|
+
return html`
|
|
112
|
+
<div part="base" class="reveal reveal--static">
|
|
113
|
+
<span class="reveal__text">${this.initial || this.revealed}</span>
|
|
114
|
+
</div>
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
return html`
|
|
106
119
|
<div part="base"
|
|
107
120
|
class=${classMap({
|
|
108
121
|
'reveal': true,
|
|
122
|
+
'reveal--clickable': !this.noToggle,
|
|
109
123
|
'reveal--revealed': this._isRevealed,
|
|
110
124
|
'reveal--toggled': this._isToggled,
|
|
111
125
|
})}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
:host {
|
|
4
4
|
display: inline-block;
|
|
5
|
-
cursor: pointer;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
|
|
@@ -13,6 +12,16 @@
|
|
|
13
12
|
overflow: hidden;
|
|
14
13
|
}
|
|
15
14
|
|
|
15
|
+
// Only a click that toggles earns the pointer: a static or hover-only reveal does nothing on click.
|
|
16
|
+
.reveal--clickable {
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// cursor inherits, so a static reveal has to opt out of a clickable container's pointer
|
|
21
|
+
.reveal--static {
|
|
22
|
+
cursor: auto;
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
.reveal__text {
|
|
17
26
|
grid-area: stack;
|
|
18
27
|
line-height: inherit;
|
|
@@ -21,6 +21,42 @@ describe('<zn-reveal>', () => {
|
|
|
21
21
|
expect(container.classList.contains('reveal--revealed')).to.be.true;
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
it('should render static text when the revealed value matches the initial', async () => {
|
|
25
|
+
const el = await fixture<ZnReveal>(html`
|
|
26
|
+
<zn-reveal initial="real" revealed="real"></zn-reveal>
|
|
27
|
+
`);
|
|
28
|
+
const container = el.shadowRoot!.querySelector<HTMLElement>('.reveal')!;
|
|
29
|
+
|
|
30
|
+
expect(container.classList.contains('reveal--static')).to.be.true;
|
|
31
|
+
|
|
32
|
+
container.click();
|
|
33
|
+
await el.updateComplete;
|
|
34
|
+
|
|
35
|
+
expect(container.classList.contains('reveal--revealed')).to.be.false;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should only show a pointer cursor when a click would toggle the value', async () => {
|
|
39
|
+
const cursorOf = (el: ZnReveal) =>
|
|
40
|
+
getComputedStyle(el.shadowRoot!.querySelector<HTMLElement>('.reveal')!).cursor;
|
|
41
|
+
|
|
42
|
+
const toggleable = await fixture<ZnReveal>(html`
|
|
43
|
+
<zn-reveal initial="****" revealed="real"></zn-reveal>
|
|
44
|
+
`);
|
|
45
|
+
// Inside a clickable row (an inline edit, say) the inherited pointer has to be shaken off
|
|
46
|
+
const unmasked = (await fixture<HTMLDivElement>(html`
|
|
47
|
+
<div style="cursor: pointer">
|
|
48
|
+
<zn-reveal initial="real" revealed="real"></zn-reveal>
|
|
49
|
+
</div>
|
|
50
|
+
`)).querySelector<ZnReveal>('zn-reveal')!;
|
|
51
|
+
const hoverOnly = await fixture<ZnReveal>(html`
|
|
52
|
+
<zn-reveal initial="****" revealed="real" no-toggle></zn-reveal>
|
|
53
|
+
`);
|
|
54
|
+
|
|
55
|
+
expect(cursorOf(toggleable)).to.equal('pointer');
|
|
56
|
+
expect(cursorOf(unmasked)).to.not.equal('pointer');
|
|
57
|
+
expect(cursorOf(hoverOnly)).to.not.equal('pointer');
|
|
58
|
+
});
|
|
59
|
+
|
|
24
60
|
it('should not toggle on click when no-toggle is set', async () => {
|
|
25
61
|
const el = await fixture<ZnReveal>(html`
|
|
26
62
|
<zn-reveal initial="****" revealed="real" no-toggle></zn-reveal>
|
|
@@ -846,7 +846,7 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
846
846
|
group.hidden = false;
|
|
847
847
|
});
|
|
848
848
|
this.updateOptGroupSeparators();
|
|
849
|
-
this.
|
|
849
|
+
this.updateEmptyState();
|
|
850
850
|
return;
|
|
851
851
|
}
|
|
852
852
|
|
|
@@ -887,6 +887,19 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
889
|
|
|
890
|
+
/**
|
|
891
|
+
* Nothing for the user to pick: either the option list is empty or every option is filtered out.
|
|
892
|
+
* The search paths track this themselves, so this covers opening a dropdown with no query.
|
|
893
|
+
*/
|
|
894
|
+
private updateEmptyState() {
|
|
895
|
+
const options = this.getAllOptions();
|
|
896
|
+
this._noResultsVisible = options.length === 0 || options.every(option => option.hidden);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
private get emptyStateText(): string {
|
|
900
|
+
return this._searchQuery ? 'No matching options' : 'No options available';
|
|
901
|
+
}
|
|
902
|
+
|
|
890
903
|
/** Clears the search query and shows all options */
|
|
891
904
|
private clearSearch() {
|
|
892
905
|
this._searchQuery = '';
|
|
@@ -1132,6 +1145,10 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
1132
1145
|
this.emit('zn-input');
|
|
1133
1146
|
this.emit('zn-change');
|
|
1134
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
if (this.open) {
|
|
1150
|
+
this.updateEmptyState();
|
|
1151
|
+
}
|
|
1135
1152
|
}
|
|
1136
1153
|
|
|
1137
1154
|
private handleTagRemove(event: ZnRemoveEvent, option: ZnOption) {
|
|
@@ -1653,6 +1670,8 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
1653
1670
|
this.displayInput.readOnly = false;
|
|
1654
1671
|
}
|
|
1655
1672
|
|
|
1673
|
+
this.updateEmptyState();
|
|
1674
|
+
|
|
1656
1675
|
// Show
|
|
1657
1676
|
this.emit('zn-show');
|
|
1658
1677
|
this.addOpenListeners();
|
|
@@ -2041,7 +2060,7 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
|
|
|
2041
2060
|
: html`
|
|
2042
2061
|
<div part="empty-state" class="select__empty-state"
|
|
2043
2062
|
?hidden=${!this._noResultsVisible || this._freeTextAddValue !== null}>
|
|
2044
|
-
|
|
2063
|
+
${this.emptyStateText}
|
|
2045
2064
|
</div>`
|
|
2046
2065
|
}
|
|
2047
2066
|
</div>
|
|
@@ -444,7 +444,7 @@
|
|
|
444
444
|
align-items: center;
|
|
445
445
|
justify-content: center;
|
|
446
446
|
gap: var(--zn-spacing-small);
|
|
447
|
-
padding: var(--zn-spacing-
|
|
447
|
+
padding: var(--zn-spacing-small) var(--zn-spacing-medium);
|
|
448
448
|
color: var(--zn-color-neutral-500);
|
|
449
449
|
font-size: var(--zn-font-size-medium);
|
|
450
450
|
}
|
|
@@ -463,7 +463,8 @@
|
|
|
463
463
|
/* Empty state (no search results) */
|
|
464
464
|
.select__empty-state {
|
|
465
465
|
display: block;
|
|
466
|
-
|
|
466
|
+
// Keeps the one-line popup close to the height of a single option row
|
|
467
|
+
padding: var(--zn-spacing-small) var(--zn-spacing-medium);
|
|
467
468
|
text-align: center;
|
|
468
469
|
color: var(--zn-color-neutral-500);
|
|
469
470
|
font-size: var(--zn-font-size-medium);
|
|
@@ -978,3 +978,62 @@ describe('<zn-select> requires', () => {
|
|
|
978
978
|
expect(c.disabled, 'both filled').to.be.false;
|
|
979
979
|
});
|
|
980
980
|
});
|
|
981
|
+
|
|
982
|
+
describe('<zn-select> empty state', () => {
|
|
983
|
+
const emptyState = (el: ZnSelect) =>
|
|
984
|
+
el.shadowRoot!.querySelector<HTMLElement>('[part="empty-state"]')!;
|
|
985
|
+
|
|
986
|
+
it('should tell the user there is nothing to pick when opened with no options', async () => {
|
|
987
|
+
const el = await fixture<ZnSelect>(html`
|
|
988
|
+
<zn-select placeholder="Select a reason"></zn-select>`);
|
|
989
|
+
await el.show();
|
|
990
|
+
await el.updateComplete;
|
|
991
|
+
|
|
992
|
+
expect(emptyState(el).hidden).to.be.false;
|
|
993
|
+
expect(emptyState(el).textContent!.trim()).to.equal('No options available');
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
it('should stay hidden when the select has options', async () => {
|
|
997
|
+
const el = await fixture<ZnSelect>(html`
|
|
998
|
+
<zn-select>
|
|
999
|
+
<zn-option value="apple">Apple</zn-option>
|
|
1000
|
+
</zn-select>`);
|
|
1001
|
+
await el.show();
|
|
1002
|
+
await el.updateComplete;
|
|
1003
|
+
|
|
1004
|
+
expect(emptyState(el).hidden).to.be.true;
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
it('should distinguish a filtered-out list from an empty one', async () => {
|
|
1008
|
+
const el = await fixture<ZnSelect>(html`
|
|
1009
|
+
<zn-select search>
|
|
1010
|
+
<zn-option value="apple">Apple</zn-option>
|
|
1011
|
+
</zn-select>`);
|
|
1012
|
+
await el.show();
|
|
1013
|
+
await el.updateComplete;
|
|
1014
|
+
|
|
1015
|
+
const displayInput = el.shadowRoot!.querySelector<HTMLInputElement>('.select__display-input')!;
|
|
1016
|
+
displayInput.value = 'zzz';
|
|
1017
|
+
displayInput.dispatchEvent(new Event('input'));
|
|
1018
|
+
await el.updateComplete;
|
|
1019
|
+
|
|
1020
|
+
expect(emptyState(el).hidden).to.be.false;
|
|
1021
|
+
expect(emptyState(el).textContent!.trim()).to.equal('No matching options');
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
it('should drop the empty state once options arrive while open', async () => {
|
|
1025
|
+
const el = await fixture<ZnSelect>(html`
|
|
1026
|
+
<zn-select></zn-select>`);
|
|
1027
|
+
await el.show();
|
|
1028
|
+
await el.updateComplete;
|
|
1029
|
+
expect(emptyState(el).hidden, 'empty before options').to.be.false;
|
|
1030
|
+
|
|
1031
|
+
const option = document.createElement('zn-option');
|
|
1032
|
+
option.value = 'apple';
|
|
1033
|
+
option.textContent = 'Apple';
|
|
1034
|
+
el.appendChild(option);
|
|
1035
|
+
await waitUntil(() => emptyState(el).hidden);
|
|
1036
|
+
|
|
1037
|
+
expect(emptyState(el).hidden).to.be.true;
|
|
1038
|
+
});
|
|
1039
|
+
});
|