@statistikzh/leu 0.3.0 → 0.4.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 (153) hide show
  1. package/.github/workflows/deploy-github-pages.yaml +33 -0
  2. package/.storybook/main.js +27 -1
  3. package/.storybook/manager-head.html +1 -0
  4. package/.storybook/manager.js +9 -0
  5. package/.storybook/preview-head.html +1 -1
  6. package/.storybook/preview.js +59 -5
  7. package/.storybook/static/logo.svg +19 -0
  8. package/.storybook/theme.js +7 -0
  9. package/CHANGELOG.md +30 -0
  10. package/README.md +1 -1
  11. package/dist/Button.js +15 -18
  12. package/dist/ButtonGroup.js +5 -7
  13. package/dist/Checkbox.js +101 -84
  14. package/dist/CheckboxGroup.js +41 -37
  15. package/dist/{Chip-5f70d04f.js → Chip-dac7337d.js} +5 -1
  16. package/dist/ChipGroup.js +2 -5
  17. package/dist/ChipLink.js +4 -7
  18. package/dist/ChipRemovable.js +4 -7
  19. package/dist/ChipSelectable.js +4 -7
  20. package/dist/Dropdown.js +55 -26
  21. package/dist/Input.js +29 -28
  22. package/dist/Menu.js +2 -5
  23. package/dist/MenuItem.js +30 -15
  24. package/dist/Pagination.js +54 -54
  25. package/dist/Radio.js +7 -6
  26. package/dist/RadioGroup.js +41 -39
  27. package/dist/Select.js +55 -43
  28. package/dist/Table.js +137 -120
  29. package/dist/{defineElement-ba770aed.js → _rollupPluginBabelHelpers-20f659f4.js} +1 -15
  30. package/dist/defineElement-47d4f665.js +15 -0
  31. package/dist/index.js +29 -19
  32. package/dist/leu-button-group.js +7 -3
  33. package/dist/leu-button.js +6 -3
  34. package/dist/leu-checkbox-group.js +6 -3
  35. package/dist/leu-checkbox.js +6 -3
  36. package/dist/leu-chip-group.js +6 -3
  37. package/dist/leu-chip-link.js +7 -4
  38. package/dist/leu-chip-removable.js +7 -4
  39. package/dist/leu-chip-selectable.js +7 -4
  40. package/dist/leu-dropdown.js +13 -3
  41. package/dist/leu-input.js +7 -3
  42. package/dist/leu-menu-item.js +8 -3
  43. package/dist/leu-menu.js +6 -3
  44. package/dist/leu-pagination.js +8 -3
  45. package/dist/leu-popup-4bf6f1f4.js +216 -0
  46. package/dist/leu-radio-group.js +6 -3
  47. package/dist/leu-radio.js +6 -3
  48. package/dist/leu-select.js +14 -3
  49. package/dist/leu-table.js +9 -3
  50. package/package.json +24 -12
  51. package/scripts/generate-component/templates/[Name].js +0 -5
  52. package/scripts/generate-component/templates/[name].css +1 -1
  53. package/scripts/generate-component/templates/[namespace]-[name].js +5 -2
  54. package/src/components/accordion/Accordion.js +0 -6
  55. package/src/components/accordion/leu-accordion.js +5 -2
  56. package/src/components/accordion/stories/accordion.stories.js +7 -4
  57. package/src/components/accordion/test/accordion.test.js +92 -2
  58. package/src/components/breadcrumb/Breadcrumb.js +310 -0
  59. package/src/components/breadcrumb/breadcrumb.css +114 -0
  60. package/src/components/breadcrumb/leu-breadcrumb.js +6 -0
  61. package/src/components/breadcrumb/stories/breadcrumb.stories.js +73 -0
  62. package/src/components/breadcrumb/test/breadcrumb.test.js +141 -0
  63. package/src/components/button/Button.js +10 -15
  64. package/src/components/button/button.css +3 -3
  65. package/src/components/button/leu-button.js +5 -2
  66. package/src/components/button/stories/button.stories.js +58 -37
  67. package/src/components/button/test/button.test.js +112 -2
  68. package/src/components/button-group/ButtonGroup.js +1 -7
  69. package/src/components/button-group/leu-button-group.js +5 -2
  70. package/src/components/button-group/stories/button-group.stories.js +6 -0
  71. package/src/components/button-group/test/button-group.test.js +79 -3
  72. package/src/components/checkbox/Checkbox.js +6 -85
  73. package/src/components/checkbox/CheckboxGroup.js +8 -38
  74. package/src/components/checkbox/checkbox-group.css +29 -0
  75. package/src/components/checkbox/checkbox.css +76 -0
  76. package/src/components/checkbox/leu-checkbox-group.js +5 -2
  77. package/src/components/checkbox/leu-checkbox.js +5 -2
  78. package/src/components/checkbox/stories/checkbox-group.stories.js +44 -21
  79. package/src/components/checkbox/stories/checkbox.stories.js +7 -1
  80. package/src/components/checkbox/test/checkbox-group.test.js +124 -0
  81. package/src/components/checkbox/test/checkbox.test.js +72 -59
  82. package/src/components/chip/Chip.js +1 -0
  83. package/src/components/chip/ChipGroup.js +0 -5
  84. package/src/components/chip/ChipLink.js +1 -6
  85. package/src/components/chip/ChipRemovable.js +1 -6
  86. package/src/components/chip/ChipSelectable.js +1 -6
  87. package/src/components/chip/exports.js +4 -10
  88. package/src/components/chip/leu-chip-group.js +5 -2
  89. package/src/components/chip/leu-chip-link.js +5 -2
  90. package/src/components/chip/leu-chip-removable.js +5 -2
  91. package/src/components/chip/leu-chip-selectable.js +5 -2
  92. package/src/components/chip/stories/chip-group.stories.js +18 -6
  93. package/src/components/chip/stories/chip-link.stories.js +16 -4
  94. package/src/components/chip/stories/chip-removable.stories.js +15 -4
  95. package/src/components/chip/stories/chip-selectable.stories.js +13 -3
  96. package/src/components/chip/test/chip-group.test.js +124 -0
  97. package/src/components/chip/test/chip-link.test.js +58 -0
  98. package/src/components/chip/test/chip-removable.test.js +79 -0
  99. package/src/components/chip/test/chip-selectable.test.js +95 -0
  100. package/src/components/chip/test/chip.test.js +1 -1
  101. package/src/components/dropdown/Dropdown.js +52 -24
  102. package/src/components/dropdown/dropdown.css +1 -2
  103. package/src/components/dropdown/leu-dropdown.js +5 -2
  104. package/src/components/dropdown/stories/dropdown.stories.js +11 -5
  105. package/src/components/dropdown/test/dropdown.test.js +6 -6
  106. package/src/components/icon/icon.js +1 -1
  107. package/src/components/icon/test/icon.test.js +66 -0
  108. package/src/components/input/Input.js +18 -24
  109. package/src/components/input/input.css +9 -6
  110. package/src/components/input/leu-input.js +5 -2
  111. package/src/components/input/stories/input.stories.js +8 -2
  112. package/src/components/input/test/input.test.js +431 -4
  113. package/src/components/menu/Menu.js +0 -5
  114. package/src/components/menu/MenuItem.js +20 -13
  115. package/src/components/menu/leu-menu-item.js +5 -2
  116. package/src/components/menu/leu-menu.js +5 -2
  117. package/src/components/menu/menu-item.css +5 -2
  118. package/src/components/menu/stories/menu-item.stories.js +13 -4
  119. package/src/components/menu/stories/menu.stories.js +11 -5
  120. package/src/components/menu/test/menu-item.test.js +180 -0
  121. package/src/components/menu/test/menu.test.js +10 -2
  122. package/src/components/pagination/Pagination.js +53 -65
  123. package/src/components/pagination/leu-pagination.js +5 -2
  124. package/src/components/pagination/stories/pagination.stories.js +17 -9
  125. package/src/components/pagination/test/pagination.test.js +191 -5
  126. package/src/components/popup/Popup.js +200 -0
  127. package/src/components/popup/leu-popup.js +6 -0
  128. package/src/components/popup/popup.css +27 -0
  129. package/src/components/popup/stories/popup.stories.js +58 -0
  130. package/src/components/popup/test/popup.test.js +29 -0
  131. package/src/components/radio/Radio.js +2 -6
  132. package/src/components/radio/RadioGroup.js +6 -38
  133. package/src/components/radio/leu-radio-group.js +5 -2
  134. package/src/components/radio/leu-radio.js +5 -2
  135. package/src/components/radio/radio-group.css +29 -0
  136. package/src/components/radio/stories/radio-group.stories.js +38 -19
  137. package/src/components/radio/stories/radio.stories.js +7 -1
  138. package/src/components/radio/test/radio-group.test.js +86 -0
  139. package/src/components/radio/test/radio.test.js +108 -17
  140. package/src/components/select/Select.js +34 -31
  141. package/src/components/select/leu-select.js +5 -2
  142. package/src/components/select/select.css +13 -13
  143. package/src/components/select/stories/select.stories.js +15 -168
  144. package/src/components/select/test/fixtures.js +162 -0
  145. package/src/components/select/test/select.test.js +236 -12
  146. package/src/components/table/Table.js +43 -118
  147. package/src/components/table/leu-table.js +5 -2
  148. package/src/components/table/stories/table.stories.js +20 -10
  149. package/src/components/table/table.css +99 -0
  150. package/src/components/table/test/table.test.js +1 -1
  151. package/src/lib/utils.js +17 -0
  152. package/{web-dev-server-storybook.config.mjs → web-dev-server.config.mjs} +1 -2
  153. package/web-test-runner.config.mjs +15 -2
