@commmerce/ui 1.19.0 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn.js +512 -535
- package/dist/components/link-tabs.d.ts +8 -1
- package/dist/components/link-tabs.js +55 -4
- package/dist/custom-elements.json +46 -1
- package/package.json +5 -5
|
@@ -12,7 +12,8 @@ declare module '../localize.js' {
|
|
|
12
12
|
/**
|
|
13
13
|
* A row of links between sibling pages, such as the sections of Settings or the parts of a product
|
|
14
14
|
* (Details, Variants, Inventory). It looks like Status tabs but each tab is a link to its own page:
|
|
15
|
-
* the current page is black and underlined. Too many tabs for the width scroll sideways
|
|
15
|
+
* the current page is black and underlined. Too many tabs for the width scroll sideways: the row fades at the edge that
|
|
16
|
+
* has more tabs past it (1.20.1), and the current tab is scrolled into view.
|
|
16
17
|
*
|
|
17
18
|
* To filter one list without leaving the page, use Status tabs instead.
|
|
18
19
|
* @element cm-link-tabs
|
|
@@ -31,15 +32,21 @@ export declare class CmLinkTabs extends CmLocalizedElement {
|
|
|
31
32
|
_slotted: {
|
|
32
33
|
state: boolean;
|
|
33
34
|
};
|
|
35
|
+
_more: {
|
|
36
|
+
state: boolean;
|
|
37
|
+
};
|
|
34
38
|
};
|
|
35
39
|
/** Tabs as data (`{ label, href, current }`). Used instead of `cm-nav-item` children when set. */
|
|
36
40
|
items: NavItem[];
|
|
37
41
|
/** Accessible name of the navigation, e.g. "Settings sections". Default: the built-in string `label` ("Sections"). */
|
|
38
42
|
label: string;
|
|
39
43
|
_slotted: NavItem[];
|
|
44
|
+
_more: string;
|
|
40
45
|
static styles: import("lit").CSSResult[];
|
|
41
46
|
connectedCallback(): void;
|
|
42
47
|
disconnectedCallback(): void;
|
|
48
|
+
firstUpdated(): void;
|
|
49
|
+
updated(): void;
|
|
43
50
|
/** The tabs in use. */
|
|
44
51
|
get tabs(): NavItem[];
|
|
45
52
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmLinkTabs_instances, _CmLinkTabs_observer, _CmLinkTabs_read;
|
|
12
|
+
var _CmLinkTabs_instances, _CmLinkTabs_observer, _CmLinkTabs_resize, _CmLinkTabs_shown, _CmLinkTabs_reveal, _CmLinkTabs_measure, _CmLinkTabs_read;
|
|
13
13
|
import { html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
@@ -21,7 +21,8 @@ const strings = defineStrings('linkTabs', {
|
|
|
21
21
|
/**
|
|
22
22
|
* A row of links between sibling pages, such as the sections of Settings or the parts of a product
|
|
23
23
|
* (Details, Variants, Inventory). It looks like Status tabs but each tab is a link to its own page:
|
|
24
|
-
* the current page is black and underlined. Too many tabs for the width scroll sideways
|
|
24
|
+
* the current page is black and underlined. Too many tabs for the width scroll sideways: the row fades at the edge that
|
|
25
|
+
* has more tabs past it (1.20.1), and the current tab is scrolled into view.
|
|
25
26
|
*
|
|
26
27
|
* To filter one list without leaving the page, use Status tabs instead.
|
|
27
28
|
* @element cm-link-tabs
|
|
@@ -35,7 +36,10 @@ export class CmLinkTabs extends CmLocalizedElement {
|
|
|
35
36
|
/** Tabs as data (`{ label, href, current }`). Used instead of `cm-nav-item` children when set. */
|
|
36
37
|
this.items = [];
|
|
37
38
|
this._slotted = [];
|
|
39
|
+
this._more = '';
|
|
38
40
|
_CmLinkTabs_observer.set(this, void 0);
|
|
41
|
+
_CmLinkTabs_resize.set(this, new ResizeObserver(() => __classPrivateFieldGet(this, _CmLinkTabs_instances, "m", _CmLinkTabs_measure).call(this)));
|
|
42
|
+
_CmLinkTabs_shown.set(this, '');
|
|
39
43
|
}
|
|
40
44
|
connectedCallback() {
|
|
41
45
|
super.connectedCallback();
|
|
@@ -45,23 +49,63 @@ export class CmLinkTabs extends CmLocalizedElement {
|
|
|
45
49
|
disconnectedCallback() {
|
|
46
50
|
super.disconnectedCallback();
|
|
47
51
|
__classPrivateFieldGet(this, _CmLinkTabs_observer, "f")?.disconnect();
|
|
52
|
+
__classPrivateFieldGet(this, _CmLinkTabs_resize, "f").disconnect();
|
|
53
|
+
}
|
|
54
|
+
firstUpdated() {
|
|
55
|
+
const row = this.renderRoot.querySelector('ul');
|
|
56
|
+
__classPrivateFieldGet(this, _CmLinkTabs_resize, "f").observe(row);
|
|
57
|
+
row.addEventListener('scroll', () => __classPrivateFieldGet(this, _CmLinkTabs_instances, "m", _CmLinkTabs_measure).call(this), { passive: true });
|
|
58
|
+
document.fonts?.ready.then(() => __classPrivateFieldGet(this, _CmLinkTabs_instances, "m", _CmLinkTabs_measure).call(this));
|
|
59
|
+
}
|
|
60
|
+
updated() {
|
|
61
|
+
// Measure after every render and watch each tab: badges or the web font can widen tabs without resizing the row.
|
|
62
|
+
for (const li of this.renderRoot.querySelectorAll('li'))
|
|
63
|
+
__classPrivateFieldGet(this, _CmLinkTabs_resize, "f").observe(li);
|
|
64
|
+
__classPrivateFieldGet(this, _CmLinkTabs_instances, "m", _CmLinkTabs_reveal).call(this);
|
|
65
|
+
__classPrivateFieldGet(this, _CmLinkTabs_instances, "m", _CmLinkTabs_measure).call(this);
|
|
48
66
|
}
|
|
49
67
|
/** The tabs in use. */
|
|
50
68
|
get tabs() { return this.items.length ? this.items : this._slotted; }
|
|
51
69
|
render() {
|
|
52
70
|
return html `<nav part="nav" aria-label=${this.label || this.t('label')}>
|
|
53
|
-
<ul part="tabs">${this.tabs.map((t) => html `<li><a part="tab" href=${t.href || '#'} aria-current=${t.current ? 'page' : nothing}
|
|
71
|
+
<ul part="tabs" class=${this._more ? `more-${this._more}` : ''}>${this.tabs.map((t) => html `<li><a part="tab" href=${t.href || '#'} aria-current=${t.current ? 'page' : nothing}
|
|
54
72
|
@click=${(e) => { if (!fireNavigate(this, t))
|
|
55
73
|
e.preventDefault(); }}>${t.label}${t.badge ? html `<span class="badge">(${t.badge})</span>` : nothing}</a></li>`)}</ul>
|
|
56
74
|
<slot hidden></slot>
|
|
57
75
|
</nav>`;
|
|
58
76
|
}
|
|
59
77
|
}
|
|
60
|
-
_CmLinkTabs_observer = new WeakMap(),
|
|
78
|
+
_CmLinkTabs_observer = new WeakMap(), _CmLinkTabs_resize = new WeakMap(), _CmLinkTabs_shown = new WeakMap(), _CmLinkTabs_instances = new WeakSet(), _CmLinkTabs_reveal = function _CmLinkTabs_reveal() {
|
|
79
|
+
const row = this.renderRoot.querySelector('ul');
|
|
80
|
+
const a = this.renderRoot.querySelector('a[aria-current="page"]');
|
|
81
|
+
const key = a?.getAttribute('href') ?? '';
|
|
82
|
+
if (!row || !a || key === __classPrivateFieldGet(this, _CmLinkTabs_shown, "f") || row.scrollWidth <= row.clientWidth)
|
|
83
|
+
return;
|
|
84
|
+
__classPrivateFieldSet(this, _CmLinkTabs_shown, key, "f");
|
|
85
|
+
const r = row.getBoundingClientRect();
|
|
86
|
+
const t = a.getBoundingClientRect();
|
|
87
|
+
const pad = 32;
|
|
88
|
+
if (t.right > r.right - pad)
|
|
89
|
+
row.scrollLeft += t.right - r.right + pad;
|
|
90
|
+
else if (t.left < r.left + pad)
|
|
91
|
+
row.scrollLeft -= r.left + pad - t.left;
|
|
92
|
+
}, _CmLinkTabs_measure = function _CmLinkTabs_measure() {
|
|
93
|
+
const row = this.renderRoot.querySelector('ul');
|
|
94
|
+
if (!row)
|
|
95
|
+
return;
|
|
96
|
+
const max = row.scrollWidth - row.clientWidth;
|
|
97
|
+
const at = Math.abs(row.scrollLeft); // negative in right-to-left rows
|
|
98
|
+
const start = max > 1 && at > 1;
|
|
99
|
+
const end = max > 1 && at < max - 1;
|
|
100
|
+
const more = start && end ? 'both' : start ? 'start' : end ? 'end' : '';
|
|
101
|
+
if (more !== this._more)
|
|
102
|
+
this._more = more;
|
|
103
|
+
}, _CmLinkTabs_read = function _CmLinkTabs_read() { this._slotted = readNavItems(this); };
|
|
61
104
|
CmLinkTabs.properties = {
|
|
62
105
|
items: { type: Array },
|
|
63
106
|
label: { string: 'label' },
|
|
64
107
|
_slotted: { state: true },
|
|
108
|
+
_more: { state: true },
|
|
65
109
|
};
|
|
66
110
|
CmLinkTabs.styles = [
|
|
67
111
|
base,
|
|
@@ -82,6 +126,13 @@ CmLinkTabs.styles = [
|
|
|
82
126
|
a[aria-current='page']::after { background: var(--cm-tab-indicator); }
|
|
83
127
|
a:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; border-radius: var(--cm-radius-xs); }
|
|
84
128
|
.badge { font-size: var(--cm-font-size-12); color: var(--cm-text-tertiary); font-variant-numeric: tabular-nums; }
|
|
129
|
+
/* Scroll affordance, as in Status tabs: the edge with more tabs past it fades out over 32px, so a cut-off row reads
|
|
130
|
+
as one that scrolls. The mask is a gradient of opacity, so it works on any background and theme. */
|
|
131
|
+
ul.more-end { mask-image: linear-gradient(to right, #000 calc(100% - var(--cm-space-32)), transparent); }
|
|
132
|
+
ul.more-start { mask-image: linear-gradient(to left, #000 calc(100% - var(--cm-space-32)), transparent); }
|
|
133
|
+
ul.more-both { mask-image: linear-gradient(to right, transparent, #000 var(--cm-space-32), #000 calc(100% - var(--cm-space-32)), transparent); }
|
|
134
|
+
:host(:dir(rtl)) ul.more-end { mask-image: linear-gradient(to left, #000 calc(100% - var(--cm-space-32)), transparent); }
|
|
135
|
+
:host(:dir(rtl)) ul.more-start { mask-image: linear-gradient(to right, #000 calc(100% - var(--cm-space-32)), transparent); }
|
|
85
136
|
@media (max-width: 640px) { ul { gap: var(--cm-space-16); } }
|
|
86
137
|
|
|
87
138
|
`,
|
|
@@ -21802,7 +21802,7 @@
|
|
|
21802
21802
|
"declarations": [
|
|
21803
21803
|
{
|
|
21804
21804
|
"kind": "class",
|
|
21805
|
-
"description": "A row of links between sibling pages, such as the sections of Settings or the parts of a product\n(Details, Variants, Inventory). It looks like Status tabs but each tab is a link to its own page:\nthe current page is black and underlined. Too many tabs for the width scroll sideways.\n\nTo filter one list without leaving the page, use Status tabs instead.",
|
|
21805
|
+
"description": "A row of links between sibling pages, such as the sections of Settings or the parts of a product\n(Details, Variants, Inventory). It looks like Status tabs but each tab is a link to its own page:\nthe current page is black and underlined. Too many tabs for the width scroll sideways: the row fades at the edge that\nhas more tabs past it (1.20.1), and the current tab is scrolled into view.\n\nTo filter one list without leaving the page, use Status tabs instead.",
|
|
21806
21806
|
"name": "CmLinkTabs",
|
|
21807
21807
|
"slots": [
|
|
21808
21808
|
{
|
|
@@ -21842,6 +21842,16 @@
|
|
|
21842
21842
|
"default": "[]",
|
|
21843
21843
|
"attribute": "_slotted"
|
|
21844
21844
|
},
|
|
21845
|
+
{
|
|
21846
|
+
"kind": "field",
|
|
21847
|
+
"name": "_more",
|
|
21848
|
+
"privacy": "public",
|
|
21849
|
+
"type": {
|
|
21850
|
+
"text": "string"
|
|
21851
|
+
},
|
|
21852
|
+
"default": "''",
|
|
21853
|
+
"attribute": "_more"
|
|
21854
|
+
},
|
|
21845
21855
|
{
|
|
21846
21856
|
"kind": "field",
|
|
21847
21857
|
"name": "#observer",
|
|
@@ -21850,6 +21860,33 @@
|
|
|
21850
21860
|
"text": "MutationObserver | undefined"
|
|
21851
21861
|
}
|
|
21852
21862
|
},
|
|
21863
|
+
{
|
|
21864
|
+
"kind": "field",
|
|
21865
|
+
"name": "#resize",
|
|
21866
|
+
"privacy": "private",
|
|
21867
|
+
"default": "new ResizeObserver(() => this.#measure())"
|
|
21868
|
+
},
|
|
21869
|
+
{
|
|
21870
|
+
"kind": "field",
|
|
21871
|
+
"name": "#shown",
|
|
21872
|
+
"privacy": "private",
|
|
21873
|
+
"type": {
|
|
21874
|
+
"text": "string"
|
|
21875
|
+
},
|
|
21876
|
+
"default": "''"
|
|
21877
|
+
},
|
|
21878
|
+
{
|
|
21879
|
+
"kind": "method",
|
|
21880
|
+
"name": "#reveal",
|
|
21881
|
+
"privacy": "private",
|
|
21882
|
+
"description": "Scrolls the row (never the page) so the current tab is fully visible, once per current tab."
|
|
21883
|
+
},
|
|
21884
|
+
{
|
|
21885
|
+
"kind": "method",
|
|
21886
|
+
"name": "#measure",
|
|
21887
|
+
"privacy": "private",
|
|
21888
|
+
"description": "Works out which edges of the row have tabs past them (for the fade)."
|
|
21889
|
+
},
|
|
21853
21890
|
{
|
|
21854
21891
|
"kind": "field",
|
|
21855
21892
|
"name": "tabs",
|
|
@@ -21993,6 +22030,14 @@
|
|
|
21993
22030
|
"default": "[]",
|
|
21994
22031
|
"fieldName": "_slotted"
|
|
21995
22032
|
},
|
|
22033
|
+
{
|
|
22034
|
+
"name": "_more",
|
|
22035
|
+
"type": {
|
|
22036
|
+
"text": "string"
|
|
22037
|
+
},
|
|
22038
|
+
"default": "''",
|
|
22039
|
+
"fieldName": "_more"
|
|
22040
|
+
},
|
|
21996
22041
|
{
|
|
21997
22042
|
"name": "strings",
|
|
21998
22043
|
"type": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commmerce/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "Commmerce UI web components: build apps that feel native to the Commmerce admin. Works in plain HTML, React, Vue and server-rendered pages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -128,13 +128,13 @@
|
|
|
128
128
|
"test": "vitest run"
|
|
129
129
|
},
|
|
130
130
|
"dependencies": {
|
|
131
|
-
"@commmerce/icons": "1.
|
|
132
|
-
"@commmerce/tokens": "1.
|
|
131
|
+
"@commmerce/icons": "1.20.1",
|
|
132
|
+
"@commmerce/tokens": "1.20.1",
|
|
133
133
|
"lit": "3.2.1"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|
|
136
136
|
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
137
|
-
"@vitest/browser": "
|
|
138
|
-
"playwright": "
|
|
137
|
+
"@vitest/browser-playwright": "4.1.12",
|
|
138
|
+
"playwright": "1.64.1"
|
|
139
139
|
}
|
|
140
140
|
}
|