@statistikzh/leu 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/deploy-github-pages.yaml +33 -0
- package/.storybook/main.js +27 -1
- package/.storybook/manager-head.html +1 -0
- package/.storybook/manager.js +9 -0
- package/.storybook/preview-head.html +1 -1
- package/.storybook/preview.js +59 -5
- package/.storybook/static/logo.svg +19 -0
- package/.storybook/theme.js +7 -0
- package/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/dist/Button.js +15 -18
- package/dist/ButtonGroup.js +5 -7
- package/dist/Checkbox.js +101 -84
- package/dist/CheckboxGroup.js +41 -37
- package/dist/{Chip-5f70d04f.js → Chip-dac7337d.js} +5 -1
- package/dist/ChipGroup.js +2 -5
- package/dist/ChipLink.js +4 -7
- package/dist/ChipRemovable.js +4 -7
- package/dist/ChipSelectable.js +4 -7
- package/dist/Dropdown.js +55 -26
- package/dist/Input.js +29 -28
- package/dist/Menu.js +2 -5
- package/dist/MenuItem.js +30 -15
- package/dist/Pagination.js +54 -54
- package/dist/Radio.js +7 -6
- package/dist/RadioGroup.js +41 -39
- package/dist/Select.js +55 -43
- package/dist/Table.js +137 -120
- package/dist/{defineElement-ba770aed.js → _rollupPluginBabelHelpers-20f659f4.js} +1 -15
- package/dist/defineElement-47d4f665.js +15 -0
- package/dist/index.js +29 -19
- package/dist/leu-button-group.js +7 -3
- package/dist/leu-button.js +6 -3
- package/dist/leu-checkbox-group.js +6 -3
- package/dist/leu-checkbox.js +6 -3
- package/dist/leu-chip-group.js +6 -3
- package/dist/leu-chip-link.js +7 -4
- package/dist/leu-chip-removable.js +7 -4
- package/dist/leu-chip-selectable.js +7 -4
- package/dist/leu-dropdown.js +13 -3
- package/dist/leu-input.js +7 -3
- package/dist/leu-menu-item.js +8 -3
- package/dist/leu-menu.js +6 -3
- package/dist/leu-pagination.js +8 -3
- package/dist/leu-popup-4bf6f1f4.js +216 -0
- package/dist/leu-radio-group.js +6 -3
- package/dist/leu-radio.js +6 -3
- package/dist/leu-select.js +14 -3
- package/dist/leu-table.js +9 -3
- package/package.json +24 -12
- package/scripts/generate-component/templates/[Name].js +0 -5
- package/scripts/generate-component/templates/[name].css +1 -1
- package/scripts/generate-component/templates/[namespace]-[name].js +5 -2
- package/src/components/accordion/Accordion.js +0 -6
- package/src/components/accordion/leu-accordion.js +5 -2
- package/src/components/accordion/stories/accordion.stories.js +7 -4
- package/src/components/accordion/test/accordion.test.js +92 -2
- package/src/components/breadcrumb/Breadcrumb.js +310 -0
- package/src/components/breadcrumb/breadcrumb.css +114 -0
- package/src/components/breadcrumb/leu-breadcrumb.js +6 -0
- package/src/components/breadcrumb/stories/breadcrumb.stories.js +73 -0
- package/src/components/breadcrumb/test/breadcrumb.test.js +141 -0
- package/src/components/button/Button.js +10 -15
- package/src/components/button/button.css +3 -3
- package/src/components/button/leu-button.js +5 -2
- package/src/components/button/stories/button.stories.js +58 -37
- package/src/components/button/test/button.test.js +112 -2
- package/src/components/button-group/ButtonGroup.js +1 -7
- package/src/components/button-group/leu-button-group.js +5 -2
- package/src/components/button-group/stories/button-group.stories.js +6 -0
- package/src/components/button-group/test/button-group.test.js +79 -3
- package/src/components/checkbox/Checkbox.js +6 -85
- package/src/components/checkbox/CheckboxGroup.js +8 -38
- package/src/components/checkbox/checkbox-group.css +29 -0
- package/src/components/checkbox/checkbox.css +76 -0
- package/src/components/checkbox/leu-checkbox-group.js +5 -2
- package/src/components/checkbox/leu-checkbox.js +5 -2
- package/src/components/checkbox/stories/checkbox-group.stories.js +44 -21
- package/src/components/checkbox/stories/checkbox.stories.js +7 -1
- package/src/components/checkbox/test/checkbox-group.test.js +124 -0
- package/src/components/checkbox/test/checkbox.test.js +72 -59
- package/src/components/chip/Chip.js +1 -0
- package/src/components/chip/ChipGroup.js +0 -5
- package/src/components/chip/ChipLink.js +1 -6
- package/src/components/chip/ChipRemovable.js +1 -6
- package/src/components/chip/ChipSelectable.js +1 -6
- package/src/components/chip/exports.js +4 -10
- package/src/components/chip/leu-chip-group.js +5 -2
- package/src/components/chip/leu-chip-link.js +5 -2
- package/src/components/chip/leu-chip-removable.js +5 -2
- package/src/components/chip/leu-chip-selectable.js +5 -2
- package/src/components/chip/stories/chip-group.stories.js +18 -6
- package/src/components/chip/stories/chip-link.stories.js +16 -4
- package/src/components/chip/stories/chip-removable.stories.js +15 -4
- package/src/components/chip/stories/chip-selectable.stories.js +13 -3
- package/src/components/chip/test/chip-group.test.js +124 -0
- package/src/components/chip/test/chip-link.test.js +58 -0
- package/src/components/chip/test/chip-removable.test.js +79 -0
- package/src/components/chip/test/chip-selectable.test.js +95 -0
- package/src/components/chip/test/chip.test.js +1 -1
- package/src/components/dropdown/Dropdown.js +52 -24
- package/src/components/dropdown/dropdown.css +1 -2
- package/src/components/dropdown/leu-dropdown.js +5 -2
- package/src/components/dropdown/stories/dropdown.stories.js +11 -5
- package/src/components/dropdown/test/dropdown.test.js +6 -6
- package/src/components/icon/icon.js +1 -1
- package/src/components/icon/test/icon.test.js +66 -0
- package/src/components/input/Input.js +18 -24
- package/src/components/input/input.css +9 -6
- package/src/components/input/leu-input.js +5 -2
- package/src/components/input/stories/input.stories.js +8 -2
- package/src/components/input/test/input.test.js +431 -4
- package/src/components/menu/Menu.js +0 -5
- package/src/components/menu/MenuItem.js +20 -13
- package/src/components/menu/leu-menu-item.js +5 -2
- package/src/components/menu/leu-menu.js +5 -2
- package/src/components/menu/menu-item.css +5 -2
- package/src/components/menu/stories/menu-item.stories.js +13 -4
- package/src/components/menu/stories/menu.stories.js +11 -5
- package/src/components/menu/test/menu-item.test.js +180 -0
- package/src/components/menu/test/menu.test.js +10 -2
- package/src/components/pagination/Pagination.js +53 -65
- package/src/components/pagination/leu-pagination.js +5 -2
- package/src/components/pagination/stories/pagination.stories.js +17 -9
- package/src/components/pagination/test/pagination.test.js +191 -5
- package/src/components/popup/Popup.js +200 -0
- package/src/components/popup/leu-popup.js +6 -0
- package/src/components/popup/popup.css +27 -0
- package/src/components/popup/stories/popup.stories.js +58 -0
- package/src/components/popup/test/popup.test.js +29 -0
- package/src/components/radio/Radio.js +2 -6
- package/src/components/radio/RadioGroup.js +6 -38
- package/src/components/radio/leu-radio-group.js +5 -2
- package/src/components/radio/leu-radio.js +5 -2
- package/src/components/radio/radio-group.css +29 -0
- package/src/components/radio/stories/radio-group.stories.js +38 -19
- package/src/components/radio/stories/radio.stories.js +7 -1
- package/src/components/radio/test/radio-group.test.js +86 -0
- package/src/components/radio/test/radio.test.js +108 -17
- package/src/components/select/Select.js +34 -31
- package/src/components/select/leu-select.js +5 -2
- package/src/components/select/select.css +13 -13
- package/src/components/select/stories/select.stories.js +15 -168
- package/src/components/select/test/fixtures.js +162 -0
- package/src/components/select/test/select.test.js +236 -12
- package/src/components/table/Table.js +43 -118
- package/src/components/table/leu-table.js +5 -2
- package/src/components/table/stories/table.stories.js +20 -10
- package/src/components/table/table.css +99 -0
- package/src/components/table/test/table.test.js +1 -1
- package/src/lib/utils.js +17 -0
- package/{web-dev-server-storybook.config.mjs → web-dev-server.config.mjs} +1 -2
- package/web-test-runner.config.mjs +15 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { html, nothing, LitElement } from "lit"
|
|
2
2
|
import { classMap } from "lit/directives/class-map.js"
|
|
3
3
|
import { Icon } from "../icon/icon.js"
|
|
4
|
-
import { defineElement } from "../../lib/defineElement.js"
|
|
5
4
|
|
|
6
5
|
import styles from "./button.css"
|
|
7
6
|
|
|
@@ -14,7 +13,7 @@ const BUTTON_VARIANTS = ["primary", "secondary", "ghost"]
|
|
|
14
13
|
Object.freeze(BUTTON_VARIANTS)
|
|
15
14
|
export { BUTTON_VARIANTS }
|
|
16
15
|
|
|
17
|
-
const BUTTON_SIZES = ["
|
|
16
|
+
const BUTTON_SIZES = ["regular", "small"]
|
|
18
17
|
Object.freeze(BUTTON_SIZES)
|
|
19
18
|
export { BUTTON_SIZES }
|
|
20
19
|
|
|
@@ -42,7 +41,7 @@ export class LeuButton extends LitElement {
|
|
|
42
41
|
static properties = {
|
|
43
42
|
label: { type: String, reflect: true },
|
|
44
43
|
icon: { type: String, reflect: true },
|
|
45
|
-
|
|
44
|
+
iconPosition: { type: String, reflect: true },
|
|
46
45
|
size: { type: String, reflect: true },
|
|
47
46
|
variant: { type: String, reflect: true },
|
|
48
47
|
type: { type: String, reflect: true },
|
|
@@ -61,10 +60,10 @@ export class LeuButton extends LitElement {
|
|
|
61
60
|
this.label = null
|
|
62
61
|
/** @type {string} */
|
|
63
62
|
this.icon = null
|
|
64
|
-
/** @type {
|
|
65
|
-
this.
|
|
63
|
+
/** @type {("before" | "after")} - Only taken into account if Label and no Icon is set */
|
|
64
|
+
this.iconPosition = "before"
|
|
66
65
|
/** @type {string} */
|
|
67
|
-
this.size = "
|
|
66
|
+
this.size = "regular"
|
|
68
67
|
/** @type {string} */
|
|
69
68
|
this.variant = "primary"
|
|
70
69
|
/** @type {string} */
|
|
@@ -94,7 +93,7 @@ export class LeuButton extends LitElement {
|
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
renderIconBefore() {
|
|
97
|
-
if (this.icon) {
|
|
96
|
+
if (this.icon && this.iconPosition === "before") {
|
|
98
97
|
return html`<div class="icon-wrapper icon-wrapper--before">
|
|
99
98
|
${Icon(this.icon, this.getIconSize())}
|
|
100
99
|
</div>`
|
|
@@ -104,9 +103,9 @@ export class LeuButton extends LitElement {
|
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
renderIconAfter() {
|
|
107
|
-
if (this.
|
|
106
|
+
if (this.icon && this.label && this.iconPosition === "after") {
|
|
108
107
|
return html`<div class="icon-wrapper icon-wrapper--after">
|
|
109
|
-
${Icon(this.
|
|
108
|
+
${Icon(this.icon, this.getIconSize())}
|
|
110
109
|
</div>`
|
|
111
110
|
}
|
|
112
111
|
|
|
@@ -125,8 +124,8 @@ export class LeuButton extends LitElement {
|
|
|
125
124
|
|
|
126
125
|
render() {
|
|
127
126
|
const cssClasses = {
|
|
128
|
-
icon: !this.label && this.icon
|
|
129
|
-
round: !this.label && this.icon &&
|
|
127
|
+
icon: !this.label && this.icon,
|
|
128
|
+
round: !this.label && this.icon && this.round,
|
|
130
129
|
active: this.active,
|
|
131
130
|
inverted: this.inverted,
|
|
132
131
|
[this.variant]: true,
|
|
@@ -144,7 +143,3 @@ export class LeuButton extends LitElement {
|
|
|
144
143
|
`
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
|
-
|
|
148
|
-
export function defineButtonElements() {
|
|
149
|
-
defineElement("button", LeuButton)
|
|
150
|
-
}
|
|
@@ -38,14 +38,14 @@ button.inverted:focus-visible {
|
|
|
38
38
|
justify-content: center;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/* size -
|
|
42
|
-
button.
|
|
41
|
+
/* size - regular */
|
|
42
|
+
button.regular {
|
|
43
43
|
padding: 12px 24px;
|
|
44
44
|
font-size: 16px;
|
|
45
45
|
line-height: 24px;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
button.
|
|
48
|
+
button.regular.icon {
|
|
49
49
|
padding: 12px;
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -20,6 +20,15 @@ function copyContent(params) {
|
|
|
20
20
|
export default {
|
|
21
21
|
title: "Button",
|
|
22
22
|
component: "leu-button",
|
|
23
|
+
parameters: {
|
|
24
|
+
design: {
|
|
25
|
+
type: "figma",
|
|
26
|
+
url: "https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=4-1444&mode=design&t=xu5Vii8jXKKCKDez-0",
|
|
27
|
+
},
|
|
28
|
+
html: {
|
|
29
|
+
root: "[data-root]",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
function Template({
|
|
@@ -31,7 +40,7 @@ function Template({
|
|
|
31
40
|
variant,
|
|
32
41
|
disabled,
|
|
33
42
|
icon,
|
|
34
|
-
|
|
43
|
+
iconPosition,
|
|
35
44
|
type,
|
|
36
45
|
expanded,
|
|
37
46
|
}) {
|
|
@@ -40,7 +49,7 @@ function Template({
|
|
|
40
49
|
size: size === "small" ? ' size="small"' : undefined,
|
|
41
50
|
variant: variant !== "primary" ? ` variant="${variant}"` : undefined,
|
|
42
51
|
icon: icon ? ` icon="${icon}"` : undefined,
|
|
43
|
-
|
|
52
|
+
iconPosition: iconPosition ? ` icon="${iconPosition}"` : undefined,
|
|
44
53
|
round: round ? " round" : undefined,
|
|
45
54
|
active: active ? " active" : undefined,
|
|
46
55
|
disabled: disabled ? " disabled" : undefined,
|
|
@@ -48,21 +57,23 @@ function Template({
|
|
|
48
57
|
expanded: expanded ? ` expanded="${expanded}"` : undefined,
|
|
49
58
|
}
|
|
50
59
|
const component = html`
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
<div data-root>
|
|
61
|
+
<leu-button
|
|
62
|
+
label=${ifDefined(label)}
|
|
63
|
+
size=${ifDefined(size)}
|
|
64
|
+
variant=${ifDefined(variant)}
|
|
65
|
+
icon=${ifDefined(icon)}
|
|
66
|
+
iconPosition=${ifDefined(iconPosition)}
|
|
67
|
+
type=${ifDefined(type)}
|
|
68
|
+
expanded=${ifDefined(expanded)}
|
|
69
|
+
?round=${round}
|
|
70
|
+
?active=${active}
|
|
71
|
+
?inverted=${inverted}
|
|
72
|
+
?disabled=${disabled}
|
|
73
|
+
@click=${() => copyContent(params)}
|
|
74
|
+
>
|
|
75
|
+
</leu-button>
|
|
76
|
+
</div>
|
|
66
77
|
<br />
|
|
67
78
|
<p>Click the button to copy the code to the clipboard</p>
|
|
68
79
|
`
|
|
@@ -75,7 +86,7 @@ function Template({
|
|
|
75
86
|
</style>
|
|
76
87
|
<div
|
|
77
88
|
style="${inverted
|
|
78
|
-
? "background:var(--leu-color-accent-blue);"
|
|
89
|
+
? "background:var(--leu-color-accent-blue); color: var(--leu-color-white-transp-90);"
|
|
79
90
|
: ""}padding:40px;"
|
|
80
91
|
>
|
|
81
92
|
${component}
|
|
@@ -87,7 +98,7 @@ export const Regular = Template.bind({})
|
|
|
87
98
|
Regular.argTypes = {
|
|
88
99
|
label: { type: "string" },
|
|
89
100
|
icon: { control: "select", options: ICON_NAMES },
|
|
90
|
-
|
|
101
|
+
iconPosition: { control: "select", options: ["before", "after"] },
|
|
91
102
|
type: { control: "radio", options: BUTTON_TYPES },
|
|
92
103
|
size: { control: "radio", options: BUTTON_SIZES },
|
|
93
104
|
variant: { control: "radio", options: BUTTON_VARIANTS },
|
|
@@ -101,7 +112,7 @@ Regular.args = {
|
|
|
101
112
|
inverted: false,
|
|
102
113
|
|
|
103
114
|
icon: null,
|
|
104
|
-
|
|
115
|
+
iconPosition: null,
|
|
105
116
|
size: null,
|
|
106
117
|
variant: null,
|
|
107
118
|
type: null,
|
|
@@ -116,9 +127,14 @@ const items = [
|
|
|
116
127
|
{ label: "Active", icon: "calendar", active: true },
|
|
117
128
|
{ label: "Disabled", icon: "calendar", disabled: true },
|
|
118
129
|
|
|
119
|
-
{ label: "Normal",
|
|
120
|
-
{ label: "Active",
|
|
121
|
-
{
|
|
130
|
+
{ label: "Normal", icon: "calendar", iconPosition: "after" },
|
|
131
|
+
{ label: "Active", icon: "calendar", iconPosition: "after", active: true },
|
|
132
|
+
{
|
|
133
|
+
label: "Disabled",
|
|
134
|
+
icon: "calendar",
|
|
135
|
+
iconPosition: "after",
|
|
136
|
+
disabled: true,
|
|
137
|
+
},
|
|
122
138
|
|
|
123
139
|
{ icon: "calendar" },
|
|
124
140
|
{ icon: "calendar", active: true },
|
|
@@ -138,14 +154,19 @@ const ghostItems = [
|
|
|
138
154
|
{ label: "Active", icon: "calendar", active: true, expanded: "closed" },
|
|
139
155
|
{ label: "Disabled", icon: "calendar", disabled: true, expanded: "closed" },
|
|
140
156
|
|
|
141
|
-
{ label: "Normal",
|
|
142
|
-
{ label: "Active",
|
|
143
|
-
{
|
|
157
|
+
{ label: "Normal", icon: "calendar", iconPosition: "after" },
|
|
158
|
+
{ label: "Active", icon: "calendar", iconPosition: "after", active: true },
|
|
159
|
+
{
|
|
160
|
+
label: "Disabled",
|
|
161
|
+
icon: "calendar",
|
|
162
|
+
iconPosition: "after",
|
|
163
|
+
disabled: true,
|
|
164
|
+
},
|
|
144
165
|
]
|
|
145
166
|
|
|
146
167
|
const sizes = [
|
|
147
168
|
{
|
|
148
|
-
size: "
|
|
169
|
+
size: "regular",
|
|
149
170
|
items,
|
|
150
171
|
},
|
|
151
172
|
{
|
|
@@ -168,7 +189,7 @@ const groups = [
|
|
|
168
189
|
{
|
|
169
190
|
inverted: false,
|
|
170
191
|
variant: "ghost",
|
|
171
|
-
sizes: [{ size: "
|
|
192
|
+
sizes: [{ size: "regular", items: ghostItems }],
|
|
172
193
|
},
|
|
173
194
|
{
|
|
174
195
|
inverted: true,
|
|
@@ -183,11 +204,11 @@ const groups = [
|
|
|
183
204
|
{
|
|
184
205
|
inverted: true,
|
|
185
206
|
variant: "ghost",
|
|
186
|
-
sizes: [{ size: "
|
|
207
|
+
sizes: [{ size: "regular", items: ghostItems }],
|
|
187
208
|
},
|
|
188
209
|
]
|
|
189
210
|
|
|
190
|
-
function
|
|
211
|
+
function TemplateOverview() {
|
|
191
212
|
return html` <style>
|
|
192
213
|
.codeblock {
|
|
193
214
|
position: relative;
|
|
@@ -267,7 +288,7 @@ function TemplateDev() {
|
|
|
267
288
|
(size) =>
|
|
268
289
|
html`
|
|
269
290
|
<div>
|
|
270
|
-
<div class=${classMap({ table: true })}>
|
|
291
|
+
<div class=${classMap({ table: true })} data-root>
|
|
271
292
|
${size.items.map((item) => {
|
|
272
293
|
const params = {
|
|
273
294
|
label: item.label
|
|
@@ -280,8 +301,8 @@ function TemplateDev() {
|
|
|
280
301
|
? ` variant="${group.variant}"`
|
|
281
302
|
: undefined,
|
|
282
303
|
icon: item.icon ? ` icon="${item.icon}"` : undefined,
|
|
283
|
-
|
|
284
|
-
? `
|
|
304
|
+
iconPosition: item.iconPosition
|
|
305
|
+
? ` iconPosition="${item.iconPosition}"`
|
|
285
306
|
: undefined,
|
|
286
307
|
round: item.round ? " round" : undefined,
|
|
287
308
|
active: item.active ? " active" : undefined,
|
|
@@ -297,7 +318,7 @@ function TemplateDev() {
|
|
|
297
318
|
size=${ifDefined(size.size)}
|
|
298
319
|
variant=${ifDefined(group.variant)}
|
|
299
320
|
icon=${ifDefined(item.icon)}
|
|
300
|
-
|
|
321
|
+
iconPosition=${ifDefined(item.iconPosition)}
|
|
301
322
|
expanded=${ifDefined(item.expanded)}
|
|
302
323
|
?round=${item.round}
|
|
303
324
|
?active=${item.active}
|
|
@@ -318,11 +339,11 @@ function TemplateDev() {
|
|
|
318
339
|
)}`
|
|
319
340
|
}
|
|
320
341
|
|
|
321
|
-
export const
|
|
322
|
-
|
|
342
|
+
export const Overview = TemplateOverview.bind({})
|
|
343
|
+
Overview.argTypes = {
|
|
323
344
|
label: { table: { disable: true } },
|
|
324
345
|
icon: { table: { disable: true } },
|
|
325
|
-
|
|
346
|
+
iconPosition: { table: { disable: true } },
|
|
326
347
|
size: { table: { disable: true } },
|
|
327
348
|
variant: { table: { disable: true } },
|
|
328
349
|
type: { table: { disable: true } },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
-
import { fixture, expect } from "@open-wc/testing"
|
|
2
|
+
import { fixture, expect, elementUpdated, oneEvent } from "@open-wc/testing"
|
|
3
3
|
|
|
4
4
|
import "../leu-button.js"
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ async function defaultFixture() {
|
|
|
9
9
|
|
|
10
10
|
describe("LeuButton", () => {
|
|
11
11
|
it("is a defined element", async () => {
|
|
12
|
-
const el =
|
|
12
|
+
const el = customElements.get("leu-button")
|
|
13
13
|
|
|
14
14
|
await expect(el).not.to.be.undefined
|
|
15
15
|
})
|
|
@@ -19,4 +19,114 @@ describe("LeuButton", () => {
|
|
|
19
19
|
|
|
20
20
|
await expect(el).shadowDom.to.be.accessible()
|
|
21
21
|
})
|
|
22
|
+
|
|
23
|
+
it("renders the label", async () => {
|
|
24
|
+
const el = await fixture(html` <leu-button label="Sichern"></leu-button>`)
|
|
25
|
+
const button = el.shadowRoot.querySelector("button")
|
|
26
|
+
|
|
27
|
+
expect(button).to.have.trimmed.text("Sichern")
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("renders the icon at the correct position", async () => {
|
|
31
|
+
const el = await fixture(
|
|
32
|
+
html` <leu-button icon="addNew" label="Sichern"></leu-button>`
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const button = el.shadowRoot.querySelector("button")
|
|
36
|
+
|
|
37
|
+
expect(button).dom.to.equal(
|
|
38
|
+
"<button><div><svg><path /></svg></div>Sichern</div>",
|
|
39
|
+
{ ignoreAttributes: ["d", "class", "type"] }
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
el.iconPosition = "after"
|
|
43
|
+
|
|
44
|
+
await elementUpdated(el)
|
|
45
|
+
|
|
46
|
+
expect(button).dom.to.equal(
|
|
47
|
+
"<button>Sichern<div><svg><path /></svg></div></div>",
|
|
48
|
+
{ ignoreAttributes: ["d", "class", "type"] }
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it("renders the icon at the correct size", async () => {
|
|
53
|
+
const el = await fixture(
|
|
54
|
+
html` <leu-button icon="addNew" label="Sichern"></leu-button>`
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const button = el.shadowRoot.querySelector("button")
|
|
58
|
+
|
|
59
|
+
expect(button).dom.to.equal(
|
|
60
|
+
"<button><div><svg width='24' height='24'><path /></svg></div>Sichern</div>",
|
|
61
|
+
{ ignoreAttributes: ["d", "class", "type"] }
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
el.size = "small"
|
|
65
|
+
|
|
66
|
+
await elementUpdated(el)
|
|
67
|
+
|
|
68
|
+
expect(button).dom.to.equal(
|
|
69
|
+
"<button><div><svg width='16' height='16'><path /></svg></div>Sichern</div>",
|
|
70
|
+
{ ignoreAttributes: ["d", "class", "type"] }
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("renders the expanded icon only when the variant is ghost", async () => {
|
|
75
|
+
const el = await fixture(
|
|
76
|
+
html` <leu-button
|
|
77
|
+
icon="addNew"
|
|
78
|
+
label="Sichern"
|
|
79
|
+
variant="ghost"
|
|
80
|
+
expanded="open"
|
|
81
|
+
></leu-button>`
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const button = el.shadowRoot.querySelector("button")
|
|
85
|
+
|
|
86
|
+
expect(button).dom.to.equal(
|
|
87
|
+
"<button class='ghost normal'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div>Sichern<div class='icon-wrapper icon-wrapper--expanded'><svg width='24' height='24'><path /></svg></div></div>",
|
|
88
|
+
{ ignoreAttributes: ["d", "type", "width", "height"] }
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
el.variant = "primary"
|
|
92
|
+
|
|
93
|
+
await elementUpdated(el)
|
|
94
|
+
|
|
95
|
+
expect(button).dom.to.equal(
|
|
96
|
+
"<button class='primary normal'><div class='icon-wrapper icon-wrapper--before'><svg width='24' height='24'><path /></svg></div>Sichern</div>",
|
|
97
|
+
{ ignoreAttributes: ["d", "type"] }
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it("sets the dissabled attrbiute", async () => {
|
|
102
|
+
const el = await fixture(
|
|
103
|
+
html` <leu-button
|
|
104
|
+
icon="addNew"
|
|
105
|
+
label="Sichern"
|
|
106
|
+
variant="ghost"
|
|
107
|
+
expanded="open"
|
|
108
|
+
disabled
|
|
109
|
+
></leu-button>`
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const button = el.shadowRoot.querySelector("button")
|
|
113
|
+
|
|
114
|
+
expect(button).to.have.attribute("disabled")
|
|
115
|
+
|
|
116
|
+
el.disabled = false
|
|
117
|
+
await elementUpdated(el)
|
|
118
|
+
|
|
119
|
+
expect(button).to.not.have.attribute("disabled")
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it("dispatches the click event", async () => {
|
|
123
|
+
const el = await fixture(html` <leu-button label="Sichern"></leu-button>`)
|
|
124
|
+
const button = el.shadowRoot.querySelector("button")
|
|
125
|
+
|
|
126
|
+
setTimeout(() => button.click())
|
|
127
|
+
|
|
128
|
+
const event = await oneEvent(el, "click")
|
|
129
|
+
|
|
130
|
+
expect(event).to.exist
|
|
131
|
+
})
|
|
22
132
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { html, LitElement } from "lit"
|
|
2
|
-
import { defineElement } from "../../lib/defineElement.js"
|
|
3
2
|
import styles from "./button-group.css"
|
|
4
|
-
import
|
|
3
|
+
import "../button/leu-button.js"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* @tagname leu-button-group
|
|
@@ -56,8 +55,3 @@ export class LeuButtonGroup extends LitElement {
|
|
|
56
55
|
`
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
export function defineButtonGroupElements() {
|
|
61
|
-
defineButtonElements()
|
|
62
|
-
defineElement("button-group", LeuButtonGroup)
|
|
63
|
-
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineElement } from "../../lib/defineElement.js"
|
|
2
|
+
import { LeuButtonGroup } from "./ButtonGroup.js"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export { LeuButtonGroup }
|
|
5
|
+
|
|
6
|
+
defineElement("button-group", LeuButtonGroup)
|
|
@@ -14,6 +14,12 @@ function updateStorybookArgss(id, args) {
|
|
|
14
14
|
export default {
|
|
15
15
|
title: "ButtonGroup",
|
|
16
16
|
component: "leu-button-group",
|
|
17
|
+
parameters: {
|
|
18
|
+
design: {
|
|
19
|
+
type: "figma",
|
|
20
|
+
url: "https://www.figma.com/file/d6Pv21UVUbnBs3AdcZijHmbN/KTZH-Design-System?type=design&node-id=18180-165796&mode=design&t=lzVrtq8lxYVJU5TB-11",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
function Template({ items, value }, { id }) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { html } from "lit"
|
|
2
|
-
import { fixture, expect } from "@open-wc/testing"
|
|
2
|
+
import { fixture, expect, oneEvent, elementUpdated } from "@open-wc/testing"
|
|
3
3
|
|
|
4
4
|
import "../leu-button-group.js"
|
|
5
5
|
|
|
6
|
+
const items = ["Eins", "Zwei", "Drei"]
|
|
7
|
+
|
|
6
8
|
async function defaultFixture() {
|
|
7
|
-
return fixture(html` <leu-button-group
|
|
9
|
+
return fixture(html` <leu-button-group .items=${items}></leu-button-group> `)
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
describe("LeuButtonGroup", () => {
|
|
11
13
|
it("is a defined element", async () => {
|
|
12
|
-
const el =
|
|
14
|
+
const el = customElements.get("leu-button-group")
|
|
13
15
|
|
|
14
16
|
await expect(el).not.to.be.undefined
|
|
15
17
|
})
|
|
@@ -19,4 +21,78 @@ describe("LeuButtonGroup", () => {
|
|
|
19
21
|
|
|
20
22
|
await expect(el).shadowDom.to.be.accessible()
|
|
21
23
|
})
|
|
24
|
+
|
|
25
|
+
it("has no value by default", async () => {
|
|
26
|
+
const el = await defaultFixture()
|
|
27
|
+
|
|
28
|
+
await expect(el.value).to.be.null
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it("has the correct value after clicking a button", async () => {
|
|
32
|
+
const el = await defaultFixture()
|
|
33
|
+
|
|
34
|
+
const buttons = el.shadowRoot.querySelectorAll("leu-button")
|
|
35
|
+
|
|
36
|
+
buttons[1].click()
|
|
37
|
+
await expect(el.value).to.equal("Zwei")
|
|
38
|
+
|
|
39
|
+
buttons[0].click()
|
|
40
|
+
await expect(el.value).to.equal("Eins")
|
|
41
|
+
|
|
42
|
+
buttons[2].click()
|
|
43
|
+
await expect(el.value).to.equal("Drei")
|
|
44
|
+
|
|
45
|
+
// Should not change after clicking the same button again
|
|
46
|
+
buttons[2].click()
|
|
47
|
+
await expect(el.value).to.equal("Drei")
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it("renders the active button as a primary button", async () => {
|
|
51
|
+
const el = await defaultFixture()
|
|
52
|
+
el.value = "Zwei"
|
|
53
|
+
await elementUpdated(el)
|
|
54
|
+
|
|
55
|
+
const buttons = el.shadowRoot.querySelectorAll("leu-button")
|
|
56
|
+
|
|
57
|
+
await expect(buttons[0].variant).to.equal("secondary")
|
|
58
|
+
await expect(buttons[1].variant).to.equal("primary")
|
|
59
|
+
await expect(buttons[2].variant).to.equal("secondary")
|
|
60
|
+
|
|
61
|
+
buttons[0].click()
|
|
62
|
+
|
|
63
|
+
await expect(buttons[0].variant).to.equal("secondary")
|
|
64
|
+
await expect(buttons[1].variant).to.equal("secondary")
|
|
65
|
+
await expect(buttons[2].variant).to.equal("secondary")
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("sets the correct aria-checked attribute", async () => {
|
|
69
|
+
const el = await defaultFixture()
|
|
70
|
+
el.value = "Drei"
|
|
71
|
+
await elementUpdated(el)
|
|
72
|
+
|
|
73
|
+
const buttons = el.shadowRoot.querySelectorAll("leu-button")
|
|
74
|
+
|
|
75
|
+
await expect(buttons[0].getAttribute("aria-checked")).to.equal("false")
|
|
76
|
+
await expect(buttons[1].getAttribute("aria-checked")).to.equal("false")
|
|
77
|
+
await expect(buttons[2].getAttribute("aria-checked")).to.equal("true")
|
|
78
|
+
|
|
79
|
+
buttons[0].click()
|
|
80
|
+
await expect(buttons[0].getAttribute("aria-checked")).to.equal("false")
|
|
81
|
+
await expect(buttons[1].getAttribute("aria-checked")).to.equal("false")
|
|
82
|
+
await expect(buttons[2].getAttribute("aria-checked")).to.equal("false")
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it("dispatches an input event when the value changes", async () => {
|
|
86
|
+
const el = await defaultFixture()
|
|
87
|
+
el.value = "Drei"
|
|
88
|
+
await elementUpdated(el)
|
|
89
|
+
|
|
90
|
+
const buttons = el.shadowRoot.querySelectorAll("leu-button")
|
|
91
|
+
|
|
92
|
+
setTimeout(() => buttons[0].click())
|
|
93
|
+
|
|
94
|
+
const inputEvent = await oneEvent(el, "input")
|
|
95
|
+
|
|
96
|
+
await expect(inputEvent.detail.value).to.be.equal("Eins")
|
|
97
|
+
})
|
|
22
98
|
})
|