@momentum-design/components 0.28.5 → 0.28.7

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.
@@ -89,6 +89,7 @@ declare class Checkbox extends Checkbox_base implements AssociatedFormControl {
89
89
  */
90
90
  handleChange(event: Event): void;
91
91
  update(changedProperties: PropertyValues): void;
92
+ private renderLabelAndHelperText;
92
93
  render(): import("lit-html").TemplateResult<1>;
93
94
  static styles: Array<CSSResult>;
94
95
  }
@@ -68,6 +68,14 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
68
68
  * @default false
69
69
  */
70
70
  this.autofocus = false;
71
+ this.renderLabelAndHelperText = () => {
72
+ if (!this.label)
73
+ return nothing;
74
+ return html `<div class="text-container">
75
+ ${this.renderLabel()}
76
+ ${this.renderHelperText()}
77
+ </div>`;
78
+ };
71
79
  // Checkbox does not contain helpTextType property.
72
80
  this.helpTextType = undefined;
73
81
  }
@@ -166,7 +174,6 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
166
174
  length-unit="rem"
167
175
  ></mdc-icon>
168
176
  ` : nothing;
169
- const helpTextContent = this.helpText ? this.renderHelperText() : nothing;
170
177
  return html `
171
178
  <div class="container mdc-focus-ring">
172
179
  <input
@@ -189,10 +196,7 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
189
196
  />
190
197
  <div class="icon-container">${checkboxIconContent}</div>
191
198
  </div>
192
- <div class="text-container">
193
- ${this.renderLabel()}
194
- ${helpTextContent}
195
- </div>
199
+ ${this.renderLabelAndHelperText()}
196
200
  `;
197
201
  }
198
202
  }
@@ -61,7 +61,7 @@ declare class FormfieldWrapper extends FormfieldWrapper_base {
61
61
  * renders the mdc-label-text container that contains the label and labelInfoToggleTip.
62
62
  * @returns void
63
63
  */
64
- protected renderLabel(): import("lit-html").TemplateResult<1>;
64
+ protected renderLabel(): import("lit-html").TemplateResult<1> | typeof nothing;
65
65
  /**
66
66
  * renders the mdc-help-text container that contains the helpertext icon and helpertext.
67
67
  * @returns void
@@ -108,6 +108,8 @@ class FormfieldWrapper extends DisabledMixin(Component) {
108
108
  * @returns void
109
109
  */
110
110
  renderLabel() {
111
+ if (!this.label)
112
+ return nothing;
111
113
  return html `<div class="mdc-label-text" part="label-text">
112
114
  <slot name="label">${this.renderLabelElement()}</slot>
113
115
  <slot name="required-label">${this.renderRequiredLabel()}</slot>
@@ -109,6 +109,7 @@ declare class Radio extends Radio_base implements AssociatedFormControl {
109
109
  */
110
110
  private updateTabIndex;
111
111
  update(changedProperties: PropertyValues): void;
112
+ private renderLabelAndHelperText;
112
113
  render(): import("lit-html").TemplateResult<1>;
113
114
  static styles: Array<CSSResult>;
114
115
  }
@@ -67,6 +67,14 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
67
67
  * @default false
68
68
  */
69
69
  this.autofocus = false;
70
+ this.renderLabelAndHelperText = () => {
71
+ if (!this.label)
72
+ return nothing;
73
+ return html `<div class="mdc-radio__label-container">
74
+ ${this.renderLabel()}
75
+ ${this.renderHelperText()}
76
+ </div>`;
77
+ };
70
78
  // Radio does not contain helpTextType property.
71
79
  this.helpTextType = undefined;
72
80
  }
@@ -267,7 +275,6 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
267
275
  }
268
276
  render() {
269
277
  var _a;
270
- const helpTextContent = this.helpText ? this.renderHelperText() : nothing;
271
278
  return html `
272
279
  <div class="mdc-radio__container">
273
280
  <div class="mdc-radio__icon-container mdc-focus-ring">
@@ -291,10 +298,7 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
291
298
  />
292
299
  <span class="mdc-radio__icon"></span>
293
300
  </div>
294
- <div class="mdc-radio__label-container">
295
- ${this.renderLabel()}
296
- ${helpTextContent}
297
- </div>
301
+ ${this.renderLabelAndHelperText()}
298
302
  </div>
299
303
  `;
300
304
  }
