@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export { CmButton } from './components/button.js';
|
|
2
|
+
export { CmTextField } from './components/text-field.js';
|
|
3
|
+
export { CmCheckbox } from './components/checkbox.js';
|
|
4
|
+
export { CmRadio, CmRadioGroup } from './components/radio.js';
|
|
5
|
+
export { CmToggle } from './components/toggle.js';
|
|
6
|
+
export { CmSelect } from './components/select.js';
|
|
7
|
+
export type { SelectOption } from './components/select.js';
|
|
8
|
+
export { CmSearch } from './components/search.js';
|
|
9
|
+
export { CmFileUpload } from './components/file-upload.js';
|
|
10
|
+
export { CmOptionGroup } from './components/option-group.js';
|
|
11
|
+
export { CmTag } from './components/tag.js';
|
|
12
|
+
export { CmPageHeader } from './components/page-header.js';
|
|
13
|
+
export type { Breadcrumb } from './components/page-header.js';
|
|
14
|
+
export { CmActionBar } from './components/action-bar.js';
|
|
15
|
+
export { CmSaveBar } from './components/save-bar.js';
|
|
16
|
+
export { CmInfoPanel, CmInfoItem } from './components/info-panel.js';
|
|
17
|
+
export { CmAccordion } from './components/accordion.js';
|
|
18
|
+
export { CmEmptyState } from './components/empty-state.js';
|
|
19
|
+
export { CmSkeleton } from './components/skeleton.js';
|
|
20
|
+
export { CmSkeletonDisplay } from './components/skeleton-display.js';
|
|
21
|
+
export { CmComment, CmCommentBox } from './components/comment.js';
|
|
22
|
+
export { CmSmartTip, CmSmartTips } from './components/smart-tip.js';
|
|
23
|
+
export { CmPagination } from './components/pagination.js';
|
|
24
|
+
export { CmStatusTabs } from './components/status-tabs.js';
|
|
25
|
+
export type { StatusTab } from './components/status-tabs.js';
|
|
26
|
+
export { CmTableHeader } from './components/table-header.js';
|
|
27
|
+
export { CmDataTable } from './components/data-table.js';
|
|
28
|
+
export type { DataTableColumn, DataTableRow, SortDirection } from './components/data-table.js';
|
|
29
|
+
export type { TableColumn } from './components/table-header.js';
|
|
30
|
+
export { CmResourceList, CmResourceItem } from './components/resource-list.js';
|
|
31
|
+
export { CmNestedList, CmNestedItem } from './components/nested-list.js';
|
|
32
|
+
export { CmReportTile, CmReportTiles } from './components/report-tile.js';
|
|
33
|
+
export { CmNavItem } from './components/nav-item.js';
|
|
34
|
+
export type { NavItem } from './components/nav-item.js';
|
|
35
|
+
export { CmSideNavigation } from './components/side-navigation.js';
|
|
36
|
+
export { CmHeaderBar } from './components/header-bar.js';
|
|
37
|
+
export { CmBottomNavigation } from './components/bottom-navigation.js';
|
|
38
|
+
export { CmMobileMenu } from './components/mobile-menu.js';
|
|
39
|
+
export { CmFlashOfferBar } from './components/flash-offer-bar.js';
|
|
40
|
+
export { CmLinkTabs } from './components/link-tabs.js';
|
|
41
|
+
export { CmAppCard } from './components/app-card.js';
|
|
42
|
+
export { CmModal } from './components/modal.js';
|
|
43
|
+
export { CmSidePanel } from './components/side-panel.js';
|
|
44
|
+
export { CmFilterPanel } from './components/filter-panel.js';
|
|
45
|
+
export type { FilterValues } from './components/filter-panel.js';
|
|
46
|
+
export { CmMenuItem } from './components/menu-item.js';
|
|
47
|
+
export type { MenuItem } from './components/menu-item.js';
|
|
48
|
+
export { CmActionMenu } from './components/action-menu.js';
|
|
49
|
+
export { CmBottomSheet } from './components/bottom-sheet.js';
|
|
50
|
+
export { CmNotificationPanel, CmNotificationItem } from './components/notification-panel.js';
|
|
51
|
+
export type { NotificationItem } from './components/notification-panel.js';
|
|
52
|
+
export type { CloseReason } from './overlay.js';
|
|
53
|
+
export { CmToast, CmToastRegion, showToast } from './components/toast.js';
|
|
54
|
+
export type { ToastTone, ToastDismissReason, ShowToastOptions } from './components/toast.js';
|
|
55
|
+
export { CmSpinner } from './components/spinner.js';
|
|
56
|
+
export { CmProgressBar } from './components/progress-bar.js';
|
|
57
|
+
export { CmBadge } from './components/badge.js';
|
|
58
|
+
export { CmCard } from './components/card.js';
|
|
59
|
+
export { CmStack } from './components/stack.js';
|
|
60
|
+
export { CmGrid } from './components/grid.js';
|
|
61
|
+
export { CmLayout, CmLayoutSection } from './components/layout.js';
|
|
62
|
+
export { CmPage } from './components/page.js';
|
|
63
|
+
export type { SpaceStep } from './spacing.js';
|
|
64
|
+
export { CmBanner } from './components/banner.js';
|
|
65
|
+
export { CmIcon } from './components/icon.js';
|
|
66
|
+
export { CmTooltip } from './components/tooltip.js';
|
|
67
|
+
export { CmAvatar, initials } from './components/avatar.js';
|
|
68
|
+
export { CmThumbnail } from './components/thumbnail.js';
|
|
69
|
+
export type { IconName } from '@commmerce/icons';
|
|
70
|
+
export type { Tone } from './base.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export { CmButton } from './components/button.js';
|
|
2
|
+
export { CmTextField } from './components/text-field.js';
|
|
3
|
+
export { CmCheckbox } from './components/checkbox.js';
|
|
4
|
+
export { CmRadio, CmRadioGroup } from './components/radio.js';
|
|
5
|
+
export { CmToggle } from './components/toggle.js';
|
|
6
|
+
export { CmSelect } from './components/select.js';
|
|
7
|
+
export { CmSearch } from './components/search.js';
|
|
8
|
+
export { CmFileUpload } from './components/file-upload.js';
|
|
9
|
+
export { CmOptionGroup } from './components/option-group.js';
|
|
10
|
+
export { CmTag } from './components/tag.js';
|
|
11
|
+
export { CmPageHeader } from './components/page-header.js';
|
|
12
|
+
export { CmActionBar } from './components/action-bar.js';
|
|
13
|
+
export { CmSaveBar } from './components/save-bar.js';
|
|
14
|
+
export { CmInfoPanel, CmInfoItem } from './components/info-panel.js';
|
|
15
|
+
export { CmAccordion } from './components/accordion.js';
|
|
16
|
+
export { CmEmptyState } from './components/empty-state.js';
|
|
17
|
+
export { CmSkeleton } from './components/skeleton.js';
|
|
18
|
+
export { CmSkeletonDisplay } from './components/skeleton-display.js';
|
|
19
|
+
export { CmComment, CmCommentBox } from './components/comment.js';
|
|
20
|
+
export { CmSmartTip, CmSmartTips } from './components/smart-tip.js';
|
|
21
|
+
export { CmPagination } from './components/pagination.js';
|
|
22
|
+
export { CmStatusTabs } from './components/status-tabs.js';
|
|
23
|
+
export { CmTableHeader } from './components/table-header.js';
|
|
24
|
+
export { CmDataTable } from './components/data-table.js';
|
|
25
|
+
export { CmResourceList, CmResourceItem } from './components/resource-list.js';
|
|
26
|
+
export { CmNestedList, CmNestedItem } from './components/nested-list.js';
|
|
27
|
+
export { CmReportTile, CmReportTiles } from './components/report-tile.js';
|
|
28
|
+
export { CmNavItem } from './components/nav-item.js';
|
|
29
|
+
export { CmSideNavigation } from './components/side-navigation.js';
|
|
30
|
+
export { CmHeaderBar } from './components/header-bar.js';
|
|
31
|
+
export { CmBottomNavigation } from './components/bottom-navigation.js';
|
|
32
|
+
export { CmMobileMenu } from './components/mobile-menu.js';
|
|
33
|
+
export { CmFlashOfferBar } from './components/flash-offer-bar.js';
|
|
34
|
+
export { CmLinkTabs } from './components/link-tabs.js';
|
|
35
|
+
export { CmAppCard } from './components/app-card.js';
|
|
36
|
+
export { CmModal } from './components/modal.js';
|
|
37
|
+
export { CmSidePanel } from './components/side-panel.js';
|
|
38
|
+
export { CmFilterPanel } from './components/filter-panel.js';
|
|
39
|
+
export { CmMenuItem } from './components/menu-item.js';
|
|
40
|
+
export { CmActionMenu } from './components/action-menu.js';
|
|
41
|
+
export { CmBottomSheet } from './components/bottom-sheet.js';
|
|
42
|
+
export { CmNotificationPanel, CmNotificationItem } from './components/notification-panel.js';
|
|
43
|
+
export { CmToast, CmToastRegion, showToast } from './components/toast.js';
|
|
44
|
+
export { CmSpinner } from './components/spinner.js';
|
|
45
|
+
export { CmProgressBar } from './components/progress-bar.js';
|
|
46
|
+
export { CmBadge } from './components/badge.js';
|
|
47
|
+
export { CmCard } from './components/card.js';
|
|
48
|
+
export { CmStack } from './components/stack.js';
|
|
49
|
+
export { CmGrid } from './components/grid.js';
|
|
50
|
+
export { CmLayout, CmLayoutSection } from './components/layout.js';
|
|
51
|
+
export { CmPage } from './components/page.js';
|
|
52
|
+
export { CmBanner } from './components/banner.js';
|
|
53
|
+
export { CmIcon } from './components/icon.js';
|
|
54
|
+
export { CmTooltip } from './components/tooltip.js';
|
|
55
|
+
export { CmAvatar, initials } from './components/avatar.js';
|
|
56
|
+
export { CmThumbnail } from './components/thumbnail.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LitElement, nothing, type PropertyValues, type TemplateResult } from 'lit';
|
|
2
|
+
import './components/icon.js';
|
|
3
|
+
/** Stops the page behind an open overlay from scrolling. Counted, so stacked overlays unlock once. */
|
|
4
|
+
export declare function lockScroll(): void;
|
|
5
|
+
export declare function unlockScroll(): void;
|
|
6
|
+
/** The focused element, looking inside shadow roots. */
|
|
7
|
+
export declare function deepActiveElement(): HTMLElement | null;
|
|
8
|
+
/** Why an overlay is closing: `escape`, `backdrop`, `close-button`, `action` (a choice inside it) or `method` (`close()`). */
|
|
9
|
+
export type CloseReason = 'escape' | 'backdrop' | 'close-button' | 'action' | 'method';
|
|
10
|
+
/**
|
|
11
|
+
* Shared behaviour of the modal overlays (Modal, Side panel, Filter panel, Bottom sheet, Notification panel).
|
|
12
|
+
* A native `<dialog>` opened with `showModal()`: the rest of the page is inert, so focus stays inside; Esc and
|
|
13
|
+
* the backdrop close it through a cancelable `cm-close`; page scrolling is locked while open; focus goes back to
|
|
14
|
+
* the element that had it when the overlay opened.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CmOverlay extends LitElement {
|
|
17
|
+
#private;
|
|
18
|
+
static properties: {
|
|
19
|
+
open: {
|
|
20
|
+
type: BooleanConstructor;
|
|
21
|
+
reflect: boolean;
|
|
22
|
+
};
|
|
23
|
+
heading: {};
|
|
24
|
+
label: {};
|
|
25
|
+
closeLabel: {
|
|
26
|
+
attribute: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** Shows the overlay. Set it, or call `show()` / `close()`. */
|
|
30
|
+
open: boolean;
|
|
31
|
+
/** Title in the header. Also the dialog's accessible name. */
|
|
32
|
+
heading: string;
|
|
33
|
+
/** Accessible name when there is no visible heading. */
|
|
34
|
+
label: string;
|
|
35
|
+
/** Accessible name of the close button. */
|
|
36
|
+
closeLabel: string;
|
|
37
|
+
protected uid: string;
|
|
38
|
+
static overlayStyles: import("lit").CSSResult[];
|
|
39
|
+
/** Opens the overlay. */
|
|
40
|
+
show(): void;
|
|
41
|
+
/** Closes the overlay without asking (no `cm-close`). */
|
|
42
|
+
close(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Asks to close: fires a cancelable `cm-close` with `detail: { reason }` and closes unless it was cancelled.
|
|
45
|
+
* Returns true when the overlay closed.
|
|
46
|
+
*/
|
|
47
|
+
requestClose(reason?: CloseReason): boolean;
|
|
48
|
+
protected get dialog(): HTMLDialogElement | null;
|
|
49
|
+
protected updated(changed: PropertyValues): void;
|
|
50
|
+
/** Focus on opening: a light-DOM child with `autofocus`, otherwise the panel itself (so its name is read). */
|
|
51
|
+
protected focusFirst(): void;
|
|
52
|
+
disconnectedCallback(): void;
|
|
53
|
+
/** True when the dialog box itself is the backdrop area (the panel sits inside it). */
|
|
54
|
+
protected backdropFillsDialog: boolean;
|
|
55
|
+
protected renderHeader(extra?: TemplateResult | typeof nothing): TemplateResult<1>;
|
|
56
|
+
protected renderDialog(content: TemplateResult, cls?: string): TemplateResult<1>;
|
|
57
|
+
}
|
package/dist/overlay.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CmOverlay_instances, _CmOverlay_opener, _CmOverlay_locked, _CmOverlay_downOnBackdrop, _CmOverlay_teardown, _CmOverlay_keydown, _CmOverlay_cancel, _CmOverlay_closed, _CmOverlay_down, _CmOverlay_click;
|
|
13
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
14
|
+
import { base, nextId } from './base.js';
|
|
15
|
+
import './components/icon.js';
|
|
16
|
+
let locks = 0;
|
|
17
|
+
let savedOverflow = '';
|
|
18
|
+
/** Stops the page behind an open overlay from scrolling. Counted, so stacked overlays unlock once. */
|
|
19
|
+
export function lockScroll() {
|
|
20
|
+
if (locks++ === 0) {
|
|
21
|
+
savedOverflow = document.documentElement.style.overflow;
|
|
22
|
+
document.documentElement.style.overflow = 'hidden';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function unlockScroll() {
|
|
26
|
+
if (locks > 0 && --locks === 0)
|
|
27
|
+
document.documentElement.style.overflow = savedOverflow;
|
|
28
|
+
}
|
|
29
|
+
/** The focused element, looking inside shadow roots. */
|
|
30
|
+
export function deepActiveElement() {
|
|
31
|
+
let a = document.activeElement;
|
|
32
|
+
while (a?.shadowRoot?.activeElement)
|
|
33
|
+
a = a.shadowRoot.activeElement;
|
|
34
|
+
return a;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Shared behaviour of the modal overlays (Modal, Side panel, Filter panel, Bottom sheet, Notification panel).
|
|
38
|
+
* A native `<dialog>` opened with `showModal()`: the rest of the page is inert, so focus stays inside; Esc and
|
|
39
|
+
* the backdrop close it through a cancelable `cm-close`; page scrolling is locked while open; focus goes back to
|
|
40
|
+
* the element that had it when the overlay opened.
|
|
41
|
+
*/
|
|
42
|
+
export class CmOverlay extends LitElement {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
_CmOverlay_instances.add(this);
|
|
46
|
+
/** Shows the overlay. Set it, or call `show()` / `close()`. */
|
|
47
|
+
this.open = false;
|
|
48
|
+
/** Title in the header. Also the dialog's accessible name. */
|
|
49
|
+
this.heading = '';
|
|
50
|
+
/** Accessible name when there is no visible heading. */
|
|
51
|
+
this.label = '';
|
|
52
|
+
/** Accessible name of the close button. */
|
|
53
|
+
this.closeLabel = 'Close';
|
|
54
|
+
this.uid = nextId('cm-ovl');
|
|
55
|
+
_CmOverlay_opener.set(this, null);
|
|
56
|
+
_CmOverlay_locked.set(this, false);
|
|
57
|
+
_CmOverlay_downOnBackdrop.set(this, false);
|
|
58
|
+
_CmOverlay_keydown.set(this, (e) => {
|
|
59
|
+
if (e.key === 'Escape' && !e.defaultPrevented) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
this.requestClose('escape');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
_CmOverlay_cancel.set(this, (e) => { e.preventDefault(); this.requestClose('escape'); });
|
|
66
|
+
/** The dialog closed by itself (e.g. the browser forced it): bring `open` in line. */
|
|
67
|
+
_CmOverlay_closed.set(this, () => { if (this.open) {
|
|
68
|
+
this.open = false;
|
|
69
|
+
__classPrivateFieldGet(this, _CmOverlay_instances, "m", _CmOverlay_teardown).call(this);
|
|
70
|
+
} });
|
|
71
|
+
_CmOverlay_down.set(this, (e) => { __classPrivateFieldSet(this, _CmOverlay_downOnBackdrop, e.target === e.currentTarget, "f"); });
|
|
72
|
+
_CmOverlay_click.set(this, (e) => {
|
|
73
|
+
if (e.target === e.currentTarget && __classPrivateFieldGet(this, _CmOverlay_downOnBackdrop, "f")) {
|
|
74
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
75
|
+
const inside = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;
|
|
76
|
+
if (!inside || this.backdropFillsDialog)
|
|
77
|
+
this.requestClose('backdrop');
|
|
78
|
+
}
|
|
79
|
+
__classPrivateFieldSet(this, _CmOverlay_downOnBackdrop, false, "f");
|
|
80
|
+
});
|
|
81
|
+
/** True when the dialog box itself is the backdrop area (the panel sits inside it). */
|
|
82
|
+
this.backdropFillsDialog = false;
|
|
83
|
+
}
|
|
84
|
+
/** Opens the overlay. */
|
|
85
|
+
show() { this.open = true; }
|
|
86
|
+
/** Closes the overlay without asking (no `cm-close`). */
|
|
87
|
+
close() { this.open = false; }
|
|
88
|
+
/**
|
|
89
|
+
* Asks to close: fires a cancelable `cm-close` with `detail: { reason }` and closes unless it was cancelled.
|
|
90
|
+
* Returns true when the overlay closed.
|
|
91
|
+
*/
|
|
92
|
+
requestClose(reason = 'method') {
|
|
93
|
+
const ok = this.dispatchEvent(new CustomEvent('cm-close', { detail: { reason }, bubbles: true, composed: true, cancelable: true }));
|
|
94
|
+
if (ok)
|
|
95
|
+
this.open = false;
|
|
96
|
+
return ok;
|
|
97
|
+
}
|
|
98
|
+
get dialog() { return this.renderRoot?.querySelector('dialog'); }
|
|
99
|
+
updated(changed) {
|
|
100
|
+
super.updated(changed);
|
|
101
|
+
if (!changed.has('open'))
|
|
102
|
+
return;
|
|
103
|
+
const d = this.dialog;
|
|
104
|
+
if (!d)
|
|
105
|
+
return;
|
|
106
|
+
if (this.open && !d.open) {
|
|
107
|
+
__classPrivateFieldSet(this, _CmOverlay_opener, deepActiveElement(), "f");
|
|
108
|
+
if (!this.isConnected)
|
|
109
|
+
return;
|
|
110
|
+
d.showModal();
|
|
111
|
+
if (!__classPrivateFieldGet(this, _CmOverlay_locked, "f")) {
|
|
112
|
+
lockScroll();
|
|
113
|
+
__classPrivateFieldSet(this, _CmOverlay_locked, true, "f");
|
|
114
|
+
}
|
|
115
|
+
this.focusFirst();
|
|
116
|
+
this.dispatchEvent(new CustomEvent('cm-open', { bubbles: true, composed: true }));
|
|
117
|
+
}
|
|
118
|
+
else if (!this.open && d.open) {
|
|
119
|
+
d.close();
|
|
120
|
+
__classPrivateFieldGet(this, _CmOverlay_instances, "m", _CmOverlay_teardown).call(this);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Focus on opening: a light-DOM child with `autofocus`, otherwise the panel itself (so its name is read). */
|
|
124
|
+
focusFirst() {
|
|
125
|
+
const auto = this.querySelector('[autofocus]');
|
|
126
|
+
if (auto) {
|
|
127
|
+
auto.focus();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.renderRoot.querySelector('.panel')?.focus();
|
|
131
|
+
}
|
|
132
|
+
disconnectedCallback() {
|
|
133
|
+
super.disconnectedCallback();
|
|
134
|
+
if (__classPrivateFieldGet(this, _CmOverlay_locked, "f")) {
|
|
135
|
+
unlockScroll();
|
|
136
|
+
__classPrivateFieldSet(this, _CmOverlay_locked, false, "f");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
renderHeader(extra = nothing) {
|
|
140
|
+
return html `<header class="head" part="header">
|
|
141
|
+
<h2 id="${this.uid}-h">${this.heading}</h2>${extra}
|
|
142
|
+
<button type="button" class="x" part="close" aria-label=${this.closeLabel || 'Close'} @click=${() => this.requestClose('close-button')}>
|
|
143
|
+
<cm-icon name="close" size="18"></cm-icon></button>
|
|
144
|
+
</header>`;
|
|
145
|
+
}
|
|
146
|
+
renderDialog(content, cls = '') {
|
|
147
|
+
return html `<dialog part="dialog" class=${cls}
|
|
148
|
+
aria-labelledby=${this.heading ? `${this.uid}-h` : nothing}
|
|
149
|
+
aria-label=${!this.heading && this.label ? this.label : nothing}
|
|
150
|
+
@keydown=${__classPrivateFieldGet(this, _CmOverlay_keydown, "f")} @cancel=${__classPrivateFieldGet(this, _CmOverlay_cancel, "f")} @close=${__classPrivateFieldGet(this, _CmOverlay_closed, "f")}
|
|
151
|
+
@pointerdown=${__classPrivateFieldGet(this, _CmOverlay_down, "f")} @click=${__classPrivateFieldGet(this, _CmOverlay_click, "f")}>${content}</dialog>`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_CmOverlay_opener = new WeakMap(), _CmOverlay_locked = new WeakMap(), _CmOverlay_downOnBackdrop = new WeakMap(), _CmOverlay_keydown = new WeakMap(), _CmOverlay_cancel = new WeakMap(), _CmOverlay_closed = new WeakMap(), _CmOverlay_down = new WeakMap(), _CmOverlay_click = new WeakMap(), _CmOverlay_instances = new WeakSet(), _CmOverlay_teardown = function _CmOverlay_teardown() {
|
|
155
|
+
if (__classPrivateFieldGet(this, _CmOverlay_locked, "f")) {
|
|
156
|
+
unlockScroll();
|
|
157
|
+
__classPrivateFieldSet(this, _CmOverlay_locked, false, "f");
|
|
158
|
+
}
|
|
159
|
+
const o = __classPrivateFieldGet(this, _CmOverlay_opener, "f");
|
|
160
|
+
__classPrivateFieldSet(this, _CmOverlay_opener, null, "f");
|
|
161
|
+
if (o?.isConnected)
|
|
162
|
+
o.focus();
|
|
163
|
+
this.dispatchEvent(new CustomEvent('cm-closed', { bubbles: true, composed: true }));
|
|
164
|
+
};
|
|
165
|
+
CmOverlay.properties = {
|
|
166
|
+
open: { type: Boolean, reflect: true },
|
|
167
|
+
heading: {},
|
|
168
|
+
label: {},
|
|
169
|
+
closeLabel: { attribute: 'close-label' },
|
|
170
|
+
};
|
|
171
|
+
CmOverlay.overlayStyles = [
|
|
172
|
+
base,
|
|
173
|
+
css `
|
|
174
|
+
:host { display: contents; }
|
|
175
|
+
dialog {
|
|
176
|
+
padding: 0; border: 0; margin: 0; max-width: none; max-height: none; background: transparent; color: inherit;
|
|
177
|
+
font: inherit; overflow: visible;
|
|
178
|
+
}
|
|
179
|
+
dialog::backdrop { background: var(--cm-overlay, rgba(0, 0, 0, 0.4)); }
|
|
180
|
+
.panel {
|
|
181
|
+
display: flex; flex-direction: column; background: var(--cm-bg-surface); color: var(--cm-text-default);
|
|
182
|
+
overflow: hidden; outline: none;
|
|
183
|
+
}
|
|
184
|
+
.head {
|
|
185
|
+
display: flex; align-items: center; gap: var(--cm-space-10); flex: none; min-height: 40px; padding: 8px 10px 8px 15px;
|
|
186
|
+
background: var(--cm-bg-panel-header); color: var(--cm-text-on-dark);
|
|
187
|
+
}
|
|
188
|
+
.head h2 { flex: 1; min-width: 0; margin: 0; font-size: 14px; line-height: 20px; font-weight: 500; overflow-wrap: anywhere; }
|
|
189
|
+
.x {
|
|
190
|
+
display: grid; place-items: center; flex: none; width: 28px; height: 28px; padding: 0; border: 0; border-radius: var(--cm-radius-sm);
|
|
191
|
+
background: none; color: inherit; cursor: pointer;
|
|
192
|
+
}
|
|
193
|
+
.x:focus-visible { outline: 2px solid var(--cm-text-on-dark); outline-offset: 0; }
|
|
194
|
+
.body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--cm-space-20); font-size: 14px; line-height: 20px; }
|
|
195
|
+
.foot {
|
|
196
|
+
display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--cm-space-10); flex: none; padding: var(--cm-space-15) var(--cm-space-20);
|
|
197
|
+
border-top: var(--cm-border-1) solid var(--cm-border-default);
|
|
198
|
+
}
|
|
199
|
+
.foot[hidden] { display: none; }
|
|
200
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
201
|
+
dialog[open] .panel { animation: cm-ovl-in 160ms ease-out; }
|
|
202
|
+
}
|
|
203
|
+
@keyframes cm-ovl-in { from { opacity: 0; } to { opacity: 1; } }
|
|
204
|
+
`,
|
|
205
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CSSResult } from 'lit';
|
|
2
|
+
/** Spacing token steps that layout components accept in `gap`: `--cm-space-<step>`, or `0`. */
|
|
3
|
+
export declare const SPACE_STEPS: readonly ["0", "10", "12", "15", "20", "22", "30"];
|
|
4
|
+
export type SpaceStep = (typeof SPACE_STEPS)[number];
|
|
5
|
+
/** `:host([<attr>='20']) { <prop>: var(--cm-space-20) }` for every step. Unknown values keep the default. */
|
|
6
|
+
export declare function spaceRules(attr: string, prop: string): CSSResult;
|
package/dist/spacing.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { unsafeCSS } from 'lit';
|
|
2
|
+
/** Spacing token steps that layout components accept in `gap`: `--cm-space-<step>`, or `0`. */
|
|
3
|
+
export const SPACE_STEPS = ['0', '10', '12', '15', '20', '22', '30'];
|
|
4
|
+
/** `:host([<attr>='20']) { <prop>: var(--cm-space-20) }` for every step. Unknown values keep the default. */
|
|
5
|
+
export function spaceRules(attr, prop) {
|
|
6
|
+
return unsafeCSS(SPACE_STEPS.map((s) => `:host([${attr}='${s}']) { ${prop}: ${s === '0' ? '0px' : `var(--cm-space-${s})`}; }`).join('\n'));
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commmerce/ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-rc.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
|
+
"keywords": [
|
|
6
|
+
"web-components",
|
|
7
|
+
"custom-elements",
|
|
8
|
+
"lit",
|
|
9
|
+
"commmerce",
|
|
10
|
+
"design-system",
|
|
11
|
+
"ui"
|
|
12
|
+
],
|
|
13
|
+
"author": "Commmerce",
|
|
14
|
+
"homepage": "https://commmerce.com/blog/commmerceui/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"email": "support@commmerce.com"
|
|
17
|
+
},
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./cdn.js": "./dist/cdn.js",
|
|
28
|
+
"./components/*": {
|
|
29
|
+
"types": "./dist/components/*.d.ts",
|
|
30
|
+
"default": "./dist/components/*.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"LICENSE.md",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": [
|
|
39
|
+
"./dist/components/*.js",
|
|
40
|
+
"./dist/index.js",
|
|
41
|
+
"./dist/cdn.js"
|
|
42
|
+
],
|
|
43
|
+
"customElements": "dist/custom-elements.json",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.json && esbuild src/index.ts --bundle --minify --format=esm --target=es2021 --outfile=dist/cdn.js && cem analyze --litelement --globs \"src/components/*.ts\" --outdir dist",
|
|
49
|
+
"test": "vitest run"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@commmerce/icons": "1.0.0-rc.4",
|
|
53
|
+
"@commmerce/tokens": "1.0.0-rc.4",
|
|
54
|
+
"lit": "3.2.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
58
|
+
"@vitest/browser": "^2.1.8",
|
|
59
|
+
"playwright": "^1.49.0"
|
|
60
|
+
}
|
|
61
|
+
}
|