@statistikzh/leu 0.0.2 → 0.2.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 (59) hide show
  1. package/.github/workflows/release-please.yml +20 -1
  2. package/CHANGELOG.md +30 -0
  3. package/README.md +27 -2
  4. package/babel.config.json +3 -0
  5. package/dist/{Button-83c6df93.js → Button.js} +58 -50
  6. package/dist/ButtonGroup.js +75 -0
  7. package/dist/Checkbox.js +60 -57
  8. package/dist/CheckboxGroup.js +35 -41
  9. package/dist/{Chip-60af1402.js → Chip-389013ff.js} +12 -13
  10. package/dist/ChipGroup.js +27 -34
  11. package/dist/ChipLink.js +18 -19
  12. package/dist/ChipRemovable.js +9 -13
  13. package/dist/ChipSelectable.js +42 -44
  14. package/dist/Dropdown.js +75 -0
  15. package/dist/Input.js +120 -122
  16. package/dist/Menu.js +40 -0
  17. package/dist/MenuItem.js +171 -0
  18. package/dist/Pagination.js +193 -0
  19. package/dist/Radio.js +26 -22
  20. package/dist/RadioGroup.js +75 -105
  21. package/dist/Select.js +125 -343
  22. package/dist/Table.js +294 -8
  23. package/dist/defineElement-ba770aed.js +44 -0
  24. package/dist/icon-03e86700.js +136 -0
  25. package/dist/index.js +14 -9
  26. package/dist/leu-button-group.js +8 -0
  27. package/dist/leu-button.js +7 -0
  28. package/dist/leu-checkbox-group.js +1 -1
  29. package/dist/leu-checkbox.js +2 -2
  30. package/dist/leu-chip-group.js +1 -1
  31. package/dist/leu-chip-link.js +2 -2
  32. package/dist/leu-chip-removable.js +3 -3
  33. package/dist/leu-chip-selectable.js +2 -2
  34. package/dist/leu-dropdown.js +10 -0
  35. package/dist/leu-input.js +2 -2
  36. package/dist/leu-menu-item.js +6 -0
  37. package/dist/leu-menu.js +5 -0
  38. package/dist/leu-pagination.js +8 -0
  39. package/dist/leu-radio-group.js +1 -1
  40. package/dist/leu-radio.js +1 -1
  41. package/dist/leu-select.js +5 -3
  42. package/dist/leu-table.js +5 -4
  43. package/dist/theme.css +7 -7
  44. package/index.js +7 -3
  45. package/package.json +3 -1
  46. package/rollup.config.js +26 -9
  47. package/src/components/accordion/Accordion.js +102 -0
  48. package/src/components/accordion/accordion.css +160 -0
  49. package/src/components/accordion/leu-accordion.js +3 -0
  50. package/src/components/accordion/stories/accordion.stories.js +55 -0
  51. package/src/components/accordion/test/accordion.test.js +22 -0
  52. package/src/components/input/Input.js +10 -0
  53. package/src/components/menu/menu.css +9 -3
  54. package/src/components/select/Select.js +28 -8
  55. package/src/styles/custom-properties.css +7 -7
  56. package/.github/workflows/publish.yml +0 -19
  57. package/dist/Table-72d305d7.js +0 -506
  58. package/dist/defineElement-47d4f665.js +0 -15
  59. package/dist/icon-b68c7e1e.js +0 -202
package/dist/Input.js CHANGED
@@ -1,9 +1,9 @@
1
+ import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
1
2
  import { css, LitElement, nothing, html } from 'lit';
2
3
  import { classMap } from 'lit/directives/class-map.js';
3
4
  import { ifDefined } from 'lit/directives/if-defined.js';
4
5
  import { createRef, ref } from 'lit/directives/ref.js';
5
- import { I as Icon } from './icon-b68c7e1e.js';
6
- import { d as defineElement } from './defineElement-47d4f665.js';
6
+ import { I as Icon } from './icon-03e86700.js';
7
7
 