@@ -0,0 +1,216 @@
1
+ import { d as defineElement } from './defineElement-47d4f665.js';
2
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
3
+ import { css, LitElement, html } from 'lit';
4
+ import { autoUpdate, size, flip, shift, computePosition } from '@floating-ui/dom';
5
+
6
+ var css_248z = css`:host,
7
+ :host * {
8
+ box-sizing: border-box;
9
+ }
10
+
11
+ :host {
12
+ --popup-font-regular: var(--leu-font-regular);
13
+ --popup-font-black: var(--leu-font-black);
14
+
15
+ font-family: var(--leu-font-regular);
16
+
17
+ font-family: var(--popup-font-regular);
18
+ }
19
+
20
+ .popup {
21
+ display: none;
22
+
23
+ max-width: none;
24
+
25
+ max-width: var(--auto-size-available-width, none);
26
+ max-height: none;
27
+ max-height: var(--auto-size-available-height, none);
28
+
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ }
33
+
34
+ /* TODO: Should visibility be a matter of the popup component? */
35
+
36
+ :host([active]) .popup {
37
+ display: block;
38
+ }
39
+ `;
40
+
41
+ /**
42
+ * @tagname leu-popup
43
+ */
44
+ class LeuPopup extends LitElement {
45
+ constructor() {
46
+ super();
47
+ this.anchorEl = null;
48
+ this.cleanup = undefined;
49
+ this.flip = false;
50
+ this.shift = false;
51
+ }
52
+ disconnectedCallback() {
53
+ super.disconnectedCallback();
54
+ this.stop();
55
+ }
56
+ updated(changedProperties) {
57
+ if (changedProperties.has("active")) {
58
+ if (this.active) {
59
+ this.start();
60
+ } else {
61
+ this.stop();
62
+ }
63
+ }
64
+ if (changedProperties.has("anchor")) {
65
+ this.handleAnchorChange();
66
+ }
67
+ if (this.active) {
68
+ this.reposition();
69
+ }
70
+ }
71
+ get popupEl() {
72
+ return this.renderRoot?.querySelector(".popup") ?? null;
73
+ }
74
+ start() {
75
+ if (!this.anchorEl || !this.active) return;
76
+ this.cleanup = autoUpdate(this.anchorEl, this.popupEl, () => {
77
+ this.reposition();
78
+ });
79
+ }
80
+ stop() {
81
+ this.cleanup?.();
82
+ this.style.removeProperty("--auto-size-available-width");
83
+ this.style.removeProperty("--auto-size-available-height");
84
+ }
85
+ reposition() {
86
+ if (!this.anchorEl || !this.popupEl || !this.active) return;
87
+ const middleware = [];
88
+ if (this.matchSize) {
89
+ middleware.push(size({
90
+ apply: ({
91
+ rects
92
+ }) => {
93
+ const matchWidth = this.matchSize === "width" || this.matchSize === "both";
94
+ const matchHeight = this.matchSize === "height" || this.matchSize === "both";
95
+ this.popupEl.style.width = matchWidth ? `${rects.reference.width}px` : "";
96
+ this.popupEl.style.height = matchHeight ? `${rects.reference.height}px` : "";
97
+ }
98
+ }));
99
+ } else {
100
+ // Cleanup styles if we're not matching width/height
101
+ this.popupEl.style.width = "";
102
+ this.popupEl.style.height = "";
103
+ }
104
+ if (this.flip) {
105
+ middleware.push(flip());
106
+ }
107
+ if (this.shift) {
108
+ middleware.push(shift({
109
+ padding: this.shiftPadding
110
+ }));
111
+ }
112
+ if (this.autoSize) {
113
+ middleware.push(size({
114
+ padding: this.autoSizePadding,
115
+ apply: ({
116
+ availableWidth,
117
+ availableHeight
118
+ }) => {
119
+ const setMaxWidth = this.autoSize === "width" || this.autoSize === "both";
120
+ const setMaxHeight = this.autoSize === "height" || this.autoSize === "both";
121
+ if (setMaxHeight) {
122
+ this.style.setProperty("--auto-size-available-height", `${availableHeight}px`);
123
+ } else {
124
+ this.style.removeProperty("--auto-size-available-height");
125
+ }
126
+ if (setMaxWidth) {
127
+ this.style.setProperty("--auto-size-available-width", `${availableWidth}px`);
128
+ } else {
129
+ this.style.removeProperty("--auto-size-available-width");
130
+ }
131
+ }
132
+ }));
133
+ } else {
134
+ // Cleanup styles if we're not auto-sizing
135
+ this.style.removeProperty("--auto-size-available-width");
136
+ this.style.removeProperty("--auto-size-available-height");
137
+ }
138
+ computePosition(this.anchorEl, this.popupEl, {
139
+ placement: this.placement,
140
+ middleware
141
+ }).then(({
142
+ x,
143
+ y
144
+ }) => {
145
+ Object.assign(this.popupEl.style, {
146
+ left: `${x}px`,
147
+ top: `${y}px`
148
+ });
149
+ });
150
+ }
151
+ handleAnchorChange() {
152
+ if (this.anchor && typeof this.anchor === "string") {
153
+ const root = this.getRootNode();
154
+ this.anchorEl = root.getElementById(this.anchor);
155
+ } else if (this.anchor instanceof HTMLElement) {
156
+ this.anchorEl = this.anchor;
157
+ } else {
158
+ this.anchorEl = this.querySelector("[slot=anchor]");
159
+ }
160
+ if (this.anchorEl instanceof HTMLSlotElement) {
161
+ [this.anchorEl] = this.anchorEl.assignedElements({
162
+ flatten: true
163
+ });
164
+ }
165
+ if (this.anchorEl) {
166
+ this.start();
167
+ }
168
+ }
169
+ render() {
170
+ return html`
171
+ <slot name="anchor" @slotchange=${this.handleAnchorChange}></slot>
172
+ <div class="popup">
173
+ <slot> </slot>
174
+ </div>
175
+ `;
176
+ }
177
+ }
178
+ _defineProperty(LeuPopup, "styles", css_248z);
179
+ _defineProperty(LeuPopup, "shadowRootOptions", {
180
+ ...LitElement.shadowRootOptions,
181
+ delegatesFocus: true
182
+ });
183
+ _defineProperty(LeuPopup, "properties", {
184
+ anchor: {},
185
+ active: {
186
+ type: Boolean
187
+ },
188
+ /**
189
+ * @type {"top"|"top-start"|"top-end"|"bottom"|"bottom-start"|"bottom-end"|"left"|"left-start"|"left-end"|"right"|"right-start"|"right-end"}
190
+ */
191
+ placement: {
192
+ type: String
193
+ },
194
+ flip: {
195
+ type: Boolean
196
+ },
197
+ shift: {
198
+ type: Boolean
199
+ },
200
+ shiftPadding: {
201
+ type: Number
202
+ },
203
+ /** @type {"width" | "height" | "both"} */
204
+ matchSize: {
205
+ type: String
206
+ },
207
+ /** @type {"width" | "height" | "both"} */
208
+ autoSize: {
209
+ type: String
210
+ },
211
+ autoSizePadding: {
212
+ type: Number
213
+ }
214
+ });
215
+
216
+ defineElement("popup", LeuPopup);
@@ -1,6 +1,9 @@
1
- import { defineRadioGroupElements } from './RadioGroup.js';
2
- import './defineElement-ba770aed.js';
1
+ import { d as defineElement } from './defineElement-47d4f665.js';
2
+ import { LeuRadioGroup } from './RadioGroup.js';
3
+ import './_rollupPluginBabelHelpers-20f659f4.js';
3
4
  import 'lit';
