@statistikzh/leu 0.3.0 → 0.5.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 -6
- package/.storybook/static/logo.svg +19 -0
- package/.storybook/theme.js +7 -0
- package/CHANGELOG.md +54 -0
- package/README.md +1 -1
- package/custom-elements-manifest.config.js +46 -0
- package/dist/Accordion.d.ts +31 -0
- package/dist/Accordion.d.ts.map +1 -0
- package/dist/Accordion.js +257 -0
- package/dist/Breadcrumb.d.ts +69 -0
- package/dist/Breadcrumb.d.ts.map +1 -0
- package/dist/Breadcrumb.js +392 -0
- package/dist/Button-da11d064.d.ts +84 -0
- package/dist/Button-da11d064.d.ts.map +1 -0
- package/dist/Button-da11d064.js +542 -0
- package/dist/Button.d.ts +2 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +6 -423
- package/dist/ButtonGroup.d.ts +24 -0
- package/dist/ButtonGroup.d.ts.map +1 -0
- package/dist/ButtonGroup.js +72 -43
- package/dist/Checkbox.d.ts +13 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +101 -84
- package/dist/CheckboxGroup.d.ts +13 -0
- package/dist/CheckboxGroup.d.ts.map +1 -0
- package/dist/CheckboxGroup.js +41 -37
- package/dist/Chip.d.ts +5 -0
- package/dist/Chip.d.ts.map +1 -0
- package/dist/{Chip-5f70d04f.js → Chip.js} +21 -6
- package/dist/ChipGroup.d.ts +28 -0
- package/dist/ChipGroup.d.ts.map +1 -0
- package/dist/ChipGroup.js +64 -10
- package/dist/ChipLink.d.ts +15 -0
- package/dist/ChipLink.d.ts.map +1 -0
- package/dist/ChipLink.js +4 -7
- package/dist/ChipRemovable.d.ts +13 -0
- package/dist/ChipRemovable.d.ts.map +1 -0
- package/dist/ChipRemovable.js +5 -8
- package/dist/ChipSelectable.d.ts +22 -0
- package/dist/ChipSelectable.d.ts.map +1 -0
- package/dist/ChipSelectable.js +8 -11
- package/dist/Dropdown.d.ts +15 -0
- package/dist/Dropdown.d.ts.map +1 -0
- package/dist/Dropdown.js +73 -26
- package/dist/Input.d.ts +154 -0
- package/dist/Input.d.ts.map +1 -0
- package/dist/Input.js +42 -35
- package/dist/Menu.d.ts +8 -0
- package/dist/Menu.d.ts.map +1 -0
- package/dist/Menu.js +2 -5
- package/dist/MenuItem.d.ts +21 -0
- package/dist/MenuItem.d.ts.map +1 -0
- package/dist/MenuItem.js +32 -17
- package/dist/Pagination.d.ts +27 -0
- package/dist/Pagination.d.ts.map +1 -0
- package/dist/Pagination.js +121 -89
- package/dist/Popup.d.ts +18 -0
- package/dist/Popup.d.ts.map +1 -0
- package/dist/Popup.js +215 -0
- package/dist/Radio.d.ts +12 -0
- package/dist/Radio.d.ts.map +1 -0
- package/dist/Radio.js +9 -8
- package/dist/RadioGroup.d.ts +20 -0
- package/dist/RadioGroup.d.ts.map +1 -0
- package/dist/RadioGroup.js +41 -39
- package/dist/ScrollTop.d.ts +19 -0
- package/dist/ScrollTop.d.ts.map +1 -0
- package/dist/ScrollTop.js +122 -0
- package/dist/Select.d.ts +98 -0
- package/dist/Select.d.ts.map +1 -0
- package/dist/Select.js +79 -122
- package/dist/Table.d.ts +48 -0
- package/dist/Table.d.ts.map +1 -0
- package/dist/Table.js +141 -121
- package/dist/VisuallyHidden.d.ts +8 -0
- package/dist/VisuallyHidden.d.ts.map +1 -0
- package/dist/VisuallyHidden.js +28 -0
- package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts +3 -0
- package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts.map +1 -0
- package/dist/{defineElement-ba770aed.js → _rollupPluginBabelHelpers-20f659f4.js} +1 -15
- package/dist/defineElement-40372b4b.d.ts +9 -0
- package/dist/defineElement-40372b4b.d.ts.map +1 -0
- package/dist/defineElement-40372b4b.js +15 -0
- package/dist/icon-03e86700.d.ts +11 -0
- package/dist/icon-03e86700.d.ts.map +1 -0
- package/dist/index.js.d.ts +21 -0
- package/dist/index.js.d.ts.map +1 -0
- package/dist/index.js.js +42 -0
- package/dist/leu-accordion.d.ts +3 -0
- package/dist/leu-accordion.d.ts.map +1 -0
- package/dist/leu-accordion.js +9 -0
- package/dist/leu-breadcrumb.d.ts +3 -0
- package/dist/leu-breadcrumb.d.ts.map +1 -0
- package/dist/leu-breadcrumb.js +23 -0
- package/dist/leu-button-group.d.ts +3 -0
- package/dist/leu-button-group.d.ts.map +1 -0
- package/dist/leu-button-group.js +6 -6
- package/dist/leu-button.d.ts +3 -0
- package/dist/leu-button.d.ts.map +1 -0
- package/dist/leu-button.js +7 -3
- package/dist/leu-checkbox-group.d.ts +3 -0
- package/dist/leu-checkbox-group.d.ts.map +1 -0
- package/dist/leu-checkbox-group.js +6 -3
- package/dist/leu-checkbox.d.ts +3 -0
- package/dist/leu-checkbox.d.ts.map +1 -0
- package/dist/leu-checkbox.js +6 -3
- package/dist/leu-chip-group.d.ts +3 -0
- package/dist/leu-chip-group.d.ts.map +1 -0
- package/dist/leu-chip-group.js +7 -3
- package/dist/leu-chip-link.d.ts +3 -0
- package/dist/leu-chip-link.d.ts.map +1 -0
- package/dist/leu-chip-link.js +7 -4
- package/dist/leu-chip-removable.d.ts +3 -0
- package/dist/leu-chip-removable.d.ts.map +1 -0
- package/dist/leu-chip-removable.js +7 -4
- package/dist/leu-chip-selectable.d.ts +3 -0
- package/dist/leu-chip-selectable.d.ts.map +1 -0
- package/dist/leu-chip-selectable.js +7 -4
- package/dist/leu-dropdown.d.ts +3 -0
- package/dist/leu-dropdown.d.ts.map +1 -0
- package/dist/leu-dropdown.js +15 -4
- package/dist/leu-input.d.ts +3 -0
- package/dist/leu-input.d.ts.map +1 -0
- package/dist/leu-input.js +7 -3
- package/dist/leu-menu-item.d.ts +3 -0
- package/dist/leu-menu-item.d.ts.map +1 -0
- package/dist/leu-menu-item.js +8 -3
- package/dist/leu-menu.d.ts +3 -0
- package/dist/leu-menu.d.ts.map +1 -0
- package/dist/leu-menu.js +6 -3
- package/dist/leu-pagination.d.ts +3 -0
- package/dist/leu-pagination.d.ts.map +1 -0
- package/dist/leu-pagination.js +12 -4
- package/dist/leu-popup.d.ts +3 -0
- package/dist/leu-popup.d.ts.map +1 -0
- package/dist/leu-popup.js +9 -0
- package/dist/leu-radio-group.d.ts +3 -0
- package/dist/leu-radio-group.d.ts.map +1 -0
- package/dist/leu-radio-group.js +6 -3
- package/dist/leu-radio.d.ts +3 -0
- package/dist/leu-radio.d.ts.map +1 -0
- package/dist/leu-radio.js +6 -3
- package/dist/leu-scroll-top.d.ts +3 -0
- package/dist/leu-scroll-top.d.ts.map +1 -0
- package/dist/leu-scroll-top.js +14 -0
- package/dist/leu-select.d.ts +3 -0
- package/dist/leu-select.d.ts.map +1 -0
- package/dist/leu-select.js +16 -4
- package/dist/leu-table.d.ts +3 -0
- package/dist/leu-table.d.ts.map +1 -0
- package/dist/leu-table.js +13 -4
- package/dist/leu-visually-hidden.d.ts +3 -0
- package/dist/leu-visually-hidden.d.ts.map +1 -0
- package/dist/leu-visually-hidden.js +8 -0
- package/dist/theme.css +386 -2
- package/dist/utils-65469421.d.ts +16 -0
- package/dist/utils-65469421.d.ts.map +1 -0
- package/dist/utils-65469421.js +35 -0
- package/index.js +3 -0
- package/package.json +47 -17
- package/postcss.config.cjs +2 -0
- package/rollup.config.js +21 -40
- package/scripts/generate-component/templates/[Name].js +0 -5
- package/scripts/generate-component/templates/[name].css +3 -3
- package/scripts/generate-component/templates/[namespace]-[name].js +5 -2
- package/scripts/postcss-leu-font-styles.cjs +160 -0
- package/src/components/accordion/Accordion.js +0 -6
- package/src/components/accordion/accordion.css +2 -2
- package/src/components/accordion/leu-accordion.js +5 -2
- package/src/components/accordion/stories/accordion.stories.js +8 -4
- package/src/components/accordion/test/accordion.test.js +95 -3
- package/src/components/breadcrumb/Breadcrumb.js +311 -0
- package/src/components/breadcrumb/breadcrumb.css +103 -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 +76 -20
- package/src/components/button/button.css +13 -5
- package/src/components/button/leu-button.js +5 -2
- package/src/components/button/stories/button.stories.js +79 -105
- package/src/components/button/test/button.test.js +184 -3
- package/src/components/button-group/ButtonGroup.js +76 -40
- package/src/components/button-group/leu-button-group.js +5 -2
- package/src/components/button-group/stories/button-group.stories.js +19 -6
- package/src/components/button-group/test/button-group.test.js +87 -4
- 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 +42 -7
- package/src/components/chip/ChipLink.js +1 -6
- package/src/components/chip/ChipRemovable.js +2 -7
- package/src/components/chip/ChipSelectable.js +5 -10
- package/src/components/chip/chip-group.css +12 -2
- package/src/components/chip/chip.css +14 -3
- 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 +110 -44
- 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 +72 -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 +25 -28
- package/src/components/input/input.css +11 -8
- package/src/components/input/leu-input.js +5 -2
- package/src/components/input/stories/input.stories.js +21 -2
- package/src/components/input/test/input.test.js +432 -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 +7 -4
- 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 +118 -99
- package/src/components/pagination/leu-pagination.js +5 -2
- package/src/components/pagination/pagination.css +6 -1
- package/src/components/pagination/stories/pagination.stories.js +30 -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/radio.css +1 -1
- 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/scroll-top/ScrollTop.js +87 -0
- package/src/components/scroll-top/leu-scroll-top.js +6 -0
- package/src/components/scroll-top/scroll-top.css +34 -0
- package/src/components/scroll-top/stories/scroll-top.stories.js +217 -0
- package/src/components/scroll-top/test/scroll-top.test.js +22 -0
- package/src/components/select/Select.js +58 -37
- package/src/components/select/leu-select.js +5 -2
- package/src/components/select/select.css +15 -15
- 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/components/visually-hidden/VisuallyHidden.js +13 -0
- package/src/components/visually-hidden/leu-visually-hidden.js +6 -0
- package/src/components/visually-hidden/stories/visually-hidden.stories.js +22 -0
- package/src/components/visually-hidden/test/visually-hidden.test.js +36 -0
- package/src/components/visually-hidden/visually-hidden.css +10 -0
- package/src/lib/defineElement.js +1 -1
- package/src/lib/hasSlotController.js +5 -3
- package/src/lib/utils.js +35 -0
- package/src/styles/custom-properties.css +6 -2
- package/src/styles/font-definitions.json +202 -0
- package/stylelint.config.mjs +2 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.json +16 -0
- package/{web-dev-server-storybook.config.mjs → web-dev-server.config.mjs} +1 -2
- package/web-test-runner.config.mjs +15 -2
- package/dist/index.js +0 -26
|
@@ -5,16 +5,22 @@ import "../leu-menu-item.js"
|
|
|
5
5
|
export default {
|
|
6
6
|
title: "Menu",
|
|
7
7
|
component: "leu-menu",
|
|
8
|
+
parameters: {
|
|
9
|
+
design: {
|
|
10
|
+
type: "figma",
|
|
11
|
+
url: "https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=17340-82208&mode=design&t=lzVrtq8lxYVJU5TB-11",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
function Template() {
|
|
11
17
|
return html` <leu-menu>
|
|
12
|
-
<leu-menu-item
|
|
13
|
-
<leu-menu-item before="check" active
|
|
14
|
-
<leu-menu-item
|
|
18
|
+
<leu-menu-item label="Menu Item 1" before="EMPTY"></leu-menu-item>
|
|
19
|
+
<leu-menu-item label="Menu Item 2" before="check" active></leu-menu-item>
|
|
20
|
+
<leu-menu-item label="Menu Item 3" before="EMPTY"></leu-menu-item>
|
|
15
21
|
<hr />
|
|
16
|
-
<leu-menu-item before="pin" after="CH"
|
|
17
|
-
<leu-menu-item
|
|
22
|
+
<leu-menu-item label="Menu Item 3" before="pin" after="CH"></leu-menu-item>
|
|
23
|
+
<leu-menu-item label="Menu Item 4"></leu-menu-item>
|
|
18
24
|
</leu-menu>`
|
|
19
25
|
}
|
|
20
26
|
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { html } from "lit"
|
|
2
|
+
import { fixture, expect, oneEvent } from "@open-wc/testing"
|
|
3
|
+
import { ifDefined } from "lit/directives/if-defined.js"
|
|
4
|
+
import { spy } from "sinon"
|
|
5
|
+
|
|
6
|
+
import "../leu-menu-item.js"
|
|
7
|
+
|
|
8
|
+
async function defaultFixture(args = {}) {
|
|
9
|
+
return fixture(html`
|
|
10
|
+
<leu-menu-item
|
|
11
|
+
label=${args.label}
|
|
12
|
+
before=${ifDefined(args.before)}
|
|
13
|
+
after=${ifDefined(args.after)}
|
|
14
|
+
href=${ifDefined(args.href)}
|
|
15
|
+
?active=${args.active}
|
|
16
|
+
?disabled=${args.disabled}
|
|
17
|
+
></leu-menu-item>
|
|
18
|
+
`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("LeuMenuItem", () => {
|
|
22
|
+
it("is a defined element", async () => {
|
|
23
|
+
const el = customElements.get("leu-menu-item")
|
|
24
|
+
|
|
25
|
+
await expect(el).not.to.be.undefined
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("passes the a11y audit", async () => {
|
|
29
|
+
const el = await defaultFixture({ label: "Download" })
|
|
30
|
+
|
|
31
|
+
await expect(el).shadowDom.to.be.accessible()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("passes the a11y audit with a link", async () => {
|
|
35
|
+
const el = await defaultFixture({
|
|
36
|
+
label: "Download",
|
|
37
|
+
href: "https://zh.ch",
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
await expect(el).shadowDom.to.be.accessible()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it("renders a label", async () => {
|
|
44
|
+
const el = await defaultFixture({ label: "Download" })
|
|
45
|
+
|
|
46
|
+
const button = el.shadowRoot.querySelector("button")
|
|
47
|
+
|
|
48
|
+
expect(button).to.have.trimmed.text("Download")
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it("renders a button", async () => {
|
|
52
|
+
const el = await defaultFixture({ label: "Download" })
|
|
53
|
+
|
|
54
|
+
const button = el.shadowRoot.querySelector("button")
|
|
55
|
+
|
|
56
|
+
expect(button).to.exist
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("renders a link", async () => {
|
|
60
|
+
const el = await defaultFixture({
|
|
61
|
+
label: "Kanton Zürich",
|
|
62
|
+
href: "https://zh.ch",
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const link = el.shadowRoot.querySelector("a")
|
|
66
|
+
|
|
67
|
+
expect(link).to.exist
|
|
68
|
+
expect(link).to.have.attribute("href", "https://zh.ch")
|
|
69
|
+
expect(link).to.have.trimmed.text("Kanton Zürich")
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it("renders a before icon", async () => {
|
|
73
|
+
const el = await defaultFixture({ label: "Download", before: "download" })
|
|
74
|
+
|
|
75
|
+
const before = el.shadowRoot.querySelector(".before")
|
|
76
|
+
expect(before).to.exist
|
|
77
|
+
|
|
78
|
+
expect(el).shadowDom.to.equal(
|
|
79
|
+
"<button class='button'><span class='before'></span><span class='label'>Download</span></button>"
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("renders a before label", async () => {
|
|
84
|
+
const el = await defaultFixture({ label: "Download", before: "DE" })
|
|
85
|
+
|
|
86
|
+
const before = el.shadowRoot.querySelector(".before")
|
|
87
|
+
expect(before).to.exist
|
|
88
|
+
expect(before).to.have.trimmed.text("DE")
|
|
89
|
+
|
|
90
|
+
expect(el).shadowDom.to.equal(
|
|
91
|
+
"<button class='button'><span class='before'>DE</span><span class='label'>Download</span></button>"
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it("renders a before placeholder", async () => {
|
|
96
|
+
const el = await defaultFixture({ label: "Download", before: "EMPTY" })
|
|
97
|
+
|
|
98
|
+
const before = el.shadowRoot.querySelector(".before")
|
|
99
|
+
expect(before).to.exist
|
|
100
|
+
expect(before).to.not.have.trimmed.text()
|
|
101
|
+
|
|
102
|
+
const iconPlaceholder = before.querySelector(".icon-placeholder")
|
|
103
|
+
expect(iconPlaceholder).to.exist
|
|
104
|
+
|
|
105
|
+
expect(el).shadowDom.to.equal(
|
|
106
|
+
"<button class='button'><span class='before'><div class='icon-placeholder'></div></span><span class='label'>Download</span></button>"
|
|
107
|
+
)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("renders a after icon", async () => {
|
|
111
|
+
const el = await defaultFixture({ label: "Download", after: "download" })
|
|
112
|
+
|
|
113
|
+
const after = el.shadowRoot.querySelector(".after")
|
|
114
|
+
expect(after).to.exist
|
|
115
|
+
|
|
116
|
+
expect(el).shadowDom.to.equal(
|
|
117
|
+
"<button class='button'><span class='label'>Download</span><span class='after'></span></button>"
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("renders a after label", async () => {
|
|
122
|
+
const el = await defaultFixture({ label: "Download", after: "DE" })
|
|
123
|
+
|
|
124
|
+
const after = el.shadowRoot.querySelector(".after")
|
|
125
|
+
expect(after).to.exist
|
|
126
|
+
expect(after).to.have.trimmed.text("DE")
|
|
127
|
+
|
|
128
|
+
expect(el).shadowDom.to.equal(
|
|
129
|
+
"<button class='button'><span class='label'>Download</span><span class='after'>DE</span></button>"
|
|
130
|
+
)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it("renders a after placeholder", async () => {
|
|
134
|
+
const el = await defaultFixture({ label: "Download", after: "EMPTY" })
|
|
135
|
+
|
|
136
|
+
const after = el.shadowRoot.querySelector(".after")
|
|
137
|
+
expect(after).to.exist
|
|
138
|
+
expect(after).to.not.have.trimmed.text()
|
|
139
|
+
|
|
140
|
+
const iconPlaceholder = after.querySelector(".icon-placeholder")
|
|
141
|
+
expect(iconPlaceholder).to.exist
|
|
142
|
+
|
|
143
|
+
expect(el).shadowDom.to.equal(
|
|
144
|
+
"<button class='button'><span class='label'>Download</span><span class='after'><div class='icon-placeholder'></div></span></button>"
|
|
145
|
+
)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it("passes the disabled attribute to the button", async () => {
|
|
149
|
+
const el = await defaultFixture({ label: "Download", disabled: true })
|
|
150
|
+
|
|
151
|
+
const button = el.shadowRoot.querySelector("button")
|
|
152
|
+
expect(button).to.have.attribute("disabled")
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it("lets the click event bubble up", async () => {
|
|
156
|
+
const el = await defaultFixture({ label: "Download" })
|
|
157
|
+
|
|
158
|
+
const button = el.shadowRoot.querySelector("button")
|
|
159
|
+
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
button.click()
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const event = await oneEvent(el, "click")
|
|
165
|
+
|
|
166
|
+
expect(event).to.exist
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it("does not let the click event bubble up when disabled", async () => {
|
|
170
|
+
const el = await defaultFixture({ label: "Download", disabled: true })
|
|
171
|
+
|
|
172
|
+
const button = el.shadowRoot.querySelector("button")
|
|
173
|
+
const clickSpy = spy()
|
|
174
|
+
button.addEventListener("click", clickSpy)
|
|
175
|
+
|
|
176
|
+
el.click()
|
|
177
|
+
|
|
178
|
+
expect(clickSpy).to.have.not.been.called
|
|
179
|
+
})
|
|
180
|
+
})
|
|
@@ -2,14 +2,22 @@ import { html } from "lit"
|
|
|
2
2
|
import { fixture, expect } from "@open-wc/testing"
|
|
3
3
|
|
|
4
4
|
import "../leu-menu.js"
|
|
5
|
+
import "../leu-menu-item.js"
|
|
5
6
|
|
|
6
7
|
async function defaultFixture() {
|
|
7
|
-
return fixture(html` <leu-menu
|
|
8
|
+
return fixture(html` <leu-menu>
|
|
9
|
+
<leu-menu-item label="Menu Item 1" before="EMPTY"></leu-menu-item>
|
|
10
|
+
<leu-menu-item label="Menu Item 2" before="check" active></leu-menu-item>
|
|
11
|
+
<leu-menu-item label="Menu Item 3" before="EMPTY"></leu-menu-item>
|
|
12
|
+
<hr />
|
|
13
|
+
<leu-menu-item label="Menu Item 3" before="pin" after="CH"></leu-menu-item>
|
|
14
|
+
<leu-menu-item label="Menu Item 4"></leu-menu-item>
|
|
15
|
+
</leu-menu>`)
|
|
8
16
|
}
|
|
9
17
|
|
|
10
18
|
describe("LeuMenu", () => {
|
|
11
19
|
it("is a defined element", async () => {
|
|
12
|
-
const el =
|
|
20
|
+
const el = customElements.get("leu-menu")
|
|
13
21
|
|
|
14
22
|
await expect(el).not.to.be.undefined
|
|
15
23
|
})
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { html, LitElement } from "lit"
|
|
2
|
-
import {
|
|
3
|
-
import { defineButtonElements } from "../button/Button.js"
|
|
2
|
+
import { live } from "lit/directives/live.js"
|
|
4
3
|
|
|
4
|
+
import "../button/leu-button.js"
|
|
5
5
|
import styles from "./pagination.css"
|
|
6
6
|
|
|
7
|
+
import "../visually-hidden/leu-visually-hidden.js"
|
|
8
|
+
|
|
7
9
|
const MIN_PAGE = 1
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -12,141 +14,158 @@ const MIN_PAGE = 1
|
|
|
12
14
|
export class LeuPagination extends LitElement {
|
|
13
15
|
static styles = styles
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
static shadowRootOptions = {
|
|
21
|
+
...LitElement.shadowRootOptions,
|
|
22
|
+
delegatesFocus: true,
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
static properties = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
defaultPage: { type: Number, reflect: true },
|
|
27
|
+
itemsPerPage: { type: Number, reflect: true },
|
|
28
|
+
numOfItems: { type: Number, reflect: true },
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Internal page state that contains an
|
|
32
|
+
* already clamped page number. Should only
|
|
33
|
+
* be accessed through the `page` getter and
|
|
34
|
+
* setter.
|
|
35
|
+
* @type {Number}
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
_page: { state: true },
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
constructor() {
|
|
28
42
|
super()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
|
|
44
|
+
/** @type {Number} */
|
|
45
|
+
this.numOfItems = 1
|
|
46
|
+
/** @type {Number} */
|
|
47
|
+
this.itemsPerPage = 1
|
|
48
|
+
/** @type {Number} */
|
|
49
|
+
this._page = 1
|
|
35
50
|
}
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
53
|
+
super.attributeChangedCallback(name, oldVal, newVal)
|
|
54
|
+
|
|
55
|
+
if (name === "defaultpage" && newVal !== oldVal) {
|
|
56
|
+
this.page = parseInt(newVal, 10)
|
|
57
|
+
}
|
|
39
58
|
}
|
|
40
59
|
|
|
41
|
-
get
|
|
42
|
-
return this.
|
|
60
|
+
get page() {
|
|
61
|
+
return this._page
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
set page(page) {
|
|
65
|
+
this._page = this._clampPage(page)
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
|
|
50
|
-
return
|
|
68
|
+
get startIndex() {
|
|
69
|
+
return (this.page - 1) * this.itemsPerPage
|
|
51
70
|
}
|
|
52
71
|
|
|
53
|
-
|
|
54
|
-
this.
|
|
72
|
+
get endIndex() {
|
|
73
|
+
return Math.min(this.startIndex + this.itemsPerPage, this.numOfItems)
|
|
74
|
+
}
|
|
55
75
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.dispatchEvent(
|
|
59
|
-
new CustomEvent("range-updated", {
|
|
60
|
-
detail: {
|
|
61
|
-
min,
|
|
62
|
-
max,
|
|
63
|
-
},
|
|
64
|
-
bubbles: false,
|
|
65
|
-
})
|
|
66
|
-
)
|
|
76
|
+
get _maxPage() {
|
|
77
|
+
return Math.ceil(this.numOfItems / this.itemsPerPage)
|
|
67
78
|
}
|
|
68
79
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.numberUpdate(parseInt(event.target.value, 10) || 0)
|
|
80
|
+
_isFirstPage() {
|
|
81
|
+
return this.page === MIN_PAGE
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
event.preventDefault()
|
|
77
|
-
this.change(event)
|
|
78
|
-
}
|
|
84
|
+
_isLastPage() {
|
|
85
|
+
return this.page === this._maxPage
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
event.preventDefault()
|
|
101
|
-
this.numberUpdate(this.page - 1)
|
|
102
|
-
}
|
|
88
|
+
_clampPage(page) {
|
|
89
|
+
return Math.min(Math.max(page, MIN_PAGE), this._maxPage)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_updatePage(page) {
|
|
93
|
+
const prevPage = this.page
|
|
94
|
+
this.page = this._clampPage(page)
|
|
95
|
+
|
|
96
|
+
if (this.page !== prevPage) {
|
|
97
|
+
this.dispatchEvent(
|
|
98
|
+
new CustomEvent("leu:pagechange", {
|
|
99
|
+
detail: {
|
|
100
|
+
startIndex: this.startIndex,
|
|
101
|
+
endIndex: this.endIndex,
|
|
102
|
+
page: this.page,
|
|
103
|
+
},
|
|
104
|
+
bubbles: false,
|
|
105
|
+
})
|
|
106
|
+
)
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
this.
|
|
110
|
+
_handleChange(event) {
|
|
111
|
+
this._updatePage(parseInt(event.target.value, 10) || 0)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_handleInput(event) {
|
|
115
|
+
if (event.target.value !== "") {
|
|
116
|
+
event.preventDefault()
|
|
117
|
+
this._handleChange(event)
|
|
118
|
+
}
|
|
108
119
|
}
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
121
|
+
_handleKeyDown(event) {
|
|
122
|
+
if (event.key === "ArrowUp") {
|
|
123
|
+
event.preventDefault()
|
|
124
|
+
this._updatePage(this.page + 1)
|
|
125
|
+
}
|
|
126
|
+
if (event.key === "ArrowDown") {
|
|
127
|
+
event.preventDefault()
|
|
128
|
+
this._updatePage(this.page - 1)
|
|
113
129
|
}
|
|
114
|
-
return super.requestUpdate(name, oldValue, newValue)
|
|
115
130
|
}
|
|
116
131
|
|
|
117
132
|
render() {
|
|
118
133
|
return html`
|
|
134
|
+
<leu-visually-hidden>
|
|
135
|
+
<label for="page-input">Aktuelle Seite</label>
|
|
136
|
+
</leu-visually-hidden>
|
|
119
137
|
<input
|
|
138
|
+
id="page-input"
|
|
120
139
|
class="input"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@
|
|
140
|
+
min=${MIN_PAGE}
|
|
141
|
+
max=${this._maxPage}
|
|
142
|
+
.value=${live(this.page.toString())}
|
|
143
|
+
@input=${this._handleInput}
|
|
144
|
+
@change=${this._handleChange}
|
|
145
|
+
@keydown=${this._handleKeyDown}
|
|
125
146
|
type="number"
|
|
126
147
|
/>
|
|
127
|
-
<div class="label">von ${this.
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
<div class="label">von ${this._maxPage}</div>
|
|
149
|
+
<div class="button-group">
|
|
150
|
+
<leu-button
|
|
151
|
+
icon="angleLeft"
|
|
152
|
+
variant="secondary"
|
|
153
|
+
label="Vorherige Seite"
|
|
154
|
+
@click=${(_) => {
|
|
155
|
+
this._updatePage(this.page - 1)
|
|
156
|
+
}}
|
|
157
|
+
?disabled=${this._isFirstPage()}
|
|
158
|
+
></leu-button>
|
|
159
|
+
<leu-button
|
|
160
|
+
icon="angleRight"
|
|
161
|
+
variant="secondary"
|
|
162
|
+
label="Nächste Seite"
|
|
163
|
+
@click=${(_) => {
|
|
164
|
+
this._updatePage(this.page + 1)
|
|
165
|
+
}}
|
|
166
|
+
?disabled=${this._isLastPage()}
|
|
167
|
+
></leu-button>
|
|
168
|
+
</div>
|
|
145
169
|
`
|
|
146
170
|
}
|
|
147
171
|
}
|
|
148
|
-
|
|
149
|
-
export function definePaginationElements() {
|
|
150
|
-
defineButtonElements()
|
|
151
|
-
defineElement("pagination", LeuPagination)
|
|
152
|
-
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineElement } from "../../lib/defineElement.js"
|
|
2
|
+
import { LeuPagination } from "./Pagination.js"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export { LeuPagination }
|
|
5
|
+
|
|
6
|
+
defineElement("pagination", LeuPagination)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
margin-top: 16px;
|
|
3
3
|
display: flex;
|
|
4
4
|
justify-content: end;
|
|
5
|
-
font-family: var(--leu-font-regular);
|
|
5
|
+
font-family: var(--leu-font-family-regular);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.input {
|
|
@@ -47,3 +47,8 @@
|
|
|
47
47
|
color: var(--leu-color-black-transp-60);
|
|
48
48
|
white-space: nowrap;
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
.button-group {
|
|
52
|
+
display: flex;
|
|
53
|
+
gap: 0.25rem;
|
|
54
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
+
import { action } from "@storybook/addon-actions"
|
|
3
|
+
|
|
2
4
|
import "../leu-pagination.js"
|
|
3
5
|
|
|
4
6
|
// https://stackoverflow.com/questions/72566428/storybook-angular-how-to-dynamically-update-args-from-the-template
|
|
5
7
|
import { UPDATE_STORY_ARGS } from "@storybook/core-events" // eslint-disable-line
|
|
8
|
+
import { ifDefined } from "lit/directives/if-defined.js"
|
|
6
9
|
function updateStorybookArgss(id, args) {
|
|
7
10
|
const channel = window.__STORYBOOK_ADDONS_CHANNEL__
|
|
8
11
|
channel.emit(UPDATE_STORY_ARGS, {
|
|
@@ -56,18 +59,34 @@ const items = [
|
|
|
56
59
|
export default {
|
|
57
60
|
title: "Pagination",
|
|
58
61
|
component: "leu-pagination",
|
|
62
|
+
args: {
|
|
63
|
+
onPageChange: action("leu:pagechange"),
|
|
64
|
+
},
|
|
65
|
+
parameters: {
|
|
66
|
+
design: {
|
|
67
|
+
type: "figma",
|
|
68
|
+
url: "https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=17341-82468&mode=design&t=lzVrtq8lxYVJU5TB-11",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
59
71
|
}
|
|
60
72
|
|
|
61
|
-
function Template(
|
|
73
|
+
function Template(
|
|
74
|
+
{ startIndex, endIndex, onPageChange, itemsPerPage, defaultPage },
|
|
75
|
+
{ id }
|
|
76
|
+
) {
|
|
62
77
|
return html`
|
|
63
|
-
${items
|
|
78
|
+
${items
|
|
79
|
+
.slice(startIndex, endIndex)
|
|
80
|
+
.map((item) => html`<div>${item.label}</div>`)}
|
|
64
81
|
<leu-pagination
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
numOfItems=${items.length}
|
|
83
|
+
itemsPerPage=${ifDefined(itemsPerPage)}
|
|
84
|
+
defaultPage=${ifDefined(defaultPage)}
|
|
85
|
+
@leu:pagechange=${(e) => {
|
|
86
|
+
onPageChange(e)
|
|
68
87
|
updateStorybookArgss(id, {
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
startIndex: e.detail.startIndex,
|
|
89
|
+
endIndex: e.detail.endIndex,
|
|
71
90
|
})
|
|
72
91
|
}}
|
|
73
92
|
>
|
|
@@ -77,6 +96,8 @@ function Template({ min, max }, { id }) {
|
|
|
77
96
|
|
|
78
97
|
export const Regular = Template.bind({})
|
|
79
98
|
Regular.args = {
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
startIndex: 0,
|
|
100
|
+
endIndex: 5,
|
|
101
|
+
itemsPerPage: 5,
|
|
102
|
+
// defaultPage: 2,
|
|
82
103
|
}
|