@momentum-design/components 0.72.0 → 0.73.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.
Files changed (33) hide show
  1. package/dist/browser/index.js +190 -190
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/animation/animation.component.d.ts +1 -0
  4. package/dist/components/animation/animation.component.js +3 -0
  5. package/dist/components/animation/animation.types.d.ts +2 -0
  6. package/dist/components/menuitemcheckbox/menuitemcheckbox.component.d.ts +2 -1
  7. package/dist/components/menuitemcheckbox/menuitemcheckbox.component.js +2 -1
  8. package/dist/components/menuitemcheckbox/menuitemcheckbox.constants.d.ts +1 -5
  9. package/dist/components/menuitemcheckbox/menuitemcheckbox.constants.js +2 -5
  10. package/dist/components/menuitemcheckbox/menuitemcheckbox.types.d.ts +2 -3
  11. package/dist/components/menuitemradio/menuitemradio.component.d.ts +2 -2
  12. package/dist/components/menuitemradio/menuitemradio.component.js +1 -1
  13. package/dist/components/menuitemradio/menuitemradio.constants.d.ts +1 -5
  14. package/dist/components/menuitemradio/menuitemradio.constants.js +1 -5
  15. package/dist/components/menuitemradio/menuitemradio.types.d.ts +1 -4
  16. package/dist/components/menusection/index.d.ts +7 -0
  17. package/dist/components/menusection/index.js +4 -0
  18. package/dist/components/menusection/menusection.component.d.ts +58 -0
  19. package/dist/components/menusection/menusection.component.js +115 -0
  20. package/dist/components/menusection/menusection.constants.d.ts +6 -0
  21. package/dist/components/menusection/menusection.constants.js +7 -0
  22. package/dist/components/menusection/menusection.types.d.ts +4 -0
  23. package/dist/components/menusection/menusection.types.js +1 -0
  24. package/dist/custom-elements.json +749 -706
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +2 -1
  27. package/dist/react/animation/index.d.ts +2 -0
  28. package/dist/react/animation/index.js +2 -0
  29. package/dist/react/index.d.ts +3 -2
  30. package/dist/react/index.js +3 -2
  31. package/dist/react/menusection/index.d.ts +16 -0
  32. package/dist/react/menusection/index.js +25 -0
  33. package/package.json +1 -1
@@ -10,6 +10,7 @@ import { AnimationNames, LoopType } from './animation.types';
10
10
  *
11
11
  * @tagname mdc-animation
12
12
  *
13
+ * @event load - (React: onLoad) This event is dispatched when the animation is loaded
13
14
  * @event complete - (React: onComplete) This event is dispatched when all animation loops completed
14
15
  * @event error - (React: onError) This event is dispatched when animation loading failed
15
16
  */
@@ -23,6 +23,7 @@ import { DEFAULTS } from './animation.constants';
23
23
  *
24
24
  * @tagname mdc-animation
25
25
  *
26
+ * @event load - (React: onLoad) This event is dispatched when the animation is loaded
26
27
  * @event complete - (React: onComplete) This event is dispatched when all animation loops completed
27
28
  * @event error - (React: onError) This event is dispatched when animation loading failed
28
29
  */
@@ -104,6 +105,8 @@ class Animation extends Component {
104
105
  });
105
106
  this.lottieInstance.addEventListener('complete', this.onCompleteHandler);
106
107
  }
108
+ // Dispatch load event when animation ready to play
109
+ this.dispatchEvent(new CustomEvent('load', { bubbles: true, cancelable: true, detail: { name: this.name } }));
107
110
  }
108
111
  /**
109
112
  * Error handler for animation loading
@@ -1,6 +1,8 @@
1
1
  import type AnimationNames from '@momentum-design/animations/dist/types/types';
2
2
  /** Event mapping for React */
