@statistikzh/leu 0.2.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 +43 -0
  10. package/README.md +1 -1
  11. package/dist/Button.js +39 -30
  12. package/dist/ButtonGroup.js +5 -7
  13. package/dist/Checkbox.js +107 -88
  14. package/dist/CheckboxGroup.js +43 -38
  15. package/dist/{Chip-389013ff.js → Chip-dac7337d.js} +7 -2
  16. package/dist/ChipGroup.js +4 -6
  17. package/dist/ChipLink.js +6 -8
  18. package/dist/ChipRemovable.js +4 -7
  19. package/dist/ChipSelectable.js +10 -10
  20. package/dist/Dropdown.js +57 -27
  21. package/dist/Input.js +59 -43
  22. package/dist/Menu.js +2 -5
  23. package/dist/MenuItem.js +34 -17
  24. package/dist/Pagination.js +57 -55
  25. package/dist/Radio.js +13 -10
  26. package/dist/RadioGroup.js +43 -40
  27. package/dist/Select.js +57 -44
  28. package/dist/Table.js +147 -125
  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 +29 -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 +3 -9
  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 +22 -27
  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 +9 -89
  73. package/src/components/checkbox/CheckboxGroup.js +9 -39
  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 +2 -1
  83. package/src/components/chip/ChipGroup.js +1 -6
  84. package/src/components/chip/ChipLink.js +2 -8
  85. package/src/components/chip/ChipRemovable.js +1 -6
  86. package/src/components/chip/ChipSelectable.js +4 -9
  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 +53 -25
  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 +33 -39
  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 +22 -15
  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 +5 -10
  132. package/src/components/radio/RadioGroup.js +7 -39
  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 +35 -32
  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 +48 -123
  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
package/dist/Input.js CHANGED
@@ -1,7 +1,8 @@
1
- import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
2
  import { css, LitElement, 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
+ import { live } from 'lit/directives/live.js';
5
6
  import { createRef, ref } from 'lit/directives/ref.js';
6
7
  import { I as Icon } from './icon-03e86700.js';
7
8
 
@@ -137,6 +138,7 @@ var css_248z = css`:host,
137
138
 
138
139
  /* is size regular AND (has focus OR contains a value) */
139
140
 
141
+ .input-wrapper--invalid .label,
140
142
  :host(:not([size])) .label,
141
143
  :host([size="regular"]) .label {
142
144
  top: calc(0.75rem - var(--input-border-width));
@@ -161,20 +163,22 @@ var css_248z = css`:host,
161
163
  content: "*";
162
164
  }
163
165
 
166
+ /* is not disabled AND has focus AND is empty */
167
+
168
+ :host(:not([disabled]):not(:focus-within)) .input-wrapper--empty .label {
169
+ --input-label-color: var(--input-label-color-empty);
170
+ }
171
+
164
172
  /* is empty AND has no focus */
165
173
 
