@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.
Files changed (148) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/dist/Accordion.js +2 -30
  4. package/dist/Button.d.ts +56 -68
  5. package/dist/Button.js +74 -52
  6. package/dist/ButtonGroup.d.ts +9 -9
  7. package/dist/ButtonGroup.js +30 -20
  8. package/dist/ChartWrapper.d.ts +38 -0
  9. package/dist/ChartWrapper.js +164 -0
  10. package/dist/Checkbox.d.ts +6 -21
  11. package/dist/Checkbox.js +17 -9
  12. package/dist/CheckboxGroup.d.ts +13 -14
  13. package/dist/CheckboxGroup.js +18 -11
  14. package/dist/Chip.js +1 -1
  15. package/dist/ChipGroup.js +1 -1
  16. package/dist/ChipLink.js +1 -1
  17. package/dist/ChipRemovable.js +1 -1
  18. package/dist/ChipSelectable.js +1 -1
  19. package/dist/Dialog.js +1 -1
  20. package/dist/Dropdown.js +3 -1
  21. package/dist/Icon.js +1 -1
  22. package/dist/Input.js +1 -1
  23. package/dist/{LeuElement-x8UlIDDl.js → LeuElement-B84x5CPL.js} +1 -1
  24. package/dist/Menu.js +1 -1
  25. package/dist/MenuItem.js +1 -1
  26. package/dist/Pagination.d.ts +40 -28
  27. package/dist/Pagination.js +39 -14
  28. package/dist/Placeholder.d.ts +27 -0
  29. package/dist/Placeholder.js +90 -0
  30. package/dist/Popup.js +1 -1
  31. package/dist/Radio.d.ts +6 -21
  32. package/dist/Radio.js +17 -9
  33. package/dist/RadioGroup.d.ts +28 -23
  34. package/dist/RadioGroup.js +29 -16
  35. package/dist/Range.js +1 -1
  36. package/dist/ScrollTop.d.ts +0 -1
  37. package/dist/ScrollTop.js +3 -1
  38. package/dist/Select.js +3 -1
  39. package/dist/Spinner.js +1 -1
  40. package/dist/Table.d.ts +0 -1
  41. package/dist/Table.js +3 -1
  42. package/dist/VisuallyHidden.js +1 -1
  43. package/dist/_tslib-CNEFicEt.js +30 -0
  44. package/dist/components/button/Button.d.ts +55 -67
  45. package/dist/components/button/Button.d.ts.map +1 -1
  46. package/dist/components/button/stories/button.stories.d.ts.map +1 -1
  47. package/dist/components/button-group/ButtonGroup.d.ts +9 -9
  48. package/dist/components/button-group/ButtonGroup.d.ts.map +1 -1
  49. package/dist/components/chart-wrapper/ChartWrapper.d.ts +34 -0
  50. package/dist/components/chart-wrapper/ChartWrapper.d.ts.map +1 -0
  51. package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts +3 -0
  52. package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts.map +1 -0
  53. package/dist/components/chart-wrapper/stories/chart-wrapper.stories.d.ts +47 -0
  54. package/dist/components/chart-wrapper/stories/chart-wrapper.stories.d.ts.map +1 -0
  55. package/dist/components/chart-wrapper/test/chart-wrapper.test.d.ts +2 -0
  56. package/dist/components/chart-wrapper/test/chart-wrapper.test.d.ts.map +1 -0
  57. package/dist/components/checkbox/Checkbox.d.ts +6 -21
  58. package/dist/components/checkbox/Checkbox.d.ts.map +1 -1
  59. package/dist/components/checkbox/CheckboxGroup.d.ts +13 -14
  60. package/dist/components/checkbox/CheckboxGroup.d.ts.map +1 -1
  61. package/dist/components/icon/stories/icon.stories.d.ts +10 -0
  62. package/dist/components/icon/stories/icon.stories.d.ts.map +1 -1
  63. package/dist/components/pagination/Pagination.d.ts +40 -27
  64. package/dist/components/pagination/Pagination.d.ts.map +1 -1
  65. package/dist/components/pagination/stories/pagination.stories.d.ts +10 -2
  66. package/dist/components/pagination/stories/pagination.stories.d.ts.map +1 -1
  67. package/dist/components/placeholder/Placeholder.d.ts +23 -0
  68. package/dist/components/placeholder/Placeholder.d.ts.map +1 -0
  69. package/dist/components/placeholder/leu-placeholder.d.ts +3 -0
  70. package/dist/components/placeholder/leu-placeholder.d.ts.map +1 -0
  71. package/dist/components/placeholder/stories/placeholder.stories.d.ts +27 -0
  72. package/dist/components/placeholder/stories/placeholder.stories.d.ts.map +1 -0
  73. package/dist/components/placeholder/test/placeholder.test.d.ts +2 -0
  74. package/dist/components/placeholder/test/placeholder.test.d.ts.map +1 -0
  75. package/dist/components/radio/Radio.d.ts +6 -21
  76. package/dist/components/radio/Radio.d.ts.map +1 -1
  77. package/dist/components/radio/RadioGroup.d.ts +28 -23
  78. package/dist/components/radio/RadioGroup.d.ts.map +1 -1
  79. package/dist/index.d.ts +1 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +5 -2
  82. package/dist/leu-accordion.js +2 -1
  83. package/dist/leu-button-group.js +8 -1
  84. package/dist/leu-button.d.ts +0 -1
  85. package/dist/leu-button.js +3 -1
  86. package/dist/leu-chart-wrapper.d.ts +6 -0
  87. package/dist/leu-chart-wrapper.js +11 -0
  88. package/dist/leu-checkbox-group.js +5 -1
  89. package/dist/leu-checkbox.js +3 -1
  90. package/dist/leu-chip-group.js +1 -1
  91. package/dist/leu-chip-link.js +1 -1
  92. package/dist/leu-chip-removable.js +1 -1
  93. package/dist/leu-chip-selectable.js +1 -1
  94. package/dist/leu-dialog.js +1 -1
  95. package/dist/leu-dropdown.js +3 -1
  96. package/dist/leu-icon.js +1 -1
  97. package/dist/leu-input.js +1 -1
  98. package/dist/leu-menu-item.js +1 -1
  99. package/dist/leu-menu.js +1 -1
  100. package/dist/leu-pagination.d.ts +0 -1
  101. package/dist/leu-pagination.js +3 -1
  102. package/dist/leu-placeholder.d.ts +4 -0
  103. package/dist/leu-placeholder.js +7 -0
  104. package/dist/leu-popup.js +1 -1
  105. package/dist/leu-radio-group.js +4 -1
  106. package/dist/leu-radio.js +3 -1
  107. package/dist/leu-range.js +1 -1
  108. package/dist/leu-scroll-top.d.ts +0 -1
  109. package/dist/leu-scroll-top.js +3 -1
  110. package/dist/leu-select.js +3 -1
  111. package/dist/leu-spinner.js +1 -1
  112. package/dist/leu-table.d.ts +0 -1
  113. package/dist/leu-table.js +3 -1
  114. package/dist/leu-visually-hidden.js +1 -1
  115. package/dist/lib/a11y.d.ts +2 -2
  116. package/dist/theme.css +18 -18
  117. package/dist/vscode.html-custom-data.json +95 -25
  118. package/dist/vue/index.d.ts +86 -46
  119. package/dist/web-types.json +222 -80
  120. package/package.json +1 -1
  121. package/release-please-config.json +1 -2
  122. package/scripts/generate-component/templates/stories/[name].stories.ts +17 -4
  123. package/scripts/postcss-leu-font-styles.cjs +10 -10
  124. package/src/components/button/Button.ts +95 -79
  125. package/src/components/button/stories/button.stories.ts +5 -6
  126. package/src/components/button-group/ButtonGroup.ts +18 -13
  127. package/src/components/chart-wrapper/ChartWrapper.ts +78 -0
  128. package/src/components/chart-wrapper/chart-wrapper.css +87 -0
  129. package/src/components/chart-wrapper/leu-chart-wrapper.ts +5 -0
  130. package/src/components/chart-wrapper/stories/chart-wrapper.stories.ts +58 -0
  131. package/src/components/chart-wrapper/test/chart-wrapper.test.ts +77 -0
  132. package/src/components/checkbox/Checkbox.ts +13 -15
  133. package/src/components/checkbox/CheckboxGroup.ts +20 -16
  134. package/src/components/icon/stories/icon.stories.ts +27 -0
  135. package/src/components/pagination/Pagination.ts +45 -32
  136. package/src/components/pagination/stories/pagination.stories.ts +28 -17
  137. package/src/components/placeholder/Placeholder.ts +33 -0
  138. package/src/components/placeholder/leu-placeholder.ts +5 -0
  139. package/src/components/placeholder/placeholder.css +59 -0
  140. package/src/components/placeholder/stories/placeholder.stories.ts +34 -0
  141. package/src/components/placeholder/test/placeholder.test.ts +31 -0
  142. package/src/components/radio/Radio.ts +13 -15
  143. package/src/components/radio/RadioGroup.ts +42 -28
  144. package/src/docs/contributing.mdx +1 -1
  145. package/src/index.ts +1 -0
  146. package/src/lib/a11y.ts +2 -2
  147. package/src/styles/theme.css +89 -1
  148. 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