8
8
  var css_248z = css`:host,
9
9
  :host * {
@@ -273,7 +273,7 @@ var css_248z = css`:host,
273
273
 
274
274
  const SIZE_TYPES = {
275
275
  SMALL: "small",
276
- REGULAR: "regular",
276
+ REGULAR: "regular"
277
277
  };
278
278
 
279
279
  /**
@@ -286,15 +286,13 @@ const SIZE_TYPES = {
286
286
  const VALIDATION_MESSAGES = {
287
287
  badInput: "Bitte überprüfen Sie das Format.",
288
288
  patternMismatch: "Bitte überprüfen Sie das Format.",
289
- rangeOverflow: (max) => `Der Wert darf nicht grösser als ${max} sein.`,
290
- rangeUnderflow: (min) => `Der Wert darf nicht kleiner als ${min} sein.`,
289
+ rangeOverflow: max => `Der Wert darf nicht grösser als ${max} sein.`,
290
+ rangeUnderflow: min => `Der Wert darf nicht kleiner als ${min} sein.`,
291
291
  stepMismatch: "Bitte überprüfen Sie das Format.",
292
- tooLong: (maxlength) =>
293
- `Die Eingabe muss kürzer als ${maxlength} Zeichen sein.`,
294
- tooShort: (minlength) =>
295
- `Die Eingabe muss länger als ${minlength} Zeichen sein.`,
292
+ tooLong: maxlength => `Die Eingabe muss kürzer als ${maxlength} Zeichen sein.`,
293
+ tooShort: minlength => `Die Eingabe muss länger als ${minlength} Zeichen sein.`,
296
294
  typeMismatch: "Bitte überprüfen Sie das Format.",
297
- valueMissing: "Bitte füllen Sie das Feld aus.",
295
+ valueMissing: "Bitte füllen Sie das Feld aus."
298
296
  };
299
297
 
300
298
  /**
@@ -326,65 +324,27 @@ const VALIDATION_MESSAGES = {
326
324
  * @tagname leu-input
327
325
  */
