@muonic/muon 0.0.2-beta.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.
Files changed (124) hide show
  1. package/.nycrc +17 -0
  2. package/.versionrc +3 -0
  3. package/CHANGELOG.md +389 -0
  4. package/components/card/index.js +1 -0
  5. package/components/card/src/card-component.js +43 -0
  6. package/components/card/src/card-styles.css +25 -0
  7. package/components/card/src/config-tokens.json +11 -0
  8. package/components/card/src/design-tokens.json +34 -0
  9. package/components/card/story.js +52 -0
  10. package/components/cta/index.js +1 -0
  11. package/components/cta/src/config-tokens.json +11 -0
  12. package/components/cta/src/cta-component.js +174 -0
  13. package/components/cta/src/cta-styles.css +105 -0
  14. package/components/cta/src/design-tokens.json +132 -0
  15. package/components/cta/story.js +99 -0
  16. package/components/detail/index.js +1 -0
  17. package/components/detail/src/config-tokens.json +11 -0
  18. package/components/detail/src/design-tokens.json +102 -0
  19. package/components/detail/src/detail-component.js +27 -0
  20. package/components/detail/src/detail-styles.css +83 -0
  21. package/components/detail/story.js +33 -0
  22. package/components/form/index.js +1 -0
  23. package/components/form/src/config-tokens.json +11 -0
  24. package/components/form/src/design-tokens.json +9 -0
  25. package/components/form/src/form-component.js +197 -0
  26. package/components/form/src/form-styles.css +10 -0
  27. package/components/form/story.js +71 -0
  28. package/components/icon/index.js +1 -0
  29. package/components/icon/src/config-tokens.json +31 -0
  30. package/components/icon/src/design-tokens.json +8 -0
  31. package/components/icon/src/icon-component.js +91 -0
  32. package/components/icon/src/icon-styles.css +26 -0
  33. package/components/icon/story.js +26 -0
  34. package/components/image/index.js +1 -0
  35. package/components/image/src/config-tokens.json +26 -0
  36. package/components/image/src/image-component.js +96 -0
  37. package/components/image/src/image-styles.css +71 -0
  38. package/components/image/story.js +31 -0
  39. package/components/inputter/index.js +1 -0
  40. package/components/inputter/src/config-tokens.json +14 -0
  41. package/components/inputter/src/design-tokens.json +308 -0
  42. package/components/inputter/src/inputter-component.js +227 -0
  43. package/components/inputter/src/inputter-styles-detail.css +59 -0
  44. package/components/inputter/src/inputter-styles.css +305 -0
  45. package/components/inputter/src/inputter-styles.slotted.css +64 -0
  46. package/components/inputter/story.js +243 -0
  47. package/css/accessibility.css +3 -0
  48. package/css/default.css +9 -0
  49. package/css/global.css +8 -0
  50. package/directives/image-loader-directive.js +116 -0
  51. package/directives/svg-loader-directive.js +94 -0
  52. package/index.js +52 -0
  53. package/mixins/card-mixin.js +27 -0
  54. package/mixins/detail-mixin.js +128 -0
  55. package/mixins/form-associate-mixin.js +36 -0
  56. package/mixins/form-element-mixin.js +378 -0
  57. package/mixins/image-holder-mixin.js +20 -0
  58. package/mixins/mask-mixin.js +159 -0
  59. package/mixins/validation-mixin.js +272 -0
  60. package/muon-element/index.js +97 -0
  61. package/package.json +72 -0
  62. package/rollup.config.mjs +30 -0
  63. package/scripts/build/storybook/index.mjs +11 -0
  64. package/scripts/build/storybook/run.mjs +47 -0
  65. package/scripts/rollup-plugins.mjs +116 -0
  66. package/scripts/serve/index.mjs +11 -0
  67. package/scripts/serve/run.mjs +27 -0
  68. package/scripts/style-dictionary.mjs +64 -0
  69. package/scripts/utils/config.mjs +30 -0
  70. package/scripts/utils/index.mjs +283 -0
  71. package/storybook/find-stories.js +36 -0
  72. package/storybook/server.config.mjs +19 -0
  73. package/storybook/stories.js +86 -0
  74. package/storybook/tokens/color.js +87 -0
  75. package/storybook/tokens/font.js +52 -0
  76. package/storybook/tokens/spacer.js +48 -0
  77. package/tests/README.md +3 -0
  78. package/tests/components/card/__snapshots__/card.test.snap.js +70 -0
  79. package/tests/components/card/card.test.js +81 -0
  80. package/tests/components/cta/__snapshots__/cta.test.snap.js +246 -0
  81. package/tests/components/cta/cta.test.js +212 -0
  82. package/tests/components/form/__snapshots__/form.test.snap.js +115 -0
  83. package/tests/components/form/form.test.js +336 -0
  84. package/tests/components/icon/__snapshots__/icon.test.snap.js +95 -0
  85. package/tests/components/icon/icon.test.js +197 -0
  86. package/tests/components/image/__snapshots__/image.test.snap.js +205 -0
  87. package/tests/components/image/image.test.js +314 -0
  88. package/tests/components/image/images/15.png +0 -0
  89. package/tests/components/image/images/150.png +0 -0
  90. package/tests/components/inputter/__snapshots__/inputter.test.snap.js +357 -0
  91. package/tests/components/inputter/inputter.test.js +427 -0
  92. package/tests/helpers/index.js +30 -0
  93. package/tests/mixins/__snapshots__/card.test.snap.js +35 -0
  94. package/tests/mixins/__snapshots__/detail.test.snap.js +237 -0
  95. package/tests/mixins/__snapshots__/form-element.test.snap.js +137 -0
  96. package/tests/mixins/__snapshots__/mask.test.snap.js +53 -0
  97. package/tests/mixins/__snapshots__/validation.test.snap.js +297 -0
  98. package/tests/mixins/card.test.js +63 -0
  99. package/tests/mixins/detail.test.js +223 -0
  100. package/tests/mixins/form-element.test.js +473 -0
  101. package/tests/mixins/mask.test.js +261 -0
  102. package/tests/mixins/muon-element.test.js +52 -0
  103. package/tests/mixins/validation.test.js +423 -0
  104. package/tests/runner/commands.mjs +19 -0
  105. package/tests/scripts/utils/card-component.js +26 -0
  106. package/tests/scripts/utils/muon.config.test.json +13 -0
  107. package/tests/scripts/utils/single.component.config.json +5 -0
  108. package/tests/scripts/utils/test-runner.mjs +1 -0
  109. package/tests/scripts/utils/utils-test.mjs +284 -0
  110. package/tests/utils/validation.functions.test.js +199 -0
  111. package/tokens/theme/color.json +482 -0
  112. package/tokens/theme/font.json +61 -0
  113. package/tokens/theme/size.json +27 -0
  114. package/tokens/theme/spacer.json +73 -0
  115. package/tokens/utils/formats/reference.js +17 -0
  116. package/tokens/utils/modular-scale.js +33 -0
  117. package/tokens/utils/templates/font-face.css.template +30 -0
  118. package/tokens/utils/transforms/color.js +27 -0
  119. package/tokens/utils/transforms/string.js +6 -0
  120. package/tokens/utils/validation.json +76 -0
  121. package/utils/scroll/index.js +31 -0
  122. package/utils/validation/index.js +205 -0
  123. package/web-test-runner.browserstack.config.mjs +123 -0
  124. package/web-test-runner.config.mjs +44 -0