3
3
  interface Events {
4
+ /** This event is dispatched when the animation is loaded */
5
+ onLoadEvent: Event;
4
6
  /** This event is dispatched when all animation loops completed */
5
7
  onCompleteEvent: Event;
6
8
  /** This event is dispatched when animation loading failed */
@@ -1,6 +1,7 @@
1
1
  import type { CSSResult, TemplateResult } from 'lit';
2
2
  import MenuItem from '../menuitem/menuitem.component';
3
- import type { AriaCheckedStates, Indicator } from './menuitemcheckbox.types';
3
+ import type { Indicator } from './menuitemcheckbox.types';
4
+ import type { AriaCheckedStates } from '../menusection/menusection.types';
4
5
  /**
5
6
  * A menuitemcheckbox component is a checkable menuitem.
6
7
  * There should be no focusable descendants inside this menuitemcheckbox component.
@@ -13,7 +13,8 @@ import { ROLE } from '../../utils/roles';
13
13
  import MenuItem from '../menuitem/menuitem.component';
14
14
  import { TYPE } from '../text/text.constants';
15
15
  import { TOGGLE_SIZE } from '../toggle/toggle.constants';
16
- import { ARIA_CHECKED_STATES, DEFAULTS, INDICATOR } from './menuitemcheckbox.constants';
16
+ import { DEFAULTS, INDICATOR } from './menuitemcheckbox.constants';
17
+ import { ARIA_CHECKED_STATES } from '../menusection/menusection.constants';
17
18
  import styles from './menuitemcheckbox.styles';
18
19
  /**
19
20
  * A menuitemcheckbox component is a checkable menuitem.
@@ -1,8 +1,4 @@
1
1
  declare const TAG_NAME: "mdc-menuitemcheckbox";
2
- declare const ARIA_CHECKED_STATES: {
3
- readonly FALSE: "false";
4
- readonly TRUE: "true";
5
- };
6
2
  declare const INDICATOR: {
7
3
  readonly CHECKBOX: "checkbox";
8
4
  readonly CHECKMARK: "checkmark";
@@ -12,4 +8,4 @@ declare const DEFAULTS: {
12
8
  readonly ARIA_CHECKED: "false";
13
9
  readonly INDICATOR: "checkbox";
14
10
  };
15
- export { TAG_NAME, ARIA_CHECKED_STATES, INDICATOR, DEFAULTS };
11
+ export { TAG_NAME, INDICATOR, DEFAULTS };
@@ -1,9 +1,6 @@
1
1
  import utils from '../../utils/tag-name';
2
+ import { ARIA_CHECKED_STATES } from '../menusection/menusection.constants';
2
3
  const TAG_NAME = utils.constructTagName('menuitemcheckbox');
3
- const ARIA_CHECKED_STATES = {
4
- FALSE: 'false',
5
- TRUE: 'true',
6
- };
7
4
  const INDICATOR = {
8
5
  CHECKBOX: 'checkbox',
9
6
  CHECKMARK: 'checkmark',
@@ -13,4 +10,4 @@ const DEFAULTS = {
13
10
  ARIA_CHECKED: ARIA_CHECKED_STATES.FALSE,
14
11
  INDICATOR: INDICATOR.CHECKBOX,
15
12
  };
16
- export { TAG_NAME, ARIA_CHECKED_STATES, INDICATOR, DEFAULTS };
13
+ export { TAG_NAME, INDICATOR, DEFAULTS };
@@ -1,10 +1,9 @@
1
1
  import { ValueOf } from '../../utils/types';
2
- import { ARIA_CHECKED_STATES, INDICATOR } from './menuitemcheckbox.constants';
3
- type AriaCheckedStates = ValueOf<typeof ARIA_CHECKED_STATES>;
2
+ import { INDICATOR } from './menuitemcheckbox.constants';
4
3
  type Indicator = ValueOf<typeof INDICATOR>;
5
4
  interface Events {
6
5
  onChangeEvent: Event;
7
6
  onClickEvent: MouseEvent;
8
7
  onFocusEvent: FocusEvent;
9
8
  }
10
- export type { Events, AriaCheckedStates, Indicator };
9
+ export type { Events, Indicator };
@@ -1,6 +1,6 @@
1
1
  import type { CSSResult } from 'lit';
2
2
  import MenuItem from '../menuitem/menuitem.component';
3
- import { AriaChecked } from './menuitemradio.types';
3
+ import type { AriaCheckedStates } from '../menusection/menusection.types';
4
4
  /**
5
5
  * A menuitemradio component is a checkable menuitem that is used in a menu.
6
6
  * A menuitemradio should be checked only one at a time. <br/>
@@ -26,7 +26,7 @@ declare class MenuItemRadio extends MenuItem {
26
26
  * The aria-checked attribute is used to indicate that the menuitemradio is checked or not.
27
27
  * @default 'false'
28
28
  */
29
- ariaChecked: AriaChecked;
29
+ ariaChecked: AriaCheckedStates;
30
30
  connectedCallback(): void;
31
31
  render(): import("lit-html").TemplateResult<1>;
32
32
  static styles: Array<CSSResult>;
@@ -12,7 +12,7 @@ import { property } from 'lit/decorators.js';
12
12
  import { ROLE } from '../../utils/roles';
13
13
  import MenuItem from '../menuitem/menuitem.component';
14
14
  import { TYPE } from '../text/text.constants';
15
- import { ARIA_CHECKED_STATES } from './menuitemradio.constants';
15
+ import { ARIA_CHECKED_STATES } from '../menusection/menusection.constants';
16
16
  /**
17
17
  * A menuitemradio component is a checkable menuitem that is used in a menu.
18
18
  * A menuitemradio should be checked only one at a time. <br/>
@@ -1,6 +1,2 @@
1
1
  declare const TAG_NAME: "mdc-menuitemradio";
2
- declare const ARIA_CHECKED_STATES: {
3
- readonly TRUE: "true";
4
- readonly FALSE: "false";
5
- };
6
- export { TAG_NAME, ARIA_CHECKED_STATES };
2
+ export { TAG_NAME };
@@ -1,7 +1,3 @@
1
1
  import utils from '../../utils/tag-name';
2
2
  const TAG_NAME = utils.constructTagName('menuitemradio');
3
- const ARIA_CHECKED_STATES = {
4
- TRUE: 'true',
5
- FALSE: 'false',
6
- };
7
- export { TAG_NAME, ARIA_CHECKED_STATES };
3
+ export { TAG_NAME };
@@ -1,9 +1,6 @@
1
- import { ValueOf } from '../../utils/types';
2
- import { ARIA_CHECKED_STATES } from './menuitemradio.constants';
3
- type AriaChecked = ValueOf<typeof ARIA_CHECKED_STATES>;
4
1
  interface Events {
5
2
  onChangeEvent: Event;
6
3
  onClickEvent: MouseEvent;
7
4
  onFocusEvent: FocusEvent;
8
5
  }
9
- export type { Events, AriaChecked };
6
+ export type { Events };
@@ -0,0 +1,7 @@
1
+ import MenuSection from './menusection.component';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ ['mdc-menusection']: MenuSection;
5
+ }
6
+ }
7
+ export default MenuSection;
@@ -0,0 +1,4 @@
1
+ import MenuSection from './menusection.component';
2
+ import { TAG_NAME } from './menusection.constants';
3
+ MenuSection.register(TAG_NAME);
4
+ export default MenuSection;
@@ -0,0 +1,58 @@
1
+ import { CSSResult } from 'lit';
2
+ import type MenuItemRadio from '../menuitemradio/menuitemradio.component';
3
+ import { Component } from '../../models';
4
+ /**
5
+ * `mdc-menusection` is a container element used to group a set of menu items.
6
+ *
7
+ * This component supports a mix of `menuitem`, `menuitemcheckbox`, and `menuitemradio` components.
8
+ *
9
+ * - If multiple `menuitemradio` components are slotted into the section, the group enforces a single-selection rule:
10
+ * only one radio item can be selected at a time.
11
+ * - If `menuitemcheckbox` components are included, their checked state can be toggled independently.
12
+ *
13
+ * @tagname mdc-menusection
14
+ *
15
+ * @slot - Default slot for inserting `menuitem`, `menuitemcheckbox`, or `menuitemradio`
16
+ */
17
+ declare class MenuSection extends Component {
18
+ /**
19
+ * Query assigned `menuitemradio` elements from the default slot.
20
+ * These elements are used to enforce single-selection behavior.
21
+ *
22
+ * @internal
23
+ */
24
+ radios: MenuItemRadio[];
25
+ connectedCallback(): void;
26
+ disconnectedCallback(): void;
27
+ /**
28
+ * Handles `click` events within the component.
29
+ * Delegates logic to `toggleCheckedState()` based on the clicked element.
30
+ *
31
+ * @param event - The click event from a child menu item
32
+ *
33
+ * @internal
34
+ */
35
+ private handleClick;
36
+ /**
37
+ * Handles `keydown` events within the component.
38
+ * Activates menu items when the Enter or Space keys are pressed.
39
+ *
40
+ * @param event - The keyboard event from a child menu item
41
+ *
42
+ * @internal
43
+ */
44
+ private handleKeydown;
45
+ /**
46
+ * Toggles the `aria-checked` state on a target menu item based on its tag name.
47
+ * - For checkboxes, toggles the checked state.
48
+ * - For radios, ensures only one item is selected in the group.
49
+ *
50
+ * @param target - The event target element to update
51
+ *
52
+ * @internal
53
+ */
54
+ private toggleCheckedState;
55
+ render(): import("lit-html").TemplateResult<1>;
56
+ static styles: CSSResult[];
57
+ }
58
+ export default MenuSection;
@@ -0,0 +1,115 @@
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 { queryAssignedElements } from 'lit/decorators.js';
12
+ import { TAG_NAME as MENUITEMRADIO_TAGNAME } from '../menuitemradio/menuitemradio.constants';
13
+ import { TAG_NAME as MENUITEMCHECKBOX_TAGNAME } from '../menuitemcheckbox/menuitemcheckbox.constants';
14
+ import { ARIA_CHECKED_STATES } from './menusection.constants';
15
+ import { Component } from '../../models';
16
+ import { ROLE } from '../../utils/roles';
17
+ import { KEYS } from '../../utils/keys';
18
+ /**
19
+ * `mdc-menusection` is a container element used to group a set of menu items.
20
+ *
21
+ * This component supports a mix of `menuitem`, `menuitemcheckbox`, and `menuitemradio` components.
22
+ *
23
+ * - If multiple `menuitemradio` components are slotted into the section, the group enforces a single-selection rule:
24
+ * only one radio item can be selected at a time.
25
+ * - If `menuitemcheckbox` components are included, their checked state can be toggled independently.
26
+ *
27
+ * @tagname mdc-menusection
28
+ *
29
+ * @slot - Default slot for inserting `menuitem`, `menuitemcheckbox`, or `menuitemradio`
30
+ */
31
+ class MenuSection extends Component {
32
+ constructor() {
33
+ super(...arguments);
34
+ /**
35
+ * Handles `click` events within the component.
36
+ * Delegates logic to `toggleCheckedState()` based on the clicked element.
37
+ *
38
+ * @param event - The click event from a child menu item
39
+ *
40
+ * @internal
41
+ */
42
+ this.handleClick = (event) => {
43
+ this.toggleCheckedState(event.target);
44
+ };
45
+ /**
46
+ * Handles `keydown` events within the component.
47
+ * Activates menu items when the Enter or Space keys are pressed.
48
+ *
49
+ * @param event - The keyboard event from a child menu item
50
+ *
51
+ * @internal
52
+ */
53
+ this.handleKeydown = (event) => {
54
+ if (event.key !== KEYS.ENTER && event.key !== KEYS.SPACE)
55
+ return;
56
+ if (event.key === KEYS.SPACE) {
57
+ event.preventDefault(); // Prevent page scroll
58
+ }
59
+ this.toggleCheckedState(event.target);
60
+ };
61
+ }
62
+ connectedCallback() {
63
+ super.connectedCallback();
64
+ this.setAttribute('role', ROLE.GROUP);
65
+ this.addEventListener('click', this.handleClick);
66
+ this.addEventListener('keydown', this.handleKeydown);
67
+ }
68
+ disconnectedCallback() {
69
+ super.disconnectedCallback();
70
+ this.removeEventListener('click', this.handleClick);
71
+ this.removeEventListener('keydown', this.handleKeydown);
72
+ }
73
+ /**
74
+ * Toggles the `aria-checked` state on a target menu item based on its tag name.
75
+ * - For checkboxes, toggles the checked state.
76
+ * - For radios, ensures only one item is selected in the group.
77
+ *
78
+ * @param target - The event target element to update
79
+ *
80
+ * @internal
81
+ */
82
+ toggleCheckedState(target) {
83
+ if (!(target instanceof HTMLElement))
84
+ return;
85
+ // Do not toggle state for disabled elements
86
+ if (target.hasAttribute('disabled'))
87
+ return;
88
+ const tagName = target.tagName.toLowerCase();
89
+ const currentChecked = target.getAttribute('aria-checked') === ARIA_CHECKED_STATES.TRUE;
90
+ switch (tagName) {
91
+ case MENUITEMCHECKBOX_TAGNAME:
92
+ target.setAttribute('aria-checked', String(!currentChecked));
93
+ break;
94
+ case MENUITEMRADIO_TAGNAME:
95
+ if (currentChecked)
96
+ return;
97
+ this.radios.forEach((radio) => {
98
+ const newCheckedState = radio === target ? ARIA_CHECKED_STATES.TRUE : ARIA_CHECKED_STATES.FALSE;
99
+ radio.setAttribute('aria-checked', newCheckedState);
100
+ });
101
+ break;
102
+ default:
103
+ break;
104
+ }
105
+ }
106
+ render() {
107
+ return html `<slot></slot>`;
108
+ }
109
+ }
110
+ MenuSection.styles = [...Component.styles];
111
+ __decorate([
112
+ queryAssignedElements({ selector: `${MENUITEMRADIO_TAGNAME}:not([disabled])` }),
113
+ __metadata("design:type", Array)
114
+ ], MenuSection.prototype, "radios", void 0);
115
+ export default MenuSection;
@@ -0,0 +1,6 @@
1
+ declare const TAG_NAME: "mdc-menusection";
2
+ declare const ARIA_CHECKED_STATES: {
3
+ readonly TRUE: "true";
4
+ readonly FALSE: "false";
5
+ };
6
+ export { ARIA_CHECKED_STATES, TAG_NAME };
@@ -0,0 +1,7 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('menusection');
3
+ const ARIA_CHECKED_STATES = {
4
+ TRUE: 'true',
5
+ FALSE: 'false',
6
+ };
7
+ export { ARIA_CHECKED_STATES, TAG_NAME };
@@ -0,0 +1,4 @@
1
+ import { ValueOf } from '../../utils/types';
2
+ import { ARIA_CHECKED_STATES } from './menusection.constants';
3
+ type AriaCheckedStates = ValueOf<typeof ARIA_CHECKED_STATES>;
4
+ export type { AriaCheckedStates };
@@ -0,0 +1 @@
1
+ export {};