4
5
  import 'lit/directives/class-map.js';
5
6
 
6
- defineRadioGroupElements();
7
+ defineElement("radio-group", LeuRadioGroup);
8
+
9
+ export { LeuRadioGroup };
package/dist/leu-radio.js CHANGED
@@ -1,5 +1,8 @@
1
- import { defineRadioElements } from './Radio.js';
2
- import './defineElement-ba770aed.js';
1
+ import { d as defineElement } from './defineElement-47d4f665.js';
2
+ import { LeuRadio } from './Radio.js';
3
+ import './_rollupPluginBabelHelpers-20f659f4.js';
3
4
  import 'lit';
4
5
 
5
- defineRadioElements();
6
+ defineElement("radio", LeuRadio);
7
+
8
+ export { LeuRadio };
@@ -1,14 +1,25 @@
1
- import { defineSelectElements } from './Select.js';
2
- import './defineElement-ba770aed.js';
1
+ import { d as defineElement } from './defineElement-47d4f665.js';
2
+ import { LeuSelect } from './Select.js';
3
+ import './_rollupPluginBabelHelpers-20f659f4.js';
3
4
  import 'lit';
4
5
  import 'lit/directives/class-map.js';
5
6
  import 'lit/directives/map.js';
6
7
  import 'lit/directives/if-defined.js';
