@statistikzh/leu 0.5.1 → 0.7.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/.husky/commit-msg +0 -3
- package/.husky/pre-commit +0 -3
- package/CHANGELOG.md +54 -0
- package/dist/Accordion.d.ts +10 -9
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +12 -11
- package/dist/Breadcrumb.d.ts +4 -4
- package/dist/Breadcrumb.d.ts.map +1 -1
- package/dist/Breadcrumb.js +28 -24
- package/dist/{Button-5326c982.d.ts → Button-7370f901.d.ts} +10 -11
- package/dist/Button-7370f901.d.ts.map +1 -0
- package/dist/{Button-5326c982.js → Button-7370f901.js} +57 -67
- package/dist/Button.d.ts +1 -1
- package/dist/Button.js +3 -3
- package/dist/ButtonGroup.d.ts +2 -2
- package/dist/ButtonGroup.d.ts.map +1 -1
- package/dist/ButtonGroup.js +3 -3
- package/dist/Checkbox.d.ts +4 -3
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Checkbox.js +14 -17
- package/dist/CheckboxGroup.d.ts +2 -2
- package/dist/CheckboxGroup.d.ts.map +1 -1
- package/dist/CheckboxGroup.js +4 -4
- package/dist/Chip.d.ts +2 -2
- package/dist/Chip.d.ts.map +1 -1
- package/dist/Chip.js +23 -28
- package/dist/ChipGroup.d.ts +16 -8
- package/dist/ChipGroup.d.ts.map +1 -1
- package/dist/ChipGroup.js +39 -9
- package/dist/ChipLink.d.ts +2 -1
- package/dist/ChipLink.d.ts.map +1 -1
- package/dist/ChipLink.js +4 -7
- package/dist/ChipRemovable.d.ts +0 -2
- package/dist/ChipRemovable.d.ts.map +1 -1
- package/dist/ChipRemovable.js +8 -11
- package/dist/ChipSelectable.d.ts +12 -2
- package/dist/ChipSelectable.d.ts.map +1 -1
- package/dist/ChipSelectable.js +24 -26
- package/dist/Dropdown.d.ts +9 -5
- package/dist/Dropdown.d.ts.map +1 -1
- package/dist/Dropdown.js +68 -32
- package/dist/Icon.d.ts +116 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/{icon-03e86700.js → Icon.js} +61 -32
- package/dist/Input.d.ts +13 -17
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +33 -24
- package/dist/LeuElement-ba5ea33d.d.ts +7 -0
- package/dist/LeuElement-ba5ea33d.d.ts.map +1 -0
- package/dist/{_rollupPluginBabelHelpers-20f659f4.js → LeuElement-ba5ea33d.js} +20 -1
- package/dist/Menu.d.ts +24 -2
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Menu.js +120 -3
- package/dist/MenuItem.d.ts +28 -11
- package/dist/MenuItem.d.ts.map +1 -1
- package/dist/MenuItem.js +110 -63
- package/dist/Pagination.d.ts +10 -3
- package/dist/Pagination.d.ts.map +1 -1
- package/dist/Pagination.js +24 -21
- package/dist/Popup.d.ts +21 -3
- package/dist/Popup.d.ts.map +1 -1
- package/dist/Popup.js +44 -17
- package/dist/Radio.d.ts +4 -2
- package/dist/Radio.d.ts.map +1 -1
- package/dist/Radio.js +9 -14
- package/dist/RadioGroup.d.ts +2 -2
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RadioGroup.js +20 -11
- package/dist/ScrollTop.d.ts +2 -2
- package/dist/ScrollTop.d.ts.map +1 -1
- package/dist/ScrollTop.js +10 -8
- package/dist/Select.d.ts +75 -37
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +279 -181
- package/dist/Table.d.ts +2 -6
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +16 -16
- package/dist/VisuallyHidden.d.ts +2 -2
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/VisuallyHidden.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -14
- package/dist/leu-accordion.d.ts.map +1 -1
- package/dist/leu-accordion.js +2 -3
- package/dist/leu-breadcrumb.d.ts.map +1 -1
- package/dist/leu-breadcrumb.js +4 -10
- package/dist/leu-button-group.d.ts.map +1 -1
- package/dist/leu-button-group.js +2 -3
- package/dist/leu-button.d.ts +1 -1
- package/dist/leu-button.d.ts.map +1 -1
- package/dist/leu-button.js +4 -5
- package/dist/leu-checkbox-group.d.ts.map +1 -1
- package/dist/leu-checkbox-group.js +2 -3
- package/dist/leu-checkbox.d.ts.map +1 -1
- package/dist/leu-checkbox.js +3 -4
- package/dist/leu-chip-group.d.ts.map +1 -1
- package/dist/leu-chip-group.js +2 -3
- package/dist/leu-chip-link.d.ts.map +1 -1
- package/dist/leu-chip-link.js +2 -3
- package/dist/leu-chip-removable.d.ts.map +1 -1
- package/dist/leu-chip-removable.js +3 -4
- package/dist/leu-chip-selectable.d.ts.map +1 -1
- package/dist/leu-chip-selectable.js +2 -3
- package/dist/leu-dropdown.d.ts.map +1 -1
- package/dist/leu-dropdown.js +5 -10
- package/dist/leu-icon.d.ts +3 -0
- package/dist/leu-icon.d.ts.map +1 -0
- package/dist/leu-icon.js +7 -0
- package/dist/leu-input.d.ts.map +1 -1
- package/dist/leu-input.js +3 -4
- package/dist/leu-menu-item.d.ts.map +1 -1
- package/dist/leu-menu-item.js +3 -5
- package/dist/leu-menu.d.ts.map +1 -1
- package/dist/leu-menu.js +5 -3
- package/dist/leu-pagination.d.ts.map +1 -1
- package/dist/leu-pagination.js +4 -7
- package/dist/leu-popup.d.ts.map +1 -1
- package/dist/leu-popup.js +2 -3
- package/dist/leu-radio-group.d.ts.map +1 -1
- package/dist/leu-radio-group.js +2 -3
- package/dist/leu-radio.d.ts.map +1 -1
- package/dist/leu-radio.js +2 -3
- package/dist/leu-scroll-top.d.ts.map +1 -1
- package/dist/leu-scroll-top.js +4 -6
- package/dist/leu-select.d.ts.map +1 -1
- package/dist/leu-select.js +5 -13
- package/dist/leu-table.d.ts.map +1 -1
- package/dist/leu-table.js +4 -8
- package/dist/leu-visually-hidden.d.ts.map +1 -1
- package/dist/leu-visually-hidden.js +2 -3
- package/dist/theme.css +2 -0
- package/dist/vscode.html-custom-data.json +124 -74
- package/dist/vue/index.d.ts +83 -67
- package/dist/web-types.json +256 -142
- package/package.json +9 -12
- package/scripts/generate-component/templates/[Name].js +6 -3
- package/scripts/generate-component/templates/test/[name].test.js +1 -1
- package/src/components/accordion/Accordion.js +13 -10
- package/src/components/accordion/leu-accordion.js +1 -2
- package/src/components/breadcrumb/Breadcrumb.js +31 -18
- package/src/components/breadcrumb/leu-breadcrumb.js +1 -2
- package/src/components/button/Button.js +45 -71
- package/src/components/button/button.css +11 -9
- package/src/components/button/leu-button.js +1 -2
- package/src/components/button/stories/button.stories.js +60 -19
- package/src/components/button/test/button.test.js +26 -63
- package/src/components/button-group/ButtonGroup.js +4 -2
- package/src/components/button-group/leu-button-group.js +1 -2
- package/src/components/checkbox/Checkbox.js +17 -11
- package/src/components/checkbox/CheckboxGroup.js +6 -3
- package/src/components/checkbox/leu-checkbox-group.js +1 -2
- package/src/components/checkbox/leu-checkbox.js +1 -2
- package/src/components/checkbox/stories/checkbox-group.stories.js +10 -26
- package/src/components/checkbox/stories/checkbox.stories.js +2 -7
- package/src/components/checkbox/test/checkbox-group.test.js +6 -21
- package/src/components/checkbox/test/checkbox.test.js +1 -12
- package/src/components/chip/Chip.js +5 -4
- package/src/components/chip/ChipGroup.js +38 -8
- package/src/components/chip/ChipLink.js +3 -7
- package/src/components/chip/ChipRemovable.js +8 -11
- package/src/components/chip/ChipSelectable.js +23 -27
- package/src/components/chip/chip.css +19 -20
- package/src/components/chip/leu-chip-group.js +1 -2
- package/src/components/chip/leu-chip-link.js +1 -2
- package/src/components/chip/leu-chip-removable.js +1 -2
- package/src/components/chip/leu-chip-selectable.js +1 -2
- package/src/components/chip/stories/chip-group.stories.js +6 -9
- package/src/components/chip/stories/chip-link.stories.js +3 -5
- package/src/components/chip/stories/chip-removable.stories.js +3 -4
- package/src/components/chip/stories/chip-selectable.stories.js +3 -3
- package/src/components/chip/test/chip-group.test.js +82 -30
- package/src/components/chip/test/chip-link.test.js +2 -6
- package/src/components/chip/test/chip-removable.test.js +4 -10
- package/src/components/chip/test/chip-selectable.test.js +10 -12
- package/src/components/dropdown/Dropdown.js +79 -26
- package/src/components/dropdown/leu-dropdown.js +1 -2
- package/src/components/dropdown/stories/dropdown.stories.js +30 -7
- package/src/components/dropdown/test/dropdown.test.js +5 -5
- package/src/components/icon/Icon.js +55 -0
- package/src/components/icon/icon.css +6 -0
- package/src/components/icon/leu-icon.js +5 -0
- package/src/components/icon/{icon.js → paths.js} +4 -37
- package/src/components/icon/stories/icon.stories.js +47 -0
- package/src/components/icon/test/icon.test.js +23 -40
- package/src/components/input/Input.js +31 -20
- package/src/components/input/input.css +4 -2
- package/src/components/input/leu-input.js +1 -2
- package/src/components/input/stories/input.stories.js +5 -5
- package/src/components/input/test/input.test.js +22 -0
- package/src/components/menu/Menu.js +143 -2
- package/src/components/menu/MenuItem.js +104 -52
- package/src/components/menu/leu-menu-item.js +1 -2
- package/src/components/menu/leu-menu.js +1 -2
- package/src/components/menu/menu-item.css +11 -4
- package/src/components/menu/stories/menu-item.stories.js +15 -4
- package/src/components/menu/stories/menu.stories.js +34 -7
- package/src/components/menu/test/menu-item.test.js +88 -82
- package/src/components/menu/test/menu.test.js +101 -8
- package/src/components/pagination/Pagination.js +27 -18
- package/src/components/pagination/leu-pagination.js +1 -2
- package/src/components/popup/Popup.js +39 -16
- package/src/components/popup/leu-popup.js +1 -2
- package/src/components/popup/popup.css +1 -0
- package/src/components/radio/Radio.js +12 -7
- package/src/components/radio/RadioGroup.js +18 -12
- package/src/components/radio/leu-radio-group.js +1 -2
- package/src/components/radio/leu-radio.js +1 -2
- package/src/components/radio/stories/radio-group.stories.js +5 -19
- package/src/components/radio/stories/radio.stories.js +2 -7
- package/src/components/radio/test/radio-group.test.js +6 -9
- package/src/components/radio/test/radio.test.js +3 -13
- package/src/components/scroll-top/ScrollTop.js +15 -5
- package/src/components/scroll-top/leu-scroll-top.js +1 -2
- package/src/components/select/Select.js +279 -175
- package/src/components/select/leu-select.js +1 -2
- package/src/components/select/select.css +20 -12
- package/src/components/select/stories/select.stories.js +16 -2
- package/src/components/select/test/select.test.js +191 -37
- package/src/components/table/Table.js +15 -9
- package/src/components/table/leu-table.js +1 -2
- package/src/components/table/table.css +3 -1
- package/src/components/visually-hidden/VisuallyHidden.js +6 -2
- package/src/components/visually-hidden/leu-visually-hidden.js +1 -2
- package/src/lib/LeuElement.js +23 -0
- package/src/lib/a11y.js +26 -0
- package/src/styles/custom-properties.css +2 -0
- package/web-test-runner.config.mjs +2 -0
- package/dist/Button-5326c982.d.ts.map +0 -1
- package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts +0 -3
- package/dist/_rollupPluginBabelHelpers-20f659f4.d.ts.map +0 -1
- package/dist/defineElement-40372b4b.d.ts +0 -9
- package/dist/defineElement-40372b4b.d.ts.map +0 -1
- package/dist/defineElement-40372b4b.js +0 -15
- package/dist/icon-03e86700.d.ts +0 -11
- package/dist/icon-03e86700.d.ts.map +0 -1
- package/src/lib/defineElement.js +0 -13
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { LitElement } from "lit"
|
|
2
1
|
import { html, unsafeStatic } from "lit/static-html.js"
|
|
2
|
+
|
|
3
|
+
import { LeuElement } from "../../lib/LeuElement.js"
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
3
6
|
import styles from "./chip-group.css"
|
|
4
7
|
|
|
5
8
|
/* Figma https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=131766-248643&mode=design&t=Kjo5VDiqivihn8dh-11 */
|
|
6
9
|
|
|
7
|
-
export const SELECTION_MODES = {
|
|
10
|
+
export const SELECTION_MODES = Object.freeze({
|
|
8
11
|
single: "single",
|
|
9
12
|
multiple: "multiple",
|
|
10
13
|
none: "none",
|
|
11
|
-
}
|
|
14
|
+
})
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* @slot - Place leu-chip-* elements inside this slot
|
|
15
18
|
* @cssproperty --leu-chip-group-gap - The gap between the chips
|
|
16
19
|
* @tagname leu-chip-group
|
|
17
20
|
*/
|
|
18
|
-
export class LeuChipGroup extends
|
|
21
|
+
export class LeuChipGroup extends LeuElement {
|
|
19
22
|
static styles = styles
|
|
20
23
|
|
|
21
24
|
static properties = {
|
|
@@ -34,22 +37,49 @@ export class LeuChipGroup extends LitElement {
|
|
|
34
37
|
|
|
35
38
|
/** @internal */
|
|
36
39
|
this.items = []
|
|
40
|
+
|
|
41
|
+
/** @type {"single" | "multiple" | "none"} */
|
|
42
|
+
this.selectionMode = SELECTION_MODES.none
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
connectedCallback() {
|
|
40
46
|
super.connectedCallback()
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
/**
|
|
49
|
+
* It is technically possible to add an event listener to the host element
|
|
50
|
+
* before it is connected to the dom. In that case the outside event listener would
|
|
51
|
+
* be called before the following event listener. But at this point multiple
|
|
52
|
+
* radio chips could be selected at the same time because `handleInput` hasn't been
|
|
53
|
+
* called yet. That's why we use the capture phase.
|
|
54
|
+
*/
|
|
55
|
+
this.addEventListener("input", this.handleInput, { capture: true })
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
disconnectedCallback() {
|
|
46
59
|
super.disconnectedCallback()
|
|
47
60
|
|
|
48
|
-
this.removeEventListener("input", this.handleInput)
|
|
61
|
+
this.removeEventListener("input", this.handleInput, { capture: true })
|
|
49
62
|
}
|
|
50
63
|
|
|
51
64
|
get value() {
|
|
52
|
-
return this.items.filter((i) => i.
|
|
65
|
+
return this.items.filter((i) => i.checked).map((i) => i.value)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Checks the items with the given values.
|
|
70
|
+
* If the selectionMode is single, only the first item with the given value is checked.
|
|
71
|
+
* @param {string[]} valueList
|
|
72
|
+
*/
|
|
73
|
+
set value(valueList) {
|
|
74
|
+
let hasChanged = false
|
|
75
|
+
|
|
76
|
+
for (const item of this.items) {
|
|
77
|
+
item.checked = hasChanged ? false : valueList.includes(item.value)
|
|
78
|
+
|
|
79
|
+
if (this.selectionMode === SELECTION_MODES.single && item.checked) {
|
|
80
|
+
hasChanged = true
|
|
81
|
+
}
|
|
82
|
+
}
|
|
53
83
|
}
|
|
54
84
|
|
|
55
85
|
/**
|
|
@@ -72,7 +102,7 @@ export class LeuChipGroup extends LitElement {
|
|
|
72
102
|
handleInput = (e) => {
|
|
73
103
|
if (this.selectionMode === SELECTION_MODES.single) {
|
|
74
104
|
this.items.forEach((item) => {
|
|
75
|
-
item.
|
|
105
|
+
item.checked = item === e.target // eslint-disable-line no-param-reassign
|
|
76
106
|
})
|
|
77
107
|
}
|
|
78
108
|
}
|
|
@@ -8,17 +8,13 @@ export const SIZES = {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @slot - The content of the chip
|
|
12
11
|
* @tagname leu-chip-link
|
|
12
|
+
* @slot - The content of the chip
|
|
13
|
+
* @prop {keyof typeof SIZES} size - The size of the chip
|
|
13
14
|
*/
|
|
14
15
|
export class LeuChipLink extends LeuChipBase {
|
|
15
16
|
static properties = {
|
|
16
17
|
...LeuChipBase.properties,
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* The size of the chip
|
|
20
|
-
* @type {keyof typeof SIZES}
|
|
21
|
-
*/
|
|
22
18
|
size: { type: String, reflect: true },
|
|
23
19
|
href: { type: String, reflect: true },
|
|
24
20
|
}
|
|
@@ -33,7 +29,7 @@ export class LeuChipLink extends LeuChipBase {
|
|
|
33
29
|
|
|
34
30
|
render() {
|
|
35
31
|
return html`<a href=${this.href} class="button">
|
|
36
|
-
<span class="label"
|
|
32
|
+
<span class="label"><slot></slot></span>
|
|
37
33
|
</a>`
|
|
38
34
|
}
|
|
39
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
2
|
|
|
3
3
|
import { LeuChipBase } from "./Chip.js"
|
|
4
|
-
import {
|
|
4
|
+
import { LeuIcon } from "../icon/Icon.js"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @slot - The content of the chip
|
|
@@ -9,20 +9,17 @@ import { Icon } from "../icon/icon.js"
|
|
|
9
9
|
* @fires remove - Dispatched when the user clicks on the chip
|
|
10
10
|
*/
|
|
11
11
|
export class LeuChipRemovable extends LeuChipBase {
|
|
12
|
-
static
|
|
13
|
-
|
|
12
|
+
static dependencies = {
|
|
13
|
+
"leu-icon": LeuIcon,
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
this._removeIcon = Icon("close", 16)
|
|
16
|
+
static properties = {
|
|
17
|
+
...LeuChipBase.properties,
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
handleClick() {
|
|
24
21
|
const customEvent = new CustomEvent("leu:remove", {
|
|
25
|
-
|
|
22
|
+
bubbles: true,
|
|
26
23
|
composed: true,
|
|
27
24
|
})
|
|
28
25
|
this.dispatchEvent(customEvent)
|
|
@@ -30,8 +27,8 @@ export class LeuChipRemovable extends LeuChipBase {
|
|
|
30
27
|
|
|
31
28
|
render() {
|
|
32
29
|
return html`<button @click=${(e) => this.handleClick(e)} class="button">
|
|
33
|
-
<span class="label"
|
|
34
|
-
<
|
|
30
|
+
<span class="label"><slot></slot></span>
|
|
31
|
+
<leu-icon name="close" class="icon"></leu-icon>
|
|
35
32
|
</button>`
|
|
36
33
|
}
|
|
37
34
|
}
|
|
@@ -14,39 +14,35 @@ export const VARIANTS = {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* A chip component that can be selected.
|
|
17
|
-
* @slot - The content of the chip
|
|
18
17
|
* @tagname leu-chip-selectable
|
|
18
|
+
* @slot - The content of the chip
|
|
19
|
+
* @prop {keyof typeof SIZES} size - The size of the chip. Not supported for radio variant.
|
|
20
|
+
* @prop {keyof typeof VARIANTS} variant - `toggle` or `radio`. Determines if only one or multiple chips can be selected.
|
|
21
|
+
* @prop {boolean} checked - Whether the chip is selected.
|
|
22
|
+
* @prop {string} value - The value of the chip.
|
|
19
23
|
*/
|
|
20
24
|
export class LeuChipSelectable extends LeuChipBase {
|
|
21
25
|
static properties = {
|
|
22
26
|
...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
27
|
size: { type: String, reflect: true },
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The variant of the chip. Has an effect not only on the visual appearance but also on the behavior.
|
|
33
|
-
* - `toggle`: The chip behaves like a toggle button.
|
|
34
|
-
* - `radio`: The chip behaves like a radio button.
|
|
35
|
-
*
|
|
36
|
-
* @type {keyof typeof VARIANTS}
|
|
37
|
-
* @default "toggle"
|
|
38
|
-
*/
|
|
39
28
|
variant: { type: String, reflect: true },
|
|
40
29
|
|
|
41
|
-
|
|
30
|
+
checked: { type: Boolean, reflect: true },
|
|
42
31
|
value: { type: String, reflect: true },
|
|
43
32
|
}
|
|
44
33
|
|
|
45
34
|
constructor() {
|
|
46
35
|
super()
|
|
47
36
|
this.size = SIZES.regular
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The variant of the chip. Has an effect not only on the visual appearance but also on the behavior.
|
|
40
|
+
* - `toggle`: The chip behaves like a toggle button.
|
|
41
|
+
* - `radio`: The chip behaves like a radio button.
|
|
42
|
+
* @default "toggle"
|
|
43
|
+
*/
|
|
48
44
|
this.variant = VARIANTS.toggle
|
|
49
|
-
this.
|
|
45
|
+
this.checked = false
|
|
50
46
|
|
|
51
47
|
if (this.variant === VARIANTS.radio && this.size === SIZES.small) {
|
|
52
48
|
console.warn("Small size has no effect on radio variant")
|
|
@@ -54,19 +50,19 @@ export class LeuChipSelectable extends LeuChipBase {
|
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
handleClick() {
|
|
57
|
-
let
|
|
53
|
+
let nextcheckedState = this.checked
|
|
58
54
|
|
|
59
55
|
if (this.variant === VARIANTS.radio) {
|
|
60
|
-
|
|
56
|
+
nextcheckedState = true
|
|
61
57
|
} else {
|
|
62
|
-
|
|
58
|
+
nextcheckedState = !this.checked
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
if (
|
|
66
|
-
this.
|
|
61
|
+
if (nextcheckedState !== this.checked) {
|
|
62
|
+
this.checked = nextcheckedState
|
|
67
63
|
this.dispatchEvent(
|
|
68
64
|
new CustomEvent("input", {
|
|
69
|
-
detail: {
|
|
65
|
+
detail: { checked: this.checked },
|
|
70
66
|
bubbles: true,
|
|
71
67
|
composed: true,
|
|
72
68
|
})
|
|
@@ -76,11 +72,11 @@ export class LeuChipSelectable extends LeuChipBase {
|
|
|
76
72
|
|
|
77
73
|
render() {
|
|
78
74
|
return html`<button
|
|
79
|
-
@click=${(
|
|
75
|
+
@click=${() => this.handleClick()}
|
|
80
76
|
class="button"
|
|
81
|
-
aria-pressed=${this.
|
|
77
|
+
aria-pressed=${this.checked ? "true" : "false"}
|
|
82
78
|
>
|
|
83
|
-
<span class="label"
|
|
79
|
+
<span class="label"><slot></slot></span>
|
|
84
80
|
</button>`
|
|
85
81
|
}
|
|
86
82
|
}
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
:host {
|
|
9
9
|
--chip-background-color-default: var(--leu-color-black-transp-10);
|
|
10
10
|
--chip-background-color-hover: var(--leu-color-black-transp-20);
|
|
11
|
-
--chip-background-color-
|
|
12
|
-
--chip-background-color-
|
|
11
|
+
--chip-background-color-checked: var(--leu-color-black-100);
|
|
12
|
+
--chip-background-color-checked-hover: var(--leu-color-black-transp-80);
|
|
13
13
|
|
|
14
14
|
--chip-color-default: var(--leu-color-black-transp-60);
|
|
15
15
|
--chip-color-hover: var(--leu-color-black-100);
|
|
16
|
-
--chip-color-
|
|
16
|
+
--chip-color-checked: var(--leu-color-black-0);
|
|
17
17
|
|
|
18
18
|
--chip-radio-border-default: var(--leu-color-black-transp-40);
|
|
19
|
-
--chip-radio-border-
|
|
19
|
+
--chip-radio-border-checked: var(--leu-color-black-0);
|
|
20
20
|
--chip-radio-background-default: var(--leu-color-black-0);
|
|
21
|
-
--chip-radio-background-
|
|
21
|
+
--chip-radio-background-checked: var(--leu-color-func-cyan);
|
|
22
22
|
|
|
23
23
|
--chip-font-regular: var(--leu-font-family-regular);
|
|
24
24
|
--chip-font-black: var(--leu-font-family-black);
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
--chip-radio-border: var(--chip-radio-border-default);
|
|
29
29
|
--chip-radio-background: var(--chip-radio-background-default);
|
|
30
30
|
|
|
31
|
+
--leu-icon-size: 1rem;
|
|
32
|
+
|
|
31
33
|
font-family: var(--chip-font-regular);
|
|
32
34
|
|
|
33
35
|
/* Allow shrinking to achieve text truncation (ellipsis) */
|
|
@@ -40,14 +42,14 @@
|
|
|
40
42
|
|
|
41
43
|
--chip-color-default: var(--leu-color-black-0);
|
|
42
44
|
--chip-color-hover: var(--leu-color-black-0);
|
|
43
|
-
--chip-color-
|
|
45
|
+
--chip-color-checked: var(--leu-color-black-0);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
:host([
|
|
47
|
-
--chip-background-color: var(--chip-background-color-
|
|
48
|
-
--chip-color: var(--chip-color-
|
|
49
|
-
--chip-radio-border: var(--chip-radio-border-
|
|
50
|
-
--chip-radio-background: var(--chip-radio-background-
|
|
48
|
+
:host([checked]) {
|
|
49
|
+
--chip-background-color: var(--chip-background-color-checked);
|
|
50
|
+
--chip-color: var(--chip-color-checked);
|
|
51
|
+
--chip-radio-border: var(--chip-radio-border-checked);
|
|
52
|
+
--chip-radio-background: var(--chip-radio-background-checked);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
.button {
|
|
@@ -58,6 +60,7 @@
|
|
|
58
60
|
padding: 0.5rem 1rem;
|
|
59
61
|
|
|
60
62
|
color: var(--chip-color);
|
|
63
|
+
font-family: inherit;
|
|
61
64
|
font-size: 0.875rem;
|
|
62
65
|
line-height: 1rem;
|
|
63
66
|
|
|
@@ -92,10 +95,10 @@
|
|
|
92
95
|
text-decoration: none;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
:host([
|
|
96
|
-
:host([
|
|
97
|
-
--chip-background-color: var(--chip-background-color-
|
|
98
|
-
--chip-color: var(--chip-color-
|
|
98
|
+
:host([checked]) .button:hover,
|
|
99
|
+
:host([checked]) .button:focus-visible {
|
|
100
|
+
--chip-background-color: var(--chip-background-color-checked-hover);
|
|
101
|
+
--chip-color: var(--chip-color-checked);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
:host([href][size="large"]) .button {
|
|
@@ -123,7 +126,7 @@
|
|
|
123
126
|
border-radius: 50%;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
:host([variant="radio"][
|
|
129
|
+
:host([variant="radio"][checked]) .button::before {
|
|
127
130
|
border-width: 3px;
|
|
128
131
|
}
|
|
129
132
|
|
|
@@ -135,7 +138,3 @@
|
|
|
135
138
|
text-overflow: ellipsis;
|
|
136
139
|
white-space: nowrap;
|
|
137
140
|
}
|
|
138
|
-
|
|
139
|
-
.icon svg {
|
|
140
|
-
display: block;
|
|
141
|
-
}
|
|
@@ -95,7 +95,8 @@ function DefaultTemplate(args) {
|
|
|
95
95
|
const content = html`
|
|
96
96
|
${chips.map(
|
|
97
97
|
(chip) => html`
|
|
98
|
-
<leu-chip-removable ?inverted=${args.inverted}
|
|
98
|
+
<leu-chip-removable ?inverted=${args.inverted}>
|
|
99
|
+
${chip}
|
|
99
100
|
</leu-chip-removable>
|
|
100
101
|
`
|
|
101
102
|
)}
|
|
@@ -112,8 +113,8 @@ function SingleTemplate(args) {
|
|
|
112
113
|
?inverted=${args.inverted}
|
|
113
114
|
variant=${SELECTABLE_VARIANTS.radio}
|
|
114
115
|
value="chip-${chip}"
|
|
115
|
-
label=${chip}
|
|
116
116
|
>
|
|
117
|
+
${chip}
|
|
117
118
|
</leu-chip-selectable>
|
|
118
119
|
`
|
|
119
120
|
)}
|
|
@@ -126,11 +127,8 @@ function MultipleTemplate(args) {
|
|
|
126
127
|
const content = html`
|
|
127
128
|
${chips.map(
|
|
128
129
|
(chip) => html`
|
|
129
|
-
<leu-chip-selectable
|
|
130
|
-
|
|
131
|
-
value="chip-${chip}"
|
|
132
|
-
label=${chip}
|
|
133
|
-
>
|
|
130
|
+
<leu-chip-selectable ?inverted=${args.inverted} value="chip-${chip}">
|
|
131
|
+
${chip}
|
|
134
132
|
</leu-chip-selectable>
|
|
135
133
|
`
|
|
136
134
|
)}
|
|
@@ -143,8 +141,7 @@ function LabeledTemplate(args) {
|
|
|
143
141
|
const content = html`
|
|
144
142
|
${links.map(
|
|
145
143
|
(chip) => html`
|
|
146
|
-
<leu-chip-link ?inverted=${args.inverted}
|
|
147
|
-
</leu-chip-link>
|
|
144
|
+
<leu-chip-link ?inverted=${args.inverted}> ${chip} </leu-chip-link>
|
|
148
145
|
`
|
|
149
146
|
)}
|
|
150
147
|
`
|
|
@@ -33,11 +33,9 @@ function Template(args) {
|
|
|
33
33
|
: "var(--leu-color-black-5)"}; padding: 1rem;"
|
|
34
34
|
data-root
|
|
35
35
|
>
|
|
36
|
-
<leu-chip-link
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
label=${args.label}
|
|
40
|
-
></leu-chip-link>
|
|
36
|
+
<leu-chip-link size=${ifDefined(args.size)} ?inverted=${args.inverted}
|
|
37
|
+
>${args.label}</leu-chip-link
|
|
38
|
+
>
|
|
41
39
|
</div>
|
|
42
40
|
`
|
|
43
41
|
}
|
|
@@ -27,10 +27,9 @@ function Template(args) {
|
|
|
27
27
|
: "var(--leu-color-black-5)"}; padding: 1rem;"
|
|
28
28
|
data-root
|
|
29
29
|
>
|
|
30
|
-
<leu-chip-removable
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
></leu-chip-removable>
|
|
30
|
+
<leu-chip-removable ?inverted=${args.inverted}
|
|
31
|
+
>${args.label}</leu-chip-removable
|
|
32
|
+
>
|
|
34
33
|
</div>
|
|
35
34
|
`
|
|
36
35
|
}
|
|
@@ -38,10 +38,10 @@ function Template(args) {
|
|
|
38
38
|
<leu-chip-selectable
|
|
39
39
|
size=${ifDefined(args.size)}
|
|
40
40
|
variant=${ifDefined(args.variant)}
|
|
41
|
-
|
|
42
|
-
?selected=${args.selected}
|
|
41
|
+
?checked=${args.checked}
|
|
43
42
|
?inverted=${args.inverted}
|
|
44
|
-
|
|
43
|
+
>${args.label}</leu-chip-selectable
|
|
44
|
+
>
|
|
45
45
|
</div>
|
|
46
46
|
`
|
|
47
47
|
}
|
|
@@ -9,12 +9,9 @@ async function removableFixture() {
|
|
|
9
9
|
return fixture(
|
|
10
10
|
html`
|
|
11
11
|
<leu-chip-group>
|
|
12
|
-
<leu-chip-removable
|
|
13
|
-
<leu-chip-removable
|
|
14
|
-
<leu-chip-removable
|
|
15
|
-
label="Schnittstellen"
|
|
16
|
-
value="3"
|
|
17
|
-
></leu-chip-removable>
|
|
12
|
+
<leu-chip-removable>Publikationen</leu-chip-removable>
|
|
13
|
+
<leu-chip-removable value="2">Daten</leu-chip-removable>
|
|
14
|
+
<leu-chip-removable value="3">Schnittstellen</leu-chip-removable>
|
|
18
15
|
</leu-chip-group>
|
|
19
16
|
`
|
|
20
17
|
)
|
|
@@ -24,21 +21,15 @@ async function singleSelectionFixture() {
|
|
|
24
21
|
return fixture(
|
|
25
22
|
html`
|
|
26
23
|
<leu-chip-group selection-mode="single">
|
|
27
|
-
<leu-chip-selectable
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
></leu-chip-selectable>
|
|
37
|
-
<leu-chip-selectable
|
|
38
|
-
label="Schnittstellen"
|
|
39
|
-
value="3"
|
|
40
|
-
variant="radio"
|
|
41
|
-
></leu-chip-selectable>
|
|
24
|
+
<leu-chip-selectable value="1" variant="radio"
|
|
25
|
+
>Publikationen</leu-chip-selectable
|
|
26
|
+
>
|
|
27
|
+
<leu-chip-selectable value="2" variant="radio"
|
|
28
|
+
>Daten</leu-chip-selectable
|
|
29
|
+
>
|
|
30
|
+
<leu-chip-selectable value="3" variant="radio"
|
|
31
|
+
>Schnittstellen</leu-chip-selectable
|
|
32
|
+
>
|
|
42
33
|
</leu-chip-group>
|
|
43
34
|
`
|
|
44
35
|
)
|
|
@@ -48,15 +39,9 @@ async function multipleSelectionFixture() {
|
|
|
48
39
|
return fixture(
|
|
49
40
|
html`
|
|
50
41
|
<leu-chip-group selection-mode="multiple">
|
|
51
|
-
<leu-chip-selectable
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
></leu-chip-selectable>
|
|
55
|
-
<leu-chip-selectable label="Daten" value="2"></leu-chip-selectable>
|
|
56
|
-
<leu-chip-selectable
|
|
57
|
-
label="Schnittstellen"
|
|
58
|
-
value="3"
|
|
59
|
-
></leu-chip-selectable>
|
|
42
|
+
<leu-chip-selectable value="1">Publikationen</leu-chip-selectable>
|
|
43
|
+
<leu-chip-selectable value="2">Daten</leu-chip-selectable>
|
|
44
|
+
<leu-chip-selectable value="3">Schnittstellen</leu-chip-selectable>
|
|
60
45
|
</leu-chip-group>
|
|
61
46
|
`
|
|
62
47
|
)
|
|
@@ -121,4 +106,71 @@ describe("LeuChipGroup", () => {
|
|
|
121
106
|
|
|
122
107
|
await expect(event).to.exist
|
|
123
108
|
})
|
|
109
|
+
|
|
110
|
+
it("checks only chip when the value of the group is set (selection-mode=single)", async () => {
|
|
111
|
+
const el = await singleSelectionFixture()
|
|
112
|
+
|
|
113
|
+
expect(el.items[0].checked).to.be.false
|
|
114
|
+
expect(el.items[1].checked).to.be.false
|
|
115
|
+
expect(el.items[2].checked).to.be.false
|
|
116
|
+
|
|
117
|
+
el.value = ["2"]
|
|
118
|
+
|
|
119
|
+
expect(el.items[0].checked).to.be.false
|
|
120
|
+
expect(el.items[1].checked).to.be.true
|
|
121
|
+
expect(el.items[2].checked).to.be.false
|
|
122
|
+
|
|
123
|
+
// Should check the first item with the given value and not first item of the value list
|
|
124
|
+
el.value = ["2", "1"]
|
|
125
|
+
|
|
126
|
+
expect(el.items[0].checked).to.be.true
|
|
127
|
+
expect(el.items[1].checked).to.be.false
|
|
128
|
+
|
|
129
|
+
el.value = []
|
|
130
|
+
|
|
131
|
+
expect(el.items[0].checked).to.be.false
|
|
132
|
+
expect(el.items[1].checked).to.be.false
|
|
133
|
+
expect(el.items[2].checked).to.be.false
|
|
134
|
+
|
|
135
|
+
el.value = ["asdf"]
|
|
136
|
+
|
|
137
|
+
expect(el.items[0].checked).to.be.false
|
|
138
|
+
expect(el.items[1].checked).to.be.false
|
|
139
|
+
expect(el.items[2].checked).to.be.false
|
|
140
|
+
expect(el.value).to.deep.equal([])
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it("checks chips when the value of the group is set (selection-mode=multiple)", async () => {
|
|
144
|
+
const el = await multipleSelectionFixture()
|
|
145
|
+
|
|
146
|
+
expect(el.items[0].checked).to.be.false
|
|
147
|
+
expect(el.items[1].checked).to.be.false
|
|
148
|
+
expect(el.items[2].checked).to.be.false
|
|
149
|
+
|
|
150
|
+
el.value = ["2"]
|
|
151
|
+
|
|
152
|
+
expect(el.items[0].checked).to.be.false
|
|
153
|
+
expect(el.items[1].checked).to.be.true
|
|
154
|
+
expect(el.items[2].checked).to.be.false
|
|
155
|
+
|
|
156
|
+
// Should check the first item with the given value and not first item of the value list
|
|
157
|
+
el.value = ["2", "1"]
|
|
158
|
+
|
|
159
|
+
expect(el.items[0].checked).to.be.true
|
|
160
|
+
expect(el.items[1].checked).to.be.true
|
|
161
|
+
expect(el.items[2].checked).to.be.false
|
|
162
|
+
|
|
163
|
+
el.value = []
|
|
164
|
+
|
|
165
|
+
expect(el.items[0].checked).to.be.false
|
|
166
|
+
expect(el.items[1].checked).to.be.false
|
|
167
|
+
expect(el.items[2].checked).to.be.false
|
|
168
|
+
|
|
169
|
+
el.value = ["asdf"]
|
|
170
|
+
|
|
171
|
+
expect(el.items[0].checked).to.be.false
|
|
172
|
+
expect(el.items[1].checked).to.be.false
|
|
173
|
+
expect(el.items[2].checked).to.be.false
|
|
174
|
+
expect(el.value).to.deep.equal([])
|
|
175
|
+
})
|
|
124
176
|
})
|
|
@@ -5,9 +5,7 @@ import "../leu-chip-link.js"
|
|
|
5
5
|
|
|
6
6
|
async function defaultFixture() {
|
|
7
7
|
return fixture(
|
|
8
|
-
html`
|
|
9
|
-
<leu-chip-link label="Daten" href="https://zh.ch/daten"></leu-chip-link>
|
|
10
|
-
`
|
|
8
|
+
html` <leu-chip-link href="https://zh.ch/daten">Daten</leu-chip-link> `
|
|
11
9
|
)
|
|
12
10
|
}
|
|
13
11
|
|
|
@@ -27,9 +25,7 @@ describe("LeuChipLink", () => {
|
|
|
27
25
|
it("renders the label", async () => {
|
|
28
26
|
const el = await defaultFixture()
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect(link).to.have.trimmed.text("Daten")
|
|
28
|
+
expect(el).to.have.trimmed.text("Daten")
|
|
33
29
|
})
|
|
34
30
|
|
|
35
31
|
it("renders a link element", async () => {
|
|
@@ -2,14 +2,10 @@ import { html } from "lit"
|
|
|
2
2
|
import { fixture, expect, oneEvent } from "@open-wc/testing"
|
|
3
3
|
import { sendKeys } from "@web/test-runner-commands"
|
|
4
4
|
|
|
5
|
-
import { iconPaths } from "../../icon/icon.js"
|
|
6
|
-
|
|
7
5
|
import "../leu-chip-removable.js"
|
|
8
6
|
|
|
9
7
|
async function defaultFixture() {
|
|
10
|
-
return fixture(
|
|
11
|
-
html` <leu-chip-removable label="Daten"></leu-chip-removable> `
|
|
12
|
-
)
|
|
8
|
+
return fixture(html` <leu-chip-removable>Daten</leu-chip-removable> `)
|
|
13
9
|
}
|
|
14
10
|
|
|
15
11
|
describe("LeuChipRemovable", () => {
|
|
@@ -28,9 +24,7 @@ describe("LeuChipRemovable", () => {
|
|
|
28
24
|
it("renders the label", async () => {
|
|
29
25
|
const el = await defaultFixture()
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(button).to.have.trimmed.text("Daten")
|
|
27
|
+
expect(el).to.have.trimmed.text("Daten")
|
|
34
28
|
})
|
|
35
29
|
|
|
36
30
|
it("renders a button element", async () => {
|
|
@@ -42,9 +36,9 @@ describe("LeuChipRemovable", () => {
|
|
|
42
36
|
it("renders a remove icon", async () => {
|
|
43
37
|
const el = await defaultFixture()
|
|
44
38
|
|
|
45
|
-
const iconPath = el.shadowRoot.querySelector("
|
|
39
|
+
const iconPath = el.shadowRoot.querySelector("leu-icon")
|
|
46
40
|
|
|
47
|
-
expect(iconPath.
|
|
41
|
+
expect(iconPath.name).to.equal("close")
|
|
48
42
|
})
|
|
49
43
|
|
|
50
44
|
it("delegates the focus to the button element", async () => {
|