@momentum-design/components 0.18.6 → 0.19.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.
@@ -1,11 +1,12 @@
1
1
  import utils from '../../utils/tag-name';
2
2
  const TAG_NAME = utils.constructTagName('iconprovider');
3
3
  const ALLOWED_FILE_EXTENSIONS = ['svg'];
4
- const ALLOWED_LENGTH_UNITS = ['em', 'rem', 'px'];
4
+ const ALLOWED_LENGTH_UNITS = ['em', 'rem', 'px', '%'];
5
5
  const LENGTH_UNIT_SIZE = {
6
6
  px: 16,
7
7
  em: 1,
8
8
  rem: 1,
9
+ '%': 100,
9
10
  };
10
11
  const DEFAULTS = {
11
12
  FILE_EXTENSION: 'svg',
@@ -0,0 +1,8 @@
1
+ import Toggle from './toggle.component';
2
+ import '../icon';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ ['mdc-toggle']: Toggle;
6
+ }
7
+ }
8
+ export default Toggle;
@@ -0,0 +1,5 @@
1
+ import Toggle from './toggle.component';
2
+ import { TAG_NAME } from './toggle.constants';
3
+ import '../icon';
4
+ Toggle.register(TAG_NAME);
5
+ export default Toggle;
@@ -0,0 +1,84 @@
1
+ import { CSSResult, PropertyValueMap } from 'lit';
2
+ import FormfieldWrapper from '../formfieldwrapper';
3
+ import { ToggleSize } from './toggle.types';
4
+ declare const Toggle_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/NameMixin").NameMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/ValueMixin").ValueMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
5
+ /**
6
+ * Toggle Component is an interactive control used to switch between two mutually exclusive options,
7
+ * such as On/Off, Active/Inactive. These are commonly used in settings panels, forms, and preference selections
8
+ * where users need to enable or disable a feature.
9
+ * It contains an optional label and an optional helper text.
10
+ *
11
+ * Note: It internally renders a checkbox styled as a toggle switch.
12
+ *
13
+ * @dependency mdc-icon
14
+ *
15
+ * @tagname mdc-toggle
16
+ *
17
+ * @cssproperty --mdc-toggle-width - width of the toggle
18
+ * @cssproperty --mdc-toggle-height - height of the toggle
19
+ * @cssproperty --mdc-toggle-width-compact - width of the toggle when it's size is compact
20
+ * @cssproperty --mdc-toggle-height-compact - height of the toggle when it's size is compact
21
+ * @cssproperty --mdc-toggle-border-radius - border radius of the toggle
22
+ * @cssproperty --mdc-toggle-border-radius-compact - border radius of the toggle when it's size is compact
23
+ * @cssproperty --mdc-toggle-border - border of the toggle
24
+ * @cssproperty --mdc-toggle-inactive-rest-color - background color of the inactive toggle in rest state
25
+ * @cssproperty --mdc-toggle-inactive-hover-color - background color of the inactive toggle in hover state
26
+ * @cssproperty --mdc-toggle-inactive-pressed-color - background color of the inactive toggle in pressed state
27
+ * @cssproperty --mdc-toggle-inactive-disabled-color - background color of the inactive toggle in disabled state
28
+ * @cssproperty --mdc-toggle-active-rest-color - background color of the active toggle in rest state
29
+ * @cssproperty --mdc-toggle-active-hover-color - background color of the active toggle in hover state
30
+ * @cssproperty --mdc-toggle-active-pressed-color - background color of the active toggle in pressed state
31
+ * @cssproperty --mdc-toggle-active-disabled-color - background color of the active toggle in disabled state
32
+ * @cssproperty --mdc-toggle-help-text-color - color of the help text label
33
+ * @cssproperty --mdc-toggle-label-color-disabled - color of the toggle label and help text in disabled state
34
+ *
35
+ */
36
+ declare class Toggle extends Toggle_base {
37
+ /**
38
+ * Determines whether the toggle is active or inactive.
39
+ * @default false
40
+ */
41
+ checked: boolean;
42
+ /**
43
+ * Determines toggle size in rem (height is specified here).
44
+ * - **Default**: 1.5
45
+ * - **Compact**: 1
46
+ * @default default
47
+ */
48
+ size: ToggleSize;
49
+ /** @internal */
50
+ private internals;
51
+ /** @internal */
52
+ static formAssociated: boolean;
53
+ /** @internal */
54
+ get form(): HTMLFormElement | null;
55
+ constructor();
56
+ /**
57
+ * Updates the form value to reflect the current state of the toggle.
58
+ * If toggle is switched on, the value is set to either the user-provided value or 'isActive' if no value is provided.
59
+ * If toggle is switched off, the value is set to null.
60
+ */
61
+ private setFormValue;
62
+ /**
63
+ * Toggles the state of the toggle element.
64
+ * If the element is not disabled, then the checked property is toggled.
65
+ */
66
+ private toggleState;
67
+ /**
68
+ * Toggles the state of the toggle element.
69
+ * and dispatch the new change event.
70
+ */
71
+ private handleChange;
72
+ /**
73
+ * Sets the size attribute for the toggle component.
74
+ * If the provided size is not included in the TOGGLE_SIZE,
75
+ * it defaults to the value specified in DEFAULTS.SIZE.
76
+ *
77
+ * @param size - The size to set.
78
+ */
79
+ private setToggleSize;
80
+ update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
81
+ render(): import("lit-html").TemplateResult<1>;
82
+ static styles: Array<CSSResult>;
83
+ }
84
+ export default Toggle;
@@ -0,0 +1,166 @@
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 { ifDefined } from 'lit/directives/if-defined.js';
13
+ import styles from './toggle.styles';
14
+ import FormfieldWrapper from '../formfieldwrapper';
15
+ import { ValueMixin } from '../../utils/mixins/ValueMixin';
16
+ import { NameMixin } from '../../utils/mixins/NameMixin';
17
+ import { DEFAULTS, ICON_NAME, ICON_SIZE_IN_REM, TOGGLE_SIZE } from './toggle.constants';
18
+ import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
19
+ /**
20
+ * Toggle Component is an interactive control used to switch between two mutually exclusive options,
21
+ * such as On/Off, Active/Inactive. These are commonly used in settings panels, forms, and preference selections
22
+ * where users need to enable or disable a feature.
23
+ * It contains an optional label and an optional helper text.
24
+ *
25
+ * Note: It internally renders a checkbox styled as a toggle switch.
26
+ *
27
+ * @dependency mdc-icon
28
+ *
29
+ * @tagname mdc-toggle
30
+ *
31
+ * @cssproperty --mdc-toggle-width - width of the toggle
32
+ * @cssproperty --mdc-toggle-height - height of the toggle
33
+ * @cssproperty --mdc-toggle-width-compact - width of the toggle when it's size is compact
34
+ * @cssproperty --mdc-toggle-height-compact - height of the toggle when it's size is compact
35
+ * @cssproperty --mdc-toggle-border-radius - border radius of the toggle
36
+ * @cssproperty --mdc-toggle-border-radius-compact - border radius of the toggle when it's size is compact
37
+ * @cssproperty --mdc-toggle-border - border of the toggle
38
+ * @cssproperty --mdc-toggle-inactive-rest-color - background color of the inactive toggle in rest state
39
+ * @cssproperty --mdc-toggle-inactive-hover-color - background color of the inactive toggle in hover state
40
+ * @cssproperty --mdc-toggle-inactive-pressed-color - background color of the inactive toggle in pressed state
41
+ * @cssproperty --mdc-toggle-inactive-disabled-color - background color of the inactive toggle in disabled state
42
+ * @cssproperty --mdc-toggle-active-rest-color - background color of the active toggle in rest state
43
+ * @cssproperty --mdc-toggle-active-hover-color - background color of the active toggle in hover state
44
+ * @cssproperty --mdc-toggle-active-pressed-color - background color of the active toggle in pressed state
45
+ * @cssproperty --mdc-toggle-active-disabled-color - background color of the active toggle in disabled state
46
+ * @cssproperty --mdc-toggle-help-text-color - color of the help text label
47
+ * @cssproperty --mdc-toggle-label-color-disabled - color of the toggle label and help text in disabled state
48
+ *
49
+ */
50
+ class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper))) {
51
+ /** @internal */
52
+ get form() {
53
+ return this.internals.form;
54
+ }
55
+ constructor() {
56
+ super();
57
+ /**
58
+ * Determines whether the toggle is active or inactive.
59
+ * @default false
60
+ */
61
+ this.checked = false;
62
+ /**
63
+ * Determines toggle size in rem (height is specified here).
64
+ * - **Default**: 1.5
65
+ * - **Compact**: 1
66
+ * @default default
67
+ */
68
+ this.size = DEFAULTS.SIZE;
69
+ /** @internal */
70
+ this.internals = this.attachInternals();
71
+ // Toggle does not contain helpTextType property.
72
+ this.helpTextType = undefined;
73
+ }
74
+ /**
75
+ * Updates the form value to reflect the current state of the toggle.
76
+ * If toggle is switched on, the value is set to either the user-provided value or 'isActive' if no value is provided.
77
+ * If toggle is switched off, the value is set to null.
78
+ */
79
+ setFormValue() {
80
+ let actualValue = null;
81
+ if (this.checked) {
82
+ actualValue = !this.value ? 'isActive' : this.value;
83
+ }
84
+ this.internals.setFormValue(actualValue);
85
+ }
86
+ /**
87
+ * Toggles the state of the toggle element.
88
+ * If the element is not disabled, then the checked property is toggled.
89
+ */
90
+ toggleState() {
91
+ if (!this.disabled) {
92
+ this.checked = !this.checked;
93
+ }
94
+ }
95
+ /**
96
+ * Toggles the state of the toggle element.
97
+ * and dispatch the new change event.
98
+ */
99
+ handleChange(event) {
100
+ this.toggleState();
101
+ // Re-dispatch the existing event instead of creating a new one since change event doesn't bubble out of shadow dom
102
+ const EventConstructor = event.constructor;
103
+ this.dispatchEvent(new EventConstructor(event.type, event));
104
+ }
105
+ /**
106
+ * Sets the size attribute for the toggle component.
107
+ * If the provided size is not included in the TOGGLE_SIZE,
108
+ * it defaults to the value specified in DEFAULTS.SIZE.
109
+ *
110
+ * @param size - The size to set.
111
+ */
112
+ setToggleSize(size) {
113
+ this.setAttribute('size', Object.values(TOGGLE_SIZE).includes(size) ? size : DEFAULTS.SIZE);
114
+ }
115
+ update(changedProperties) {
116
+ super.update(changedProperties);
117
+ if (changedProperties.has('checked')) {
118
+ this.setFormValue();
119
+ }
120
+ if (changedProperties.has('size')) {
121
+ this.setToggleSize(this.size);
122
+ }
123
+ }
124
+ render() {
125
+ var _a;
126
+ return html `
127
+ <div class="mdc-toggle__container mdc-focus-ring">
128
+ <input
129
+ id="${this.id}"
130
+ type="checkbox"
131
+ class="mdc-toggle__input"
132
+ role="switch"
133
+ name="${ifDefined(this.name)}"
134
+ value="${ifDefined(this.value)}"
135
+ .checked="${this.checked}"
136
+ .disabled="${this.disabled}"
137
+ aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
138
+ tabindex="${this.disabled ? -1 : 0}"
139
+ @change="${this.handleChange}"
140
+ />
141
+ <div class="mdc-toggle__slider">
142
+ <mdc-icon
143
+ name="${this.checked ? ICON_NAME.CHECKED : ICON_NAME.UNCHECKED}"
144
+ class="mdc-toggle__icon"
145
+ length-unit="rem"
146
+ size="${ICON_SIZE_IN_REM[this.size]}"
147
+ ></mdc-icon>
148
+ </div>
149
+ </div>
150
+ ${this.renderLabel()}
151
+ ${this.renderHelperText()}
152
+ `;
153
+ }
154
+ }
155
+ /** @internal */
156
+ Toggle.formAssociated = true;
157
+ Toggle.styles = [...FormfieldWrapper.styles, ...styles];
158
+ __decorate([
159
+ property({ type: Boolean, reflect: true }),
160
+ __metadata("design:type", Object)
161
+ ], Toggle.prototype, "checked", void 0);
162
+ __decorate([
163
+ property({ type: String, reflect: true }),
164
+ __metadata("design:type", String)
165
+ ], Toggle.prototype, "size", void 0);
166
+ export default Toggle;
@@ -0,0 +1,17 @@
1
+ declare const TAG_NAME: "mdc-toggle";
2
+ declare const TOGGLE_SIZE: {
3
+ readonly DEFAULT: "default";
4
+ readonly COMPACT: "compact";
5
+ };
6
+ declare const ICON_NAME: {
7
+ readonly CHECKED: "check-bold";
8
+ readonly UNCHECKED: "cancel-bold";
9
+ };
10
+ declare const ICON_SIZE_IN_REM: {
11
+ compact: number;
12
+ default: number;
13
+ };
14
+ declare const DEFAULTS: {
15
+ readonly SIZE: "default";
16
+ };
17
+ export { TAG_NAME, DEFAULTS, TOGGLE_SIZE, ICON_NAME, ICON_SIZE_IN_REM };
@@ -0,0 +1,18 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('toggle');
3
+ const TOGGLE_SIZE = {
4
+ DEFAULT: 'default',
5
+ COMPACT: 'compact',
6
+ };
7
+ const ICON_NAME = {
8
+ CHECKED: 'check-bold',
9
+ UNCHECKED: 'cancel-bold',
10
+ };
11
+ const ICON_SIZE_IN_REM = {
12
+ compact: 0.75,
13
+ default: 1.25,
14
+ };
15
+ const DEFAULTS = {
16
+ SIZE: TOGGLE_SIZE.DEFAULT,
17
+ };
18
+ export { TAG_NAME, DEFAULTS, TOGGLE_SIZE, ICON_NAME, ICON_SIZE_IN_REM };
@@ -0,0 +1,2 @@
1
+ declare const styles: import("lit").CSSResult[];
2
+ export default styles;
@@ -0,0 +1,148 @@
1
+ import { css } from 'lit';
2
+ import { hostFitContentStyles, hostFocusRingStyles } from '../../utils/styles';
3
+ const styles = [hostFitContentStyles, css `
4
+ :host {
5
+ --mdc-toggle-width: 3rem;
6
+ --mdc-toggle-height: 1.5rem;
7
+ --mdc-toggle-width-compact: 2rem;
8
+ --mdc-toggle-height-compact: 1rem;
9
+ --mdc-toggle-border-radius: 0.75rem;
10
+ --mdc-toggle-border-radius-compact: 0.5rem;
11
+ --mdc-toggle-border: 0.0625rem solid var(--mds-color-theme-outline-input-normal);
12
+
13
+ --mdc-toggle-inactive-rest-color: var(--mds-color-theme-control-inactive-normal);
14
+ --mdc-toggle-inactive-hover-color: var(--mds-color-theme-control-inactive-hover);
15
+ --mdc-toggle-inactive-pressed-color: var(--mds-color-theme-control-inactive-pressed);
16
+ --mdc-toggle-inactive-disabled-color: var(--mds-color-theme-control-inactive-disabled);
17
+ --mdc-toggle-active-rest-color: var(--mds-color-theme-control-active-normal);
18
+ --mdc-toggle-active-hover-color: var(--mds-color-theme-control-active-hover);
19
+ --mdc-toggle-active-pressed-color: var(--mds-color-theme-control-active-pressed);
20
+ --mdc-toggle-active-disabled-color: var(--mds-color-theme-control-active-disabled);
21
+
22
+ --mdc-toggle-label-lineheight: var(--mds-font-lineheight-body-midsize);
23
+ --mdc-toggle-label-fontsize: var(--mds-font-size-body-midsize);
24
+ --mdc-toggle-label-fontweight: 400;
25
+ --mdc-toggle-label-color-disabled: var(--mds-color-theme-text-primary-disabled);
26
+ --mdc-toggle-help-text-color: var(--mds-color-theme-text-secondary-normal);
27
+
28
+ --mdc-toggle-icon-color-normal: var(--mds-color-theme-common-inverted-text-primary-normal);
29
+ --mdc-toggle-icon-color-disabled: var(--mds-color-theme-common-inverted-text-primary-disabled);
30
+ --mdc-toggle-icon-background-color-normal: var(--mds-color-theme-common-text-primary-normal);
31
+ --mdc-toggle-icon-background-color-disabled: var(--mds-color-theme-common-text-primary-disabled);
32
+
33
+ display: grid;
34
+ grid-template-rows: auto auto;
35
+ grid-template-columns: auto auto;
36
+ column-gap: 0.75rem;
37
+ row-gap: 0.25rem;
38
+ }
39
+
40
+ :host([help-text='']) {
41
+ row-gap: 0rem;
42
+ }
43
+
44
+ .mdc-toggle__container {
45
+ position: relative;
46
+ border-radius: var(--mdc-toggle-border-radius);
47
+ }
48
+
49
+ .mdc-toggle__input {
50
+ opacity: 0;
51
+ position: absolute;
52
+ width: var(--mdc-toggle-width);
53
+ height: var(--mdc-toggle-height);
54
+ cursor: pointer;
55
+ }
56
+
57
+ .mdc-toggle__slider {
58
+ width: var(--mdc-toggle-width);
59
+ height: var(--mdc-toggle-height);
60
+ background: var(--mdc-toggle-inactive-rest-color);
61
+ border-radius: var(--mdc-toggle-border-radius);
62
+ border: var(--mdc-toggle-border);
63
+ display: flex;
64
+ align-items: center;
65
+ justify-content: flex-start;
66
+ transition: background-color 0.3s ease;
67
+ outline: none;
68
+ padding: 0.0625rem;
69
+ }
70
+
71
+ :host([checked]) .mdc-toggle__slider {
72
+ background-color: var(--mdc-toggle-active-rest-color);
73
+ justify-content: flex-end;
74
+ border-color: transparent;
75
+ }
76
+
77
+ :host([size='compact']) .mdc-toggle__slider {
78
+ width: var(--mdc-toggle-width-compact);
79
+ height: var(--mdc-toggle-height-compact);
80
+ border-radius: var(--mdc-toggle-border-radius-compact);
81
+ }
82
+
83
+ .mdc-toggle__icon {
84
+ padding: 0.25rem;
85
+ --mdc-icon-fill-color: var(--mdc-toggle-icon-color-normal);
86
+ background-color: var(--mdc-toggle-icon-background-color-normal);
87
+ border-radius: 50%;
88
+ }
89
+
90
+ :host([disabled]) .mdc-toggle__icon {
91
+ --mdc-icon-fill-color: var(--mdc-toggle-icon-color-disabled);
92
+ }
93
+
94
+ :host([size='compact']) .mdc-toggle__icon {
95
+ padding: 0.125rem;
96
+ }
97
+
98
+ :host(:not([disabled])) .mdc-toggle__container:hover .mdc-toggle__slider {
99
+ background-color: var(--mdc-toggle-inactive-hover-color);
100
+ }
101
+
102
+ :host(:not([disabled])) .mdc-toggle__container:active .mdc-toggle__slider {
103
+ background-color: var(--mdc-toggle-inactive-pressed-color);
104
+ }
105
+
106
+ :host(:not([disabled])[checked]) .mdc-toggle__container:hover .mdc-toggle__slider {
107
+ background-color: var(--mdc-toggle-active-hover-color);
108
+ }
109
+
110
+ :host(:not([disabled])[checked]) .mdc-toggle__container:active .mdc-toggle__slider {
111
+ background-color: var(--mdc-toggle-active-pressed-color);
112
+ }
113
+
114
+ :host([disabled]) .mdc-toggle__slider {
115
+ background-color: var(--mdc-toggle-inactive-disabled-color);
116
+ }
117
+
118
+ :host([disabled][checked]) .mdc-toggle__slider {
119
+ background-color: var(--mdc-toggle-active-disabled-color);
120
+ }
121
+
122
+ :host([disabled]) .mdc-toggle__icon {
123
+ background-color: var(--mdc-toggle-icon-background-color-disabled);
124
+ }
125
+
126
+ .mdc-label-text, .mdc-help-text {
127
+ font-size: var(--mdc-toggle-label-fontsize);
128
+ font-weight: var(--mdc-toggle-label-fontweight);
129
+ line-height: var(--mdc-toggle-label-lineheight);
130
+ grid-column: 2;
131
+ }
132
+
133
+ .mdc-help-text {
134
+ color: var(--mdc-toggle-help-text-color);
135
+ }
136
+
137
+ :host([disabled]) .mdc-label-text, :host([disabled]) .mdc-help-text {
138
+ color: var(--mdc-toggle-label-color-disabled);
139
+ }
140
+
141
+ /* High Contrast Mode */
142
+ @media (forced-colors: active) {
143
+ :host([checked]) .mdc-toggle__slider, .mdc-toggle__icon {
144
+ border: var(--mdc-toggle-border);
145
+ }
146
+ }
147
+ `, ...hostFocusRingStyles(true)];
148
+ export default styles;
@@ -0,0 +1,4 @@
1
+ import type { ValueOf } from '../../utils/types';
2
+ import { TOGGLE_SIZE } from './toggle.constants';
3
+ type ToggleSize = ValueOf<typeof TOGGLE_SIZE>;
4
+ export { ToggleSize };
@@ -0,0 +1 @@
1
+ export {};