@statistikzh/leu 0.4.0 → 0.5.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 (216) hide show
  1. package/.storybook/preview.js +1 -2
  2. package/CHANGELOG.md +24 -0
  3. package/custom-elements-manifest.config.js +46 -0
  4. package/dist/Accordion.d.ts +31 -0
  5. package/dist/Accordion.d.ts.map +1 -0
  6. package/dist/Accordion.js +257 -0
  7. package/dist/Breadcrumb.d.ts +69 -0
  8. package/dist/Breadcrumb.d.ts.map +1 -0
  9. package/dist/Breadcrumb.js +392 -0
  10. package/dist/Button-da11d064.d.ts +84 -0
  11. package/dist/Button-da11d064.d.ts.map +1 -0
  12. package/dist/Button-da11d064.js +542 -0
  13. package/dist/Button.d.ts +2 -0
  14. package/dist/Button.d.ts.map +1 -0
  15. package/dist/Button.js +6 -420
  16. package/dist/ButtonGroup.d.ts +24 -0
  17. package/dist/ButtonGroup.d.ts.map +1 -0
  18. package/dist/ButtonGroup.js +70 -39
  19. package/dist/Checkbox.d.ts +13 -0
  20. package/dist/Checkbox.d.ts.map +1 -0
  21. package/dist/Checkbox.js +2 -2
  22. package/dist/CheckboxGroup.d.ts +13 -0
  23. package/dist/CheckboxGroup.d.ts.map +1 -0
  24. package/dist/CheckboxGroup.js +3 -3
  25. package/dist/Chip.d.ts +5 -0
  26. package/dist/Chip.d.ts.map +1 -0
  27. package/dist/{Chip-dac7337d.js → Chip.js} +16 -5
  28. package/dist/ChipGroup.d.ts +28 -0
  29. package/dist/ChipGroup.d.ts.map +1 -0
  30. package/dist/ChipGroup.js +62 -5
  31. package/dist/ChipLink.d.ts +15 -0
  32. package/dist/ChipLink.d.ts.map +1 -0
  33. package/dist/ChipLink.js +1 -1
  34. package/dist/ChipRemovable.d.ts +13 -0
  35. package/dist/ChipRemovable.d.ts.map +1 -0
  36. package/dist/ChipRemovable.js +2 -2
  37. package/dist/ChipSelectable.d.ts +22 -0
  38. package/dist/ChipSelectable.d.ts.map +1 -0
  39. package/dist/ChipSelectable.js +5 -5
  40. package/dist/Dropdown.d.ts +15 -0
  41. package/dist/Dropdown.d.ts.map +1 -0
  42. package/dist/Dropdown.js +25 -7
  43. package/dist/Input.d.ts +154 -0
  44. package/dist/Input.d.ts.map +1 -0
  45. package/dist/Input.js +13 -7
  46. package/dist/Menu.d.ts +8 -0
  47. package/dist/Menu.d.ts.map +1 -0
  48. package/dist/MenuItem.d.ts +21 -0
  49. package/dist/MenuItem.d.ts.map +1 -0
  50. package/dist/MenuItem.js +3 -3
  51. package/dist/Pagination.d.ts +27 -0
  52. package/dist/Pagination.d.ts.map +1 -0
  53. package/dist/Pagination.js +93 -61
  54. package/dist/Popup.d.ts +18 -0
  55. package/dist/Popup.d.ts.map +1 -0
  56. package/dist/{leu-popup-4bf6f1f4.js → Popup.js} +4 -5
  57. package/dist/Radio.d.ts +12 -0
  58. package/dist/Radio.d.ts.map +1 -0
  59. package/dist/Radio.js +2 -2
  60. package/dist/RadioGroup.d.ts +20 -0
  61. package/dist/RadioGroup.d.ts.map +1 -0
  62. package/dist/RadioGroup.js +3 -3
  63. package/dist/ScrollTop.d.ts +19 -0
  64. package/dist/ScrollTop.d.ts.map +1 -0
  65. package/dist/ScrollTop.js +122 -0
  66. package/dist/Select.d.ts +98 -0
  67. package/dist/Select.d.ts.map +1 -0
  68. package/dist/Select.js +27 -82
  69. package/dist/Table.d.ts +48 -0
  70. package/dist/Table.d.ts.map +1 -0
  71. package/dist/Table.js +7 -4
  72. package/dist/VisuallyHidden.d.ts +8 -0
  73. package/dist/VisuallyHidden.d.ts.map +1 -0
  74. package/dist/VisuallyHidden.js +28 -0
  75. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts +3 -0
  76. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts.map +1 -0
  77. package/dist/defineElement-40372b4b.d.ts +9 -0
  78. package/dist/defineElement-40372b4b.d.ts.map +1 -0
  79. package/dist/{defineElement-47d4f665.js → defineElement-40372b4b.js} +1 -1
  80. package/dist/icon-03e86700.d.ts +11 -0
  81. package/dist/icon-03e86700.d.ts.map +1 -0
  82. package/dist/index.js.d.ts +21 -0
  83. package/dist/index.js.d.ts.map +1 -0
  84. package/dist/{index.js → index.js.js} +14 -8
  85. package/dist/leu-accordion.d.ts +3 -0
  86. package/dist/leu-accordion.d.ts.map +1 -0
  87. package/dist/leu-accordion.js +9 -0
  88. package/dist/leu-breadcrumb.d.ts +3 -0
  89. package/dist/leu-breadcrumb.d.ts.map +1 -0
  90. package/dist/leu-breadcrumb.js +23 -0
  91. package/dist/leu-button-group.d.ts +3 -0
  92. package/dist/leu-button-group.d.ts.map +1 -0
  93. package/dist/leu-button-group.js +1 -5
  94. package/dist/leu-button.d.ts +3 -0
  95. package/dist/leu-button.d.ts.map +1 -0
  96. package/dist/leu-button.js +3 -2
  97. package/dist/leu-checkbox-group.d.ts +3 -0
  98. package/dist/leu-checkbox-group.d.ts.map +1 -0
  99. package/dist/leu-checkbox-group.js +1 -1
  100. package/dist/leu-checkbox.d.ts +3 -0
  101. package/dist/leu-checkbox.d.ts.map +1 -0
  102. package/dist/leu-checkbox.js +1 -1
  103. package/dist/leu-chip-group.d.ts +3 -0
  104. package/dist/leu-chip-group.d.ts.map +1 -0
  105. package/dist/leu-chip-group.js +2 -1
  106. package/dist/leu-chip-link.d.ts +3 -0
  107. package/dist/leu-chip-link.d.ts.map +1 -0
  108. package/dist/leu-chip-link.js +2 -2
  109. package/dist/leu-chip-removable.d.ts +3 -0
  110. package/dist/leu-chip-removable.d.ts.map +1 -0
  111. package/dist/leu-chip-removable.js +2 -2
  112. package/dist/leu-chip-selectable.d.ts +3 -0
  113. package/dist/leu-chip-selectable.d.ts.map +1 -0
  114. package/dist/leu-chip-selectable.js +2 -2
  115. package/dist/leu-dropdown.d.ts +3 -0
  116. package/dist/leu-dropdown.d.ts.map +1 -0
  117. package/dist/leu-dropdown.js +5 -4
  118. package/dist/leu-input.d.ts +3 -0
  119. package/dist/leu-input.d.ts.map +1 -0
  120. package/dist/leu-input.js +1 -1
  121. package/dist/leu-menu-item.d.ts +3 -0
  122. package/dist/leu-menu-item.d.ts.map +1 -0
  123. package/dist/leu-menu-item.js +1 -1
  124. package/dist/leu-menu.d.ts +3 -0
  125. package/dist/leu-menu.d.ts.map +1 -0
  126. package/dist/leu-menu.js +1 -1
  127. package/dist/leu-pagination.d.ts +3 -0
  128. package/dist/leu-pagination.d.ts.map +1 -0
  129. package/dist/leu-pagination.js +5 -2
  130. package/dist/leu-popup.d.ts +3 -0
  131. package/dist/leu-popup.d.ts.map +1 -0
  132. package/dist/leu-popup.js +9 -0
  133. package/dist/leu-radio-group.d.ts +3 -0
  134. package/dist/leu-radio-group.d.ts.map +1 -0
  135. package/dist/leu-radio-group.js +1 -1
  136. package/dist/leu-radio.d.ts +3 -0
  137. package/dist/leu-radio.d.ts.map +1 -0
  138. package/dist/leu-radio.js +1 -1
  139. package/dist/leu-scroll-top.d.ts +3 -0
  140. package/dist/leu-scroll-top.d.ts.map +1 -0
  141. package/dist/leu-scroll-top.js +14 -0
  142. package/dist/leu-select.d.ts +3 -0
  143. package/dist/leu-select.d.ts.map +1 -0
  144. package/dist/leu-select.js +4 -3
  145. package/dist/leu-table.d.ts +3 -0
  146. package/dist/leu-table.d.ts.map +1 -0
  147. package/dist/leu-table.js +5 -2
  148. package/dist/leu-visually-hidden.d.ts +3 -0
  149. package/dist/leu-visually-hidden.d.ts.map +1 -0
  150. package/dist/leu-visually-hidden.js +8 -0
  151. package/dist/theme.css +386 -2
  152. package/dist/utils-65469421.d.ts +16 -0
  153. package/dist/utils-65469421.d.ts.map +1 -0
  154. package/dist/utils-65469421.js +35 -0
  155. package/index.js +3 -0
  156. package/package.json +30 -12
  157. package/postcss.config.cjs +2 -0
  158. package/rollup.config.js +21 -40
  159. package/scripts/generate-component/templates/[name].css +2 -2
  160. package/scripts/postcss-leu-font-styles.cjs +160 -0
  161. package/src/components/accordion/accordion.css +2 -2
  162. package/src/components/accordion/stories/accordion.stories.js +2 -1
  163. package/src/components/accordion/test/accordion.test.js +4 -2
  164. package/src/components/breadcrumb/Breadcrumb.js +2 -1
  165. package/src/components/breadcrumb/breadcrumb.css +2 -13
  166. package/src/components/button/Button.js +69 -8
  167. package/src/components/button/button.css +10 -2
  168. package/src/components/button/stories/button.stories.js +43 -90
  169. package/src/components/button/test/button.test.js +90 -19
  170. package/src/components/button-group/ButtonGroup.js +76 -34
  171. package/src/components/button-group/stories/button-group.stories.js +13 -6
  172. package/src/components/button-group/test/button-group.test.js +38 -31
  173. package/src/components/checkbox/checkbox-group.css +2 -2
  174. package/src/components/checkbox/checkbox.css +1 -1
  175. package/src/components/chip/ChipGroup.js +42 -2
  176. package/src/components/chip/ChipRemovable.js +1 -1
  177. package/src/components/chip/ChipSelectable.js +4 -4
  178. package/src/components/chip/chip-group.css +12 -2
  179. package/src/components/chip/chip.css +14 -3
  180. package/src/components/chip/stories/chip-group.stories.js +100 -46
  181. package/src/components/chip/test/chip-removable.test.js +3 -3
  182. package/src/components/dropdown/Dropdown.js +23 -3
  183. package/src/components/input/Input.js +7 -4
  184. package/src/components/input/input.css +2 -2
  185. package/src/components/input/stories/input.stories.js +13 -0
  186. package/src/components/input/test/input.test.js +1 -0
  187. package/src/components/menu/menu-item.css +3 -3
  188. package/src/components/pagination/Pagination.js +91 -60
  189. package/src/components/pagination/pagination.css +6 -1
  190. package/src/components/pagination/stories/pagination.stories.js +15 -2
  191. package/src/components/pagination/test/pagination.test.js +15 -15
  192. package/src/components/popup/popup.css +2 -2
  193. package/src/components/popup/stories/popup.stories.js +1 -1
  194. package/src/components/radio/radio-group.css +2 -2
  195. package/src/components/radio/radio.css +1 -1
  196. package/src/components/scroll-top/ScrollTop.js +87 -0
  197. package/src/components/scroll-top/leu-scroll-top.js +6 -0
  198. package/src/components/scroll-top/scroll-top.css +34 -0
  199. package/src/components/scroll-top/stories/scroll-top.stories.js +217 -0
  200. package/src/components/scroll-top/test/scroll-top.test.js +22 -0
  201. package/src/components/select/Select.js +24 -6
  202. package/src/components/select/select.css +2 -2
  203. package/src/components/table/table.css +2 -2
  204. package/src/components/visually-hidden/VisuallyHidden.js +13 -0
  205. package/src/components/visually-hidden/leu-visually-hidden.js +6 -0
  206. package/src/components/visually-hidden/stories/visually-hidden.stories.js +22 -0
  207. package/src/components/visually-hidden/test/visually-hidden.test.js +36 -0
  208. package/src/components/visually-hidden/visually-hidden.css +10 -0
  209. package/src/lib/defineElement.js +1 -1
  210. package/src/lib/hasSlotController.js +5 -3
  211. package/src/lib/utils.js +21 -3
  212. package/src/styles/custom-properties.css +6 -2
  213. package/src/styles/font-definitions.json +202 -0
  214. package/stylelint.config.mjs +2 -0
  215. package/tsconfig.build.json +21 -0
  216. package/tsconfig.json +16 -0
