@statistikzh/leu 0.0.2

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 (141) hide show
  1. package/.editorconfig +29 -0
  2. package/.eslintrc.json +27 -0
  3. package/.github/workflows/publish.yml +19 -0
  4. package/.github/workflows/release-please.yml +19 -0
  5. package/.github/workflows/test.yml +38 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.prettierignore +1 -0
  9. package/.storybook/main.js +11 -0
  10. package/.storybook/preview-head.html +5 -0
  11. package/.storybook/preview.js +23 -0
  12. package/CHANGELOG.md +63 -0
  13. package/CODE_OF_CONDUCT.md +128 -0
  14. package/CONTRIBUTING.md +31 -0
  15. package/LICENSE +21 -0
  16. package/README.md +170 -0
  17. package/commitlint.config.cjs +1 -0
  18. package/dist/Button-83c6df93.js +403 -0
  19. package/dist/Checkbox.js +144 -0
  20. package/dist/CheckboxGroup.js +82 -0
  21. package/dist/Chip-60af1402.js +162 -0
  22. package/dist/ChipGroup.js +79 -0
  23. package/dist/ChipLink.js +46 -0
  24. package/dist/ChipRemovable.js +43 -0
  25. package/dist/ChipSelectable.js +92 -0
  26. package/dist/Input.js +686 -0
  27. package/dist/Radio.js +156 -0
  28. package/dist/RadioGroup.js +194 -0
  29. package/dist/Select.js +859 -0
  30. package/dist/Table-72d305d7.js +506 -0
  31. package/dist/Table.js +8 -0
  32. package/dist/defineElement-47d4f665.js +15 -0
  33. package/dist/icon-b68c7e1e.js +202 -0
  34. package/dist/index.js +21 -0
  35. package/dist/leu-checkbox-group.js +6 -0
  36. package/dist/leu-checkbox.js +6 -0
  37. package/dist/leu-chip-group.js +5 -0
  38. package/dist/leu-chip-link.js +6 -0
  39. package/dist/leu-chip-removable.js +7 -0
  40. package/dist/leu-chip-selectable.js +6 -0
  41. package/dist/leu-input.js +9 -0
  42. package/dist/leu-radio-group.js +6 -0
  43. package/dist/leu-radio.js +5 -0
  44. package/dist/leu-select.js +12 -0
  45. package/dist/leu-table.js +10 -0
  46. package/dist/theme.css +51 -0
  47. package/index.js +10 -0
  48. package/package.json +85 -0
  49. package/postcss.config.cjs +14 -0
  50. package/rollup.config.js +54 -0
  51. package/scripts/generate-component/generate.js +167 -0
  52. package/scripts/generate-component/templates/[Name].js +33 -0
  53. package/scripts/generate-component/templates/[name].css +11 -0
  54. package/scripts/generate-component/templates/[namespace]-[name].js +3 -0
  55. package/scripts/generate-component/templates/stories/[name].stories.js +13 -0
  56. package/scripts/generate-component/templates/test/[name].test.js +22 -0
  57. package/src/components/button/Button.js +150 -0
  58. package/src/components/button/button.css +232 -0
  59. package/src/components/button/leu-button.js +3 -0
  60. package/src/components/button/stories/button.stories.js +333 -0
  61. package/src/components/button/test/button.test.js +22 -0
  62. package/src/components/button-group/ButtonGroup.js +63 -0
  63. package/src/components/button-group/button-group.css +10 -0
  64. package/src/components/button-group/leu-button-group.js +3 -0
  65. package/src/components/button-group/stories/button-group.stories.js +41 -0
  66. package/src/components/button-group/test/button-group.test.js +22 -0
  67. package/src/components/checkbox/Checkbox.js +142 -0
  68. package/src/components/checkbox/CheckboxGroup.js +80 -0
  69. package/src/components/checkbox/leu-checkbox-group.js +3 -0
  70. package/src/components/checkbox/leu-checkbox.js +3 -0
  71. package/src/components/checkbox/stories/checkbox-group.stories.js +52 -0
  72. package/src/components/checkbox/stories/checkbox.stories.js +43 -0
  73. package/src/components/checkbox/test/checkbox.test.js +101 -0
  74. package/src/components/chip/Chip.js +24 -0
  75. package/src/components/chip/ChipGroup.js +71 -0
  76. package/src/components/chip/ChipLink.js +45 -0
  77. package/src/components/chip/ChipRemovable.js +42 -0
  78. package/src/components/chip/ChipSelectable.js +91 -0
  79. package/src/components/chip/chip-group.css +5 -0
  80. package/src/components/chip/chip.css +130 -0
  81. package/src/components/chip/exports.js +10 -0
  82. package/src/components/chip/leu-chip-group.js +3 -0
  83. package/src/components/chip/leu-chip-link.js +3 -0
  84. package/src/components/chip/leu-chip-removable.js +3 -0
  85. package/src/components/chip/leu-chip-selectable.js +3 -0
  86. package/src/components/chip/stories/chip-group.stories.js +99 -0
  87. package/src/components/chip/stories/chip-link.stories.js +37 -0
  88. package/src/components/chip/stories/chip-removable.stories.js +28 -0
  89. package/src/components/chip/stories/chip-selectable.stories.js +46 -0
  90. package/src/components/chip/test/chip.test.js +22 -0
  91. package/src/components/dropdown/Dropdown.js +55 -0
  92. package/src/components/dropdown/dropdown.css +17 -0
  93. package/src/components/dropdown/leu-dropdown.js +3 -0
  94. package/src/components/dropdown/stories/dropdown.stories.js +25 -0
  95. package/src/components/dropdown/test/dropdown.test.js +31 -0
  96. package/src/components/icon/icon.js +201 -0
  97. package/src/components/input/Input.js +421 -0
  98. package/src/components/input/input.css +231 -0
  99. package/src/components/input/leu-input.js +3 -0
  100. package/src/components/input/stories/input.stories.js +185 -0
  101. package/src/components/input/test/input.test.js +22 -0
  102. package/src/components/menu/Menu.js +18 -0
  103. package/src/components/menu/MenuItem.js +95 -0
  104. package/src/components/menu/leu-menu-item.js +3 -0
  105. package/src/components/menu/leu-menu.js +3 -0
  106. package/src/components/menu/menu-item.css +72 -0
  107. package/src/components/menu/menu.css +14 -0
  108. package/src/components/menu/stories/menu-item.stories.js +51 -0
  109. package/src/components/menu/stories/menu.stories.js +21 -0
  110. package/src/components/menu/test/menu.test.js +22 -0
  111. package/src/components/pagination/Pagination.js +152 -0
  112. package/src/components/pagination/leu-pagination.js +3 -0
  113. package/src/components/pagination/pagination.css +49 -0
  114. package/src/components/pagination/stories/pagination.stories.js +82 -0
  115. package/src/components/pagination/test/pagination.test.js +22 -0
  116. package/src/components/radio/Radio.js +62 -0
  117. package/src/components/radio/RadioGroup.js +193 -0
  118. package/src/components/radio/leu-radio-group.js +3 -0
  119. package/src/components/radio/leu-radio.js +3 -0
  120. package/src/components/radio/radio.css +76 -0
  121. package/src/components/radio/stories/radio-group.stories.js +49 -0
  122. package/src/components/radio/stories/radio.stories.js +48 -0
  123. package/src/components/radio/test/radio.test.js +38 -0
  124. package/src/components/select/Select.js +350 -0
  125. package/src/components/select/leu-select.js +3 -0
  126. package/src/components/select/select.css +215 -0
  127. package/src/components/select/stories/select.stories.js +302 -0
  128. package/src/components/select/test/select.test.js +29 -0
  129. package/src/components/table/Table.js +301 -0
  130. package/src/components/table/leu-table.js +3 -0
  131. package/src/components/table/stories/table.stories.js +116 -0
  132. package/src/components/table/test/table.test.js +36 -0
  133. package/src/lib/defineElement.js +13 -0
  134. package/src/lib/hasSlotController.js +85 -0
  135. package/src/styles/custom-media.css +5 -0
  136. package/src/styles/custom-properties.css +51 -0
  137. package/src/styles/theme.css +1 -0
  138. package/stat_zh.png +0 -0
  139. package/stylelint.config.mjs +21 -0
  140. package/web-dev-server-storybook.config.mjs +19 -0
  141. package/web-test-runner.config.mjs +49 -0
