@statistikzh/leu 0.14.4 → 0.15.1
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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +17 -0
- package/dist/Accordion.js +2 -30
- package/dist/Button.d.ts +56 -68
- package/dist/Button.js +74 -52
- package/dist/ButtonGroup.d.ts +9 -9
- package/dist/ButtonGroup.js +30 -20
- package/dist/ChartWrapper.d.ts +38 -0
- package/dist/ChartWrapper.js +164 -0
- package/dist/Checkbox.d.ts +6 -21
- package/dist/Checkbox.js +17 -9
- package/dist/CheckboxGroup.d.ts +13 -14
- package/dist/CheckboxGroup.js +18 -11
- package/dist/Chip.js +1 -1
- package/dist/ChipGroup.js +1 -1
- package/dist/ChipLink.js +1 -1
- package/dist/ChipRemovable.js +1 -1
- package/dist/ChipSelectable.js +1 -1
- package/dist/Dialog.js +1 -1
- package/dist/Dropdown.js +3 -1
- package/dist/Icon.js +1 -1
- package/dist/Input.js +1 -1
- package/dist/{LeuElement-x8UlIDDl.js → LeuElement-B84x5CPL.js} +1 -1
- package/dist/Menu.js +1 -1
- package/dist/MenuItem.js +1 -1
- package/dist/Pagination.d.ts +40 -28
- package/dist/Pagination.js +39 -14
- package/dist/Placeholder.d.ts +27 -0
- package/dist/Placeholder.js +90 -0
- package/dist/Popup.js +1 -1
- package/dist/Radio.d.ts +6 -21
- package/dist/Radio.js +17 -9
- package/dist/RadioGroup.d.ts +28 -23
- package/dist/RadioGroup.js +29 -16
- package/dist/Range.js +1 -1
- package/dist/ScrollTop.d.ts +0 -1
- package/dist/ScrollTop.js +3 -1
- package/dist/Select.js +3 -1
- package/dist/Spinner.js +1 -1
- package/dist/Table.d.ts +0 -1
- package/dist/Table.js +3 -1
- package/dist/VisuallyHidden.js +1 -1
- package/dist/_tslib-CNEFicEt.js +30 -0
- package/dist/components/button/Button.d.ts +55 -67
- package/dist/components/button/Button.d.ts.map +1 -1
- package/dist/components/button/stories/button.stories.d.ts.map +1 -1
- package/dist/components/button-group/ButtonGroup.d.ts +9 -9
- package/dist/components/button-group/ButtonGroup.d.ts.map +1 -1
- package/dist/components/chart-wrapper/ChartWrapper.d.ts +34 -0
- package/dist/components/chart-wrapper/ChartWrapper.d.ts.map +1 -0
- package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts +3 -0
- package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts.map +1 -0
- package/dist/components/chart-wrapper/stories/chart-wrapper.stories.d.ts +47 -0
- package/dist/components/chart-wrapper/stories/chart-wrapper.stories.d.ts.map +1 -0
- package/dist/components/chart-wrapper/test/chart-wrapper.test.d.ts +2 -0
- package/dist/components/chart-wrapper/test/chart-wrapper.test.d.ts.map +1 -0
- package/dist/components/checkbox/Checkbox.d.ts +6 -21
- package/dist/components/checkbox/Checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/CheckboxGroup.d.ts +13 -14
- package/dist/components/checkbox/CheckboxGroup.d.ts.map +1 -1
- package/dist/components/icon/stories/icon.stories.d.ts +10 -0
- package/dist/components/icon/stories/icon.stories.d.ts.map +1 -1
- package/dist/components/pagination/Pagination.d.ts +40 -27
- package/dist/components/pagination/Pagination.d.ts.map +1 -1
- package/dist/components/pagination/stories/pagination.stories.d.ts +10 -2
- package/dist/components/pagination/stories/pagination.stories.d.ts.map +1 -1
- package/dist/components/placeholder/Placeholder.d.ts +23 -0
- package/dist/components/placeholder/Placeholder.d.ts.map +1 -0
- package/dist/components/placeholder/leu-placeholder.d.ts +3 -0
- package/dist/components/placeholder/leu-placeholder.d.ts.map +1 -0
- package/dist/components/placeholder/stories/placeholder.stories.d.ts +27 -0
- package/dist/components/placeholder/stories/placeholder.stories.d.ts.map +1 -0
- package/dist/components/placeholder/test/placeholder.test.d.ts +2 -0
- package/dist/components/placeholder/test/placeholder.test.d.ts.map +1 -0
- package/dist/components/radio/Radio.d.ts +6 -21
- package/dist/components/radio/Radio.d.ts.map +1 -1
- package/dist/components/radio/RadioGroup.d.ts +28 -23
- package/dist/components/radio/RadioGroup.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/leu-accordion.js +2 -1
- package/dist/leu-button-group.js +8 -1
- package/dist/leu-button.d.ts +0 -1
- package/dist/leu-button.js +3 -1
- package/dist/leu-chart-wrapper.d.ts +6 -0
- package/dist/leu-chart-wrapper.js +11 -0
- package/dist/leu-checkbox-group.js +5 -1
- package/dist/leu-checkbox.js +3 -1
- package/dist/leu-chip-group.js +1 -1
- package/dist/leu-chip-link.js +1 -1
- package/dist/leu-chip-removable.js +1 -1
- package/dist/leu-chip-selectable.js +1 -1
- package/dist/leu-dialog.js +1 -1
- package/dist/leu-dropdown.js +3 -1
- package/dist/leu-icon.js +1 -1
- package/dist/leu-input.js +1 -1
- package/dist/leu-menu-item.js +1 -1
- package/dist/leu-menu.js +1 -1
- package/dist/leu-pagination.d.ts +0 -1
- package/dist/leu-pagination.js +3 -1
- package/dist/leu-placeholder.d.ts +4 -0
- package/dist/leu-placeholder.js +7 -0
- package/dist/leu-popup.js +1 -1
- package/dist/leu-radio-group.js +4 -1
- package/dist/leu-radio.js +3 -1
- package/dist/leu-range.js +1 -1
- package/dist/leu-scroll-top.d.ts +0 -1
- package/dist/leu-scroll-top.js +3 -1
- package/dist/leu-select.js +3 -1
- package/dist/leu-spinner.js +1 -1
- package/dist/leu-table.d.ts +0 -1
- package/dist/leu-table.js +3 -1
- package/dist/leu-visually-hidden.js +1 -1
- package/dist/lib/a11y.d.ts +2 -2
- package/dist/theme.css +18 -18
- package/dist/vscode.html-custom-data.json +95 -25
- package/dist/vue/index.d.ts +86 -46
- package/dist/web-types.json +222 -80
- package/package.json +1 -1
- package/release-please-config.json +1 -2
- package/scripts/generate-component/templates/stories/[name].stories.ts +17 -4
- package/scripts/postcss-leu-font-styles.cjs +10 -10
- package/src/components/button/Button.ts +95 -79
- package/src/components/button/stories/button.stories.ts +5 -6
- package/src/components/button-group/ButtonGroup.ts +18 -13
- package/src/components/chart-wrapper/ChartWrapper.ts +78 -0
- package/src/components/chart-wrapper/chart-wrapper.css +87 -0
- package/src/components/chart-wrapper/leu-chart-wrapper.ts +5 -0
- package/src/components/chart-wrapper/stories/chart-wrapper.stories.ts +58 -0
- package/src/components/chart-wrapper/test/chart-wrapper.test.ts +77 -0
- package/src/components/checkbox/Checkbox.ts +13 -15
- package/src/components/checkbox/CheckboxGroup.ts +20 -16
- package/src/components/icon/stories/icon.stories.ts +27 -0
- package/src/components/pagination/Pagination.ts +45 -32
- package/src/components/pagination/stories/pagination.stories.ts +28 -17
- package/src/components/placeholder/Placeholder.ts +33 -0
- package/src/components/placeholder/leu-placeholder.ts +5 -0
- package/src/components/placeholder/placeholder.css +59 -0
- package/src/components/placeholder/stories/placeholder.stories.ts +34 -0
- package/src/components/placeholder/test/placeholder.test.ts +31 -0
- package/src/components/radio/Radio.ts +13 -15
- package/src/components/radio/RadioGroup.ts +42 -28
- package/src/docs/contributing.mdx +1 -1
- package/src/index.ts +1 -0
- package/src/lib/a11y.ts +2 -2
- package/src/styles/theme.css +89 -1
- package/src/styles/custom-properties.css +0 -89
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { html, nothing } from "lit"
|
|
2
2
|
import { classMap } from "lit/directives/class-map.js"
|
|
3
3
|
import { ifDefined } from "lit/directives/if-defined.js"
|
|
4
|
+
import { property } from "lit/decorators.js"
|
|
4
5
|
|
|
5
6
|
import { LeuIcon } from "../icon/Icon.js"
|
|
6
7
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
@@ -9,31 +10,12 @@ import { ARIA_CHECKED_ROLES, ARIA_SELECTED_ROLES } from "../../lib/a11y.js"
|
|
|
9
10
|
|
|
10
11
|
import styles from "./button.css"
|
|
11
12
|
|
|
12
|
-
/*
|
|
13
|
-
Design: https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=4-1444&mode=design&t=xu5Vii8jXKKCKDez-0
|
|
14
|
-
Live Demo: zh.ch
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const BUTTON_VARIANTS = ["primary", "secondary", "ghost"]
|
|
18
|
-
Object.freeze(BUTTON_VARIANTS)
|
|
19
|
-
export { BUTTON_VARIANTS }
|
|
20
|
-
|
|
21
|
-
const BUTTON_SIZES = ["regular", "small"]
|
|
22
|
-
Object.freeze(BUTTON_SIZES)
|
|
23
|
-
export { BUTTON_SIZES }
|
|
24
|
-
|
|
25
|
-
const BUTTON_TYPES = ["button", "submit", "reset"]
|
|
26
|
-
Object.freeze(BUTTON_TYPES)
|
|
27
|
-
export { BUTTON_TYPES }
|
|
28
|
-
|
|
29
|
-
export const BUTTON_EXPANDED_OPTIONS = ["true", "false"]
|
|
30
|
-
Object.freeze(BUTTON_EXPANDED_OPTIONS)
|
|
31
|
-
|
|
32
13
|
/**
|
|
33
14
|
* @tagname leu-button
|
|
34
15
|
* @slot before - The icon to display before the label
|
|
35
16
|
* @slot after - The icon to display after the label
|
|
36
17
|
* @slot - The label of the button or the icon if no label is set
|
|
18
|
+
* @see https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=4-1444&mode=design&t=xu5Vii8jXKKCKDez-0
|
|
37
19
|
*/
|
|
38
20
|
export class LeuButton extends LeuElement {
|
|
39
21
|
static dependencies = {
|
|
@@ -42,72 +24,92 @@ export class LeuButton extends LeuElement {
|
|
|
42
24
|
|
|
43
25
|
static styles = [LeuElement.styles, styles]
|
|
44
26
|
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
27
|
static shadowRootOptions = {
|
|
49
28
|
...LeuElement.shadowRootOptions,
|
|
50
29
|
delegatesFocus: true,
|
|
51
30
|
}
|
|
52
31
|
|
|
53
|
-
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
hasSlotController = new HasSlotController(this, [
|
|
32
|
+
private hasSlotController = new HasSlotController(this, [
|
|
57
33
|
"before",
|
|
58
34
|
"after",
|
|
59
35
|
"[default]",
|
|
60
36
|
])
|
|
61
37
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
disabled: { type: Boolean, reflect: true },
|
|
70
|
-
round: { type: Boolean, reflect: true },
|
|
71
|
-
active: { type: Boolean, reflect: true },
|
|
72
|
-
inverted: { type: Boolean, reflect: true },
|
|
73
|
-
expanded: { type: String, reflect: true },
|
|
74
|
-
fluid: { type: Boolean, reflect: true },
|
|
75
|
-
}
|
|
38
|
+
/**
|
|
39
|
+
* `aria-label` of the underlying button elements.
|
|
40
|
+
* Use it to provide a label when only an icon is visible.
|
|
41
|
+
*/
|
|
42
|
+
@property({ type: String, reflect: true })
|
|
43
|
+
label: null | string = null
|
|
76
44
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The size of the button.
|
|
47
|
+
*/
|
|
48
|
+
@property({ type: String, reflect: true })
|
|
49
|
+
size: "regular" | "small" = "regular"
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The visual variant of the button.
|
|
53
|
+
*/
|
|
54
|
+
@property({ type: String, reflect: true })
|
|
55
|
+
variant: "primary" | "secondary" | "ghost" = "primary"
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The `type` of the underlying button element.
|
|
59
|
+
*/
|
|
60
|
+
@property({ type: String, reflect: true })
|
|
61
|
+
type: "button" | "submit" | "reset" = "button"
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The `role` of the underlying button element.
|
|
65
|
+
*/
|
|
66
|
+
@property({ type: String, reflect: true })
|
|
67
|
+
componentRole?: string
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether the button is disabled or not.
|
|
71
|
+
* @type {boolean}
|
|
72
|
+
*/
|
|
73
|
+
@property({ type: Boolean, reflect: true })
|
|
74
|
+
disabled: boolean = false
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether the button should be round.
|
|
78
|
+
* Can only be applied when the button contains an icon without a visible label.
|
|
79
|
+
* @type {boolean}
|
|
80
|
+
*/
|
|
81
|
+
@property({ type: Boolean, reflect: true })
|
|
82
|
+
round: boolean = false
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Whether the button is active or not.
|
|
86
|
+
* Depending on the `componentRole`, it applies `aria-checked` or `aria-selected` to the underlying button element.
|
|
87
|
+
*/
|
|
88
|
+
@property({ type: Boolean, reflect: true })
|
|
89
|
+
active: boolean = false
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Wheter the colors should be inverted. For use on dark backgrounds.
|
|
93
|
+
*/
|
|
94
|
+
@property({ type: Boolean, reflect: true })
|
|
95
|
+
inverted: boolean = false
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether the button is expanded or not.
|
|
99
|
+
* Only has an effect on the variant `ghost` to show an expanding icon.
|
|
100
|
+
* If the property is not set, the icon will not be shown.
|
|
101
|
+
* If it is set, the icon will either show an expanded or collapsed state.
|
|
102
|
+
*/
|
|
103
|
+
@property({ type: String, reflect: true })
|
|
104
|
+
expanded?: "true" | "false"
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Alters the shape of the button to be full width of its parent container
|
|
108
|
+
*/
|
|
109
|
+
@property({ type: Boolean, reflect: true })
|
|
110
|
+
fluid: boolean = false
|
|
109
111
|
|
|
110
|
-
renderExpandingIcon() {
|
|
112
|
+
private renderExpandingIcon() {
|
|
111
113
|
if (typeof this.expanded !== "undefined" && this.variant === "ghost") {
|
|
112
114
|
return html`<div class="icon-expanded">
|
|
113
115
|
<leu-icon name="angleDropDown" size="24"></leu-icon>
|
|
@@ -117,16 +119,30 @@ export class LeuButton extends LeuElement {
|
|
|
117
119
|
return nothing
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
getAriaAttributes() {
|
|
121
|
-
const attributes
|
|
122
|
+
private getAriaAttributes() {
|
|
123
|
+
const attributes: {
|
|
124
|
+
role: string
|
|
125
|
+
label: string
|
|
126
|
+
checked?: "true" | "false"
|
|
127
|
+
selected?: "true" | "false"
|
|
128
|
+
} = {
|
|
122
129
|
role: this.componentRole,
|
|
123
130
|
label: this.label,
|
|
124
131
|
}
|
|
125
132
|
|
|
133
|
+
// TODO: checked and selected roles are not mutually exclusive
|
|
126
134
|
if (this.componentRole) {
|
|
127
|
-
if (
|
|
135
|
+
if (
|
|
136
|
+
(ARIA_CHECKED_ROLES as ReadonlyArray<string>).includes(
|
|
137
|
+
this.componentRole,
|
|
138
|
+
)
|
|
139
|
+
) {
|
|
128
140
|
attributes.checked = this.active ? "true" : "false"
|
|
129
|
-
} else if (
|
|
141
|
+
} else if (
|
|
142
|
+
(ARIA_SELECTED_ROLES as ReadonlyArray<string>).includes(
|
|
143
|
+
this.componentRole,
|
|
144
|
+
)
|
|
145
|
+
) {
|
|
130
146
|
attributes.selected = this.active ? "true" : "false"
|
|
131
147
|
}
|
|
132
148
|
}
|
|
@@ -134,7 +150,7 @@ export class LeuButton extends LeuElement {
|
|
|
134
150
|
return attributes
|
|
135
151
|
}
|
|
136
152
|
|
|
137
|
-
hasTextContent() {
|
|
153
|
+
private hasTextContent() {
|
|
138
154
|
return Array.from(this.childNodes).some(
|
|
139
155
|
(node) =>
|
|
140
156
|
node.nodeType === node.TEXT_NODE && node.textContent.trim() !== "",
|
|
@@ -4,12 +4,11 @@ import { classMap } from "lit/directives/class-map.js"
|
|
|
4
4
|
import "../leu-button.js"
|
|
5
5
|
import "../../icon/leu-icon.js"
|
|
6
6
|
import { paths as iconPaths } from "../../icon/paths.js"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "../Button.js"
|
|
7
|
+
|
|
8
|
+
const BUTTON_VARIANTS = ["primary", "secondary", "ghost"] as const
|
|
9
|
+
const BUTTON_SIZES = ["regular", "small"] as const
|
|
10
|
+
const BUTTON_TYPES = ["button", "submit", "reset"] as const
|
|
11
|
+
const BUTTON_EXPANDED_OPTIONS = ["true", "false"] as const
|
|
13
12
|
|
|
14
13
|
function copyContent(e) {
|
|
15
14
|
navigator.clipboard.writeText(e.target.outerHTML.replace(/<!--.*?-->/g, ""))
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
+
|
|
2
3
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
4
|
+
import { LeuButton } from "../button/Button.js"
|
|
3
5
|
|
|
4
6
|
import styles from "./button-group.css"
|
|
5
|
-
import { LeuButton } from "../button/Button.js"
|
|
6
7
|
|
|
7
8
|
/**
|
|
9
|
+
* A radio input-like button group component.
|
|
10
|
+
* It allows only one button to be active at a time.
|
|
8
11
|
* @tagname leu-button-group
|
|
9
12
|
* @slot - Slot for the buttons
|
|
10
|
-
* @prop {string} value - The value of the currenty selected (active) button
|
|
11
13
|
* @fires input - When the value of the group changes by clicking a button
|
|
12
14
|
*/
|
|
13
15
|
export class LeuButtonGroup extends LeuElement {
|
|
@@ -16,13 +18,15 @@ export class LeuButtonGroup extends LeuElement {
|
|
|
16
18
|
private _items: LeuButton[] = []
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @returns {string}
|
|
21
|
+
* Retrieves the value or the text content of a given LeuButton element.
|
|
21
22
|
*/
|
|
22
|
-
static getButtonValue(button) {
|
|
23
|
-
return button.getAttribute("value") ?? button.
|
|
23
|
+
private static getButtonValue(button: LeuButton) {
|
|
24
|
+
return button.getAttribute("value") ?? button.textContent.trim()
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The value of the currently selected (active) button
|
|
29
|
+
*/
|
|
26
30
|
get value() {
|
|
27
31
|
const activeButton = this._items.find((item) => item.active)
|
|
28
32
|
return activeButton ? LeuButtonGroup.getButtonValue(activeButton) : null
|
|
@@ -36,7 +40,7 @@ export class LeuButtonGroup extends LeuElement {
|
|
|
36
40
|
})
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
_handleSlotChange() {
|
|
43
|
+
private _handleSlotChange() {
|
|
40
44
|
/**
|
|
41
45
|
* Remove all event listeners that were added before.
|
|
42
46
|
* Just because a slotchange event was fired, it doesn't mean that all of the
|
|
@@ -47,13 +51,15 @@ export class LeuButtonGroup extends LeuElement {
|
|
|
47
51
|
})
|
|
48
52
|
|
|
49
53
|
const slot = this.shadowRoot.querySelector("slot")
|
|
50
|
-
this._items = slot
|
|
54
|
+
this._items = slot
|
|
55
|
+
.assignedElements({ flatten: true })
|
|
56
|
+
.filter((el) => el instanceof LeuButton)
|
|
51
57
|
|
|
52
58
|
let foundActiveButtonBefore = false
|
|
53
59
|
|
|
54
60
|
this._items.forEach((item) => {
|
|
55
61
|
/* eslint-disable no-param-reassign */
|
|
56
|
-
item.addEventListener("click",
|
|
62
|
+
item.addEventListener("click", this._handleButtonClick)
|
|
57
63
|
item.componentRole = "menuitemradio"
|
|
58
64
|
|
|
59
65
|
/**
|
|
@@ -70,10 +76,9 @@ export class LeuButtonGroup extends LeuElement {
|
|
|
70
76
|
})
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
_handleButtonClick(button) {
|
|
79
|
+
private _handleButtonClick = (event: MouseEvent) => {
|
|
80
|
+
const button = event.currentTarget as LeuButton
|
|
81
|
+
|
|
77
82
|
if (!button.active) {
|
|
78
83
|
this.value = LeuButtonGroup.getButtonValue(button)
|
|
79
84
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { html, nothing } from "lit"
|
|
2
|
+
import { property } from "lit/decorators.js"
|
|
3
|
+
|
|
4
|
+
import { LeuElement } from "../../lib/LeuElement.js"
|
|
5
|
+
|
|
6
|
+
import styles from "./chart-wrapper.css"
|
|
7
|
+
import { HasSlotController } from "../../lib/hasSlotController.js"
|
|
8
|
+
import { LeuSpinner } from "../spinner/Spinner.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A wrapper element for charts.
|
|
12
|
+
* @tagname leu-chart-wrapper
|
|
13
|
+
* @slot title - The title of the chart. Use a heading tag (h2-4) depending on your context.
|
|
14
|
+
* @slot description - A description of the chart. Content is wrapped in a `<p>` tag by the component.
|
|
15
|
+
* @slot chart - The actual chart
|
|
16
|
+
* @slot caption - A caption for the chart, e.g. a source or explanation of the data.
|
|
17
|
+
* @slot download - A download button or dropdown to export the chart in different formats.
|
|
18
|
+
*/
|
|
19
|
+
export class LeuChartWrapper extends LeuElement {
|
|
20
|
+
static styles = [LeuElement.styles, styles]
|
|
21
|
+
|
|
22
|
+
static shadowRootOptions = {
|
|
23
|
+
...LeuElement.shadowRootOptions,
|
|
24
|
+
delegatesFocus: true,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static dependencies = {
|
|
28
|
+
"leu-spinner": LeuSpinner,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether the chart is currently loading or not.
|
|
33
|
+
* When set to `true`, a spinner will be shown in the chart container.
|
|
34
|
+
*/
|
|
35
|
+
@property({ type: Boolean, reflect: true })
|
|
36
|
+
pending: boolean = false
|
|
37
|
+
|
|
38
|
+
hasSlotController = new HasSlotController(this, [
|
|
39
|
+
"description",
|
|
40
|
+
"caption",
|
|
41
|
+
"download",
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
render() {
|
|
45
|
+
const hasDescription = this.hasSlotController.test("description")
|
|
46
|
+
const hasCaption = this.hasSlotController.test("caption")
|
|
47
|
+
const hasDownload = this.hasSlotController.test("download")
|
|
48
|
+
|
|
49
|
+
return html`
|
|
50
|
+
<figure class="chart-wrapper">
|
|
51
|
+
<slot name="title" class="chart-wrapper__title"></slot>
|
|
52
|
+
${hasDescription
|
|
53
|
+
? html`<slot
|
|
54
|
+
name="description"
|
|
55
|
+
class="chart-wrapper__description"
|
|
56
|
+
></slot>`
|
|
57
|
+
: nothing}
|
|
58
|
+
<div class="chart-wrapper__container">
|
|
59
|
+
<slot name="chart" class="chart-wrapper__chart"></slot>
|
|
60
|
+
${this.pending
|
|
61
|
+
? html`<div class="chart-wrapper__spinner-container">
|
|
62
|
+
<leu-spinner class="chart-wrapper__spinner"></leu-spinner>
|
|
63
|
+
</div>`
|
|
64
|
+
: nothing}
|
|
65
|
+
</div>
|
|
66
|
+
${hasCaption
|
|
67
|
+
? html`<figcaption>
|
|
68
|
+
<slot name="caption" class="chart-wrapper__caption"></slot>
|
|
69
|
+
</figcaption>`
|
|
70
|
+
: nothing}
|
|
71
|
+
<hr class="chart-wrapper__ruler" />
|
|
72
|
+
${hasDownload
|
|
73
|
+
? html`<slot name="download" class="chart-wrapper__download"></slot>`
|
|
74
|
+
: nothing}
|
|
75
|
+
</figure>
|
|
76
|
+
`
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
@import url("../../styles/custom-media.css");
|
|
2
|
+
|
|
3
|
+
.chart-wrapper {
|
|
4
|
+
display: block;
|
|
5
|
+
width: 100%;
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.chart-wrapper__title::slotted(h2) {
|
|
10
|
+
color: var(--leu-color-black-100);
|
|
11
|
+
font: var(--leu-t-curve-large-black-font);
|
|
12
|
+
margin: 0 0 0.75rem;
|
|
13
|
+
|
|
14
|
+
@media (--viewport-medium) {
|
|
15
|
+
margin: 0 0 1.25rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@media (--viewport-xlarge) {
|
|
19
|
+
margin: 0 0 1.5rem;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.chart-wrapper__title::slotted(h3) {
|
|
24
|
+
color: var(--leu-color-black-100);
|
|
25
|
+
font: var(--leu-t-curve-medium-black-font);
|
|
26
|
+
margin: 0 0 0.5rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.chart-wrapper__title::slotted(h4) {
|
|
30
|
+
color: var(--leu-color-black-100);
|
|
31
|
+
font: var(--leu-t-curve-regular-black-font);
|
|
32
|
+
margin: 0 0 0.5rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.chart-wrapper__description,
|
|
36
|
+
.chart-wrapper__chart {
|
|
37
|
+
display: block;
|
|
38
|
+
margin-bottom: 0.75rem;
|
|
39
|
+
|
|
40
|
+
@media (--viewport-medium) {
|
|
41
|
+
margin-bottom: 1.25rem;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@media (--viewport-xlarge) {
|
|
45
|
+
margin-bottom: 1.5rem;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.chart-wrapper__description {
|
|
50
|
+
font: var(--leu-t-curve-small-regular-font);
|
|
51
|
+
color: var(--leu-color-black-60);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.chart-wrapper__caption {
|
|
55
|
+
font: var(--leu-t-curve-tiny-regular-font);
|
|
56
|
+
color: var(--leu-color-black-60);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.chart-wrapper__ruler {
|
|
60
|
+
display: block;
|
|
61
|
+
border: none;
|
|
62
|
+
border-top: 1px solid var(--leu-color-black-transp-20);
|
|
63
|
+
margin: 0.75rem 0;
|
|
64
|
+
|
|
65
|
+
@media (--viewport-xlarge) {
|
|
66
|
+
margin-block: 1rem;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.chart-wrapper__download {
|
|
71
|
+
display: block;
|
|
72
|
+
margin-left: -0.5rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.chart-wrapper__container {
|
|
76
|
+
position: relative;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.chart-wrapper__spinner-container {
|
|
80
|
+
position: absolute;
|
|
81
|
+
top: 0;
|
|
82
|
+
left: 0;
|
|
83
|
+
width: 100%;
|
|
84
|
+
height: 100%;
|
|
85
|
+
display: grid;
|
|
86
|
+
place-content: center;
|
|
87
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/web-components"
|
|
2
|
+
import { html } from "lit"
|
|
3
|
+
|
|
4
|
+
import "../../dropdown/leu-dropdown.js"
|
|
5
|
+
import "../leu-chart-wrapper.js"
|
|
6
|
+
import { LeuChartWrapper } from "../ChartWrapper.js"
|
|
7
|
+
|
|
8
|
+
type StoryArgs = LeuChartWrapper
|
|
9
|
+
type Story = StoryObj<StoryArgs>
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: "Components/ChartWrapper",
|
|
13
|
+
component: "leu-chart-wrapper",
|
|
14
|
+
} satisfies Meta<StoryArgs>
|
|
15
|
+
|
|
16
|
+
const Template: Story = {
|
|
17
|
+
render: ({ pending }) =>
|
|
18
|
+
html`<leu-chart-wrapper ?pending=${pending}>
|
|
19
|
+
<h2 slot="title">Entwicklung der Leerwohnungsziffer seit 1984</h2>
|
|
20
|
+
<span slot="description">Leerwohnungsziffer, in Prozent</span>
|
|
21
|
+
<img
|
|
22
|
+
style="display: block; width: 100%; height: auto;"
|
|
23
|
+
slot="chart"
|
|
24
|
+
src="https://placehold.co/1200x400"
|
|
25
|
+
alt="A placeholder to indicate where a chart would appear"
|
|
26
|
+
/>
|
|
27
|
+
<span slot="caption">Quelle: Statistisches Amt des Kantons Zürich</span>
|
|
28
|
+
<leu-dropdown slot="download" label="Download">
|
|
29
|
+
<leu-icon name="download" slot="icon"></leu-icon>
|
|
30
|
+
<leu-menu>
|
|
31
|
+
<leu-menu-item
|
|
32
|
+
href="https://www.web.statistik.zh.ch/ogd/daten/ressourcen/KTZH_00001120_00002165.csv"
|
|
33
|
+
>OGD Ressource</leu-menu-item
|
|
34
|
+
>
|
|
35
|
+
<leu-menu-item>Als CSV Tabelle</leu-menu-item>
|
|
36
|
+
<leu-menu-item>Als XLS Tabelle</leu-menu-item>
|
|
37
|
+
<hr />
|
|
38
|
+
<leu-menu-item>Als PNG exportieren</leu-menu-item>
|
|
39
|
+
<leu-menu-item>Als SVG exportieren</leu-menu-item>
|
|
40
|
+
<leu-menu-item disabled>Als PDF exportieren</leu-menu-item>
|
|
41
|
+
</leu-menu>
|
|
42
|
+
</leu-dropdown>
|
|
43
|
+
</leu-chart-wrapper>`,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const Regular = {
|
|
47
|
+
...Template,
|
|
48
|
+
args: {
|
|
49
|
+
pending: false,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const Pending = {
|
|
54
|
+
...Template,
|
|
55
|
+
args: {
|
|
56
|
+
pending: true,
|
|
57
|
+
},
|
|
58
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { html } from "lit"
|
|
2
|
+
import { fixture, expect } from "@open-wc/testing"
|
|
3
|
+
|
|
4
|
+
import "../leu-chart-wrapper.js"
|
|
5
|
+
|
|
6
|
+
async function defaultFixture({ pending = false } = {}) {
|
|
7
|
+
return fixture(
|
|
8
|
+
html`<leu-chart-wrapper ?pending=${pending}>
|
|
9
|
+
<h2 slot="title">Entwicklung der Leerwohnungsziffer seit 1984</h2>
|
|
10
|
+
<span slot="description">Leerwohnungsziffer, in Prozent</span>
|
|
11
|
+
<img
|
|
12
|
+
style="display: block; width: 100%; height: auto;"
|
|
13
|
+
slot="chart"
|
|
14
|
+
src="https://placehold.co/1200x400"
|
|
15
|
+
alt="A placeholder to indicate where a chart would appear"
|
|
16
|
+
/>
|
|
17
|
+
<span slot="caption">Quelle: Statistisches Amt des Kantons Zürich</span>
|
|
18
|
+
<leu-dropdown slot="download" label="Download">
|
|
19
|
+
<leu-icon name="download" slot="icon"></leu-icon>
|
|
20
|
+
<leu-menu>
|
|
21
|
+
<leu-menu-item
|
|
22
|
+
href="https://www.web.statistik.zh.ch/ogd/daten/ressourcen/KTZH_00001120_00002165.csv"
|
|
23
|
+
>OGD Ressource</leu-menu-item
|
|
24
|
+
>
|
|
25
|
+
<leu-menu-item>Als CSV Tabelle</leu-menu-item>
|
|
26
|
+
<leu-menu-item>Als XLS Tabelle</leu-menu-item>
|
|
27
|
+
<hr />
|
|
28
|
+
<leu-menu-item>Als PNG exportieren</leu-menu-item>
|
|
29
|
+
<leu-menu-item>Als SVG exportieren</leu-menu-item>
|
|
30
|
+
<leu-menu-item disabled>Als PDF exportieren</leu-menu-item>
|
|
31
|
+
</leu-menu>
|
|
32
|
+
</leu-dropdown>
|
|
33
|
+
</leu-chart-wrapper>`,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe("LeuChartWrapper", () => {
|
|
38
|
+
it("is a defined element", async () => {
|
|
39
|
+
const el = await customElements.get("leu-chart-wrapper")
|
|
40
|
+
|
|
41
|
+
await expect(el).not.to.be.undefined
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("passes the a11y audit", async () => {
|
|
45
|
+
const el = await defaultFixture()
|
|
46
|
+
|
|
47
|
+
await expect(el).shadowDom.to.be.accessible()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it("conditionally renders slots", async () => {
|
|
51
|
+
let el = await defaultFixture()
|
|
52
|
+
|
|
53
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__description")).to.exist
|
|
54
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__caption")).to.exist
|
|
55
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__download")).to.exist
|
|
56
|
+
|
|
57
|
+
el = await fixture(html`<leu-chart-wrapper></leu-chart-wrapper>`)
|
|
58
|
+
|
|
59
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__description")).not.to
|
|
60
|
+
.exist
|
|
61
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__caption")).not.to.exist
|
|
62
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__download")).not.to.exist
|
|
63
|
+
|
|
64
|
+
// Check that the title and chart slots are always present
|
|
65
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__title")).to.exist
|
|
66
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__chart")).to.exist
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it("shows a spinner when pending is set", async () => {
|
|
70
|
+
const el = await defaultFixture({ pending: true })
|
|
71
|
+
|
|
72
|
+
expect(el.shadowRoot.querySelector(".chart-wrapper__spinner-container")).to
|
|
73
|
+
.exist
|
|
74
|
+
expect(el.shadowRoot.querySelector("leu-spinner.chart-wrapper__spinner")).to
|
|
75
|
+
.exist
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
+
import { property } from "lit/decorators.js"
|
|
2
3
|
|
|
3
4
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
4
5
|
import { LeuIcon } from "../icon/Icon.js"
|
|
@@ -21,29 +22,26 @@ export class LeuCheckbox extends LeuElement {
|
|
|
21
22
|
delegatesFocus: true,
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
disabled: { type: Boolean, reflect: true },
|
|
27
|
-
value: { type: String, reflect: true },
|
|
28
|
-
name: { type: String, reflect: true },
|
|
29
|
-
}
|
|
25
|
+
@property({ type: Boolean, reflect: true })
|
|
26
|
+
checked: boolean = false
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
28
|
+
@property({ type: Boolean, reflect: true })
|
|
29
|
+
disabled: boolean = false
|
|
30
|
+
|
|
31
|
+
@property({ type: String, reflect: true })
|
|
32
|
+
value: string = ""
|
|
33
|
+
|
|
34
|
+
@property({ type: String, reflect: true })
|
|
35
|
+
name: string = ""
|
|
38
36
|
|
|
39
|
-
handleChange(event) {
|
|
37
|
+
private handleChange(event: Event & { target: HTMLInputElement }) {
|
|
40
38
|
this.checked = event.target.checked
|
|
41
39
|
|
|
42
40
|
const customEvent = new CustomEvent(event.type, event)
|
|
43
41
|
this.dispatchEvent(customEvent)
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
handleInput(event) {
|
|
44
|
+
private handleInput(event: InputEvent & { target: HTMLInputElement }) {
|
|
47
45
|
this.checked = event.target.checked
|
|
48
46
|
}
|
|
49
47
|
|