@statistikzh/leu 0.5.1 → 0.6.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 (236) hide show
  1. package/.husky/commit-msg +0 -3
  2. package/.husky/pre-commit +0 -3
  3. package/CHANGELOG.md +40 -0
  4. package/dist/Accordion.d.ts +10 -9
  5. package/dist/Accordion.d.ts.map +1 -1
  6. package/dist/Accordion.js +12 -11
  7. package/dist/Breadcrumb.d.ts +4 -4
  8. package/dist/Breadcrumb.d.ts.map +1 -1
  9. package/dist/Breadcrumb.js +28 -26
  10. package/dist/{Button-5326c982.d.ts → Button-9692e403.d.ts} +10 -11
  11. package/dist/Button-9692e403.d.ts.map +1 -0
  12. package/dist/{Button-5326c982.js → Button-9692e403.js} +57 -67
  13. package/dist/Button.d.ts +1 -1
  14. package/dist/Button.js +3 -3
  15. package/dist/ButtonGroup.d.ts +2 -2
  16. package/dist/ButtonGroup.d.ts.map +1 -1
  17. package/dist/ButtonGroup.js +3 -3
  18. package/dist/Checkbox.d.ts +4 -3
  19. package/dist/Checkbox.d.ts.map +1 -1
  20. package/dist/Checkbox.js +14 -19
  21. package/dist/CheckboxGroup.d.ts +2 -2
  22. package/dist/CheckboxGroup.d.ts.map +1 -1
  23. package/dist/CheckboxGroup.js +4 -6
  24. package/dist/Chip.d.ts +2 -2
  25. package/dist/Chip.d.ts.map +1 -1
  26. package/dist/Chip.js +6 -13
  27. package/dist/ChipGroup.d.ts +9 -7
  28. package/dist/ChipGroup.d.ts.map +1 -1
  29. package/dist/ChipGroup.js +8 -5
  30. package/dist/ChipLink.d.ts +2 -1
  31. package/dist/ChipLink.d.ts.map +1 -1
  32. package/dist/ChipLink.js +4 -7
  33. package/dist/ChipRemovable.d.ts +0 -2
  34. package/dist/ChipRemovable.d.ts.map +1 -1
  35. package/dist/ChipRemovable.js +8 -11
  36. package/dist/ChipSelectable.d.ts +9 -1
  37. package/dist/ChipSelectable.d.ts.map +1 -1
  38. package/dist/ChipSelectable.js +12 -16
  39. package/dist/Dropdown.d.ts +9 -5
  40. package/dist/Dropdown.d.ts.map +1 -1
  41. package/dist/Dropdown.js +68 -32
  42. package/dist/Icon.d.ts +20 -0
  43. package/dist/Icon.d.ts.map +1 -0
  44. package/dist/{icon-03e86700.js → Icon.js} +61 -32
  45. package/dist/Input.d.ts +7 -16
  46. package/dist/Input.d.ts.map +1 -1
  47. package/dist/Input.js +24 -28
  48. package/dist/LeuElement-6de6f209.d.ts +7 -0
  49. package/dist/LeuElement-6de6f209.d.ts.map +1 -0
  50. package/dist/LeuElement-6de6f209.js +43 -0
  51. package/dist/Menu.d.ts +24 -2
  52. package/dist/Menu.d.ts.map +1 -1
  53. package/dist/Menu.js +120 -3
  54. package/dist/MenuItem.d.ts +28 -11
  55. package/dist/MenuItem.d.ts.map +1 -1
  56. package/dist/MenuItem.js +110 -63
  57. package/dist/Pagination.d.ts +10 -3
  58. package/dist/Pagination.d.ts.map +1 -1
  59. package/dist/Pagination.js +24 -21
  60. package/dist/Popup.d.ts +21 -3
  61. package/dist/Popup.d.ts.map +1 -1
  62. package/dist/Popup.js +44 -19
  63. package/dist/Radio.d.ts +4 -2
  64. package/dist/Radio.d.ts.map +1 -1
  65. package/dist/Radio.js +9 -16
  66. package/dist/RadioGroup.d.ts +2 -2
  67. package/dist/RadioGroup.d.ts.map +1 -1
  68. package/dist/RadioGroup.js +4 -6
  69. package/dist/ScrollTop.d.ts +2 -2
  70. package/dist/ScrollTop.d.ts.map +1 -1
  71. package/dist/ScrollTop.js +10 -8
  72. package/dist/Select.d.ts +75 -37
  73. package/dist/Select.d.ts.map +1 -1
  74. package/dist/Select.js +279 -183
  75. package/dist/Table.d.ts +2 -6
  76. package/dist/Table.d.ts.map +1 -1
  77. package/dist/Table.js +17 -18
  78. package/dist/VisuallyHidden.d.ts +2 -2
  79. package/dist/VisuallyHidden.d.ts.map +1 -1
  80. package/dist/VisuallyHidden.js +5 -7
  81. package/dist/index.d.ts +2 -2
  82. package/dist/index.js +5 -14
  83. package/dist/leu-accordion.d.ts.map +1 -1
  84. package/dist/leu-accordion.js +2 -3
  85. package/dist/leu-breadcrumb.d.ts.map +1 -1
  86. package/dist/leu-breadcrumb.js +4 -10
  87. package/dist/leu-button-group.d.ts.map +1 -1
  88. package/dist/leu-button-group.js +2 -3
  89. package/dist/leu-button.d.ts +1 -1
  90. package/dist/leu-button.d.ts.map +1 -1
  91. package/dist/leu-button.js +4 -5
  92. package/dist/leu-checkbox-group.d.ts.map +1 -1
  93. package/dist/leu-checkbox-group.js +2 -3
  94. package/dist/leu-checkbox.d.ts.map +1 -1
  95. package/dist/leu-checkbox.js +3 -4
  96. package/dist/leu-chip-group.d.ts.map +1 -1
  97. package/dist/leu-chip-group.js +2 -3
  98. package/dist/leu-chip-link.d.ts.map +1 -1
  99. package/dist/leu-chip-link.js +2 -3
  100. package/dist/leu-chip-removable.d.ts.map +1 -1
  101. package/dist/leu-chip-removable.js +3 -4
  102. package/dist/leu-chip-selectable.d.ts.map +1 -1
  103. package/dist/leu-chip-selectable.js +2 -3
  104. package/dist/leu-dropdown.d.ts.map +1 -1
  105. package/dist/leu-dropdown.js +5 -10
  106. package/dist/leu-icon.d.ts +3 -0
  107. package/dist/leu-icon.d.ts.map +1 -0
  108. package/dist/leu-icon.js +7 -0
  109. package/dist/leu-input.d.ts.map +1 -1
  110. package/dist/leu-input.js +3 -4
  111. package/dist/leu-menu-item.d.ts.map +1 -1
  112. package/dist/leu-menu-item.js +3 -5
  113. package/dist/leu-menu.d.ts.map +1 -1
  114. package/dist/leu-menu.js +5 -3
  115. package/dist/leu-pagination.d.ts.map +1 -1
  116. package/dist/leu-pagination.js +4 -7
  117. package/dist/leu-popup.d.ts.map +1 -1
  118. package/dist/leu-popup.js +2 -3
  119. package/dist/leu-radio-group.d.ts.map +1 -1
  120. package/dist/leu-radio-group.js +2 -3
  121. package/dist/leu-radio.d.ts.map +1 -1
  122. package/dist/leu-radio.js +2 -3
  123. package/dist/leu-scroll-top.d.ts.map +1 -1
  124. package/dist/leu-scroll-top.js +4 -6
  125. package/dist/leu-select.d.ts.map +1 -1
  126. package/dist/leu-select.js +5 -13
  127. package/dist/leu-table.d.ts.map +1 -1
  128. package/dist/leu-table.js +4 -8
  129. package/dist/leu-visually-hidden.d.ts.map +1 -1
  130. package/dist/leu-visually-hidden.js +2 -3
  131. package/dist/theme.css +2 -0
  132. package/dist/vscode.html-custom-data.json +116 -79
  133. package/dist/vue/index.d.ts +80 -76
  134. package/dist/web-types.json +405 -270
  135. package/package.json +9 -12
  136. package/scripts/generate-component/templates/[Name].js +6 -3
  137. package/scripts/generate-component/templates/test/[name].test.js +1 -1
  138. package/src/components/accordion/Accordion.js +13 -10
  139. package/src/components/accordion/leu-accordion.js +1 -2
  140. package/src/components/breadcrumb/Breadcrumb.js +31 -18
  141. package/src/components/breadcrumb/leu-breadcrumb.js +1 -2
  142. package/src/components/button/Button.js +45 -71
  143. package/src/components/button/button.css +11 -9
  144. package/src/components/button/leu-button.js +1 -2
  145. package/src/components/button/stories/button.stories.js +60 -19
  146. package/src/components/button/test/button.test.js +26 -63
  147. package/src/components/button-group/ButtonGroup.js +4 -2
  148. package/src/components/button-group/leu-button-group.js +1 -2
  149. package/src/components/checkbox/Checkbox.js +17 -11
  150. package/src/components/checkbox/CheckboxGroup.js +6 -3
  151. package/src/components/checkbox/leu-checkbox-group.js +1 -2
  152. package/src/components/checkbox/leu-checkbox.js +1 -2
  153. package/src/components/checkbox/stories/checkbox-group.stories.js +10 -26
  154. package/src/components/checkbox/stories/checkbox.stories.js +2 -7
  155. package/src/components/checkbox/test/checkbox-group.test.js +6 -21
  156. package/src/components/checkbox/test/checkbox.test.js +1 -12
  157. package/src/components/chip/Chip.js +5 -4
  158. package/src/components/chip/ChipGroup.js +10 -4
  159. package/src/components/chip/ChipLink.js +3 -7
  160. package/src/components/chip/ChipRemovable.js +8 -11
  161. package/src/components/chip/ChipSelectable.js +11 -17
  162. package/src/components/chip/chip.css +3 -4
  163. package/src/components/chip/leu-chip-group.js +1 -2
  164. package/src/components/chip/leu-chip-link.js +1 -2
  165. package/src/components/chip/leu-chip-removable.js +1 -2
  166. package/src/components/chip/leu-chip-selectable.js +1 -2
  167. package/src/components/chip/stories/chip-link.stories.js +3 -5
  168. package/src/components/chip/stories/chip-removable.stories.js +3 -4
  169. package/src/components/chip/stories/chip-selectable.stories.js +2 -2
  170. package/src/components/chip/test/chip-group.test.js +15 -30
  171. package/src/components/chip/test/chip-link.test.js +2 -6
  172. package/src/components/chip/test/chip-removable.test.js +4 -10
  173. package/src/components/chip/test/chip-selectable.test.js +3 -5
  174. package/src/components/dropdown/Dropdown.js +79 -26
  175. package/src/components/dropdown/leu-dropdown.js +1 -2
  176. package/src/components/dropdown/stories/dropdown.stories.js +30 -7
  177. package/src/components/dropdown/test/dropdown.test.js +5 -5
  178. package/src/components/icon/Icon.js +55 -0
  179. package/src/components/icon/icon.css +6 -0
  180. package/src/components/icon/leu-icon.js +5 -0
  181. package/src/components/icon/{icon.js → paths.js} +4 -37
  182. package/src/components/icon/stories/icon.stories.js +47 -0
  183. package/src/components/icon/test/icon.test.js +23 -40
  184. package/src/components/input/Input.js +21 -23
  185. package/src/components/input/input.css +4 -2
  186. package/src/components/input/leu-input.js +1 -2
  187. package/src/components/input/stories/input.stories.js +2 -2
  188. package/src/components/input/test/input.test.js +2 -0
  189. package/src/components/menu/Menu.js +143 -2
  190. package/src/components/menu/MenuItem.js +104 -52
  191. package/src/components/menu/leu-menu-item.js +1 -2
  192. package/src/components/menu/leu-menu.js +1 -2
  193. package/src/components/menu/menu-item.css +11 -4
  194. package/src/components/menu/stories/menu-item.stories.js +15 -4
  195. package/src/components/menu/stories/menu.stories.js +34 -7
  196. package/src/components/menu/test/menu-item.test.js +88 -82
  197. package/src/components/menu/test/menu.test.js +101 -8
  198. package/src/components/pagination/Pagination.js +27 -18
  199. package/src/components/pagination/leu-pagination.js +1 -2
  200. package/src/components/popup/Popup.js +39 -16
  201. package/src/components/popup/leu-popup.js +1 -2
  202. package/src/components/popup/popup.css +1 -0
  203. package/src/components/radio/Radio.js +12 -7
  204. package/src/components/radio/RadioGroup.js +6 -3
  205. package/src/components/radio/leu-radio-group.js +1 -2
  206. package/src/components/radio/leu-radio.js +1 -2
  207. package/src/components/radio/stories/radio-group.stories.js +5 -19
  208. package/src/components/radio/stories/radio.stories.js +2 -7
  209. package/src/components/radio/test/radio-group.test.js +6 -9
  210. package/src/components/radio/test/radio.test.js +3 -13
  211. package/src/components/scroll-top/ScrollTop.js +15 -5
  212. package/src/components/scroll-top/leu-scroll-top.js +1 -2
  213. package/src/components/select/Select.js +279 -175
  214. package/src/components/select/leu-select.js +1 -2
  215. package/src/components/select/select.css +20 -12
  216. package/src/components/select/stories/select.stories.js +16 -2
  217. package/src/components/select/test/select.test.js +191 -37
  218. package/src/components/table/Table.js +15 -9
  219. package/src/components/table/leu-table.js +1 -2
  220. package/src/components/table/table.css +3 -1
  221. package/src/components/visually-hidden/VisuallyHidden.js +6 -2
  222. package/src/components/visually-hidden/leu-visually-hidden.js +1 -2
  223. package/src/lib/LeuElement.js +23 -0
  224. package/src/lib/a11y.js +26 -0
  225. package/src/styles/custom-properties.css +2 -0
  226. package/web-test-runner.config.mjs +2 -0
  227. package/dist/Button-5326c982.d.ts.map +0 -1
  228. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts +0 -3
  229. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts.map +0 -1
  230. package/dist/_rollupPluginBabelHelpers-20f659f4.js +0 -30
  231. package/dist/defineElement-40372b4b.d.ts +0 -9
  232. package/dist/defineElement-40372b4b.d.ts.map +0 -1
  233. package/dist/defineElement-40372b4b.js +0 -15
  234. package/dist/icon-03e86700.d.ts +0 -11
  235. package/dist/icon-03e86700.d.ts.map +0 -1
  236. package/src/lib/defineElement.js +0 -13
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.5.1",
6
+ "version": "0.6.0",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "format:prettier": "prettier \"**/*.{js,mjs,md,html,json}\" --write --ignore-path .gitignore",
40
40
  "test": "web-test-runner --coverage",
