@momentum-design/components 0.129.28 → 0.129.30

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.
@@ -10,7 +10,7 @@ declare const Toggle_base: import("../../utils/mixins/index.types").Constructor<
10
10
  *
11
11
  * To create a group of toggles, use the `mdc-formfieldgroup` component.
12
12
  *
13
- * **Note:** This component internally renders a native checkbox input element styled as a toggle switch.
13
+ * **Note:** This component internally renders a native checkbox input element with the `switch` role, styled as a toggle switch.
14
14
  *
15
15
  * ## When to use
16
16
  * Use toggles for binary choices where the change takes effect immediately, such as enabling/disabling settings or features.
@@ -43,8 +43,9 @@ declare const Toggle_base: import("../../utils/mixins/index.types").Constructor<
43
43
  * @csspart help-text - The helper/validation text element.
44
44
  * @csspart helper-icon - The helper/validation icon element that is displayed next to the helper/validation text.
45
45
  * @csspart help-text-container - The container for the helper/validation icon and text elements.
46
+ * @csspart text-container - The container for the label and helper text elements.
46
47
  * @csspart static-toggle - The statictoggle that provides the visual toggle switch appearance.
47
- * @csspart toggle-input - The native checkbox input element that provides the interactive functionality.
48
+ * @csspart toggle-input - The native input element with switch role that provides the interactive functionality.
48
49
  */
49
50
  declare class Toggle extends Toggle_base implements AssociatedFormControl {
50
51
  /**
@@ -64,15 +65,15 @@ declare class Toggle extends Toggle_base implements AssociatedFormControl {
64
65
  connectedCallback(): void;
65
66
  protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
66
67
  /** @internal
67
- * Resets the checkbox to its initial state.
68
+ * Resets the toggle switch to its initial state.
68
69
  * The checked property is set to false.
69
70
  */
70
71
  formResetCallback(): void;
71
72
  /** @internal */
72
73
  formStateRestoreCallback(state: string): void;
73
74
  /**
74
- * Manages the required state of the checkbox.
75
- * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
75
+ * Manages the required state of the toggle switch.
76
+ * If the toggle switch is not checked and the required property is set, then the toggle switch is invalid.
76
77
  * If the validationMessage is set, it will be used as the custom validity message.
77
78
  * If the validationMessage is not set, it will clear the custom validity message.
78
79
  * @internal
@@ -114,6 +115,8 @@ declare class Toggle extends Toggle_base implements AssociatedFormControl {
114
115
  */
115
116
  private setToggleSize;
116
117
  update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
118
+ /** @internal */
119
+ private renderLabelAndHelperText;
117
120
  render(): import("lit-html").TemplateResult<1>;
118
121
  static styles: Array<CSSResult>;
119
122
  }
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { html } from 'lit';
10
+ import { html, nothing } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
13
  import { KEYS } from '../../utils/keys';
@@ -26,7 +26,7 @@ import styles from './toggle.styles';
26
26
  *
27
27
  * To create a group of toggles, use the `mdc-formfieldgroup` component.
28
28
  *
29
- * **Note:** This component internally renders a native checkbox input element styled as a toggle switch.
29
+ * **Note:** This component internally renders a native checkbox input element with the `switch` role, styled as a toggle switch.
30
30
  *
31
31
  * ## When to use
32
32
  * Use toggles for binary choices where the change takes effect immediately, such as enabling/disabling settings or features.
@@ -59,8 +59,9 @@ import styles from './toggle.styles';
59
59
  * @csspart help-text - The helper/validation text element.
60
60
  * @csspart helper-icon - The helper/validation icon element that is displayed next to the helper/validation text.
61
61
  * @csspart help-text-container - The container for the helper/validation icon and text elements.
62
+ * @csspart text-container - The container for the label and helper text elements.
62
63
  * @csspart static-toggle - The statictoggle that provides the visual toggle switch appearance.
63
- * @csspart toggle-input - The native checkbox input element that provides the interactive functionality.
64
+ * @csspart toggle-input - The native input element with switch role that provides the interactive functionality.
64
65
  */
