@statistikzh/leu 0.22.0 → 0.22.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/.github/workflows/release-please.yml +1 -2
- package/.nvmrc +1 -1
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +9 -0
- package/README.md +15 -10
- package/dist/Accordion.js +1 -1
- package/dist/Button.d.ts +1 -1
- package/dist/Button.js +1 -1
- package/dist/ButtonGroup.js +1 -1
- package/dist/ChartWrapper.js +1 -1
- package/dist/Checkbox.d.ts +1 -1
- package/dist/Checkbox.js +1 -1
- package/dist/CheckboxGroup.js +1 -1
- package/dist/Chip.d.ts +1 -7
- package/dist/Chip.js +7 -5
- package/dist/ChipGroup.d.ts +17 -36
- package/dist/ChipGroup.js +35 -33
- package/dist/ChipLink.d.ts +5 -21
- package/dist/ChipLink.js +14 -15
- package/dist/ChipRemovable.d.ts +4 -15
- package/dist/ChipRemovable.js +7 -9
- package/dist/ChipSelectable.d.ts +14 -37
- package/dist/ChipSelectable.js +24 -28
- package/dist/Dialog.d.ts +7 -18
- package/dist/Dialog.js +15 -18
- package/dist/Dropdown.d.ts +16 -28
- package/dist/Dropdown.js +22 -23
- package/dist/FileInput.d.ts +2 -1
- package/dist/FileInput.js +19 -5
- package/dist/Icon.d-itcQ94ym.d.ts +151 -0
- package/dist/Icon.d.ts +4 -156
- package/dist/Icon.js +1 -4
- package/dist/Input.d.ts +73 -141
- package/dist/Input.js +91 -88
- package/dist/{LeuElement-BooZrClI.js → LeuElement-DfsEye-A.js} +1 -1
- package/dist/Menu.d.ts +2 -8
- package/dist/Menu.js +7 -9
- package/dist/MenuItem.d.ts +31 -59
- package/dist/MenuItem.js +30 -33
- package/dist/Message.d.ts +1 -1
- package/dist/Message.js +1 -1
- package/dist/Pagination.d.ts +1 -1
- package/dist/Pagination.js +1 -1
- package/dist/Placeholder.js +1 -1
- package/dist/Popup.js +1 -1
- package/dist/ProgressBar.js +1 -1
- package/dist/Radio.js +1 -1
- package/dist/RadioGroup.js +1 -1
- package/dist/Range.d.ts +22 -65
- package/dist/Range.js +36 -37
- package/dist/ScrollTop.d.ts +5 -7
- package/dist/ScrollTop.js +10 -15
- package/dist/Select.d.ts +2 -1
- package/dist/Select.js +1 -1
- package/dist/Spinner.js +1 -1
- package/dist/Table.d.ts +1 -1
- package/dist/Table.js +1 -1
- package/dist/Tag.js +1 -1
- package/dist/VisuallyHidden.js +1 -1
- package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts +5 -0
- package/dist/components/chart-wrapper/leu-chart-wrapper.d.ts.map +1 -1
- package/dist/components/chip/Chip.d.ts +1 -7
- package/dist/components/chip/Chip.d.ts.map +1 -1
- package/dist/components/chip/ChipGroup.d.ts +15 -35
- package/dist/components/chip/ChipGroup.d.ts.map +1 -1
- package/dist/components/chip/ChipLink.d.ts +4 -20
- package/dist/components/chip/ChipLink.d.ts.map +1 -1
- package/dist/components/chip/ChipRemovable.d.ts +3 -14
- package/dist/components/chip/ChipRemovable.d.ts.map +1 -1
- package/dist/components/chip/ChipSelectable.d.ts +13 -36
- package/dist/components/chip/ChipSelectable.d.ts.map +1 -1
- package/dist/components/chip/stories/chip-group.stories.d.ts +1 -1
- package/dist/components/chip/stories/chip-group.stories.d.ts.map +1 -1
- package/dist/components/chip/stories/chip-link.stories.d.ts.map +1 -1
- package/dist/components/chip/stories/chip-selectable.stories.d.ts.map +1 -1
- package/dist/components/dialog/Dialog.d.ts +5 -17
- package/dist/components/dialog/Dialog.d.ts.map +1 -1
- package/dist/components/dropdown/Dropdown.d.ts +14 -27
- package/dist/components/dropdown/Dropdown.d.ts.map +1 -1
- package/dist/components/file-input/FileInput.d.ts +1 -0
- package/dist/components/file-input/FileInput.d.ts.map +1 -1
- package/dist/components/file-input/leu-file-input.d.ts +5 -0
- package/dist/components/file-input/leu-file-input.d.ts.map +1 -1
- package/dist/components/file-input/stories/file-input.stories.d.ts +4 -0
- package/dist/components/file-input/stories/file-input.stories.d.ts.map +1 -1
- package/dist/components/icon/Icon.d.ts +0 -6
- package/dist/components/icon/Icon.d.ts.map +1 -1
- package/dist/components/input/Input.d.ts +73 -140
- package/dist/components/input/Input.d.ts.map +1 -1
- package/dist/components/menu/Menu.d.ts +1 -7
- package/dist/components/menu/Menu.d.ts.map +1 -1
- package/dist/components/menu/MenuItem.d.ts +30 -57
- package/dist/components/menu/MenuItem.d.ts.map +1 -1
- package/dist/components/message/leu-message.d.ts +5 -0
- package/dist/components/message/leu-message.d.ts.map +1 -1
- package/dist/components/placeholder/leu-placeholder.d.ts +5 -0
- package/dist/components/placeholder/leu-placeholder.d.ts.map +1 -1
- package/dist/components/progress-bar/leu-progress-bar.d.ts +5 -0
- package/dist/components/progress-bar/leu-progress-bar.d.ts.map +1 -1
- package/dist/components/range/Range.d.ts +22 -65
- package/dist/components/range/Range.d.ts.map +1 -1
- package/dist/components/scroll-top/ScrollTop.d.ts +4 -6
- package/dist/components/scroll-top/ScrollTop.d.ts.map +1 -1
- package/dist/components/tag/leu-tag.d.ts +5 -0
- package/dist/components/tag/leu-tag.d.ts.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/leu-accordion.js +1 -1
- package/dist/leu-button-group.js +1 -1
- package/dist/leu-button.d.ts +1 -1
- package/dist/leu-button.js +1 -1
- package/dist/leu-chart-wrapper.d.ts +10 -1
- package/dist/leu-chart-wrapper.js +1 -1
- package/dist/leu-checkbox-group.js +1 -1
- package/dist/leu-checkbox.d.ts +1 -1
- package/dist/leu-checkbox.js +1 -1
- package/dist/leu-chip-group.d.ts +2 -0
- package/dist/leu-chip-group.js +5 -1
- package/dist/leu-chip-link.js +3 -1
- package/dist/leu-chip-removable.d.ts +1 -1
- package/dist/leu-chip-removable.js +3 -3
- package/dist/leu-chip-selectable.js +3 -1
- package/dist/leu-dialog.d.ts +2 -1
- package/dist/leu-dialog.js +3 -3
- package/dist/leu-dropdown.d.ts +2 -1
- package/dist/leu-dropdown.js +3 -3
- package/dist/leu-file-input.d.ts +11 -2
- package/dist/leu-file-input.js +11 -4
- package/dist/leu-icon.d.ts +1 -1
- package/dist/leu-icon.js +1 -1
- package/dist/leu-input.d.ts +2 -1
- package/dist/leu-input.js +3 -3
- package/dist/leu-menu-item.d.ts +2 -2
- package/dist/leu-menu-item.js +3 -3
- package/dist/leu-menu.d.ts +1 -1
- package/dist/leu-menu.js +3 -3
- package/dist/leu-message.d.ts +11 -2
- package/dist/leu-message.js +1 -1
- package/dist/leu-pagination.d.ts +1 -1
- package/dist/leu-pagination.js +1 -1
- package/dist/leu-placeholder.d.ts +10 -1
- package/dist/leu-placeholder.js +1 -1
- package/dist/leu-popup.js +1 -1
- package/dist/leu-progress-bar.d.ts +10 -1
- package/dist/leu-progress-bar.js +1 -1
- package/dist/leu-radio-group.js +1 -1
- package/dist/leu-radio.js +1 -1
- package/dist/leu-range.js +3 -1
- package/dist/leu-scroll-top.d.ts +1 -1
- package/dist/leu-scroll-top.js +3 -3
- package/dist/leu-select.d.ts +2 -1
- package/dist/leu-select.js +1 -1
- package/dist/leu-spinner.js +1 -1
- package/dist/leu-table.d.ts +1 -1
- package/dist/leu-table.js +1 -1
- package/dist/leu-tag.d.ts +10 -1
- package/dist/leu-tag.js +1 -1
- package/dist/leu-visually-hidden.js +1 -1
- package/dist/vscode.html-custom-data.json +126 -123
- package/dist/vue/index.d.ts +129 -146
- package/dist/web-types.json +340 -345
- package/package.json +1 -1
- package/scripts/generate-component/templates/[namespace]-[name].ts +6 -0
- package/src/components/chart-wrapper/leu-chart-wrapper.ts +6 -0
- package/src/components/chip/Chip.ts +3 -9
- package/src/components/chip/ChipGroup.ts +26 -39
- package/src/components/chip/ChipLink.ts +7 -18
- package/src/components/chip/ChipRemovable.ts +4 -11
- package/src/components/chip/ChipSelectable.ts +21 -35
- package/src/components/chip/stories/chip-group.stories.ts +4 -7
- package/src/components/chip/stories/chip-link.stories.ts +2 -4
- package/src/components/chip/stories/chip-selectable.stories.ts +4 -6
- package/src/components/chip/test/chip-group.test.ts +34 -31
- package/src/components/dialog/Dialog.ts +9 -22
- package/src/components/dropdown/Dropdown.ts +19 -26
- package/src/components/file-input/FileInput.ts +12 -1
- package/src/components/file-input/leu-file-input.ts +6 -0
- package/src/components/file-input/stories/file-input.stories.ts +7 -0
- package/src/components/icon/Icon.ts +0 -4
- package/src/components/input/Input.ts +108 -105
- package/src/components/menu/Menu.ts +3 -12
- package/src/components/menu/MenuItem.ts +37 -41
- package/src/components/message/leu-message.ts +6 -0
- package/src/components/placeholder/leu-placeholder.ts +6 -0
- package/src/components/progress-bar/leu-progress-bar.ts +6 -0
- package/src/components/range/Range.ts +51 -59
- package/src/components/scroll-top/ScrollTop.ts +8 -15
- package/src/components/tag/leu-tag.ts +6 -0
- package/src/index.ts +11 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html, nothing } from "lit"
|
|
2
2
|
import { createRef, ref } from "lit/directives/ref.js"
|
|
3
|
+
import { property } from "lit/decorators.js"
|
|
3
4
|
|
|
4
5
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
5
6
|
import { HasSlotController } from "../../lib/hasSlotController.js"
|
|
@@ -24,24 +25,18 @@ export class LeuDropdown extends LeuElement {
|
|
|
24
25
|
|
|
25
26
|
static styles = [LeuElement.styles, styles]
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expanded: { type: Boolean, reflect: true },
|
|
30
|
-
inverted: { type: Boolean, reflect: true },
|
|
31
|
-
}
|
|
28
|
+
@property({ type: String, reflect: true })
|
|
29
|
+
label: string = ""
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
@property({ type: Boolean, reflect: true })
|
|
32
|
+
expanded: boolean = false
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
@property({ type: Boolean, reflect: true })
|
|
35
|
+
inverted: boolean = false
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
this.expanded = false
|
|
40
|
-
this.inverted = false
|
|
37
|
+
protected hasSlotController = new HasSlotController(this, ["icon"])
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
this._toggleRef = createRef()
|
|
44
|
-
}
|
|
39
|
+
protected _toggleRef = createRef<HTMLButtonElement>()
|
|
45
40
|
|
|
46
41
|
connectedCallback() {
|
|
47
42
|
super.connectedCallback()
|
|
@@ -65,19 +60,19 @@ export class LeuDropdown extends LeuElement {
|
|
|
65
60
|
menu.removeEventListener("click", this._menuItemClickHandler)
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
_documentClickHandler = (event) => {
|
|
63
|
+
protected _documentClickHandler = (event: MouseEvent) => {
|
|
69
64
|
if (!event.composedPath().includes(this)) {
|
|
70
65
|
this.expanded = false
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
_keyUpHandler(event) {
|
|
69
|
+
protected _keyUpHandler = (event: KeyboardEvent) => {
|
|
75
70
|
if (event.key === "Escape") {
|
|
76
71
|
this.expanded = false
|
|
77
72
|
}
|
|
78
73
|
}
|
|
79
74
|
|
|
80
|
-
async _keyDownToggleHandler(event) {
|
|
75
|
+
protected async _keyDownToggleHandler(event: KeyboardEvent) {
|
|
81
76
|
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
|
|
82
77
|
event.preventDefault()
|
|
83
78
|
const menu = this._getMenu()
|
|
@@ -94,7 +89,9 @@ export class LeuDropdown extends LeuElement {
|
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
|
|
97
|
-
_menuItemClickHandler = (
|
|
92
|
+
protected _menuItemClickHandler = (
|
|
93
|
+
e: MouseEvent & { target: HTMLElement },
|
|
94
|
+
) => {
|
|
98
95
|
if (e.target.tagName.toLowerCase() === "leu-menu-item") {
|
|
99
96
|
this.expanded = false
|
|
100
97
|
this._toggleRef.value.focus()
|
|
@@ -104,9 +101,8 @@ export class LeuDropdown extends LeuElement {
|
|
|
104
101
|
/**
|
|
105
102
|
* Close the dropdown when the user presses the Escape or the Tab key.
|
|
106
103
|
* Navigating the menu with the arrow keys is handled by the menu itself.
|
|
107
|
-
* @param {KeyboardEvent} e
|
|
108
104
|
*/
|
|
109
|
-
_keyDownMenuHandler = (e) => {
|
|
105
|
+
protected _keyDownMenuHandler = (e: KeyboardEvent) => {
|
|
110
106
|
if (e.key === "Escape" || e.key === "Tab") {
|
|
111
107
|
e.preventDefault()
|
|
112
108
|
this.expanded = false
|
|
@@ -114,15 +110,12 @@ export class LeuDropdown extends LeuElement {
|
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
_handleToggleClick() {
|
|
113
|
+
protected _handleToggleClick() {
|
|
118
114
|
this.expanded = !this.expanded
|
|
119
115
|
}
|
|
120
116
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
_getMenu() {
|
|
125
|
-
return this.querySelector("leu-menu")
|
|
117
|
+
protected _getMenu() {
|
|
118
|
+
return this.querySelector<LeuMenu>("leu-menu")
|
|
126
119
|
}
|
|
127
120
|
|
|
128
121
|
render() {
|
|
@@ -129,6 +129,10 @@ export class LeuFileInput extends LeuElement {
|
|
|
129
129
|
|
|
130
130
|
protected removeFile(fileToRemove: File) {
|
|
131
131
|
this.files = this.files.filter((file) => file !== fileToRemove)
|
|
132
|
+
this.dispatchChangeAndInputEvents()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
protected dispatchChangeAndInputEvents() {
|
|
132
136
|
this.dispatchEvent(
|
|
133
137
|
new CustomEvent("input", {
|
|
134
138
|
composed: true,
|
|
@@ -182,6 +186,8 @@ export class LeuFileInput extends LeuElement {
|
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
protected handleDrop = (event: DragEvent) => {
|
|
189
|
+
this.isDragging = false
|
|
190
|
+
|
|
185
191
|
if (this.disabled) return
|
|
186
192
|
|
|
187
193
|
event.preventDefault()
|
|
@@ -191,10 +197,15 @@ export class LeuFileInput extends LeuElement {
|
|
|
191
197
|
const files = dt.files
|
|
192
198
|
const acceptedFiles = [...files].filter((file) => this.isAcceptedFile(file))
|
|
193
199
|
|
|
200
|
+
if (acceptedFiles.length < 1) {
|
|
201
|
+
return
|
|
202
|
+
}
|
|
203
|
+
|
|
194
204
|
this.files = this.multiple
|
|
195
205
|
? this.files.concat(acceptedFiles)
|
|
196
206
|
: acceptedFiles.slice(0, 1)
|
|
197
|
-
|
|
207
|
+
|
|
208
|
+
this.dispatchChangeAndInputEvents()
|
|
198
209
|
}
|
|
199
210
|
|
|
200
211
|
isAcceptedFile(file: File): boolean {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Meta, StoryObj } from "@storybook/web-components"
|
|
2
|
+
import { action } from "@storybook/addon-actions"
|
|
2
3
|
import { html } from "lit"
|
|
3
4
|
import { ifDefined } from "lit/directives/if-defined.js"
|
|
4
5
|
|
|
@@ -11,6 +12,10 @@ type Story = StoryObj<StoryArgs>
|
|
|
11
12
|
export default {
|
|
12
13
|
title: "Components/FileInput",
|
|
13
14
|
component: "leu-file-input",
|
|
15
|
+
args: {
|
|
16
|
+
oninput: action("input"),
|
|
17
|
+
onchange: action("change"),
|
|
18
|
+
},
|
|
14
19
|
} satisfies Meta<StoryArgs>
|
|
15
20
|
|
|
16
21
|
const Template: Story = {
|
|
@@ -22,6 +27,8 @@ const Template: Story = {
|
|
|
22
27
|
?disabled=${args.disabled}
|
|
23
28
|
?multiple=${args.multiple}
|
|
24
29
|
?required=${args.required}
|
|
30
|
+
@input=${args.oninput}
|
|
31
|
+
@change=${args.onchange}
|
|
25
32
|
></leu-file-input>
|
|
26
33
|
`,
|
|
27
34
|
}
|
|
@@ -18,10 +18,6 @@ import { paths, IconPathName } from "./paths.js"
|
|
|
18
18
|
export class LeuIcon extends LeuElement {
|
|
19
19
|
static styles = [LeuElement.styles, styles]
|
|
20
20
|
|
|
21
|
-
static properties = {
|
|
22
|
-
name: { type: String, reflect: true },
|
|
23
|
-
}
|
|
24
|
-
|
|
25
21
|
/**
|
|
26
22
|
* The name of the icon to display.
|
|
27
23
|
*/
|
|
@@ -3,17 +3,32 @@ import { classMap } from "lit/directives/class-map.js"
|
|
|
3
3
|
import { ifDefined } from "lit/directives/if-defined.js"
|
|
4
4
|
import { live } from "lit/directives/live.js"
|
|
5
5
|
import { createRef, ref } from "lit/directives/ref.js"
|
|
6
|
+
import { property, state } from "lit/decorators.js"
|
|
6
7
|
|
|
7
8
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
8
9
|
import { LeuIcon } from "../icon/Icon.js"
|
|
9
10
|
|
|
10
11
|
import styles from "./input.css"
|
|
12
|
+
import { IconPathName } from "../icon/paths.js"
|
|
11
13
|
|
|
12
14
|
export const SIZES = Object.freeze({
|
|
13
15
|
SMALL: "small",
|
|
14
16
|
REGULAR: "regular",
|
|
15
17
|
})
|
|
16
18
|
|
|
19
|
+
type InputType =
|
|
20
|
+
| "date"
|
|
21
|
+
| "datetime-local"
|
|
22
|
+
| "email"
|
|
23
|
+
| "month"
|
|
24
|
+
| "number"
|
|
25
|
+
| "password"
|
|
26
|
+
| "search"
|
|
27
|
+
| "tel"
|
|
28
|
+
| "text"
|
|
29
|
+
| "time"
|
|
30
|
+
| "week"
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
* TODO:
|
|
19
34
|
* - Add section to docs about how to mark up suffix and prefix for screenreaders
|
|
@@ -38,27 +53,6 @@ const VALIDATION_MESSAGES = {
|
|
|
38
53
|
/**
|
|
39
54
|
* A text input element.
|
|
40
55
|
*
|
|
41
|
-
* @prop {boolean} disabled - Disables the input element.
|
|
42
|
-
* @prop {boolean} required - Marks the input element as required.
|
|
43
|
-
* @prop {boolean} clearable - Adds a button to clear the input element.
|
|
44
|
-
* @prop {string} value - The value of the input element.
|
|
45
|
-
* @prop {string} name - The name of the input element.
|
|
46
|
-
* @prop {string} label - The label of the input element.
|
|
47
|
-
* @prop {string} error - A custom error that is completely independent of the validity state. Useful for displaying server side errors.
|
|
48
|
-
* @prop {string} size - The size of the input element.
|
|
49
|
-
* @prop {string} icon - The icon that is displayed at the end of the input element.
|
|
50
|
-
* @prop {string} prefix - A prefix that relates to the value of the input (e.g. CHF).
|
|
51
|
-
* @prop {string} suffix - A suffix that relates to the value of the input (e.g. mm).
|
|
52
|
-
* @prop {string} pattern - A regular expression that the value is checked against.
|
|
53
|
-
* @prop {string} type - The type of the input element.
|
|
54
|
-
* @prop {string} min - The minimum value of the input element.
|
|
55
|
-
* @prop {string} max - The maximum value of the input element.
|
|
56
|
-
* @prop {string} minlength - The minimum length of the input element.
|
|
57
|
-
* @prop {string} maxlength - The maximum length of the input element.
|
|
58
|
-
* @prop {object} validationMessages - Custom validation messages. The key is the name of the validity state and the value is the message.
|
|
59
|
-
* @prop {boolean} novalidate - Disables the browser's validation.
|
|
60
|
-
* @prop {string} step - The step value of the input element.
|
|
61
|
-
*
|
|
62
56
|
* @fires {CustomEvent} input - Dispatched when the value of the input element changes.
|
|
63
57
|
* @fires {CustomEvent} change - Dispatched when the value of the input element changes and the input element loses focus.
|
|
64
58
|
*
|
|
@@ -79,34 +73,88 @@ export class LeuInput extends LeuElement {
|
|
|
79
73
|
delegatesFocus: true,
|
|
80
74
|
}
|
|
81
75
|
|
|
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
|
-
|
|
109
|
-
|
|
76
|
+
/** Disables the input element. */
|
|
77
|
+
@property({ type: Boolean, reflect: true })
|
|
78
|
+
disabled: boolean = false
|
|
79
|
+
|
|
80
|
+
/** Marks the input element as required */
|
|
81
|
+
@property({ type: Boolean, reflect: true })
|
|
82
|
+
required: boolean = false
|
|
83
|
+
|
|
84
|
+
/** Adds a button to clear the input element */
|
|
85
|
+
@property({ type: Boolean, reflect: true })
|
|
86
|
+
clearable: boolean = false
|
|
87
|
+
|
|
88
|
+
/** The value of the input element. */
|
|
89
|
+
@property({ type: String, reflect: true })
|
|
90
|
+
value: string = ""
|
|
91
|
+
|
|
92
|
+
/** The name of the input element. */
|
|
93
|
+
@property({ type: String, reflect: true })
|
|
94
|
+
name: string = ""
|
|
95
|
+
|
|
96
|
+
/** A custom error that is completely independent of the validity state. Useful for displaying server side errors. */
|
|
97
|
+
@property({ type: String, reflect: true })
|
|
98
|
+
error: string = ""
|
|
99
|
+
|
|
100
|
+
/** The label of the input element */
|
|
101
|
+
@property({ type: String, reflect: true })
|
|
102
|
+
label: string = ""
|
|
103
|
+
|
|
104
|
+
/** A prefix that relates to the value of the input (e.g. CHF) */
|
|
105
|
+
@property({ type: String, reflect: true })
|
|
106
|
+
prefix: string
|
|
107
|
+
|
|
108
|
+
/** A suffix that relates to the value of the input (e.g. mm). */
|
|
109
|
+
@property({ type: String, reflect: true })
|
|
110
|
+
suffix: string
|
|
111
|
+
|
|
112
|
+
/** The size of the input element */
|
|
113
|
+
@property({ type: String, reflect: true })
|
|
114
|
+
size: "small" | "regular" = "regular"
|
|
115
|
+
|
|
116
|
+
/** The icon that is displayed at the end of the input element */
|
|
117
|
+
@property({ type: String, reflect: true })
|
|
118
|
+
icon: IconPathName
|
|
119
|
+
|
|
120
|
+
/** A regular expression that the value is checked against. */
|
|
121
|
+
@property({ type: String, reflect: true })
|
|
122
|
+
pattern: string
|
|
123
|
+
|
|
124
|
+
/** The type of the input element. */
|
|
125
|
+
@property({ type: String, reflect: true })
|
|
126
|
+
type: InputType = "text"
|
|
127
|
+
|
|
128
|
+
/** The minimum value of the input element. */
|
|
129
|
+
@property({ type: Number, reflect: true })
|
|
130
|
+
min: number
|
|
131
|
+
|
|
132
|
+
/** The maximum value of the input element. */
|
|
133
|
+
@property({ type: Number, reflect: true })
|
|
134
|
+
max: number
|
|
135
|
+
|
|
136
|
+
/** The step value of the input element. */
|
|
137
|
+
@property({ type: Number, reflect: true })
|
|
138
|
+
step: number
|
|
139
|
+
|
|
140
|
+
/** The maximum length of the input element. */
|
|
141
|
+
@property({ type: Number, reflect: true })
|
|
142
|
+
maxlength: number
|
|
143
|
+
|
|
144
|
+
/** The minimum length of the input element. */
|
|
145
|
+
@property({ type: Number, reflect: true })
|
|
146
|
+
minlength: number
|
|
147
|
+
|
|
148
|
+
/** Custom validation messages. The key is the name of the validity state and the value is the message. */
|
|
149
|
+
@property({ type: Object })
|
|
150
|
+
validationMessages: Record<string, string> = {}
|
|
151
|
+
|
|
152
|
+
/** Disables the browser's validation. */
|
|
153
|
+
@property({ type: Boolean, reflect: true })
|
|
154
|
+
novalidate: boolean = false
|
|
155
|
+
|
|
156
|
+
@state()
|
|
157
|
+
_validity: ValidityState | null = null
|
|
110
158
|
|
|
111
159
|
static resolveErrorMessage(message, refernceValue) {
|
|
112
160
|
if (typeof message === "function") {
|
|
@@ -116,28 +164,7 @@ export class LeuInput extends LeuElement {
|
|
|
116
164
|
return message
|
|
117
165
|
}
|
|
118
166
|
|
|
119
|
-
|
|
120
|
-
super()
|
|
121
|
-
|
|
122
|
-
this.disabled = false
|
|
123
|
-
this.required = false
|
|
124
|
-
this.clearable = false
|
|
125
|
-
|
|
126
|
-
/** @type {"small" | "regular"} */
|
|
127
|
-
this.size = SIZES.REGULAR
|
|
128
|
-
|
|
129
|
-
this.type = "text"
|
|
130
|
-
this._validity = null
|
|
131
|
-
this.validationMessages = {}
|
|
132
|
-
this.novalidate = false
|
|
133
|
-
this.value = ""
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @internal
|
|
137
|
-
* @type {import("lit/directives/ref.js").Ref<HTMLInputElement>}
|
|
138
|
-
*/
|
|
139
|
-
this._inputRef = createRef()
|
|
140
|
-
}
|
|
167
|
+
protected _inputRef = createRef<HTMLInputElement>()
|
|
141
168
|
|
|
142
169
|
get valueAsNumber() {
|
|
143
170
|
if (this.value === "") {
|
|
@@ -153,11 +180,8 @@ export class LeuInput extends LeuElement {
|
|
|
153
180
|
* looks like the input element. But the actual input field does not
|
|
154
181
|
* completely fill the wrapper element. Keyboard events don't need to be
|
|
155
182
|
* handled because the actual input element is focusable.
|
|
156
|
-
* @private
|
|
157
|
-
* @param {MouseEvent|PointerEvent} event
|
|
158
|
-
* @returns {void}
|
|
159
183
|
*/
|
|
160
|
-
handleWrapperClick(event) {
|
|
184
|
+
protected handleWrapperClick(event: MouseEvent | PointerEvent) {
|
|
161
185
|
if (event.target === event.currentTarget) {
|
|
162
186
|
this._inputRef.value.focus()
|
|
163
187
|
}
|
|
@@ -166,11 +190,8 @@ export class LeuInput extends LeuElement {
|
|
|
166
190
|
/**
|
|
167
191
|
* Method for handling the blur event of the input element.
|
|
168
192
|
* Checks validity of the input element and sets the validity state.
|
|
169
|
-
* @private
|
|
170
|
-
* @param {FocusEvent & {target: HTMLInputElement}} event
|
|
171
|
-
* @returns {void}
|
|
172
193
|
*/
|
|
173
|
-
handleBlur(event) {
|
|
194
|
+
protected handleBlur(event: FocusEvent & { target: HTMLInputElement }) {
|
|
174
195
|
this._validity = null
|
|
175
196
|
|
|
176
197
|
if (!this.novalidate) {
|
|
@@ -181,11 +202,8 @@ export class LeuInput extends LeuElement {
|
|
|
181
202
|
/**
|
|
182
203
|
* Method for handling the invalid event of the input element.
|
|
183
204
|
* Sets the validity state.
|
|
184
|
-
* @private
|
|
185
|
-
* @param {Event} event
|
|
186
|
-
* @returns {void}
|
|
187
205
|
*/
|
|
188
|
-
handleInvalid(event) {
|
|
206
|
+
protected handleInvalid(event: Event & { target: HTMLInputElement }) {
|
|
189
207
|
this._validity = event.target.validity
|
|
190
208
|
}
|
|
191
209
|
|
|
@@ -193,12 +211,9 @@ export class LeuInput extends LeuElement {
|
|
|
193
211
|
* Method for handling the change event of the input element.
|
|
194
212
|
* Sets the value property and dispatches a change event so that
|
|
195
213
|
* the event can be handled outside the shadow DOM.
|
|
196
|
-
* @private
|
|
197
|
-
* @param {Event} event
|
|
198
214
|
* @fires {CustomEvent} change
|
|
199
|
-
* @returns {void}
|
|
200
215
|
*/
|
|
201
|
-
handleChange(event) {
|
|
216
|
+
protected handleChange(event: Event & { target: HTMLInputElement }) {
|
|
202
217
|
if (event.target.validity.valid) {
|
|
203
218
|
this.value = event.target.value
|
|
204
219
|
}
|
|
@@ -211,11 +226,8 @@ export class LeuInput extends LeuElement {
|
|
|
211
226
|
* Method for handling the input event of the input element.
|
|
212
227
|
* Sets the value property and dispatches an input event so that
|
|
213
228
|
* the event can be handled outside the shadow DOM.
|
|
214
|
-
* @private
|
|
215
|
-
* @param {Event} event
|
|
216
|
-
* @returns {void}
|
|
217
229
|
*/
|
|
218
|
-
handleInput(event) {
|
|
230
|
+
protected handleInput(event: Event & { target: HTMLInputElement }) {
|
|
219
231
|
this.value = event.target.value
|
|
220
232
|
|
|
221
233
|
const customEvent = new CustomEvent("input", {
|
|
@@ -229,12 +241,10 @@ export class LeuInput extends LeuElement {
|
|
|
229
241
|
* Method for clearing the input element.
|
|
230
242
|
* Sets the value property to an empty string and dispatches
|
|
231
243
|
* an input and a change event.
|
|
232
|
-
* @private
|
|
233
|
-
* @returns {void}
|
|
234
244
|
* @fires {CustomEvent} input
|
|
235
245
|
* @fires {CustomEvent} change
|
|
236
246
|
*/
|
|
237
|
-
clear() {
|
|
247
|
+
protected clear() {
|
|
238
248
|
this.value = ""
|
|
239
249
|
|
|
240
250
|
this._inputRef.value.focus()
|
|
@@ -255,10 +265,8 @@ export class LeuInput extends LeuElement {
|
|
|
255
265
|
* e.g.
|
|
256
266
|
* `tooLong(this.maxlength)`
|
|
257
267
|
* This way the framework user can create reasonable validation messages
|
|
258
|
-
*
|
|
259
|
-
* @returns {Object} validationMessages
|
|
260
268
|
*/
|
|
261
|
-
getValidationMessages() {
|
|
269
|
+
protected getValidationMessages() {
|
|
262
270
|
const validationMessages = {
|
|
263
271
|
...VALIDATION_MESSAGES,
|
|
264
272
|
...this.validationMessages,
|
|
@@ -299,7 +307,6 @@ export class LeuInput extends LeuElement {
|
|
|
299
307
|
|
|
300
308
|
/**
|
|
301
309
|
* Check input validation
|
|
302
|
-
* @returns {boolean} if valid or not
|
|
303
310
|
*/
|
|
304
311
|
checkValidity() {
|
|
305
312
|
return this._inputRef.value?.checkValidity() ?? false
|
|
@@ -307,9 +314,8 @@ export class LeuInput extends LeuElement {
|
|
|
307
314
|
|
|
308
315
|
/**
|
|
309
316
|
* Creates an error list with an item for the given validity state.
|
|
310
|
-
* @returns {import("lit").TemplateResult | nothing}
|
|
311
317
|
*/
|
|
312
|
-
renderErrorMessages() {
|
|
318
|
+
protected renderErrorMessages() {
|
|
313
319
|
if (!this.isInvalid()) {
|
|
314
320
|
return nothing
|
|
315
321
|
}
|
|
@@ -317,7 +323,7 @@ export class LeuInput extends LeuElement {
|
|
|
317
323
|
const validationMessages = this.getValidationMessages()
|
|
318
324
|
let errorMessages = this._validity
|
|
319
325
|
? Object.entries(validationMessages)
|
|
320
|
-
.filter(([
|
|
326
|
+
.filter(([prop]) => this._validity[prop])
|
|
321
327
|
.map(([_, message]) => message)
|
|
322
328
|
: []
|
|
323
329
|
|
|
@@ -337,11 +343,8 @@ export class LeuInput extends LeuElement {
|
|
|
337
343
|
/**
|
|
338
344
|
* Determines the content that is displayed after the input element.
|
|
339
345
|
* This can be either an icon, a clear button or an error indicator icon.
|
|
340
|
-
*
|
|
341
|
-
* @private
|
|
342
|
-
* @returns {import("lit").TemplateResult | nothing}
|
|
343
346
|
*/
|
|
344
|
-
renderAfterContent() {
|
|
347
|
+
protected renderAfterContent() {
|
|
345
348
|
if (this.isInvalid()) {
|
|
346
349
|
return html`<div class="error-icon">
|
|
347
350
|
<leu-icon name="caution"></leu-icon>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { html, PropertyValues } from "lit"
|
|
2
|
+
import { property } from "lit/decorators.js"
|
|
2
3
|
|
|
3
4
|
import { LeuElement } from "../../lib/LeuElement.js"
|
|
4
5
|
|
|
@@ -22,18 +23,8 @@ export class LeuMenu extends LeuElement {
|
|
|
22
23
|
delegatesFocus: true,
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
super()
|
|
31
|
-
|
|
32
|
-
/** @type {SelectsType} */
|
|
33
|
-
this.selects = "none"
|
|
34
|
-
|
|
35
|
-
this.value = undefined
|
|
36
|
-
}
|
|
26
|
+
@property({ type: String, reflect: true })
|
|
27
|
+
selects: "single" | "multiple" | "none" = "none"
|
|
37
28
|
|
|
38
29
|
connectedCallback() {
|
|
39
30
|
super.connectedCallback()
|