@momentum-design/components 0.58.0 → 0.58.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.
@@ -1,8 +1,8 @@
1
1
  import type { PropertyValues } from 'lit';
2
2
  import { CSSResult } from 'lit';
3
3
  import Buttonsimple from '../buttonsimple/buttonsimple.component';
4
- import type { IconNames } from '../icon/icon.types';
5
- import type { ButtonColor, ButtonVariant, IconButtonSize, PillButtonSize } from './button.types';
4
+ import type { IconButtonSize, PillButtonSize } from './button.types';
5
+ declare const Button_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/ButtonComponentMixin").ButtonComponentMixinInterface> & typeof Buttonsimple;
6
6
  /**
7
7
  * `mdc-button` is a component that can be configured in various ways to suit different use cases.
8
8
  *
@@ -35,25 +35,7 @@ import type { ButtonColor, ButtonVariant, IconButtonSize, PillButtonSize } from
35
35
  *
36
36
  * @slot - Text label of the button.
37
37
  */
38
- declare class Button extends Buttonsimple {
39
- /**
40
- * The name of the icon to display as a prefix.
41
- * The icon is displayed on the left side of the button.
42
- */
43
- prefixIcon?: IconNames;
44
- /**
45
- * The name of the icon to display as a postfix.
46
- * The icon is displayed on the right side of the button.
47
- */
48
- postfixIcon?: IconNames;
49
- /**
50
- * There are 3 variants of button: primary, secondary, tertiary. They are styled differently.
51
- * - **Primary**: Solid background color.
52
- * - **Secondary**: Transparent background with a solid border.
53
- * - **Tertiary**: No background or border, appears as plain text but retains all button functionalities.
54
- * @default primary
55
- */
56
- variant: ButtonVariant;
38
+ declare class Button extends Button_base {
57
39
  /**
58
40
  * Button sizing is based on the button type.
59
41
  * - **Pill button**: 40, 32, 28, 24.
@@ -62,11 +44,6 @@ declare class Button extends Buttonsimple {
62
44
  * @default 32
63
45
  */
64
46
  size: PillButtonSize | IconButtonSize;
65
- /**
66
- * There are 5 colors for button: positive, negative, accent, promotional, default.
67
- * @default default
68
- */
69
- color: ButtonColor;
70
47
  /**
71
48
  * This property defines the ARIA role for the element. By default, it is set to 'button'.
72
49
  * Consumers should override this role when:
@@ -75,8 +52,6 @@ declare class Button extends Buttonsimple {
75
52
  * @default button
76
53
  */
77
54
  role: string;
78
- /** @internal */
79
- private typeInternal;
80
55
  /**
81
56
  * @internal
82
57
  */
@@ -95,34 +70,6 @@ declare class Button extends Buttonsimple {
95
70
  * @param active - The active state.
96
71
  */
97
72
  private inferFilledIconName;
98
- /**
99
- * Sets the variant attribute for the button component.
100
- * If the provided variant is not included in the BUTTON_VARIANTS,
101
- * it defaults to the value specified in DEFAULTS.VARIANT.
102
- *
103
- * @param variant - The variant to set.
104
- */
105
- private setVariant;
106
- /**
107
- * Sets the size attribute for the button component.
108
- * Validates the size based on the button type (icon, pill, or tertiary).
109
- * Defaults to DEFAULTS.SIZE if invalid.
110
- *
111
- * @param size - The size to set.
112
- */
113
- private setSize;
114
- /**
115
- * Sets the color attribute for the button.
116
- * Defaults to DEFAULTS.COLOR if invalid or for tertiary buttons.
117
- *
118
- * @param color - The color to set.
119
- */
120
- private setColor;
121
- /**
122
- * Infers the type of button based on the presence of slot and/or prefix and postfix icons.
123
- * @param slot - default slot of button
124
- */
125
- private inferButtonType;
126
73
  render(): import("lit-html").TemplateResult<1>;
127
74
  static styles: Array<CSSResult>;
128
75
  }
@@ -9,8 +9,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { html } from 'lit';
11
11
  import { property, state } from 'lit/decorators.js';
12
+ import { ButtonComponentMixin } from '../../utils/mixins/ButtonComponentMixin';
12
13
  import Buttonsimple from '../buttonsimple/buttonsimple.component';
13
- import { BUTTON_COLORS, BUTTON_TYPE_INTERNAL, BUTTON_VARIANTS, DEFAULTS, ICON_BUTTON_SIZES, PILL_BUTTON_SIZES, } from './button.constants';
14
+ import { DEFAULTS } from './button.constants';
14
15
  import styles from './button.styles';
15
16
  import { getIconNameWithoutStyle } from './button.utils';
16
17
  /**
@@ -45,17 +46,9 @@ import { getIconNameWithoutStyle } from './button.utils';
45
46
  *
46
47
  * @slot - Text label of the button.
47
48
  */
48
- class Button extends Buttonsimple {
49
+ class Button extends ButtonComponentMixin(Buttonsimple) {
49
50
  constructor() {
50
51
  super(...arguments);
51
- /**
52
- * There are 3 variants of button: primary, secondary, tertiary. They are styled differently.
53
- * - **Primary**: Solid background color.
54
- * - **Secondary**: Transparent background with a solid border.
55
- * - **Tertiary**: No background or border, appears as plain text but retains all button functionalities.
56
- * @default primary
57
- */
58
- this.variant = DEFAULTS.VARIANT;
59
52
  /**
60
53
  * Button sizing is based on the button type.
61
54
  * - **Pill button**: 40, 32, 28, 24.
@@ -64,11 +57,6 @@ class Button extends Buttonsimple {
64
57
  * @default 32
65
58
  */
66
59
  this.size = DEFAULTS.SIZE;
67
- /**
68
- * There are 5 colors for button: positive, negative, accent, promotional, default.
69
- * @default default
70
- */
71
- this.color = DEFAULTS.COLOR;
72
60
  /**
73
61
  * This property defines the ARIA role for the element. By default, it is set to 'button'.
74
62
  * Consumers should override this role when:
@@ -77,8 +65,6 @@ class Button extends Buttonsimple {
77
65
  * @default button
78
66
  */
79
67
  this.role = 'button';
80
- /** @internal */
81
- this.typeInternal = DEFAULTS.TYPE_INTERNAL;
82
68
  }
83
69
  update(changedProperties) {
84
70
  super.update(changedProperties);
@@ -125,65 +111,6 @@ class Button extends Buttonsimple {
125
111
  this.postfixFilledIconName = this.postfixIcon;
126
112
  }
127
113
  }
128
- /**
129
- * Sets the variant attribute for the button component.
130
- * If the provided variant is not included in the BUTTON_VARIANTS,
131
- * it defaults to the value specified in DEFAULTS.VARIANT.
132
- *
133
- * @param variant - The variant to set.
134
- */
135
- setVariant(variant) {
136
- this.setAttribute('variant', Object.values(BUTTON_VARIANTS).includes(variant) ? variant : DEFAULTS.VARIANT);
137
- }
138
- /**
139
- * Sets the size attribute for the button component.
140
- * Validates the size based on the button type (icon, pill, or tertiary).
141
- * Defaults to DEFAULTS.SIZE if invalid.
142
- *
143
- * @param size - The size to set.
144
- */
145
- setSize(size) {
146
- const isIconType = this.typeInternal === BUTTON_TYPE_INTERNAL.ICON;
147
- const isValidSize = isIconType
148
- ? Object.values(ICON_BUTTON_SIZES).includes(size)
149
- && !(size === ICON_BUTTON_SIZES[20] && this.variant !== BUTTON_VARIANTS.TERTIARY)
150
- : Object.values(PILL_BUTTON_SIZES).includes(size);
151
- this.setAttribute('size', isValidSize ? `${size}` : `${DEFAULTS.SIZE}`);
152
- }
153
- /**
154
- * Sets the color attribute for the button.
155
- * Defaults to DEFAULTS.COLOR if invalid or for tertiary buttons.
156
- *
157
- * @param color - The color to set.
158
- */
159
- setColor(color) {
160
- if (!Object.values(BUTTON_COLORS).includes(color) || this.variant === BUTTON_VARIANTS.TERTIARY) {
161
- this.setAttribute('color', `${DEFAULTS.COLOR}`);
162
- }
163
- else {
164
- this.setAttribute('color', color);
165
- }
166
- }
167
- /**
168
- * Infers the type of button based on the presence of slot and/or prefix and postfix icons.
169
- * @param slot - default slot of button
170
- */
171
- inferButtonType() {
172
- var _a, _b;
173
- const slot = (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot')) === null || _b === void 0 ? void 0 : _b.assignedNodes().filter((node) => { var _a; return node.nodeType !== Node.TEXT_NODE || ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()); }).length;
174
- if (slot && (this.prefixIcon || this.postfixIcon)) {
175
- this.typeInternal = BUTTON_TYPE_INTERNAL.PILL_WITH_ICON;
176
- this.setAttribute('data-btn-type', 'pill-with-icon');
177
- }
178
- else if (!slot && (this.prefixIcon || this.postfixIcon)) {
179
- this.typeInternal = BUTTON_TYPE_INTERNAL.ICON;
180
- this.setAttribute('data-btn-type', 'icon');
181
- }
182
- else {
183
- this.typeInternal = BUTTON_TYPE_INTERNAL.PILL;
184
- this.setAttribute('data-btn-type', 'pill');
185
- }
186
- }
187
114
  render() {
188
115
  return html `
189
116
  ${this.prefixFilledIconName
@@ -197,34 +124,14 @@ class Button extends Buttonsimple {
197
124
  }
198
125
  }
199
126
  Button.styles = [...Buttonsimple.styles, ...styles];
200
- __decorate([
201
- property({ type: String, attribute: 'prefix-icon', reflect: true }),
202
- __metadata("design:type", String)
203
- ], Button.prototype, "prefixIcon", void 0);
204
- __decorate([
205
- property({ type: String, attribute: 'postfix-icon', reflect: true }),
206
- __metadata("design:type", String)
207
- ], Button.prototype, "postfixIcon", void 0);
208
- __decorate([
209
- property({ type: String }),
210
- __metadata("design:type", String)
211
- ], Button.prototype, "variant", void 0);
212
127
  __decorate([
213
128
  property({ type: Number }),
214
129
  __metadata("design:type", Number)
215
130
  ], Button.prototype, "size", void 0);
216
- __decorate([
217
- property({ type: String }),
218
- __metadata("design:type", String)
219
- ], Button.prototype, "color", void 0);
220
131
  __decorate([
221
132
  property({ type: String, reflect: true }),
222
133
  __metadata("design:type", Object)
223
134
  ], Button.prototype, "role", void 0);
224
- __decorate([
225
- state(),
226
- __metadata("design:type", String)
227
- ], Button.prototype, "typeInternal", void 0);
228
135
  __decorate([
229
136
  state(),
230
137
  __metadata("design:type", String)
@@ -0,0 +1,59 @@
1
+ import { CSSResult, PropertyValues } from 'lit';
2
+ import Linksimple from '../linksimple/linksimple.component';
3
+ import type { IconButtonSize, PillButtonSize } from '../button/button.types';
4
+ declare const ButtonLink_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/ButtonComponentMixin").ButtonComponentMixinInterface> & typeof Linksimple;
5
+ /**
6
+ * `mdc-buttonlink` combines the functional behavior of `mdc-linksimple` with the visual and structural
7
+ * features of `mdc-button`. This includes support for variants, sizing, and optional
8
+ * prefix and postfix icons via slots.
9
+ *
10
+ * ### Features:
11
+ * - Behaves like an link while visually resembling a button.
12
+ * - Supports slots for `prefix-icon` and `postfix-icon`.
13
+ * - Customizable size, color, and variant through attributes.
14
+ * - Inherits accessibility and keyboard interaction support from `mdc-linksimple`.
15
+ *
16
+ * @dependency mdc-icon
17
+ *
18
+ * @tagname mdc-buttonlink
19
+ *
20
+ * @event click - (React: onClick) Fired when the user activates the buttonLink using a mouse or assistive technology.
21
+ * @event keydown - (React: onKeyDown) Fired when the user presses a key while the buttonLink has focus.
22
+ * @event focus - (React: onFocus) Fired when the buttonLink receives keyboard or mouse focus.
23
+ * @event blur - (React: onBlur) Fired when the buttonLink loses keyboard or mouse focus.
24
+ *
25
+ */
26
+ declare class ButtonLink extends ButtonLink_base {
27
+ /**
28
+ * ButtonLink sizing is based on the buttonlink type.
29
+ * - **Pill buttonlink**: 40, 32, 28, 24.
30
+ * - **Icon buttonlink**: 64, 52, 40, 32, 28, 24.
31
+ * - Tertiary icon buttonlink can also be 20.
32
+ * @default 32
33
+ */
34
+ size: PillButtonSize | IconButtonSize;
35
+ /**
36
+ * Indicates whether the buttonlink is soft disabled.
37
+ * When set to `true`, the buttonlink appears visually disabled but still allows
38
+ * focus, click, and keyboard actions to be passed through.
39
+ *
40
+ * **Important:** When using soft disabled, consumers must ensure that
41
+ * the buttonlink behaves like a disabled buttonlink, allowing only focus and
42
+ * preventing any interactions (clicks or keyboard actions) from triggering unintended actions.
43
+ * @default undefined
44
+ */
45
+ softDisabled?: boolean;
46
+ /**
47
+ * Sets the soft-disabled attribute for the buttonlink.
48
+ * When soft-disabled, the buttonlink looks to be disabled but remains focusable and clickable.
49
+ * Also sets/removes aria-disabled attribute.
50
+ *
51
+ * @param element - The buttonlink element.
52
+ * @param softDisabled - The soft-disabled state.
53
+ */
54
+ private setSoftDisabled;
55
+ update(changedProperties: PropertyValues): void;
56
+ render(): import("lit-html").TemplateResult<1>;
57
+ static styles: Array<CSSResult>;
58
+ }
59
+ export default ButtonLink;
@@ -0,0 +1,106 @@
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 Button from '../button/button.component';
13
+ import { ButtonComponentMixin } from '../../utils/mixins/ButtonComponentMixin';
14
+ import { DEFAULTS } from '../button/button.constants';
15
+ import Linksimple from '../linksimple/linksimple.component';
16
+ /**
17
+ * `mdc-buttonlink` combines the functional behavior of `mdc-linksimple` with the visual and structural
18
+ * features of `mdc-button`. This includes support for variants, sizing, and optional
19
+ * prefix and postfix icons via slots.
20
+ *
21
+ * ### Features:
22
+ * - Behaves like an link while visually resembling a button.
23
+ * - Supports slots for `prefix-icon` and `postfix-icon`.
24
+ * - Customizable size, color, and variant through attributes.
25
+ * - Inherits accessibility and keyboard interaction support from `mdc-linksimple`.
26
+ *
27
+ * @dependency mdc-icon
28
+ *
29
+ * @tagname mdc-buttonlink
30
+ *
31
+ * @event click - (React: onClick) Fired when the user activates the buttonLink using a mouse or assistive technology.
32
+ * @event keydown - (React: onKeyDown) Fired when the user presses a key while the buttonLink has focus.
33
+ * @event focus - (React: onFocus) Fired when the buttonLink receives keyboard or mouse focus.
34
+ * @event blur - (React: onBlur) Fired when the buttonLink loses keyboard or mouse focus.
35
+ *
36
+ */
37
+ class ButtonLink extends ButtonComponentMixin(Linksimple) {
38
+ constructor() {
39
+ super(...arguments);
40
+ /**
41
+ * ButtonLink sizing is based on the buttonlink type.
42
+ * - **Pill buttonlink**: 40, 32, 28, 24.
43
+ * - **Icon buttonlink**: 64, 52, 40, 32, 28, 24.
44
+ * - Tertiary icon buttonlink can also be 20.
45
+ * @default 32
46
+ */
47
+ this.size = DEFAULTS.SIZE;
48
+ }
49
+ /**
50
+ * Sets the soft-disabled attribute for the buttonlink.
51
+ * When soft-disabled, the buttonlink looks to be disabled but remains focusable and clickable.
52
+ * Also sets/removes aria-disabled attribute.
53
+ *
54
+ * @param element - The buttonlink element.
55
+ * @param softDisabled - The soft-disabled state.
56
+ */
57
+ setSoftDisabled(element, softDisabled) {
58
+ if (softDisabled) {
59
+ element.setAttribute('aria-disabled', 'true');
60
+ }
61
+ else {
62
+ element.removeAttribute('aria-disabled');
63
+ }
64
+ }
65
+ update(changedProperties) {
66
+ super.update(changedProperties);
67
+ if (changedProperties.has('softDisabled')) {
68
+ this.setSoftDisabled(this, this.softDisabled);
69
+ }
70
+ if (changedProperties.has('size')) {
71
+ this.setSize(this.size);
72
+ }
73
+ if (changedProperties.has('variant')) {
74
+ this.setVariant(this.variant);
75
+ this.setSize(this.size);
76
+ }
77
+ if (changedProperties.has('color')) {
78
+ this.setColor(this.color);
79
+ }
80
+ if (changedProperties.has('typeInternal')) {
81
+ this.setSize(this.size);
82
+ }
83
+ if (changedProperties.has('prefixIcon') || changedProperties.has('postfixIcon')) {
84
+ this.inferButtonType();
85
+ }
86
+ }
87
+ render() {
88
+ return html `
89
+ ${this.prefixIcon ? html ` <mdc-icon name="${this.prefixIcon}" part="prefix-icon"></mdc-icon>` : ''}
90
+ <slot @slotchange=${this.inferButtonType}></slot>
91
+ ${this.postfixIcon
92
+ ? html ` <mdc-icon name="${this.postfixIcon}" part="postfix-icon"></mdc-icon>`
93
+ : ''}
94
+ `;
95
+ }
96
+ }
97
+ ButtonLink.styles = [...Button.styles];
98
+ __decorate([
99
+ property({ type: Number, reflect: true }),
100
+ __metadata("design:type", Number)
101
+ ], ButtonLink.prototype, "size", void 0);
102
+ __decorate([
103
+ property({ type: Boolean, attribute: 'soft-disabled', reflect: true }),
104
+ __metadata("design:type", Boolean)
105
+ ], ButtonLink.prototype, "softDisabled", void 0);
106
+ export default ButtonLink;
@@ -0,0 +1,2 @@
1
+ declare const TAG_NAME: "mdc-buttonlink";
2
+ export { TAG_NAME };
@@ -0,0 +1,3 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('buttonlink');
3
+ export { TAG_NAME };
@@ -0,0 +1,7 @@
1
+ interface Events {
2
+ onClickEvent: MouseEvent;
3
+ onKeyDownEvent: KeyboardEvent;
4
+ onFocusEvent: FocusEvent;
5
+ onBlurEvent: Event;
6
+ }
7
+ export type { Events };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import ButtonLink from './buttonlink.component';
2
+ import '../icon';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ ['mdc-buttonlink']: ButtonLink;
6
+ }
7
+ }
8
+ export default ButtonLink;
@@ -0,0 +1,5 @@
1
+ import ButtonLink from './buttonlink.component';
2
+ import { TAG_NAME } from './buttonlink.constants';
3
+ import '../icon';
4
+ ButtonLink.register(TAG_NAME);
5
+ export default ButtonLink;