@@ -0,0 +1,162 @@
1
+ import { css, LitElement } from 'lit';
2
+
3
+ var css_248z = css`:host,
4
+ :host *,
5
+ :host *::before,
6
+ :host *::after {
7
+ box-sizing: border-box;
8
+ }
9
+
10
+ :host {
11
+ --chip-background-color-default: var(--leu-color-black-transp-10);
12
+ --chip-background-color-hover: var(--leu-color-black-transp-20);
13
+ --chip-background-color-selected: var(--leu-color-black-100);
14
+ --chip-background-color-selected-hover: var(--leu-color-black-transp-80);
15
+
16
+ --chip-color-default: var(--leu-color-black-transp-60);
17
+ --chip-color-hover: var(--leu-color-black-100);
18
+ --chip-color-selected: var(--leu-color-black-0);
19
+
20
+ --chip-radio-border-default: var(--leu-color-black-transp-40);
21
+ --chip-radio-border-selected: var(--leu-color-black-0);
22
+ --chip-radio-background-default: var(--leu-color-black-0);
23
+ --chip-radio-background-selected: var(--leu-color-func-cyan);
24
+
25
+ --chip-font-regular: var(--leu-font-regular);
26
+ --chip-font-black: var(--leu-font-black);
27
+
28
+ --chip-background-color: var(--chip-background-color-default);
29
+ --chip-color: var(--chip-color-default);
30
+ --chip-radio-border: var(--chip-radio-border-default);
31
+ --chip-radio-background: var(--chip-radio-background-default);
32
+
33
+ font-family: var(--leu-font-regular);
34
+
35
+ font-family: var(--chip-font-regular);
36
+ }
37
+
38
+ :host([inverted]) {
39
+ --chip-background-color: var(--leu-color-black-transp-20);
40
+ --chip-background-color-hover: var(--leu-color-black-transp-40);
41
+
42
+ --chip-color-default: var(--leu-color-black-0);
43
+ --chip-color-hover: var(--leu-color-black-0);
44
+ --chip-color-selected: var(--leu-color-black-0);
45
+ }
46
+
47
+ :host([selected]) {
48
+ --chip-background-color: var(--chip-background-color-selected);
49
+ --chip-color: var(--chip-color-selected);
50
+ --chip-radio-border: var(--chip-radio-border-selected);
51
+ --chip-radio-background: var(--chip-radio-background-selected);
52
+ }
53
+
54
+ .button {
55
+ -webkit-appearance: none;
56
+ -moz-appearance: none;
57
+ appearance: none;
58
+ border: none;
59
+ border-radius: 1rem;
60
+ background-color: var(--chip-background-color);
61
+ padding: 0.5rem 1rem;
62
+
63
+ color: var(--chip-color);
64
+ font-size: 0.875rem;
65
+ line-height: 1rem;
66
+
67
+ cursor: pointer;
68
+
69
+ display: inline-flex;
70
+ align-items: center;
71
+ gap: 0.5rem;
72
+ }
73
+
74
+ .button:hover,
75
+ .button:focus-visible {
76
+ --chip-background-color: var(--chip-background-color-hover);
77
+ --chip-color: var(--chip-color-hover);
78
+ }
79
+
80
+ .button:focus-visible {
81
+ outline: 2px solid var(--leu-color-func-cyan);
82
+ outline-offset: 2px;
83
+ }
84
+
85
+ :host([href]) .button {
86
+ border-radius: 1.25rem;
87
+ padding: 0.5rem 1rem;
88
+
89
+ font-family: var(--chip-font-black);
90
+ font-size: 1.125rem;
91
+ line-height: 1.5rem;
92
+ -webkit-text-decoration: none;
93
+ text-decoration: none;
94
+ }
95
+
96
+ :host([selected]) .button:hover,
97
+ :host([selected]) .button:focus-visible {
98
+ --chip-background-color: var(--chip-background-color-selected-hover);
99
+ --chip-color: var(--chip-color-selected);
100
+ }
101
+
102
+ :host([href][size="large"]) .button {
103
+ border-radius: 1.5rem;
104
+ padding: 0.3125rem 1.5rem;
105
+
106
+ font-size: 2rem;
107
+ line-height: 2.375rem;
108
+ }
109
+
110
+ :host([size="small"]:not([variant="radio"])) .button {
111
+ padding: 0.5625rem 0.75rem 0.4375rem;
112
+
113
+ font-size: 0.75rem;
114
+ line-height: 1;
115
+ }
116
+
117
+ :host([variant="radio"]) .button::before {
118
+ content: "";
119
+ width: 1rem;
120
+ height: 1rem;
121
+ background-color: var(--chip-radio-background);
122
+ border: 2px solid var(--chip-radio-border);
123
+ border-radius: 50%;
124
+ }
125
+
126
+ :host([variant="radio"][selected]) .button::before {
127
+ border-width: 3px;
128
+ }
129
+
130
+ .label {
131
+ position: relative;
132
+ top: -0.0625rem;
133
+ }
134
+
135
+ .icon svg {
136
+ display: block;
137
+ }
138
+ `;
139
+
140
+ /* Design: https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=21161-184433&mode=design&t=Kjo5VDiqivihn8dh-11 */
141
+
142
+ class LeuChipBase extends LitElement {
143
+ static styles = css_248z
144
+
145
+ /** @internal */
146
+ static shadowRootOptions = {
147
+ ...LitElement.shadowRootOptions,
148
+ delegatesFocus: true,
149
+ }
150
+
151
+ static properties = {
152
+ inverted: { type: Boolean },
153
+ }
154
+
155
+ constructor() {
156
+ super();
157
+
158
+ this.inverted = false;
159
+ }
160
+ }
161
+
162
+ export { LeuChipBase as L };
@@ -0,0 +1,79 @@
1
+ import { css, LitElement, html } from 'lit';
2
+ import { d as defineElement } from './defineElement-47d4f665.js';
3
+
4
+ var css_248z = css`:host {
5
+ display: flex;
6
+ flex-wrap: wrap;
7
+ gap: 0.5rem;
8
+ }
9
+ `;
10
+
11
+ /* Figma https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=131766-248643&mode=design&t=Kjo5VDiqivihn8dh-11 */
12
+
13
+ const SELECTION_MODES = {
14
+ single: "single",
15
+ multiple: "multiple",
16
+ none: "none",
17
+ };
18
+
19
+ /**
20
+ * @slot - Place leu-chip-* elements inside this slot
21
+ * @tagname leu-chip-group
22
+ */
23
+ class LeuChipGroup extends LitElement {
24
+ static styles = css_248z
25
+
26
+ static properties = {
27
+ selectionMode: { type: String, attribute: "selection-mode" },
28
+ }
29
+
30
+ constructor() {
31
+ super();
32
+
33
+ /** @internal */
34
+ this.items = [];
35
+ }
36
+
37
+ connectedCallback() {
38
+ super.connectedCallback();
39
+
40
+ this.addEventListener("input", this.handleInput);
41
+ }
42
+
43
+ disconnectedCallback() {
44
+ super.disconnectedCallback();
45
+
46
+ this.removeEventListener("input", this.handleInput);
47
+ }
48
+
49
+ get value() {
50
+ return this.items.filter((i) => i.selected).map((i) => i.value)
51
+ }
52
+
53
+ /** @internal */
54
+ handleInput = (e) => {
55
+ if (this.selectionMode === SELECTION_MODES.single) {
56
+ this.items.forEach((item) => {
57
+ item.selected = item === e.target; // eslint-disable-line no-param-reassign
58
+ });
59
+ }
60
+ }
61
+
62
+ /** @internal */
63
+ handleSlotChange = (e) => {
64
+ const slot = e.target;
65
+ const items = slot.assignedElements({ flatten: true });
66
+
67
+ this.items = items;
68
+ }
69
+
70
+ render() {
71
+ return html`<slot @slotchange=${this.handleSlotChange}></slot>`
72
+ }
73
+ }
74
+
75
+ function defineChipGroupElements() {
76
+ defineElement("chip-group", LeuChipGroup);
77
+ }
78
+
79
+ export { LeuChipGroup, SELECTION_MODES, defineChipGroupElements };
@@ -0,0 +1,46 @@
1
+ import { html } from 'lit';
2
+ import { d as defineElement } from './defineElement-47d4f665.js';
3
+ import { L as LeuChipBase } from './Chip-60af1402.js';
4
+
5
+ const SIZES = {
6
+ regular: "regular",
7
+ large: "large",
8
+ };
9
+
10
+ /**
11
+ * @slot - The content of the chip
12
+ * @tagname leu-chip-link
13
+ */
14
+ class LeuChipLink extends LeuChipBase {
15
+ static properties = {
16
+ ...LeuChipBase.properties,
17
+
18
+ /**
19
+ * The size of the chip
20
+ * @type {keyof typeof SIZES}
21
+ */
22
+ size: { type: String },
23
+
24
+ href: { type: String, reflect: true },
25
+ }
26
+
27
+ constructor() {
28
+ super();
29
+
30
+ this.inverted = false;
31
+ this.size = SIZES.regular;
32
+ this.href = "";
33
+ }
34
+
35
+ render() {
36
+ return html`<a href=${this.href} class="button">
37
+ <span class="label"><slot></slot></span>
38
+ </a>`
39
+ }
40
+ }
41
+
42
+ function defineChipLinkElements() {
43
+ defineElement("chip-link", LeuChipLink);
44
+ }
45
+
46
+ export { LeuChipLink, SIZES, defineChipLinkElements };
@@ -0,0 +1,43 @@
1
+ import { html } from 'lit';
2
+ import { d as defineElement } from './defineElement-47d4f665.js';
3
+ import { L as LeuChipBase } from './Chip-60af1402.js';
4
+ import { I as Icon } from './icon-b68c7e1e.js';
5
+
6
+ /**
7
+ * @slot - The content of the chip
8
+ * @tagname leu-chip-removable
9
+ * @fires remove - Dispatched when the user clicks on the chip
10
+ */
11
+ class LeuChipRemovable extends LeuChipBase {
12
+ static properties = {
13
+ ...LeuChipBase.properties,
14
+ }
15
+
16
+ constructor() {
17
+ super();
18
+
19
+ /** @internal */
20
+ this._removeIcon = Icon("close", 16);
21
+ }
22
+
23
+ handleClick() {
24
+ const customEvent = new CustomEvent("remove", {
25
+ bubble: true,
26
+ composed: true,
27
+ });
28
+ this.dispatchEvent(customEvent);
29
+ }
30
+
31
+ render() {
32
+ return html`<button @click=${(e) => this.handleClick(e)} class="button">
33
+ <span class="label"><slot></slot></span>
34
+ <div class="icon">${this._removeIcon}</div>
35
+ </button>`
36
+ }
37
+ }
38
+
39
+ function defineChipRemovableElements() {
40
+ defineElement("chip-removable", LeuChipRemovable);
41
+ }
42
+
43
+ export { LeuChipRemovable, defineChipRemovableElements };
@@ -0,0 +1,92 @@
1
+ import { html } from 'lit';
2
+ import { d as defineElement } from './defineElement-47d4f665.js';
3
+ import { L as LeuChipBase } from './Chip-60af1402.js';
4
+
5
+ const SIZES = {
6
+ small: "small",
7
+ regular: "regular",
8
+ };
9
+
10
+ const VARIANTS = {
11
+ default: "default",
12
+ radio: "radio",
13
+ };
14
+
15
+ /**
16
+ * A chip component that can be selected.
17
+ * @slot - The content of the chip
18
+ * @tagname leu-chip-selectable
19
+ */
20
+ class LeuChipSelectable extends LeuChipBase {
21
+ static properties = {
22
+ ...LeuChipBase.properties,
23
+
24
+ /**
25
+ * The size of the chip. Not supported for radio variant.
26
+ * @type {keyof typeof SIZES}
27
+ * @default "regular"
28
+ */
29
+ size: { type: String },
30
+
31
+ /**
32
+ * The variant of the chip. Has an effect not only on the visual appearance but also on the behavior.
33
+ * - `default`: The chip behaves like a toggle button.
34
+ * - `radio`: The chip behaves like a radio button.
35
+ *
36
+ * @type {keyof typeof VARIANTS}
37
+ * @default "default"
38
+ */
39
+ variant: { type: String },
40
+
41
+ selected: { type: Boolean, reflect: true },
42
+ value: { type: String },
43
+ }
44
+
45
+ constructor() {
46
+ super();
47
+ this.size = SIZES.regular;
48
+ this.variant = VARIANTS.toggle;
49
+ this.selected = false;
50
+
51
+ if (this.variant === VARIANTS.radio && this.size === SIZES.small) {
52
+ console.warn("Small size has no effect on radio variant");
53
+ }
54
+ }
55
+
56
+ handleClick() {
57
+ let nextSelectedState = this.selected;
58
+
59
+ if (this.variant === VARIANTS.radio) {
60
+ nextSelectedState = true;
61
+ } else {
62
+ nextSelectedState = !this.selected;
63
+ }
64
+
65
+ if (nextSelectedState !== this.selected) {
66
+ this.selected = nextSelectedState;
67
+ this.dispatchEvent(
68
+ new CustomEvent("input", {
69
+ detail: { selected: this.selected },
70
+ bubbles: true,
71
+ composed: true,
72
+ })
73
+ );
74
+ }
75
+ }
76
+
77
+ render() {
78
+ return html`<button
79
+ @click=${(e) => this.handleClick(e)}
80
+ class="button"
81
+ aria-selected=${this.selected ? "true" : "false"}
82
+ >
83
+ <span class="label"><slot></slot></span>
84
+ </button>`
85
+ }
86
+ }
87
+
88
+ function defineChipSelectableElements() {
89
+ defineElement("chip-selectable", LeuChipSelectable);
90
+ }
91
+
92
+ export { LeuChipSelectable, SIZES, VARIANTS, defineChipSelectableElements };