@@ -29,7 +29,9 @@ const styles = [hostFitContentStyles, css `
29
29
  --mdc-toggle-icon-color-disabled: var(--mds-color-theme-common-inverted-text-primary-disabled);
30
30
  --mdc-toggle-icon-background-color-normal: var(--mds-color-theme-common-text-primary-normal);
31
31
  --mdc-toggle-icon-background-color-disabled: var(--mds-color-theme-common-text-primary-disabled);
32
+ }
32
33
 
34
+ :host([label]), :host([help-text]){
33
35
  display: grid;
34
36
  grid-template-rows: auto auto;
35
37
  grid-template-columns: auto auto;
@@ -38,6 +40,7 @@ const styles = [hostFitContentStyles, css `
38
40
  }
39
41
 
40
42
  :host([help-text='']) {
43
+ grid-template-rows: auto;
41
44
  row-gap: 0rem;
42
45
  }
43
46
 
@@ -49,9 +52,10 @@ const styles = [hostFitContentStyles, css `
49
52
  .mdc-toggle__input {
50
53
  opacity: 0;
51
54
  position: absolute;
55
+ cursor: pointer;
56
+ margin: 0;
52
57
  width: var(--mdc-toggle-width);
53
58
  height: var(--mdc-toggle-height);
54
- cursor: pointer;
55
59
  }
56
60
 
57
61
  .mdc-toggle__slider {
@@ -79,7 +83,11 @@ const styles = [hostFitContentStyles, css `
79
83
  height: var(--mdc-toggle-height-compact);
80
84
  border-radius: var(--mdc-toggle-border-radius-compact);
81
85
  }