7
8
  import 'lit/directives/ref.js';
8
9
  import './icon-03e86700.js';
10
+ import './leu-button.js';
9
11
  import './Button.js';
12
+ import './leu-menu.js';
10
13
  import './Menu.js';
14
+ import './leu-menu-item.js';
11
15
  import './MenuItem.js';
16
+ import 'lit/static-html.js';
17
+ import './leu-input.js';
12
18
  import './Input.js';
19
+ import 'lit/directives/live.js';
20
+ import './leu-popup-4bf6f1f4.js';
21
+ import '@floating-ui/dom';
13
22
 
14
- defineSelectElements();
23
+ defineElement("select", LeuSelect);
24
+
25
+ export { LeuSelect };
package/dist/leu-table.js CHANGED
@@ -1,11 +1,17 @@
1
- import { defineTableElements } from './Table.js';
2
- import './defineElement-ba770aed.js';
1
+ import { d as defineElement } from './defineElement-47d4f665.js';
2
+ import { LeuTable } from './Table.js';
3
+ import './_rollupPluginBabelHelpers-20f659f4.js';
3
4
  import 'lit';
4
5
  import 'lit/directives/class-map.js';
5
6
  import 'lit/directives/style-map.js';
6
7
  import 'lit/directives/ref.js';
7
8
  import './icon-03e86700.js';
