@momentum-design/components 0.39.5 → 0.40.0

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,9 @@
1
+ import Progressbar from './progressbar.component';
2
+ import '../icon';
3
+ import '../text';
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ ['mdc-progressbar']: Progressbar;
7
+ }
8
+ }
9
+ export default Progressbar;
@@ -0,0 +1,6 @@
1
+ import Progressbar from './progressbar.component';
2
+ import { TAG_NAME } from './progressbar.constants';
3
+ import '../icon';
4
+ import '../text';
5
+ Progressbar.register(TAG_NAME);
6
+ export default Progressbar;
@@ -0,0 +1,79 @@
1
+ import { CSSResult } from 'lit';
2
+ import FormfieldWrapper from '../formfieldwrapper';
3
+ import type { Variant } from './progressbar.types';
4
+ declare const Progressbar_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
5
+ /**
6
+ * mdc-progressbar component visually represents a progress indicator, typically used to show
7
+ * the completion state of an ongoing process (e.g., loading, file upload, etc.).
8
+ * It contains an optional label and an optional helper text.
9
+ *
10
+ * - It supports mainly two types: Default and Inline
11
+ * - It supports three validation variants: Default, Success and Error.
12
+ *
13
+ * This component is created by extending FormfieldWrapper.
14
+ *
15
+ * @tagname mdc-progressbar
16
+ *
17
+ * @dependency mdc-icon
18
+ * @dependency mdc-text
19
+ *
20
+ * @cssproperty --mdc-progressbar-default-background-color - Background color of the progressbar when inactive.
21
+ * @cssproperty --mdc-progressbar-default-active-background-color - Background color of the progressbar when active.
22
+ * @cssproperty --mdc-progressbar-success-background-color - Background color of the progressbar when in success state.
23
+ * @cssproperty --mdc-progressbar-error-background-color - Background color of the progressbar when in error state.
24
+ * @cssproperty --mdc-progressbar-height - The height of the progressbar.
25
+ * @cssproperty --mdc-progressbar-border-radius - The border radius of the progressbar.
26
+ * @cssproperty --mdc-progressbar-label-color - Color of the progressbar label text.
27
+ * @cssproperty --mdc-progressbar-label-lineheight - Line height of the label text.
28
+ * @cssproperty --mdc-progressbar-label-fontsize - Font size of the label text.
29
+ * @cssproperty --mdc-progressbar-label-fontweight - Font weight of the label text.
30
+ * @cssproperty --mdc-progressbar-help-text-color - Color of the help text.
31
+ */
32
+ declare class Progressbar extends Progressbar_base {
33
+ /**
34
+ * Types of the progressbar
35
+ * - **Default**
36
+ * - **Inline**
37
+ *
38
+ * @default default
39
+ */
40
+ variant: Variant;
41
+ /**
42
+ * The current progress as a percentage, 0 to 100.
43
+ * The value will be clamped between 0 and 100.
44
+ * @default 0
45
+ */
46
+ value: string;
47
+ /**
48
+ * Define error state of the progressbar
49
+ * - **true**
50
+ * - **false**
51
+ * @default false
52
+ */
53
+ error: boolean;
54
+ connectedCallback(): void;
55
+ /**
56
+ * Ensures that the value is clamped between 0 and 100
57
+ * @returns The clamped value
58
+ * @internal
59
+ */
60
+ private get clampedValue();
61
+ /**
62
+ * Determines the validation state (success, error, or default) based on progress value and error state.
63
+ * @returns The appropriate validation state for the progressbar.
64
+ */
65
+ private getValidationVariant;
66
+ /**
67
+ * Renders the progress bar with dynamic width and variant styles.
68
+ * @returns The rendered HTML for the progress bar.
69
+ * @internal
70
+ */
71
+ private renderProgressbar;
72
+ /**
73
+ * Renders the component based on the variant (inline or default).
74
+ * @returns The rendered HTML for the component.
75
+ */
76
+ render(): import("lit-html").TemplateResult<1>;
77
+ static styles: Array<CSSResult>;
78
+ }
79
+ export default Progressbar;
@@ -0,0 +1,160 @@
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 } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ import { v4 as uuidv4 } from 'uuid';
13
+ import styles from './progressbar.styles';
14
+ import FormfieldWrapper from '../formfieldwrapper';
15
+ import { DEFAULTS, VARIANT } from './progressbar.constants';
16
+ import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
17
+ import { VALIDATION } from '../formfieldwrapper/formfieldwrapper.constants';
18
+ /**
19
+ * mdc-progressbar component visually represents a progress indicator, typically used to show
20
+ * the completion state of an ongoing process (e.g., loading, file upload, etc.).
21
+ * It contains an optional label and an optional helper text.
22
+ *
23
+ * - It supports mainly two types: Default and Inline
24
+ * - It supports three validation variants: Default, Success and Error.
25
+ *
26
+ * This component is created by extending FormfieldWrapper.
27
+ *
28
+ * @tagname mdc-progressbar
29
+ *
30
+ * @dependency mdc-icon
31
+ * @dependency mdc-text
32
+ *
33
+ * @cssproperty --mdc-progressbar-default-background-color - Background color of the progressbar when inactive.
34
+ * @cssproperty --mdc-progressbar-default-active-background-color - Background color of the progressbar when active.
35
+ * @cssproperty --mdc-progressbar-success-background-color - Background color of the progressbar when in success state.
36
+ * @cssproperty --mdc-progressbar-error-background-color - Background color of the progressbar when in error state.
37
+ * @cssproperty --mdc-progressbar-height - The height of the progressbar.
38
+ * @cssproperty --mdc-progressbar-border-radius - The border radius of the progressbar.
39
+ * @cssproperty --mdc-progressbar-label-color - Color of the progressbar label text.
40
+ * @cssproperty --mdc-progressbar-label-lineheight - Line height of the label text.
41
+ * @cssproperty --mdc-progressbar-label-fontsize - Font size of the label text.
42
+ * @cssproperty --mdc-progressbar-label-fontweight - Font weight of the label text.
43
+ * @cssproperty --mdc-progressbar-help-text-color - Color of the help text.
44
+ */
45
+ class Progressbar extends DataAriaLabelMixin(FormfieldWrapper) {
46
+ constructor() {
47
+ super(...arguments);
48
+ /**
49
+ * Types of the progressbar
50
+ * - **Default**
51
+ * - **Inline**
52
+ *
53
+ * @default default
54
+ */
55
+ this.variant = DEFAULTS.VARIANT;
56
+ /**
57
+ * The current progress as a percentage, 0 to 100.
58
+ * The value will be clamped between 0 and 100.
59
+ * @default 0
60
+ */
61
+ this.value = '0';
62
+ /**
63
+ * Define error state of the progressbar
64
+ * - **true**
65
+ * - **false**
66
+ * @default false
67
+ */
68
+ this.error = false;
69
+ /**
70
+ * Renders the progress bar with dynamic width and variant styles.
71
+ * @returns The rendered HTML for the progress bar.
72
+ * @internal
73
+ */
74
+ this.renderProgressbar = () => {
75
+ var _a;
76
+ const variant = this.getValidationVariant();
77
+ const isGap = this.clampedValue > 0 && this.clampedValue < 100;
78
+ const progressWidth = this.error ? '100' : `${this.clampedValue}`;
79
+ return html `
80
+ <div
81
+ part="progress-container ${isGap ? 'gap' : ''}"
82
+ role="progressbar"
83
+ aria-valuenow="${this.clampedValue}"
84
+ aria-valuemin="0"
85
+ aria-valuemax="100"
86
+ aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
87
+ >
88
+ <div part="progress-bar ${variant}" style="width: ${progressWidth}%"></div>
89
+ <div part="remaining"></div>
90
+ </div>
91
+ `;
92
+ };
93
+ }
94
+ connectedCallback() {
95
+ super.connectedCallback();
96
+ this.id = `mdc-progressbar-${uuidv4()}`;
97
+ this.disabled = undefined;
98
+ }
99
+ /**
100
+ * Ensures that the value is clamped between 0 and 100
101
+ * @returns The clamped value
102
+ * @internal
103
+ */
104
+ get clampedValue() {
105
+ const value = Number(this.value);
106
+ const clampedValue = Number.isNaN(value) ? 0 : Math.max(0, Math.min(100, value));
107
+ return clampedValue;
108
+ }
109
+ /**
110
+ * Determines the validation state (success, error, or default) based on progress value and error state.
111
+ * @returns The appropriate validation state for the progressbar.
112
+ */
113
+ getValidationVariant() {
114
+ if (this.error) {
115
+ this.helpTextType = VALIDATION.ERROR;
116
+ }
117
+ else if (this.clampedValue === 100) {
118
+ this.helpTextType = VALIDATION.SUCCESS;
119
+ }
120
+ else {
121
+ this.helpTextType = VALIDATION.DEFAULT;
122
+ }
123
+ return this.helpTextType;
124
+ }
125
+ /**
126
+ * Renders the component based on the variant (inline or default).
127
+ * @returns The rendered HTML for the component.
128
+ */
129
+ render() {
130
+ const isInline = this.variant === VARIANT.INLINE;
131
+ return html `
132
+ ${isInline
133
+ ? html `<div part="inline-label-container">${this.renderLabelElement()} ${this.renderProgressbar()}</div>`
134
+ : html `
135
+ <div part="label-container">
136
+ ${this.renderLabelElement()}
137
+ ${this.variant === VARIANT.DEFAULT && this.label
138
+ ? html `<span part="percentage">${this.clampedValue}%</span>`
139
+ : ''}
140
+ </div>
141
+ ${this.renderProgressbar()}
142
+ ${this.renderHelperText()}
143
+ `}
144
+ `;
145
+ }
146
+ }
147
+ Progressbar.styles = [...FormfieldWrapper.styles, ...styles];
148
+ __decorate([
149
+ property({ type: String, reflect: true }),
150
+ __metadata("design:type", String)
151
+ ], Progressbar.prototype, "variant", void 0);
152
+ __decorate([
153
+ property({ type: String, reflect: true }),
154
+ __metadata("design:type", String)
155
+ ], Progressbar.prototype, "value", void 0);
156
+ __decorate([
157
+ property({ type: Boolean, attribute: 'error' }),
158
+ __metadata("design:type", Object)
159
+ ], Progressbar.prototype, "error", void 0);
160
+ export default Progressbar;
@@ -0,0 +1,11 @@
1
+ import { VALIDATION } from '../formfieldwrapper/formfieldwrapper.constants';
2
+ declare const TAG_NAME: "mdc-progressbar";
3
+ declare const VARIANT: {
4
+ readonly DEFAULT: "default";
5
+ readonly INLINE: "inline";
6
+ };
7
+ declare const DEFAULTS: {
8
+ readonly VARIANT: "default";
9
+ readonly VALIDATION: "default";
10
+ };
11
+ export { TAG_NAME, VARIANT, VALIDATION, DEFAULTS };
@@ -0,0 +1,12 @@
1
+ import utils from '../../utils/tag-name';
2
+ import { VALIDATION } from '../formfieldwrapper/formfieldwrapper.constants';
3
+ const TAG_NAME = utils.constructTagName('progressbar');
4
+ const VARIANT = {
5
+ DEFAULT: 'default',
6
+ INLINE: 'inline',
7
+ };
8
+ const DEFAULTS = {
9
+ VARIANT: VARIANT.DEFAULT,
10
+ VALIDATION: VALIDATION.DEFAULT,
11
+ };
12
+ export { TAG_NAME, VARIANT, VALIDATION, DEFAULTS };
@@ -0,0 +1,2 @@
1
+ declare const styles: import("lit").CSSResult[];
2
+ export default styles;
@@ -0,0 +1,86 @@
1
+ import { css } from 'lit';
2
+ const styles = [css `
3
+ :host {
4
+ --mdc-progressbar-background-color: var(--mds-color-theme-control-indicator-inactive-normal);
5
+ --mdc-progressbar-active-background-color: var(--mds-color-theme-control-active-normal);
6
+ --mdc-progressbar-success-color: var(--mds-color-theme-indicator-stable);
7
+ --mdc-progressbar-error-color: var(--mds-color-theme-indicator-attention);
8
+ --mdc-progressbar-height: 0.25rem;
9
+ --mdc-progressbar-border: 0.5px solid transparent;
10
+ --mdc-progressbar-border-radius: var(--mdc-progressbar-height);
11
+
12
+ --mdc-progressbar-label-color: var(--mds-color-theme-text-primary-normal);
13
+ --mdc-progressbar-label-line-height: var(--mds-font-lineheight-body-midsize);
14
+ --mdc-progressbar-label-font-size: var(--mds-font-size-body-midsize);
15
+ --mdc-progressbar-label-font-weight: var(--mds-font-weight-regular);
16
+ --mdc-progressbar-help-text-color: var(--mds-color-theme-text-secondary-normal);
17
+
18
+ display: block;
19
+ width: 100%;
20
+ }
21
+
22
+ :host::part(label-container) {
23
+ display: flex;
24
+ justify-content: space-between;
25
+ }
26
+
27
+ :host::part(inline-label-container) {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: 0.5rem;
31
+ }
32
+
33
+ :host::part(progress-container) {
34
+ display: flex;
35
+ align-items: center;
36
+ width: 100%;
37
+ height: var(--mdc-progressbar-height);
38
+ margin: 0.5rem 0;
39
+ }
40
+
41
+ :host::part(gap) {
42
+ gap: 0.25rem;
43
+ }
44
+
45
+ :host([variant="inline"])::part(label) {
46
+ overflow: unset;
47
+ }
48
+
49
+ :host::part(progress-bar) {
50
+ height: 100%;
51
+ background-color: var(--mdc-progressbar-active-background-color);
52
+ border-radius: var(--mdc-progressbar-border-radius);
53
+ transition: width 0.3s ease-in-out;
54
+ }
55
+
56
+ :host::part(success) {
57
+ background-color: var(--mdc-progressbar-success-color);
58
+ }
59
+
60
+ :host::part(error) {
61
+ background-color: var(--mdc-progressbar-error-color);
62
+ }
63
+
64
+ :host::part(remaining) {
65
+ height: 100%;
66
+ flex-grow: 1;
67
+ background-color: var(--mdc-progressbar-background-color);
68
+ border-radius: var(--mdc-progressbar-border-radius);
69
+ }
70
+
71
+ :host::part(label-text), :host::part(help-text), :host::part(percentage) {
72
+ font-size: var(--mdc-progressbar-label-font-size);
73
+ font-weight: var(--mdc-progressbar-label-font-weight);
74
+ line-height: var(--mdc-progressbar-label-line-height);
75
+ }
76
+
77
+ :host([help-text-type="default"])::part(help-text) {
78
+ color: var(--mdc-progressbar-help-text-color);
79
+ }
80
+
81
+ @media (forced-colors: active) {
82
+ :host::part(progress-container), :host::part(progress-bar) {
83
+ border: var(--mdc-progressbar-border);
84
+ }
85
+ `];
86
+ export default styles;
@@ -0,0 +1,3 @@
1
+ import type { ValueOf } from '../../utils/types';
2
+ import { VARIANT } from './progressbar.constants';
3
+ export type Variant = ValueOf<typeof VARIANT>;
@@ -0,0 +1 @@
1
+ export {};