@statistikzh/leu 0.3.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.
- package/.github/workflows/deploy-github-pages.yaml +33 -0
- package/.storybook/main.js +27 -1
- package/.storybook/manager-head.html +1 -0
- package/.storybook/manager.js +9 -0
- package/.storybook/preview-head.html +1 -1
- package/.storybook/preview.js +59 -5
- package/.storybook/static/logo.svg +19 -0
- package/.storybook/theme.js +7 -0
- package/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/dist/Button.js +15 -18
- package/dist/ButtonGroup.js +5 -7
- package/dist/Checkbox.js +101 -84
- package/dist/CheckboxGroup.js +41 -37
- package/dist/{Chip-5f70d04f.js → Chip-dac7337d.js} +5 -1
- package/dist/ChipGroup.js +2 -5
- package/dist/ChipLink.js +4 -7
- package/dist/ChipRemovable.js +4 -7
- package/dist/ChipSelectable.js +4 -7
- package/dist/Dropdown.js +55 -26
- package/dist/Input.js +29 -28
- package/dist/Menu.js +2 -5
- package/dist/MenuItem.js +30 -15
- package/dist/Pagination.js +54 -54
- package/dist/Radio.js +7 -6
- package/dist/RadioGroup.js +41 -39
- package/dist/Select.js +55 -43
- package/dist/Table.js +137 -120
- package/dist/{defineElement-ba770aed.js → _rollupPluginBabelHelpers-20f659f4.js} +1 -15
- package/dist/defineElement-47d4f665.js +15 -0
- package/dist/index.js +29 -19
- package/dist/leu-button-group.js +7 -3
- package/dist/leu-button.js +6 -3
- package/dist/leu-checkbox-group.js +6 -3
- package/dist/leu-checkbox.js +6 -3
- package/dist/leu-chip-group.js +6 -3
- package/dist/leu-chip-link.js +7 -4
- package/dist/leu-chip-removable.js +7 -4
- package/dist/leu-chip-selectable.js +7 -4
- package/dist/leu-dropdown.js +13 -3
- package/dist/leu-input.js +7 -3
- package/dist/leu-menu-item.js +8 -3
- package/dist/leu-menu.js +6 -3
- package/dist/leu-pagination.js +8 -3
- package/dist/leu-popup-4bf6f1f4.js +216 -0
- package/dist/leu-radio-group.js +6 -3
- package/dist/leu-radio.js +6 -3
- package/dist/leu-select.js +14 -3
- package/dist/leu-table.js +9 -3
- package/package.json +24 -12
- package/scripts/generate-component/templates/[Name].js +0 -5
- package/scripts/generate-component/templates/[name].css +1 -1
- package/scripts/generate-component/templates/[namespace]-[name].js +5 -2
- package/src/components/accordion/Accordion.js +0 -6
- package/src/components/accordion/leu-accordion.js +5 -2
- package/src/components/accordion/stories/accordion.stories.js +7 -4
- package/src/components/accordion/test/accordion.test.js +92 -2
- package/src/components/breadcrumb/Breadcrumb.js +310 -0
- package/src/components/breadcrumb/breadcrumb.css +114 -0
- package/src/components/breadcrumb/leu-breadcrumb.js +6 -0
- package/src/components/breadcrumb/stories/breadcrumb.stories.js +73 -0
- package/src/components/breadcrumb/test/breadcrumb.test.js +141 -0
- package/src/components/button/Button.js +10 -15
- package/src/components/button/button.css +3 -3
- package/src/components/button/leu-button.js +5 -2
- package/src/components/button/stories/button.stories.js +58 -37
- package/src/components/button/test/button.test.js +112 -2
- package/src/components/button-group/ButtonGroup.js +1 -7
- package/src/components/button-group/leu-button-group.js +5 -2
- package/src/components/button-group/stories/button-group.stories.js +6 -0
- package/src/components/button-group/test/button-group.test.js +79 -3
- package/src/components/checkbox/Checkbox.js +6 -85
- package/src/components/checkbox/CheckboxGroup.js +8 -38
- package/src/components/checkbox/checkbox-group.css +29 -0
- package/src/components/checkbox/checkbox.css +76 -0
- package/src/components/checkbox/leu-checkbox-group.js +5 -2
- package/src/components/checkbox/leu-checkbox.js +5 -2
- package/src/components/checkbox/stories/checkbox-group.stories.js +44 -21
- package/src/components/checkbox/stories/checkbox.stories.js +7 -1
- package/src/components/checkbox/test/checkbox-group.test.js +124 -0
- package/src/components/checkbox/test/checkbox.test.js +72 -59
- package/src/components/chip/Chip.js +1 -0
- package/src/components/chip/ChipGroup.js +0 -5
- package/src/components/chip/ChipLink.js +1 -6
- package/src/components/chip/ChipRemovable.js +1 -6
- package/src/components/chip/ChipSelectable.js +1 -6
- package/src/components/chip/exports.js +4 -10
- package/src/components/chip/leu-chip-group.js +5 -2
- package/src/components/chip/leu-chip-link.js +5 -2
- package/src/components/chip/leu-chip-removable.js +5 -2
- package/src/components/chip/leu-chip-selectable.js +5 -2
- package/src/components/chip/stories/chip-group.stories.js +18 -6
- package/src/components/chip/stories/chip-link.stories.js +16 -4
- package/src/components/chip/stories/chip-removable.stories.js +15 -4
- package/src/components/chip/stories/chip-selectable.stories.js +13 -3
- package/src/components/chip/test/chip-group.test.js +124 -0
- package/src/components/chip/test/chip-link.test.js +58 -0
- package/src/components/chip/test/chip-removable.test.js +79 -0
- package/src/components/chip/test/chip-selectable.test.js +95 -0
- package/src/components/chip/test/chip.test.js +1 -1
- package/src/components/dropdown/Dropdown.js +52 -24
- package/src/components/dropdown/dropdown.css +1 -2
- package/src/components/dropdown/leu-dropdown.js +5 -2
- package/src/components/dropdown/stories/dropdown.stories.js +11 -5
- package/src/components/dropdown/test/dropdown.test.js +6 -6
- package/src/components/icon/icon.js +1 -1
- package/src/components/icon/test/icon.test.js +66 -0
- package/src/components/input/Input.js +18 -24
- package/src/components/input/input.css +9 -6
- package/src/components/input/leu-input.js +5 -2
- package/src/components/input/stories/input.stories.js +8 -2
- package/src/components/input/test/input.test.js +431 -4
- package/src/components/menu/Menu.js +0 -5
- package/src/components/menu/MenuItem.js +20 -13
- package/src/components/menu/leu-menu-item.js +5 -2
- package/src/components/menu/leu-menu.js +5 -2
- package/src/components/menu/menu-item.css +5 -2
- package/src/components/menu/stories/menu-item.stories.js +13 -4
- package/src/components/menu/stories/menu.stories.js +11 -5
- package/src/components/menu/test/menu-item.test.js +180 -0
- package/src/components/menu/test/menu.test.js +10 -2
- package/src/components/pagination/Pagination.js +53 -65
- package/src/components/pagination/leu-pagination.js +5 -2
- package/src/components/pagination/stories/pagination.stories.js +17 -9
- package/src/components/pagination/test/pagination.test.js +191 -5
- package/src/components/popup/Popup.js +200 -0
- package/src/components/popup/leu-popup.js +6 -0
- package/src/components/popup/popup.css +27 -0
- package/src/components/popup/stories/popup.stories.js +58 -0
- package/src/components/popup/test/popup.test.js +29 -0
- package/src/components/radio/Radio.js +2 -6
- package/src/components/radio/RadioGroup.js +6 -38
- package/src/components/radio/leu-radio-group.js +5 -2
- package/src/components/radio/leu-radio.js +5 -2
- package/src/components/radio/radio-group.css +29 -0
- package/src/components/radio/stories/radio-group.stories.js +38 -19
- package/src/components/radio/stories/radio.stories.js +7 -1
- package/src/components/radio/test/radio-group.test.js +86 -0
- package/src/components/radio/test/radio.test.js +108 -17
- package/src/components/select/Select.js +34 -31
- package/src/components/select/leu-select.js +5 -2
- package/src/components/select/select.css +13 -13
- package/src/components/select/stories/select.stories.js +15 -168
- package/src/components/select/test/fixtures.js +162 -0
- package/src/components/select/test/select.test.js +236 -12
- package/src/components/table/Table.js +43 -118
- package/src/components/table/leu-table.js +5 -2
- package/src/components/table/stories/table.stories.js +20 -10
- package/src/components/table/table.css +99 -0
- package/src/components/table/test/table.test.js +1 -1
- package/src/lib/utils.js +17 -0
- package/{web-dev-server-storybook.config.mjs → web-dev-server.config.mjs} +1 -2
- package/web-test-runner.config.mjs +15 -2
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export const MUNICIPALITIES = [
|
|
2
|
+
"Aeugst am Albis",
|
|
3
|
+
"Affoltern am Albis",
|
|
4
|
+
"Bonstetten",
|
|
5
|
+
"Hausen am Albis",
|
|
6
|
+
"Hedingen",
|
|
7
|
+
"Kappel am Albis",
|
|
8
|
+
"Knonau",
|
|
9
|
+
"Maschwanden",
|
|
10
|
+
"Mettmenstetten",
|
|
11
|
+
"Obfelden",
|
|
12
|
+
"Ottenbach",
|
|
13
|
+
"Rifferswil",
|
|
14
|
+
"Stallikon",
|
|
15
|
+
"Wettswil am Albis",
|
|
16
|
+
"Benken (ZH)",
|
|
17
|
+
"Berg am Irchel",
|
|
18
|
+
"Buch am Irchel",
|
|
19
|
+
"Dachsen",
|
|
20
|
+
"Dorf",
|
|
21
|
+
"Feuerthalen",
|
|
22
|
+
"Flaach",
|
|
23
|
+
"Flurlingen",
|
|
24
|
+
"Henggart",
|
|
25
|
+
"Kleinandelfingen",
|
|
26
|
+
"Laufen-Uhwiesen",
|
|
27
|
+
"Marthalen",
|
|
28
|
+
"Ossingen",
|
|
29
|
+
"Rheinau",
|
|
30
|
+
"Thalheim an der Thur",
|
|
31
|
+
"Trüllikon",
|
|
32
|
+
"Truttikon",
|
|
33
|
+
"Volken",
|
|
34
|
+
"Bachenbülach",
|
|
35
|
+
"Bassersdorf",
|
|
36
|
+
"Bülach",
|
|
37
|
+
"Dietlikon",
|
|
38
|
+
"Eglisau",
|
|
39
|
+
"Embrach",
|
|
40
|
+
"Freienstein-Teufen",
|
|
41
|
+
"Glattfelden",
|
|
42
|
+
"Hochfelden",
|
|
43
|
+
"Höri",
|
|
44
|
+
"Hüntwangen",
|
|
45
|
+
"Kloten",
|
|
46
|
+
"Lufingen",
|
|
47
|
+
"Nürensdorf",
|
|
48
|
+
"Oberembrach",
|
|
49
|
+
"Opfikon",
|
|
50
|
+
"Rafz",
|
|
51
|
+
"Rorbas",
|
|
52
|
+
"Wallisellen",
|
|
53
|
+
"Wasterkingen",
|
|
54
|
+
"Wil (ZH)",
|
|
55
|
+
"Winkel",
|
|
56
|
+
"Bachs",
|
|
57
|
+
"Boppelsen",
|
|
58
|
+
"Buchs (ZH)",
|
|
59
|
+
"Dällikon",
|
|
60
|
+
"Dänikon",
|
|
61
|
+
"Dielsdorf",
|
|
62
|
+
"Hüttikon",
|
|
63
|
+
"Neerach",
|
|
64
|
+
"Niederglatt",
|
|
65
|
+
"Niederhasli",
|
|
66
|
+
"Niederweningen",
|
|
67
|
+
"Oberglatt",
|
|
68
|
+
"Oberweningen",
|
|
69
|
+
"Otelfingen",
|
|
70
|
+
"Regensberg",
|
|
71
|
+
"Regensdorf",
|
|
72
|
+
"Rümlang",
|
|
73
|
+
"Schleinikon",
|
|
74
|
+
"Schöfflisdorf",
|
|
75
|
+
"Stadel",
|
|
76
|
+
"Steinmaur",
|
|
77
|
+
"Weiach",
|
|
78
|
+
"Bäretswil",
|
|
79
|
+
"Bubikon",
|
|
80
|
+
"Dürnten",
|
|
81
|
+
"Fischenthal",
|
|
82
|
+
"Gossau (ZH)",
|
|
83
|
+
"Grüningen",
|
|
84
|
+
"Hinwil",
|
|
85
|
+
"Rüti (ZH)",
|
|
86
|
+
"Seegräben",
|
|
87
|
+
"Wald (ZH)",
|
|
88
|
+
"Wetzikon (ZH)",
|
|
89
|
+
"Adliswil",
|
|
90
|
+
"Kilchberg (ZH)",
|
|
91
|
+
"Langnau am Albis",
|
|
92
|
+
"Oberrieden",
|
|
93
|
+
"Richterswil",
|
|
94
|
+
"Rüschlikon",
|
|
95
|
+
"Thalwil",
|
|
96
|
+
"Erlenbach (ZH)",
|
|
97
|
+
"Herrliberg",
|
|
98
|
+
"Hombrechtikon",
|
|
99
|
+
"Küsnacht (ZH)",
|
|
100
|
+
"Männedorf",
|
|
101
|
+
"Meilen",
|
|
102
|
+
"Oetwil am See",
|
|
103
|
+
"Stäfa",
|
|
104
|
+
"Uetikon am See",
|
|
105
|
+
"Zumikon",
|
|
106
|
+
"Zollikon",
|
|
107
|
+
"Fehraltorf",
|
|
108
|
+
"Hittnau",
|
|
109
|
+
"Lindau",
|
|
110
|
+
"Pfäffikon",
|
|
111
|
+
"Russikon",
|
|
112
|
+
"Weisslingen",
|
|
113
|
+
"Wila",
|
|
114
|
+
"Wildberg",
|
|
115
|
+
"Dübendorf",
|
|
116
|
+
"Egg",
|
|
117
|
+
"Fällanden",
|
|
118
|
+
"Greifensee",
|
|
119
|
+
"Maur",
|
|
120
|
+
"Mönchaltorf",
|
|
121
|
+
"Schwerzenbach",
|
|
122
|
+
"Uster",
|
|
123
|
+
"Volketswil",
|
|
124
|
+
"Wangen-Brüttisellen",
|
|
125
|
+
"Altikon",
|
|
126
|
+
"Brütten",
|
|
127
|
+
"Dägerlen",
|
|
128
|
+
"Dättlikon",
|
|
129
|
+
"Dinhard",
|
|
130
|
+
"Ellikon an der Thur",
|
|
131
|
+
"Elsau",
|
|
132
|
+
"Hagenbuch",
|
|
133
|
+
"Hettlingen",
|
|
134
|
+
"Neftenbach",
|
|
135
|
+
"Pfungen",
|
|
136
|
+
"Rickenbach (ZH)",
|
|
137
|
+
"Schlatt (ZH)",
|
|
138
|
+
"Seuzach",
|
|
139
|
+
"Turbenthal",
|
|
140
|
+
"Winterthur",
|
|
141
|
+
"Zell (ZH)",
|
|
142
|
+
"Aesch (ZH)",
|
|
143
|
+
"Birmensdorf (ZH)",
|
|
144
|
+
"Dietikon",
|
|
145
|
+
"Geroldswil",
|
|
146
|
+
"Oberengstringen",
|
|
147
|
+
"Oetwil an der Limmat",
|
|
148
|
+
"Schlieren",
|
|
149
|
+
"Uitikon",
|
|
150
|
+
"Unterengstringen",
|
|
151
|
+
"Urdorf",
|
|
152
|
+
"Weiningen (ZH)",
|
|
153
|
+
"Zürich",
|
|
154
|
+
"Andelfingen",
|
|
155
|
+
"Stammheim",
|
|
156
|
+
"Wädenswil",
|
|
157
|
+
"Elgg",
|
|
158
|
+
"Horgen",
|
|
159
|
+
"Illnau-Effretikon",
|
|
160
|
+
"Bauma",
|
|
161
|
+
"Wiesendangen",
|
|
162
|
+
]
|
|
@@ -1,29 +1,253 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
-
import {
|
|
2
|
+
import { ifDefined } from "lit/directives/if-defined.js"
|
|
3
|
+
import { fixture, expect, elementUpdated } from "@open-wc/testing"
|
|
4
|
+
import { sendKeys } from "@web/test-runner-commands"
|
|
3
5
|
|
|
4
6
|
import "../leu-select.js"
|
|
7
|
+
import { MUNICIPALITIES } from "./fixtures.js"
|
|
5
8
|
|
|
6
|
-
async function defaultFixture() {
|
|
7
|
-
return fixture(html
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
async function defaultFixture(args = {}) {
|
|
10
|
+
return fixture(html`<leu-select
|
|
11
|
+
.options=${args.options}
|
|
12
|
+
label=${ifDefined(args.label)}
|
|
13
|
+
.value=${args.value ?? []}
|
|
14
|
+
?clearable=${args.clearable}
|
|
15
|
+
?disabled=${args.disabled}
|
|
16
|
+
?filterable=${args.filterable}
|
|
17
|
+
?multiple=${args.multiple}
|
|
18
|
+
>
|
|
19
|
+
</leu-select> `)
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
describe("LeuSelect", () => {
|
|
18
23
|
it("is a defined element", async () => {
|
|
19
|
-
const el =
|
|
24
|
+
const el = customElements.get("leu-select")
|
|
20
25
|
|
|
21
26
|
await expect(el).not.to.be.undefined
|
|
22
27
|
})
|
|
23
28
|
|
|
24
29
|
it("passes the a11y audit", async () => {
|
|
25
|
-
const el = await defaultFixture(
|
|
30
|
+
const el = await defaultFixture({
|
|
31
|
+
options: MUNICIPALITIES,
|
|
32
|
+
label: "Gemeinde",
|
|
33
|
+
})
|
|
26
34
|
|
|
27
35
|
await expect(el).shadowDom.to.be.accessible()
|
|
28
36
|
})
|
|
37
|
+
|
|
38
|
+
it("passes the a11y audit in the open state", async () => {
|
|
39
|
+
const el = await defaultFixture({
|
|
40
|
+
options: MUNICIPALITIES,
|
|
41
|
+
label: "Gemeinde",
|
|
42
|
+
open: true,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
await expect(el).shadowDom.to.be.accessible()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("renders a label", async () => {
|
|
49
|
+
const el = await defaultFixture({
|
|
50
|
+
options: MUNICIPALITIES,
|
|
51
|
+
label: "Gemeinde",
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
55
|
+
|
|
56
|
+
expect(toggleButton).to.have.trimmed.text("Gemeinde")
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("doesn't show the list of options by default", async () => {
|
|
60
|
+
const el = await defaultFixture({
|
|
61
|
+
options: MUNICIPALITIES,
|
|
62
|
+
label: "Gemeinde",
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const dialog = el.shadowRoot.querySelector("dialog")
|
|
66
|
+
|
|
67
|
+
expect(dialog).to.not.have.attribute("open")
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it("opens the list of options when the toggle button is clicked", async () => {
|
|
71
|
+
const el = await defaultFixture({
|
|
72
|
+
options: MUNICIPALITIES,
|
|
73
|
+
label: "Gemeinde",
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
77
|
+
toggleButton.click()
|
|
78
|
+
|
|
79
|
+
const dialog = el.shadowRoot.querySelector("dialog")
|
|
80
|
+
await elementUpdated(el)
|
|
81
|
+
|
|
82
|
+
expect(dialog).to.have.attribute("open")
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it("has a default value of an empty array", async () => {
|
|
86
|
+
const el = await defaultFixture({
|
|
87
|
+
options: MUNICIPALITIES,
|
|
88
|
+
label: "Gemeinde",
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
expect(el.value).to.deep.equal([])
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it("marks the menu item as selected a the value is set", async () => {
|
|
95
|
+
const el = await defaultFixture({
|
|
96
|
+
options: MUNICIPALITIES,
|
|
97
|
+
label: "Gemeinde",
|
|
98
|
+
value: "Affoltern am Albis",
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
102
|
+
toggleButton.click()
|
|
103
|
+
|
|
104
|
+
const menuItem = el.shadowRoot.querySelector(
|
|
105
|
+
"leu-menu-item[label='Affoltern am Albis']"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
expect(menuItem).to.have.attribute("active")
|
|
109
|
+
expect(menuItem).to.have.attribute("aria-selected")
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it("shows the clear button when a value is set", async () => {
|
|
113
|
+
const el = await defaultFixture({
|
|
114
|
+
options: MUNICIPALITIES,
|
|
115
|
+
label: "Gemeinde",
|
|
116
|
+
value: "Affoltern am Albis",
|
|
117
|
+
clearable: true,
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const clearButton = el.shadowRoot.querySelector(".clear-button")
|
|
121
|
+
|
|
122
|
+
expect(clearButton).to.exist
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("renders a input field to filter the options", async () => {
|
|
126
|
+
const el = await defaultFixture({
|
|
127
|
+
options: MUNICIPALITIES,
|
|
128
|
+
label: "Gemeinde",
|
|
129
|
+
filterable: true,
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const filterInput = el.shadowRoot.querySelector(".select-search")
|
|
133
|
+
|
|
134
|
+
expect(filterInput).to.exist
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it("filters the options when the filter input is changed", async () => {
|
|
138
|
+
const el = await defaultFixture({
|
|
139
|
+
options: MUNICIPALITIES,
|
|
140
|
+
label: "Gemeinde",
|
|
141
|
+
filterable: true,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
145
|
+
toggleButton.click()
|
|
146
|
+
|
|
147
|
+
const filterInput = el.shadowRoot.querySelector(".select-search")
|
|
148
|
+
filterInput.focus()
|
|
149
|
+
|
|
150
|
+
await sendKeys({ type: "am albis" })
|
|
151
|
+
|
|
152
|
+
const menuItems = el.shadowRoot.querySelectorAll("leu-menu-item")
|
|
153
|
+
expect(menuItems.length).to.equal(6)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it("resets the filter when the filter input is cleared", async () => {
|
|
157
|
+
const el = await defaultFixture({
|
|
158
|
+
options: MUNICIPALITIES,
|
|
159
|
+
label: "Gemeinde",
|
|
160
|
+
filterable: true,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
164
|
+
toggleButton.click()
|
|
165
|
+
|
|
166
|
+
const filterInput = el.shadowRoot.querySelector(".select-search")
|
|
167
|
+
filterInput.focus()
|
|
168
|
+
|
|
169
|
+
await sendKeys({ type: "am albis" })
|
|
170
|
+
|
|
171
|
+
const clearFilterButton =
|
|
172
|
+
filterInput.shadowRoot.querySelector(".clear-button")
|
|
173
|
+
clearFilterButton.click()
|
|
174
|
+
await elementUpdated(el)
|
|
175
|
+
|
|
176
|
+
const menuItems = el.shadowRoot.querySelectorAll("leu-menu-item")
|
|
177
|
+
expect(menuItems.length).to.equal(MUNICIPALITIES.length)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it("renders a message when no options are available", async () => {
|
|
181
|
+
const el = await defaultFixture({
|
|
182
|
+
options: [],
|
|
183
|
+
label: "Gemeinde",
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
187
|
+
toggleButton.click()
|
|
188
|
+
|
|
189
|
+
const menuItem = el.shadowRoot.querySelector("leu-menu-item")
|
|
190
|
+
expect(menuItem).to.have.attribute("label", "Keine Optionen")
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it("renders a message when no options are available after filtering", async () => {
|
|
194
|
+
const el = await defaultFixture({
|
|
195
|
+
options: MUNICIPALITIES,
|
|
196
|
+
label: "Gemeinde",
|
|
197
|
+
filterable: true,
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
201
|
+
toggleButton.click()
|
|
202
|
+
|
|
203
|
+
const filterInput = el.shadowRoot.querySelector(".select-search")
|
|
204
|
+
filterInput.focus()
|
|
205
|
+
|
|
206
|
+
await sendKeys({ type: "am albissss" })
|
|
207
|
+
|
|
208
|
+
const menuItem = el.shadowRoot.querySelector("leu-menu-item")
|
|
209
|
+
expect(menuItem).to.have.attribute("label", "Keine Resultate")
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it("renders a apply button when multiple selection is allowed", async () => {
|
|
213
|
+
const el = await defaultFixture({
|
|
214
|
+
options: MUNICIPALITIES,
|
|
215
|
+
label: "Gemeinde",
|
|
216
|
+
multiple: true,
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
const applyButton = el.shadowRoot.querySelector("leu-menu + .apply-button")
|
|
220
|
+
expect(applyButton).to.exist
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it("updates the value when an option is selected", async () => {
|
|
224
|
+
const el = await defaultFixture({
|
|
225
|
+
options: MUNICIPALITIES,
|
|
226
|
+
label: "Gemeinde",
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
230
|
+
toggleButton.click()
|
|
231
|
+
|
|
232
|
+
const menuItem = el.shadowRoot.querySelector("leu-menu-item[label='Maur']")
|
|
233
|
+
menuItem.click()
|
|
234
|
+
|
|
235
|
+
expect(el.value).to.deep.equal(["Maur"])
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it("allows a value with multiple values", async () => {
|
|
239
|
+
const el = await defaultFixture({
|
|
240
|
+
options: MUNICIPALITIES,
|
|
241
|
+
label: "Gemeinde",
|
|
242
|
+
multiple: true,
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
const toggleButton = el.shadowRoot.querySelector(".select-toggle")
|
|
246
|
+
toggleButton.click()
|
|
247
|
+
|
|
248
|
+
el.shadowRoot.querySelector("leu-menu-item[label='Maur']").click()
|
|
249
|
+
el.shadowRoot.querySelector("leu-menu-item[label='Zollikon']").click()
|
|
250
|
+
|
|
251
|
+
expect(el.value).to.deep.equal(["Maur", "Zollikon"])
|
|
252
|
+
})
|
|
29
253
|
})
|
|
@@ -1,116 +1,30 @@
|
|
|
1
|
-
import { html,
|
|
1
|
+
import { html, LitElement, nothing } from "lit"
|
|
2
2
|
import { classMap } from "lit/directives/class-map.js"
|
|
3
3
|
import { styleMap } from "lit/directives/style-map.js"
|
|
4
4
|
import { createRef, ref } from "lit/directives/ref.js"
|
|
5
5
|
import { Icon } from "../icon/icon.js"
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import "../pagination/leu-pagination.js"
|
|
7
|
+
|
|
8
|
+
import styles from "./table.css"
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @tagname leu-table
|
|
11
12
|
*/
|
|
12
13
|
export class LeuTable extends LitElement {
|
|
13
|
-
static styles =
|
|
14
|
-
:host {
|
|
15
|
-
position: relative;
|
|
16
|
-
display: block;
|
|
17
|
-
}
|
|
18
|
-
div.scroll {
|
|
19
|
-
display: inline-block;
|
|
20
|
-
width: 100%;
|
|
21
|
-
overflow: auto;
|
|
22
|
-
}
|
|
23
|
-
div.shadow {
|
|
24
|
-
position: absolute;
|
|
25
|
-
left: 0;
|
|
26
|
-
top: 0;
|
|
27
|
-
width: 100%;
|
|
28
|
-
height: 100%;
|
|
29
|
-
pointer-events: none;
|
|
30
|
-
z-index: 1;
|
|
31
|
-
}
|
|
32
|
-
div.pagination {
|
|
33
|
-
height: calc(100% - 66px);
|
|
34
|
-
}
|
|
35
|
-
table {
|
|
36
|
-
width: 100%;
|
|
37
|
-
border-spacing: 0;
|
|
38
|
-
color: rgb(0 0 0 / 60%);
|
|
39
|
-
font-size: 16px;
|
|
40
|
-
font-family: var(--leu-font-regular);
|
|
41
|
-
line-height: 1.5;
|
|
42
|
-
}
|
|
43
|
-
td {
|
|
44
|
-
padding: 12px;
|
|
45
|
-
}
|
|
46
|
-
th {
|
|
47
|
-
padding: 16px 16px 8px;
|
|
48
|
-
text-align: left;
|
|
49
|
-
font-size: 12px;
|
|
50
|
-
font-weight: normal;
|
|
51
|
-
font-family: var(--leu-font-black);
|
|
52
|
-
background: var(--table-even-row-bg);
|
|
53
|
-
}
|
|
54
|
-
td:first-child,
|
|
55
|
-
th:first-child {
|
|
56
|
-
left: 0;
|
|
57
|
-
background: inherit;
|
|
58
|
-
z-index: 1;
|
|
59
|
-
}
|
|
60
|
-
tr {
|
|
61
|
-
background: #fff;
|
|
62
|
-
}
|
|
63
|
-
tbody tr:nth-child(odd) {
|
|
64
|
-
background: var(--leu-color-black-5);
|
|
65
|
-
}
|
|
66
|
-
button {
|
|
67
|
-
background: none;
|
|
68
|
-
cursor: pointer;
|
|
69
|
-
line-height: 1.5;
|
|
70
|
-
padding: 0;
|
|
71
|
-
border: 0;
|
|
72
|
-
width: 100%;
|
|
73
|
-
display: flex;
|
|
74
|
-
align-items: flex-center;
|
|
75
|
-
font-size: inherit;
|
|
76
|
-
font-family: inherit;
|
|
77
|
-
}
|
|
78
|
-
thead svg {
|
|
79
|
-
display: inline-block;
|
|
80
|
-
color: var(--leu-color-accent-blue);
|
|
81
|
-
padding: 0;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
table.sticky td:first-child,
|
|
85
|
-
table.sticky th:first-child {
|
|
86
|
-
position: sticky;
|
|
87
|
-
}
|
|
88
|
-
div.shadow-left table.sticky td:first-child,
|
|
89
|
-
div.shadow-left table.sticky th:first-child {
|
|
90
|
-
box-shadow: 0 0 5px rgb(0 0 0 / 50%);
|
|
91
|
-
clip-path: inset(0 -15px 0 0);
|
|
92
|
-
}
|
|
93
|
-
div.shadow-left {
|
|
94
|
-
box-shadow: inset 5px 0 5px -5px rgb(0 0 0 / 50%);
|
|
95
|
-
}
|
|
96
|
-
div.shadow-right {
|
|
97
|
-
box-shadow: inset -5px 0 5px -5px rgb(0 0 0 / 50%);
|
|
98
|
-
}
|
|
99
|
-
`
|
|
14
|
+
static styles = styles
|
|
100
15
|
|
|
101
16
|
static properties = {
|
|
102
17
|
columns: { type: Array },
|
|
103
18
|
data: { type: Array },
|
|
104
19
|
firstColumnSticky: { type: Boolean, reflect: true },
|
|
105
|
-
|
|
20
|
+
itemsPerPage: { type: Number, reflect: true },
|
|
106
21
|
sortIndex: { type: Number, reflect: true },
|
|
107
22
|
sortOrderAsc: { type: Boolean, reflect: true },
|
|
108
23
|
width: { type: Number, reflect: true },
|
|
109
24
|
|
|
110
|
-
_shadowLeft: {
|
|
111
|
-
_shadowRight: {
|
|
112
|
-
|
|
113
|
-
_max: { type: Number, state: true },
|
|
25
|
+
_shadowLeft: { state: true },
|
|
26
|
+
_shadowRight: { state: true },
|
|
27
|
+
_page: { state: true },
|
|
114
28
|
}
|
|
115
29
|
|
|
116
30
|
constructor() {
|
|
@@ -122,7 +36,7 @@ export class LeuTable extends LitElement {
|
|
|
122
36
|
/** @type {boolean} */
|
|
123
37
|
this.firstColumnSticky = false
|
|
124
38
|
/** @type {number} */
|
|
125
|
-
this.
|
|
39
|
+
this.itemsPerPage = null
|
|
126
40
|
/** @type {number} */
|
|
127
41
|
this.sortIndex = null
|
|
128
42
|
/** @type {boolean} */
|
|
@@ -140,14 +54,31 @@ export class LeuTable extends LitElement {
|
|
|
140
54
|
this._shadowRight = false
|
|
141
55
|
/** @internal */
|
|
142
56
|
this._scrollRef = createRef()
|
|
57
|
+
|
|
143
58
|
/** @internal */
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
this.
|
|
59
|
+
this._page = 1
|
|
60
|
+
|
|
61
|
+
this._resizeObserver = new ResizeObserver(() => {
|
|
62
|
+
this.shadowToggle(this._scrollRef.value)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
disconnectedCallback() {
|
|
67
|
+
this._resizeObserver.disconnect()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
71
|
+
super.attributeChangedCallback(name, oldVal, newVal)
|
|
72
|
+
|
|
73
|
+
if (name === "itemsperpage" || name === "data") {
|
|
74
|
+
this._page = 1
|
|
75
|
+
}
|
|
147
76
|
}
|
|
148
77
|
|
|
149
78
|
firstUpdated() {
|
|
150
79
|
this.shadowToggle(this._scrollRef.value)
|
|
80
|
+
|
|
81
|
+
this._resizeObserver.observe(this._scrollRef.value)
|
|
151
82
|
}
|
|
152
83
|
|
|
153
84
|
shadowToggle(target) {
|
|
@@ -205,8 +136,11 @@ export class LeuTable extends LitElement {
|
|
|
205
136
|
}
|
|
206
137
|
|
|
207
138
|
get _data() {
|
|
208
|
-
return this.
|
|
209
|
-
? this._sortedData.slice(
|
|
139
|
+
return this.itemsPerPage && this.itemsPerPage > 0
|
|
140
|
+
? this._sortedData.slice(
|
|
141
|
+
(this._page - 1) * this.itemsPerPage,
|
|
142
|
+
this._page * this.itemsPerPage
|
|
143
|
+
)
|
|
210
144
|
: this._sortedData
|
|
211
145
|
}
|
|
212
146
|
|
|
@@ -219,13 +153,13 @@ export class LeuTable extends LitElement {
|
|
|
219
153
|
const shadowClassesLeft = {
|
|
220
154
|
shadow: true,
|
|
221
155
|
"shadow-left": !this.firstColumnSticky && this._shadowLeft,
|
|
222
|
-
pagination: this.
|
|
156
|
+
pagination: this.itemsPerPage > 0,
|
|
223
157
|
}
|
|
224
158
|
|
|
225
159
|
const shadowClassesRight = {
|
|
226
160
|
shadow: true,
|
|
227
161
|
"shadow-right": this._shadowRight,
|
|
228
|
-
pagination: this.
|
|
162
|
+
pagination: this.itemsPerPage > 0,
|
|
229
163
|
}
|
|
230
164
|
|
|
231
165
|
const stickyClass = {
|
|
@@ -274,18 +208,14 @@ export class LeuTable extends LitElement {
|
|
|
274
208
|
<div class=${classMap(shadowClassesRight)}></div>
|
|
275
209
|
</div>
|
|
276
210
|
|
|
277
|
-
${this.
|
|
211
|
+
${this.itemsPerPage > 0
|
|
278
212
|
? html`
|
|
279
213
|
<leu-pagination
|
|
280
|
-
.
|
|
281
|
-
.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.
|
|
285
|
-
// after render
|
|
286
|
-
setTimeout(() => {
|
|
287
|
-
this.shadowToggle(this._scrollRef.value)
|
|
288
|
-
}, 0)
|
|
214
|
+
.numOfItems=${this._sortedData.length}
|
|
215
|
+
.itemsPerPage=${this.itemsPerPage}
|
|
216
|
+
page=${this._page}
|
|
217
|
+
@leu:pagechange=${(e) => {
|
|
218
|
+
this._page = e.detail.page
|
|
289
219
|
}}
|
|
290
220
|
>
|
|
291
221
|
</leu-pagination>
|
|
@@ -294,8 +224,3 @@ export class LeuTable extends LitElement {
|
|
|
294
224
|
`
|
|
295
225
|
}
|
|
296
226
|
}
|
|
297
|
-
|
|
298
|
-
export function defineTableElements() {
|
|
299
|
-
definePaginationElements()
|
|
300
|
-
defineElement("table", LeuTable)
|
|
301
|
-
}
|