@@ -4,7 +4,7 @@ import { fixture, expect, elementUpdated, oneEvent } from "@open-wc/testing"
4
4
  import "../leu-button.js"
5
5
 
6
6
  async function defaultFixture() {
7
- return fixture(html` <leu-button label="button"></leu-button>`)
7
+ return fixture(html` <leu-button>button</leu-button>`)
8
8
  }
9
9
 
10
10
  describe("LeuButton", () => {
@@ -20,22 +20,41 @@ describe("LeuButton", () => {
20
20
  await expect(el).shadowDom.to.be.accessible()
21
21
  })
22
22
 
23
+ it("passes the a11y audit with no visible text", async () => {
24
+ const el = await fixture(
25
+ html` <leu-button icon="download" label="sichern"></leu-button>`
26
+ )
27
+
28
+ await expect(el).shadowDom.to.be.accessible()
29
+ })
30
+
23
31
  it("renders the label", async () => {
24
- const el = await fixture(html` <leu-button label="Sichern"></leu-button>`)
32
+ const el = await fixture(html` <leu-button>Sichern</leu-button>`)
33
+
34
+ expect(el).to.have.trimmed.text("Sichern")
35
+ })
36
+
37
+ it("sets the aria-label attribute", async () => {
38
+ const el = await fixture(
39
+ html` <leu-button
40
+ icon="download"
41
+ label="Dokument herunterladen"
42
+ ></leu-button>`
43
+ )
25
44
  const button = el.shadowRoot.querySelector("button")
26
45
 
27
- expect(button).to.have.trimmed.text("Sichern")
46
+ expect(button).to.have.attribute("aria-label", "Dokument herunterladen")
28
47
  })
29
48
 
30
49
  it("renders the icon at the correct position", async () => {
31
50
  const el = await fixture(
32
- html` <leu-button icon="addNew" label="Sichern"></leu-button>`
51
+ html` <leu-button icon="addNew">Sichern</leu-button>`
33
52
  )
34
53
 
35
54
  const button = el.shadowRoot.querySelector("button")
36
55
 
37
56
  expect(button).dom.to.equal(
38
- "<button><div><svg><path /></svg></div>Sichern</div>",
57
+ "<button><div><svg><path /></svg></div><slot></slot></div>",
39
58
  { ignoreAttributes: ["d", "class", "type"] }
40
59
  )
41
60
 
@@ -44,20 +63,20 @@ describe("LeuButton", () => {
44
63
  await elementUpdated(el)
45
64
 
46
65
  expect(button).dom.to.equal(
47
- "<button>Sichern<div><svg><path /></svg></div></div>",
66
+ "<button><slot></slot><div><svg><path /></svg></div></div>",
48
67
  { ignoreAttributes: ["d", "class", "type"] }
49
68
  )
50
69
  })
51
70
 
52
71
  it("renders the icon at the correct size", async () => {
53
72
  const el = await fixture(
54
- html` <leu-button icon="addNew" label="Sichern"></leu-button>`
73
+ html` <leu-button icon="addNew">Sichern</leu-button>`
55
74
  )
56
75
 
57
76
  const button = el.shadowRoot.querySelector("button")
58
77
 
59
78
  expect(button).dom.to.equal(
60
- "<button><div><svg width='24' height='24'><path /></svg></div>Sichern</div>",
79
+ "<button><div><svg width='24' height='24'><path /></svg></div><slot></slot></div>",
61
80
  { ignoreAttributes: ["d", "class", "type"] }
62
81
  )
63
82
 
@@ -66,25 +85,22 @@ describe("LeuButton", () => {
66
85
  await elementUpdated(el)
67
86
 
68
87
  expect(button).dom.to.equal(
69
- "<button><div><svg width='16' height='16'><path /></svg></div>Sichern</div>",
88
+ "<button><div><svg width='16' height='16'><path /></svg></div><slot></slot></div>",
70
89
  { ignoreAttributes: ["d", "class", "type"] }
71
90
  )
72
91
  })
73
92
 
74
93
  it("renders the expanded icon only when the variant is ghost", async () => {
75
94
  const el = await fixture(
76
- html` <leu-button
77
- icon="addNew"
78
- label="Sichern"
79
- variant="ghost"
80
- expanded="open"
81
- ></leu-button>`
95
+ html` <leu-button icon="addNew" variant="ghost" expanded="true"
96
+ >Sichern</leu-button
97
+ >`
82
98
  )
83
99
 
84
100
  const button = el.shadowRoot.querySelector("button")
85
101
 
86
102
  expect(button).dom.to.equal(
87
- "<button class='ghost normal'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div>Sichern<div class='icon-wrapper icon-wrapper--expanded'><svg width='24' height='24'><path /></svg></div></div>",
103
+ "<button class='ghost regular'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div><slot></slot><div class='icon-wrapper icon-wrapper--expanded'><svg width='24' height='24'><path /></svg></div></div>",
88
104
  { ignoreAttributes: ["d", "type", "width", "height"] }
89
105
  )
90
106
 
@@ -93,7 +109,7 @@ describe("LeuButton", () => {
93
109
  await elementUpdated(el)
94
110
 
95
111
  expect(button).dom.to.equal(
96
- "<button class='primary normal'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div>Sichern</div>",
112
+ "<button class='primary regular'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div><slot></slot></div>",
97
113
  { ignoreAttributes: ["d", "type"] }
98
114
  )
99
115
  })
@@ -104,7 +120,7 @@ describe("LeuButton", () => {
104
120
  icon="addNew"
105
121
  label="Sichern"
106
122
  variant="ghost"
107
- expanded="open"
123
+ expanded="true"
108
124
  disabled
109
125
  ></leu-button>`
110
126
  )
@@ -119,8 +135,63 @@ describe("LeuButton", () => {
119
135
  expect(button).to.not.have.attribute("disabled")
120
136
  })
121
137
 
138
+ it("reflects the role attribute", async () => {
139
+ const el = await fixture(
140
+ html` <leu-button
141
+ icon="addNew"
142
+ variant="ghost"
143
+ componentRole="menuitemradio"
144
+ >Sichern</leu-button
145
+ >`
146
+ )
147
+
148
+ const button = el.shadowRoot.querySelector("button")
149
+
150
+ expect(button).to.have.attribute("role", "menuitemradio")
151
+ })
152
+
153
+ it("sets the either checked or selected attribute depending on the role", async () => {
154
+ const el = await fixture(
155
+ html` <leu-button
156
+ icon="addNew"
157
+ variant="ghost"
158
+ componentRole="menuitemradio"
159
+ active
160
+ >Sichern</leu-button
161
+ >`
162
+ )
163
+
164
+ const button = el.shadowRoot.querySelector("button")
165
+
166
+ expect(button).to.have.attribute("aria-checked", "true")
167
+ expect(button).to.not.have.attribute("aria-selected")
168
+
169
+ el.componentRole = "tab"
170
+
171
+ await elementUpdated(el)
172
+
173
+ expect(button).to.have.attribute("aria-selected", "true")
174
+ expect(button).to.not.have.attribute("aria-checked")
175
+
176
+ el.componentRole = "checkbox"
177
+ el.active = false
178
+
179
+ await elementUpdated(el)
180
+
181
+ expect(button).to.have.attribute("aria-checked", "false")
182
+ expect(button).to.not.have.attribute("aria-selected")
183
+
184
+ el.componentRole = undefined
185
+ el.active = true
186
+
187
+ await elementUpdated(el)
188
+
189
+ expect(button).to.not.have.attribute("aria-checked")
190
+ expect(button).to.not.have.attribute("aria-selected")
191
+ })
192
+
122
193
  it("dispatches the click event", async () => {
123
- const el = await fixture(html` <leu-button label="Sichern"></leu-button>`)
194
+ const el = await fixture(html` <leu-button>Sichern</leu-button>`)
124
195
  const button = el.shadowRoot.querySelector("button")
125
196
 
126
197
  setTimeout(() => button.click())
@@ -1,56 +1,98 @@
1
1
  import { html, LitElement } from "lit"
2
+ // @ts-ignore
2
3
  import styles from "./button-group.css"
3
- import "../button/leu-button.js"
4
4
 
5
5
  /**
6
6
  * @tagname leu-button-group
7
+ * @slot - Slot for the buttons
8
+ * @prop {string} value - The value of the currenty selected (active) button
9
+ * @fires input - When the value of the group changes by clicking a button
7
10
  */
8
11
  export class LeuButtonGroup extends LitElement {
9
12
  static styles = styles
10
13
 
11
- static properties = {
12
- items: { type: Array, reflect: true },
13
- value: { type: String, reflect: true },
14
- }
15
-
16
14
  constructor() {
17
15
  super()
18
- /** @type {Array} */
19
- this.items = []
20
- /** @type {string} */
21
- this.value = null
16
+
17
+ this._items = []
18
+ }
19
+
20
+ /**
21
+ * @param {import("../button/Button").LeuButton} button
22
+ * @returns {string}
23
+ */
24
+ static getButtonValue(button) {
25
+ return button.getAttribute("value") ?? button.innerText.trim()
26
+ }
27
+
28
+ get value() {
29
+ const activeButton = this._items.find((item) => item.active)
30
+ return activeButton ? LeuButtonGroup.getButtonValue(activeButton) : null
31
+ }
32
+
33
+ set value(newValue) {
34
+ this._items.forEach((item) => {
35
+ /* eslint-disable no-param-reassign */
36
+ item.active = LeuButtonGroup.getButtonValue(item) === newValue
37
+ /* eslint-enable no-param-reassign */
38
+ })
39
+ }
40
+
41
+ _handleSlotChange() {
42
+ /**
43
+ * Remove all event listeners that were added before.
44
+ * Just because a slotchange event was fired, it doesn't mean that all of the
45
+ * children of the slot have changed.
46
+ */
47
+ this._items.forEach((item) => {
48
+ item.removeEventListener("click", this._handleButtonClick)
49
+ })
50
+
51
+ const slot = this.shadowRoot.querySelector("slot")
52
+ this._items = slot.assignedElements({ flatten: true })
53
+
54
+ let foundActiveButtonBefore = false
55
+
56
+ this._items.forEach((item) => {
57
+ /* eslint-disable no-param-reassign */
58
+ item.addEventListener("click", () => this._handleButtonClick(item))
59
+ item.componentRole = "menuitemradio"
60
+
61
+ /**
62
+ * In case there are multiple active buttons
63
+ * only the first one will be kept active.
64
+ */
65
+ if (item.active && foundActiveButtonBefore) {
66
+ item.active = false
67
+ } else if (item.active) {
68
+ foundActiveButtonBefore = true
69
+ }
70
+
71
+ /* eslint-enable no-param-reassign */
72
+ })
22
73
  }
23
74
 
24
- _setValue(newValue) {
25
- this.value = newValue
75
+ /**
76
+ * @param {import("../button/Button").LeuButton} button
77
+ */
78
+ _handleButtonClick(button) {
79
+ if (!button.active) {
80
+ this.value = LeuButtonGroup.getButtonValue(button)
26
81
 
27
- this.dispatchEvent(
28
- new CustomEvent("input", {
29
- bubbles: true,
30
- composed: true,
31
- detail: { value: newValue },
32
- })
33
- )
82
+ this.dispatchEvent(
83
+ new CustomEvent("input", {
84
+ bubbles: true,
85
+ composed: true,
86
+ detail: { value: LeuButtonGroup.getButtonValue(button) },
87
+ })
88
+ )
89
+ }
34
90
  }
35
91
 
36
92
  render() {
37
93
  return html`
38
94
  <div role="menubar" class="group">
39
- ${this.items.map(
40
- (item) =>
41
- html`
42
- <leu-button
43
- label=${item}
44
- variant=${this.value === item ? "primary" : "secondary"}
45
- @click=${() => {
46
- this._setValue(item)
47
- }}
48
- role="menuitemradio"
49
- aria-checked=${this.value === item}
50
- >
51
- </leu-button>
52
- `
53
- )}
95
+ <slot @slotchange=${this._handleSlotChange}></slot>
54
96
  </div>
55
97
  `
56
98
  }
@@ -1,5 +1,6 @@
1
1
  import { html } from "lit"
2
2
  import "../leu-button-group.js"
3
+ import "../../button/leu-button.js"
3
4
 
4
5
  // https://stackoverflow.com/questions/72566428/storybook-angular-how-to-dynamically-update-args-from-the-template
5
6
  import { UPDATE_STORY_ARGS } from "@storybook/core-events" // eslint-disable-line
@@ -23,21 +24,27 @@ export default {
23
24
  }
24
25
 
25
26
  function Template({ items, value }, { id }) {
26
- return html`
27
- <leu-button-group
28
- .items=${items}
27
+ return html` <leu-button-group
29
28
  .value=${value}
30
- @click=${(event) => {
29
+ @input=${(event) => {
31
30
  updateStorybookArgss(id, {
32
31
  value: event.target.value,
33
32
  })
34
33
  }}
35
34
  >
35
+ ${items.map(
36
+ (i) =>
37
+ html`<leu-button
38
+ variant="secondary"
39
+ ?active=${value === i}
40
+ value=${`${i}-attr`}
41
+ >${i}
42
+ </leu-button>`
43
+ )}
36
44
  </leu-button-group>
37
45
  <br />
38
46
  <br />
39
- <pre>value = '${value}'</pre>
40
- `
47
+ <pre>value = '${value}'</pre>`
41
48
  }
42
49
 
43
50
  export const Regular = Template.bind({})
@@ -1,12 +1,23 @@
1
1
  import { html } from "lit"
2
- import { fixture, expect, oneEvent, elementUpdated } from "@open-wc/testing"
2
+ import {
3
+ fixture,
4
+ expect,
5
+ oneEvent,
6
+ elementUpdated,
7
+ aTimeout,
8
+ } from "@open-wc/testing"
3
9
 
4
10
  import "../leu-button-group.js"
5
-
6
- const items = ["Eins", "Zwei", "Drei"]
11
+ import "../../button/leu-button.js"
7
12
 
8
13
  async function defaultFixture() {
9
- return fixture(html` <leu-button-group .items=${items}></leu-button-group> `)
14
+ return fixture(html`
15
+ <leu-button-group>
16
+ <leu-button variant="secondary" value="Eins">Eins</leu-button>
17
+ <leu-button variant="secondary" value="Zweierlei">Zwei</leu-button>
18
+ <leu-button variant="secondary">Drei</leu-button>
19
+ </leu-button-group>
20
+ `)
10
21
  }
11
22
 
12
23
  describe("LeuButtonGroup", () => {
@@ -19,7 +30,7 @@ describe("LeuButtonGroup", () => {
19
30
  it("passes the a11y audit", async () => {
20
31
  const el = await defaultFixture()
21
32
 
22
- await expect(el).shadowDom.to.be.accessible()
33
+ await expect(el).to.be.accessible()
23
34
  })
24
35
 
25
36
  it("has no value by default", async () => {
@@ -31,32 +42,36 @@ describe("LeuButtonGroup", () => {
31
42
  it("has the correct value after clicking a button", async () => {
32
43
  const el = await defaultFixture()
33
44
 
34
- const buttons = el.shadowRoot.querySelectorAll("leu-button")
45
+ const buttons = Array.from(el.querySelectorAll("leu-button"))
35
46
 
36
- buttons[1].click()
37
- await expect(el.value).to.equal("Zwei")
47
+ setTimeout(() => buttons[1].click())
48
+ await oneEvent(el, "input")
49
+ await expect(el.value).to.equal("Zweierlei")
38
50
 
39
- buttons[0].click()
51
+ setTimeout(() => buttons[0].click())
52
+ await oneEvent(el, "input")
40
53
  await expect(el.value).to.equal("Eins")
41
54
 
42
- buttons[2].click()
55
+ setTimeout(() => buttons[2].click())
56
+ await oneEvent(el, "input")
43
57
  await expect(el.value).to.equal("Drei")
44
58
 
45
59
  // Should not change after clicking the same button again
46
- buttons[2].click()
60
+ setTimeout(() => buttons[2].click())
61
+ await aTimeout(100) // There is no event to wait for so
47
62
  await expect(el.value).to.equal("Drei")
48
63
  })
49
64
 
50
- it("renders the active button as a primary button", async () => {
65
+ it("sets the active attribute on the active button", async () => {
51
66
  const el = await defaultFixture()
52
- el.value = "Zwei"
67
+ el.value = "Zweierlei"
53
68
  await elementUpdated(el)
54
69
 
55
- const buttons = el.shadowRoot.querySelectorAll("leu-button")
70
+ const buttons = el.querySelectorAll("leu-button")
56
71
 
57
- await expect(buttons[0].variant).to.equal("secondary")
58
- await expect(buttons[1].variant).to.equal("primary")
59
- await expect(buttons[2].variant).to.equal("secondary")
72
+ await expect(buttons[0].active).to.be.false
73
+ await expect(buttons[1].active).to.be.true
74
+ await expect(buttons[2].active).to.be.false
60
75
 
61
76
  buttons[0].click()
62
77
 
@@ -65,21 +80,13 @@ describe("LeuButtonGroup", () => {
65
80
  await expect(buttons[2].variant).to.equal("secondary")
66
81
  })
67
82
 
68
- it("sets the correct aria-checked attribute", async () => {
83
+ it("sets the menuitemradio role on the buttons", async () => {
69
84
  const el = await defaultFixture()
70
- el.value = "Drei"
71
- await elementUpdated(el)
72
-
73
- const buttons = el.shadowRoot.querySelectorAll("leu-button")
85
+ const buttons = el.querySelectorAll("leu-button")
74
86
 
75
- await expect(buttons[0].getAttribute("aria-checked")).to.equal("false")
76
- await expect(buttons[1].getAttribute("aria-checked")).to.equal("false")
77
- await expect(buttons[2].getAttribute("aria-checked")).to.equal("true")
78
-
79
- buttons[0].click()
80
- await expect(buttons[0].getAttribute("aria-checked")).to.equal("false")
81
- await expect(buttons[1].getAttribute("aria-checked")).to.equal("false")
82
- await expect(buttons[2].getAttribute("aria-checked")).to.equal("false")
87
+ await expect(buttons[0].componentRole).to.equal("menuitemradio")
88
+ await expect(buttons[1].componentRole).to.equal("menuitemradio")
89
+ await expect(buttons[2].componentRole).to.equal("menuitemradio")
83
90
  })
84
91
 
85
92
  it("dispatches an input event when the value changes", async () => {
@@ -87,7 +94,7 @@ describe("LeuButtonGroup", () => {
87
94
  el.value = "Drei"
88
95
  await elementUpdated(el)
89
96
 
90
- const buttons = el.shadowRoot.querySelectorAll("leu-button")
97
+ const buttons = el.querySelectorAll("leu-button")
91
98
 
92
99
  setTimeout(() => buttons[0].click())
93
100
 
@@ -1,6 +1,6 @@
1
1
  :host {
2
- --group-font-regular: var(--leu-font-regular);
3
- --group-font-black: var(--leu-font-black);
2
+ --group-font-regular: var(--leu-font-family-regular);
3
+ --group-font-black: var(--leu-font-family-black);
4
4
 
5
5
  font-family: var(--group-font-regular);
6
6
  }
@@ -8,7 +8,7 @@
8
8
 
9
9
  --checkbox-tick-color: var(--leu-color-black-0);
10
10
 
11
- --checkbox-font-regular: var(--leu-font-regular);
11
+ --checkbox-font-regular: var(--leu-font-family-regular);
12
12
 
13
13
  position: relative;
14
14
 
@@ -1,4 +1,5 @@
1
- import { LitElement, html } from "lit"
1
+ import { LitElement } from "lit"
2
+ import { html, unsafeStatic } from "lit/static-html.js"
2
3
  import styles from "./chip-group.css"
3
4
 
4
5
  /* Figma https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=131766-248643&mode=design&t=Kjo5VDiqivihn8dh-11 */
@@ -11,18 +12,26 @@ export const SELECTION_MODES = {
11
12
 
12
13
  /**
13
14
  * @slot - Place leu-chip-* elements inside this slot
15
+ * @cssproperty --leu-chip-group-gap - The gap between the chips
14
16
  * @tagname leu-chip-group
15
17
  */
16
18
  export class LeuChipGroup extends LitElement {
17
19
  static styles = styles
18
20
 
19
21
  static properties = {
22
+ inverted: { type: Boolean, reflect: true },
20
23
  selectionMode: { type: String, attribute: "selection-mode", reflect: true },
24
+ headingLevel: { type: Number, attribute: "heading-level", reflect: true },
25
+ label: { type: String, reflect: true },
21
26
  }
22
27
 
23
28
  constructor() {
24
29
  super()
25
30
 
31
+ this.inverted = false
32
+ this.headingLevel = 2
33
+ this.label = ""
34
+
26
35
  /** @internal */
27
36
  this.items = []
28
37
  }
@@ -43,6 +52,22 @@ export class LeuChipGroup extends LitElement {
43
52
  return this.items.filter((i) => i.selected).map((i) => i.value)
44
53
  }
45
54
 
55
+ /**
56
+ * Determines the heading tag of the accordion toggle.
57
+ * The headingLevel shouldn't be used directly to render the heading tag
58
+ * in order to avoid XSS issues.
59
+ * @returns {String} The heading tag of the accordion toggle.
60
+ * @internal
61
+ */
62
+ _getHeadingTag() {
63
+ let level = 2
64
+ if (this.headingLevel > 0 && this.headingLevel < 7) {
65
+ level = this.headingLevel
66
+ }
67
+
68
+ return `h${level}`
69
+ }
70
+
46
71
  /** @internal */
47
72
  handleInput = (e) => {
48
73
  if (this.selectionMode === SELECTION_MODES.single) {
@@ -61,6 +86,21 @@ export class LeuChipGroup extends LitElement {
61
86
  }
62
87
 
63
88
  render() {
64
- return html`<slot @slotchange=${this.handleSlotChange}></slot>`
89
+ const hTag = this._getHeadingTag()
90
+
91
+ /* The eslint rules don't recognize html import from lit/static-html.js */
92
+ /* eslint-disable lit/binding-positions, lit/no-invalid-html */
93
+ return html`
94
+ ${this.label
95
+ ? html`<${unsafeStatic(hTag)} class="label">
96
+ <span class="label">${this.label}</span>
97
+ </${unsafeStatic(hTag)}>`
98
+ : ""}
99
+ <slot
100
+ class="group"
101
+ part="group"
102
+ @slotchange=${this.handleSlotChange}
103
+ ></slot>
104
+ `
65
105
  }
66
106
  }
@@ -21,7 +21,7 @@ export class LeuChipRemovable extends LeuChipBase {
21
21
  }
22
22
 
23
23
  handleClick() {
24
- const customEvent = new CustomEvent("remove", {
24
+ const customEvent = new CustomEvent("leu:remove", {
25
25
  bubble: true,
26
26
  composed: true,
27
27
  })
@@ -8,7 +8,7 @@ export const SIZES = {
8
8
  }
9
9
 
10
10
  export const VARIANTS = {
11
- default: "default",
11
+ toggle: "toggle",
12
12
  radio: "radio",
13
13
  }
14
14
 
@@ -30,11 +30,11 @@ export class LeuChipSelectable extends LeuChipBase {
30
30
 
31
31
  /**
32
32
  * The variant of the chip. Has an effect not only on the visual appearance but also on the behavior.
33
- * - `default`: The chip behaves like a toggle button.
33
+ * - `toggle`: The chip behaves like a toggle button.
34
34
  * - `radio`: The chip behaves like a radio button.
35
35
  *
36
36
  * @type {keyof typeof VARIANTS}
37
- * @default "default"
37
+ * @default "toggle"
38
38
  */
39
39
  variant: { type: String, reflect: true },
40
40
 
@@ -78,7 +78,7 @@ export class LeuChipSelectable extends LeuChipBase {
78
78
  return html`<button
79
79
  @click=${(e) => this.handleClick(e)}
80
80
  class="button"
81
- aria-selected=${this.selected ? "true" : "false"}
81
+ aria-pressed=${this.selected ? "true" : "false"}
82
82
  >
83
83
  <span class="label">${this.label}</span>
84
84
  </button>`
@@ -1,5 +1,15 @@
1
- :host {
1
+ .label {
2
+ margin: 0 0 0.5rem;
3
+ font: var(--leu-t-curve-35-black-font);
4
+ color: var(--leu-color-black-100);
5
+ }
6
+
7
+ :host([inverted]) .label {
8
+ color: var(--leu-color-black-0);
9
+ }
10
+
11
+ .group {
2
12
  display: flex;
3
13
  flex-wrap: wrap;
4
- gap: 0.5rem;
14
+ gap: var(--leu-chip-group-gap, 0.5rem);
5
15
  }