@@ -0,0 +1,197 @@
1
+ /* eslint-disable no-undef */
2
+ import { expect, fixture, html, defineCE, unsafeStatic } from '@open-wc/testing';
3
+ import sinon from 'sinon';
4
+ import { defaultChecks } from '../../helpers';
5
+ import { Icon } from '@muonic/muon/components/icon';
6
+
7
+ const tagName = defineCE(Icon);
8
+ const tag = unsafeStatic(tagName);
9
+
10
+ const awaitLoading = () => {
11
+ return new Promise((resolve) => {
12
+ window.addEventListener('svg-loaded', resolve);
13
+ });
14
+ };
15
+
16
+ describe('icon', () => {
17
+
18
+ afterEach(() => {
19
+ sinon.restore();
20
+ });
21
+
22
+ it('implements standard self', async () => {
23
+ const el = await fixture(html`<${tag}></${tag}>`);
24
+
25
+ await awaitLoading(el);
26
+ await defaultChecks(el);
27
+
28
+ const shadowRoot = el.shadowRoot;
29
+ const icon = shadowRoot.querySelector('.icon');
30
+ const elementSVG = icon.querySelector('svg');
31
+
32
+ expect(elementSVG).to.not.be.null; // eslint-disable-line no-unused-expressions
33
+ expect(el.type).to.equal('standard', '`type` property has default value `standard`');
34
+ expect(el.name).to.equal('arrow-right', '`name` property has default value `arrow-right`');
35
+ expect(Array.from(icon.classList)).to.deep.equal(['icon', 'standard'], 'class list for parent div');
36
+ expect(icon.getAttribute('aria-hidden')).to.equal('true', '`aria-hidden` attribute added to not be seen by screen readers');
37
+ expect(icon.getAttribute('aria-label')).to.equal(null, '`aria-label` not added');
38
+ expect(icon.getAttribute('role')).to.equal(null, 'no `role` attribute added');
39
+ expect(getComputedStyle(elementSVG).fill).to.equal('rgb(0, 0, 0)', 'computed style value added for svg of fill'); // getComputedStyle will create the colour from currentColor
40
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal('100%', 'default value added for custom css variable');
41
+ expect(el.sizes).to.equal('100%', 'getter `sizes` returns default value');
42
+ });
43
+
44
+ it('implements icon size 16', async () => {
45
+ const size = 16;
46
+ const el = await fixture(html`<${tag} size="1"></${tag}>`);
47
+
48
+ await awaitLoading(el);
49
+
50
+ const shadowRoot = el.shadowRoot;
51
+ const icon = shadowRoot.querySelector('.icon');
52
+
53
+ expect(getComputedStyle(icon).width).to.equal(`${size}px`, 'computed size equal related size for width');
54
+ expect(getComputedStyle(icon).height).to.equal(`${size}px`, 'computed size equal related size for height');
55
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal(`${size}px`, 'size value added for custom css variable');
56
+ expect(el.sizes).to.equal(size, 'getter `sizes` returns size value');
57
+ });
58
+
59
+ it('implements icon size 32', async () => {
60
+ const size = 32;
61
+ const el = await fixture(html`<${tag} size="2"></${tag}>`);
62
+
63
+ await awaitLoading(el);
64
+
65
+ const shadowRoot = el.shadowRoot;
66
+ const icon = shadowRoot.querySelector('.icon');
67
+
68
+ expect(getComputedStyle(icon).width).to.equal(`${size}px`, 'computed size equal related size for width');
69
+ expect(getComputedStyle(icon).height).to.equal(`${size}px`, 'computed size equal related size for height');
70
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal(`${size}px`, 'size value added for custom css variable');
71
+ expect(el.sizes).to.equal(size, 'getter `sizes` returns size value');
72
+ });
73
+
74
+ it('implements icon size 48', async () => {
75
+ const size = 48;
76
+ const el = await fixture(html`<${tag} size="3"></${tag}>`);
77
+
78
+ await awaitLoading(el);
79
+
80
+ const shadowRoot = el.shadowRoot;
81
+ const icon = shadowRoot.querySelector('.icon');
82
+
83
+ expect(getComputedStyle(icon).width).to.equal(`${size}px`, 'computed size equal related size for width');
84
+ expect(getComputedStyle(icon).height).to.equal(`${size}px`, 'computed size equal related size for height');
85
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal(`${size}px`, 'size value added for custom css variable');
86
+ expect(el.sizes).to.equal(size, 'getter `sizes` returns size value');
87
+ });
88
+
89
+ it('implements icon size 64', async () => {
90
+ const size = 64;
91
+ const el = await fixture(html`<${tag} size="4"></${tag}>`);
92
+
93
+ await awaitLoading(el);
94
+
95
+ const shadowRoot = el.shadowRoot;
96
+ const icon = shadowRoot.querySelector('.icon');
97
+
98
+ expect(getComputedStyle(icon).width).to.equal(`${size}px`, 'computed size equal related size for width');
99
+ expect(getComputedStyle(icon).height).to.equal(`${size}px`, 'computed size equal related size for height');
100
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal(`${size}px`, 'size value added for custom css variable');
101
+ expect(el.sizes).to.equal(size, 'getter `sizes` returns size value');
102
+ });
103
+
104
+ it('implements icon size 72', async () => {
105
+ const size = 72;
106
+ const el = await fixture(html`<${tag} size="5"></${tag}>`);
107
+
108
+ await awaitLoading(el);
109
+
110
+ const shadowRoot = el.shadowRoot;
111
+ const icon = shadowRoot.querySelector('.icon');
112
+
113
+ expect(getComputedStyle(icon).width).to.equal(`${size}px`, 'computed size equal related size for width');
114
+ expect(getComputedStyle(icon).height).to.equal(`${size}px`, 'computed size equal related size for height');
115
+ expect(icon.style.getPropertyValue('--icon-size')).to.equal(`${size}px`, 'size value added for custom css variable');
116
+ expect(el.sizes).to.equal(size, 'getter `sizes` returns size value');
117
+ });
118
+
119
+ it('select icon name', async () => {
120
+ const el = await fixture(html`<${tag} name="arrow-left"></${tag}>`);
121
+
122
+ await awaitLoading(el);
123
+ await defaultChecks(el);
124
+
125
+ const shadowRoot = el.shadowRoot;
126
+ const icon = shadowRoot.querySelector('.icon');
127
+ const elementSVG = icon.querySelector('svg');
128
+
129
+ expect(elementSVG).to.not.be.null; // eslint-disable-line no-unused-expressions
130
+ expect(el.type).to.equal('standard', '`type` property has default value `standard`');
131
+ expect(el.name).to.equal('arrow-left', '`name` property has default value `arrow-right`');
132
+ expect(icon.getAttribute('aria-label')).to.equal(null, '`aria-label` not added');
133
+ expect(icon.getAttribute('role')).to.equal(null, 'no `role` attribute added');
134
+ });
135
+
136
+ it('fails gracefully when using non existent name', async () => {
137
+ const el = await fixture(html`<${tag} name="this-does-not-exist-as-an-icon-sad-face"></${tag}>`);
138
+
139
+ await awaitLoading(el);
140
+ await defaultChecks(el);
141
+
142
+ const shadowRoot = el.shadowRoot;
143
+ const icon = shadowRoot.querySelector('.icon');
144
+ const elementSVG = icon.querySelector('svg');
145
+
146
+ expect(elementSVG).to.be.null; // eslint-disable-line no-unused-expressions
147
+ expect(el.type).to.equal('standard', '`type` property has default value `standard`');
148
+ expect(el.name).to.equal('this-does-not-exist-as-an-icon-sad-face', '`name` property has attribute value');
149
+ });
150
+
151
+ it('fails gracefully when using no name', async () => {
152
+ const el = await fixture(html`<${tag} name=""></${tag}>`);
153
+
154
+ await defaultChecks(el);
155
+
156
+ expect(el.shadowRoot.querySelector('.icon')).to.equal(null); // eslint-disable-line no-unused-expressions
157
+
158
+ expect(el.type).to.equal('standard', '`type` property has default value `standard`');
159
+ expect(el.name).to.equal('', '`name` property has no value');
160
+ });
161
+
162
+ it('adds attributes for when describe used', async () => {
163
+ const el = await fixture(html`<${tag} describe="foobar"></${tag}>`);
164
+
165
+ await defaultChecks(el);
166
+
167
+ const shadowRoot = el.shadowRoot;
168
+ const icon = shadowRoot.querySelector('.icon');
169
+
170
+ expect(el.type).to.equal('standard', '`type` property has default value `standard`');
171
+ expect(icon.getAttribute('aria-hidden')).to.equal(null, 'element is not hidden');
172
+ expect(icon.getAttribute('aria-label')).to.equal('foobar', 'element has an aria label');
173
+ expect(icon.getAttribute('role')).to.equal('img', 'element is given a role of img');
174
+ });
175
+
176
+ it('no anonymous slot', async () => {
177
+ const el = await fixture(html`<${tag}>some additional content that will not be rendered</${tag}>`);
178
+
179
+ await awaitLoading(el);
180
+ await defaultChecks(el);
181
+
182
+ expect(el.innerText.trim()).to.equal('', 'has no light dom');
183
+ });
184
+
185
+ it('caches not available', async () => {
186
+ delete self.caches; // replicate caches API not being available
187
+
188
+ const consoleWarn = sinon.stub(console, 'info');
189
+ const el = await fixture(html`<${tag}></${tag}>`);
190
+
191
+ await awaitLoading(el);
192
+ await defaultChecks(el);
193
+
194
+ expect(consoleWarn.args[0]).to.deep.equal(['cache not available'], 'console info shows that cache is not available');
195
+ expect(consoleWarn.args.length).to.equal(2, 'info shows 2 messages');
196
+ });
197
+ });
@@ -0,0 +1,205 @@
1
+ /* @web/test-runner snapshot v1 */
2
+ export const snapshots = {};
3
+
4
+ snapshots["icon implements standard self"] =
5
+ `<div class="image">
6
+ </div>
7
+ `;
8
+ /* end snapshot icon implements standard self */
9
+
10
+ snapshots["image implements standard self"] =
11
+ `<div class="image">
12
+ </div>
13
+ `;
14
+ /* end snapshot image implements standard self */
15
+
16
+ snapshots["image implements src image"] =
17
+ `<div
18
+ class="image"
19
+ style="--image-ratio:16 / 9;"
20
+ >
21
+ <img
22
+ alt=""
23
+ class="blur-out image-lazy"
24
+ src="tests/components/image/images/150.png"
25
+ >
26
+ </div>
27
+ `;
28
+ /* end snapshot image implements src image */
29
+
30
+ snapshots["image implements ratio"] =
31
+ `<div
32
+ class="image"
33
+ style="--image-ratio:1 / 1;"
34
+ >
35
+ <img
36
+ alt=""
37
+ class="blur-out image-lazy"
38
+ src="tests/components/image/images/150.png"
39
+ >
40
+ </div>
41
+ `;
42
+ /* end snapshot image implements ratio */
43
+
44
+ snapshots["image implements background"] =
45
+ `<div
46
+ class="image is-background"
47
+ style="--image-ratio:16 / 9;--background-size:cover;"
48
+ >
49
+ <div
50
+ class="blur-out image-holder"
51
+ style="--background-image:url(&quot;tests/components/image/images/150.png&quot;);"
52
+ >
53
+ </div>
54
+ </div>
55
+ `;
56
+ /* end snapshot image implements background */
57
+
58
+ snapshots["image implements placeholder image"] =
59
+ `<div
60
+ class="image"
61
+ style="--image-ratio:16 / 9;"
62
+ >
63
+ <img
64
+ alt=""
65
+ class="blur image-lazy"
66
+ src="tests/components/image/images/15.png"
67
+ >
68
+ </div>
69
+ `;
70
+ /* end snapshot image implements placeholder image */
71
+
72
+ snapshots["image implements alt"] =
73
+ `<div
74
+ class="image"
75
+ style="--image-ratio:16 / 9;"
76
+ >
77
+ <img
78
+ alt="alternative text for the image"
79
+ class="blur-out image-lazy"
80
+ src="tests/components/image/images/150.png"
81
+ >
82
+ </div>
83
+ `;
84
+ /* end snapshot image implements alt */
85
+
86
+ snapshots["image fallsback on ratio if not correct"] =
87
+ `<div
88
+ class="image"
89
+ style="--image-ratio:16 / 9;"
90
+ >
91
+ <img
92
+ alt=""
93
+ class="blur-out image-lazy"
94
+ src="tests/components/image/images/150.png"
95
+ >
96
+ </div>
97
+ `;
98
+ /* end snapshot image fallsback on ratio if not correct */
99
+
100
+ snapshots["image fallsback on image padding if aspect-ratio not available"] =
101
+ `<div
102
+ class="image"
103
+ style="--image-padding:56.25%;"
104
+ >
105
+ <img
106
+ alt=""
107
+ class="blur-out image-lazy"
108
+ src="tests/components/image/images/150.png"
109
+ >
110
+ </div>
111
+ `;
112
+ /* end snapshot image fallsback on image padding if aspect-ratio not available */
113
+
114
+ snapshots["image image fails to loads"] =
115
+ `<div
116
+ class="image"
117
+ style="--image-padding:56.25%;"
118
+ >
119
+ </div>
120
+ `;
121
+ /* end snapshot image image fails to loads */
122
+
123
+ snapshots["image image fails to load"] =
124
+ `<div
125
+ class="image"
126
+ style="--image-ratio:16 / 9;"
127
+ >
128
+ </div>
129
+ `;
130
+ /* end snapshot image image fails to load */
131
+
132
+ snapshots["image image is eager"] =
133
+ `<div
134
+ class="image"
135
+ style="--image-ratio:16 / 9;"
136
+ >
137
+ <img
138
+ alt=""
139
+ class="blur-out image-lazy"
140
+ src="tests/components/image/images/150.png"
141
+ >
142
+ </div>
143
+ `;
144
+ /* end snapshot image image is eager */
145
+
146
+ snapshots["image image fails to load for background"] =
147
+ `<div
148
+ class="image"
149
+ style="--image-ratio:16 / 9;"
150
+ >
151
+ </div>
152
+ `;
153
+ /* end snapshot image image fails to load for background */
154
+
155
+ snapshots["image implements placeholder image for background"] =
156
+ `<div
157
+ class="image is-background"
158
+ style="--image-ratio:16 / 9;--background-size:cover;"
159
+ >
160
+ <div
161
+ class="blur image-holder"
162
+ style="--background-image:url(&quot;tests/components/image/images/15.png&quot;);"
163
+ >
164
+ </div>
165
+ </div>
166
+ `;
167
+ /* end snapshot image implements placeholder image for background */
168
+
169
+ snapshots["image implements placeholder image for chrome"] =
170
+ `<div
171
+ class="image"
172
+ style="--image-ratio:16 / 9;"
173
+ >
174
+ </div>
175
+ `;
176
+ /* end snapshot image implements placeholder image for chrome */
177
+
178
+ snapshots["image fallsback for ratios"] =
179
+ `<div
180
+ class="image"
181
+ style="--image-ratio:16 / 9;"
182
+ >
183
+ <img
184
+ alt=""
185
+ class="blur-out image-lazy"
186
+ src="https://via.placeholder.com/150"
187
+ >
188
+ </div>
189
+ `;
190
+ /* end snapshot image fallsback for ratios */
191
+
192
+ snapshots["image fallback for ratio"] =
193
+ `<div
194
+ class="image is-background"
195
+ style="--image-ratio:16 / 9;--background-size:cover;"
196
+ >
197
+ <div
198
+ class="blur-out image-holder"
199
+ style="--background-image:url(&quot;https://via.placeholder.com/150&quot;);"
200
+ >
201
+ </div>
202
+ </div>
203
+ `;
204
+ /* end snapshot image fallback for ratio */
205
+