82
-
86
+ :host([size='compact']) .mdc-toggle__input {
87
+ width: var(--mdc-toggle-width-compact);
88
+ height: var(--mdc-toggle-height-compact);
89
+ }
90
+
83
91
  .mdc-toggle__icon {
84
92
  padding: 0.25rem;
85
93
  --mdc-icon-fill-color: var(--mdc-toggle-icon-color-normal);
@@ -1,5 +1,5 @@
1
1
  import { CSSResult, PropertyValues, TemplateResult } from 'lit';
2
- import { Virtualizer } from '@tanstack/virtual-core';
2
+ import { Virtualizer, VirtualItem } from '@tanstack/virtual-core';
3
3
  import { Ref } from 'lit/directives/ref.js';
4
4
  import { Component } from '../../models';
5
5
  import { SetListDataProps, VirtualizerProps } from './virtualizedlist.types';
@@ -24,7 +24,7 @@ declare class VirtualizedList extends Component {
24
24
  * handling logic related when the user scrolls to the top or bottom of a list.
25
25
  * @default undefined
26
26
  */
27
- onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
27
+ onscroll: ((this: GlobalEventHandlers, ev: Event) => void) | null;
28
28
  /**
29
29
  * Object that sets and updates the virtualizer with any relevant props.
30
30
  * There are two required object props in order to get virtualization to work properly.
@@ -39,7 +39,7 @@ declare class VirtualizedList extends Component {
39
39
  * [Tanstack Virtualizer API Docs](https://tanstack.com/virtual/latest/docs/api/virtualizer)
40
40
  *
41
41
  */
42
- virtualizerprops: VirtualizerProps;
42
+ virtualizerProps: VirtualizerProps;
43
43
  /**
44
44
  * Callback that gets envoked when updates to the virtualizer interally occur.
45
45
  * This must be implemented in such a way that this function will trigger update to parent.
@@ -57,6 +57,7 @@ declare class VirtualizedList extends Component {
57
57
  private virtualizerController;
58
58
  scrollElementRef: Ref<HTMLDivElement>;
59
59
  virtualizer: Virtualizer<Element, Element> | null;
60
+ virtualItems: Array<VirtualItem>;
60
61
  constructor();
61
62
  /**
62
63
  * This override is necessary to update the virtualizer with relevant props
@@ -64,6 +65,15 @@ declare class VirtualizedList extends Component {
64
65
  * this way ensures we don't initialize a new virtualizer upon very prop change.
65
66
  */
66
67
  update(changedProperties: PropertyValues): void;
68
+ /**
69
+ * This is needed in order to ensure the initial render happens
70
+ */
71
+ firstUpdated(changedProperties: PropertyValues): void;
72
+ /**
73
+ * @internal
74
+ * Update virtuailzer with the union of the two virtualizer options (current, passed in).
75
+ */
76
+ private setVirtualizerOptions;
67
77
  connectedCallback(): void;
68
78
  /**
69
79
  * @internal
@@ -45,8 +45,9 @@ class VirtualizedList extends Component {
45
45
  * [Tanstack Virtualizer API Docs](https://tanstack.com/virtual/latest/docs/api/virtualizer)
46
46
  *
47
47
  */
48
- this.virtualizerprops = DEFAULTS.VIRTUALIZER_PROPS;
48
+ this.virtualizerProps = DEFAULTS.VIRTUALIZER_PROPS;
49
49
  this.scrollElementRef = createRef();
50
+ this.virtualItems = [];
50
51
  this.virtualizerController = null;
51
52
  this.virtualizer = null;
52
53
  this.setlistdata = null;
@@ -58,22 +59,34 @@ class VirtualizedList extends Component {
58
59
  * this way ensures we don't initialize a new virtualizer upon very prop change.
59
60
  */
60
61
  update(changedProperties) {
61
- var _a;
62
62
  super.update(changedProperties);
63
- // if the virtuailzer props change at all,
64
- // update virtuailzer with the union of the two virtualizer options (current, passed in).
65
- if (changedProperties.get('virtualizerprops')) {
66
- (_a = this.virtualizer) === null || _a === void 0 ? void 0 : _a.setOptions({ ...this.virtualizer.options, ...this.virtualizerprops });
67
- this.requestUpdate();
63
+ if (changedProperties.get('virtualizerProps')) {
64
+ this.setVirtualizerOptions();
68
65
  }
69
66
  }
67
+ /**
68
+ * This is needed in order to ensure the initial render happens
69
+ */
70
+ firstUpdated(changedProperties) {
71
+ super.firstUpdated(changedProperties);
72
+ this.setVirtualizerOptions();
73
+ }
74
+ /**
75
+ * @internal
76
+ * Update virtuailzer with the union of the two virtualizer options (current, passed in).
77
+ */
78
+ setVirtualizerOptions() {
79
+ var _a;
80
+ (_a = this.virtualizer) === null || _a === void 0 ? void 0 : _a.setOptions({ ...this.virtualizer.options, ...this.virtualizerProps });
81
+ this.requestUpdate();
82
+ }
70
83
  connectedCallback() {
71
84
  var _a;
72
85
  this.virtualizerController = new VirtualizerController(this, {
73
- count: this.virtualizerprops.count,
74
- estimateSize: (_a = this.virtualizerprops) === null || _a === void 0 ? void 0 : _a.estimateSize,
86
+ count: this.virtualizerProps.count,
87
+ estimateSize: (_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.estimateSize,
75
88
  getScrollElement: () => this.scrollElementRef.value || null,
76
- ...this.virtualizerprops,
89
+ ...this.virtualizerProps,
77
90
  });
78
91
  super.connectedCallback();
79
92
  }
@@ -89,19 +102,24 @@ class VirtualizedList extends Component {
89
102
  getVirtualizedListWrapper(virtualizerController) {
90
103
  var _a, _b;
91
104
  this.virtualizer = virtualizerController.getVirtualizer();
92
- const { getVirtualItems, measureElement, getTotalSize } = this.virtualizer;
93
- const virtualItems = getVirtualItems();
94
- // this style is required to be rendered by the client side list in order to handle scrolling properly
95
- const listStyle = {
96
- position: 'absolute',
97
- top: 0,
98
- left: 0,
99
- width: '100%',
100
- transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`,
101
- };
102
- // pass back data to client for rendering
103
- if (this.setlistdata) {
104
- this.setlistdata({ virtualItems, measureElement, listStyle });
105
+ const { getTotalSize, getVirtualItems, measureElement } = this.virtualizer;
106
+ const newVirtualItems = getVirtualItems();
107
+ // Only update client if there's a difference in virtual items
108
+ if (newVirtualItems !== this.virtualItems) {
109
+ this.virtualItems = newVirtualItems;
110
+ const virtualItems = getVirtualItems();
111
+ // this style is required to be rendered by the client side list in order to handle scrolling properly
112
+ const listStyle = {
113
+ position: 'absolute',
114
+ top: 0,
115
+ left: 0,
116
+ width: '100%',
117
+ transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`,
118
+ };
119
+ // pass back data to client for rendering
120
+ if (this.setlistdata) {
121
+ this.setlistdata({ virtualItems, measureElement, listStyle });
122
+ }
105
123
  }
106
124
  return html `<div
107
125
  part="container"
@@ -129,7 +147,7 @@ __decorate([
129
147
  __decorate([
130
148
  property({ type: Object, attribute: 'virtualizerprops' }),
131
149
  __metadata("design:type", Object)
132
- ], VirtualizedList.prototype, "virtualizerprops", void 0);
150
+ ], VirtualizedList.prototype, "virtualizerProps", void 0);
133
151
  __decorate([
134
152
  property({ type: Function, attribute: 'setlistdata' }),
135
153
  __metadata("design:type", Object)
@@ -2,8 +2,8 @@ import { CSSResult, PropertyValues, TemplateResult } from 'lit';
2
2
  import { VirtualizerProps } from './virtualizedlist.types';
3
3
  import { Component } from '../../models';
4
4
  declare class VirtualizedWrapper extends Component {
5
- onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
6
- virtualizerprops: VirtualizerProps;
5
+ onscroll: ((this: GlobalEventHandlers, ev: Event) => void) | null;
6
+ virtualizerProps: VirtualizerProps;
7
7
  list: TemplateResult<1>;
8
8
  listItemTexts: string[];
9
9
  constructor();
@@ -15,9 +15,9 @@ import { Component } from '../../models';
15
15
  class VirtualizedWrapper extends Component {
16
16
  constructor() {
17
17
  super();
18
- this.virtualizerprops = { count: 100, estimateSize: () => 100, overscan: 60 };
18
+ this.virtualizerProps = { count: 100, estimateSize: () => 100, overscan: 60 };
19
19
  this.list = html ``;
20
- this.listItemTexts = new Array(this.virtualizerprops.count)
20
+ this.listItemTexts = new Array(this.virtualizerProps.count)
21
21
  .fill(true)
22
22
  .map((_, index) => `list item number ${index}`);
23
23
  this.onscroll = null;
@@ -25,20 +25,20 @@ class VirtualizedWrapper extends Component {
25
25
  }
26
26
  update(changedProperties) {
27
27
  super.update(changedProperties);
28
- if (changedProperties.get('virtualizerprops')) {
28
+ if (changedProperties.get('virtualizerProps')) {
29
29
  this.updateListItemTextArray();
30
30
  }
31
31
  }
32
32
  connectedCallback() {
33
33
  var _a;
34
34
  super.connectedCallback();
35
- if ((_a = this.virtualizerprops) === null || _a === void 0 ? void 0 : _a.count) {
35
+ if ((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count) {
36
36
  this.updateListItemTextArray();
37
37
  }
38
38
  }
39
39
  updateListItemTextArray() {
40
40
  var _a;
41
- this.listItemTexts = new Array((_a = this.virtualizerprops) === null || _a === void 0 ? void 0 : _a.count)
41
+ this.listItemTexts = new Array((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count)
42
42
  .fill(true)
43
43
  .map((_, index) => `list item number ${index}`);
44
44
  }
@@ -53,7 +53,7 @@ class VirtualizedWrapper extends Component {
53
53
  <div style="height: 500px; width: 500px;">
54
54
  <mdc-virtualizedlist
55
55
  .onscroll=${this.onscroll}
56
- .virtualizerprops=${this.virtualizerprops}
56
+ .virtualizerProps=${this.virtualizerProps}
57
57
  .setlistdata=${this.setListData}
58
58
  >${this.list}</mdc-virtualizedlist></div>
59
59
  `;
@@ -67,7 +67,7 @@ __decorate([
67
67
  __decorate([
68
68
  property({ type: Object, attribute: 'virtualizerprops' }),
69
69
  __metadata("design:type", Object)
70
- ], VirtualizedWrapper.prototype, "virtualizerprops", void 0);
70
+ ], VirtualizedWrapper.prototype, "virtualizerProps", void 0);
71
71
  __decorate([
72
72
  state(),
73
73
  __metadata("design:type", Object)