@momentum-design/components 0.62.2 → 0.62.4

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 (74) hide show
  1. package/dist/browser/index.js +804 -536
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/card/card.component.d.ts +100 -0
  4. package/dist/components/card/card.component.js +197 -0
  5. package/dist/components/card/card.constants.d.ts +22 -0
  6. package/dist/components/card/card.constants.js +26 -0
  7. package/dist/components/card/card.styles.d.ts +2 -0
  8. package/dist/components/card/card.styles.js +79 -0
  9. package/dist/components/card/card.types.d.ts +5 -0
  10. package/dist/components/card/card.types.js +1 -0
  11. package/dist/components/card/index.d.ts +9 -0
  12. package/dist/components/card/index.js +6 -0
  13. package/dist/components/cardbutton/cardbutton.component.d.ts +37 -0
  14. package/dist/components/cardbutton/cardbutton.component.js +61 -0
  15. package/dist/components/cardbutton/cardbutton.constants.d.ts +2 -0
  16. package/dist/components/cardbutton/cardbutton.constants.js +3 -0
  17. package/dist/components/cardbutton/cardbutton.styles.d.ts +2 -0
  18. package/dist/components/cardbutton/cardbutton.styles.js +26 -0
  19. package/dist/components/cardbutton/cardbutton.types.d.ts +7 -0
  20. package/dist/components/cardbutton/cardbutton.types.js +1 -0
  21. package/dist/components/cardbutton/index.d.ts +9 -0
  22. package/dist/components/cardbutton/index.js +6 -0
  23. package/dist/components/cardcheckbox/cardcheckbox.component.d.ts +76 -0
  24. package/dist/components/cardcheckbox/cardcheckbox.component.js +159 -0
  25. package/dist/components/cardcheckbox/cardcheckbox.constants.d.ts +15 -0
  26. package/dist/components/cardcheckbox/cardcheckbox.constants.js +16 -0
  27. package/dist/components/cardcheckbox/cardcheckbox.styles.d.ts +2 -0
  28. package/dist/components/cardcheckbox/cardcheckbox.styles.js +57 -0
  29. package/dist/components/cardcheckbox/cardcheckbox.types.d.ts +11 -0
  30. package/dist/components/cardcheckbox/cardcheckbox.types.js +1 -0
  31. package/dist/components/cardcheckbox/index.d.ts +10 -0
  32. package/dist/components/cardcheckbox/index.js +7 -0
  33. package/dist/components/cardradio/cardradio.component.d.ts +76 -0
  34. package/dist/components/cardradio/cardradio.component.js +155 -0
  35. package/dist/components/cardradio/cardradio.constants.d.ts +2 -0
  36. package/dist/components/cardradio/cardradio.constants.js +3 -0
  37. package/dist/components/cardradio/cardradio.styles.d.ts +2 -0
  38. package/dist/components/cardradio/cardradio.styles.js +53 -0
  39. package/dist/components/cardradio/cardradio.types.d.ts +8 -0
  40. package/dist/components/cardradio/cardradio.types.js +1 -0
  41. package/dist/components/cardradio/index.d.ts +10 -0
  42. package/dist/components/cardradio/index.js +7 -0
  43. package/dist/components/listitem/index.d.ts +1 -1
  44. package/dist/components/listitem/index.js +1 -1
  45. package/dist/components/listitem/listitem.component.d.ts +4 -4
  46. package/dist/components/listitem/listitem.component.js +2 -2
  47. package/dist/components/menuitem/index.d.ts +8 -0
  48. package/dist/components/menuitem/index.js +5 -0
  49. package/dist/components/menuitem/menuitem.component.d.ts +25 -0
  50. package/dist/components/menuitem/menuitem.component.js +29 -0
  51. package/dist/components/menuitem/menuitem.constants.d.ts +2 -0
  52. package/dist/components/menuitem/menuitem.constants.js +3 -0
  53. package/dist/components/menuitem/menuitem.types.d.ts +6 -0
  54. package/dist/components/menuitem/menuitem.types.js +1 -0
  55. package/dist/components/option/option.component.js +0 -4
  56. package/dist/components/radiogroup/radiogroup.component.js +2 -1
  57. package/dist/custom-elements.json +6221 -3340
  58. package/dist/index.d.ts +12 -7
  59. package/dist/index.js +12 -7
  60. package/dist/react/card/index.d.ts +47 -0
  61. package/dist/react/card/index.js +56 -0
  62. package/dist/react/cardbutton/index.d.ts +32 -0
  63. package/dist/react/cardbutton/index.js +40 -0
  64. package/dist/react/cardcheckbox/index.d.ts +40 -0
  65. package/dist/react/cardcheckbox/index.js +48 -0
  66. package/dist/react/cardradio/index.d.ts +40 -0
  67. package/dist/react/cardradio/index.js +48 -0
  68. package/dist/react/index.d.ts +7 -2
  69. package/dist/react/index.js +7 -2
  70. package/dist/react/menuitem/index.d.ts +27 -0
  71. package/dist/react/menuitem/index.js +35 -0
  72. package/dist/utils/mixins/CardComponentMixin.d.ts +20 -0
  73. package/dist/utils/mixins/CardComponentMixin.js +130 -0
  74. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ import { CSSResult, nothing, PropertyValues } from 'lit';