41
41
  "test:watch": "web-test-runner --watch",
42
- "prepare": "husky install",
42
+ "prepare": "husky",
43
43
  "storybook": "npm run storybook:start",
44
44
  "storybook:start": "npm run analyze && npm run watch:css & storybook dev -p 8080 --no-open",
45
45
  "storybook:build": "npm run analyze && npm run build:css && storybook build --output-dir docs"
@@ -64,11 +64,11 @@
64
64
  "@storybook/addon-links": "^7.6.17",
65
65
  "@storybook/blocks": "^7.6.17",
66
66
  "@storybook/web-components": "^7.6.17",
67
- "@web/dev-server": "^0.1.34",
68
- "@web/dev-server-rollup": "^0.5.2",
69
- "@web/storybook-builder": "^0.1.6",
70
- "@web/storybook-framework-web-components": "^0.1.1",
71
- "@web/test-runner": "^0.18.0",
67
+ "@web/dev-server": "^0.4.6",
68
+ "@web/dev-server-rollup": "^0.6.4",
69
+ "@web/storybook-builder": "^0.1.16",
70
+ "@web/storybook-framework-web-components": "^0.1.2",
71
+ "@web/test-runner": "^0.18.2",
72
72
  "@web/test-runner-commands": "^0.9.0",
73
73
  "@web/test-runner-playwright": "^0.11.0",
