@momentum-design/components 0.53.8 → 0.53.9

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,15 +1,13 @@
1
- import type { PropertyValues } from 'lit';
2
- import { CSSResult } from 'lit';
1
+ import { PropertyValues, CSSResult } from 'lit';
3
2
  import { Component } from '../../models';
4
3
  import type { LinkSize } from './link.types';
5
- declare const Link_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/IconNameMixin").IconNameMixinInterface> & typeof Component;
4
+ declare const Link_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/TabIndexMixin").TabIndexMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/IconNameMixin").IconNameMixinInterface> & typeof Component;
6
5
  /**
7
6
  * `mdc-link` component can be used to navigate to a different page
8
7
  * within the application or to an external site. It can be used to link to
9
8
  * emails or phone numbers.
10
9
  *
11
- * The `children` of the link component is expected to be an anchor element
12
- * containing the text, href, and other attributes.
10
+ * The `children` of the link component is expected to be the text content.
13
11
  *
14
12
  * For `icon`, the `mdc-icon` component is used to render the icon.
15
13
  *
@@ -17,6 +15,11 @@ declare const Link_base: import("../../utils/mixins/index.types").Constructor<im
17
15
  *
18
16
  * @tagname mdc-link
19
17
  *
18
+ * @event click - (React: onClick) Fired when the user activates the buttonLink using a mouse or assistive technology.
19
+ * @event keydown - (React: onKeyDown) Fired when the user presses a key while the buttonLink has focus.
20
+ * @event focus - (React: onFocus) Fired when the buttonLink receives keyboard or mouse focus.
21
+ * @event blur - (React: onBlur) Fired when the buttonLink loses keyboard or mouse focus.
22
+ *
20
23
  * @cssproperty --mdc-link-border-radius - Border radius of the link
21
24
  * @cssproperty --mdc-link-color-active - Text and icon color of the link in active state
22
25
  * @cssproperty --mdc-link-color-disabled - Text and icon color of the link in disabled state
@@ -52,31 +55,39 @@ declare class Link extends Link_base {
52
55
  */
53
56
  size: LinkSize;
54
57
  /**
55
- * Used to store the previous tabindex value of the host element
56
- * null value means that the host element did not have a tabindex attribute.
58
+ * Href for navigation. The URL that the hyperlink points to
59
+ */
60
+ href: string;
61
+ /**
62
+ * Optional target: _blank, _self, _parent, _top and _unfencedTop
63
+ */
64
+ target: string;
65
+ /**
66
+ * Optional rel attribute that defines the relationship of the linked URL as space-separated link types.
67
+ */
68
+ rel?: string;
69
+ /**
70
+ * Stores the previous tabindex if set by user
71
+ * so it can be restored after disabling
57
72
  * @internal
58
73
  */
59
74
  private prevTabindex;
75
+ connectedCallback(): void;
76
+ disconnectedCallback(): void;
77
+ private handleNavigation;
60
78
  /**
61
79
  * Method to get the size of the trailing icon based on the link size.
62
80
  * @returns The icon size value and units.
63
81
  */
64
82
  private getIconSize;
65
83
  /**
66
- * Updates the tabindex of the host element to disable or enable the link.
67
- * When disabled, the link is not focusable or clickable, and tabindex is set to -1
68
- * and aria-disabled attribute is set to true
69
- * When link is not disabled, the previous tabindex of the host element is restored
70
- * and aria-disabled attribute is removed.
84
+ * Sets or removes `aria-disabled` and updates `tabIndex` to reflect
85
+ * the disabled state. When disabled, the element becomes unfocusable;
86
+ * when enabled, the previous `tabIndex` is restored.
71
87
  *
72
- * @param disabled - The disabled state of icon
88
+ * @param disabled - Whether the element should be disabled
73
89
  */
74
90
  private setDisabled;
75
- /**
76
- * Method to create and append trailing icon to the first anchor element in the slot.
77
- * If no icon name is provided, no icon will be rendered.
78
- */
79
- private updateTrailingIcon;
80
91
  update(changedProperties: PropertyValues): void;
