@muonic/muon 0.0.2-experimental-162-8df3e7e.0 → 0.0.2-experimental-163-66fa43f.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.
@@ -1,4 +1,4 @@
1
- import { MuonElement, html, ScopedElementsMixin } from '@muonic/muon';
1
+ import { MuonElement, classMap, styleMap, html, ScopedElementsMixin } from '@muonic/muon';
2
2
  import { CardMixin } from '@muon/mixins/card-mixin';
3
3
  import { ImageHolderMixin } from '@muon/mixins/image-holder-mixin';
4
4
  import { Image } from '@muon/components/image';
@@ -17,6 +17,16 @@ export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonEle
17
17
  };
18
18
  }
19
19
 
20
+ get classes() {
21
+ return {
22
+ card: true
23
+ };
24
+ }
25
+
26
+ get inlineStyles() {
27
+ return {};
28
+ }
29
+
20
30
  get _addImage() {
21
31
  return this.image ? html`
22
32
  <div class="media">
@@ -26,7 +36,7 @@ export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonEle
26
36
 
27
37
  get standardTemplate() {
28
38
  return html`
29
- <div class="card">
39
+ <div class="${classMap(this.classes)}" style="${styleMap(this.inlineStyles)}">
30
40
  ${this._addImage}
31
41
  <div class="body">
32
42
  ${this._addHeader}
@@ -1,4 +1,4 @@
1
- import { MuonElement, html, classMap, ScopedElementsMixin, literal, staticHTML, ifDefined } from '@muonic/muon';
1
+ import { MuonElement, html, classMap, styleMap, ScopedElementsMixin, literal, staticHTML, ifDefined } from '@muonic/muon';
2
2
  import { Icon } from '@muon/components/icon';
3
3
  import {
4
4
  CTA_CONFIG_TYPE,
@@ -49,6 +49,22 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
49
49
  this.icon = CTA_ICON_NAME;
50
50
  }
51
51
 
52
+ get classes() {
53
+ const parentElement = this.parentElement;
54
+ const isDisabled = parentElement.getAttribute('disabled') || this.disabled;
55
+
56
+ return {
57
+ cta: true,
58
+ [this.type]: true,
59
+ loading: this.loading,
60
+ disabled: isDisabled
61
+ };
62
+ }
63
+
64
+ get inlineStyles() {
65
+ return {};
66
+ }
67
+
52
68
  /**
53
69
  * Adds icon html.
54
70
  *
@@ -123,18 +139,12 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
123
139
 
124
140
  // eslint-disable-next-line no-nested-ternary
125
141
  const tabIndex = isInLink ? -1 : element !== 'div' ? 0 : undefined;
126
- const classes = {
127
- cta: true,
128
- [this.type]: true,
129
- loading: this.loading,
130
- disabled: isDisabled
131
- };
132
142
 
133
143
  // eslint-disable-next-line no-nested-ternary
134
144
  const elementTag = element === 'button' ? literal`button` : element === 'a' ? literal`a` : literal`div`;
135
145
 
136
146
  return staticHTML`
137
- <${elementTag} .href=${element === 'a' && this.href} ?disabled=${element === 'button' && (this.loading || this.disabled)} tabindex="${ifDefined(tabIndex)}" aria-label="${this.textContent}" class=${classMap(classes)}>
147
+ <${elementTag} .href=${element === 'a' && this.href} ?disabled=${element === 'button' && (this.loading || this.disabled)} tabindex="${ifDefined(tabIndex)}" aria-label="${this.textContent}" class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)}>
138
148
  ${content}
139
149
  </${elementTag}>
140
150
  `;
@@ -43,6 +43,19 @@ export class Icon extends MuonElement {
43
43
  this.describe = '';
44
44
  }
45
45
 
46
+ get classes() {
47
+ return {
48
+ icon: true,
49
+ [this.type]: true
50
+ };
51
+ }
52
+
53
+ get inlineStyles() {
54
+ return {
55
+ '--icon-size': this.iconSize
56
+ };
57
+ }
58
+
46
59
  /**
47
60
  * A getter method to get size of image.
48
61
  *
@@ -65,17 +78,9 @@ export class Icon extends MuonElement {
65
78
  get standardTemplate() {
66
79
  const hidden = this.describe?.length === 0 ? 'true' : undefined;
67
80
  const role = !hidden ? 'img' : undefined;
68
- const classes = {
69
- icon: true,
70
- [this.type]: true
71
- };
72
-
73
- const styles = {
74
- '--icon-size': this.iconSize
75
- };
76
81
 
77
82
  return html`
78
- <div aria-hidden=${ifDefined(hidden)} role=${ifDefined(role)} aria-label=${ifDefined(role && this.describe)} class=${classMap(classes)} style=${styleMap(styles)}>
83
+ <div aria-hidden=${ifDefined(hidden)} role=${ifDefined(role)} aria-label=${ifDefined(role && this.describe)} class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)}>
79
84
  ${svgLoader({ name: this.name, category: this.category, path: this.url })}
80
85
  </div>
81
86
  `;
@@ -45,7 +45,23 @@ export class Image extends MuonElement {
45
45
  this.placeholder = IMAGE_CONFIG_PLACEHOLDER;
46
46
  this.loading = 'lazy'; // eager|lazy
47
47
  this._ratios = IMAGE_CONFIG_RATIOS;
48
+ }
48
49
 
50
+ get classes() {
51
+ return {
52
+ image: true,
53
+ 'no-ratio': !this.ratio || this.ratio?.length < 1,
54
+ 'is-background': this.background
55
+ };
56
+ }
57
+
58
+ get inlineStyles() {
59
+ const [x, y] = this.ratio.split(' / ');
60
+ return {
61
+ '--image-ratio': CSS?.supports('aspect-ratio', '1 / 1') && this.ratio ? this.ratio : undefined,
62
+ '--image-padding': CSS?.supports('aspect-ratio', '1 / 1') || !x && !y ? undefined : `${y / x * 100}%`,
63
+ '--background-size': this.background ? this.backgroundsize : undefined
64
+ };
49
65
  }
50
66
 
51
67
  get placeholderImage() {
@@ -63,19 +79,6 @@ export class Image extends MuonElement {
63
79
  this.ratio = this.ratio?.length > 0 ? this.ratio : '16 / 9'; // without a default size background images won't show
64
80
  }
65
81
 
66
- const [x, y] = this.ratio.split(' / ');
67
- const styles = {
68
- '--image-ratio': CSS?.supports('aspect-ratio', '1 / 1') && this.ratio ? this.ratio : undefined,
69
- '--image-padding': CSS?.supports('aspect-ratio', '1 / 1') || !x && !y ? undefined : `${y / x * 100}%`,
70
- '--background-size': isBackground ? this.backgroundsize : undefined
71
- };
72
-
73
- const classes = {
74
- image: true,
75
- 'no-ratio': !this.ratio || this.ratio?.length < 1,
76
- 'is-background': isBackground
77
- };
78
-
79
82
  if (this.src && this.src.length > 0) {
80
83
  const imageObj = {
81
84
  src: this.src,
@@ -85,7 +88,7 @@ export class Image extends MuonElement {
85
88
  };
86
89
 
87
90
  return html`
88
- <div class=${classMap(classes)} style=${styleMap(styles)}>
91
+ <div class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)}>
89
92
  ${isBackground ? imageBackgroundLoader(imageObj) : imageInlineLoader(imageObj)}
90
93
  </div>
91
94
  `;
@@ -47,6 +47,29 @@ export class Inputter extends ScopedElementsMixin(ValidationMixin(MaskMixin(Muon
47
47
  return styles;
48
48
  }
49
49
 
50
+ get classes() {
51
+ return {
52
+ inputter: true,
53
+ select: this._isSelect,
54
+ 'has-mask': this.mask,
55
+ radio: this._inputType === this._inputTypes.RADIO,
56
+ checkbox: this._inputType === this._inputTypes.CHECKBOX,
57
+ search: this._inputType === this._inputTypes.SEARCH,
58
+ date: this._inputType === this._inputTypes.DATE,
59
+ 'has-disabled': this._hasDisabled
60
+ };
61
+ }
62
+
63
+ get inlineStyles() {
64
+ if (this.mask) {
65
+ return {
66
+ '--maxlength': this.mask.length
67
+ };
68
+ }
69
+
70
+ return {};
71
+ }
72
+
50
73
  get slottedStyles() {
51
74
  return slottedStyles;
52
75
  }
@@ -172,26 +195,8 @@ export class Inputter extends ScopedElementsMixin(ValidationMixin(MaskMixin(Muon
172
195
  }
173
196
 
174
197
  get standardTemplate() {
175
- const classes = {
176
- inputter: true,
177
- select: this._isSelect,
178
- 'has-mask': this.mask,
179
- radio: this._inputType === this._inputTypes.RADIO,
180
- checkbox: this._inputType === this._inputTypes.CHECKBOX,
181
- search: this._inputType === this._inputTypes.SEARCH,
182
- date: this._inputType === this._inputTypes.DATE,
183
- 'has-disabled': this._hasDisabled
184
- };
185
-
186
- let styles = {};
187
- if (this.mask) {
188
- styles = {
189
- '--maxlength': this.mask.length
190
- };
191
- }
192
-
193
198
  return html`
194
- <div class="${classMap(classes)}" style="${styleMap(styles)}">
199
+ <div class="${classMap(this.classes)}" style="${styleMap(this.inlineStyles)}">
195
200
  ${this._isMultiple ? this._addHeading : this._addLabel}
196
201
  ${this._addHelper}
197
202
  <div class="wrapper">
@@ -1,4 +1,4 @@
1
- import { html, classMap, ScopedElementsMixin, dedupeMixin } from '@muonic/muon';
1
+ import { html, classMap, styleMap, ScopedElementsMixin, dedupeMixin } from '@muonic/muon';
2
2
  import { Icon } from '@muon/components/icon';
3
3
 
4
4
  /**.
@@ -50,6 +50,19 @@ export const DetailMixin = dedupeMixin((superClass) =>
50
50
  this._toggleEvent = 'detail-toggle';
51
51
  }
52
52
 
53
+ get classes() {
54
+ return {
55
+ details: true,
56
+ 'toggle-start': this._togglePosition === 'start',
57
+ 'toggle-end': this._togglePosition === 'end',
58
+ 'has-icon': !!this.icon
59
+ };
60
+ }
61
+
62
+ get inlineStyles() {
63
+ return {};
64
+ }
65
+
53
66
  /**
54
67
  * A method to handle 'toggle' event from the html detail element.
55
68
  *
@@ -68,14 +81,8 @@ export const DetailMixin = dedupeMixin((superClass) =>
68
81
  }
69
82
 
70
83
  get standardTemplate() {
71
- const classes = {
72
- details: true,
73
- 'toggle-start': this._togglePosition === 'start',
74
- 'toggle-end': this._togglePosition === 'end',
75
- 'has-icon': !!this.icon
76
- };
77
84
  return html`
78
- <details class=${classMap(classes)} ?open="${this.open}" @toggle="${this._onToggle}">
85
+ <details class=${classMap(this.classes)} style=${styleMap(this.inlineStyles)} ?open="${this.open}" @toggle="${this._onToggle}">
79
86
  ${this._addHeading}
80
87
  ${this._addContent}
81
88
  </details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-162-8df3e7e.0",
3
+ "version": "0.0.2-experimental-163-66fa43f.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,7 +2,10 @@
2
2
  export const snapshots = {};
3
3
 
4
4
  snapshots["card default"] =
5
- `<div class="card">
5
+ `<div
6
+ class="card"
7
+ style=""
8
+ >
6
9
  <div class="body">
7
10
  <div class="header">
8
11
  <slot name="header">
@@ -22,7 +25,10 @@ snapshots["card default"] =
22
25
  /* end snapshot card default */
23
26
 
24
27
  snapshots["card standard"] =
25
- `<div class="card">
28
+ `<div
29
+ class="card"
30
+ style=""
31
+ >
26
32
  <div class="body">
27
33
  <div class="header">
28
34
  <slot name="header">
@@ -42,7 +48,10 @@ snapshots["card standard"] =
42
48
  /* end snapshot card standard */
43
49
 
44
50
  snapshots["card standard with image"] =
45
- `<div class="card">
51
+ `<div
52
+ class="card"
53
+ style=""
54
+ >
46
55
  <div class="media">
47
56
  <card-image
48
57
  alt="image alt"
@@ -5,6 +5,7 @@ snapshots["cta implements standard self"] =
5
5
  `<div
6
6
  aria-label="Buy a doughnut"
7
7
  class="cta standard"
8
+ style=""
8
9
  >
9
10
  <span class="label-holder">
10
11
  <slot>
@@ -36,6 +37,7 @@ snapshots["cta implements with no icon"] =
36
37
  `<div
37
38
  aria-label="Click me please"
38
39
  class="cta standard"
40
+ style=""
39
41
  >
40
42
  <span class="label-holder">
41
43
  <slot>
@@ -56,6 +58,7 @@ snapshots["cta implements with loading"] =
56
58
  <div
57
59
  aria-label="This is a button"
58
60
  class="cta loading standard"
61
+ style=""
59
62
  >
60
63
  <span class="label-holder">
61
64
  Loading...
@@ -73,6 +76,7 @@ snapshots["cta implements with icon at start"] =
73
76
  `<div
74
77
  aria-label="Something something...danger zone"
75
78
  class="cta standard"
79
+ style=""
76
80
  >
77
81
  <cta-icon
78
82
  class="icon"
@@ -92,6 +96,7 @@ snapshots["cta implements with a href"] =
92
96
  aria-label="This is a button"
93
97
  class="cta standard"
94
98
  href="https://example.com"
99
+ style=""
95
100
  tabindex="0"
96
101
  >
97
102
  <span class="label-holder">
@@ -111,6 +116,7 @@ snapshots["cta implements cta within an anchor element"] =
111
116
  `<div
112
117
  aria-label="This is a button"
113
118
  class="cta standard"
119
+ style=""
114
120
  tabindex="-1"
115
121
  >
116
122
  <span class="label-holder">
@@ -130,6 +136,7 @@ snapshots["cta implements within a form"] =
130
136
  `<button
131
137
  aria-label="This is a button"
132
138
  class="cta standard"
139
+ style=""
133
140
  tabindex="0"
134
141
  >
135
142
  <span class="label-holder">
@@ -149,6 +156,7 @@ snapshots["cta implements with triggering button"] =
149
156
  `<button
150
157
  aria-label="This is a button"
151
158
  class="cta standard"
159
+ style=""
152
160
  tabindex="0"
153
161
  >
154
162
  <span class="label-holder">
@@ -176,6 +184,7 @@ snapshots["cta implements loading as a button"] =
176
184
  aria-label="This is a button"
177
185
  class="cta loading standard"
178
186
  disabled=""
187
+ style=""
179
188
  tabindex="0"
180
189
  >
181
190
  <span class="label-holder">
@@ -194,6 +203,7 @@ snapshots["cta implements with disabled"] =
194
203
  `<div
195
204
  aria-label="This is a button"
196
205
  class="cta disabled standard"
206
+ style=""
197
207
  >
198
208
  <span class="label-holder">
199
209
  <slot>
@@ -212,6 +222,7 @@ snapshots["cta implements template `submit`"] =
212
222
  `<div
213
223
  aria-label="This is a button"
214
224
  class="cta submit"
225
+ style=""
215
226
  >
216
227
  <span class="label-holder">
217
228
  <slot>
@@ -230,6 +241,7 @@ snapshots["cta implements template `reset`"] =
230
241
  `<div
231
242
  aria-label="This is a button"
232
243
  class="cta reset"
244
+ style=""
233
245
  >
234
246
  <span class="label-holder">
235
247
  <slot>
@@ -2,7 +2,10 @@
2
2
  export const snapshots = {};
3
3
 
4
4
  snapshots["detail standard"] =
5
- `<details class="details">
5
+ `<details
6
+ class="details"
7
+ style=""
8
+ >
6
9
  <summary class="heading">
7
10
  <slot name="heading">
8
11
  </slot>
@@ -24,6 +27,7 @@ snapshots["detail standard open"] =
24
27
  `<details
25
28
  class="details"
26
29
  open=""
30
+ style=""
27
31
  >
28
32
  <summary class="heading">
29
33
  <slot name="heading">
@@ -69,7 +73,10 @@ snapshots["detail standard heading"] =
69
73
  /* end snapshot detail standard heading */
70
74
 
71
75
  snapshots["detail standard slotted content"] =
72
- `<details class="details">
76
+ `<details
77
+ class="details"
78
+ style=""
79
+ >
73
80
  <summary class="heading">
74
81
  <slot name="heading">
75
82
  </slot>
@@ -114,7 +121,10 @@ snapshots["detail standard toggle event"] =
114
121
  /* end snapshot detail standard toggle event */
115
122
 
116
123
  snapshots["detail standard toggle event true"] =
117
- `<details class="details">
124
+ `<details
125
+ class="details"
126
+ style=""
127
+ >
118
128
  <summary class="heading">
119
129
  <slot name="heading">
120
130
  </slot>
@@ -136,6 +146,7 @@ snapshots["detail standard toggle event false"] =
136
146
  `<details
137
147
  class="details toggle-start"
138
148
  open=""
149
+ style=""
139
150
  >
140
151
  <summary class="heading">
141
152
  <detail-icon
@@ -155,7 +166,10 @@ snapshots["detail standard toggle event false"] =
155
166
  /* end snapshot detail standard toggle event false */
156
167
 
157
168
  snapshots["detail standard icon"] =
158
- `<details class="details has-icon">
169
+ `<details
170
+ class="details has-icon"
171
+ style=""
172
+ >
159
173
  <summary class="heading">
160
174
  <detail-icon
161
175
  class="icon"
@@ -198,7 +212,10 @@ snapshots["detail standard icon end"] =
198
212
  /* end snapshot detail standard icon end */
199
213
 
200
214
  snapshots["detail standard toggle"] =
201
- `<details class="details toggle-start">
215
+ `<details
216
+ class="details toggle-start"
217
+ style=""
218
+ >
202
219
  <summary class="heading">
203
220
  <detail-icon
204
221
  class="toggle"
@@ -217,7 +234,10 @@ snapshots["detail standard toggle"] =
217
234
  /* end snapshot detail standard toggle */
218
235
 
219
236
  snapshots["detail standard toggle end"] =
220
- `<details class="details toggle-end">
237
+ `<details
238
+ class="details toggle-end"
239
+ style=""
240
+ >
221
241
  <summary class="heading">
222
242
  <slot name="heading">
223
243
  </slot>
@@ -181,20 +181,20 @@ testRunner('sourceFilesAnalyzer', async (t) => {
181
181
 
182
182
  const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
183
183
  const propertiesMap = {
184
- card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
185
- cta: ['href', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
186
- detail: ['icon', 'standardTemplate', 'open', 'type'],
184
+ card: ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
185
+ cta: ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
186
+ detail: ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
187
187
  form: ['standardTemplate', 'type'],
188
- icon: ['size', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
189
- image: ['src', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
190
- inputter: ['helper', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
191
- 'inputter-detail': ['icon', 'standardTemplate', 'open', 'type']
188
+ icon: ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
189
+ image: ['src', 'classes', 'inlineStyles', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
190
+ inputter: ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
191
+ 'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type']
192
192
  };
193
193
  t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
194
194
 
195
195
  components.forEach((component) => {
196
196
  t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
197
- (property) => property.name), propertiesMap[component]);
197
+ (property) => property.name), propertiesMap[component], component);
198
198
  });
199
199
  jsonResult.tags?.map((tag) => {
200
200
  t.true(tag.description !== undefined, `${tag.name} description is not present`);
@@ -225,13 +225,13 @@ testRunner('sourceFilesAnalyzer single file', async (t) => {
225
225
 
226
226
  const components = ['card'];
227
227
  const propertiesMap = {
228
- card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
228
+ card: ['classes', 'inlineStyles', 'standardTemplate', 'image', 'alt', 'background', 'type'],
229
229
  };
230
230
  t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
231
231
 
232
232
  components.forEach((component) => {
233
233
  t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
234
- (property) => property.name), propertiesMap[component]);
234
+ (property) => property.name), propertiesMap[component], component);
235
235
  });
236
236
  jsonResult.tags?.map((tag) => {
237
237
  t.true(tag.description !== undefined, `${tag.name} description is not present`);