@statistikzh/leu 0.5.1 → 0.7.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 +54 -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 -24
  10. package/dist/{Button-5326c982.d.ts → Button-7370f901.d.ts} +10 -11
  11. package/dist/Button-7370f901.d.ts.map +1 -0
  12. package/dist/{Button-5326c982.js → Button-7370f901.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 -17
  21. package/dist/CheckboxGroup.d.ts +2 -2
  22. package/dist/CheckboxGroup.d.ts.map +1 -1
  23. package/dist/CheckboxGroup.js +4 -4
  24. package/dist/Chip.d.ts +2 -2
  25. package/dist/Chip.d.ts.map +1 -1
  26. package/dist/Chip.js +23 -28
  27. package/dist/ChipGroup.d.ts +16 -8
  28. package/dist/ChipGroup.d.ts.map +1 -1
  29. package/dist/ChipGroup.js +39 -9
  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 +12 -2
  37. package/dist/ChipSelectable.d.ts.map +1 -1
  38. package/dist/ChipSelectable.js +24 -26
  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 +116 -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 +13 -17
  46. package/dist/Input.d.ts.map +1 -1
  47. package/dist/Input.js +33 -24
  48. package/dist/LeuElement-ba5ea33d.d.ts +7 -0
  49. package/dist/LeuElement-ba5ea33d.d.ts.map +1 -0
  50. package/dist/{_rollupPluginBabelHelpers-20f659f4.js → LeuElement-ba5ea33d.js} +20 -1
  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 -17
  63. package/dist/Radio.d.ts +4 -2
  64. package/dist/Radio.d.ts.map +1 -1
  65. package/dist/Radio.js +9 -14
  66. package/dist/RadioGroup.d.ts +2 -2
  67. package/dist/RadioGroup.d.ts.map +1 -1
  68. package/dist/RadioGroup.js +20 -11
  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 -181
  75. package/dist/Table.d.ts +2 -6
  76. package/dist/Table.d.ts.map +1 -1
  77. package/dist/Table.js +16 -16
  78. package/dist/VisuallyHidden.d.ts +2 -2
  79. package/dist/VisuallyHidden.d.ts.map +1 -1
  80. package/dist/VisuallyHidden.js +3 -3
  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 +124 -74
  133. package/dist/vue/index.d.ts +83 -67
  134. package/dist/web-types.json +256 -142
  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 +38 -8
  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 +23 -27
  162. package/src/components/chip/chip.css +19 -20
  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-group.stories.js +6 -9
  168. package/src/components/chip/stories/chip-link.stories.js +3 -5
  169. package/src/components/chip/stories/chip-removable.stories.js +3 -4
  170. package/src/components/chip/stories/chip-selectable.stories.js +3 -3
  171. package/src/components/chip/test/chip-group.test.js +82 -30
  172. package/src/components/chip/test/chip-link.test.js +2 -6
  173. package/src/components/chip/test/chip-removable.test.js +4 -10
  174. package/src/components/chip/test/chip-selectable.test.js +10 -12
  175. package/src/components/dropdown/Dropdown.js +79 -26
  176. package/src/components/dropdown/leu-dropdown.js +1 -2
  177. package/src/components/dropdown/stories/dropdown.stories.js +30 -7
  178. package/src/components/dropdown/test/dropdown.test.js +5 -5
  179. package/src/components/icon/Icon.js +55 -0
  180. package/src/components/icon/icon.css +6 -0
  181. package/src/components/icon/leu-icon.js +5 -0
  182. package/src/components/icon/{icon.js → paths.js} +4 -37
  183. package/src/components/icon/stories/icon.stories.js +47 -0
  184. package/src/components/icon/test/icon.test.js +23 -40
  185. package/src/components/input/Input.js +31 -20
  186. package/src/components/input/input.css +4 -2
  187. package/src/components/input/leu-input.js +1 -2
  188. package/src/components/input/stories/input.stories.js +5 -5
  189. package/src/components/input/test/input.test.js +22 -0
  190. package/src/components/menu/Menu.js +143 -2
  191. package/src/components/menu/MenuItem.js +104 -52
  192. package/src/components/menu/leu-menu-item.js +1 -2
  193. package/src/components/menu/leu-menu.js +1 -2
  194. package/src/components/menu/menu-item.css +11 -4
  195. package/src/components/menu/stories/menu-item.stories.js +15 -4
  196. package/src/components/menu/stories/menu.stories.js +34 -7
  197. package/src/components/menu/test/menu-item.test.js +88 -82
  198. package/src/components/menu/test/menu.test.js +101 -8
  199. package/src/components/pagination/Pagination.js +27 -18
  200. package/src/components/pagination/leu-pagination.js +1 -2
  201. package/src/components/popup/Popup.js +39 -16
  202. package/src/components/popup/leu-popup.js +1 -2
  203. package/src/components/popup/popup.css +1 -0
  204. package/src/components/radio/Radio.js +12 -7
  205. package/src/components/radio/RadioGroup.js +18 -12
  206. package/src/components/radio/leu-radio-group.js +1 -2
  207. package/src/components/radio/leu-radio.js +1 -2
  208. package/src/components/radio/stories/radio-group.stories.js +5 -19
  209. package/src/components/radio/stories/radio.stories.js +2 -7
  210. package/src/components/radio/test/radio-group.test.js +6 -9
  211. package/src/components/radio/test/radio.test.js +3 -13
  212. package/src/components/scroll-top/ScrollTop.js +15 -5
  213. package/src/components/scroll-top/leu-scroll-top.js +1 -2
  214. package/src/components/select/Select.js +279 -175
  215. package/src/components/select/leu-select.js +1 -2
  216. package/src/components/select/select.css +20 -12
  217. package/src/components/select/stories/select.stories.js +16 -2
  218. package/src/components/select/test/select.test.js +191 -37
  219. package/src/components/table/Table.js +15 -9
  220. package/src/components/table/leu-table.js +1 -2
  221. package/src/components/table/table.css +3 -1
  222. package/src/components/visually-hidden/VisuallyHidden.js +6 -2
  223. package/src/components/visually-hidden/leu-visually-hidden.js +1 -2
  224. package/src/lib/LeuElement.js +23 -0
  225. package/src/lib/a11y.js +26 -0
  226. package/src/styles/custom-properties.css +2 -0
  227. package/web-test-runner.config.mjs +2 -0
  228. package/dist/Button-5326c982.d.ts.map +0 -1
  229. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts +0 -3
  230. package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts.map +0 -1
  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/dist/Input.js CHANGED
@@ -1,10 +1,10 @@
1
- import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
- import { css, LitElement, nothing, html } from 'lit';
1
+ import { _ as _defineProperty, L as LeuElement } from './LeuElement-ba5ea33d.js';
2
+ import { css, nothing, html } from 'lit';
3
3
  import { classMap } from 'lit/directives/class-map.js';
4
4
  import { ifDefined } from 'lit/directives/if-defined.js';
5
5
  import { live } from 'lit/directives/live.js';
6
6
  import { createRef, ref } from 'lit/directives/ref.js';
7
- import { I as Icon } from './icon-03e86700.js';
7
+ import { LeuIcon } from './Icon.js';
8
8
 
9
9
  var css_248z = css`:host,
10
10
  :host * {
@@ -181,7 +181,9 @@ var css_248z = css`:host,
181
181
 
182
182
  /* is size small AND has no focus AND is empty */
183
183
 
184
- :host(:not(:focus-within)[size="small"]) .input-wrapper--empty .label {
184
+ :host(:not(:focus-within)[size="small"])
185
+ .input-wrapper--empty:not(.input-wrapper--invalid)
186
+ .label {
185
187
  top: calc(0.75rem - var(--input-border-width));
186
188
  opacity: 1;
187
189
  visibility: visible;
@@ -270,15 +272,15 @@ var css_248z = css`:host,
270
272
  color: var(--input-color-invalid);
271
273
  }
272
274
 
273
- .icon svg, .error-icon svg {
275
+ .icon leu-icon, .error-icon leu-icon {
274
276
  display: block;
275
277
  }
276
278
  `;
277
279
 
278
- const SIZE_TYPES = {
280
+ const SIZES = Object.freeze({
279
281
  SMALL: "small",
280
282
  REGULAR: "regular"
281
- };
283
+ });
282
284
 
283
285
  /**
284
286
  * TODO:
@@ -328,7 +330,7 @@ const VALIDATION_MESSAGES = {
328
330
  *
329
331
  * @tagname leu-input
330
332
  */
331
- class LeuInput extends LitElement {
333
+ class LeuInput extends LeuElement {
332
334
  static resolveErrorMessage(message, refernceValue) {
333
335
  if (typeof message === "function") {
334
336
  return message(refernceValue);
@@ -341,25 +343,29 @@ class LeuInput extends LitElement {
341
343
  this.required = false;
342
344
  this.clearable = false;
343
345
 
344
- /** @type {keyof typeof SIZE_TYPES} */
345
- this.size = SIZE_TYPES.REGULAR;
346
+ /** @type {"small" | "regular"} */
347
+ this.size = SIZES.REGULAR;
346
348
  this.type = "text";
347
349
  this._validity = null;
348
350
  this.validationMessages = {};
349
351
  this.novalidate = false;
352
+ this.value = "";
350
353
 
351
354
  /** @internal */
352
355
  this._identifier = "";
353
356
 
354
- /** @internal */
355
- this._clearIcon = Icon("clear");
356
-
357
357
  /**
358
358
  * @internal
359
359
  * @type {import("lit/directives/ref.js").Ref<HTMLInputElement>}
360
360
  */
361
361
  this._inputRef = createRef();
362
362
  }
363
+ get valueAsNumber() {
364
+ if (this.value === "") {
365
+ return NaN;
366
+ }
367
+ return Number(this.value);
368
+ }
363
369
 
364
370
  /**
365
371
  * Method for handling the click event of the wrapper element.
@@ -510,10 +516,7 @@ class LeuInput extends LitElement {
510
516
 
511
517
  /**
512
518
  * Creates an error list with an item for the given validity state.
513
- * @param {ValidityState} validityState
514
- * @param {Object} validationMessages
515
- * @param {String} idRef
516
- * @returns
519
+ * @returns {import("lit").TemplateResult | nothing}
517
520
  */
518
521
  renderErrorMessages() {
519
522
  if (!this.isInvalid()) {
@@ -536,11 +539,13 @@ class LeuInput extends LitElement {
536
539
  * This can be either an icon, a clear button or an error indicator icon.
537
540
  *
538
541
  * @private
539
- * @returns {TemplateResult}
542
+ * @returns {import("lit").TemplateResult | nothing}
540
543
  */
541
544
  renderAfterContent() {
542
545
  if (this.isInvalid()) {
543
- return html`<div class="error-icon">${Icon("caution")}</div>`;
546
+ return html`<div class="error-icon">
547
+ <leu-icon name="caution"></leu-icon>
548
+ </div>`;
544
549
  }
545
550
  if (this.clearable && this.value) {
546
551
  return html`<button
@@ -549,11 +554,13 @@ class LeuInput extends LitElement {
549
554
  aria-label="Eingabefeld zurücksetzen"
550
555
  ?disabled=${this.disabled}
551
556
  >
552
- ${this._clearIcon}
557
+ <leu-icon name="clear"></leu-icon>
553
558
  </button>`;
554
559
  }
555
560
  if (this.icon) {
556
- return html`<div class="icon">${Icon(this.icon)}</div>`;
561
+ return html`<div class="icon">
562
+ <leu-icon name=${this.icon}></leu-icon>
563
+ </div>`;
557
564
  }
558
565
  return nothing;
559
566
  }
@@ -608,12 +615,15 @@ class LeuInput extends LitElement {
608
615
  `;
609
616
  }
610
617
  }
618
+ _defineProperty(LeuInput, "dependencies", {
619
+ "leu-icon": LeuIcon
620
+ });
611
621
  _defineProperty(LeuInput, "styles", css_248z);
612
622
  /**
613
623
  * @internal
614
624
  */
615
625
  _defineProperty(LeuInput, "shadowRootOptions", {
616
- ...LitElement.shadowRootOptions,
626
+ ...LeuElement.shadowRootOptions,
617
627
  delegatesFocus: true
618
628
  });
619
629
  _defineProperty(LeuInput, "properties", {
@@ -697,10 +707,9 @@ _defineProperty(LeuInput, "properties", {
697
707
  type: String,
698
708
  reflect: true
699
709
  },
700
- /** @type {ValidityState} */
701
710
  _validity: {
702
711
  state: true
703
712
  }
704
713
  });
705
714
 
706
- export { LeuInput, SIZE_TYPES };
715
+ export { LeuInput, SIZES };
@@ -0,0 +1,7 @@
1
+ declare class LeuElement extends LitElement {
2
+ static define(name: any, constructor?: typeof LeuElement, options?: {}): void;
3
+ }
4
+ declare function _defineProperty(obj: any, key: any, value: any): any;
5
+ import { LitElement } from 'lit';
6
+ export { LeuElement as L, _defineProperty as _ };
7
+ //# sourceMappingURL=LeuElement-ba5ea33d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LeuElement-ba5ea33d.d.ts","sourceRoot":"","sources":["LeuElement-ba5ea33d.js"],"names":[],"mappings":"AA+BA;IACE,8EAMC;CAOF;AA3CD,sEAaC;2BAf0B,KAAK"}
@@ -1,3 +1,5 @@
1
+ import { LitElement } from 'lit';
2
+
1
3
  function _defineProperty(obj, key, value) {
2
4
  key = _toPropertyKey(key);
3
5
  if (key in obj) {
@@ -27,4 +29,21 @@ function _toPropertyKey(arg) {
27
29
  return typeof key === "symbol" ? key : String(key);
28
30
  }
29
31
 
30
- export { _defineProperty as _ };
32
+ class LeuElement extends LitElement {
33
+ static define(name, constructor = this, options = {}) {
34
+ if (!customElements.get(name)) {
35
+ customElements.define(name, constructor, options);
36
+ } else {
37
+ console.info(`${name} is already defined`);
38
+ }
39
+ }
40
+ constructor() {
41
+ super();
42
+ Object.entries(this.constructor.dependencies).forEach(([name, component]) => {
43
+ this.constructor.define(name, component);
44
+ });
45
+ }
46
+ }
47
+ _defineProperty(LeuElement, "dependencies", {});
48
+
49
+ export { LeuElement as L, _defineProperty as _ };
package/dist/Menu.d.ts CHANGED
@@ -1,8 +1,30 @@
1
+ export type SelectsType = 'single' | 'multiple' | 'none';
2
+ /**
3
+ * @typedef {'single' | 'multiple' | 'none'} SelectsType
4
+ */
1
5
  /**
2
6
  * @tagname leu-menu
7
+ * @property {SelectsType} selects - This has only an effect when the role is 'menu'. It defines which role the menu items will get. Default is 'none'.
3
8
  */
4
- export class LeuMenu extends LitElement {
9
+ export class LeuMenu extends LeuElement {
10
+ /** @type {SelectsType} */
11
+ selects: SelectsType;
12
+ value: any;
13
+ _handleSlotChange(): void;
14
+ _setMenuItemRoles(): void;
15
+ /**
16
+ *
17
+ * @returns {import("./MenuItem").LeuMenuItem[]}
18
+ */
19
+ getMenuItems(): import("./MenuItem").LeuMenuItem[];
20
+ getVisibleMenuItems(): LeuMenuItem[];
21
+ _handleKeyDown(event: any): void;
22
+ setCurrentItem(index: any): any;
23
+ focusItem(index: any): void;
24
+ firstUpdated(): void;
25
+ updated(changedProperties: any): void;
5
26
  render(): import("lit-html").TemplateResult<1>;
6
27
  }
7
- import { LitElement } from 'lit';
28
+ import { L as LeuElement } from './LeuElement-ba5ea33d.js';
29
+ import { LeuMenuItem } from './MenuItem.js';
8
30
  //# sourceMappingURL=Menu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["Menu.js"],"names":[],"mappings":"AA0BA;;GAEG;AACH;IACE,+CAEC;CACF;2BAhCqC,KAAK"}
1
+ {"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["Menu.js"],"names":[],"mappings":"0BA8Ba,QAAQ,GAAG,UAAU,GAAG,MAAM;AAD3C;;GAEG;AAEH;;;GAGG;AACH;IAII,0BAA0B;IAC1B,SADW,WAAW,CACD;IACrB,WAAsB;IAaxB,0BAGC;IACD,0BAmBC;IAED;;;OAGG;IACH,gBAFa,OAAO,YAAY,EAAE,WAAW,EAAE,CAO9C;IACD,qCAEC;IACD,iCAgBC;IACD,gCAaC;IACD,4BAGC;IACD,qBAEC;IACD,sCAIC;IACD,+CAEC;CACF;gCA5IqD,0BAA0B;4BAEpD,eAAe"}
package/dist/Menu.js CHANGED
@@ -1,5 +1,8 @@
1
- import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
- import { css, LitElement, html } from 'lit';
1
+ import { _ as _defineProperty, L as LeuElement } from './LeuElement-ba5ea33d.js';
2
+ import { css, html } from 'lit';
3
+ import { LeuMenuItem } from './MenuItem.js';
4
+ import 'lit/directives/if-defined.js';
5
+ import './Icon.js';
3
6
 
4
7
  var css_248z = css`:host,
5
8
  :host * {
@@ -24,14 +27,128 @@ var css_248z = css`:host,
24
27
  }
25
28
  `;
26
29
 
30
+ /**
31
+ * @typedef {'single' | 'multiple' | 'none'} SelectsType
32
+ */
33
+
27
34
  /**
28
35
  * @tagname leu-menu
36
+ * @property {SelectsType} selects - This has only an effect when the role is 'menu'. It defines which role the menu items will get. Default is 'none'.
29
37
  */
30
- class LeuMenu extends LitElement {
38
+ class LeuMenu extends LeuElement {
39
+ constructor() {
40
+ super();
41
+
42
+ /** @type {SelectsType} */
43
+ this.selects = "none";
44
+ this.value = undefined;
45
+ }
46
+ connectedCallback() {
47
+ super.connectedCallback();
48
+ if (!this.getAttribute("role")) {
49
+ this.setAttribute("role", "menu");
50
+ }
51
+ this.addEventListener("keydown", this._handleKeyDown);
52
+ }
53
+ disconnectedCallback() {
54
+ super.disconnectedCallback();
55
+ this.removeEventListener("keydown", this._handleKeyDown);
56
+ }
57
+ _handleSlotChange() {
58
+ this.setCurrentItem(0);
59
+ this._setMenuItemRoles();
60
+ }
61
+ _setMenuItemRoles() {
62
+ const menuRole = this.getAttribute("role");
63
+ let menuItemRole;
64
+ if (menuRole === "menu") {
65
+ if (this.selects === "multiple") {
66
+ menuItemRole = "menuitemcheckbox";
67
+ } else if (this.selects === "single") {
68
+ menuItemRole = "menuitemradio";
69
+ } else {
70
+ menuItemRole = "menuitem";
71
+ }
72
+ } else if (menuRole === "listbox") {
73
+ menuItemRole = "option";
74
+ }
75
+ if (menuItemRole) {
76
+ this.getMenuItems().forEach(menuItem => {
77
+ menuItem.componentRole = menuItemRole; // eslint-disable-line no-param-reassign
78
+ });
79
+ }
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @returns {import("./MenuItem").LeuMenuItem[]}
85
+ */
86
+ getMenuItems() {
87
+ const slot = this.shadowRoot.querySelector("slot");
88
+ return slot.assignedElements({
89
+ flatten: true
90
+ }).filter(el => el instanceof LeuMenuItem);
91
+ }
92
+ getVisibleMenuItems() {
93
+ return this.getMenuItems().filter(menuItem => !menuItem.hidden);
94
+ }
95
+ _handleKeyDown(event) {
96
+ if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
97
+ event.preventDefault();
98
+ const menuItems = this.getVisibleMenuItems();
99
+ let index = menuItems.findIndex(menuItem => menuItem.tabbable);
100
+ if (event.key === "ArrowDown") {
101
+ index += 1;
102
+ } else if (event.key === "ArrowUp") {
103
+ index -= 1;
104
+ } else if (event.key === "Home") {
105
+ index = 0;
106
+ } else if (event.key === "End") {
107
+ index = menuItems.length - 1;
108
+ }
109
+ this.focusItem(index);
110
+ }
111
+ }
112
+ setCurrentItem(index) {
113
+ const menuItems = this.getVisibleMenuItems();
114
+ let currentItem = null;
115
+ const currentItemIndex = (index + menuItems.length) % menuItems.length;
116
+ menuItems.forEach((menuItem, i) => {
117
+ if (i === currentItemIndex) {
118
+ currentItem = menuItem;
119
+ menuItem.tabbable = true; // eslint-disable-line no-param-reassign
120
+ } else {
121
+ menuItem.tabbable = false; // eslint-disable-line no-param-reassign
122
+ }
123
+ });
124
+ return currentItem;
125
+ }
126
+ focusItem(index) {
127
+ const currentItem = this.setCurrentItem(index);
128
+ currentItem.focus();
129
+ }
130
+ firstUpdated() {
131
+ this.setCurrentItem(0);
132
+ }
133
+ updated(changedProperties) {
134
+ if (changedProperties.has("selects")) {
135
+ this._setMenuItemRoles();
136
+ }
137
+ }
31
138
  render() {
32
139
  return html`<slot></slot>`;
33
140
  }
34
141
  }
35
142
  _defineProperty(LeuMenu, "styles", css_248z);
143
+ _defineProperty(LeuMenu, "shadowRootOptions", {
144
+ ...LeuElement.shadowRootOptions,
145
+ delegatesFocus: true
146
+ });
147
+ _defineProperty(LeuMenu, "properties", {
148
+ selects: {
149
+ type: String,
150
+ reflect: true
151
+ }
152
+ });
36
153
 
37
154
  export { LeuMenu };
@@ -1,21 +1,38 @@
1
+ export type MenuItemRole = 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'option' | 'none';
2
+ /**
3
+ * @typedef {'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'option' | 'none'} MenuItemRole
4
+ */
1
5
  /**
2
6
  * @tagname leu-menu-item
3
7
  * @slot - The label of the menu item
8
+ * @property {boolean} active - Defines if the item is selected or checked
9
+ * @property {boolean} disabled - Disables the underlying button or link
10
+ * @property {string} value - The value of the item. It must not contain commas. See `getValue()`
11
+ * @property {string} href - The href of the underlying link
12
+ * @property {boolean} tabbable - If the item should be focusable. Will be reflected as `tabindex` to the underlying button or link
13
+ * @property {MenuItemRole} componentRole - The role of the item. This will be reflected as `role` to the underlying button or link. Default is `'menuitem'.`
4
14
  */
5
- export class LeuMenuItem extends LitElement {
6
- static getIconOrText(name: any): any;
15
+ export class LeuMenuItem extends LeuElement {
7
16
  active: boolean;
8
17
  disabled: boolean;
18
+ value: any;
19
+ href: any;
20
+ tabbable: any;
21
+ /** @type {MenuItemRole} */
22
+ componentRole: MenuItemRole;
23
+ _handleClick(event: any): void;
9
24
  /**
10
- * A programmatic way to highlight the menu item like it is hovered.
11
- * This is just a visual effect and does not change the active state.
25
+ * Returns the value of the item. If `value` is not set, it will return the inner text
26
+ * @returns {string}
12
27
  */
13
- highlighted: boolean;
14
- renderBefore(): typeof nothing | import("lit-html").TemplateResult;
15
- renderAfter(): typeof nothing | import("lit-html").TemplateResult;
16
- getTagName(): "button" | "a";
17
- render(): import("lit-html").TemplateResult;
28
+ getValue(): string;
29
+ _getAria(): {
30
+ disabled: boolean;
31
+ };
32
+ _getTabIndex(): 0 | -1;
33
+ _renderLink(content: any): import("lit-html").TemplateResult<1>;
34
+ _renderButton(content: any): import("lit-html").TemplateResult<1>;
35
+ render(): import("lit-html").TemplateResult<1>;
18
36
  }
19
- import { LitElement } from 'lit';
20
- import { nothing } from 'lit';
37
+ import { L as LeuElement } from './LeuElement-ba5ea33d.js';
21
38
  //# sourceMappingURL=MenuItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["MenuItem.js"],"names":[],"mappings":"AAsFA;;;GAGG;AACH;IAYE,qCAQC;IAjBC,gBAAmB;IACnB,kBAAqB;IAErB;;;OAGG;IACH,qBAAwB;IAW1B,mEAMC;IACD,kEAMC;IACD,6BAEC;IACD,4CAQC;CACF;2BAxIwC,KAAK;wBAAL,KAAK"}
1
+ {"version":3,"file":"MenuItem.d.ts","sourceRoot":"","sources":["MenuItem.js"],"names":[],"mappings":"2BA8Fa,UAAU,GAAG,kBAAkB,GAAG,eAAe,GAAG,QAAQ,GAAG,MAAM;AADlF;;GAEG;AAEH;;;;;;;;;GASG;AACH;IAGI,gBAAmB;IACnB,kBAAqB;IACrB,WAAsB;IACtB,UAAqB;IACrB,cAAyB;IAEzB,2BAA2B;IAC3B,eADW,YAAY,CACQ;IAUjC,+BAKC;IAED;;;OAGG;IACH,YAFa,MAAM,CAIlB;IACD;;MAaC;IACD,uBAKC;IACD,gEAYC;IACD,kEAYC;IACD,+CAOC;CACF;gCAnMqD,0BAA0B"}