328
326
  class LeuInput extends LitElement {
329
- static styles = css_248z
330
-
331
- static properties = {
332
- disabled: { type: Boolean, reflect: true },
333
- required: { type: Boolean, reflect: true },
334
- clearable: { type: Boolean, reflect: true },
335
-
336
- value: { type: String },
337
- name: { type: String },
338
- error: { type: String },
339
-
340
- label: { type: String },
341
- prefix: { type: String },
342
- suffix: { type: String },
343
- size: { type: String },
344
- icon: { type: String },
345
-
346
- /* Validation attributes */
347
- pattern: { type: String },
348
- type: { type: String },
349
- min: { type: Number },
350
- max: { type: Number },
351
- maxlength: { type: Number },
352
- minlength: { type: Number },
353
- validationMessages: { type: Object },
354
- novalidate: { type: Boolean },
355
-
356
- /** @type {ValidityState} */
357
- _validity: { state: true },
358
- }
359
-
360
327
  static resolveErrorMessage(message, refernceValue) {
361
328
  if (typeof message === "function") {
362
- return message(refernceValue)
329
+ return message(refernceValue);
363
330
  }
364
-
365
- return message
331
+ return message;
366
332
  }
367
-
368
333
  constructor() {
369
334
  super();
370
-
371
335
  this.disabled = false;
372
336
  this.required = false;
373
337
  this.clearable = false;
374
-
375
338
  this.value = "";
376
339
  this.name = "";
377
340
  this.error = "";
378
-
379
341
  this.label = "";
380
342
  this.prefix = "";
381
343
  this.suffix = "";
382
344
 
383
345
  /** @type {keyof typeof SIZE_TYPES} */
384
346
  this.size = SIZE_TYPES.REGULAR;
385
-
386
347
  this.icon = "";
387
-
388
348
  this.type = "text";
389
349
  this._validity = null;
390
350
  this.validationMessages = {};
@@ -429,7 +389,6 @@ class LeuInput extends LitElement {
429
389
  */
430
390
  handleBlur(event) {
431
391
  this._validity = null;
432
-
433
392
  if (!this.novalidate) {
434
393
  event.target.checkValidity();
435
394
  }
@@ -457,7 +416,6 @@ class LeuInput extends LitElement {
457
416
  */
458
417
  handleChange(event) {
459
418
  this.value = event.target.value;
460
-
461
419
  const customEvent = new CustomEvent(event.type, event);
462
420
  this.dispatchEvent(customEvent);
463
421
  }
@@ -485,13 +443,15 @@ class LeuInput extends LitElement {
485
443
  */
486
444
  clear() {
487
445
  this.value = "";
488
-
489
- this.dispatchEvent(
490
- new CustomEvent("input", { bubbles: true, composed: true })
491
- );
492
- this.dispatchEvent(
493
- new CustomEvent("change", { bubbles: true, composed: true })
494
- );
446
+ this._inputRef.value.focus();
447
+ this.dispatchEvent(new CustomEvent("input", {
448
+ bubbles: true,
449
+ composed: true
450
+ }));
451
+ this.dispatchEvent(new CustomEvent("change", {
452
+ bubbles: true,
453
+ composed: true
454
+ }));
495
455
  }
496
456
 
497
457
  /**
@@ -504,17 +464,14 @@ class LeuInput extends LitElement {
504
464
  */
505
465
  getId() {
506
466
  const id = this.getAttribute("id");
507
-
508
467
  if (id !== null && id !== "") {
509
- return id
468
+ return id;
510
469
  }
511
-
512
470
  if (this._identifier !== "") {
513
- return this._identifier
471
+ return this._identifier;
514
472
  }
515
-
516
473
  this._identifier = crypto.randomUUID();
517
- return this._identifier
474
+ return this._identifier;
518
475
  }
519
476
 
520
477
  /**
@@ -531,30 +488,19 @@ class LeuInput extends LitElement {
531
488
  getValidationMessages() {
532
489
  const validationMessages = {
533
490
  ...VALIDATION_MESSAGES,
534
- ...this.validationMessages,
491
+ ...this.validationMessages
535
492
  };
536
-
537
- const { tooLong, tooShort, rangeOverflow, rangeUnderflow } =
538
- validationMessages;
539
-
540
- validationMessages.tooLong = LeuInput.resolveErrorMessage(
493
+ const {
541
494
  tooLong,
542
- this.maxlength
543
- );
544
- validationMessages.tooShort = LeuInput.resolveErrorMessage(
545
495
  tooShort,
546
- this.minlength
547
- );
548
- validationMessages.rangeOverflow = LeuInput.resolveErrorMessage(
549
496
  rangeOverflow,
550
- this.max
551
- );
552
- validationMessages.rangeUnderflow = LeuInput.resolveErrorMessage(
553
- rangeUnderflow,
554
- this.min
555
- );
556
-
557
- return validationMessages
497
+ rangeUnderflow
498
+ } = validationMessages;
499
+ validationMessages.tooLong = LeuInput.resolveErrorMessage(tooLong, this.maxlength);
500
+ validationMessages.tooShort = LeuInput.resolveErrorMessage(tooShort, this.minlength);
501
+ validationMessages.rangeOverflow = LeuInput.resolveErrorMessage(rangeOverflow, this.max);
502
+ validationMessages.rangeUnderflow = LeuInput.resolveErrorMessage(rangeUnderflow, this.min);
503
+ return validationMessages;
558
504
  }
559
505
 
560
506
  /**
@@ -566,27 +512,18 @@ class LeuInput extends LitElement {
566
512
  */
567
513
  renderErrorMessages() {
568
514
  if (!this.isInvalid()) {
569
- return nothing
515
+ return nothing;
570
516
  }
571
-
572
517
  const validationMessages = this.getValidationMessages();
573
- let errorMessages = this._validity
574
- ? Object.entries(validationMessages)
575
- .filter(([property]) => this._validity[property])
576
- .map(([_, message]) => message)
577
- : [];
578
-
518
+ let errorMessages = this._validity ? Object.entries(validationMessages).filter(([property]) => this._validity[property]).map(([_, message]) => message) : [];
579
519
  if (this.error !== "") {
580
520
  errorMessages = [this.error, errorMessages];
581
521
  }
582
-
583
522
  return html`
584
523
  <ul class="error" aria-errormessage=${`input-${this.getId()}`}>
585
- ${errorMessages.map(
586
- (message) => html`<li class="error-message">${message}</li>`
587
- )}
524
+ ${errorMessages.map(message => html`<li class="error-message">${message}</li>`)}
588
525
  </ul>
589
- `
526
+ `;
590
527
  }
591
528
 
592
529
  /**
@@ -598,9 +535,8 @@ class LeuInput extends LitElement {
598
535
  */
599
536
  renderAfterContent() {
600
537
  if (this.isInvalid()) {
601
- return html`<div class="error-icon">${Icon("caution")}</div>`
538
+ return html`<div class="error-icon">${Icon("caution")}</div>`;
602
539
  }
603
-
604
540
  if (this.clearable && this.value !== "") {
605
541
  return html`<button
606
542
  class="clear-button"
@@ -609,33 +545,25 @@ class LeuInput extends LitElement {
609
545
  ?disabled=${this.disabled}
610
546
  >
611
547
  ${this._clearIcon}
612
- </button>`
548
+ </button>`;
613
549
  }
614
-
615
550
  if (this.icon !== "") {
616
- return html`<div class="icon">${Icon(this.icon)}</div>`
551
+ return html`<div class="icon">${Icon(this.icon)}</div>`;
617
552
  }
618
-
619
- return nothing
553
+ return nothing;
620
554
  }
621
-
622
555
  isInvalid() {
623
556
  if (this.error !== "") {
624
- return true
557
+ return true;
625
558
  }
626
-
627
- return this._validity === null || this.novalidate
628
- ? false
629
- : !this._validity.valid
559
+ return this._validity === null || this.novalidate ? false : !this._validity.valid;
630
560
  }
631
-
632
561
  render() {
633
562
  const isInvalid = this.isInvalid();
634
-
635
563
  const inputWrapperClasses = {
636
564
  "input-wrapper": true,
637
565
  "input-wrapper--empty": this.value === "",
638
- "input-wrapper--invalid": isInvalid,
566
+ "input-wrapper--invalid": isInvalid
639
567
  };
640
568
 
641
569
  /* See the description of the handleWrapperClick method on why this rule is disabled */
@@ -666,19 +594,89 @@ class LeuInput extends LitElement {
666
594
  aria-invalid=${isInvalid}
667
595
  />
668
596
  <label for="input-${this.getId()}" class="label"><slot></slot></label>
669
- ${this.prefix !== ""
670
- ? html`<div class="prefix" .aria-hidden=${true}>${this.prefix}</div>`
671
- : nothing}
672
- ${this.suffix !== ""
673
- ? html`<div class="suffix" .aria-hidden=${true}>${this.suffix}</div>`
674
- : nothing}
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}
675
599
  ${this.renderAfterContent()}
676
600
  </div>
677
601
  ${this.renderErrorMessages()}
678
- `
602
+ `;
679
603
  }
680
604
  }
681
-
605
+ _defineProperty(LeuInput, "styles", css_248z);
606
+ /**
607
+ * @internal
608
+ */
609
+ _defineProperty(LeuInput, "shadowRootOptions", {
610
+ ...LitElement.shadowRootOptions,
611
+ delegatesFocus: true
612
+ });
613
+ _defineProperty(LeuInput, "properties", {
614
+ disabled: {
615
+ type: Boolean,
616
+ reflect: true
617
+ },
618
+ required: {
619
+ type: Boolean,
620
+ reflect: true
621
+ },
622
+ clearable: {
623
+ type: Boolean,
624
+ reflect: true
625
+ },
626
+ value: {
627
+ type: String
628
+ },
629
+ name: {
630
+ type: String
631
+ },
632
+ error: {
633
+ type: String
634
+ },
635
+ label: {
636
+ type: String
637
+ },
638
+ prefix: {
639
+ type: String
640
+ },
641
+ suffix: {
642
+ type: String
643
+ },
644
+ size: {
645
+ type: String
646
+ },
647
+ icon: {
648
+ type: String
649
+ },
650
+ /* Validation attributes */
651
+ pattern: {
652
+ type: String
653
+ },
654
+ type: {
655
+ type: String
656
+ },
657
+ min: {
658
+ type: Number
659
+ },
660
+ max: {
661
+ type: Number
662
+ },
663
+ maxlength: {
664
+ type: Number
665
+ },
666
+ minlength: {
667
+ type: Number
668
+ },
669
+ validationMessages: {
670
+ type: Object
671
+ },
672
+ novalidate: {
673
+ type: Boolean
674
+ },
675
+ /** @type {ValidityState} */
676
+ _validity: {
677
+ state: true
678
+ }
679
+ });
682
680
  function defineInputElements() {
683
681
  defineElement("input", LeuInput);
684
682
  }
package/dist/Menu.js ADDED
@@ -0,0 +1,40 @@
1
+ import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
2
+ import { css, LitElement, html } from 'lit';
3
+
4
+ var css_248z = css`:host,
5
+ :host * {
6
+ box-sizing: border-box;
7
+ }
8
+
9
+ :host {
10
+ --menu-divider-color: var(--leu-color-black-transp-20);
11
+ }
12
+
13
+ /*
14
+ * Set styles with important as the hr element is part of the
15
+ * light dom and therefore is affected by the global styles.
16
+ */
17
+
18
+ :host ::slotted(hr) {
19
+ border: 0 !important;
20
+ border-top: 1px solid var(--menu-divider-color) !important;
21
+ margin: 0.5rem 0 !important;
22
+ padding: 0 !important;
23
+ background: none !important;
24
+ }
25
+ `;
26
+
27
+ /**
28
+ * @tagname leu-menu
29
+ */
30
+ class LeuMenu extends LitElement {
31
+ render() {
32
+ return html`<slot></slot>`;
33
+ }
34
+ }
35
+ _defineProperty(LeuMenu, "styles", css_248z);
36
+ function defineMenuElements() {
37
+ defineElement("menu", LeuMenu);
38
+ }
39
+
40
+ export { LeuMenu, defineMenuElements };
@@ -0,0 +1,171 @@
1
+ import { _ as _defineProperty, d as defineElement } from './defineElement-ba770aed.js';
2
+ import { css, LitElement, html, nothing } from 'lit';
3
+ import { a as ICON_NAMES, I as Icon } from './icon-03e86700.js';
4
+
5
+ var css_248z = css`:host,
6
+ :host * {
7
+ box-sizing: border-box;
8
+ }
9
+
10
+ :host {
11
+ --background: var(--leu-color-black-0);
12
+ --background-hover: var(--leu-color-black-10);
13
+ --background-active: var(--leu-color-func-cyan);
14
+ --background-disabled: var(--leu-color-black-0);
15
+ --color: var(--leu-color-black-transp-60);
16
+ --font-regular: var(--leu-font-regular);
17
+ --font-black: var(--leu-font-black);
18
+
19
+ font-family: var(--chip-font-regular);
20
+ }
21
+
22
+ .button {
23
+ -webkit-appearance: none;
24
+ -moz-appearance: none;
25
+ appearance: none;
26
+ border: none;
27
+ cursor: pointer;
28
+
29
+ display: flex;
30
+ align-items: center;
31
+ gap: 0.5rem;
32
+ width: 100%;
33
+
34
+ padding: 0.75rem;
35
+
36
+ font-size: 1rem;
37
+ line-height: 1.5;
38
+ text-align: left;
39
+
40
+ background: var(--background);
41
+ color: var(--color);
42
+ }
43
+
44
+ .button:focus-visible {
45
+ outline: 2px solid var(--leu-color-func-cyan);
46
+ outline-offset: 2px;
47
+ }
48
+
49
+ .button:hover,
50
+ :host([highlighted]) .button {
51
+ --background: var(--background-hover);
52
+ }
53
+
54
+ :host([active]) .button {
55
+ --background: var(--background-active);
56
+ }
57
+
58
+ :host([disabled]) .button {
59
+ --background: var(--background-disabled);
60
+ cursor: default;
61
+ }
62
+
63
+ .before svg, .after svg {
64
+ display: block;
65
+ }
66
+
67
+ .label {
68
+ flex: 1;
69
+ overflow: hidden;
70
+ text-overflow: ellipsis;
71
+ white-space: nowrap;
72
+ }
73
+
74
+ .icon-placeholder {
75
+ display: block;
76
+ width: 1.5rem;
77
+ aspect-ratio: 1;
78
+ }
79
+ `;
80
+
81
+ /**
82
+ * @tagname leu-menu-item
83
+ * @slot - The label of the menu item
84
+ */
85
+ class LeuMenuItem extends LitElement {
86
+ constructor() {
87
+ super();
88
+ this.active = false;
89
+ this.disabled = false;
90
+ this.before = "";
91
+ this.after = "";
92
+
93
+ /**
94
+ * A programmatic way to highlight the menu item like it is hovered.
95
+ * This is just a visual effect and does not change the active state.
96
+ */
97
+ this.highlighted = false;
98
+ }
99
+ static getIconOrText(name) {
100
+ if (ICON_NAMES.includes(name)) {
101
+ return Icon(name);
102
+ }
103
+ if (name === "EMPTY") {
104
+ return html`<div class="icon-placeholder"></div>`;
105
+ }
106
+ return name;
107
+ }
108
+ renderBefore() {
109
+ if (this.before !== "") {
110
+ const content = LeuMenuItem.getIconOrText(this.before);
111
+ return html`<span class="before">${content}</span>`;
112
+ }
113
+ return nothing;
114
+ }
115
+ renderAfter() {
116
+ if (this.after !== "") {
117
+ const content = LeuMenuItem.getIconOrText(this.after);
118
+ return html`<span class="after">${content}</span>`;
119
+ }
120
+ return nothing;
121
+ }
122
+ render() {
123
+ return html`<button class="button" ?disabled=${this.disabled}>
124
+ ${this.renderBefore()}<span class="label"><slot></slot></span
125
+ >${this.renderAfter()}
126
+ </button>`;
127
+ }
128
+ }
129
+ _defineProperty(LeuMenuItem, "styles", css_248z);
130
+ /**
131
+ * @internal
132
+ */
133
+ _defineProperty(LeuMenuItem, "shadowRootOptions", {
134
+ ...LitElement.shadowRootOptions,
135
+ delegatesFocus: true
136
+ });
137
+ _defineProperty(LeuMenuItem, "properties", {
138
+ /**
139
+ * Can be either an icon name or a text
140
+ * If no icon with this value is found, it will be displayed as text.
141
+ * If the value is "EMPTY", an empty placeholder with the size of an icon will be displayed.
142
+ */
143
+ before: {
144
+ type: String
145
+ },
146
+ /**
147
+ * Can be either an icon name or a text
148
+ * If no icon with this value is found, it will be displayed as text
149
+ * If the value is "EMPTY", an empty placeholder with the size of an icon will be displayed.
150
+ */
151
+ after: {
152
+ type: String
153
+ },
154
+ active: {
155
+ type: Boolean,
156
+ reflect: true
157
+ },
158
+ highlighted: {
159
+ type: Boolean,
160
+ reflect: true
161
+ },
162
+ disabled: {
163
+ type: Boolean,
164
+ reflect: true
165
+ }
166
+ });
167
+ function defineMenuItemElements() {
168
+ defineElement("menu-item", LeuMenuItem);
169
+ }
170
+
171
+ export { LeuMenuItem, defineMenuItemElements };