74
74
  "@whitespace/storybook-addon-html": "^5.1.6",
@@ -76,14 +76,12 @@
76
76
  "custom-element-jet-brains-integration": "^1.4.4",
77
77
  "custom-element-vs-code-integration": "^1.2.3",
78
78
  "custom-element-vuejs-integration": "^1.1.0",
79
- "es-dev-server": "^2.1.0",
80
- "esbuild": "^0.20.0",
81
79
  "eslint": "^8.31.0",
82
80
  "eslint-config-prettier": "^8.3.0",
83
81
  "eslint-plugin-storybook": "^0.6.14",
84
82
  "glob": "^10.3.10",
85
- "husky": "^8.0.0",
86
- "lint-staged": "^10.5.4",
83
+ "husky": "^9.0.11",
84
+ "lint-staged": "^15.2.7",
87
85
  "nodemon": "^3.0.2",
88
86
  "postcss": "^8.4.31",
89
87
  "postcss-cli": "^10.1.0",
@@ -96,7 +94,6 @@
96
94
  "react-syntax-highlighter": "^15.5.0",
97
95
  "rimraf": "^5.0.5",
98
96
  "rollup": "^3.29.4",
99
- "rollup-plugin-esbuild": "^6.0.2",
100
97
  "rollup-plugin-postcss": "^4.0.2",
