@muonic/muon 0.0.2-experimental-173-ae546db.0 → 0.0.2-experimental-175-121b4aa.0
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.
- package/CHANGELOG.md +9 -0
- package/components/cta/src/cta-component.js +20 -11
- package/components/icon/src/icon-component.js +3 -3
- package/package.json +1 -1
- package/tests/components/cta/__snapshots__/cta.test.snap.js +0 -5
- package/tests/components/cta/cta.test.js +0 -5
- package/tests/scripts/utils/utils-test.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.2-beta.8](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.7...v0.0.2-beta.8) (2023-04-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* check if parentElement exists ([2055f37](https://github.com/centrica-engineering/muon/commit/2055f377a03194ebd28fa74f38597dca8e612507))
|
|
11
|
+
* loading and disabled cta ([0569563](https://github.com/centrica-engineering/muon/commit/056956309c202557ac708e17ad4ed5a5760c3887))
|
|
12
|
+
* url state ([023fb86](https://github.com/centrica-engineering/muon/commit/023fb86886cf9d0dbe432fbae1b97e3cb220d5d8))
|
|
13
|
+
|
|
5
14
|
### [0.0.2-beta.7](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.6...v0.0.2-beta.7) (2023-04-04)
|
|
6
15
|
|
|
7
16
|
### [0.0.2-beta.6](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.5...v0.0.2-beta.6) (2023-03-28)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MuonElement, html, classMap, styleMap, ScopedElementsMixin, literal, staticHTML
|
|
1
|
+
import { MuonElement, html, classMap, styleMap, ScopedElementsMixin, literal, staticHTML } from '@muonic/muon';
|
|
2
2
|
import { Icon } from '@muon/components/icon';
|
|
3
3
|
import {
|
|
4
4
|
CTA_CONFIG_TYPE,
|
|
@@ -51,7 +51,7 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
|
|
|
51
51
|
|
|
52
52
|
get classes() {
|
|
53
53
|
const parentElement = this.parentElement;
|
|
54
|
-
const isDisabled = parentElement
|
|
54
|
+
const isDisabled = parentElement?.getAttribute('disabled') || this.disabled;
|
|
55
55
|
|
|
56
56
|
return {
|
|
57
57
|
cta: true,
|
|
@@ -100,7 +100,7 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
|
|
|
100
100
|
const isInLink = parentName === 'A';
|
|
101
101
|
const isInBtn = parentName === 'BUTTON';
|
|
102
102
|
const isInNativeForm = parentName === 'FORM';
|
|
103
|
-
const isDisabled = parentElement
|
|
103
|
+
const isDisabled = parentElement?.getAttribute('disabled') || this.disabled;
|
|
104
104
|
let element = this.href?.length > 0 ? 'a' : 'div';
|
|
105
105
|
|
|
106
106
|
if (
|
|
@@ -109,23 +109,35 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
|
|
|
109
109
|
!isInLink &&
|
|
110
110
|
!isInBtn &&
|
|
111
111
|
!isDisabled &&
|
|
112
|
+
!this.loading &&
|
|
112
113
|
!this._isButton
|
|
113
114
|
) {
|
|
114
115
|
if (!this.getAttribute('role')) {
|
|
115
116
|
this.setAttribute('role', 'button');
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
this.setAttribute('tabindex', '0');
|
|
120
|
-
}
|
|
119
|
+
this.setAttribute('tabindex', '0');
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
if (isDisabled) {
|
|
122
|
+
if (isDisabled || this.loading) {
|
|
124
123
|
if (!this.getAttribute('aria-disabled')) {
|
|
125
124
|
this.setAttribute('aria-disabled', 'true');
|
|
126
125
|
}
|
|
126
|
+
|
|
127
|
+
this.setAttribute('tabindex', '-1');
|
|
127
128
|
} else {
|
|
128
129
|
this.removeAttribute('aria-disabled');
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
this.getAttribute('tabindex') === '-1' &&
|
|
133
|
+
(this._isButton ||
|
|
134
|
+
isInBtn ||
|
|
135
|
+
isInNativeForm ||
|
|
136
|
+
isInLink ||
|
|
137
|
+
element === 'a')
|
|
138
|
+
) {
|
|
139
|
+
this.removeAttribute('tabindex');
|
|
140
|
+
}
|
|
129
141
|
}
|
|
130
142
|
|
|
131
143
|
if (isInNativeForm || this._isButton) {
|
|
@@ -137,14 +149,11 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
|
|
|
137
149
|
this.removeAttribute('tabindex');
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
// eslint-disable-next-line no-nested-ternary
|
|
141
|
-
const tabIndex = isInLink ? -1 : element !== 'div' ? 0 : undefined;
|
|
142
|
-
|
|
143
152
|
// eslint-disable-next-line no-nested-ternary
|
|
144
153
|
const elementTag = element === 'button' ? literal`button` : element === 'a' ? literal`a` : literal`div`;
|
|
145
154
|
|
|
146
155
|
return staticHTML`
|
|
147
|
-
<${elementTag} .href=${element === 'a' && this.href} ?disabled=${element === 'button' && (this.loading || this.disabled)}
|
|
156
|
+
<${elementTag} .href=${element === 'a' && this.href} ?disabled=${element === 'button' && (this.loading || this.disabled)} aria-label="${this.textContent}" class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)}>
|
|
148
157
|
${content}
|
|
149
158
|
</${elementTag}>
|
|
150
159
|
`;
|
|
@@ -24,7 +24,7 @@ export class Icon extends MuonElement {
|
|
|
24
24
|
describe: { type: String },
|
|
25
25
|
size: { type: Number },
|
|
26
26
|
category: { type: String },
|
|
27
|
-
|
|
27
|
+
_url: { type: String, state: true }
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -39,7 +39,7 @@ export class Icon extends MuonElement {
|
|
|
39
39
|
this.name = ICON_CONFIG_NAME;
|
|
40
40
|
this.category = ICON_CONFIG_CATEGORY;
|
|
41
41
|
this.allSizes = ICON_CONFIG_SIZES;
|
|
42
|
-
this.
|
|
42
|
+
this._url = ICON_CONFIG_URL;
|
|
43
43
|
this.describe = '';
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -81,7 +81,7 @@ export class Icon extends MuonElement {
|
|
|
81
81
|
|
|
82
82
|
return html`
|
|
83
83
|
<div aria-hidden=${ifDefined(hidden)} role=${ifDefined(role)} aria-label=${ifDefined(role && this.describe)} class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)}>
|
|
84
|
-
${svgLoader({ name: this.name, category: this.category, path: this.
|
|
84
|
+
${svgLoader({ name: this.name, category: this.category, path: this._url })}
|
|
85
85
|
</div>
|
|
86
86
|
`;
|
|
87
87
|
}
|
package/package.json
CHANGED
|
@@ -97,7 +97,6 @@ snapshots["cta implements with a href"] =
|
|
|
97
97
|
class="cta standard"
|
|
98
98
|
href="https://example.com"
|
|
99
99
|
style=""
|
|
100
|
-
tabindex="0"
|
|
101
100
|
>
|
|
102
101
|
<span class="label-holder">
|
|
103
102
|
<slot>
|
|
@@ -117,7 +116,6 @@ snapshots["cta implements cta within an anchor element"] =
|
|
|
117
116
|
aria-label="This is a button"
|
|
118
117
|
class="cta standard"
|
|
119
118
|
style=""
|
|
120
|
-
tabindex="-1"
|
|
121
119
|
>
|
|
122
120
|
<span class="label-holder">
|
|
123
121
|
<slot>
|
|
@@ -137,7 +135,6 @@ snapshots["cta implements within a form"] =
|
|
|
137
135
|
aria-label="This is a button"
|
|
138
136
|
class="cta standard"
|
|
139
137
|
style=""
|
|
140
|
-
tabindex="0"
|
|
141
138
|
>
|
|
142
139
|
<span class="label-holder">
|
|
143
140
|
<slot>
|
|
@@ -157,7 +154,6 @@ snapshots["cta implements with triggering button"] =
|
|
|
157
154
|
aria-label="This is a button"
|
|
158
155
|
class="cta standard"
|
|
159
156
|
style=""
|
|
160
|
-
tabindex="0"
|
|
161
157
|
>
|
|
162
158
|
<span class="label-holder">
|
|
163
159
|
<slot>
|
|
@@ -185,7 +181,6 @@ snapshots["cta implements loading as a button"] =
|
|
|
185
181
|
class="cta loading standard"
|
|
186
182
|
disabled=""
|
|
187
183
|
style=""
|
|
188
|
-
tabindex="0"
|
|
189
184
|
>
|
|
190
185
|
<span class="label-holder">
|
|
191
186
|
Loading...
|
|
@@ -110,7 +110,6 @@ describe('cta', () => {
|
|
|
110
110
|
expect(el.type).to.equal('standard', '`type` property has default value `standard`');
|
|
111
111
|
expect(cta.nodeName).to.equal('A', 'cta is an anchor element');
|
|
112
112
|
expect(cta.href).to.equal('https://example.com/', 'cta has the href');
|
|
113
|
-
expect(cta.getAttribute('tabindex')).to.equal('0', 'has tab index');
|
|
114
113
|
expect(cta.getAttribute('disabled')).to.equal(null, 'cta is not disabled');
|
|
115
114
|
});
|
|
116
115
|
|
|
@@ -126,7 +125,6 @@ describe('cta', () => {
|
|
|
126
125
|
expect(el.type).to.equal('standard', '`type` property has default value `standard`');
|
|
127
126
|
expect(cta.nodeName).to.equal('DIV', 'cta is a `div` element');
|
|
128
127
|
expect(cta.href).to.equal(false, 'cta has NO href');
|
|
129
|
-
expect(cta.getAttribute('tabindex')).to.equal('-1', 'has tab index');
|
|
130
128
|
expect(cta.getAttribute('disabled')).to.equal(null, 'cta is not disabled');
|
|
131
129
|
});
|
|
132
130
|
|
|
@@ -144,7 +142,6 @@ describe('cta', () => {
|
|
|
144
142
|
expect(el.getAttribute('tabindex')).to.not.exist; // eslint-disable-line no-unused-expressions
|
|
145
143
|
expect(cta.nodeName).to.equal('BUTTON', 'cta is a `div` element');
|
|
146
144
|
expect(cta.href).to.equal(false, 'cta has NO href');
|
|
147
|
-
expect(cta.getAttribute('tabindex')).to.equal('0', 'has tab index');
|
|
148
145
|
expect(cta.getAttribute('disabled')).to.equal(null, 'cta is not disabled');
|
|
149
146
|
});
|
|
150
147
|
|
|
@@ -162,7 +159,6 @@ describe('cta', () => {
|
|
|
162
159
|
expect(el.getAttribute('tabindex')).to.not.exist; // eslint-disable-line no-unused-expressions
|
|
163
160
|
expect(cta.nodeName).to.equal('BUTTON', 'cta is a `div` element');
|
|
164
161
|
expect(cta.href).to.equal(false, 'cta has NO href');
|
|
165
|
-
expect(cta.getAttribute('tabindex')).to.equal('0', 'has tab index');
|
|
166
162
|
expect(cta.getAttribute('disabled')).to.equal(null, 'cta is not disabled');
|
|
167
163
|
});
|
|
168
164
|
|
|
@@ -180,7 +176,6 @@ describe('cta', () => {
|
|
|
180
176
|
expect(el.getAttribute('tabindex')).to.not.exist; // eslint-disable-line no-unused-expressions
|
|
181
177
|
expect(cta.nodeName).to.equal('BUTTON', 'cta is a `button` element');
|
|
182
178
|
expect(cta.href).to.equal(false, 'cta has NO href');
|
|
183
|
-
expect(cta.getAttribute('tabindex')).to.equal('0', 'has tab index');
|
|
184
179
|
expect(cta.getAttribute('disabled')).to.equal('', 'cta is disabled');
|
|
185
180
|
});
|
|
186
181
|
|
|
@@ -185,7 +185,7 @@ testRunner('sourceFilesAnalyzer', async (t) => {
|
|
|
185
185
|
cta: ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
|
|
186
186
|
detail: ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
|
|
187
187
|
form: ['standardTemplate', 'type'],
|
|
188
|
-
icon: ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', '
|
|
188
|
+
icon: ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'describe', 'type'],
|
|
189
189
|
image: ['src', 'classes', 'inlineStyles', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
|
|
190
190
|
inputter: ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
|
|
191
191
|
'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type']
|