65
66
  class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))) {
66
67
  constructor() {
@@ -79,6 +80,12 @@ class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin
79
80
  * @default default
80
81
  */
81
82
  this.size = DEFAULTS.SIZE;
83
+ /** @internal */
84
+ this.renderLabelAndHelperText = () => {
85
+ if (!this.label)
86
+ return nothing;
87
+ return html `<div part="text-container">${this.renderLabel()} ${this.renderHelperText()}</div>`;
88
+ };
82
89
  }
83
90
  connectedCallback() {
84
91
  super.connectedCallback();
@@ -95,7 +102,7 @@ class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin
95
102
  super.firstUpdated(_changedProperties);
96
103
  }
97
104
  /** @internal
98
- * Resets the checkbox to its initial state.
105
+ * Resets the toggle switch to its initial state.
99
106
  * The checked property is set to false.
100
107
  */
101
108
  formResetCallback() {
@@ -108,8 +115,8 @@ class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin
108
115
  }
109
116
  }
110
117
  /**
111
- * Manages the required state of the checkbox.
112
- * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
118
+ * Manages the required state of the toggle switch.
119
+ * If the toggle switch is not checked and the required property is set, then the toggle switch is invalid.
113
120
  * If the validationMessage is set, it will be used as the custom validity message.
114
121
  * If the validationMessage is not set, it will clear the custom validity message.
115
122
  * @internal
@@ -216,7 +223,7 @@ class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin
216
223
  id="${this.inputId}"
217
224
  type="checkbox"
218
225
  part="toggle-input"
219
- role="${ROLE.CHECKBOX}"
226
+ role="${ROLE.SWITCH}"
220
227
  ?required="${this.required}"
221
228
  name="${ifDefined(this.name)}"
222
229
  value="${ifDefined(this.value)}"
@@ -231,7 +238,7 @@ class Toggle extends AutoFocusOnMountMixin(FormInternalsMixin(DataAriaLabelMixin
231
238
  @keydown="${this.handleKeyDown}"
232
239
  />
233
240
  </mdc-statictoggle>
234
- ${this.renderLabel()} ${this.renderHelperText()}
241
+ ${this.renderLabelAndHelperText()}
235
242
  `;
236
243
  }
237
244
  }
@@ -9,24 +9,27 @@ const styles = [
9
9
  --mdc-label-line-height: var(--mds-font-apps-body-midsize-regular-line-height);
10
10
  }
11
11
 
12
- /* Grid layout for labeled toggles */
12
+ /* Flexbox layout for labeled toggles */
13
13
  :host([label]),
14
14
  :host([help-text]) {
15
- display: grid;
16
- grid-template-rows: auto auto;
17
- grid-template-columns: auto auto;
18
- column-gap: 0.75rem;
19
- row-gap: 0.25rem;
15
+ display: flex;
16
+ flex-direction: row;
17
+ align-items: flex-start;
18
+ gap: 0.75rem;
20
19
  }
21
20
 
22
- :host([help-text='']) {
23
- grid-template-rows: auto;
24
- row-gap: 0rem;
21
+ :host([size='default'])::part(label-text) {
22
+ margin: 0.125rem 0;
25
23
  }
26
24
 
27
- :host::part(label-text),
28
- :host::part(help-text-container) {
29
- grid-column: 2;
25
+ :host([size='compact'])::part(static-toggle) {
26
+ margin: 0.125rem 0;
27
+ }
28
+
29
+ :host::part(text-container) {
30
+ display: flex;
31
+ flex-direction: column;
32
+ gap: 0.25rem;
30
33
  }
31
34
 
32
35
  /* Component structure and layout */
@@ -37,8 +40,11 @@ const styles = [
37
40
  opacity: 0.1%;
38
41
  overflow: visible;
39
42
  z-index: 1;
40
- width: var(--mdc-statictoggle-width);
41
- height: var(--mdc-statictoggle-height);
43
+ width: 100%;
44
+ height: 100%;
45
+ top: 0;
46
+ left: 0;
47
+ cursor: pointer;
42
48
  }
43
49
 
44
50
  :host::part(label) {