166
- :host(:not(:focus-within)) .input-wrapper--empty .label {
174
+ :host(:not(:focus-within))
175
+ .input-wrapper--empty:not(.input-wrapper--invalid)
176
+ .label {
167
177
  font-family: var(--input-font-regular);
168
178
  font-size: 1rem;
169
179
  top: calc(1.5rem - var(--input-border-width));
170
180
  }
171
181
 
172
- /* is not disabled AND has focus AND is empty */
173
-
174
- :host(:not([disabled]):not(:focus-within)) .input-wrapper--empty .label {
175
- --input-label-color: var(--input-label-color-empty);
176
- }
177
-
178
182
  /* is size small AND has no focus AND is empty */
179
183
 
180
184
  :host(:not(:focus-within)[size="small"]) .input-wrapper--empty .label {
@@ -335,16 +339,9 @@ class LeuInput extends LitElement {
335
339
  this.disabled = false;
336
340
  this.required = false;
337
341
  this.clearable = false;
338
- this.value = "";
339
- this.name = "";
340
- this.error = "";
341
- this.label = "";
342
- this.prefix = "";
343
- this.suffix = "";
344
342
 
345
343
  /** @type {keyof typeof SIZE_TYPES} */
346
344
  this.size = SIZE_TYPES.REGULAR;
347
- this.icon = "";
348
345
  this.type = "text";
349
346
  this._validity = null;
350
347
  this.validationMessages = {};
@@ -415,7 +412,9 @@ class LeuInput extends LitElement {
415
412
  * @returns {void}
416
413
  */
417
414
  handleChange(event) {
418
- this.value = event.target.value;
415
+ if (event.target.validity.valid) {
416
+ this.value = event.target.value;
417
+ }
419
418
  const customEvent = new CustomEvent(event.type, event);
420
419
  this.dispatchEvent(customEvent);
421
420
  }
@@ -430,6 +429,11 @@ class LeuInput extends LitElement {
430
429
  */
431
430
  handleInput(event) {
432
431
  this.value = event.target.value;
432
+ const customEvent = new CustomEvent("input", {
433
+ bubbles: true,
434
+ composed: true
435
+ });
436
+ this.dispatchEvent(customEvent);
433
437
  }
434
438
 
435
439
  /**
@@ -537,7 +541,7 @@ class LeuInput extends LitElement {
537
541
  if (this.isInvalid()) {
538
542
  return html`<div class="error-icon">${Icon("caution")}</div>`;
539
543
  }
540
- if (this.clearable && this.value !== "") {
544
+ if (this.clearable && this.value) {
541
545
  return html`<button
542
546
  class="clear-button"
543
547
  @click=${this.clear}
@@ -547,13 +551,13 @@ class LeuInput extends LitElement {
547
551
  ${this._clearIcon}
548
552
  </button>`;
549
553
  }
550
- if (this.icon !== "") {
554
+ if (this.icon) {
551
555
  return html`<div class="icon">${Icon(this.icon)}</div>`;
552
556
  }
553
557
  return nothing;
554
558
  }
555
559
  isInvalid() {
556
- if (this.error !== "") {
560
+ if (this.error) {
557
561
  return true;
558
562
  }
559
563
  return this._validity === null || this.novalidate ? false : !this._validity.valid;
@@ -562,7 +566,7 @@ class LeuInput extends LitElement {
562
566
  const isInvalid = this.isInvalid();
563
567
  const inputWrapperClasses = {
564
568
  "input-wrapper": true,
565
- "input-wrapper--empty": this.value === "",
569
+ "input-wrapper--empty": !this.value,
566
570
  "input-wrapper--invalid": isInvalid
567
571
  };
568
572
 
@@ -584,18 +588,18 @@ class LeuInput extends LitElement {
584
588
  @invalid=${this.handleInvalid}
585
589
  ?disabled=${this.disabled}
586
590
  ?required=${this.required}
591
+ .value=${live(this.value ?? "")}
587
592
  pattern=${ifDefined(this.pattern)}
588
593
  min=${ifDefined(this.min)}
589
594
  max=${ifDefined(this.max)}
590
595
  maxlength=${ifDefined(this.maxlength)}
591
596
  minlength=${ifDefined(this.minlength)}
592
- .value=${this.value}
593
597
  ref=${ref(this._inputRef)}
594
598
  aria-invalid=${isInvalid}
595
599
  />
596
- <label for="input-${this.getId()}" class="label"><slot></slot></label>
597
- ${this.prefix !== "" ? html`<div class="prefix" .aria-hidden=${true}>${this.prefix}</div>` : nothing}
598
- ${this.suffix !== "" ? html`<div class="suffix" .aria-hidden=${true}>${this.suffix}</div>` : nothing}
600
+ <label for="input-${this.getId()}" class="label">${this.label}</label>
601
+ ${this.prefix ? html`<div class="prefix" .aria-hidden=${true}>${this.prefix}</div>` : nothing}
602
+ ${this.suffix ? html`<div class="suffix" .aria-hidden=${true}>${this.suffix}</div>` : nothing}
599
603
  ${this.renderAfterContent()}
600
604
  </div>
601
605
  ${this.renderErrorMessages()}
@@ -624,61 +628,73 @@ _defineProperty(LeuInput, "properties", {
624
628
  reflect: true
625
629
  },
626
630
  value: {
627
- type: String
631
+ type: String,
632
+ reflect: true
628
633
  },
629
634
  name: {
630
- type: String
635
+ type: String,
636
+ reflect: true
631
637
  },
632
638
  error: {
633
- type: String
639
+ type: String,
640
+ reflect: true
634
641
  },
635
642
  label: {
636
- type: String
643
+ type: String,
644
+ reflect: true
637
645
  },
638
646
  prefix: {
639
- type: String
647
+ type: String,
648
+ reflect: true
640
649
  },
641
650
  suffix: {
642
- type: String
651
+ type: String,
652
+ reflect: true
643
653
  },
644
654
  size: {
645
- type: String
655
+ type: String,
656
+ reflect: true
646
657
  },
647
658
  icon: {
648
- type: String
659
+ type: String,
660
+ reflect: true
649
661
  },
650
662
  /* Validation attributes */
651
663
  pattern: {
652
- type: String
664
+ type: String,
665
+ reflect: true
653
666
  },
654
667
  type: {
655
- type: String
668
+ type: String,
669
+ reflect: true
656
670
  },
657
671
  min: {
658
- type: Number
672
+ type: Number,
673
+ reflect: true
659
674
  },
660
675
  max: {
661
- type: Number
676
+ type: Number,
677
+ reflect: true
662
678
  },
663
679
  maxlength: {
664
- type: Number
680
+ type: Number,
681
+ reflect: true
665
682
  },
666
683
  minlength: {
667
- type: Number
684
+ type: Number,
685
+ reflect: true
668
686
  },
669
687
  validationMessages: {
670
688
  type: Object
671
689
  },
672
690
  novalidate: {
673
- type: Boolean
691
+ type: Boolean,
692
+ reflect: true
674
693
  },
675
694
  /** @type {ValidityState} */
676
695
  _validity: {
677
696
  state: true
678
697
  }
679
698
  });
680
- function defineInputElements() {
681
- defineElement("input", LeuInput);
682
- }
683
699
 
684
- export { LeuInput, SIZE_TYPES, defineInputElements };
700
+ export { LeuInput, SIZE_TYPES };
package/dist/Menu.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
2
  import { css, LitElement, html } from 'lit';
3
3
 
4
4
  var css_248z = css`:host,
@@ -33,8 +33,5 @@ class LeuMenu extends LitElement {
33
33
  }
34
34
  }
35
35
  _defineProperty(LeuMenu, "styles", css_248z);
36
- function defineMenuElements() {
37
- defineElement("menu", LeuMenu);
38
- }
39
36
 
40
- export { LeuMenu, defineMenuElements };
37
+ export { LeuMenu };
package/dist/MenuItem.js CHANGED
@@ -1,5 +1,7 @@
1
- import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
2
- import { css, LitElement, html, nothing } from 'lit';
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
+ import { css, LitElement, nothing } from 'lit';
3
+ import { html, unsafeStatic } from 'lit/static-html.js';
4
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
5
  import { a as ICON_NAMES, I as Icon } from './icon-03e86700.js';
4
6
 
5
7
  var css_248z = css`:host,
@@ -11,15 +13,18 @@ var css_248z = css`:host,
11
13
  --background: var(--leu-color-black-0);
12
14
  --background-hover: var(--leu-color-black-10);
13
15
  --background-active: var(--leu-color-func-cyan);
14
- --background-disabled: var(--leu-color-black-0);
16
+ --background-disabled: var(--leu-color-black-black-0);
15
17
  --color: var(--leu-color-black-transp-60);
18
+ --color-disabled: var(--leu-color-black-transp-20);
16
19
  --font-regular: var(--leu-font-regular);
17
20
  --font-black: var(--leu-font-black);
18
21
 
19
- font-family: var(--chip-font-regular);
22
+ font-family: var(--leu-font-regular);
20
23
  }
21
24
 
22
25
  .button {
26
+ -webkit-text-decoration: none;
27
+ text-decoration: none;
23
28
  -webkit-appearance: none;
24
29
  -moz-appearance: none;
25
30
  appearance: none;
@@ -57,6 +62,7 @@ var css_248z = css`:host,
57
62
 
58
63
  :host([disabled]) .button {
59
64
  --background: var(--background-disabled);
65
+ --color: var(--color-disabled);
60
66
  cursor: default;
61
67
  }
62
68
 
@@ -87,8 +93,6 @@ class LeuMenuItem extends LitElement {
87
93
  super();
88
94
  this.active = false;
89
95
  this.disabled = false;
90
- this.before = "";
91
- this.after = "";
92
96
 
93
97
  /**
94
98
  * A programmatic way to highlight the menu item like it is hovered.
@@ -106,24 +110,30 @@ class LeuMenuItem extends LitElement {
106
110
  return name;
107
111
  }
108
112
  renderBefore() {
109
- if (this.before !== "") {
113
+ if (this.before) {
110
114
  const content = LeuMenuItem.getIconOrText(this.before);
111
115
  return html`<span class="before">${content}</span>`;
112
116
  }
113
117
  return nothing;
114
118
  }
115
119
  renderAfter() {
116
- if (this.after !== "") {
120
+ if (this.after) {
117
121
  const content = LeuMenuItem.getIconOrText(this.after);
118
122
  return html`<span class="after">${content}</span>`;
119
123
  }
120
124
  return nothing;
121
125
  }
126
+ getTagName() {
127
+ return this.href ? "a" : "button";
128
+ }
122
129
  render() {
123
- return html`<button class="button" ?disabled=${this.disabled}>
124
- ${this.renderBefore()}<span class="label"><slot></slot></span
130
+ /* The eslint rules don't recognize html import from lit/static-html.js */
131
+ /* eslint-disable lit/binding-positions, lit/no-invalid-html */
132
+ return html`<${unsafeStatic(this.getTagName())} class="button" href=${ifDefined(this.href)} ?disabled=${this.disabled}>
133
+ ${this.renderBefore()}<span class="label">${this.label}</span
125
134
  >${this.renderAfter()}
126
- </button>`;
135
+ </${unsafeStatic(this.getTagName())}>`;
136
+ /* eslint-enable lit/binding-positions, lit/no-invalid-html */
127
137
  }
128
138
  }
129
139
  _defineProperty(LeuMenuItem, "styles", css_248z);
@@ -141,7 +151,8 @@ _defineProperty(LeuMenuItem, "properties", {
141
151
  * If the value is "EMPTY", an empty placeholder with the size of an icon will be displayed.
142
152
  */
143
153
  before: {
144
- type: String
154
+ type: String,
155
+ reflect: true
145
156
  },
146
157
  /**
147
158
  * Can be either an icon name or a text
@@ -149,7 +160,8 @@ _defineProperty(LeuMenuItem, "properties", {
149
160
  * If the value is "EMPTY", an empty placeholder with the size of an icon will be displayed.
150
161
  */
151
162
  after: {
152
- type: String
163
+ type: String,
164
+ reflect: true
153
165
  },
154
166
  active: {
155
167
  type: Boolean,
@@ -162,10 +174,15 @@ _defineProperty(LeuMenuItem, "properties", {
162
174
  disabled: {
163
175
  type: Boolean,
164
176
  reflect: true
177
+ },
178
+ label: {
179
+ type: String,
180
+ reflect: true
181
+ },
182
+ href: {
183
+ type: String,
184
+ reflect: true
165
185
  }
166
186
  });
167
- function defineMenuItemElements() {
168
- defineElement("menu-item", LeuMenuItem);
169
- }
170
187
 
171
- export { LeuMenuItem, defineMenuItemElements };
188
+ export { LeuMenuItem };
@@ -1,6 +1,9 @@
1
- import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
2
  import { css, LitElement, html } from 'lit';
3
- import { defineButtonElements } from './Button.js';
3
+ import { live } from 'lit/directives/live.js';
4
+ import './leu-button.js';
5
+ import './defineElement-47d4f665.js';
6
+ import './Button.js';
4
7
  import 'lit/directives/class-map.js';
5
8
  import './icon-03e86700.js';
6
9
 
@@ -71,36 +74,47 @@ class LeuPagination extends LitElement {
71
74
  /** @type {number} */
72
75
  this.page = 1;
73
76
  /** @type {number} */
74
- this.dataLength = 0;
77
+ this.numOfItems = 1;
75
78
  /** @type {number} */
76
- this.itemsOnAPage = 30;
79
+ this.itemsPerPage = 1;
77
80
  }
78
81
  get maxPage() {
79
- return Math.ceil(this.dataLength / this.itemsOnAPage);
82
+ return Math.ceil(this.numOfItems / this.itemsPerPage);
80
83
  }
81
84
  get firstPage() {
82
- return this.page === MIN_PAGE;
85
+ return this.boundPage === MIN_PAGE;
83
86
  }
84
87
  get lastPage() {
85
- return this.page === this.maxPage;
88
+ return this.boundPage === this.maxPage;
86
89
  }
87
- holdInRange(value) {
88
- return Math.min(Math.max(value, MIN_PAGE), this.maxPage);
90
+
91
+ /**
92
+ * The boundPage getter is necessary to ensure that the current page (this.page) is always within the valid range of pages.
93
+ * It prevents the page number from going below the minimum page limit (MIN_PAGE) or above the maximum page limit (this.maxPage).
94
+ * This is important for the correct functioning of the pagination system, as it prevents users from navigating to non-existent pages.
95
+ *
96
+ * @returns {number}
97
+ */
98
+ get boundPage() {
99
+ return Math.min(Math.max(this.page, MIN_PAGE), this.maxPage);
89
100
  }
90
101
  numberUpdate(number) {
91
- this.page = this.holdInRange(number);
92
- const min = (this.page - 1) * this.itemsOnAPage;
93
- const max = Math.min(min + this.itemsOnAPage, this.dataLength);
94
- this.dispatchEvent(new CustomEvent("range-updated", {
95
- detail: {
96
- min,
97
- max
98
- },
99
- bubbles: false
100
- }));
102
+ const prevPage = this.page;
103
+ this.page = number;
104
+ if (this.page !== prevPage) {
105
+ const startIndex = (this.boundPage - 1) * this.itemsPerPage;
106
+ const endIndex = Math.min(startIndex + this.itemsPerPage, this.numOfItems);
107
+ this.dispatchEvent(new CustomEvent("leu:pagechange", {
108
+ detail: {
109
+ startIndex,
110
+ endIndex,
111
+ page: this.boundPage
112
+ },
113
+ bubbles: false
114
+ }));
115
+ }
101
116
  }
102
117
  change(event) {
103
- // target.value = this.page // eslint-disable-line
104
118
  this.numberUpdate(parseInt(event.target.value, 10) || 0);
105
119
  }
106
120
  input(event) {
@@ -110,35 +124,22 @@ class LeuPagination extends LitElement {
110
124
  }
111
125
  }
112
126
  keydown(event) {
113
- const specialKeys = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Backspace", "Enter", "Tab"];
114
- const numberKeys = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
115
- if (!numberKeys.includes(event.key) && !specialKeys.includes(event.key)) {
127
+ if (event.key === "ArrowUp") {
116
128
  event.preventDefault();
117
- } else {
118
- if (event.key === "ArrowUp") {
119
- event.preventDefault();
120
- this.numberUpdate(this.page + 1);
121
- }
122
- if (event.key === "ArrowDown") {
123
- event.preventDefault();
124
- this.numberUpdate(this.page - 1);
125
- }
129
+ this.numberUpdate(this.boundPage + 1);
126
130
  }
127
- }
128
- firstUpdated() {
129
- this.numberUpdate(this.page);
130
- }
131
- requestUpdate(name, oldValue, newValue) {
132
- if (name === "itemsOnAPage") {
133
- this.numberUpdate(this.page);
131
+ if (event.key === "ArrowDown") {
132
+ event.preventDefault();
133
+ this.numberUpdate(this.boundPage - 1);
134
134
  }
135
- return super.requestUpdate(name, oldValue, newValue);
136
135
  }
137
136
  render() {
138
137
  return html`
139
138
  <input
140
139
  class="input"
141
- .value=${this.page}
140
+ min=${MIN_PAGE}
141
+ max=${this.maxPage}
142
+ .value=${live(this.boundPage.toString())}
142
143
  @input=${this.input}
143
144
  @change=${this.change}
144
145
  @keydown=${this.keydown}
@@ -149,7 +150,7 @@ class LeuPagination extends LitElement {
149
150
  icon="angleLeft"
150
151
  variant="secondary"
151
152
  @click=${_ => {
152
- this.numberUpdate(this.page - 1);
153
+ this.numberUpdate(this.boundPage - 1);
153
154
  }}
154
155
  ?disabled=${this.firstPage}
155
156
  ></leu-button>
@@ -157,7 +158,7 @@ class LeuPagination extends LitElement {
157
158
  icon="angleRight"
158
159
  variant="secondary"
159
160
  @click=${_ => {
160
- this.numberUpdate(this.page + 1);
161
+ this.numberUpdate(this.boundPage + 1);
161
162
  }}
162
163
  ?disabled=${this.lastPage}
163
164
  style="margin-left:4px;"
@@ -166,6 +167,13 @@ class LeuPagination extends LitElement {
166
167
  }
167
168
  }
168
169
  _defineProperty(LeuPagination, "styles", css_248z);
170
+ /**
171
+ * @internal
172
+ */
173
+ _defineProperty(LeuPagination, "shadowRootOptions", {
174
+ ...LitElement.shadowRootOptions,
175
+ delegatesFocus: true
176
+ });
169
177
  _defineProperty(LeuPagination, "events", {
170
178
  range: {}
171
179
  });
@@ -174,20 +182,14 @@ _defineProperty(LeuPagination, "properties", {
174
182
  type: Number,
175
183
  reflect: true
176
184
  },
177
- itemsOnAPage: {
178
- type: Number
179
- },
180
- dataLength: {
181
- type: Number
185
+ itemsPerPage: {
186
+ type: Number,
187
+ reflect: true
182
188
  },
183
- _minPage: {
189
+ numOfItems: {
184
190
  type: Number,
185
- state: true
191
+ reflect: true
186
192
  }
187
193
  });
188
- function definePaginationElements() {
189
- defineButtonElements();
190
- defineElement("pagination", LeuPagination);
191
- }
192
194
 
193
- export { LeuPagination, definePaginationElements };
195
+ export { LeuPagination };
package/dist/Radio.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
1
+ import { _ as _defineProperty } from './_rollupPluginBabelHelpers-20f659f4.js';
2
2
  import { css, LitElement, html } from 'lit';
3
3
 
4
4
  var css_248z = css`:host {
@@ -102,7 +102,6 @@ class LeuRadio extends LitElement {
102
102
  super();
103
103
  this.checked = false;
104
104
  this.disabled = false;
105
- this.tabIndex = 0;
106
105
  }
107
106
  handleChange(event) {
108
107
  this.checked = event.target.checked;
@@ -125,7 +124,7 @@ class LeuRadio extends LitElement {
125
124
  ?disabled=${this.disabled}
126
125
  .value=${this.value}
127
126
  />
128
- <label for=${this.identifier} class="label"><slot></slot></label>
127
+ <label for=${this.identifier} class="label">${this.label}</label>
129
128
  `;
130
129
  }
131
130
  }
@@ -144,17 +143,21 @@ _defineProperty(LeuRadio, "properties", {
144
143
  reflect: true
145
144
  },
146
145
  identifier: {
147
- type: String
146
+ type: String,
147
+ reflect: true
148
148
  },
149
149
  value: {
150
- type: String
150
+ type: String,
151
+ reflect: true
151
152
  },
152
153
  name: {
153
- type: String
154
+ type: String,
155
+ reflect: true
156
+ },
157
+ label: {
158
+ type: String,
159
+ reflect: true
154
160
  }
155
161
  });
156
- function defineRadioElements() {
157
- defineElement("radio", LeuRadio);
158
- }
159
162
 
160
- export { LeuRadio, defineRadioElements };
163
+ export { LeuRadio };