@commmerce/ui 1.9.1 → 1.9.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/dist/cdn.js +511 -467
- package/dist/components/account-menu.d.ts +118 -0
- package/dist/components/account-menu.js +114 -0
- package/dist/components/action-menu.d.ts +4 -0
- package/dist/components/action-menu.js +67 -5
- package/dist/components/button.js +1 -1
- package/dist/components/header-bar.d.ts +2 -1
- package/dist/components/header-bar.js +4 -2
- package/dist/custom-elements.json +1215 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { CmActionMenu } from './action-menu.js';
|
|
2
|
+
import './avatar.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
declare const strings: {
|
|
5
|
+
/** Accessible name of the avatar button. {name} is the signed-in person. */
|
|
6
|
+
trigger: string;
|
|
7
|
+
};
|
|
8
|
+
declare module '../localize.js' {
|
|
9
|
+
interface CmStrings {
|
|
10
|
+
accountMenu: typeof strings;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The signed-in person's menu at the end of a Commmerce product's header bar (since 1.9.2): a round avatar button that
|
|
15
|
+
* opens a panel with who is signed in (avatar, name, role and place), the business or store they're working in (its
|
|
16
|
+
* logo, name, kind and plan), then the choices: `cm-menu-item`s such as Settings, Lock screen and Log out. The panel
|
|
17
|
+
* is the action menu's: keyboard, outside click and Escape behave the same, and it opens in the top layer, aligned
|
|
18
|
+
* to the avatar's end edge. Put it in `cm-header-bar`'s `account` slot, so it is always last in the bar.
|
|
19
|
+
* For Commmerce products only, not for apps.
|
|
20
|
+
* @element cm-account-menu
|
|
21
|
+
* @slot - `cm-menu-item` elements (and `cm-menu-item divider`).
|
|
22
|
+
* @slot org-logo - The business's logo (an `<img>`, 40px round). Without it, a store icon on the brand tone is shown.
|
|
23
|
+
* @fires cm-select - When a choice is picked (as on `cm-action-menu`).
|
|
24
|
+
* @csspart trigger - The avatar button.
|
|
25
|
+
* @csspart profile - The signed-in person's row.
|
|
26
|
+
* @csspart org - The business row.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CmAccountMenu extends CmActionMenu {
|
|
29
|
+
static properties: {
|
|
30
|
+
name: {};
|
|
31
|
+
avatarSrc: {
|
|
32
|
+
attribute: string;
|
|
33
|
+
};
|
|
34
|
+
meta: {};
|
|
35
|
+
profileHref: {
|
|
36
|
+
attribute: string;
|
|
37
|
+
};
|
|
38
|
+
orgName: {
|
|
39
|
+
attribute: string;
|
|
40
|
+
};
|
|
41
|
+
orgMeta: {
|
|
42
|
+
attribute: string;
|
|
43
|
+
};
|
|
44
|
+
orgHref: {
|
|
45
|
+
attribute: string;
|
|
46
|
+
};
|
|
47
|
+
plan: {};
|
|
48
|
+
items: {
|
|
49
|
+
type: ArrayConstructor;
|
|
50
|
+
};
|
|
51
|
+
open: {
|
|
52
|
+
type: BooleanConstructor;
|
|
53
|
+
reflect: boolean;
|
|
54
|
+
};
|
|
55
|
+
label: {
|
|
56
|
+
string: string;
|
|
57
|
+
};
|
|
58
|
+
triggerLabel: {
|
|
59
|
+
attribute: string;
|
|
60
|
+
};
|
|
61
|
+
iconOnly: {
|
|
62
|
+
type: BooleanConstructor;
|
|
63
|
+
attribute: string;
|
|
64
|
+
};
|
|
65
|
+
icon: {};
|
|
66
|
+
align: {
|
|
67
|
+
reflect: boolean;
|
|
68
|
+
};
|
|
69
|
+
heading: {};
|
|
70
|
+
subheading: {};
|
|
71
|
+
density: {
|
|
72
|
+
reflect: boolean;
|
|
73
|
+
};
|
|
74
|
+
loading: {
|
|
75
|
+
type: BooleanConstructor;
|
|
76
|
+
reflect: boolean;
|
|
77
|
+
};
|
|
78
|
+
disabled: {
|
|
79
|
+
type: BooleanConstructor;
|
|
80
|
+
reflect: boolean;
|
|
81
|
+
};
|
|
82
|
+
_slotted: {
|
|
83
|
+
state: boolean;
|
|
84
|
+
};
|
|
85
|
+
_active: {
|
|
86
|
+
state: boolean;
|
|
87
|
+
};
|
|
88
|
+
_custom: {
|
|
89
|
+
state: boolean;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/** The signed-in person's name. Their initials show when there is no `avatar-src`. */
|
|
93
|
+
name: string;
|
|
94
|
+
/** Their photo. */
|
|
95
|
+
avatarSrc: string;
|
|
96
|
+
/** One line under the name: role and place ("Owner · Bangalore"). */
|
|
97
|
+
meta: string;
|
|
98
|
+
/** Their profile page; makes the row a link with a chevron. */
|
|
99
|
+
profileHref: string;
|
|
100
|
+
/** The business or store they're working in ("Bangalore"). Empty hides the business row. */
|
|
101
|
+
orgName: string;
|
|
102
|
+
/** One line under it ("POS store"). */
|
|
103
|
+
orgMeta: string;
|
|
104
|
+
/** The business's page or switcher; makes the row a link with a chevron. */
|
|
105
|
+
orgHref: string;
|
|
106
|
+
/** The plan, shown under the business with a check ("POS Standard"). */
|
|
107
|
+
plan: string;
|
|
108
|
+
constructor();
|
|
109
|
+
static styles: import("lit").CSSResult[];
|
|
110
|
+
protected triggerTemplate(click: (e: Event) => void, key: (e: KeyboardEvent) => void): import("lit-html").TemplateResult<1>;
|
|
111
|
+
protected headTemplate(): import("lit-html").TemplateResult<1>;
|
|
112
|
+
}
|
|
113
|
+
declare global {
|
|
114
|
+
interface HTMLElementTagNameMap {
|
|
115
|
+
'cm-account-menu': CmAccountMenu;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { html, css, nothing } from 'lit';
|
|
2
|
+
import { define } from '../base.js';
|
|
3
|
+
import { defineStrings } from '../localize.js';
|
|
4
|
+
import { CmActionMenu } from './action-menu.js';
|
|
5
|
+
import './avatar.js';
|
|
6
|
+
import './icon.js';
|
|
7
|
+
const strings = defineStrings('accountMenu', {
|
|
8
|
+
/** Accessible name of the avatar button. {name} is the signed-in person. */
|
|
9
|
+
trigger: 'Account: {name}',
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The signed-in person's menu at the end of a Commmerce product's header bar (since 1.9.2): a round avatar button that
|
|
13
|
+
* opens a panel with who is signed in (avatar, name, role and place), the business or store they're working in (its
|
|
14
|
+
* logo, name, kind and plan), then the choices: `cm-menu-item`s such as Settings, Lock screen and Log out. The panel
|
|
15
|
+
* is the action menu's: keyboard, outside click and Escape behave the same, and it opens in the top layer, aligned
|
|
16
|
+
* to the avatar's end edge. Put it in `cm-header-bar`'s `account` slot, so it is always last in the bar.
|
|
17
|
+
* For Commmerce products only, not for apps.
|
|
18
|
+
* @element cm-account-menu
|
|
19
|
+
* @slot - `cm-menu-item` elements (and `cm-menu-item divider`).
|
|
20
|
+
* @slot org-logo - The business's logo (an `<img>`, 40px round). Without it, a store icon on the brand tone is shown.
|
|
21
|
+
* @fires cm-select - When a choice is picked (as on `cm-action-menu`).
|
|
22
|
+
* @csspart trigger - The avatar button.
|
|
23
|
+
* @csspart profile - The signed-in person's row.
|
|
24
|
+
* @csspart org - The business row.
|
|
25
|
+
*/
|
|
26
|
+
export class CmAccountMenu extends CmActionMenu {
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
/** The signed-in person's name. Their initials show when there is no `avatar-src`. */
|
|
30
|
+
this.name = '';
|
|
31
|
+
/** Their photo. */
|
|
32
|
+
this.avatarSrc = '';
|
|
33
|
+
/** One line under the name: role and place ("Owner · Bangalore"). */
|
|
34
|
+
this.meta = '';
|
|
35
|
+
/** Their profile page; makes the row a link with a chevron. */
|
|
36
|
+
this.profileHref = '';
|
|
37
|
+
/** The business or store they're working in ("Bangalore"). Empty hides the business row. */
|
|
38
|
+
this.orgName = '';
|
|
39
|
+
/** One line under it ("POS store"). */
|
|
40
|
+
this.orgMeta = '';
|
|
41
|
+
/** The business's page or switcher; makes the row a link with a chevron. */
|
|
42
|
+
this.orgHref = '';
|
|
43
|
+
/** The plan, shown under the business with a check ("POS Standard"). */
|
|
44
|
+
this.plan = '';
|
|
45
|
+
this.align = 'end';
|
|
46
|
+
}
|
|
47
|
+
triggerTemplate(click, key) {
|
|
48
|
+
return html `<button type="button" class="trigger account" part="trigger" aria-haspopup="menu" aria-expanded=${String(this.open)}
|
|
49
|
+
aria-label=${this.t('trigger', { name: this.name })} ?disabled=${this.disabled} @click=${click} @keydown=${key}>
|
|
50
|
+
<cm-avatar name=${this.name} src=${this.avatarSrc || nothing} decorative></cm-avatar></button>`;
|
|
51
|
+
}
|
|
52
|
+
headTemplate() {
|
|
53
|
+
const row = (href, part, lead, title, sub) => {
|
|
54
|
+
const inner = html `${lead}<span class="who"><strong>${title}</strong>${sub ? html `<span>${sub}</span>` : nothing}</span>${href
|
|
55
|
+
? html `<cm-icon class="chev" name="chevron-right" size="16"></cm-icon>` : nothing}`;
|
|
56
|
+
return href ? html `<a class="row" part=${part} href=${href}>${inner}</a>` : html `<div class="row" part=${part}>${inner}</div>`;
|
|
57
|
+
};
|
|
58
|
+
return html `<div class="acct">
|
|
59
|
+
${row(this.profileHref, 'profile', html `<span class="ring"><cm-avatar name=${this.name} src=${this.avatarSrc || nothing} decorative></cm-avatar></span>`, this.name, this.meta)}
|
|
60
|
+
${this.orgName ? html `<div class="split"></div>
|
|
61
|
+
${row(this.orgHref, 'org', html `<span class="logo"><slot name="org-logo"><cm-icon name="store" size="20"></cm-icon></slot></span>`, this.orgName, this.orgMeta)}
|
|
62
|
+
${this.plan ? html `<div class="plan"><cm-icon name="check-circle" size="16"></cm-icon>${this.plan}</div>` : nothing}` : nothing}
|
|
63
|
+
</div>`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
CmAccountMenu.properties = {
|
|
67
|
+
...CmActionMenu.properties,
|
|
68
|
+
name: {},
|
|
69
|
+
avatarSrc: { attribute: 'avatar-src' },
|
|
70
|
+
meta: {},
|
|
71
|
+
profileHref: { attribute: 'profile-href' },
|
|
72
|
+
orgName: { attribute: 'org-name' },
|
|
73
|
+
orgMeta: { attribute: 'org-meta' },
|
|
74
|
+
orgHref: { attribute: 'org-href' },
|
|
75
|
+
plan: {},
|
|
76
|
+
};
|
|
77
|
+
CmAccountMenu.styles = [
|
|
78
|
+
...CmActionMenu.styles,
|
|
79
|
+
css `
|
|
80
|
+
/* The avatar button: 36px round with a ring (40 and a 44px hit area on touch screens). */
|
|
81
|
+
.trigger.account {
|
|
82
|
+
position: relative; width: var(--cm-control-height-md, 36px); height: var(--cm-control-height-md, 36px); min-height: 0; padding: 2px;
|
|
83
|
+
border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full); background: var(--cm-bg-surface);
|
|
84
|
+
}
|
|
85
|
+
.trigger.account:hover { background: var(--cm-bg-hover); }
|
|
86
|
+
.trigger.account cm-avatar { --cm-avatar-size: 28px; } /* 36 less the 2px gap and 1px ring on each side */
|
|
87
|
+
@media (pointer: coarse) {
|
|
88
|
+
.trigger.account { width: var(--cm-control-height-lg, 40px); height: var(--cm-control-height-lg, 40px); }
|
|
89
|
+
.trigger.account cm-avatar { --cm-avatar-size: 32px; }
|
|
90
|
+
.trigger.account::after { content: ''; position: absolute; inset: -3px; }
|
|
91
|
+
}
|
|
92
|
+
.pop { width: min(320px, calc(100vw - 32px)); }
|
|
93
|
+
.acct { display: flex; flex-direction: column; padding: var(--cm-space-4) 0; margin-bottom: var(--cm-space-4); border-bottom: var(--cm-border-1) solid var(--cm-border-subtle); }
|
|
94
|
+
.row {
|
|
95
|
+
display: flex; align-items: center; gap: var(--cm-space-12); padding: var(--cm-space-8) var(--cm-space-12); border-radius: var(--cm-radius-sm);
|
|
96
|
+
color: var(--cm-text-default); text-decoration: none;
|
|
97
|
+
}
|
|
98
|
+
a.row:hover { background: var(--cm-bg-hover); }
|
|
99
|
+
a.row:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: -2px; }
|
|
100
|
+
.ring { flex: none; display: grid; place-items: center; width: 40px; height: 40px; box-sizing: border-box; padding: 2px; border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full); }
|
|
101
|
+
.ring cm-avatar { --cm-avatar-size: 34px; }
|
|
102
|
+
.logo { flex: none; display: grid; place-items: center; width: 40px; height: 40px; overflow: hidden; border-radius: var(--cm-radius-full); background: var(--cm-bg-brand, var(--cm-action-primary)); color: var(--cm-text-on-brand, var(--cm-action-primary-text)); }
|
|
103
|
+
::slotted([slot='org-logo']) { width: 40px; height: 40px; object-fit: cover; }
|
|
104
|
+
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
105
|
+
.who strong { font-size: var(--cm-font-size-16); line-height: var(--cm-line-height-16); font-weight: 500; overflow-wrap: anywhere; }
|
|
106
|
+
.who span { font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); color: var(--cm-text-tertiary); overflow-wrap: anywhere; }
|
|
107
|
+
.chev { flex: none; color: var(--cm-icon-default); }
|
|
108
|
+
.plan { display: flex; align-items: center; gap: var(--cm-space-8); padding: 0 var(--cm-space-12) var(--cm-space-8); font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); color: var(--cm-text-tertiary); }
|
|
109
|
+
.plan cm-icon { color: var(--cm-text-success); }
|
|
110
|
+
.split { height: 0; margin: var(--cm-space-4) var(--cm-space-12); border-top: var(--cm-border-1) solid var(--cm-border-subtle); }
|
|
111
|
+
:host(:dir(rtl)) .chev { transform: scaleX(-1); }
|
|
112
|
+
`,
|
|
113
|
+
];
|
|
114
|
+
define('cm-account-menu', CmAccountMenu);
|
|
@@ -119,6 +119,10 @@ export declare class CmActionMenu extends CmLocalizedElement {
|
|
|
119
119
|
/** Closes the menu. With `returnFocus`, focus goes back to the trigger. */
|
|
120
120
|
hide(returnFocus?: boolean): void;
|
|
121
121
|
protected updated(changed: PropertyValues): void;
|
|
122
|
+
/** @internal A subclass's own trigger (it must carry class="trigger"); undefined keeps the standard one. */
|
|
123
|
+
protected triggerTemplate(_click: (e: Event) => void, _key: (e: KeyboardEvent) => void): unknown;
|
|
124
|
+
/** @internal A subclass's own content above the choices; undefined keeps the heading/subheading block. */
|
|
125
|
+
protected headTemplate(): unknown;
|
|
122
126
|
render(): import("lit-html").TemplateResult<1>;
|
|
123
127
|
}
|
|
124
128
|
declare global {
|
|
@@ -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 _CmActionMenu_instances, _CmActionMenu_observer, _CmActionMenu_id, _CmActionMenu_typed, _CmActionMenu_typedAt, _CmActionMenu_read, _CmActionMenu_outside, _CmActionMenu_trigger, _CmActionMenu_enabled, _CmActionMenu_setOpen, _CmActionMenu_focusActive, _CmActionMenu_fit, _CmActionMenu_triggerKey, _CmActionMenu_triggerClick, _CmActionMenu_move, _CmActionMenu_menuKey, _CmActionMenu_choose, _CmActionMenu_item, _CmActionMenu_rows;
|
|
12
|
+
var _CmActionMenu_instances, _CmActionMenu_observer, _CmActionMenu_id, _CmActionMenu_typed, _CmActionMenu_typedAt, _CmActionMenu_read, _CmActionMenu_outside, _CmActionMenu_trigger, _CmActionMenu_enabled, _CmActionMenu_setOpen, _CmActionMenu_focusActive, _CmActionMenu_fit, _CmActionMenu_place, _CmActionMenu_onMove, _CmActionMenu_following, _CmActionMenu_follow, _CmActionMenu_triggerKey, _CmActionMenu_triggerClick, _CmActionMenu_move, _CmActionMenu_menuKey, _CmActionMenu_choose, _CmActionMenu_item, _CmActionMenu_rows;
|
|
13
13
|
import { html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define, nextId } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
@@ -76,6 +76,9 @@ export class CmActionMenu extends CmLocalizedElement {
|
|
|
76
76
|
_CmActionMenu_typedAt.set(this, 0);
|
|
77
77
|
_CmActionMenu_outside.set(this, (e) => { if (this.open && !e.composedPath().includes(this))
|
|
78
78
|
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_setOpen).call(this, false); });
|
|
79
|
+
_CmActionMenu_onMove.set(this, () => { const pop = this.renderRoot.querySelector('.pop'); if (pop && this.open)
|
|
80
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_place).call(this, pop); });
|
|
81
|
+
_CmActionMenu_following.set(this, false);
|
|
79
82
|
_CmActionMenu_triggerKey.set(this, (e) => {
|
|
80
83
|
if (this.disabled)
|
|
81
84
|
return;
|
|
@@ -151,6 +154,7 @@ export class CmActionMenu extends CmLocalizedElement {
|
|
|
151
154
|
super.disconnectedCallback();
|
|
152
155
|
__classPrivateFieldGet(this, _CmActionMenu_observer, "f")?.disconnect();
|
|
153
156
|
document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmActionMenu_outside, "f"), true);
|
|
157
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, false);
|
|
154
158
|
}
|
|
155
159
|
/** The choices in use. */
|
|
156
160
|
get menuItems() { return this.items.length ? this.items : this._slotted; }
|
|
@@ -170,6 +174,15 @@ export class CmActionMenu extends CmLocalizedElement {
|
|
|
170
174
|
updated(changed) {
|
|
171
175
|
if (changed.has('open') && this.open)
|
|
172
176
|
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_fit).call(this);
|
|
177
|
+
if (changed.has('open') && !this.open) {
|
|
178
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, false);
|
|
179
|
+
const pop = this.renderRoot.querySelector('.pop');
|
|
180
|
+
try {
|
|
181
|
+
if (pop?.matches(':popover-open'))
|
|
182
|
+
pop.hidePopover();
|
|
183
|
+
}
|
|
184
|
+
catch { /* already hidden */ }
|
|
185
|
+
}
|
|
173
186
|
if (this._custom) {
|
|
174
187
|
const t = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this);
|
|
175
188
|
if (t) {
|
|
@@ -187,19 +200,23 @@ export class CmActionMenu extends CmLocalizedElement {
|
|
|
187
200
|
this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
|
|
188
201
|
}
|
|
189
202
|
}
|
|
203
|
+
/** @internal A subclass's own trigger (it must carry class="trigger"); undefined keeps the standard one. */
|
|
204
|
+
triggerTemplate(_click, _key) { return undefined; }
|
|
205
|
+
/** @internal A subclass's own content above the choices; undefined keeps the heading/subheading block. */
|
|
206
|
+
headTemplate() { return undefined; }
|
|
190
207
|
render() {
|
|
191
208
|
const items = this.menuItems;
|
|
192
209
|
const name = this.triggerLabel || this.label;
|
|
193
210
|
const trigger = this._custom
|
|
194
211
|
? html `<slot name="trigger" @click=${__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")} @slotchange=${() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_read).call(this)}></slot>`
|
|
195
|
-
: html `<button type="button" class="trigger ${this.iconOnly ? 'icon' : ''}" part="trigger" aria-haspopup="menu"
|
|
212
|
+
: this.triggerTemplate(__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f"), __classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")) ?? html `<button type="button" class="trigger ${this.iconOnly ? 'icon' : ''}" part="trigger" aria-haspopup="menu"
|
|
196
213
|
aria-expanded=${String(this.open)} aria-controls="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.iconOnly ? name : nothing}
|
|
197
214
|
?disabled=${this.disabled} @click=${__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")}>${this.iconOnly
|
|
198
215
|
? html `<cm-icon name=${this.icon} size="18"></cm-icon>`
|
|
199
216
|
: html `<span>${name}</span><cm-icon name="chevron-down" size="14"></cm-icon>`}</button>`;
|
|
200
217
|
return html `${trigger}
|
|
201
|
-
<div class="pop" part="menu" ?hidden=${!this.open}>
|
|
202
|
-
${this.heading ? html `<div class="head" part="heading"><strong>${this.heading}</strong>${this.subheading ? html `<span>${this.subheading}</span>` : nothing}</div>` : nothing}
|
|
218
|
+
<div class="pop" part="menu" popover="manual" ?hidden=${!this.open}>
|
|
219
|
+
${this.headTemplate() ?? (this.heading ? html `<div class="head" part="heading"><strong>${this.heading}</strong>${this.subheading ? html `<span>${this.subheading}</span>` : nothing}</div>` : nothing)}
|
|
203
220
|
<div role="menu" id="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.heading || this.label} aria-busy=${this.loading ? 'true' : nothing} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_menuKey, "f")}>
|
|
204
221
|
${this.loading
|
|
205
222
|
? html `<div class="loading" role="presentation"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span>${this.t('loading')}</span></div>`
|
|
@@ -209,7 +226,7 @@ export class CmActionMenu extends CmLocalizedElement {
|
|
|
209
226
|
<slot hidden></slot>`;
|
|
210
227
|
}
|
|
211
228
|
}
|
|
212
|
-
_CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmActionMenu_typed = new WeakMap(), _CmActionMenu_typedAt = new WeakMap(), _CmActionMenu_outside = new WeakMap(), _CmActionMenu_triggerKey = new WeakMap(), _CmActionMenu_triggerClick = new WeakMap(), _CmActionMenu_menuKey = new WeakMap(), _CmActionMenu_instances = new WeakSet(), _CmActionMenu_read = function _CmActionMenu_read() {
|
|
229
|
+
_CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmActionMenu_typed = new WeakMap(), _CmActionMenu_typedAt = new WeakMap(), _CmActionMenu_outside = new WeakMap(), _CmActionMenu_onMove = new WeakMap(), _CmActionMenu_following = new WeakMap(), _CmActionMenu_triggerKey = new WeakMap(), _CmActionMenu_triggerClick = new WeakMap(), _CmActionMenu_menuKey = new WeakMap(), _CmActionMenu_instances = new WeakSet(), _CmActionMenu_read = function _CmActionMenu_read() {
|
|
213
230
|
this._slotted = readMenuItems(this);
|
|
214
231
|
this._custom = !!this.querySelector(':scope > [slot="trigger"]');
|
|
215
232
|
}, _CmActionMenu_trigger = function _CmActionMenu_trigger() {
|
|
@@ -231,6 +248,18 @@ _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmAct
|
|
|
231
248
|
const pop = this.renderRoot.querySelector('.pop');
|
|
232
249
|
if (!pop)
|
|
233
250
|
return;
|
|
251
|
+
if (typeof pop.showPopover === 'function') {
|
|
252
|
+
try {
|
|
253
|
+
if (!pop.matches(':popover-open'))
|
|
254
|
+
pop.showPopover();
|
|
255
|
+
}
|
|
256
|
+
catch { /* not connected yet */ }
|
|
257
|
+
if (pop.matches(':popover-open')) {
|
|
258
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_place).call(this, pop);
|
|
259
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, true);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
234
263
|
pop.classList.remove('to-end', 'to-start');
|
|
235
264
|
const r = pop.getBoundingClientRect(), vw = document.documentElement.clientWidth, m = 8;
|
|
236
265
|
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
@@ -240,6 +269,36 @@ _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmAct
|
|
|
240
269
|
pop.classList.add('to-end');
|
|
241
270
|
else if (this.align === 'end' && startOverflow)
|
|
242
271
|
pop.classList.add('to-start');
|
|
272
|
+
}, _CmActionMenu_place = function _CmActionMenu_place(pop) {
|
|
273
|
+
const t = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this) ?? this;
|
|
274
|
+
const r = t.getBoundingClientRect();
|
|
275
|
+
const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight, m = 8, gap = 4;
|
|
276
|
+
pop.style.maxHeight = '';
|
|
277
|
+
const w = pop.offsetWidth, h = pop.offsetHeight;
|
|
278
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
279
|
+
const startEdge = rtl ? r.right - w : r.left, endEdge = rtl ? r.left : r.right - w;
|
|
280
|
+
let left = this.align === 'end' ? endEdge : startEdge;
|
|
281
|
+
if (left + w > vw - m)
|
|
282
|
+
left = rtl ? startEdge : endEdge;
|
|
283
|
+
if (left < m)
|
|
284
|
+
left = this.align === 'end' ? startEdge : (rtl ? r.left : left);
|
|
285
|
+
left = Math.max(m, Math.min(left, vw - m - w));
|
|
286
|
+
let top = r.bottom + gap;
|
|
287
|
+
if (top + h > vh - m) {
|
|
288
|
+
if (r.top - gap - h >= m)
|
|
289
|
+
top = r.top - gap - h;
|
|
290
|
+
else
|
|
291
|
+
pop.style.maxHeight = `${Math.max(120, vh - top - m)}px`;
|
|
292
|
+
}
|
|
293
|
+
pop.style.left = `${Math.round(left)}px`;
|
|
294
|
+
pop.style.top = `${Math.round(top)}px`;
|
|
295
|
+
}, _CmActionMenu_follow = function _CmActionMenu_follow(on) {
|
|
296
|
+
if (on === __classPrivateFieldGet(this, _CmActionMenu_following, "f"))
|
|
297
|
+
return;
|
|
298
|
+
__classPrivateFieldSet(this, _CmActionMenu_following, on, "f");
|
|
299
|
+
const f = on ? 'addEventListener' : 'removeEventListener';
|
|
300
|
+
window[f]('scroll', __classPrivateFieldGet(this, _CmActionMenu_onMove, "f"), true);
|
|
301
|
+
window[f]('resize', __classPrivateFieldGet(this, _CmActionMenu_onMove, "f"));
|
|
243
302
|
}, _CmActionMenu_move = function _CmActionMenu_move(to) {
|
|
244
303
|
this._active = to;
|
|
245
304
|
this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
|
|
@@ -335,6 +394,9 @@ CmActionMenu.styles = [
|
|
|
335
394
|
:host([align='end']) .pop, .pop.to-end { inset-inline-start: auto; inset-inline-end: 0; }
|
|
336
395
|
:host([align='end']) .pop.to-start { inset-inline-start: 0; inset-inline-end: auto; }
|
|
337
396
|
.pop[hidden] { display: none; }
|
|
397
|
+
/* 1.9.2: the open menu is a popover in the top layer, so a scrolling ancestor (a board column, a table, a card
|
|
398
|
+
body) can't clip it; #place() puts it beside the trigger. Browsers without popovers keep the absolute menu. */
|
|
399
|
+
.pop:popover-open { position: fixed; inset: auto; margin: 0; overflow: auto; color: var(--cm-text-default); }
|
|
338
400
|
.head { padding: var(--cm-space-4) var(--cm-space-12) var(--cm-space-8); margin-bottom: 4px; border-bottom: var(--cm-border-1) solid var(--cm-border-subtle); overflow-wrap: anywhere; }
|
|
339
401
|
.head strong { display: block; font-size: 14px; font-weight: 500; }
|
|
340
402
|
.head span { display: block; font-size: var(--cm-font-size-12); color: var(--cm-text-tertiary); }
|
|
@@ -126,7 +126,7 @@ CmButton.styles = [
|
|
|
126
126
|
css `
|
|
127
127
|
:host { display: inline-flex; vertical-align: middle; max-width: 100%; }
|
|
128
128
|
/* A label longer than the room (a button in a narrow card) ends with an ellipsis instead of spilling out (1.8.1). */
|
|
129
|
-
.text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
129
|
+
.text { min-width: 0; overflow: hidden; text-overflow: ellipsis; line-height: var(--cm-line-height-14, 20px); } /* a full line box, so overflow: hidden doesn't cut g, p and y (1.9.3) */
|
|
130
130
|
.btn {
|
|
131
131
|
position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--cm-space-8);
|
|
132
132
|
width: 100%; min-width: 0; font: inherit; font-weight: 500; line-height: 1; white-space: nowrap;
|
|
@@ -29,7 +29,8 @@ declare module '../localize.js' {
|
|
|
29
29
|
* @element cm-header-bar
|
|
30
30
|
* @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
|
|
31
31
|
* @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
|
|
32
|
-
* @slot end -
|
|
32
|
+
* @slot end - Controls before the signed-in person, in this order: refresh, then notifications (1.9.2: the user comes last).
|
|
33
|
+
* @slot account - The signed-in person's menu, last in the bar: a `cm-account-menu` (since 1.9.2). Use it instead of `user-name`.
|
|
33
34
|
* @slot search - One search box for the whole product, usually `cm-global-search`. Inline on wide bars; behind a search button that opens a full-screen layer at 900px or narrower.
|
|
34
35
|
* @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
|
|
35
36
|
* @fires cm-wallet - When the wallet balance is pressed.
|
|
@@ -38,7 +38,8 @@ const strings = defineStrings('headerBar', {
|
|
|
38
38
|
* @element cm-header-bar
|
|
39
39
|
* @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
|
|
40
40
|
* @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
|
|
41
|
-
* @slot end -
|
|
41
|
+
* @slot end - Controls before the signed-in person, in this order: refresh, then notifications (1.9.2: the user comes last).
|
|
42
|
+
* @slot account - The signed-in person's menu, last in the bar: a `cm-account-menu` (since 1.9.2). Use it instead of `user-name`.
|
|
42
43
|
* @slot search - One search box for the whole product, usually `cm-global-search`. Inline on wide bars; behind a search button that opens a full-screen layer at 900px or narrower.
|
|
43
44
|
* @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
|
|
44
45
|
* @fires cm-wallet - When the wallet balance is pressed.
|
|
@@ -151,10 +152,11 @@ export class CmHeaderBar extends CmLocalizedElement {
|
|
|
151
152
|
<div class="actions"><slot name="actions"></slot></div>
|
|
152
153
|
${this.balance ? html `<button type="button" class="pill" part="balance" aria-label=${this.t('balance', { balance: this.balance })}
|
|
153
154
|
@click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-wallet')}>${this.balance}</button>` : nothing}
|
|
155
|
+
<slot name="end"></slot>
|
|
154
156
|
${this.userName ? html `<button type="button" class="user" part="user" aria-haspopup="true" aria-label=${this.t('account', { name: this.userName })}
|
|
155
157
|
@click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-account')}><span class="name">${this.userName}</span>
|
|
156
158
|
<cm-avatar class="avatar" name=${this.userName} src=${this.avatarSrc} decorative></cm-avatar></button>` : nothing}
|
|
157
|
-
<slot name="
|
|
159
|
+
<slot name="account"></slot>
|
|
158
160
|
</div>
|
|
159
161
|
</header>
|
|
160
162
|
${this._narrow ? html `<dialog class="layer" part="search-layer" aria-label=${this.searchLabel}
|