2
+ import Card from '../card/card.component';
3
+ import type { SelectionType } from './cardcheckbox.types';
4
+ declare const CardCheckbox_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/TabIndexMixin").TabIndexMixinInterface> & typeof Card;
5
+ /**
6
+ * cardcheckbox component extends `mdc-card` and supports checkbox selection interaction addtionally.
7
+ *
8
+ * While using this component within a form or group of cards, make sure cards are in a role = "checkbox-group".
9
+ * This card would have events for selected and unselected (similar to checkbox)
10
+ *
11
+ * **Note**: This is a single selection card i.e. interacting anywhere on the card would toggle the checked state.
12
+ * Make sure to pass only non-interactable elements within the slots.
13
+ *
14
+ * Make sure to pass the `card-title` mandatorily for this card.
15
+ *
16
+ * @tagname mdc-cardcheckbox
17
+ *
18
+ * @dependency mdc-icon
19
+ * @dependency mdc-staticcheckbox
20
+ * @dependency mdc-text
21
+ *
22
+ * @slot before-body - This slot is for passing the content before the body
23
+ * @slot body - This slot is for passing the text content for the card
24
+ * @slot after-body - This slot is for passing the content after the body
25
+ *
26
+ * @event click - (React: onClick) Event that gets dispatched when the card is clicked. It toggles the checked state.
27
+ * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the card.
28
+ * It toggles the checked state when enter key is used.
29
+ * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the card.
30
+ * It toggles the checked state when space key is used.
31
+ * @event change - (React: onChange) Event that gets dispatched when the card state changes.
32
+ * @event focus - (React: onFocus) Event that gets dispatched when the card receives focus.
33
+ *
34
+ */
35
+ declare class CardCheckbox extends CardCheckbox_base {
36
+ /**
37
+ * The checked state of the card
38
+ * @default false
39
+ */
40
+ checked: boolean;
41
+ /**
42
+ * The selection type of the card. It can either be set to 'check' or 'checkbox'
43
+ * @default 'check'
44
+ */
45
+ selectionType: SelectionType;
46
+ constructor();
47
+ connectedCallback(): void;
48
+ update(changedProperties: PropertyValues<CardCheckbox>): void;
49
+ /**
50
+ * Toggles the checked state
51
+ */
52
+ private toggleChecked;
53
+ /**
54
+ * Toggles the checked state when enter key is used
55
+ * @param event - The keyboard event
56
+ */
57
+ private toggleOnEnter;
58
+ /**
59
+ * Toggles the checked state when space key is used
60
+ * @param event - The keyboard event
61
+ */
62
+ private toggleOnSpace;
63
+ /**
64
+ * Renders the selection icon or checkbox based on the selection type
65
+ * @returns The selection icon or checkbox
66
+ */
67
+ private renderSelection;
68
+ /**
69
+ * Renders the header of the card
70
+ * @returns The header of the card
71
+ */
72
+ renderHeader(): import("lit-html").TemplateResult<1> | typeof nothing;
73
+ render(): import("lit-html").TemplateResult<1>;
74
+ static styles: Array<CSSResult>;
75
+ }
76
+ export default CardCheckbox;
@@ -0,0 +1,159 @@
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, nothing } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ import styles from './cardcheckbox.styles';
13
+ import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
14
+ import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
15
+ import Card from '../card/card.component';
16
+ import { CHECK_MARK, DEFAULTS, SELECTION_TYPE } from './cardcheckbox.constants';
17
+ /**
18
+ * cardcheckbox component extends `mdc-card` and supports checkbox selection interaction addtionally.
19
+ *
20
+ * While using this component within a form or group of cards, make sure cards are in a role = "checkbox-group".
21
+ * This card would have events for selected and unselected (similar to checkbox)
22
+ *
23
+ * **Note**: This is a single selection card i.e. interacting anywhere on the card would toggle the checked state.
24
+ * Make sure to pass only non-interactable elements within the slots.
25
+ *
26
+ * Make sure to pass the `card-title` mandatorily for this card.
27
+ *
28
+ * @tagname mdc-cardcheckbox
29
+ *
30
+ * @dependency mdc-icon
31
+ * @dependency mdc-staticcheckbox
32
+ * @dependency mdc-text
33
+ *
34
+ * @slot before-body - This slot is for passing the content before the body
35
+ * @slot body - This slot is for passing the text content for the card
36
+ * @slot after-body - This slot is for passing the content after the body
37
+ *
38
+ * @event click - (React: onClick) Event that gets dispatched when the card is clicked. It toggles the checked state.
39
+ * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the card.
40
+ * It toggles the checked state when enter key is used.
41
+ * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the card.
42
+ * It toggles the checked state when space key is used.
43
+ * @event change - (React: onChange) Event that gets dispatched when the card state changes.
44
+ * @event focus - (React: onFocus) Event that gets dispatched when the card receives focus.
45
+ *
46
+ */
47
+ class CardCheckbox extends DisabledMixin(TabIndexMixin(Card)) {
48
+ constructor() {
49
+ super();
50
+ /**
51
+ * The checked state of the card
52
+ * @default false
53
+ */
54
+ this.checked = false;
55
+ /**
56
+ * The selection type of the card. It can either be set to 'check' or 'checkbox'
57
+ * @default 'check'
58
+ */
59
+ this.selectionType = DEFAULTS.SELECTION_TYPE;
60
+ this.addEventListener('click', this.toggleChecked);
61
+ this.addEventListener('keydown', this.toggleOnEnter);
62
+ this.addEventListener('keyup', this.toggleOnSpace);
63
+ }
64
+ connectedCallback() {
65
+ super.connectedCallback();
66
+ this.role = 'checkbox';
67
+ }
68
+ update(changedProperties) {
69
+ super.update(changedProperties);
70
+ if (changedProperties.has('checked')) {
71
+ this.setAttribute('aria-checked', `${this.checked}`);
72
+ }
73
+ if (changedProperties.has('disabled')) {
74
+ this.setAttribute('aria-disabled', `${this.disabled}`);
75
+ }
76
+ }
77
+ /**
78
+ * Toggles the checked state
79
+ */
80
+ toggleChecked() {
81
+ if (!this.disabled) {
82
+ this.checked = !this.checked;
83
+ }
84
+ }
85
+ /**
86
+ * Toggles the checked state when enter key is used
87
+ * @param event - The keyboard event
88
+ */
89
+ toggleOnEnter(event) {
90
+ if (event.key === 'Enter') {
91
+ this.toggleChecked();
92
+ }
93
+ }
94
+ /**
95
+ * Toggles the checked state when space key is used
96
+ * @param event - The keyboard event
97
+ */
98
+ toggleOnSpace(event) {
99
+ if (event.key === ' ') {
100
+ this.toggleChecked();
101
+ }
102
+ }
103
+ /**
104
+ * Renders the selection icon or checkbox based on the selection type
105
+ * @returns The selection icon or checkbox
106
+ */
107
+ renderSelection() {
108
+ const ICON_NAME = this.checked ? CHECK_MARK.CHECKED : CHECK_MARK.DEFAULT;
109
+ switch (this.selectionType) {
110
+ case SELECTION_TYPE.CHECK: {
111
+ return html `<mdc-icon part="check check-icon"
112
+ size="${DEFAULTS.ICON_SIZE}"
113
+ length-unit="${DEFAULTS.ICON_LENGTH_UNIT}"
114
+ name="${ICON_NAME}"></mdc-icon>`;
115
+ }
116
+ case SELECTION_TYPE.CHECKBOX: {
117
+ return html `<mdc-staticcheckbox part="check"
118
+ ?checked="${this.checked}"
119
+ ?disabled="${this.disabled}"></mdc-staticcheckbox>`;
120
+ }
121
+ default: return nothing;
122
+ }
123
+ }
124
+ /**
125
+ * Renders the header of the card
126
+ * @returns The header of the card
127
+ */
128
+ renderHeader() {
129
+ if (!this.cardTitle) {
130
+ return nothing;
131
+ }
132
+ return html `<div part="header">
133
+ ${this.renderIcon()}
134
+ ${this.renderTitle()}
135
+ ${this.renderSelection()}
136
+ </div>`;
137
+ }
138
+ render() {
139
+ return html `
140
+ ${this.renderImage()}
141
+ <div part="body">
142
+ ${this.renderHeader()}
143
+ <slot name="before-body"></slot>
144
+ <slot name="body"></slot>
145
+ <slot name="after-body"></slot>
146
+ </div>
147
+ `;
148
+ }
149
+ }
150
+ CardCheckbox.styles = [...Card.styles, ...styles];
151
+ __decorate([
152
+ property({ type: Boolean, reflect: true }),
153
+ __metadata("design:type", Boolean)
154
+ ], CardCheckbox.prototype, "checked", void 0);
155
+ __decorate([
156
+ property({ type: String, attribute: 'selection-type' }),
157
+ __metadata("design:type", String)
158
+ ], CardCheckbox.prototype, "selectionType", void 0);
159
+ export default CardCheckbox;
@@ -0,0 +1,15 @@
1
+ declare const TAG_NAME: "mdc-cardcheckbox";
2
+ declare const CHECK_MARK: {
3
+ readonly DEFAULT: "check-circle-bold";
4
+ readonly CHECKED: "check-circle-filled";
5
+ };
6
+ declare const SELECTION_TYPE: {
7
+ readonly CHECK: "check";
8
+ readonly CHECKBOX: "checkbox";
9
+ };
10
+ declare const DEFAULTS: {
11
+ SELECTION_TYPE: "check";
12
+ ICON_SIZE: number;
13
+ ICON_LENGTH_UNIT: string;
14
+ };
15
+ export { TAG_NAME, DEFAULTS, SELECTION_TYPE, CHECK_MARK };
@@ -0,0 +1,16 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('cardcheckbox');
3
+ const CHECK_MARK = {
4
+ DEFAULT: 'check-circle-bold',
5
+ CHECKED: 'check-circle-filled',
6
+ };
7
+ const SELECTION_TYPE = {
8
+ CHECK: 'check',
9
+ CHECKBOX: 'checkbox',
10
+ };
11
+ const DEFAULTS = {
12
+ SELECTION_TYPE: SELECTION_TYPE.CHECK,
13
+ ICON_SIZE: 1.5,
14
+ ICON_LENGTH_UNIT: 'rem',
15
+ };
16
+ export { TAG_NAME, DEFAULTS, SELECTION_TYPE, CHECK_MARK };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,57 @@
1
+ import { css } from 'lit';
2
+ import { hostFocusRingStyles } from '../../utils/styles';
3
+ const styles = css `
4
+ :host {
5
+ cursor: pointer;
6
+ user-select: none;
7
+ }
8
+
9
+ :host::part(check){
10
+ margin-left: auto;
11
+ }
12
+
13
+ :host(:hover) {
14
+ background-color: var(--mds-color-theme-background-primary-hover);
15
+ }
16
+
17
+ :host(:active) {
18
+ background-color: var(--mds-color-theme-background-primary-active);
19
+ }
20
+
21
+ :host([checked]){
22
+ border: 1px solid var(--mds-color-theme-outline-input-active);
23
+ box-shadow: 0 0 0 1px var(--mds-color-theme-outline-input-active);
24
+ background-color: var(--mds-color-theme-background-primary-active);
25
+ }
26
+
27
+ :host([checked]:hover){
28
+ background-color: var(--mds-color-theme-background-primary-hover);
29
+ }
30
+
31
+ :host([checked]:active){
32
+ background-color: var(--mds-color-theme-background-primary-ghost);
33
+ }
34
+
35
+ :host::part(check-icon){
36
+ color: var(--mds-color-theme-text-secondary-normal);
37
+ }
38
+
39
+ :host([checked])::part(check-icon){
40
+ color: var(--mds-color-theme-text-accent-normal);
41
+ }
42
+
43
+ :host([disabled]) {
44
+ background-color: var(--mds-color-theme-background-primary-ghost);
45
+ color: var(--mds-color-theme-text-primary-disabled);
46
+ border-color: var(--mds-color-theme-outline-primary-disabled);
47
+ }
48
+
49
+ :host([disabled])::part(image){
50
+ opacity: 0.5;
51
+ }
52
+
53
+ :host([disabled])::part(check-icon){
54
+ color: var(--mds-color-theme-text-primary-disabled);
55
+ }
56
+ `;
57
+ export default [styles, ...hostFocusRingStyles()];
@@ -0,0 +1,11 @@
1
+ import type { ValueOf } from '../../utils/types';
2
+ import { SELECTION_TYPE } from './cardcheckbox.constants';
3
+ type SelectionType = ValueOf<typeof SELECTION_TYPE>;
4
+ interface Events {
5
+ onClickEvent: MouseEvent;
6
+ onKeyDownEvent: KeyboardEvent;
7
+ onKeyUpEvent: KeyboardEvent;
8
+ onFocusEvent: FocusEvent;
9
+ onChangeEvent: Event;
10
+ }
11
+ export { SelectionType, Events };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import CardCheckbox from './cardcheckbox.component';
2
+ import '../icon';
3
+ import '../text';
4
+ import '../staticcheckbox';
5
+ declare global {
6
+ interface HTMLElementTagNameMap {
7
+ ['mdc-cardcheckbox']: CardCheckbox;
8
+ }
9
+ }
10
+ export default CardCheckbox;
@@ -0,0 +1,7 @@
1
+ import CardCheckbox from './cardcheckbox.component';
2
+ import { TAG_NAME } from './cardcheckbox.constants';
3
+ import '../icon';
4
+ import '../text';
5
+ import '../staticcheckbox';
6
+ CardCheckbox.register(TAG_NAME);
7
+ export default CardCheckbox;
@@ -0,0 +1,76 @@
1
+ import { CSSResult, nothing, PropertyValues } from 'lit';
2
+ import Card from '../card/card.component';
3
+ declare const CardRadio_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/TabIndexMixin").TabIndexMixinInterface> & typeof Card;
4
+ /**
5
+ * cardradio component extends `mdc-card` and supports radio selection interaction addtionally.
6
+ *
7
+ * While using this component within a form or group of cards, make sure cards are in a role = "radio-group".
8
+ * This card would have events for selected and unselected (similar to radio)
9
+ *
10
+ * **Note**: This is a single selection card i.e. interacting anywhere on the card would toggle the checked state.
11
+ * Make sure to pass only non-interactable elements within the slots.
12
+ *
13
+ * Make sure to pass the `card-title` mandatorily for this card.
14
+ *
15
+ * @tagname mdc-cardradio
16
+ *
17
+ * @dependency mdc-icon
18
+ * @dependency mdc-staticradio
19
+ * @dependency mdc-text
20
+ *
21
+ * @slot before-body - This slot is for passing the content before the body
22
+ * @slot body - This slot is for passing the text content for the card
23
+ * @slot after-body - This slot is for passing the content after the body
24
+ *
25
+ * @event click - (React: onClick) Event that gets dispatched when the card is clicked. It toggles the checked state.
26
+ * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the card.
27
+ * It toggles the checked state when enter key is used.
28
+ * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the card.
29
+ * It toggles the checked state when space key is used.
30
+ * @event change - (React: onChange) Event that gets dispatched when the card state changes.
31
+ * @event focus - (React: onFocus) Event that gets dispatched when the card receives focus.
32
+ *
33
+ */
34
+ declare class CardRadio extends CardRadio_base {
35
+ /**
36
+ * The checked state of the card
37
+ * @default false
38
+ */
39
+ checked: boolean;
40
+ /**
41
+ * The name of the radio.
42
+ * @default ''
43
+ */
44
+ name: string;
45
+ constructor();
46
+ connectedCallback(): void;
47
+ /**
48
+ * Returns all cards within the same group (name).
49
+ */
50
+ private getAllCardsWithinSameGroup;
51
+ /**
52
+ * Handles the change event on the radio element.
53
+ * This will toggle the state of the radio element.
54
+ * Dispatches the change event.
55
+ */
56
+ private toggleChecked;
57
+ update(changedProperties: PropertyValues<CardRadio>): void;
58
+ /**
59
+ * Toggles the checked state when enter key is used
60
+ * @param event - The keyboard event
61
+ */
62
+ private toggleOnEnter;
63
+ /**
64
+ * Toggles the checked state when space key is used
65
+ * @param event - The keyboard event
66
+ */
67
+ private toggleOnSpace;
68
+ /**
69
+ * Renders the header of the card
70
+ * @returns The header of the card
71
+ */
72
+ renderHeader(): import("lit-html").TemplateResult<1> | typeof nothing;
73
+ render(): import("lit-html").TemplateResult<1>;
74
+ static styles: Array<CSSResult>;
75
+ }
76
+ export default CardRadio;
@@ -0,0 +1,155 @@
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
+ /* eslint-disable no-param-reassign */
11
+ import { html, nothing } from 'lit';
12
+ import { property } from 'lit/decorators.js';
13
+ import styles from './cardradio.styles';
14
+ import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
15
+ import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
16
+ import Card from '../card/card.component';
17
+ /**
18
+ * cardradio component extends `mdc-card` and supports radio selection interaction addtionally.
19
+ *
20
+ * While using this component within a form or group of cards, make sure cards are in a role = "radio-group".
21
+ * This card would have events for selected and unselected (similar to radio)
22
+ *
23
+ * **Note**: This is a single selection card i.e. interacting anywhere on the card would toggle the checked state.
24
+ * Make sure to pass only non-interactable elements within the slots.
25
+ *
26
+ * Make sure to pass the `card-title` mandatorily for this card.
27
+ *
28
+ * @tagname mdc-cardradio
29
+ *
30
+ * @dependency mdc-icon
31
+ * @dependency mdc-staticradio
32
+ * @dependency mdc-text
33
+ *
34
+ * @slot before-body - This slot is for passing the content before the body
35
+ * @slot body - This slot is for passing the text content for the card
36
+ * @slot after-body - This slot is for passing the content after the body
37
+ *
38
+ * @event click - (React: onClick) Event that gets dispatched when the card is clicked. It toggles the checked state.
39
+ * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the card.
40
+ * It toggles the checked state when enter key is used.
41
+ * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the card.
42
+ * It toggles the checked state when space key is used.
43
+ * @event change - (React: onChange) Event that gets dispatched when the card state changes.
44
+ * @event focus - (React: onFocus) Event that gets dispatched when the card receives focus.
45
+ *
46
+ */
47
+ class CardRadio extends DisabledMixin(TabIndexMixin(Card)) {
48
+ constructor() {
49
+ super();
50
+ /**
51
+ * The checked state of the card
52
+ * @default false
53
+ */
54
+ this.checked = false;
55
+ /**
56
+ * The name of the radio.
57
+ * @default ''
58
+ */
59
+ this.name = '';
60
+ this.addEventListener('click', this.toggleChecked);
61
+ this.addEventListener('keydown', this.toggleOnEnter);
62
+ this.addEventListener('keyup', this.toggleOnSpace);
63
+ }
64
+ connectedCallback() {
65
+ super.connectedCallback();
66
+ this.role = 'radio';
67
+ }
68
+ /**
69
+ * Returns all cards within the same group (name).
70
+ */
71
+ getAllCardsWithinSameGroup() {
72
+ return Array.from(document.querySelectorAll(`mdc-cardradio[name="${this.name}"]`));
73
+ }
74
+ /**
75
+ * Handles the change event on the radio element.
76
+ * This will toggle the state of the radio element.
77
+ * Dispatches the change event.
78
+ */
79
+ toggleChecked() {
80
+ if (this.disabled)
81
+ return;
82
+ const cards = this.getAllCardsWithinSameGroup();
83
+ cards.forEach((card) => {
84
+ /**
85
+ * Uncheck all cards in the same group (name)
86
+ */
87
+ card.checked = false;
88
+ });
89
+ this.checked = true;
90
+ }
91
+ update(changedProperties) {
92
+ super.update(changedProperties);
93
+ if (changedProperties.has('checked')) {
94
+ this.setAttribute('aria-checked', `${this.checked}`);
95
+ }
96
+ if (changedProperties.has('disabled')) {
97
+ this.setAttribute('aria-disabled', `${this.disabled}`);
98
+ }
99
+ }
100
+ /**
101
+ * Toggles the checked state when enter key is used
102
+ * @param event - The keyboard event
103
+ */
104
+ toggleOnEnter(event) {
105
+ if (event.key === 'Enter') {
106
+ this.toggleChecked();
107
+ }
108
+ }
109
+ /**
110
+ * Toggles the checked state when space key is used
111
+ * @param event - The keyboard event
112
+ */
113
+ toggleOnSpace(event) {
114
+ if (event.key === ' ') {
115
+ this.toggleChecked();
116
+ }
117
+ }
118
+ /**
119
+ * Renders the header of the card
120
+ * @returns The header of the card
121
+ */
122
+ renderHeader() {
123
+ if (!this.cardTitle) {
124
+ return nothing;
125
+ }
126
+ return html `<div part="header">
127
+ ${this.renderIcon()}
128
+ ${this.renderTitle()}
129
+ <mdc-staticradio part="check"
130
+ ?checked="${this.checked}"
131
+ ?disabled="${this.disabled}"></mdc-staticradio>
132
+ </div>`;
133
+ }
134
+ render() {
135
+ return html `
136
+ ${this.renderImage()}
137
+ <div part="body">
138
+ ${this.renderHeader()}
139
+ <slot name="before-body"></slot>
140
+ <slot name="body"></slot>
141
+ <slot name="after-body"></slot>
142
+ </div>
143
+ `;
144
+ }
145
+ }
146
+ CardRadio.styles = [...Card.styles, ...styles];
147
+ __decorate([
148
+ property({ type: Boolean, reflect: true }),
149
+ __metadata("design:type", Object)
150
+ ], CardRadio.prototype, "checked", void 0);
151
+ __decorate([
152
+ property({ type: String }),
153
+ __metadata("design:type", Object)
154
+ ], CardRadio.prototype, "name", void 0);
155
+ export default CardRadio;
@@ -0,0 +1,2 @@
1
+ declare const TAG_NAME: "mdc-cardradio";
2
+ export { TAG_NAME };
@@ -0,0 +1,3 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('cardradio');
3
+ export { TAG_NAME };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { css } from 'lit';
2
+ import { hostFocusRingStyles } from '../../utils/styles';
3
+ const styles = css `
4
+ :host {
5
+ cursor: pointer;
6
+ user-select: none;
7
+ }
8
+
9
+ :host::part(check){
10
+ margin-left: auto;
11
+ }
12
+
13
+ :host(:hover) {
14
+ background-color: var(--mds-color-theme-background-primary-hover);
15
+ }
16
+
17
+ :host(:active) {
18
+ background-color: var(--mds-color-theme-background-primary-active);
19
+ }
20
+
21
+ :host([checked]){
22
+ border: 1px solid var(--mds-color-theme-outline-input-active);
23
+ box-shadow: 0 0 0 1px var(--mds-color-theme-outline-input-active);
24
+ background-color: var(--mds-color-theme-background-primary-active);
25
+ }
26
+
27
+ :host([checked]:hover){
28
+ background-color: var(--mds-color-theme-background-primary-hover);
29
+ }
30
+
31
+ :host([checked]:active){
32
+ background-color: var(--mds-color-theme-background-primary-ghost);
33
+ }
34
+
35
+ :host::part(check-icon){
36
+ color: var(--mds-color-theme-text-secondary-normal);
37
+ }
38
+
39
+ :host([checked])::part(check-icon){
40
+ color: var(--mds-color-theme-text-accent-normal);
41
+ }
42
+
43
+ :host([disabled]) {
44
+ background-color: var(--mds-color-theme-background-primary-ghost);
45
+ color: var(--mds-color-theme-text-primary-disabled);
46
+ border-color: var(--mds-color-theme-outline-primary-disabled);
47
+ }
48
+
49
+ :host([disabled])::part(image){
50
+ opacity: 0.5;
51
+ }
52
+ `;
53
+ export default [styles, ...hostFocusRingStyles()];
@@ -0,0 +1,8 @@
1
+ interface Events {
2
+ onClickEvent: MouseEvent;
3
+ onKeyDownEvent: KeyboardEvent;
4
+ onKeyUpEvent: KeyboardEvent;
5
+ onFocusEvent: FocusEvent;
6
+ onChangeEvent: Event;
7
+ }
8
+ export type { Events };
@@ -0,0 +1 @@
1
+ export {};