101
98
  "rollup-plugin-postcss-lit": "^2.1.0",
102
99
  "sinon": "^17.0.1",
@@ -1,14 +1,17 @@
1
- import { html, LitElement } from "lit"
1
+ import { html } from "lit"
2
+
3
+ import { LeuElement } from "../../lib/LeuElement.js"
4
+
2
5
  import styles from "./[name].css"
3
6
 
4
7
  /**
5
8
  * @tagname [namespace]-[name]
6
9
  */
7
- export class Leu[Name] extends LitElement {
10
+ export class Leu[Name] extends LeuElement {
8
11
  static styles = styles
9
12
 
10
13
  static shadowRootOptions = {
11
- ...LitElement.shadowRootOptions,
14
+ ...LeuElement.shadowRootOptions,
12
15
  delegatesFocus: true,
13
16
  }
14
17
 
@@ -4,7 +4,7 @@ import { fixture, expect } from "@open-wc/testing"
4
4
  import "../[namespace]-[name].js"
5
5
 
6
6
  async function defaultFixture() {
7
- return fixture(html` <[namespace]-[name] /> `)
7
+ return fixture(html`<[namespace]-[name]></[namespace]-[name]>`)
8
8
  }
9
9
 
10
10
  describe("[Namespace][Name]", () => {
@@ -1,24 +1,26 @@
1
- import { LitElement, nothing } from "lit"
1
+ import { nothing } from "lit"
2
2
  import { html, unsafeStatic } from "lit/static-html.js"
3
+ import { LeuElement } from "../../lib/LeuElement.js"
3
4
 
5
+ // @ts-ignore
4
6
  import styles from "./accordion.css"
5
7
 
6
8
  /**
7
9
  * @tagname leu-accordion
8
10
  * @slot content - The content of the accordion. No styles will be applied to the content.
9
- * @prop {Number} headingLevel - The heading level of the accordion title. Must be between 1 and 6.
10
- * @prop {Boolean} open - The expanded state of the accordion.
11
- * @prop {String} label - The label (title) of the accordion.
12
- * @prop {String} labelPrefix - The prefix of the accordion label. e.g. "01"
13
- * @attr {Number} heading-level - The heading level of the accordion title. Must be between 1 and 6.
14
- * @attr {String} label-prefix - The prefix of the accordion label. e.g. "01"
11
+ * @prop {number} headingLevel - The heading level of the accordion title. Must be between 1 and 6.
12
+ * @prop {boolean} open - The expanded state of the accordion.
13
+ * @prop {string} label - The label (title) of the accordion.
14
+ * @prop {string} labelPrefix - The prefix of the accordion label. e.g. "01"
15
+ * @attr {number} heading-level - The heading level of the accordion title. Must be between 1 and 6.
16
+ * @attr {string} label-prefix - The prefix of the accordion label. e.g. "01"
15
17
  */
16
- export class LeuAccordion extends LitElement {
18
+ export class LeuAccordion extends LeuElement {
17
19
  static styles = styles
18
20
 
19
21
  /** @internal */
20
22
  static shadowRootOptions = {
21
- ...LitElement.shadowRootOptions,
23
+ ...LeuElement.shadowRootOptions,
22
24
  delegatesFocus: true,
23
25
  }
24
26
 
@@ -34,13 +36,14 @@ export class LeuAccordion extends LitElement {
34
36
  this.headingLevel = 2
35
37
  this.open = false
36
38
  this.label = ""
39
+ this.labelPrefix = ""
37
40
  }
38
41
 
39
42
  /**
40
43
  * Determines the heading tag of the accordion toggle.
41
44
  * The headingLevel shouldn't be used directly to render the heading tag
42
45
  * in order to avoid XSS issues.
43
- * @returns {String} The heading tag of the accordion toggle.
46
+ * @returns {string} The heading tag of the accordion toggle.
44
47
  * @internal
45
48
  */
46
49
  _getHeadingTag() {
@@ -1,6 +1,5 @@
1
- import { defineElement } from "../../lib/defineElement.js"
2
1
  import { LeuAccordion } from "./Accordion.js"
3
2
 
4
3
  export { LeuAccordion }
5
4
 
6
- defineElement("accordion", LeuAccordion)
5
+ LeuAccordion.define("leu-accordion")
@@ -1,14 +1,16 @@
1
- import { html, LitElement, nothing } from "lit"
1
+ import { html, nothing } from "lit"
2
2
  import { createRef, ref } from "lit/directives/ref.js"
3
3
  import { classMap } from "lit/directives/class-map.js"
4
4
 
5
- import styles from "./breadcrumb.css"
6
- import { Icon } from "../icon/icon.js"
7
- import "../menu/leu-menu.js"
8
- import "../menu/leu-menu-item.js"
9
- import "../popup/leu-popup.js"
10
- import "../visually-hidden/leu-visually-hidden.js"
5
+ import { LeuElement } from "../../lib/LeuElement.js"
11
6
  import { debounce } from "../../lib/utils.js"
7
+ import { LeuIcon } from "../icon/Icon.js"
8
+ import { LeuMenu } from "../menu/Menu.js"
9
+ import { LeuMenuItem } from "../menu/MenuItem.js"
10
+ import { LeuPopup } from "../popup/Popup.js"
11
+ import { LeuVisuallyHidden } from "../visually-hidden/VisuallyHidden.js"
12
+
13
+ import styles from "./breadcrumb.css"
12
14
 
13
15
  /**
14
16
  * A Breadcrumb Navigation.
@@ -40,11 +42,19 @@ import { debounce } from "../../lib/utils.js"
40
42
  *
41
43
  *
42
44
  * @prop {Array} items - Object array with { label, href }
43
- * @prop {Boolean} inverted - invert color on dark background
45
+ * @prop {boolean} inverted - invert color on dark background
44
46
  *
45
47
  * @tagname leu-breadcrumb
46
48
  */
47
- export class LeuBreadcrumb extends LitElement {
49
+ export class LeuBreadcrumb extends LeuElement {
50
+ static dependencies = {
51
+ "leu-icon": LeuIcon,
52
+ "leu-menu": LeuMenu,
53
+ "leu-menu-item": LeuMenuItem,
54
+ "leu-popup": LeuPopup,
55
+ "leu-visually-hidden": LeuVisuallyHidden,
56
+ }
57
+
48
58
  static styles = styles
49
59
 
50
60
  static properties = {
@@ -63,7 +73,7 @@ export class LeuBreadcrumb extends LitElement {
63
73
  super()
64
74
  /** @type {Array} */
65
75
  this.items = []
66
- /** @type {Boolean} - will be used on dark Background */
76
+ /** @type {boolean} - will be used on dark Background */
67
77
  this.inverted = false
68
78
 
69
79
  /** @internal */
@@ -225,7 +235,9 @@ export class LeuBreadcrumb extends LitElement {
225
235
 
226
236
  return html`
227
237
  <li class="breadcrumbs__item" data-dropdown-toggle>
228
- <span class="breadcrumbs__icon">${Icon("angleRight")}</span>
238
+ <span class="breadcrumbs__icon"
239
+ ><leu-icon name="angleRight"></leu-icon
240
+ ></span>
229
241
  <leu-popup
230
242
  ?active=${this._isDropdownOpen}
231
243
  placement="bottom-start"
@@ -248,10 +260,9 @@ export class LeuBreadcrumb extends LitElement {
248
260
  ${this._dropdownItems.map(
249
261
  (item) =>
250
262
  html`
251
- <leu-menu-item
252
- label=${item.label}
253
- href=${item.href}
254
- ></leu-menu-item>
263
+ <leu-menu-item href=${item.href}
264
+ >${item.label}</leu-menu-item
265
+ >
255
266
  `
256
267
  )}
257
268
  </leu-menu>
@@ -281,7 +292,9 @@ export class LeuBreadcrumb extends LitElement {
281
292
  <ol class="breadcrumbs__list" ref=${ref(this._containerRef)}>
282
293
  ${showBackOnly
283
294
  ? html` <li class="breadcrumbs__item breadcrumbs__item--back">
284
- <span class="breadcrumbs__icon">${Icon("arrowLeft")}</span>
295
+ <span class="breadcrumbs__icon"
296
+ ><leu-icon name="arrowLeft"></leu-icon
297
+ ></span>
285
298
  <a class="breadcrumbs__link" href=${parentItem.href}
286
299
  >${parentItem.label}</a
287
300
  >
@@ -292,8 +305,8 @@ export class LeuBreadcrumb extends LitElement {
292
305
  <li class="breadcrumbs__item">
293
306
  ${index > 0
294
307
  ? html`<span class="breadcrumbs__icon"
295
- >${Icon("angleRight")}</span
296
- >` // First list item doesn't have an arrow
308
+ ><leu-icon name="angleRight"></leu-icon
309
+ ></span>` // First list item doesn't have an arrow
297
310
  : nothing}
298
311
  ${index === list.length - 1
299
312
  ? item.label // Last list item doesn't contain a link
@@ -1,6 +1,5 @@
1
- import { defineElement } from "../../lib/defineElement.js"
2
1
  import { LeuBreadcrumb } from "./Breadcrumb.js"
3
2
 
4
3
  export { LeuBreadcrumb }
5
4
 
6
- defineElement("breadcrumb", LeuBreadcrumb)
5
+ LeuBreadcrumb.define("leu-breadcrumb")
@@ -1,10 +1,13 @@
1
- import { html, nothing, LitElement } from "lit"
1
+ import { html, nothing } from "lit"
2
2
  import { classMap } from "lit/directives/class-map.js"
3
3
  import { ifDefined } from "lit/directives/if-defined.js"
4
4
 
5
- import { Icon } from "../icon/icon.js"
5
+ import { LeuIcon } from "../icon/Icon.js"
6
+ import { LeuElement } from "../../lib/LeuElement.js"
6
7
  import { HasSlotController } from "../../lib/hasSlotController.js"
8
+ import { ARIA_CHECKED_ROLES, ARIA_SELECTED_ROLES } from "../../lib/a11y.js"
7
9
 
10
+ // @ts-ignore
8
11
  import styles from "./button.css"
9
12
 
10
13
  /*
@@ -27,56 +30,38 @@ export { BUTTON_TYPES }
27
30
  export const BUTTON_EXPANDED_OPTIONS = ["true", "false"]
28
31
  Object.freeze(BUTTON_EXPANDED_OPTIONS)
29
32
 
30
- /**
31
- * All roles that are associated with a aria-checked attribute
32
- * @link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-checked
33
- */
34
- const ARIA_ROLES_CHECKED = [
35
- "checkbox",
36
- "menuitemcheckbox",
37
- "menuitemradio",
38
- "option",
39
- "radio",
40
- "switch",
41
- ]
42
-
43
- /**
44
- * All roles that are associated with a aria-selected attribute
45
- * @link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-selected
46
- */
47
- const ARIA_ROLES_SELECTED = [
48
- "gridcell",
49
- "option",
50
- "row",
51
- "tab",
52
- "columnheader",
53
- "rowheader",
54
- "treeitem",
55
- ]
56
-
57
33
  /**
58
34
  * @tagname leu-button
35
+ * @slot before - The icon to display before the label
36
+ * @slot after - The icon to display after the label
37
+ * @slot - The label of the button or the icon if no label is set
59
38
  */
60
- export class LeuButton extends LitElement {
39
+ export class LeuButton extends LeuElement {
40
+ static dependencies = {
41
+ "leu-icon": LeuIcon,
42
+ }
43
+
61
44
  static styles = styles
62
45
 
63
46
  /**
64
47
  * @internal
65
48
  */
66
49
  static shadowRootOptions = {
67
- ...LitElement.shadowRootOptions,
50
+ ...LeuElement.shadowRootOptions,
68
51
  delegatesFocus: true,
69
52
  }
70
53
 
71
54
  /**
72
55
  * @internal
73
56
  */
74
- hasSlotController = new HasSlotController(this, ["[default]"])
57
+ hasSlotController = new HasSlotController(this, [
58
+ "before",
59
+ "after",
60
+ "[default]",
61
+ ])
75
62
 
76
63
  static properties = {
77
64
  label: { type: String, reflect: true },
78
- icon: { type: String, reflect: true },
79
- iconPosition: { type: String, reflect: true },
80
65
  size: { type: String, reflect: true },
81
66
  variant: { type: String, reflect: true },
82
67
  type: { type: String, reflect: true },
@@ -95,16 +80,15 @@ export class LeuButton extends LitElement {
95
80
  /** @type {string} */
96
81
  this.label = null
97
82
  /** @type {string} */
98
- this.icon = null
99
- /** @type {("before" | "after")} - Only taken into account if Label and no Icon is set */
100
- this.iconPosition = "before"
101
- /** @type {string} */
102
83
  this.size = "regular"
103
84
  /** @type {string} */
104
85
  this.variant = "primary"
105
86
  /** @type {"button" | "submit" | "reset"} */
106
87
  this.type = "button"
107
88
 
89
+ /** @type {string} */
90
+ this.componentRole = undefined
91
+
108
92
  /** @type {boolean} */
109
93
  this.disabled = false
110
94
  /** @type {boolean} - Only taken into account if no Label and an Icon is set */
@@ -124,34 +108,10 @@ export class LeuButton extends LitElement {
124
108
  this.expanded = undefined
125
109
  }
126
110
 
127
- getIconSize() {
128
- return this.size === "small" || this.variant === "ghost" ? 16 : 24
129
- }
130
-
131
- renderIconBefore() {
132
- if (this.icon && this.iconPosition === "before") {
133
- return html`<div class="icon-wrapper icon-wrapper--before">
134
- ${Icon(this.icon, this.getIconSize())}
135
- </div>`
136
- }
137
-
138
- return nothing
139
- }
140
-
141
- renderIconAfter() {
142
- if (this.icon && this.iconPosition === "after") {
143
- return html`<div class="icon-wrapper icon-wrapper--after">
144
- ${Icon(this.icon, this.getIconSize())}
145
- </div>`
146
- }
147
-
148
- return nothing
149
- }
150
-
151
111
  renderExpandingIcon() {
152
112
  if (typeof this.expanded !== "undefined" && this.variant === "ghost") {
153
113
  return html`<div class="icon-wrapper icon-wrapper--expanded">
154
- ${Icon("angleDropDown", 24)}
114
+ <leu-icon name="angleDropDown" size="24"></leu-icon>
155
115
  </div>`
156
116
  }
157
117
 
@@ -165,9 +125,9 @@ export class LeuButton extends LitElement {
165
125
  }
166
126
 
167
127
  if (this.componentRole) {
168
- if (ARIA_ROLES_CHECKED.includes(this.componentRole)) {
128
+ if (ARIA_CHECKED_ROLES.includes(this.componentRole)) {
169
129
  attributes.checked = this.active ? "true" : "false"
170
- } else if (ARIA_ROLES_SELECTED.includes(this.componentRole)) {
130
+ } else if (ARIA_SELECTED_ROLES.includes(this.componentRole)) {
171
131
  attributes.selected = this.active ? "true" : "false"
172
132
  }
173
133
  }
@@ -175,13 +135,25 @@ export class LeuButton extends LitElement {
175
135
  return attributes
176
136
  }
177
137
 
138
+ hasTextContent() {
139
+ return Array.from(this.childNodes).some(
140
+ (node) =>
141
+ node.nodeType === node.TEXT_NODE && node.textContent.trim() !== ""
142
+ )
143
+ }
144
+
178
145
  render() {
179
- const hasContent = this.hasSlotController.test("[default]")
146
+ const hasTextContent = this.hasTextContent()
147
+ const hasIconDefault = Boolean(this.querySelector("leu-icon"))
148
+ const hasIconBefore = this.hasSlotController.test("before")
149
+ const hasIconAfter = this.hasSlotController.test("after")
180
150
  const aria = this.getAriaAttributes()
181
151
 
182
152
  const cssClasses = {
183
- icon: !hasContent && this.icon,
184
- round: !hasContent && this.icon && this.round,
153
+ "icon-only": hasIconDefault && !hasTextContent,
154
+ "icon-before": hasIconBefore,
155
+ "icon-after": hasIconAfter,
156
+ round: this.round,
185
157
  active: this.active,
186
158
  inverted: this.inverted,
187
159
  [this.variant]: true,
@@ -192,14 +164,16 @@ export class LeuButton extends LitElement {
192
164
  aria-label=${ifDefined(aria.label)}
193
165
  aria-selected=${ifDefined(aria.selected)}
194
166
  aria-checked=${ifDefined(aria.checked)}
167
+ aria-expanded=${ifDefined(this.expanded)}
195
168
  role=${ifDefined(aria.role)}
196
169
  class=${classMap(cssClasses)}
197
170
  ?disabled=${this.disabled}
198
171
  type=${this.type}
199
172
  >
200
- ${this.renderIconBefore()}
201
- <span class="label"><slot></slot></span>
202
- ${this.renderIconAfter()} ${this.renderExpandingIcon()}
173
+ <slot name="before" class="icon-wrapper icon-wrapper--before"></slot>
174
+ <span class="content"><slot></slot></span>
175
+ <slot name="after" class="icon-wrapper icon-wrapper--after"></slot>
176
+ ${this.renderExpandingIcon()}
203
177
  </button>
204
178
  `
205
179
  }
@@ -17,17 +17,13 @@ button {
17
17
  column-gap: 8px;
18
18
  }
19
19
 
20
- .label {
20
+ .content {
21
21
  flex: 1 1 0;
22
22
  overflow: hidden;
23
23
  text-overflow: ellipsis;
24
24
  white-space: nowrap;
25
25
  }
26
26
 
27
- .icon .label {
28
- display: none;
29
- }
30
-
31
27
  button.round {
32
28
  border-radius: 50%;
33
29
  }
@@ -58,7 +54,7 @@ button.regular {
58
54
  line-height: 24px;
59
55
  }
60
56
 
61
- button.regular.icon {
57
+ button.regular.icon-only {
62
58
  padding: 12px;
63
59
  }
64
60
 
@@ -67,9 +63,11 @@ button.small {
67
63
  padding: 6px 24px;
68
64
  font-size: 14px;
69
65
  line-height: 20px;
66
+
67
+ --leu-icon-size: 1rem;
70
68
  }
71
69
 
72
- button.small.icon {
70
+ button.small.icon-only {
73
71
  padding: 8px;
74
72
  }
75
73
 
@@ -125,6 +123,8 @@ button.secondary:disabled {
125
123
 
126
124
  /* ghost */
127
125
  button.ghost {
126
+ --leu-icon-size: 1rem;
127
+
128
128
  background: transparent;
129
129
  padding: 0 0.5rem;
130
130
  color: var(--leu-color-black-60);
@@ -203,11 +203,13 @@ button.ghost.inverted:disabled {
203
203
  }
204
204
 
205
205
  /* icon-wrapper */
206
- .icon-wrapper svg {
206
+ .icon-wrapper leu-icon {
207
207
  display: block;
208
208
  }
209
209
 
210
- .ghost :is(.icon-wrapper--before, .icon-wrapper--after) {
210
+ .ghost.icon-before .icon-wrapper--before,
211
+ .ghost.icon-after .icon-wrapper--after {
212
+ display: block;
211
213
  padding: 0.5rem;
212
214
  border-radius: 50%;
213
215
  background: var(--leu-color-black-transp-10);
@@ -1,6 +1,5 @@
1
- import { defineElement } from "../../lib/defineElement.js"
2
1
  import { LeuButton } from "./Button.js"
3
2
 
4
3
  export { LeuButton }
5
4
 
6
- defineElement("button", LeuButton)
5
+ LeuButton.define("leu-button")