@momentum-design/components 0.115.0 → 0.116.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ import type { CSSResult } from 'lit';
2
+ import { Component } from '../../models';
3
+ import type { BannerVariant } from './banner.types';
4
+ /**
5
+ * `mdc-banner` is a component that allows applications to communicate important messages to users
6
+ * and requires user action to dismiss them. It supports different message types with appropriate styling
7
+ * and icons, and provides flexibility for customization through label, secondary label, icons, and actions.
8
+ *
9
+ * They are designed to be noticeable yet non-intrusive, helping users stay informed without interrupting their workflow.
10
+ *
11
+ * This component supports both structured content via properties and flexible customization via slots:
12
+ * - Use the properties (`label`, `secondaryLabel`, `variant`) for standard banner layouts with automatic icon selection.
13
+ * - Use slots for custom content and complete layout control.
14
+ * - Combine both approaches for maximum flexibility.
15
+ * - Create custom orientations and actions using CSS parts and slots.
16
+ *
17
+ * @dependency mdc-icon
18
+ * @dependency mdc-text
19
+ *
20
+ * @slot content - Complete content override. When used, it replaces all default banner content including icon, label, secondary label, and actions.
21
+ * @slot leading-icon - Custom icon content. Overrides the default variant-based icon.
22
+ * @slot leading-text - Custom text content. Overrides the label and secondaryLabel properties.
23
+ * @slot trailing-actions - Custom action buttons and controls. Use this for dismiss buttons, reset buttons, or any other actions.
24
+ *
25
+ * @tagname mdc-banner
26
+ *
27
+ * @csspart leading - The leading section containing the icon and text.
28
+ * @csspart leading-icon - The icon displayed for variants or custom icon slot.
29
+ * @csspart leading-text - The leading section containing label and secondary label text.
30
+ * @csspart trailing - The trailing section containing action buttons and controls.
31
+ * @csspart leading-label - The label text of the banner.
32
+ * @csspart leading-secondary-label - The secondary label text of the banner.
33
+ *
34
+ * @cssproperty --mdc-banner-background-color - Background color of the banner.
35
+ * @cssproperty --mdc-banner-border-color - Border color of the banner.
36
+ * @cssproperty --mdc-banner-icon-color - Color of the icon in the banner.
37
+ * @cssproperty --mdc-banner-elevation - Elevation/shadow of the banner.
38
+ * @cssproperty --mdc-banner-padding - Padding inside the banner.
39
+ * @cssproperty --mdc-banner-gap - Gap between banner elements.
40
+ */
41
+ declare class Banner extends Component {
42
+ /**
43
+ * The type of banner variant.
44
+ * - Can be `custom`, `informational`, `warning`, `error`, or `success`.
45
+ *
46
+ * Note: When using the `custom` variant, provide your own icon via the `leading-icon` slot; otherwise, no icon will be shown.
47
+ * @default 'custom'
48
+ */
49
+ variant: BannerVariant;
50
+ /**
51
+ * Banner label text
52
+ */
53
+ label: string;
54
+ /**
55
+ * Banner secondary label text
56
+ *
57
+ * Note: Optional supporting text that appears below the label. Only rendered when label is also provided.
58
+ */
59
+ secondaryLabel?: string;
60
+ /**
61
+ * @internal
62
+ * Renders the icon based on the provided icon name.
63
+ *
64
+ * @param iconName - The name of the icon to render
65
+ * @returns Template result containing the icon element, or nothing if no icon name provided
66
+ */
67
+ private renderIcon;
68
+ /**
69
+ * @internal
70
+ * Generates a template for the label and secondary label text.
71
+ * Returns nothing if no label is provided, ensuring secondary label is only shown when label exists.
72
+ *
73
+ * @returns Template result containing label and optional secondary label elements
74
+ */
75
+ private getTextLabel;
76
+ render(): import("lit-html").TemplateResult<1>;
77
+ static styles: Array<CSSResult>;
78
+ }
79
+ export default Banner;
@@ -0,0 +1,142 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { html, nothing } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ import { Component } from '../../models';
13
+ import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
14
+ import { DEFAULTS } from './banner.constants';
15
+ import styles from './banner.styles';
16
+ import { getIconNameForVariant } from './banner.utils';
17
+ /**
18
+ * `mdc-banner` is a component that allows applications to communicate important messages to users
19
+ * and requires user action to dismiss them. It supports different message types with appropriate styling
20
+ * and icons, and provides flexibility for customization through label, secondary label, icons, and actions.
21
+ *
22
+ * They are designed to be noticeable yet non-intrusive, helping users stay informed without interrupting their workflow.
23
+ *
24
+ * This component supports both structured content via properties and flexible customization via slots:
25
+ * - Use the properties (`label`, `secondaryLabel`, `variant`) for standard banner layouts with automatic icon selection.
26
+ * - Use slots for custom content and complete layout control.
27
+ * - Combine both approaches for maximum flexibility.
28
+ * - Create custom orientations and actions using CSS parts and slots.
29
+ *
30
+ * @dependency mdc-icon
31
+ * @dependency mdc-text
32
+ *
33
+ * @slot content - Complete content override. When used, it replaces all default banner content including icon, label, secondary label, and actions.
34
+ * @slot leading-icon - Custom icon content. Overrides the default variant-based icon.
35
+ * @slot leading-text - Custom text content. Overrides the label and secondaryLabel properties.
36
+ * @slot trailing-actions - Custom action buttons and controls. Use this for dismiss buttons, reset buttons, or any other actions.
37
+ *
38
+ * @tagname mdc-banner
39
+ *
40
+ * @csspart leading - The leading section containing the icon and text.
41
+ * @csspart leading-icon - The icon displayed for variants or custom icon slot.
42
+ * @csspart leading-text - The leading section containing label and secondary label text.
43
+ * @csspart trailing - The trailing section containing action buttons and controls.
44
+ * @csspart leading-label - The label text of the banner.
45
+ * @csspart leading-secondary-label - The secondary label text of the banner.
46
+ *
47
+ * @cssproperty --mdc-banner-background-color - Background color of the banner.
48
+ * @cssproperty --mdc-banner-border-color - Border color of the banner.
49
+ * @cssproperty --mdc-banner-icon-color - Color of the icon in the banner.
50
+ * @cssproperty --mdc-banner-elevation - Elevation/shadow of the banner.
51
+ * @cssproperty --mdc-banner-padding - Padding inside the banner.
52
+ * @cssproperty --mdc-banner-gap - Gap between banner elements.
53
+ */
54
+ class Banner extends Component {
55
+ constructor() {
56
+ super(...arguments);
57
+ /**
58
+ * The type of banner variant.
59
+ * - Can be `custom`, `informational`, `warning`, `error`, or `success`.
60
+ *
61
+ * Note: When using the `custom` variant, provide your own icon via the `leading-icon` slot; otherwise, no icon will be shown.
62
+ * @default 'custom'
63
+ */
64
+ this.variant = DEFAULTS.VARIANT;
65
+ /**
66
+ * Banner label text
67
+ */
68
+ this.label = '';
69
+ }
70
+ /**
71
+ * @internal
72
+ * Renders the icon based on the provided icon name.
73
+ *
74
+ * @param iconName - The name of the icon to render
75
+ * @returns Template result containing the icon element, or nothing if no icon name provided
76
+ */
77
+ renderIcon(iconName) {
78
+ if (!iconName)
79
+ return nothing;
80
+ return html `
81
+ <mdc-icon
82
+ name="${iconName}"
83
+ size="${DEFAULTS.PREFIX_ICON_SIZE}"
84
+ part="leading-icon"
85
+ length-unit="rem"
86
+ ></mdc-icon>
87
+ `;
88
+ }
89
+ /**
90
+ * @internal
91
+ * Generates a template for the label and secondary label text.
92
+ * Returns nothing if no label is provided, ensuring secondary label is only shown when label exists.
93
+ *
94
+ * @returns Template result containing label and optional secondary label elements
95
+ */
96
+ getTextLabel() {
97
+ if (!this.label)
98
+ return nothing;
99
+ return html `
100
+ <mdc-text part="leading-label" type="${TYPE.BODY_LARGE_REGULAR}" tagname="${VALID_TEXT_TAGS.SPAN}"
101
+ >${this.label}</mdc-text
102
+ >
103
+ ${this.secondaryLabel
104
+ ? html `<mdc-text part="leading-secondary-label" type="${TYPE.BODY_MIDSIZE_REGULAR}" tagname="${VALID_TEXT_TAGS.SPAN}"
105
+ >${this.secondaryLabel}</mdc-text
106
+ >`
107
+ : nothing}
108
+ `;
109
+ }
110
+ render() {
111
+ var _a;
112
+ return html `
113
+ <slot name="content">
114
+ <div part="leading">
115
+ <slot name="leading-icon">
116
+ ${this.variant !== DEFAULTS.VARIANT ? this.renderIcon((_a = getIconNameForVariant(this.variant)) !== null && _a !== void 0 ? _a : '') : nothing}
117
+ </slot>
118
+ <slot name="leading-text">
119
+ <div part="leading-text">${this.getTextLabel()}</div>
120
+ </slot>
121
+ </div>
122
+ <div part="trailing">
123
+ <slot name="trailing-actions"></slot>
124
+ </div>
125
+ </slot>
126
+ `;
127
+ }
128
+ }
129
+ Banner.styles = [...Component.styles, ...styles];
130
+ __decorate([
131
+ property({ type: String, reflect: true }),
132
+ __metadata("design:type", String)
133
+ ], Banner.prototype, "variant", void 0);
134
+ __decorate([
135
+ property({ type: String, reflect: true }),
136
+ __metadata("design:type", String)
137
+ ], Banner.prototype, "label", void 0);
138
+ __decorate([
139
+ property({ type: String, reflect: true, attribute: 'secondary-label' }),
140
+ __metadata("design:type", String)
141
+ ], Banner.prototype, "secondaryLabel", void 0);
142
+ export default Banner;
@@ -0,0 +1,28 @@
1
+ declare const TAG_NAME: "mdc-banner";
2
+ /**
3
+ * Banner variants
4
+ */
5
+ declare const BANNER_VARIANT: {
6
+ readonly CUSTOM: "custom";
7
+ readonly INFORMATIONAL: "informational";
8
+ readonly WARNING: "warning";
9
+ readonly ERROR: "error";
10
+ readonly SUCCESS: "success";
11
+ };
12
+ /**
13
+ * Icon names for variants
14
+ */
15
+ declare const VARIANT_ICON_NAMES: {
16
+ readonly INFORMATIONAL_ICON_NAME: "info-circle-bold";
17
+ readonly SUCCESS_ICON_NAME: "check-circle-bold";
18
+ readonly WARNING_ICON_NAME: "warning-bold";
19
+ readonly ERROR_ICON_NAME: "error-legacy-bold";
20
+ };
21
+ /**
22
+ * Default values
23
+ */
24
+ declare const DEFAULTS: {
25
+ readonly VARIANT: "custom";
26
+ readonly PREFIX_ICON_SIZE: 1.5;
27
+ };
28
+ export { TAG_NAME, BANNER_VARIANT, DEFAULTS, VARIANT_ICON_NAMES };
@@ -0,0 +1,29 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('banner');
3
+ /**
4
+ * Banner variants
5
+ */
6
+ const BANNER_VARIANT = {
7
+ CUSTOM: 'custom',
8
+ INFORMATIONAL: 'informational',
9
+ WARNING: 'warning',
10
+ ERROR: 'error',
11
+ SUCCESS: 'success',
12
+ };
13
+ /**
14
+ * Icon names for variants
15
+ */
16
+ const VARIANT_ICON_NAMES = {
17
+ INFORMATIONAL_ICON_NAME: 'info-circle-bold',
18
+ SUCCESS_ICON_NAME: 'check-circle-bold',
19
+ WARNING_ICON_NAME: 'warning-bold',
20
+ ERROR_ICON_NAME: 'error-legacy-bold',
21
+ };
22
+ /**
23
+ * Default values
24
+ */
25
+ const DEFAULTS = {
26
+ VARIANT: BANNER_VARIANT.CUSTOM,
27
+ PREFIX_ICON_SIZE: 1.5,
28
+ };
29
+ export { TAG_NAME, BANNER_VARIANT, DEFAULTS, VARIANT_ICON_NAMES };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,86 @@
1
+ import { css } from 'lit';
2
+ const styles = css `
3
+ :host {
4
+ --mdc-banner-background-color: var(--mds-color-theme-background-solid-primary-normal);
5
+ --mdc-banner-border-color: var(--mds-color-theme-outline-secondary-normal);
6
+ --mdc-banner-icon-color: var(--mds-color-theme-text-primary-normal);
7
+ --mdc-banner-elevation: var(--mds-elevation-3);
8
+ --mdc-banner-padding: 0.75rem;
9
+ --mdc-banner-gap: 0.5rem;
10
+
11
+ display: flex;
12
+ padding: var(--mdc-banner-padding);
13
+ align-items: flex-start;
14
+ gap: var(--mdc-banner-gap);
15
+ align-self: stretch;
16
+ width: 100%;
17
+ background-color: var(--mdc-banner-background-color);
18
+ border: 1px solid var(--mdc-banner-border-color);
19
+ border-radius: 0.5rem;
20
+ filter: var(--mdc-banner-elevation);
21
+ }
22
+
23
+ :host([variant='success']) {
24
+ --mdc-banner-icon-color: var(--mds-color-theme-text-success-normal);
25
+ --mdc-banner-background-color: var(--mds-color-theme-background-alert-success-normal);
26
+ --mdc-banner-border-color: var(--mds-color-theme-outline-join-normal);
27
+ }
28
+
29
+ :host([variant='warning']) {
30
+ --mdc-banner-icon-color: var(--mds-color-theme-text-warning-normal);
31
+ --mdc-banner-background-color: var(--mds-color-theme-background-alert-warning-normal);
32
+ --mdc-banner-border-color: var(--mds-color-theme-outline-warning-normal);
33
+ }
34
+
35
+ :host([variant='error']) {
36
+ --mdc-banner-icon-color: var(--mds-color-theme-text-error-normal);
37
+ --mdc-banner-background-color: var(--mds-color-theme-background-alert-error-normal);
38
+ --mdc-banner-border-color: var(--mds-color-theme-outline-cancel-normal);
39
+ }
40
+
41
+ :host([variant='informational']) {
42
+ --mdc-banner-icon-color: var(--mds-color-theme-text-accent-normal);
43
+ --mdc-banner-background-color: var(--mds-color-theme-background-alert-theme-normal);
44
+ --mdc-banner-border-color: var(--mds-color-theme-outline-theme-normal);
45
+ }
46
+
47
+ :host::part(leading) {
48
+ display: flex;
49
+ align-items: flex-start;
50
+ gap: var(--mdc-banner-gap);
51
+ align-self: stretch;
52
+ flex: 1 0 0;
53
+ }
54
+
55
+ :host::part(leading-text) {
56
+ flex: 1 0 0;
57
+ display: flex;
58
+ flex-direction: column;
59
+ gap: 0.25rem;
60
+ }
61
+
62
+ :host(:not([secondary-label]))::part(leading) {
63
+ align-items: center;
64
+ }
65
+
66
+ :host::part(leading-icon) {
67
+ color: var(--mdc-banner-icon-color);
68
+ padding: 0.25rem 0;
69
+ }
70
+
71
+ :host::part(trailing) {
72
+ display: flex;
73
+ align-items: center;
74
+ gap: var(--mdc-banner-gap);
75
+ align-self: stretch;
76
+ flex-wrap: wrap;
77
+ }
78
+
79
+ ::slotted([slot='trailing-actions']) {
80
+ display: flex;
81
+ align-items: center;
82
+ gap: var(--mdc-banner-gap);
83
+ flex-wrap: wrap;
84
+ }
85
+ `;
86
+ export default [styles];
@@ -0,0 +1,4 @@
1
+ import type { ValueOf } from '../../utils/types';
2
+ import type { BANNER_VARIANT } from './banner.constants';
3
+ type BannerVariant = ValueOf<typeof BANNER_VARIANT>;
4
+ export type { BannerVariant };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { BannerVariant } from './banner.types';
2
+ declare const getIconNameForVariant: (variant: BannerVariant) => string | null;
3
+ export { getIconNameForVariant };
@@ -0,0 +1,16 @@
1
+ import { BANNER_VARIANT, VARIANT_ICON_NAMES } from './banner.constants';
2
+ const getIconNameForVariant = (variant) => {
3
+ switch (variant) {
4
+ case BANNER_VARIANT.INFORMATIONAL:
5
+ return VARIANT_ICON_NAMES.INFORMATIONAL_ICON_NAME;
6
+ case BANNER_VARIANT.SUCCESS:
7
+ return VARIANT_ICON_NAMES.SUCCESS_ICON_NAME;
8
+ case BANNER_VARIANT.WARNING:
9
+ return VARIANT_ICON_NAMES.WARNING_ICON_NAME;
10
+ case BANNER_VARIANT.ERROR:
11
+ return VARIANT_ICON_NAMES.ERROR_ICON_NAME;
12
+ default:
13
+ return null;
14
+ }
15
+ };
16
+ export { getIconNameForVariant };
@@ -0,0 +1,9 @@
1
+ import '../icon';
2
+ import '../text';
3
+ import Banner from './banner.component';
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ ['mdc-banner']: Banner;
7
+ }
8
+ }
9
+ export default Banner;
@@ -0,0 +1,6 @@
1
+ import '../icon';
2
+ import '../text';
3
+ import Banner from './banner.component';
4
+ import { TAG_NAME } from './banner.constants';
5
+ Banner.register(TAG_NAME);
6
+ export default Banner;