9
+ import './leu-pagination.js';
8
10
  import './Pagination.js';
11
+ import 'lit/directives/live.js';
12
+ import './leu-button.js';
9
13
  import './Button.js';
10
14
 
11
- defineTableElements();
15
+ defineElement("table", LeuTable);
16
+
17
+ export { LeuTable };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "UI component library of the canton of zurich",
4
4
  "license": "MIT",
5
5
  "author": "statistikzh",
6
- "version": "0.3.0",
6
+ "version": "0.4.0",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.js",
@@ -16,7 +16,8 @@
16
16
  "analyze": "cem analyze --litelement --globs \"src/**/*.js\"",
17
17
  "build": "rimraf dist && npm run build:js && npm run build:css",
18
18
  "build:js": "rollup -c rollup.config.js",
19
- "build:css": "postcss src/styles/theme.css -o dist/theme.css",
19
+ "build:css": "postcss src/styles/theme.css -o dist/theme.css && cp dist/theme.css .storybook/static/",
20
+ "watch:css": "nodemon --watch 'src/styles/*' -e css --exec npm run build:css",
20
21
  "lint": "npm run lint:eslint && npm run lint:prettier",
21
22
  "lint:eslint": "eslint --ext .js,.mjs,.html . --ignore-path .gitignore ",