81
92
  render(): import("lit-html").TemplateResult<1>;
82
93
  static styles: Array<CSSResult>;
@@ -7,20 +7,20 @@ 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 { Component } from '../../models';
13
13
  import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
14
14
  import { IconNameMixin } from '../../utils/mixins/IconNameMixin';
15
15
  import { DEFAULTS, LINK_ICON_SIZES, LINK_SIZES } from './link.constants';
16
16
  import styles from './link.styles';
17
+ import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
17
18
  /**
18
19
  * `mdc-link` component can be used to navigate to a different page
19
20
  * within the application or to an external site. It can be used to link to
20
21
  * emails or phone numbers.
21
22
  *
22
- * The `children` of the link component is expected to be an anchor element
23
- * containing the text, href, and other attributes.
23
+ * The `children` of the link component is expected to be the text content.
24
24
  *
25
25
  * For `icon`, the `mdc-icon` component is used to render the icon.
26
26
  *
@@ -28,6 +28,11 @@ import styles from './link.styles';
28
28
  *
29
29
  * @tagname mdc-link
30
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
+ *
31
36
  * @cssproperty --mdc-link-border-radius - Border radius of the link
32
37
  * @cssproperty --mdc-link-color-active - Text and icon color of the link in active state
33
38
  * @cssproperty --mdc-link-color-disabled - Text and icon color of the link in disabled state
@@ -40,7 +45,7 @@ import styles from './link.styles';
40
45
  * @cssproperty --mdc-link-inverted-color-normal - Text and icon color of the inverted link in normal state
41
46
  * @cssproperty --mdc-link-text-decoration-disabled - Text decoration of the link in disabled state for all variants
42
47
  */
