@commmerce/ui 0.0.0-stage → 1.0.0-rc.4
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/LICENSE.md +17 -0
- package/README.md +41 -2
- package/dist/base.d.ts +7 -0
- package/dist/base.js +22 -0
- package/dist/cdn.js +1958 -0
- package/dist/components/accordion.d.ts +43 -0
- package/dist/components/accordion.js +83 -0
- package/dist/components/action-bar.d.ts +42 -0
- package/dist/components/action-bar.js +84 -0
- package/dist/components/action-menu.d.ts +89 -0
- package/dist/components/action-menu.js +283 -0
- package/dist/components/app-card.d.ts +57 -0
- package/dist/components/app-card.js +100 -0
- package/dist/components/avatar.d.ts +48 -0
- package/dist/components/avatar.js +82 -0
- package/dist/components/badge.d.ts +23 -0
- package/dist/components/badge.js +35 -0
- package/dist/components/banner.d.ts +36 -0
- package/dist/components/banner.js +88 -0
- package/dist/components/bottom-navigation.d.ts +48 -0
- package/dist/components/bottom-navigation.js +98 -0
- package/dist/components/bottom-sheet.d.ts +54 -0
- package/dist/components/bottom-sheet.js +133 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +101 -0
- package/dist/components/card.d.ts +37 -0
- package/dist/components/card.js +58 -0
- package/dist/components/checkbox.d.ts +68 -0
- package/dist/components/checkbox.js +114 -0
- package/dist/components/comment.d.ts +76 -0
- package/dist/components/comment.js +170 -0
- package/dist/components/data-table.d.ts +132 -0
- package/dist/components/data-table.js +331 -0
- package/dist/components/empty-state.d.ts +49 -0
- package/dist/components/empty-state.js +94 -0
- package/dist/components/file-upload.d.ts +102 -0
- package/dist/components/file-upload.js +243 -0
- package/dist/components/filter-panel.d.ts +86 -0
- package/dist/components/filter-panel.js +128 -0
- package/dist/components/flash-offer-bar.d.ts +34 -0
- package/dist/components/flash-offer-bar.js +73 -0
- package/dist/components/grid.d.ts +39 -0
- package/dist/components/grid.js +42 -0
- package/dist/components/header-bar.d.ts +48 -0
- package/dist/components/header-bar.js +121 -0
- package/dist/components/icon.d.ts +30 -0
- package/dist/components/icon.js +36 -0
- package/dist/components/info-panel.d.ts +63 -0
- package/dist/components/info-panel.js +108 -0
- package/dist/components/layout.d.ts +45 -0
- package/dist/components/layout.js +67 -0
- package/dist/components/link-tabs.d.ts +40 -0
- package/dist/components/link-tabs.js +85 -0
- package/dist/components/menu-item.d.ts +68 -0
- package/dist/components/menu-item.js +64 -0
- package/dist/components/mobile-menu.d.ts +69 -0
- package/dist/components/mobile-menu.js +184 -0
- package/dist/components/modal.d.ts +46 -0
- package/dist/components/modal.js +59 -0
- package/dist/components/nav-item.d.ts +98 -0
- package/dist/components/nav-item.js +84 -0
- package/dist/components/nested-list.d.ts +105 -0
- package/dist/components/nested-list.js +279 -0
- package/dist/components/notification-panel.d.ts +121 -0
- package/dist/components/notification-panel.js +174 -0
- package/dist/components/option-group.d.ts +74 -0
- package/dist/components/option-group.js +172 -0
- package/dist/components/page-header.d.ts +58 -0
- package/dist/components/page-header.js +121 -0
- package/dist/components/page.d.ts +34 -0
- package/dist/components/page.js +41 -0
- package/dist/components/pagination.d.ts +64 -0
- package/dist/components/pagination.js +160 -0
- package/dist/components/progress-bar.d.ts +45 -0
- package/dist/components/progress-bar.js +81 -0
- package/dist/components/radio.d.ts +131 -0
- package/dist/components/radio.js +252 -0
- package/dist/components/report-tile.d.ts +65 -0
- package/dist/components/report-tile.js +112 -0
- package/dist/components/resource-list.d.ts +143 -0
- package/dist/components/resource-list.js +335 -0
- package/dist/components/save-bar.d.ts +58 -0
- package/dist/components/save-bar.js +128 -0
- package/dist/components/search.d.ts +78 -0
- package/dist/components/search.js +144 -0
- package/dist/components/select.d.ts +106 -0
- package/dist/components/select.js +338 -0
- package/dist/components/side-navigation.d.ts +51 -0
- package/dist/components/side-navigation.js +194 -0
- package/dist/components/side-panel.d.ts +50 -0
- package/dist/components/side-panel.js +73 -0
- package/dist/components/skeleton-display.d.ts +32 -0
- package/dist/components/skeleton-display.js +70 -0
- package/dist/components/skeleton.d.ts +41 -0
- package/dist/components/skeleton.js +59 -0
- package/dist/components/smart-tip.d.ts +62 -0
- package/dist/components/smart-tip.js +128 -0
- package/dist/components/spinner.d.ts +27 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/stack.d.ts +45 -0
- package/dist/components/stack.js +49 -0
- package/dist/components/status-tabs.d.ts +65 -0
- package/dist/components/status-tabs.js +158 -0
- package/dist/components/table-header.d.ts +84 -0
- package/dist/components/table-header.js +151 -0
- package/dist/components/tag.d.ts +39 -0
- package/dist/components/tag.js +68 -0
- package/dist/components/text-field.d.ts +101 -0
- package/dist/components/text-field.js +162 -0
- package/dist/components/thumbnail.d.ts +40 -0
- package/dist/components/thumbnail.js +61 -0
- package/dist/components/toast.d.ts +108 -0
- package/dist/components/toast.js +268 -0
- package/dist/components/toggle.d.ts +60 -0
- package/dist/components/toggle.js +108 -0
- package/dist/components/tooltip.d.ts +56 -0
- package/dist/components/tooltip.js +267 -0
- package/dist/custom-elements.json +13222 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +56 -0
- package/dist/overlay.d.ts +57 -0
- package/dist/overlay.js +205 -0
- package/dist/spacing.d.ts +6 -0
- package/dist/spacing.js +7 -0
- package/package.json +59 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
/**
|
|
4
|
+
* A row that shows or hides extra detail. Used in side panels and cards.
|
|
5
|
+
* @element cm-accordion
|
|
6
|
+
* @slot - The detail shown when open.
|
|
7
|
+
* @fires cm-toggle - After it opens or closes; `detail.open` is the new state.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CmAccordion extends LitElement {
|
|
10
|
+
#private;
|
|
11
|
+
static properties: {
|
|
12
|
+
heading: {};
|
|
13
|
+
open: {
|
|
14
|
+
type: BooleanConstructor;
|
|
15
|
+
reflect: boolean;
|
|
16
|
+
};
|
|
17
|
+
disabled: {
|
|
18
|
+
type: BooleanConstructor;
|
|
19
|
+
reflect: boolean;
|
|
20
|
+
};
|
|
21
|
+
headingLevel: {
|
|
22
|
+
type: NumberConstructor;
|
|
23
|
+
attribute: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** The always-visible row text. */
|
|
27
|
+
heading: string;
|
|
28
|
+
/** Shows the detail. */
|
|
29
|
+
open: boolean;
|
|
30
|
+
/** Blocks opening and closing. */
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
/** Heading level wrapping the toggle button, so the page outline stays correct. Default 3. */
|
|
33
|
+
headingLevel: 2 | 3 | 4 | 5 | 6;
|
|
34
|
+
static styles: import("lit").CSSResult[];
|
|
35
|
+
/** Opens or closes it, as if the row was pressed. */
|
|
36
|
+
toggle(): void;
|
|
37
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
38
|
+
}
|
|
39
|
+
declare global {
|
|
40
|
+
interface HTMLElementTagNameMap {
|
|
41
|
+
'cm-accordion': CmAccordion;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _CmAccordion_id;
|
|
7
|
+
import { LitElement, html, css } from 'lit';
|
|
8
|
+
import { base, define, nextId } from '../base.js';
|
|
9
|
+
import './icon.js';
|
|
10
|
+
/**
|
|
11
|
+
* A row that shows or hides extra detail. Used in side panels and cards.
|
|
12
|
+
* @element cm-accordion
|
|
13
|
+
* @slot - The detail shown when open.
|
|
14
|
+
* @fires cm-toggle - After it opens or closes; `detail.open` is the new state.
|
|
15
|
+
*/
|
|
16
|
+
export class CmAccordion extends LitElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
/** The always-visible row text. */
|
|
20
|
+
this.heading = '';
|
|
21
|
+
/** Shows the detail. */
|
|
22
|
+
this.open = false;
|
|
23
|
+
/** Blocks opening and closing. */
|
|
24
|
+
this.disabled = false;
|
|
25
|
+
/** Heading level wrapping the toggle button, so the page outline stays correct. Default 3. */
|
|
26
|
+
this.headingLevel = 3;
|
|
27
|
+
_CmAccordion_id.set(this, nextId('cm-accordion'));
|
|
28
|
+
}
|
|
29
|
+
/** Opens or closes it, as if the row was pressed. */
|
|
30
|
+
toggle() {
|
|
31
|
+
if (this.disabled)
|
|
32
|
+
return;
|
|
33
|
+
this.open = !this.open;
|
|
34
|
+
this.dispatchEvent(new CustomEvent('cm-toggle', { bubbles: true, composed: true, detail: { open: this.open } }));
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
const level = Math.min(6, Math.max(2, this.headingLevel || 3));
|
|
38
|
+
return html `<div class="wrap" part="accordion">
|
|
39
|
+
<div class="h" role="heading" aria-level=${level}>
|
|
40
|
+
<button type="button" part="toggle" id="${__classPrivateFieldGet(this, _CmAccordion_id, "f")}-btn" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmAccordion_id, "f")}-body"
|
|
41
|
+
?disabled=${this.disabled} @click=${this.toggle}>
|
|
42
|
+
<span>${this.heading}</span>
|
|
43
|
+
<span class="chev" aria-hidden="true"><cm-icon name="chevron-down" size="16"></cm-icon></span>
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="body" part="body" id="${__classPrivateFieldGet(this, _CmAccordion_id, "f")}-body" role="region" aria-labelledby="${__classPrivateFieldGet(this, _CmAccordion_id, "f")}-btn" ?hidden=${!this.open}><slot></slot></div>
|
|
47
|
+
</div>`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_CmAccordion_id = new WeakMap();
|
|
51
|
+
CmAccordion.properties = {
|
|
52
|
+
heading: {},
|
|
53
|
+
open: { type: Boolean, reflect: true },
|
|
54
|
+
disabled: { type: Boolean, reflect: true },
|
|
55
|
+
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
56
|
+
};
|
|
57
|
+
CmAccordion.styles = [
|
|
58
|
+
base,
|
|
59
|
+
css `
|
|
60
|
+
:host { display: block; }
|
|
61
|
+
.wrap { border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-md); background: var(--cm-bg-surface); }
|
|
62
|
+
.h { margin: 0; font: inherit; }
|
|
63
|
+
button {
|
|
64
|
+
display: flex; align-items: center; justify-content: space-between; gap: var(--cm-space-15); width: 100%;
|
|
65
|
+
min-height: 60px; padding: var(--cm-space-12) var(--cm-space-15) var(--cm-space-12) var(--cm-space-20);
|
|
66
|
+
border: 0; border-radius: inherit; background: none; color: var(--cm-text-default);
|
|
67
|
+
font: inherit; font-size: 16px; text-align: left; cursor: pointer;
|
|
68
|
+
}
|
|
69
|
+
button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
70
|
+
button:disabled { color: var(--cm-text-secondary); cursor: not-allowed; }
|
|
71
|
+
.chev {
|
|
72
|
+
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
|
|
73
|
+
border-radius: var(--cm-radius-full); background: var(--cm-bg-page); color: var(--cm-icon-selected);
|
|
74
|
+
transition: transform .2s ease;
|
|
75
|
+
}
|
|
76
|
+
:host([open]) .chev { transform: rotate(180deg); }
|
|
77
|
+
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
|
|
78
|
+
.body { padding: var(--cm-space-15) var(--cm-space-20); border-top: var(--cm-border-1) solid var(--cm-border-default); font-size: 14px; }
|
|
79
|
+
.body[hidden] { display: none; }
|
|
80
|
+
@media (max-width: 640px) { button { min-height: 50px; font-size: 14px; } .chev { width: 28px; height: 28px; } }
|
|
81
|
+
`,
|
|
82
|
+
];
|
|
83
|
+
define('cm-accordion', CmAccordion);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
/**
|
|
4
|
+
* Bar at the bottom of a long form or record page that repeats what the page is about and its
|
|
5
|
+
* main actions, so they stay in reach. The Figma file calls this the "Bottom Tab".
|
|
6
|
+
* With `tone="critical"` it explains a blocking error and offers the action that fixes it.
|
|
7
|
+
* @element cm-action-bar
|
|
8
|
+
* @slot - Extra content under the heading, such as an amount.
|
|
9
|
+
* @slot adornment - Badge next to the eyebrow (for example the order status).
|
|
10
|
+
* @slot actions - Buttons, secondary first and the primary action last (large size).
|
|
11
|
+
*/
|
|
12
|
+
export declare class CmActionBar extends LitElement {
|
|
13
|
+
static properties: {
|
|
14
|
+
eyebrow: {};
|
|
15
|
+
heading: {};
|
|
16
|
+
tone: {
|
|
17
|
+
reflect: boolean;
|
|
18
|
+
};
|
|
19
|
+
sticky: {
|
|
20
|
+
type: BooleanConstructor;
|
|
21
|
+
reflect: boolean;
|
|
22
|
+
};
|
|
23
|
+
label: {};
|
|
24
|
+
};
|
|
25
|
+
/** Small line above the heading: the page or record ID ("Add product", "#ODYOD0744"). */
|
|
26
|
+
eyebrow: string;
|
|
27
|
+
/** The record name, or the error message when `tone="critical"`. */
|
|
28
|
+
heading: string;
|
|
29
|
+
/** `default` white bar; `critical` pink bar with a red top edge and warning icon, announced as an alert. */
|
|
30
|
+
tone: 'default' | 'critical';
|
|
31
|
+
/** Sticks the bar to the bottom of the scrolling area. */
|
|
32
|
+
sticky: boolean;
|
|
33
|
+
/** Accessible name of the bar's region. Defaults to the heading. */
|
|
34
|
+
label: string;
|
|
35
|
+
static styles: import("lit").CSSResult[];
|
|
36
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
37
|
+
}
|
|
38
|
+
declare global {
|
|
39
|
+
interface HTMLElementTagNameMap {
|
|
40
|
+
'cm-action-bar': CmActionBar;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
2
|
+
import { base, define } from '../base.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
/**
|
|
5
|
+
* Bar at the bottom of a long form or record page that repeats what the page is about and its
|
|
6
|
+
* main actions, so they stay in reach. The Figma file calls this the "Bottom Tab".
|
|
7
|
+
* With `tone="critical"` it explains a blocking error and offers the action that fixes it.
|
|
8
|
+
* @element cm-action-bar
|
|
9
|
+
* @slot - Extra content under the heading, such as an amount.
|
|
10
|
+
* @slot adornment - Badge next to the eyebrow (for example the order status).
|
|
11
|
+
* @slot actions - Buttons, secondary first and the primary action last (large size).
|
|
12
|
+
*/
|
|
13
|
+
export class CmActionBar extends LitElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
/** Small line above the heading: the page or record ID ("Add product", "#ODYOD0744"). */
|
|
17
|
+
this.eyebrow = '';
|
|
18
|
+
/** The record name, or the error message when `tone="critical"`. */
|
|
19
|
+
this.heading = '';
|
|
20
|
+
/** `default` white bar; `critical` pink bar with a red top edge and warning icon, announced as an alert. */
|
|
21
|
+
this.tone = 'default';
|
|
22
|
+
/** Sticks the bar to the bottom of the scrolling area. */
|
|
23
|
+
this.sticky = false;
|
|
24
|
+
/** Accessible name of the bar's region. Defaults to the heading. */
|
|
25
|
+
this.label = '';
|
|
26
|
+
}
|
|
27
|
+
render() {
|
|
28
|
+
const critical = this.tone === 'critical';
|
|
29
|
+
return html `<div class="bar" part="bar" role="region" aria-label=${this.label || this.heading || this.eyebrow || 'Actions'}>
|
|
30
|
+
<div class="lead">
|
|
31
|
+
${critical ? html `<span class="icon" aria-hidden="true"><cm-icon name="alert" size="20"></cm-icon></span>` : nothing}
|
|
32
|
+
<div class="text">
|
|
33
|
+
<div class="eyebrow" ?hidden=${!this.eyebrow}>${this.eyebrow}<slot name="adornment"></slot></div>
|
|
34
|
+
${this.heading ? html `<p class="heading" part="heading" role=${critical ? 'alert' : nothing}>${this.heading}</p>` : nothing}
|
|
35
|
+
<slot></slot>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="actions"><slot name="actions"></slot></div>
|
|
39
|
+
</div>`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
CmActionBar.properties = {
|
|
43
|
+
eyebrow: {},
|
|
44
|
+
heading: {},
|
|
45
|
+
tone: { reflect: true },
|
|
46
|
+
sticky: { type: Boolean, reflect: true },
|
|
47
|
+
label: {},
|
|
48
|
+
};
|
|
49
|
+
CmActionBar.styles = [
|
|
50
|
+
base,
|
|
51
|
+
css `
|
|
52
|
+
:host { display: block; }
|
|
53
|
+
:host([sticky]) { position: sticky; bottom: 0; z-index: 10; }
|
|
54
|
+
.bar {
|
|
55
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--cm-space-20);
|
|
56
|
+
min-height: 80px; padding: var(--cm-space-15) var(--cm-space-20) var(--cm-space-15) var(--cm-space-20);
|
|
57
|
+
background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-card); border-radius: var(--cm-radius-md);
|
|
58
|
+
}
|
|
59
|
+
:host([sticky]) .bar { box-shadow: var(--cm-shadow-100); }
|
|
60
|
+
:host([tone='critical']) .bar {
|
|
61
|
+
background: var(--cm-bg-error-bar); border-color: transparent; border-top-color: var(--cm-border-critical); border-radius: 0;
|
|
62
|
+
}
|
|
63
|
+
.lead { flex: 1 1 280px; display: flex; align-items: center; gap: var(--cm-space-10); min-width: 0; }
|
|
64
|
+
.text { min-width: 0; display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
65
|
+
.eyebrow { display: flex; align-items: center; gap: var(--cm-space-10); font-size: 14px; font-weight: 500; }
|
|
66
|
+
.eyebrow[hidden] { display: none; }
|
|
67
|
+
.heading { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
|
|
68
|
+
:host([tone='critical']) .heading { font-weight: 400; }
|
|
69
|
+
.icon {
|
|
70
|
+
flex: none; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
|
|
71
|
+
border-radius: var(--cm-radius-full); background: var(--cm-bg-surface); color: var(--cm-icon-critical);
|
|
72
|
+
}
|
|
73
|
+
.actions { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--cm-space-20); margin-left: auto; }
|
|
74
|
+
@media (max-width: 640px) {
|
|
75
|
+
.bar { min-height: 68px; padding: var(--cm-space-10); gap: var(--cm-space-10); }
|
|
76
|
+
.heading { font-size: 14px; }
|
|
77
|
+
.eyebrow { font-size: 12px; }
|
|
78
|
+
.text { gap: var(--cm-space-10); }
|
|
79
|
+
.icon { width: 30px; height: 30px; }
|
|
80
|
+
.actions { gap: var(--cm-space-10); }
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
];
|
|
84
|
+
define('cm-action-bar', CmActionBar);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { LitElement, type PropertyValues } from 'lit';
|
|
2
|
+
import { type MenuItem } from './menu-item.js';
|
|
3
|
+
import './icon.js';
|
|
4
|
+
/**
|
|
5
|
+
* A button that opens a short list of actions: row actions in a table ("Cancel shipment", "Change tracking
|
|
6
|
+
* info"), "Add…" menus, or the account menu with the merchant's name and email on top. The highlighted choice
|
|
7
|
+
* is black with white text.
|
|
8
|
+
*
|
|
9
|
+
* Follows the WAI-ARIA menu button pattern: the trigger has `aria-haspopup` and `aria-expanded`; ↓/↑ (or
|
|
10
|
+
* Enter/Space) open it, ↓/↑ Home/End and the first letter move between choices, Enter/Space choose, Esc closes
|
|
11
|
+
* and returns focus to the trigger, Tab closes and moves on. A click outside closes it.
|
|
12
|
+
* @element cm-action-menu
|
|
13
|
+
* @slot - `cm-menu-item`s, with `<hr>` between groups.
|
|
14
|
+
* @slot trigger - Your own trigger button (optional). The menu sets its ARIA state.
|
|
15
|
+
* @fires cm-select - When a choice is made. `detail: { value, item }`. Cancelable: for link items, `preventDefault()` stops the navigation.
|
|
16
|
+
* @fires cm-toggle - When the menu opens or closes. `detail: { open }`.
|
|
17
|
+
*/
|
|
18
|
+
export declare class CmActionMenu extends LitElement {
|
|
19
|
+
#private;
|
|
20
|
+
static properties: {
|
|
21
|
+
items: {
|
|
22
|
+
type: ArrayConstructor;
|
|
23
|
+
};
|
|
24
|
+
open: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
reflect: boolean;
|
|
27
|
+
};
|
|
28
|
+
label: {};
|
|
29
|
+
triggerLabel: {
|
|
30
|
+
attribute: string;
|
|
31
|
+
};
|
|
32
|
+
iconOnly: {
|
|
33
|
+
type: BooleanConstructor;
|
|
34
|
+
attribute: string;
|
|
35
|
+
};
|
|
36
|
+
icon: {};
|
|
37
|
+
align: {
|
|
38
|
+
reflect: boolean;
|
|
39
|
+
};
|
|
40
|
+
heading: {};
|
|
41
|
+
subheading: {};
|
|
42
|
+
_slotted: {
|
|
43
|
+
state: boolean;
|
|
44
|
+
};
|
|
45
|
+
_active: {
|
|
46
|
+
state: boolean;
|
|
47
|
+
};
|
|
48
|
+
_custom: {
|
|
49
|
+
state: boolean;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** Choices as data, used instead of children when set: `[{ label: 'Add product', value: 'product' }, { divider: true }, …]`. */
|
|
53
|
+
items: MenuItem[];
|
|
54
|
+
/** Shows the menu. */
|
|
55
|
+
open: boolean;
|
|
56
|
+
/** Accessible name of the menu. Also the trigger's name when it is icon-only. */
|
|
57
|
+
label: string;
|
|
58
|
+
/** Text of the built-in trigger. Empty uses `label`. */
|
|
59
|
+
triggerLabel: string;
|
|
60
|
+
/** The built-in trigger is a "more" (⋮) icon button, e.g. for table rows. */
|
|
61
|
+
iconOnly: boolean;
|
|
62
|
+
/** Icon of the icon-only trigger. Default `more` (⋮); `chevron-down` for a menu attached to another control. */
|
|
63
|
+
icon: string;
|
|
64
|
+
/** Which trigger edge the menu lines up with: `start` (default) or `end` (for triggers at the right edge). */
|
|
65
|
+
align: 'start' | 'end';
|
|
66
|
+
/** Bold line above the choices, e.g. the merchant's name in the account menu. */
|
|
67
|
+
heading: string;
|
|
68
|
+
/** Smaller line under the heading, e.g. the email. */
|
|
69
|
+
subheading: string;
|
|
70
|
+
_slotted: MenuItem[];
|
|
71
|
+
_active: number;
|
|
72
|
+
_custom: boolean;
|
|
73
|
+
static styles: import("lit").CSSResult[];
|
|
74
|
+
connectedCallback(): void;
|
|
75
|
+
disconnectedCallback(): void;
|
|
76
|
+
/** The choices in use. */
|
|
77
|
+
get menuItems(): MenuItem[];
|
|
78
|
+
/** Opens the menu and highlights the first (or last) choice. */
|
|
79
|
+
show(focus?: 'first' | 'last'): void;
|
|
80
|
+
/** Closes the menu. With `returnFocus`, focus goes back to the trigger. */
|
|
81
|
+
hide(returnFocus?: boolean): void;
|
|
82
|
+
protected updated(changed: PropertyValues): void;
|
|
83
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
84
|
+
}
|
|
85
|
+
declare global {
|
|
86
|
+
interface HTMLElementTagNameMap {
|
|
87
|
+
'cm-action-menu': CmActionMenu;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
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
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
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_triggerKey, _CmActionMenu_triggerClick, _CmActionMenu_move, _CmActionMenu_menuKey, _CmActionMenu_choose, _CmActionMenu_item;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { base, define, nextId } from '../base.js';
|
|
15
|
+
import { readMenuItems, watchMenuItems } from './menu-item.js';
|
|
16
|
+
import './icon.js';
|
|
17
|
+
/**
|
|
18
|
+
* A button that opens a short list of actions: row actions in a table ("Cancel shipment", "Change tracking
|
|
19
|
+
* info"), "Add…" menus, or the account menu with the merchant's name and email on top. The highlighted choice
|
|
20
|
+
* is black with white text.
|
|
21
|
+
*
|
|
22
|
+
* Follows the WAI-ARIA menu button pattern: the trigger has `aria-haspopup` and `aria-expanded`; ↓/↑ (or
|
|
23
|
+
* Enter/Space) open it, ↓/↑ Home/End and the first letter move between choices, Enter/Space choose, Esc closes
|
|
24
|
+
* and returns focus to the trigger, Tab closes and moves on. A click outside closes it.
|
|
25
|
+
* @element cm-action-menu
|
|
26
|
+
* @slot - `cm-menu-item`s, with `<hr>` between groups.
|
|
27
|
+
* @slot trigger - Your own trigger button (optional). The menu sets its ARIA state.
|
|
28
|
+
* @fires cm-select - When a choice is made. `detail: { value, item }`. Cancelable: for link items, `preventDefault()` stops the navigation.
|
|
29
|
+
* @fires cm-toggle - When the menu opens or closes. `detail: { open }`.
|
|
30
|
+
*/
|
|
31
|
+
export class CmActionMenu extends LitElement {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments);
|
|
34
|
+
_CmActionMenu_instances.add(this);
|
|
35
|
+
/** Choices as data, used instead of children when set: `[{ label: 'Add product', value: 'product' }, { divider: true }, …]`. */
|
|
36
|
+
this.items = [];
|
|
37
|
+
/** Shows the menu. */
|
|
38
|
+
this.open = false;
|
|
39
|
+
/** Accessible name of the menu. Also the trigger's name when it is icon-only. */
|
|
40
|
+
this.label = 'Actions';
|
|
41
|
+
/** Text of the built-in trigger. Empty uses `label`. */
|
|
42
|
+
this.triggerLabel = '';
|
|
43
|
+
/** The built-in trigger is a "more" (⋮) icon button, e.g. for table rows. */
|
|
44
|
+
this.iconOnly = false;
|
|
45
|
+
/** Icon of the icon-only trigger. Default `more` (⋮); `chevron-down` for a menu attached to another control. */
|
|
46
|
+
this.icon = 'more';
|
|
47
|
+
/** Which trigger edge the menu lines up with: `start` (default) or `end` (for triggers at the right edge). */
|
|
48
|
+
this.align = 'start';
|
|
49
|
+
/** Bold line above the choices, e.g. the merchant's name in the account menu. */
|
|
50
|
+
this.heading = '';
|
|
51
|
+
/** Smaller line under the heading, e.g. the email. */
|
|
52
|
+
this.subheading = '';
|
|
53
|
+
this._slotted = [];
|
|
54
|
+
this._active = -1;
|
|
55
|
+
this._custom = false;
|
|
56
|
+
_CmActionMenu_observer.set(this, void 0);
|
|
57
|
+
_CmActionMenu_id.set(this, nextId('cm-menu'));
|
|
58
|
+
_CmActionMenu_typed.set(this, '');
|
|
59
|
+
_CmActionMenu_typedAt.set(this, 0);
|
|
60
|
+
_CmActionMenu_outside.set(this, (e) => { if (this.open && !e.composedPath().includes(this))
|
|
61
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_setOpen).call(this, false); });
|
|
62
|
+
_CmActionMenu_triggerKey.set(this, (e) => {
|
|
63
|
+
if (e.key === 'ArrowDown') {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
this.show('first');
|
|
66
|
+
}
|
|
67
|
+
else if (e.key === 'ArrowUp') {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
this.show('last');
|
|
70
|
+
}
|
|
71
|
+
else if (e.key === 'Escape' && this.open) {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
e.stopPropagation();
|
|
74
|
+
this.hide(true);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
_CmActionMenu_triggerClick.set(this, () => { if (this.open)
|
|
78
|
+
this.hide();
|
|
79
|
+
else
|
|
80
|
+
this.show(); });
|
|
81
|
+
_CmActionMenu_menuKey.set(this, (e) => {
|
|
82
|
+
const en = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_enabled).call(this);
|
|
83
|
+
const pos = en.indexOf(this._active);
|
|
84
|
+
switch (e.key) {
|
|
85
|
+
case 'ArrowDown':
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_move).call(this, en[(pos + 1) % en.length]);
|
|
88
|
+
break;
|
|
89
|
+
case 'ArrowUp':
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_move).call(this, en[(pos - 1 + en.length) % en.length]);
|
|
92
|
+
break;
|
|
93
|
+
case 'Home':
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_move).call(this, en[0]);
|
|
96
|
+
break;
|
|
97
|
+
case 'End':
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_move).call(this, en[en.length - 1]);
|
|
100
|
+
break;
|
|
101
|
+
case 'Escape':
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
this.hide(true);
|
|
105
|
+
break;
|
|
106
|
+
case 'Tab':
|
|
107
|
+
this.hide();
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
if (e.key.length === 1 && /\S/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
111
|
+
const now = Date.now();
|
|
112
|
+
__classPrivateFieldSet(this, _CmActionMenu_typed, (now - __classPrivateFieldGet(this, _CmActionMenu_typedAt, "f") < 600 ? __classPrivateFieldGet(this, _CmActionMenu_typed, "f") : '') + e.key.toLowerCase(), "f");
|
|
113
|
+
__classPrivateFieldSet(this, _CmActionMenu_typedAt, now, "f");
|
|
114
|
+
const items = this.menuItems;
|
|
115
|
+
const start = __classPrivateFieldGet(this, _CmActionMenu_typed, "f").length > 1 ? pos : pos + 1;
|
|
116
|
+
const order = [...en.slice(Math.max(start, 0)), ...en.slice(0, Math.max(start, 0))];
|
|
117
|
+
const hit = order.find((i) => (items[i].label ?? '').toLowerCase().startsWith(__classPrivateFieldGet(this, _CmActionMenu_typed, "f")));
|
|
118
|
+
if (hit !== undefined)
|
|
119
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_move).call(this, hit);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
connectedCallback() {
|
|
125
|
+
super.connectedCallback();
|
|
126
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_read).call(this);
|
|
127
|
+
__classPrivateFieldSet(this, _CmActionMenu_observer, watchMenuItems(this, () => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_read).call(this)), "f");
|
|
128
|
+
document.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmActionMenu_outside, "f"), true);
|
|
129
|
+
}
|
|
130
|
+
disconnectedCallback() {
|
|
131
|
+
super.disconnectedCallback();
|
|
132
|
+
__classPrivateFieldGet(this, _CmActionMenu_observer, "f")?.disconnect();
|
|
133
|
+
document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmActionMenu_outside, "f"), true);
|
|
134
|
+
}
|
|
135
|
+
/** The choices in use. */
|
|
136
|
+
get menuItems() { return this.items.length ? this.items : this._slotted; }
|
|
137
|
+
/** Opens the menu and highlights the first (or last) choice. */
|
|
138
|
+
show(focus = 'first') {
|
|
139
|
+
const en = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_enabled).call(this);
|
|
140
|
+
this._active = focus === 'first' ? en[0] ?? -1 : en[en.length - 1] ?? -1;
|
|
141
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_setOpen).call(this, true);
|
|
142
|
+
this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
|
|
143
|
+
}
|
|
144
|
+
/** Closes the menu. With `returnFocus`, focus goes back to the trigger. */
|
|
145
|
+
hide(returnFocus = false) {
|
|
146
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_setOpen).call(this, false);
|
|
147
|
+
if (returnFocus)
|
|
148
|
+
__classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this)?.focus();
|
|
149
|
+
}
|
|
150
|
+
updated(changed) {
|
|
151
|
+
if (this._custom) {
|
|
152
|
+
const t = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this);
|
|
153
|
+
if (t) {
|
|
154
|
+
// Only write changes: the item observer watches attributes, so rewriting would loop.
|
|
155
|
+
const set = (k, v) => { if (t.getAttribute(k) !== v)
|
|
156
|
+
t.setAttribute(k, v); };
|
|
157
|
+
set('aria-haspopup', 'menu');
|
|
158
|
+
set('aria-expanded', String(this.open));
|
|
159
|
+
set('aria-controls', `${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (changed.has('open') && this.open && this._active < 0) {
|
|
163
|
+
const en = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_enabled).call(this);
|
|
164
|
+
this._active = en[0] ?? -1;
|
|
165
|
+
this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
render() {
|
|
169
|
+
const items = this.menuItems;
|
|
170
|
+
const name = this.triggerLabel || this.label;
|
|
171
|
+
const trigger = this._custom
|
|
172
|
+
? 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>`
|
|
173
|
+
: html `<button type="button" class="trigger ${this.iconOnly ? 'icon' : ''}" part="trigger" aria-haspopup="menu"
|
|
174
|
+
aria-expanded=${String(this.open)} aria-controls="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.iconOnly ? name : nothing}
|
|
175
|
+
@click=${__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")}>${this.iconOnly
|
|
176
|
+
? html `<cm-icon name=${this.icon} size="18"></cm-icon>`
|
|
177
|
+
: html `<span>${name}</span><cm-icon name="chevron-down" size="14"></cm-icon>`}</button>`;
|
|
178
|
+
return html `${trigger}
|
|
179
|
+
<div class="pop" part="menu" ?hidden=${!this.open}>
|
|
180
|
+
${this.heading ? html `<div class="head" part="heading"><strong>${this.heading}</strong>${this.subheading ? html `<span>${this.subheading}</span>` : nothing}</div>` : nothing}
|
|
181
|
+
<div role="menu" id="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.heading || this.label} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_menuKey, "f")}>
|
|
182
|
+
${items.map((it, i) => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_item).call(this, it, i))}
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
<slot hidden></slot>`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
_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() {
|
|
189
|
+
this._slotted = readMenuItems(this);
|
|
190
|
+
this._custom = !!this.querySelector(':scope > [slot="trigger"]');
|
|
191
|
+
}, _CmActionMenu_trigger = function _CmActionMenu_trigger() {
|
|
192
|
+
if (this._custom)
|
|
193
|
+
return this.querySelector(':scope > [slot="trigger"]');
|
|
194
|
+
return this.renderRoot.querySelector('.trigger');
|
|
195
|
+
}, _CmActionMenu_enabled = function _CmActionMenu_enabled() { return this.menuItems.map((it, i) => (!it.divider && !it.disabled ? i : -1)).filter((i) => i >= 0); }, _CmActionMenu_setOpen = function _CmActionMenu_setOpen(v) {
|
|
196
|
+
if (this.open === v)
|
|
197
|
+
return;
|
|
198
|
+
this.open = v;
|
|
199
|
+
if (!v)
|
|
200
|
+
this._active = -1;
|
|
201
|
+
this.dispatchEvent(new CustomEvent('cm-toggle', { detail: { open: v }, bubbles: true, composed: true }));
|
|
202
|
+
}, _CmActionMenu_focusActive = function _CmActionMenu_focusActive() { this.renderRoot.querySelector(`[data-i="${this._active}"]`)?.focus(); }, _CmActionMenu_move = function _CmActionMenu_move(to) {
|
|
203
|
+
this._active = to;
|
|
204
|
+
this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
|
|
205
|
+
}, _CmActionMenu_choose = function _CmActionMenu_choose(e, it) {
|
|
206
|
+
if (it.disabled) {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const ok = this.dispatchEvent(new CustomEvent('cm-select', {
|
|
211
|
+
detail: { value: it.value ?? it.label, item: it }, bubbles: true, composed: true, cancelable: true,
|
|
212
|
+
}));
|
|
213
|
+
if (!ok)
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
this.hide(!it.href || !ok);
|
|
216
|
+
}, _CmActionMenu_item = function _CmActionMenu_item(it, i) {
|
|
217
|
+
if (it.divider)
|
|
218
|
+
return html `<div role="separator"></div>`;
|
|
219
|
+
const cls = `item${it.critical ? ' critical' : ''}${i === this._active ? ' active' : ''}`;
|
|
220
|
+
const inner = html `${it.icon ? html `<cm-icon name=${it.icon} size="16"></cm-icon>` : nothing}<span>${it.label}</span>`;
|
|
221
|
+
const common = {
|
|
222
|
+
over: () => { if (!it.disabled)
|
|
223
|
+
this._active = i; },
|
|
224
|
+
click: (e) => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_choose).call(this, e, it),
|
|
225
|
+
};
|
|
226
|
+
return it.href && !it.disabled
|
|
227
|
+
? html `<a class=${cls} part="item" role="menuitem" tabindex="-1" data-i=${i} href=${it.href}
|
|
228
|
+
@pointerenter=${common.over} @click=${common.click}>${inner}</a>`
|
|
229
|
+
: html `<button type="button" class=${cls} part="item" role="menuitem" tabindex="-1" data-i=${i}
|
|
230
|
+
aria-disabled=${it.disabled ? 'true' : nothing} @pointerenter=${common.over} @click=${common.click}>${inner}</button>`;
|
|
231
|
+
};
|
|
232
|
+
CmActionMenu.properties = {
|
|
233
|
+
items: { type: Array },
|
|
234
|
+
open: { type: Boolean, reflect: true },
|
|
235
|
+
label: {},
|
|
236
|
+
triggerLabel: { attribute: 'trigger-label' },
|
|
237
|
+
iconOnly: { type: Boolean, attribute: 'icon-only' },
|
|
238
|
+
icon: {},
|
|
239
|
+
align: { reflect: true },
|
|
240
|
+
heading: {},
|
|
241
|
+
subheading: {},
|
|
242
|
+
_slotted: { state: true },
|
|
243
|
+
_active: { state: true },
|
|
244
|
+
_custom: { state: true },
|
|
245
|
+
};
|
|
246
|
+
CmActionMenu.styles = [
|
|
247
|
+
base,
|
|
248
|
+
css `
|
|
249
|
+
:host { display: inline-block; position: relative; vertical-align: middle; }
|
|
250
|
+
.trigger {
|
|
251
|
+
display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; font: inherit; font-size: 14px; font-weight: 500;
|
|
252
|
+
color: var(--cm-text-default); background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input);
|
|
253
|
+
border-radius: var(--cm-radius-sm); cursor: pointer;
|
|
254
|
+
}
|
|
255
|
+
.trigger.icon { width: 36px; padding: 0; justify-content: center; border-color: transparent; background: none; }
|
|
256
|
+
.trigger:hover { background: var(--cm-bg-hover); }
|
|
257
|
+
.trigger:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
258
|
+
.pop {
|
|
259
|
+
position: absolute; z-index: 20; top: calc(100% + 4px); inset-inline-start: 0; min-width: 180px; max-width: min(320px, calc(100vw - 32px));
|
|
260
|
+
padding: 6px; text-align: start; background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-default);
|
|
261
|
+
border-radius: var(--cm-radius-sm); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
|
|
262
|
+
}
|
|
263
|
+
:host([align='end']) .pop { inset-inline-start: auto; inset-inline-end: 0; }
|
|
264
|
+
.pop[hidden] { display: none; }
|
|
265
|
+
.head { padding: 4px 6px 8px; margin-bottom: 4px; border-bottom: var(--cm-border-1) solid var(--cm-border-default); overflow-wrap: anywhere; }
|
|
266
|
+
.head strong { display: block; font-size: 14px; font-weight: 500; }
|
|
267
|
+
.head span { display: block; font-size: 11px; color: var(--cm-text-tertiary); }
|
|
268
|
+
[role='menu'] { display: flex; flex-direction: column; outline: none; }
|
|
269
|
+
.item {
|
|
270
|
+
display: flex; align-items: center; gap: 8px; width: 100%; min-height: 30px; padding: 5px 8px; font: inherit; font-size: 13px; line-height: 18px;
|
|
271
|
+
color: var(--cm-text-default); text-align: start; text-decoration: none; background: none; border: 0; border-radius: var(--cm-radius-xs);
|
|
272
|
+
cursor: pointer; outline: none;
|
|
273
|
+
}
|
|
274
|
+
.item.critical { color: var(--cm-text-critical); }
|
|
275
|
+
.item[aria-disabled='true'] { color: var(--cm-text-secondary); cursor: default; }
|
|
276
|
+
.item.active:not([aria-disabled='true']), .item:not([aria-disabled='true']):hover {
|
|
277
|
+
background: var(--cm-bg-panel-header); color: var(--cm-text-on-dark);
|
|
278
|
+
}
|
|
279
|
+
.item.active:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 1px; }
|
|
280
|
+
[role='separator'] { height: 0; margin: 4px 0; border-top: var(--cm-border-1) solid var(--cm-border-default); }
|
|
281
|
+
`,
|
|
282
|
+
];
|
|
283
|
+
define('cm-action-menu', CmActionMenu);
|