22
23
  "lint:prettier": "prettier \"**/*.{js,mjs,md,html,json}\" --check --ignore-path .gitignore",
@@ -27,10 +28,12 @@
27
28
  "test": "web-test-runner --coverage",
28
29
  "test:watch": "web-test-runner --watch",
29
30
  "prepare": "husky install",
30
- "storybook": "npm run analyze && web-dev-server --config web-dev-server-storybook.config.mjs --watch",
31
- "build-storybook": "storybook build"
31
+ "storybook": "npm run storybook:start",
32
+ "storybook:start": "npm run analyze && npm run watch:css & storybook dev -p 8080 --no-open",
33
+ "storybook:build": "npm run analyze && npm run build:css && storybook build --output-dir docs"
32
34
  },
33
35
  "dependencies": {
36
+ "@floating-ui/dom": "^1.6.3",
34
37
  "lit": "^3.0.2"
35
38
  },
36
39
  "devDependencies": {
@@ -39,25 +42,32 @@
39
42
  "@commitlint/config-conventional": "^17.7.0",
40
43
  "@custom-elements-manifest/analyzer": "^0.4.17",
41
44
  "@open-wc/eslint-config": "^9.2.1",
42
- "@open-wc/testing": "^3.1.6",
45
+ "@open-wc/testing": "^4.0.0",
43
46
  "@rollup/plugin-babel": "^6.0.4",
47
+ "@rollup/plugin-commonjs": "^25.0.7",
44
48
  "@rollup/plugin-json": "^6.0.0",
49
+ "@storybook/addon-designs": "^7.0.9",
50
+ "@storybook/addon-essentials": "^7.6.10",
51
+ "@storybook/addon-links": "^7.6.10",
52
+ "@storybook/blocks": "^7.6.10",
53
+ "@storybook/web-components": "^7.6.10",
45
54
  "@web/dev-server": "^0.1.34",
46
55
  "@web/dev-server-rollup": "^0.5.2",
47
- "@web/dev-server-storybook": "^1.0.6",
48
- "@web/storybook-builder": "^0.1.0",
56
+ "@web/storybook-builder": "^0.1.2",
49
57
  "@web/storybook-framework-web-components": "^0.1.1",
50
- "@web/test-runner": "^0.14.0",
51
- "@web/test-runner-commands": "^0.8.0",
52
- "@web/test-runner-playwright": "^0.10.1",
58
+ "@web/test-runner": "^0.18.0",
59
+ "@web/test-runner-commands": "^0.9.0",
60
+ "@web/test-runner-playwright": "^0.11.0",
61
+ "@whitespace/storybook-addon-html": "^5.1.6",
53
62
  "arg": "^5.0.2",
54
63
  "es-dev-server": "^2.1.0",
55
- "esbuild": "^0.19.4",
64
+ "esbuild": "^0.20.0",
56
65
  "eslint": "^8.31.0",
57
66
  "eslint-config-prettier": "^8.3.0",
58
67
  "eslint-plugin-storybook": "^0.6.14",
59
68
  "husky": "^8.0.0",
60
69
  "lint-staged": "^10.5.4",
70
+ "nodemon": "^3.0.2",
61
71
  "postcss": "^8.4.31",
62
72
  "postcss-cli": "^10.1.0",
63
73
  "postcss-import": "^15.1.0",
@@ -66,12 +76,14 @@
66
76
  "prettier": "^2.4.1",
67
77
  "react": "^18.2.0",
68
78
  "react-dom": "^18.2.0",
79
+ "react-syntax-highlighter": "^15.5.0",
69
80
  "rimraf": "^5.0.5",
70
81
  "rollup": "^3.29.4",
71
82
  "rollup-plugin-esbuild": "^6.0.2",
72
83
  "rollup-plugin-postcss": "^4.0.2",
73
84
  "rollup-plugin-postcss-lit": "^2.1.0",
74
- "storybook": "^7.4.5",
85
+ "sinon": "^17.0.1",
86
+ "storybook": "^7.6.10",
75
87
  "stylelint": "^15.10.3",
76
88
  "stylelint-config-standard": "^34.0.0"
77
89
  },
