@muonic/muon 0.0.2-beta.2 → 0.0.2-beta.20

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 (46) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/components/card/src/card-component.js +13 -2
  3. package/components/cta/src/cta-component.js +35 -16
  4. package/components/cta/src/cta-styles.css +2 -2
  5. package/components/cta/src/design-tokens.json +10 -0
  6. package/components/icon/src/icon-component.js +17 -12
  7. package/components/image/src/image-component.js +17 -14
  8. package/components/inputter/src/design-tokens.json +217 -35
  9. package/components/inputter/src/inputter-component.js +24 -19
  10. package/components/inputter/src/inputter-extends.css +170 -0
  11. package/components/inputter/src/inputter-styles-detail.css +13 -10
  12. package/components/inputter/src/inputter-styles.css +50 -108
  13. package/components/inputter/src/inputter-styles.slotted.css +154 -2
  14. package/css/default.css +1 -0
  15. package/css/global.css +28 -8
  16. package/css/reset.css +12 -0
  17. package/directives/svg-loader-directive.js +7 -5
  18. package/directives/tokens.json +9 -0
  19. package/mixins/detail-mixin.js +15 -8
  20. package/muon-element/index.js +49 -39
  21. package/package.json +36 -34
  22. package/rollup.config.mjs +4 -1
  23. package/scripts/rollup-plugins.mjs +64 -32
  24. package/scripts/style-dictionary.mjs +1 -1
  25. package/scripts/utils/index.mjs +74 -23
  26. package/storybook/server.config.mjs +3 -0
  27. package/storybook/stories.js +3 -4
  28. package/tests/components/cta/__snapshots__/cta.test.snap.js +0 -5
  29. package/tests/components/cta/cta.test.js +0 -5
  30. package/tests/components/icon/__snapshots__/icon.test.snap.js +6 -12
  31. package/tests/components/icon/icon.test.js +1 -1
  32. package/tests/components/image/__snapshots__/image.test.snap.js +13 -52
  33. package/tests/components/inputter/__snapshots__/inputter.test.snap.js +56 -192
  34. package/tests/helpers/index.js +3 -1
  35. package/tests/mixins/muon-element.test.js +1 -1
  36. package/tests/scripts/utils/cta-component.js +17 -0
  37. package/tests/scripts/utils/font.css.template +4 -0
  38. package/tests/scripts/utils/muon.config.prefix.no-included.json +12 -0
  39. package/tests/scripts/utils/muon.config.prefix.override.json +13 -0
  40. package/tests/scripts/utils/muon.config.style-dictionary.test.json +14 -0
  41. package/tests/scripts/utils/muon.config.test.json +2 -2
  42. package/tests/scripts/utils/style-dictionary.config.mjs +32 -0
  43. package/tests/scripts/utils/utils-test.mjs +115 -14
  44. package/tokens/theme/font.json +4 -0
  45. package/tokens/utils/formats/reference.js +17 -13
  46. package/tokens/utils/transforms/color.js +8 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,116 @@
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.20](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.19...v0.0.2-beta.20) (2023-06-06)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * pull back width and font default styles ([9afa041](https://github.com/centrica-engineering/muon/commit/9afa0419ebb9475d31506da795e12a8a123291a1))
11
+
12
+ ### [0.0.2-beta.19](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.18...v0.0.2-beta.19) (2023-06-05)
13
+
14
+
15
+ ### Features
16
+
17
+ * nested import ([a5cb81c](https://github.com/centrica-engineering/muon/commit/a5cb81ca28b041af98728bce26726d3a214c4c28))
18
+
19
+ ### [0.0.2-beta.18](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.17...v0.0.2-beta.18) (2023-06-05)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * finding all component files ([1216b2f](https://github.com/centrica-engineering/muon/commit/1216b2f45347220bd19c521c3dd5c196dba38200))
25
+
26
+ ### [0.0.2-beta.17](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.16...v0.0.2-beta.17) (2023-05-31)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * switch to light-dom ([5e1c67b](https://github.com/centrica-engineering/muon/commit/5e1c67bbb9be239a0717103685be0a2e24e51990))
32
+
33
+ ### [0.0.2-beta.16](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.15...v0.0.2-beta.16) (2023-05-31)
34
+
35
+ ### [0.0.2-beta.15](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.14...v0.0.2-beta.15) (2023-05-24)
36
+
37
+ ### [0.0.2-beta.14](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.13...v0.0.2-beta.14) (2023-05-23)
38
+
39
+
40
+ ### Features
41
+
42
+ * include lineLength token ([f5d00f9](https://github.com/centrica-engineering/muon/commit/f5d00f94078e7f49d055c9b42da041fa95c788ee))
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * commands ([351c59e](https://github.com/centrica-engineering/muon/commit/351c59e3e98d1aa2181ae3a6e498ee6fcb3ea891))
48
+ * default ([c766154](https://github.com/centrica-engineering/muon/commit/c766154159d7c4c8fcca59ed2d096bdbcf5d94c2))
49
+ * snapshots ([444b5ba](https://github.com/centrica-engineering/muon/commit/444b5bae280c962909088d2abc24b10b18170193))
50
+
51
+ ### [0.0.2-beta.13](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.12...v0.0.2-beta.13) (2023-05-15)
52
+
53
+ ### [0.0.2-beta.12](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.11...v0.0.2-beta.12) (2023-05-09)
54
+
55
+ ### [0.0.2-beta.11](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.10...v0.0.2-beta.11) (2023-05-05)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * revert dev-storybook ([1b7d07b](https://github.com/centrica-engineering/muon/commit/1b7d07b97456efcbb774ea15da3ae7e3dac52aa2))
61
+
62
+ ### [0.0.2-beta.10](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.9...v0.0.2-beta.10) (2023-05-04)
63
+
64
+
65
+ ### Bug Fixes
66
+
67
+ * move adding lightdom on perform ([41e7843](https://github.com/centrica-engineering/muon/commit/41e7843f57342e84d719a86a34de0ce1862081dc))
68
+
69
+ ### [0.0.2-beta.9](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.8...v0.0.2-beta.9) (2023-04-21)
70
+
71
+ ### [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)
72
+
73
+
74
+ ### Bug Fixes
75
+
76
+ * check if parentElement exists ([2055f37](https://github.com/centrica-engineering/muon/commit/2055f377a03194ebd28fa74f38597dca8e612507))
77
+ * loading and disabled cta ([0569563](https://github.com/centrica-engineering/muon/commit/056956309c202557ac708e17ad4ed5a5760c3887))
78
+ * url state ([023fb86](https://github.com/centrica-engineering/muon/commit/023fb86886cf9d0dbe432fbae1b97e3cb220d5d8))
79
+
80
+ ### [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)
81
+
82
+ ### [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)
83
+
84
+
85
+ ### Features
86
+
87
+ * postcss extend ([7608e26](https://github.com/centrica-engineering/muon/commit/7608e26e1f1876abacbca562fb6724bebc0cbf50))
88
+
89
+ ### [0.0.2-beta.5](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.4...v0.0.2-beta.5) (2023-02-27)
90
+
91
+
92
+ ### Features
93
+
94
+ * global styles ([6705c22](https://github.com/centrica-engineering/muon/commit/6705c224f7664e1ab6ad9d7261921474de1bf0fc))
95
+
96
+ ### [0.0.2-beta.4](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.3...v0.0.2-beta.4) (2023-02-23)
97
+
98
+
99
+ ### Features
100
+
101
+ * config extend style dictionary ([70bbdc7](https://github.com/centrica-engineering/muon/commit/70bbdc7d7cae3e103da8420d1699c6143d833c07))
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * enable style dictionary extension ([d718dd9](https://github.com/centrica-engineering/muon/commit/d718dd93676976d0b4fcb25acb7572b15c5d05c5))
107
+
108
+ ### [0.0.2-beta.3](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.2...v0.0.2-beta.3) (2023-02-21)
109
+
110
+
111
+ ### Features
112
+
113
+ * getters for style and class ([e486ea2](https://github.com/centrica-engineering/muon/commit/e486ea2d25c5a6eb0ce5acb1701cc33e1443bc56))
114
+
5
115
  ### [0.0.2-beta.2](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.1...v0.0.2-beta.2) (2023-02-16)
6
116
 
7
117
 
@@ -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';
@@ -9,6 +9,7 @@ import styles from './card-styles.css';
9
9
  *
10
10
  * @element card
11
11
  */
12
+
12
13
  export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonElement))) {
13
14
 
14
15
  static get scopedElements() {
@@ -17,6 +18,16 @@ export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonEle
17
18
  };
18
19
  }
19
20
 
21
+ get classes() {
22
+ return {
23
+ card: true
24
+ };
25
+ }
26
+
27
+ get inlineStyles() {
28
+ return {};
29
+ }
30
+
20
31
  get _addImage() {
21
32
  return this.image ? html`
22
33
  <div class="media">
@@ -26,7 +37,7 @@ export class Card extends ScopedElementsMixin(ImageHolderMixin(CardMixin(MuonEle
26
37
 
27
38
  get standardTemplate() {
28
39
  return html`
29
- <div class="card">
40
+ <div class="${classMap(this.classes)}" style="${styleMap(this.inlineStyles)}">
30
41
  ${this._addImage}
31
42
  <div class="body">
32
43
  ${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 } 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
  *
@@ -84,7 +100,7 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
84
100
  const isInLink = parentName === 'A';
85
101
  const isInBtn = parentName === 'BUTTON';
86
102
  const isInNativeForm = parentName === 'FORM';
87
- const isDisabled = parentElement.getAttribute('disabled') || this.disabled;
103
+ const isDisabled = parentElement?.getAttribute('disabled') || this.disabled;
88
104
  let element = this.href?.length > 0 ? 'a' : 'div';
89
105
 
90
106
  if (
@@ -93,23 +109,35 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
93
109
  !isInLink &&
94
110
  !isInBtn &&
95
111
  !isDisabled &&
112
+ !this.loading &&
96
113
  !this._isButton
97
114
  ) {
98
115
  if (!this.getAttribute('role')) {
99
116
  this.setAttribute('role', 'button');
100
117
  }
101
118
 
102
- if (!this.getAttribute('tabindex')) {
103
- this.setAttribute('tabindex', '0');
104
- }
119
+ this.setAttribute('tabindex', '0');
105
120
  }
106
121
 
107
- if (isDisabled) {
122
+ if (isDisabled || this.loading) {
108
123
  if (!this.getAttribute('aria-disabled')) {
109
124
  this.setAttribute('aria-disabled', 'true');
110
125
  }
126
+
127
+ this.setAttribute('tabindex', '-1');
111
128
  } else {
112
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
+ }
113
141
  }
114
142
 
115
143
  if (isInNativeForm || this._isButton) {
@@ -121,20 +149,11 @@ export class Cta extends ScopedElementsMixin(MuonElement) {
121
149
  this.removeAttribute('tabindex');
122
150
  }
123
151
 
124
- // eslint-disable-next-line no-nested-ternary
125
- 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
-
133
152
  // eslint-disable-next-line no-nested-ternary
134
153
  const elementTag = element === 'button' ? literal`button` : element === 'a' ? literal`a` : literal`div`;
135
154
 
136
155
  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)}>
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)}>
138
157
  ${content}
139
158
  </${elementTag}>
140
159
  `;
@@ -82,8 +82,8 @@
82
82
  }
83
83
 
84
84
  & .label-holder {
85
- min-inline-size: 10em;
86
- max-inline-size: 32em;
85
+ min-inline-size: $CTA_LABEL_MIN_WIDTH;
86
+ max-inline-size: $CTA_LABEL_MAX_WIDTH;
87
87
  }
88
88
 
89
89
  & .icon {
@@ -72,6 +72,16 @@
72
72
  "value": "{ theme.size.md.value }"
73
73
  }
74
74
  },
75
+ "label": {
76
+ "minWidth": {
77
+ "description": "The minimum width of the label.",
78
+ "value": "15ch"
79
+ },
80
+ "maxWidth": {
81
+ "description": "The maximum width of the label.",
82
+ "value": "{ theme.font.lineLength.value }"
83
+ }
84
+ },
75
85
  "font": {
76
86
  "family": {
77
87
  "description": "Font family which defaults to sans-serif.",
@@ -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
- url: { type: String, state: true }
27
+ _url: { type: String, state: true }
28
28
  };
29
29
  }
30
30
 
@@ -39,10 +39,23 @@ 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.url = ICON_CONFIG_URL;
42
+ this._url = ICON_CONFIG_URL;
43
43
  this.describe = '';
44
44
  }
45
45
 
46
+ get classes() {
47
+ return {
48
+ icon: true,
49
+ [this.name]: 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,18 +78,10 @@ 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)}>
79
- ${svgLoader({ name: this.name, category: this.category, path: this.url })}
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._url })}
80
85
  </div>
81
86
  `;
82
87
  }
@@ -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
  `;