- static properties = {
63
- label: { type: String, reflect: true },
64
- size: { type: String, reflect: true },
65
- variant: { type: String, reflect: true },
66
- type: { type: String, reflect: true },
67
- componentRole: { type: String, reflect: true },
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
- constructor() {
78
- super()
79
- /** @type {string} */
80
- this.label = null
81
- /** @type {string} */
82
- this.size = "regular"
83
- /** @type {string} */
84
- this.variant = "primary"
85
- /** @type {"button" | "submit" | "reset"} */
86
- this.type = "button"
87
-
88
- /** @type {string} */
89
- this.componentRole = undefined
90
-
91
- /** @type {boolean} */
92
- this.disabled = false
93
- /** @type {boolean} - Only taken into account if no Label and an Icon is set */
94
- this.round = false
95
- /** @type {boolean} */
96
- this.active = false
97
- /** @type {boolean} - will be used on dark Background */
98
- this.inverted = false
99
-
100
- /** @type {boolean} - Alters the shape of the button to be full width of its parent container */
101
- this.fluid = false
102
-
103
- /**
104
- * Only taken into account if variant is "ghost"
105
- * @type {("true" | "false" | undefined)}
106
- */
107
- this.expanded = undefined
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 (ARIA_CHECKED_ROLES.includes(this.componentRole)) {
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 (ARIA_SELECTED_ROLES.includes(this.componentRole)) {
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
- import {
8
- BUTTON_VARIANTS,
9
- BUTTON_TYPES,
10
- BUTTON_SIZES,
11
- BUTTON_EXPANDED_OPTIONS,
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
- * @param {import("../button/Button.js").LeuButton} button
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.innerText.trim()
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.assignedElements({ flatten: true })
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", () => this._handleButtonClick(item))
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
- * @param {import("../button/Button.js").LeuButton} button
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,5 @@
1
+ import { LeuChartWrapper } from "./ChartWrapper.js"
2
+
3
+ export { LeuChartWrapper }
4
+
5
+ LeuChartWrapper.define("leu-chart-wrapper")
@@ -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
- static properties = {
25
- checked: { type: Boolean, reflect: true },
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
- constructor() {
32
- super()
33
- this.checked = false
34
- this.disabled = false
35
- this.name = ""
36
- this.value = ""
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