@@ -1,5 +1,4 @@
1
1
  import { html, LitElement } from "lit"
2
- import { defineElement } from "../../lib/defineElement.js"
3
2
  import styles from "./[name].css"
4
3
 
5
4
  /**
@@ -27,7 +26,3 @@ export class Leu[Name] extends LitElement {
27
26
  `
28
27
  }
29
28
  }
30
-
31
- export function define[Name]Elements() {
32
- defineElement("[name]", [Namespace][Name])
33
- }
@@ -7,5 +7,5 @@
7
7
  --[name]-font-regular: var(--leu-font-regular);
8
8
  --[name]-font-black: var(--leu-font-black);
9
9
 
10
- font-family: var(--chip-font-regular);
10
+ font-family: var(--[name]-font-regular);
11
11
  }
@@ -1,3 +1,6 @@
1
- import { define[Name]Elements } from "./[Name].js"
1
+ import { defineElement } from "../../lib/defineElement.js"
2
+ import { [Namespace][Name] } from "./[Name].js"
2
3
 
3
- define[Name]Elements()
4
+ export { [Namespace][Name] }
5
+
6
+ defineElement("[name]", [Namespace][Name])
@@ -1,7 +1,6 @@
1
1
  import { LitElement, nothing } from "lit"
2
2
  import { html, unsafeStatic } from "lit/static-html.js"
3
3
 
4
- import { defineElement } from "../../lib/defineElement.js"
5
4
  import styles from "./accordion.css"
6
5
 
7
6
  /**
@@ -35,7 +34,6 @@ export class LeuAccordion extends LitElement {
35
34
  this.headingLevel = 2
36
35
  this.open = false
37
36
  this.label = ""
38
- this.labelPrefix = ""
39
37
  }
40
38
 
41
39
  /**
@@ -96,7 +94,3 @@ export class LeuAccordion extends LitElement {
96
94
  }
97
95
  /* eslint-enable lit/binding-positions, lit/no-invalid-html */
98
96
  }
99
-
100
- export function defineAccordionElements() {
101
- defineElement("accordion", LeuAccordion)
102
- }
@@ -1,3 +1,6 @@
1
- import { defineAccordionElements } from "./Accordion.js"
1
+ import { defineElement } from "../../lib/defineElement.js"
2
+ import { LeuAccordion } from "./Accordion.js"
2
3
 