43
- class Link extends DisabledMixin(IconNameMixin(Component)) {
48
+ class Link extends DisabledMixin(TabIndexMixin(IconNameMixin(Component))) {
44
49
  constructor() {
45
50
  super(...arguments);
46
51
  /**
@@ -65,11 +70,37 @@ class Link extends DisabledMixin(IconNameMixin(Component)) {
65
70
  */
66
71
  this.size = DEFAULTS.LINK_SIZE;
67
72
  /**
68
- * Used to store the previous tabindex value of the host element
69
- * null value means that the host element did not have a tabindex attribute.
73
+ * Href for navigation. The URL that the hyperlink points to
74
+ */
75
+ this.href = '#';
76
+ /**
77
+ * Optional target: _blank, _self, _parent, _top and _unfencedTop
78
+ */
79
+ this.target = '_self';
80
+ /**
81
+ * Stores the previous tabindex if set by user
82
+ * so it can be restored after disabling
70
83
  * @internal
71
84
  */
72
- this.prevTabindex = null;
85
+ this.prevTabindex = 0;
86
+ this.handleNavigation = (e) => {
87
+ if ((e.type === 'click' || (e instanceof KeyboardEvent && e.key === 'Enter')) && this.href) {
88
+ if (this.disabled)
89
+ return;
90
+ window.open(this.href, this.target, this.rel);
91
+ }
92
+ };
93
+ }
94
+ connectedCallback() {
95
+ super.connectedCallback();
96
+ this.setAttribute('role', 'link');
97
+ this.addEventListener('click', this.handleNavigation);
98
+ this.addEventListener('keydown', this.handleNavigation);
99
+ }
100
+ disconnectedCallback() {
101
+ super.disconnectedCallback();
102
+ this.removeEventListener('click', this.handleNavigation);
103
+ this.removeEventListener('keydown', this.handleNavigation);
73
104
  }
74
105
  /**
75
106
  * Method to get the size of the trailing icon based on the link size.
@@ -86,45 +117,25 @@ class Link extends DisabledMixin(IconNameMixin(Component)) {
86
117
  }
87
118
  }
88
119
  /**
89
- * Updates the tabindex of the host element to disable or enable the link.
90
- * When disabled, the link is not focusable or clickable, and tabindex is set to -1
91
- * and aria-disabled attribute is set to true
92
- * When link is not disabled, the previous tabindex of the host element is restored
93
- * and aria-disabled attribute is removed.
120
+ * Sets or removes `aria-disabled` and updates `tabIndex` to reflect
121
+ * the disabled state. When disabled, the element becomes unfocusable;
122
+ * when enabled, the previous `tabIndex` is restored.
94
123
  *
95
- * @param disabled - The disabled state of icon
124
+ * @param disabled - Whether the element should be disabled
96
125
  */
97
126
  setDisabled(disabled) {
98
127
  if (disabled) {
99
- this.prevTabindex = this.hasAttribute('tabindex') ? this.tabIndex : null;
100
- this.tabIndex = -1;
101
128
  this.setAttribute('aria-disabled', 'true');
102
- }
103
- else if (this.prevTabindex === null) {
104
- this.removeAttribute('tabindex');
105
- this.removeAttribute('aria-disabled');
129
+ this.prevTabindex = this.tabIndex;
130
+ this.tabIndex = -1;
106
131
  }
107
132
  else {
108
- this.tabIndex = this.prevTabindex;
133
+ if (this.tabIndex === -1) {
134
+ this.tabIndex = this.prevTabindex;
135
+ }
109
136
  this.removeAttribute('aria-disabled');
110
137
  }
111
138
  }
112
- /**
113
- * Method to create and append trailing icon to the first anchor element in the slot.
114
- * If no icon name is provided, no icon will be rendered.
115
- */
116
- updateTrailingIcon() {
117
- var _a, _b;
118
- const anchorElement = (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot')) === null || _b === void 0 ? void 0 : _b.assignedElements({ flatten: true }).find((element) => element.tagName === 'A');
119
- const iconSize = this.getIconSize();
120
- if (this.iconName && anchorElement) {
121
- const trailingIcon = document.createElement('mdc-icon');
122
- trailingIcon.setAttribute('name', this.iconName);
123
- trailingIcon.setAttribute('size', `${iconSize}`);
124
- trailingIcon.setAttribute('length-unit', 'rem');
125
- anchorElement.appendChild(trailingIcon);
126
- }
127
- }
128
139
  update(changedProperties) {
129
140
  super.update(changedProperties);
130
141
  if (changedProperties.has('disabled')) {
@@ -133,9 +144,14 @@ class Link extends DisabledMixin(IconNameMixin(Component)) {
133
144
  }
134
145
  render() {
135
146
  return html `
136
- <div part='link-container' class='mdc-focus-ring'>
137
- <slot @slotchange=${this.updateTrailingIcon}></slot>
138
- </div>
147
+ <slot></slot>
148
+ ${this.iconName ? html `
149
+ <mdc-icon
150
+ name=${this.iconName}
151
+ size=${this.getIconSize()}
152
+ length-unit="rem"
153
+ ></mdc-icon>
154
+ ` : nothing}
139
155
  `;
140
156
  }
141
157
  }
@@ -152,4 +168,16 @@ __decorate([
152
168
  property({ type: String, reflect: true }),
153
169
  __metadata("design:type", String)
154
170
  ], Link.prototype, "size", void 0);
171
+ __decorate([
172
+ property({ type: String, reflect: true }),
173
+ __metadata("design:type", Object)
174
+ ], Link.prototype, "href", void 0);
175
+ __decorate([
176
+ property({ type: String, reflect: true }),
177
+ __metadata("design:type", Object)
178
+ ], Link.prototype, "target", void 0);
179
+ __decorate([
180
+ property({ type: String, reflect: true }),
181
+ __metadata("design:type", String)
182
+ ], Link.prototype, "rel", void 0);
155
183
  export default Link;
@@ -1,9 +1,7 @@
1
1
  import { css } from 'lit';
2
2
  import { hostFitContentStyles, hostFocusRingStyles } from '../../utils/styles';
3
3
  const styles = [hostFitContentStyles, css `
4
-
5
4
  :host {
6
-
7
5
  --mdc-link-border-radius: 0.25rem;
8
6
  --mdc-link-color-active: var(--mds-color-theme-text-accent-active);
9
7
  --mdc-link-color-disabled: var(--mds-color-theme-text-primary-disabled);
@@ -15,49 +13,50 @@ const styles = [hostFitContentStyles, css `
15
13
  --mdc-link-inverted-color-hover: var(--mds-color-theme-inverted-text-accent-hover);
16
14
  --mdc-link-inverted-color-normal: var(--mds-color-theme-inverted-text-accent-normal);
17
15
  --mdc-link-text-decoration-disabled: underline;
18
- }
19
16
 
20
- :host::part(link-container){
21
17
  border-radius: var(--mdc-link-border-radius);
22
18
  color: var(--mdc-link-color-normal);
23
- }
24
-
25
- ::slotted(a) {
26
- outline: none;
27
- align-items: center;
28
- color: inherit;
29
- display: flex;
30
19
  gap: var(--mdc-link-icon-margin-left);
31
- text-decoration: inherit;
32
20
  text-underline-offset: auto;
33
21
  text-underline-position: from-font;
22
+ cursor: pointer;
34
23
  }
35
24
 
36
- :host(:hover)::part(link-container) {
37
- color: var(--mdc-link-color-hover);
25
+ :host([inline]) {
26
+ display: inline-flex;
38
27
  }
39
28
 
40
- :host(:active)::part(link-container) {
41
- color: var(--mdc-link-color-active);
29
+ :host(:hover) {
30
+ color: var(--mdc-link-color-hover);
42
31
  }
43
32
 
44
- :host([inline]) {
45
- display: inline-flex;
33
+ :host(:active) {
34
+ color: var(--mdc-link-color-active);
35
+ box-shadow: none;
46
36
  }
47
37
 
48
- :host([inverted])::part(link-container) {
38
+ :host([inverted]) {
49
39
  color: var(--mdc-link-inverted-color-normal);
50
40
  }
51
41
 
52
- :host([inverted]:hover)::part(link-container) {
42
+ :host([inverted]:hover) {
53
43
  color: var(--mdc-link-inverted-color-hover);
54
44
  }
55
45
 
56
- :host([inverted]:active)::part(link-container) {
46
+ :host([inverted]:active) {
57
47
  color: var(--mdc-link-inverted-color-active);
58
48
  }
59
49
 
60
- :host([size="large"])::part(link-container) {
50
+ :host([disabled]) {
51
+ color: var(--mdc-link-color-disabled);
52
+ pointer-events: none;
53
+ }
54
+
55
+ :host([inverted][disabled]) {
56
+ color: var(--mdc-link-inverted-color-disabled);
57
+ }
58
+
59
+ :host([size="large"]) {
61
60
  font-size: var(--mds-font-apps-body-large-regular-font-size);
62
61
  font-weight: var(--mds-font-apps-body-large-regular-font-weight);
63
62
  line-height: var(--mds-font-apps-body-large-regular-line-height);
@@ -65,7 +64,7 @@ const styles = [hostFitContentStyles, css `
65
64
  text-transform: var(--mds-font-apps-body-large-regular-text-case);
66
65
  }
67
66
 
68
- :host([size="midsize"])::part(link-container) {
67
+ :host([size="midsize"]) {
69
68
  font-size: var(--mds-font-apps-body-midsize-regular-font-size);
70
69
  font-weight: var(--mds-font-apps-body-midsize-regular-font-weight);
71
70
  line-height: var(--mds-font-apps-body-midsize-regular-line-height);
@@ -73,7 +72,7 @@ const styles = [hostFitContentStyles, css `
73
72
  text-transform: var(--mds-font-apps-body-midsize-regular-text-case);
74
73
  }
75
74
 
76
- :host([size="small"])::part(link-container) {
75
+ :host([size="small"]) {
77
76
  font-size: var(--mds-font-apps-body-small-regular-font-size);
78
77
  font-weight: var(--mds-font-apps-body-small-regular-font-weight);
79
78
  line-height: var(--mds-font-apps-body-small-regular-line-height);
@@ -81,9 +80,9 @@ const styles = [hostFitContentStyles, css `
81
80
  text-transform: var(--mds-font-apps-body-small-regular-text-case);
82
81
  }
83
82
 
84
- :host([size="large"]:hover)::part(link-container),
85
- :host([size="large"]:active)::part(link-container),
86
- :host([size="large"][inline])::part(link-container) {
83
+ :host([size="large"]:hover),
84
+ :host([size="large"]:active),
85
+ :host([size="large"][inline]) {
87
86
  font-size: var(--mds-font-apps-body-large-regular-underline-font-size);
88
87
  font-weight: var(--mds-font-apps-body-large-regular-underline-font-weight);
89
88
  line-height: var(--mds-font-apps-body-large-regular-underline-line-height);
@@ -91,9 +90,9 @@ const styles = [hostFitContentStyles, css `
91
90
  text-transform: var(--mds-font-apps-body-large-regular-underline-text-case);
92
91
  }
93
92
 
94
- :host([size="midsize"]:hover)::part(link-container),
95
- :host([size="midsize"]:active)::part(link-container),
96
- :host([size="midsize"][inline])::part(link-container) {
93
+ :host([size="midsize"]:hover),
94
+ :host([size="midsize"]:active),
95
+ :host([size="midsize"][inline]) {
97
96
  font-size: var(--mds-font-apps-body-midsize-regular-underline-font-size);
98
97
  font-weight: var(--mds-font-apps-body-midsize-regular-underline-font-weight);
99
98
  line-height: var(--mds-font-apps-body-midsize-regular-underline-line-height);
@@ -101,28 +100,15 @@ const styles = [hostFitContentStyles, css `
101
100
  text-transform: var(--mds-font-apps-body-midsize-regular-underline-text-case);
102
101
  }
103
102
 
104
- :host([size="small"]:hover)::part(link-container),
105
- :host([size="small"]:active)::part(link-container),
106
- :host([size="small"][inline])::part(link-container) {
103
+ :host([size="small"]:hover),
104
+ :host([size="small"]:active),
105
+ :host([size="small"][inline]) {
107
106
  font-size: var(--mds-font-apps-body-small-regular-underline-font-size);
108
107
  font-weight: var(--mds-font-apps-body-small-regular-underline-font-weight);
109
108
  line-height: var(--mds-font-apps-body-small-regular-underline-line-height);
110
109
  text-decoration: var(--mds-font-apps-body-small-regular-underline-text-decoration);
111
110
  text-transform: var(--mds-font-apps-body-small-regular-underline-text-case);
112
111
  }
113
-
114
- :host([disabled])::part(link-container) {
115
- color: var(--mdc-link-color-disabled);
116
- pointer-events: none;
117
- }
118
-
119
- :host([inverted][disabled])::part(link-container) {
120
- color: var(--mdc-link-inverted-color-disabled);
121
- }
122
- `, ...hostFocusRingStyles(true),
123
- css `
124
- :host(:active)::part(link-container) {
125
- box-shadow: none;
126
- }
127
- `];
112
+ `, ...hostFocusRingStyles(),
113
+ ];
128
114
  export default styles;
@@ -1,4 +1,10 @@
1
1
  import type { ValueOf } from '../../utils/types';
2
2
  import { LINK_SIZES } from './link.constants';
3
3
  type LinkSize = ValueOf<typeof LINK_SIZES>;
4
- export type { LinkSize };
4
+ interface Events {
5
+ onClickEvent: MouseEvent;
6
+ onBlurEvent: Event;
7
+ onKeyDownEvent: KeyboardEvent;
8
+ onFocusEvent: FocusEvent;
9
+ }
10
+ export type { LinkSize, Events };