3
- defineAccordionElements()
4
+ export { LeuAccordion }
5
+
6
+ defineElement("accordion", LeuAccordion)
@@ -8,10 +8,7 @@ export default {
8
8
  component: "leu-accordion",
9
9
  argTypes: {
10
10
  headingLevel: {
11
- control: {
12
- type: "select",
13
- options: [0, 1, 2, 3, 4, 5, 6],
14
- },
11
+ options: [0, 1, 2, 3, 4, 5, 6],
15
12
  },
16
13
  content: {
17
14
  control: {
@@ -19,6 +16,12 @@ export default {
19
16
  },
20
17
  },
21
18
  },
19
+ parameters: {
20
+ design: {
21
+ type: "figma",
22
+ url: "https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=17341-82464&mode=design&t=lzVrtq8lxYVJU5TB-11",
23
+ },
24
+ },
22
25
  }
23
26
 
24
27
  function Template(args) {
@@ -4,12 +4,14 @@ import { fixture, expect } from "@open-wc/testing"
4
4
  import "../leu-accordion.js"
5
5
 
6
6
  async function defaultFixture() {
7
- return fixture(html` <leu-accordion /> `)
7
+ return fixture(
8
+ html` <leu-accordion label="Titel des Akkordeons"></leu-accordion> `
9
+ )
8
10
  }
9
11
 
10
12
  describe("LeuAccordion", () => {
11
13
  it("is a defined element", async () => {
12
- const el = await customElements.get("leu-accordion")
14
+ const el = customElements.get("leu-accordion")
13
15
 
14
16
  await expect(el).not.to.be.undefined
15
17
  })
@@ -19,4 +21,92 @@ describe("LeuAccordion", () => {
19
21
 
20
22
  await expect(el).shadowDom.to.be.accessible()
21
23
  })
24
+
25
+ it("renders the correct heading tag", async () => {
26
+ const el = await defaultFixture()
27
+
28
+ await expect(el._getHeadingTag()).to.equal("h2")
29
+
30
+ el.headingLevel = 1
31
+ await expect(el._getHeadingTag()).to.equal("h1")
32
+
33
+ el.headingLevel = 2
34
+ await expect(el._getHeadingTag()).to.equal("h2")
35
+
36
+ el.headingLevel = 3
37
+ await expect(el._getHeadingTag()).to.equal("h3")
38
+
39
+ el.headingLevel = 4
40
+ await expect(el._getHeadingTag()).to.equal("h4")
41
+
42
+ el.headingLevel = 5
43
+ await expect(el._getHeadingTag()).to.equal("h5")
44
+
45
+ el.headingLevel = 6
46
+ await expect(el._getHeadingTag()).to.equal("h6")
47
+ })
48
+
49
+ it("doesn't render an invalid heading tag", async () => {
50
+ const el = await defaultFixture()
51
+
52
+ el.headingLevel = 10
53
+ expect(el._getHeadingTag()).to.equal("h2")
54
+
55
+ el.headingLevel = -1
56
+ expect(el._getHeadingTag()).to.equal("h2")
57
+
58
+ el.headingLevel = 0
59
+ expect(el._getHeadingTag()).to.equal("h2")
60
+
61
+ el.headingLevel = "h3"
62
+ expect(el._getHeadingTag()).to.equal("h2")
63
+ })
64
+
65
+ it("toggles the open state", async () => {
66
+ const el = await fixture(
67
+ html`<leu-accordion label="Titel des Akkordeons"
68
+ ><div slot="content">Das ist der Inhalt</div></leu-accordion
69
+ >`
70
+ )
71
+
72
+ const button = el.shadowRoot.querySelector("button")
73
+
74
+ expect(el.open).to.be.false
75
+
76
+ button.click()
77
+ expect(el.open).to.be.true
78
+
79
+ button.click()
80
+ expect(el.open).to.be.false
81
+ })
82
+
83
+ it("doesn't show the content when it is closed", async () => {
84
+ const el = await fixture(
85
+ html`<leu-accordion label="Titel des Akkordeons"
86
+ ><div slot="content">Das ist der Inhalt</div></leu-accordion
87
+ >`
88
+ )
89
+
90
+ const button = el.shadowRoot.querySelector("button")
91
+ const content = el.shadowRoot.querySelector(".content")
92
+
93
+ expect(content).not.to.be.visible
94
+
95
+ button.click()
96
+ expect(content).to.be.visible
97
+ })
98
+
99
+ it("shows the label prefix before the label", async () => {
100
+ const el = await fixture(
101
+ html`<leu-accordion
102
+ label-prefix="01"
103
+ label="Titel des Akkordeons"
104
+ ></leu-accordion>`
105
+ )
106
+
107
+ const button = el.shadowRoot.querySelector("button")
108
+
109
+ expect(button).to.contain.text("01")
110
+ expect(button).to.contain.text("Titel des Akkordeons")
111
+ })
22
112
  })