@statistikzh/leu 0.0.2

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 (141) hide show
  1. package/.editorconfig +29 -0
  2. package/.eslintrc.json +27 -0
  3. package/.github/workflows/publish.yml +19 -0
  4. package/.github/workflows/release-please.yml +19 -0
  5. package/.github/workflows/test.yml +38 -0
  6. package/.husky/commit-msg +4 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.prettierignore +1 -0
  9. package/.storybook/main.js +11 -0
  10. package/.storybook/preview-head.html +5 -0
  11. package/.storybook/preview.js +23 -0
  12. package/CHANGELOG.md +63 -0
  13. package/CODE_OF_CONDUCT.md +128 -0
  14. package/CONTRIBUTING.md +31 -0
  15. package/LICENSE +21 -0
  16. package/README.md +170 -0
  17. package/commitlint.config.cjs +1 -0
  18. package/dist/Button-83c6df93.js +403 -0
  19. package/dist/Checkbox.js +144 -0
  20. package/dist/CheckboxGroup.js +82 -0
  21. package/dist/Chip-60af1402.js +162 -0
  22. package/dist/ChipGroup.js +79 -0
  23. package/dist/ChipLink.js +46 -0
  24. package/dist/ChipRemovable.js +43 -0
  25. package/dist/ChipSelectable.js +92 -0
  26. package/dist/Input.js +686 -0
  27. package/dist/Radio.js +156 -0
  28. package/dist/RadioGroup.js +194 -0
  29. package/dist/Select.js +859 -0
  30. package/dist/Table-72d305d7.js +506 -0
  31. package/dist/Table.js +8 -0
  32. package/dist/defineElement-47d4f665.js +15 -0
  33. package/dist/icon-b68c7e1e.js +202 -0
  34. package/dist/index.js +21 -0
  35. package/dist/leu-checkbox-group.js +6 -0
  36. package/dist/leu-checkbox.js +6 -0
  37. package/dist/leu-chip-group.js +5 -0
  38. package/dist/leu-chip-link.js +6 -0
  39. package/dist/leu-chip-removable.js +7 -0
  40. package/dist/leu-chip-selectable.js +6 -0
  41. package/dist/leu-input.js +9 -0
  42. package/dist/leu-radio-group.js +6 -0
  43. package/dist/leu-radio.js +5 -0
  44. package/dist/leu-select.js +12 -0
  45. package/dist/leu-table.js +10 -0
  46. package/dist/theme.css +51 -0
  47. package/index.js +10 -0
  48. package/package.json +85 -0
  49. package/postcss.config.cjs +14 -0
  50. package/rollup.config.js +54 -0
  51. package/scripts/generate-component/generate.js +167 -0
  52. package/scripts/generate-component/templates/[Name].js +33 -0
  53. package/scripts/generate-component/templates/[name].css +11 -0
  54. package/scripts/generate-component/templates/[namespace]-[name].js +3 -0
  55. package/scripts/generate-component/templates/stories/[name].stories.js +13 -0
  56. package/scripts/generate-component/templates/test/[name].test.js +22 -0
  57. package/src/components/button/Button.js +150 -0
  58. package/src/components/button/button.css +232 -0
  59. package/src/components/button/leu-button.js +3 -0
  60. package/src/components/button/stories/button.stories.js +333 -0
  61. package/src/components/button/test/button.test.js +22 -0
  62. package/src/components/button-group/ButtonGroup.js +63 -0
  63. package/src/components/button-group/button-group.css +10 -0
  64. package/src/components/button-group/leu-button-group.js +3 -0
  65. package/src/components/button-group/stories/button-group.stories.js +41 -0
  66. package/src/components/button-group/test/button-group.test.js +22 -0
  67. package/src/components/checkbox/Checkbox.js +142 -0
  68. package/src/components/checkbox/CheckboxGroup.js +80 -0
  69. package/src/components/checkbox/leu-checkbox-group.js +3 -0
  70. package/src/components/checkbox/leu-checkbox.js +3 -0
  71. package/src/components/checkbox/stories/checkbox-group.stories.js +52 -0
  72. package/src/components/checkbox/stories/checkbox.stories.js +43 -0
  73. package/src/components/checkbox/test/checkbox.test.js +101 -0
  74. package/src/components/chip/Chip.js +24 -0
  75. package/src/components/chip/ChipGroup.js +71 -0
  76. package/src/components/chip/ChipLink.js +45 -0
  77. package/src/components/chip/ChipRemovable.js +42 -0
  78. package/src/components/chip/ChipSelectable.js +91 -0
  79. package/src/components/chip/chip-group.css +5 -0
  80. package/src/components/chip/chip.css +130 -0
  81. package/src/components/chip/exports.js +10 -0
  82. package/src/components/chip/leu-chip-group.js +3 -0
  83. package/src/components/chip/leu-chip-link.js +3 -0
  84. package/src/components/chip/leu-chip-removable.js +3 -0
  85. package/src/components/chip/leu-chip-selectable.js +3 -0
  86. package/src/components/chip/stories/chip-group.stories.js +99 -0
  87. package/src/components/chip/stories/chip-link.stories.js +37 -0
  88. package/src/components/chip/stories/chip-removable.stories.js +28 -0
  89. package/src/components/chip/stories/chip-selectable.stories.js +46 -0
  90. package/src/components/chip/test/chip.test.js +22 -0
  91. package/src/components/dropdown/Dropdown.js +55 -0
  92. package/src/components/dropdown/dropdown.css +17 -0
  93. package/src/components/dropdown/leu-dropdown.js +3 -0
  94. package/src/components/dropdown/stories/dropdown.stories.js +25 -0
  95. package/src/components/dropdown/test/dropdown.test.js +31 -0
  96. package/src/components/icon/icon.js +201 -0
  97. package/src/components/input/Input.js +421 -0
  98. package/src/components/input/input.css +231 -0
  99. package/src/components/input/leu-input.js +3 -0
  100. package/src/components/input/stories/input.stories.js +185 -0
  101. package/src/components/input/test/input.test.js +22 -0
  102. package/src/components/menu/Menu.js +18 -0
  103. package/src/components/menu/MenuItem.js +95 -0
  104. package/src/components/menu/leu-menu-item.js +3 -0
  105. package/src/components/menu/leu-menu.js +3 -0
  106. package/src/components/menu/menu-item.css +72 -0
  107. package/src/components/menu/menu.css +14 -0
  108. package/src/components/menu/stories/menu-item.stories.js +51 -0
  109. package/src/components/menu/stories/menu.stories.js +21 -0
  110. package/src/components/menu/test/menu.test.js +22 -0
  111. package/src/components/pagination/Pagination.js +152 -0
  112. package/src/components/pagination/leu-pagination.js +3 -0
  113. package/src/components/pagination/pagination.css +49 -0
  114. package/src/components/pagination/stories/pagination.stories.js +82 -0
  115. package/src/components/pagination/test/pagination.test.js +22 -0
  116. package/src/components/radio/Radio.js +62 -0
  117. package/src/components/radio/RadioGroup.js +193 -0
  118. package/src/components/radio/leu-radio-group.js +3 -0
  119. package/src/components/radio/leu-radio.js +3 -0
  120. package/src/components/radio/radio.css +76 -0
  121. package/src/components/radio/stories/radio-group.stories.js +49 -0
  122. package/src/components/radio/stories/radio.stories.js +48 -0
  123. package/src/components/radio/test/radio.test.js +38 -0
  124. package/src/components/select/Select.js +350 -0
  125. package/src/components/select/leu-select.js +3 -0
  126. package/src/components/select/select.css +215 -0
  127. package/src/components/select/stories/select.stories.js +302 -0
  128. package/src/components/select/test/select.test.js +29 -0
  129. package/src/components/table/Table.js +301 -0
  130. package/src/components/table/leu-table.js +3 -0
  131. package/src/components/table/stories/table.stories.js +116 -0
  132. package/src/components/table/test/table.test.js +36 -0
  133. package/src/lib/defineElement.js +13 -0
  134. package/src/lib/hasSlotController.js +85 -0
  135. package/src/styles/custom-media.css +5 -0
  136. package/src/styles/custom-properties.css +51 -0
  137. package/src/styles/theme.css +1 -0
  138. package/stat_zh.png +0 -0
  139. package/stylelint.config.mjs +21 -0
  140. package/web-dev-server-storybook.config.mjs +19 -0
  141. package/web-test-runner.config.mjs +49 -0
@@ -0,0 +1,421 @@
1
+ import { html, LitElement, nothing } from "lit"
2
+ import { classMap } from "lit/directives/class-map.js"
3
+ import { ifDefined } from "lit/directives/if-defined.js"
4
+ import { createRef, ref } from "lit/directives/ref.js"
5
+
6
+ import { Icon } from "../icon/icon.js"
7
+ import { defineElement } from "../../lib/defineElement.js"
8
+
9
+ import styles from "./input.css"
10
+
11
+ export const SIZE_TYPES = {
12
+ SMALL: "small",
13
+ REGULAR: "regular",
14
+ }
15
+
16
+ /**
17
+ * TODO:
18
+ * - Add section to docs about how to mark up suffix and prefix for screenreaders
19
+ * - Handle validation
20
+ * - Infotext attribute or slot?
21
+ */
22
+
23
+ const VALIDATION_MESSAGES = {
24
+ badInput: "Bitte überprüfen Sie das Format.",
25
+ patternMismatch: "Bitte überprüfen Sie das Format.",
26
+ rangeOverflow: (max) => `Der Wert darf nicht grösser als ${max} sein.`,
27
+ rangeUnderflow: (min) => `Der Wert darf nicht kleiner als ${min} sein.`,
28
+ stepMismatch: "Bitte überprüfen Sie das Format.",
29
+ tooLong: (maxlength) =>
30
+ `Die Eingabe muss kürzer als ${maxlength} Zeichen sein.`,
31
+ tooShort: (minlength) =>
32
+ `Die Eingabe muss länger als ${minlength} Zeichen sein.`,
33
+ typeMismatch: "Bitte überprüfen Sie das Format.",
34
+ valueMissing: "Bitte füllen Sie das Feld aus.",
35
+ }
36
+
37
+ /**
38
+ * A text input element.
39
+ *
40
+ * @prop {boolean} disabled - Disables the input element.
41
+ * @prop {boolean} required - Marks the input element as required.
42
+ * @prop {boolean} clearable - Adds a button to clear the input element.
43
+ * @prop {string} value - The value of the input element.
44
+ * @prop {string} name - The name of the input element.
45
+ * @prop {string} label - The label of the input element.
46
+ * @prop {string} error - A custom error that is completely independent of the validity state. Useful for displaying server side errors.
47
+ * @prop {string} size - The size of the input element.
48
+ * @prop {string} icon - The icon that is displayed at the end of the input element.
49
+ * @prop {string} prefix - A prefix that relates to the value of the input (e.g. CHF).
50
+ * @prop {string} suffix - A suffix that relates to the value of the input (e.g. mm).
51
+ * @prop {string} pattern - A regular expression that the value is checked against.
52
+ * @prop {string} type - The type of the input element.
53
+ * @prop {string} min - The minimum value of the input element.
54
+ * @prop {string} max - The maximum value of the input element.
55
+ * @prop {string} minlength - The minimum length of the input element.
56
+ * @prop {string} maxlength - The maximum length of the input element.
57
+ * @prop {object} validationMessages - Custom validation messages. The key is the name of the validity state and the value is the message.
58
+ * @prop {boolean} novalidate - Disables the browser's validation.
59
+ *
60
+ * @fires {CustomEvent} input - Dispatched when the value of the input element changes.
61
+ * @fires {CustomEvent} change - Dispatched when the value of the input element changes and the input element loses focus.
62
+ *
63
+ * @tagname leu-input
64
+ */
65
+ export class LeuInput extends LitElement {
66
+ static styles = styles
67
+
68
+ static properties = {
69
+ disabled: { type: Boolean, reflect: true },
70
+ required: { type: Boolean, reflect: true },
71
+ clearable: { type: Boolean, reflect: true },
72
+
73
+ value: { type: String },
74
+ name: { type: String },
75
+ error: { type: String },
76
+
77
+ label: { type: String },
78
+ prefix: { type: String },
79
+ suffix: { type: String },
80
+ size: { type: String },
81
+ icon: { type: String },
82
+
83
+ /* Validation attributes */
84
+ pattern: { type: String },
85
+ type: { type: String },
86
+ min: { type: Number },
87
+ max: { type: Number },
88
+ maxlength: { type: Number },
89
+ minlength: { type: Number },
90
+ validationMessages: { type: Object },
91
+ novalidate: { type: Boolean },
92
+
93
+ /** @type {ValidityState} */
94
+ _validity: { state: true },
95
+ }
96
+
97
+ static resolveErrorMessage(message, refernceValue) {
98
+ if (typeof message === "function") {
99
+ return message(refernceValue)
100
+ }
101
+
102
+ return message
103
+ }
104
+
105
+ constructor() {
106
+ super()
107
+
108
+ this.disabled = false
109
+ this.required = false
110
+ this.clearable = false
111
+
112
+ this.value = ""
113
+ this.name = ""
114
+ this.error = ""
115
+
116
+ this.label = ""
117
+ this.prefix = ""
118
+ this.suffix = ""
119
+
120
+ /** @type {keyof typeof SIZE_TYPES} */
121
+ this.size = SIZE_TYPES.REGULAR
122
+
123
+ this.icon = ""
124
+
125
+ this.type = "text"
126
+ this._validity = null
127
+ this.validationMessages = {}
128
+ this.novalidate = false
129
+
130
+ /** @internal */
131
+ this._identifier = ""
132
+
133
+ /** @internal */
134
+ this._clearIcon = Icon("clear")
135
+
136
+ /**
137
+ * @internal
138
+ * @type {import("lit/directives/ref.js").Ref<HTMLInputElement>}
139
+ */
140
+ this._inputRef = createRef()
141
+ }
142
+
143
+ /**
144
+ * Method for handling the click event of the wrapper element.
145
+ * Redirect every click on the wrapper to the input element.
146
+ * This is only necessary for click events because the wrapper element
147
+ * looks like the input element. But the actual input field does not
148
+ * completely fill the wrapper element. Keyboard events don't need to be
149
+ * handled because the actual input element is focusable.
150
+ * @private
151
+ * @param {MouseEvent|PointerEvent} event
152
+ * @returns {void}
153
+ */
154
+ handleWrapperClick(event) {
155
+ if (event.target === event.currentTarget) {
156
+ this._inputRef.value.focus()
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Method for handling the blur event of the input element.
162
+ * Checks validity of the input element and sets the validity state.
163
+ * @private
164
+ * @param {FocusEvent} event
165
+ * @returns {void}
166
+ */
167
+ handleBlur(event) {
168
+ this._validity = null
169
+
170
+ if (!this.novalidate) {
171
+ event.target.checkValidity()
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Method for handling the invalid event of the input element.
177
+ * Sets the validity state.
178
+ * @private
179
+ * @param {Event} event
180
+ * @returns {void}
181
+ */
182
+ handleInvalid(event) {
183
+ this._validity = event.target.validity
184
+ }
185
+
186
+ /**
187
+ * Method for handling the change event of the input element.
188
+ * Sets the value property and dispatches a change event so that
189
+ * the event can be handled outside the shadow DOM.
190
+ * @private
191
+ * @param {Event} event
192
+ * @fires {CustomEvent} change
193
+ * @returns {void}
194
+ */
195
+ handleChange(event) {
196
+ this.value = event.target.value
197
+
198
+ const customEvent = new CustomEvent(event.type, event)
199
+ this.dispatchEvent(customEvent)
200
+ }
201
+
202
+ /**
203
+ * Method for handling the input event of the input element.
204
+ * Sets the value property and dispatches an input event so that
205
+ * the event can be handled outside the shadow DOM.
206
+ * @private
207
+ * @param {Event} event
208
+ * @returns {void}
209
+ */
210
+ handleInput(event) {
211
+ this.value = event.target.value
212
+ }
213
+
214
+ /**
215
+ * Method for clearing the input element.
216
+ * Sets the value property to an empty string and dispatches
217
+ * an input and a change event.
218
+ * @private
219
+ * @returns {void}
220
+ * @fires {CustomEvent} input
221
+ * @fires {CustomEvent} change
222
+ */
223
+ clear() {
224
+ this.value = ""
225
+
226
+ this.dispatchEvent(
227
+ new CustomEvent("input", { bubbles: true, composed: true })
228
+ )
229
+ this.dispatchEvent(
230
+ new CustomEvent("change", { bubbles: true, composed: true })
231
+ )
232
+ }
233
+
234
+ /**
235
+ * Method for getting the id of the input element.
236
+ * If the id attribute is set, the value of the id attribute is returned.
237
+ * Otherwise a random id is generated and returned.
238
+ *
239
+ * @private
240
+ * @returns {string} id
241
+ */
242
+ getId() {
243
+ const id = this.getAttribute("id")
244
+
245
+ if (id !== null && id !== "") {
246
+ return id
247
+ }
248
+
249
+ if (this._identifier !== "") {
250
+ return this._identifier
251
+ }
252
+
253
+ this._identifier = crypto.randomUUID()
254
+ return this._identifier
255
+ }
256
+
257
+ /**
258
+ * Merge custom and default validation messages.
259
+ * A validation message can be a function or a string.
260
+ * If it s a function, the function is called with the corresponding
261
+ * attribute value as argument.
262
+ * e.g.
263
+ * `tooLong(this.maxlength)`
264
+ * This way the framework user can create reasonable validation messages
265
+ *
266
+ * @returns {Object} validationMessages
267
+ */
268
+ getValidationMessages() {
269
+ const validationMessages = {
270
+ ...VALIDATION_MESSAGES,
271
+ ...this.validationMessages,
272
+ }
273
+
274
+ const { tooLong, tooShort, rangeOverflow, rangeUnderflow } =
275
+ validationMessages
276
+
277
+ validationMessages.tooLong = LeuInput.resolveErrorMessage(
278
+ tooLong,
279
+ this.maxlength
280
+ )
281
+ validationMessages.tooShort = LeuInput.resolveErrorMessage(
282
+ tooShort,
283
+ this.minlength
284
+ )
285
+ validationMessages.rangeOverflow = LeuInput.resolveErrorMessage(
286
+ rangeOverflow,
287
+ this.max
288
+ )
289
+ validationMessages.rangeUnderflow = LeuInput.resolveErrorMessage(
290
+ rangeUnderflow,
291
+ this.min
292
+ )
293
+
294
+ return validationMessages
295
+ }
296
+
297
+ /**
298
+ * Creates an error list with an item for the given validity state.
299
+ * @param {ValidityState} validityState
300
+ * @param {Object} validationMessages
301
+ * @param {String} idRef
302
+ * @returns
303
+ */
304
+ renderErrorMessages() {
305
+ if (!this.isInvalid()) {
306
+ return nothing
307
+ }
308
+
309
+ const validationMessages = this.getValidationMessages()
310
+ let errorMessages = this._validity
311
+ ? Object.entries(validationMessages)
312
+ .filter(([property]) => this._validity[property])
313
+ .map(([_, message]) => message)
314
+ : []
315
+
316
+ if (this.error !== "") {
317
+ errorMessages = [this.error, errorMessages]
318
+ }
319
+
320
+ return html`
321
+ <ul class="error" aria-errormessage=${`input-${this.getId()}`}>
322
+ ${errorMessages.map(
323
+ (message) => html`<li class="error-message">${message}</li>`
324
+ )}
325
+ </ul>
326
+ `
327
+ }
328
+
329
+ /**
330
+ * Determines the content that is displayed after the input element.
331
+ * This can be either an icon, a clear button or an error indicator icon.
332
+ *
333
+ * @private
334
+ * @returns {TemplateResult}
335
+ */
336
+ renderAfterContent() {
337
+ if (this.isInvalid()) {
338
+ return html`<div class="error-icon">${Icon("caution")}</div>`
339
+ }
340
+
341
+ if (this.clearable && this.value !== "") {
342
+ return html`<button
343
+ class="clear-button"
344
+ @click=${this.clear}
345
+ aria-label="Eingabefeld zurücksetzen"
346
+ ?disabled=${this.disabled}
347
+ >
348
+ ${this._clearIcon}
349
+ </button>`
350
+ }
351
+
352
+ if (this.icon !== "") {
353
+ return html`<div class="icon">${Icon(this.icon)}</div>`
354
+ }
355
+
356
+ return nothing
357
+ }
358
+
359
+ isInvalid() {
360
+ if (this.error !== "") {
361
+ return true
362
+ }
363
+
364
+ return this._validity === null || this.novalidate
365
+ ? false
366
+ : !this._validity.valid
367
+ }
368
+
369
+ render() {
370
+ const isInvalid = this.isInvalid()
371
+
372
+ const inputWrapperClasses = {
373
+ "input-wrapper": true,
374
+ "input-wrapper--empty": this.value === "",
375
+ "input-wrapper--invalid": isInvalid,
376
+ }
377
+
378
+ /* See the description of the handleWrapperClick method on why this rule is disabled */
379
+ /* eslint-disable lit-a11y/click-events-have-key-events */
380
+ return html`
381
+ <div
382
+ @click=${this.handleWrapperClick}
383
+ class=${classMap(inputWrapperClasses)}
384
+ >
385
+ <input
386
+ class="input"
387
+ id="input-${this.getId()}"
388
+ type=${this.type}
389
+ name=${this.name}
390
+ @change=${this.handleChange}
391
+ @blur=${this.handleBlur}
392
+ @input=${this.handleInput}
393
+ @invalid=${this.handleInvalid}
394
+ ?disabled=${this.disabled}
395
+ ?required=${this.required}
396
+ pattern=${ifDefined(this.pattern)}
397
+ min=${ifDefined(this.min)}
398
+ max=${ifDefined(this.max)}
399
+ maxlength=${ifDefined(this.maxlength)}
400
+ minlength=${ifDefined(this.minlength)}
401
+ .value=${this.value}
402
+ ref=${ref(this._inputRef)}
403
+ aria-invalid=${isInvalid}
404
+ />
405
+ <label for="input-${this.getId()}" class="label"><slot></slot></label>
406
+ ${this.prefix !== ""
407
+ ? html`<div class="prefix" .aria-hidden=${true}>${this.prefix}</div>`
408
+ : nothing}
409
+ ${this.suffix !== ""
410
+ ? html`<div class="suffix" .aria-hidden=${true}>${this.suffix}</div>`
411
+ : nothing}
412
+ ${this.renderAfterContent()}
413
+ </div>
414
+ ${this.renderErrorMessages()}
415
+ `
416
+ }
417
+ }
418
+
419
+ export function defineInputElements() {
420
+ defineElement("input", LeuInput)
421
+ }
@@ -0,0 +1,231 @@
1
+ :host,
2
+ :host * {
3
+ box-sizing: border-box;
4
+ }
5
+
6
+ :host {
7
+ --input-color: var(--leu-color-black-100);
8
+ --input-color-disabled: var(--leu-color-black-20);
9
+ --input-color-invalid: var(--leu-color-func-red);
10
+ --input-color-focus: var(--leu-color-func-cyan);
11
+ --input-border-width: 2px;
12
+
13
+ --input-label-color: var(--leu-color-black-100);
14
+ --input-label-color-disabled: var(--input-color-disabled);
15
+ --input-label-color-empty: var(--leu-color-black-60);
16
+
17
+ --input-affix-color: var(--leu-color-black-60);
18
+ --input-affix-color-disabled: var(--input-color-disabled);
19
+
20
+ --input-border-color: var(--leu-color-black-40);
21
+ --input-border-color-focus: var(--input-color-focus);
22
+ --input-border-color-disabled: var(--leu-color-black-20);
23
+ --input-border-color-invalid: var(--input-color-invalid);
24
+
25
+ --input-error-color: var(--leu-color-black-0);
26
+
27
+ --input-clear-color: var(--leu-color-black-60);
28
+
29
+ --input-font-regular: var(--leu-font-regular);
30
+ --input-font-black: var(--leu-font-black);
31
+
32
+ display: block;
33
+ font-family: var(--input-font-regular);
34
+ }
35
+
36
+ :host([disabled]) {
37
+ --input-color: var(--input-color-disabled);
38
+ --input-border-color: var(--input-border-color-disabled);
39
+ --input-label-color: var(--input-color-disabled);
40
+ --input-color-focus: var(--input-color-disabled);
41
+ --input-affix-color: var(--input-color-disabled);
42
+ }
43
+
44
+ :host(:focus-within) {
45
+ outline: 2px solid var(--input-color-focus);
46
+ outline-offset: 2px;
47
+ }
48
+
49
+ .input-wrapper {
50
+ position: relative;
51
+ display: flex;
52
+ gap: 0.5rem;
53
+ padding-inline: 0.875rem;
54
+
55
+ border: var(--input-border-width) solid var(--input-border-color);
56
+ border-radius: 2px;
57
+
58
+ line-height: 1;
59
+ }
60
+
61
+ .input-wrapper:focus-within,
62
+ .input-wrapper:hover {
63
+ --input-border-color: var(--input-border-color-focus);
64
+ }
65
+
66
+ .input-wrapper--invalid,
67
+ .input-wrapper--invalid:is(:hover, :focus-within) {
68
+ --input-border-color: var(--input-border-color-invalid);
69
+ border-radius: 2px 2px 0 0;
70
+ }
71
+
72
+ .input {
73
+ appearance: none;
74
+ display: block;
75
+ width: 100%;
76
+
77
+ font-size: 1rem;
78
+ line-height: 1;
79
+ color: var(--input-color);
80
+
81
+ border: 0;
82
+
83
+ padding-block: 2rem 1rem;
84
+ }
85
+
86
+ .input:focus-visible {
87
+ outline: none;
88
+ }
89
+
90
+ :host([size="small"]) .input {
91
+ padding-block: 0.75rem;
92
+ }
93
+
94
+ .prefix,
95
+ .suffix {
96
+ padding-block: 2rem 1rem;
97
+
98
+ font-size: 1rem;
99
+ line-height: 1.5;
100
+ color: var(--input-affix-color);
101
+ pointer-events: none;
102
+ }
103
+
104
+ .prefix {
105
+ order: -1;
106
+ }
107
+
108
+ /* Label styles for when the input has focus OR contains a value */
109
+ .label {
110
+ position: absolute;
111
+ left: 1rem;
112
+
113
+ line-height: 1.5;
114
+ color: var(--input-label-color);
115
+ }
116
+
117
+ /* is size regular AND (has focus OR contains a value) */
118
+ :host(:not([size])) .label,
119
+ :host([size="regular"]) .label {
120
+ top: calc(0.75rem - var(--input-border-width));
121
+
122
+ font-size: 0.75rem;
123
+ font-family: var(--input-font-black);
124
+
125
+ transition: 0.15s ease-out;
126
+ transition-property: font-size, top;
127
+ }
128
+
129
+ /* is size small AND (has focus OR contains a value) */
130
+ :host([size="small"]) .label {
131
+ opacity: 0;
132
+ visibility: hidden;
133
+
134
+ font-size: 1rem;
135
+ }
136
+
137
+ :host([required]) .label::after {
138
+ content: "*";
139
+ }
140
+
141
+ /* is empty AND has no focus */
142
+ :host(:not(:focus-within)) .input-wrapper--empty .label {
143
+ font-family: var(--input-font-regular);
144
+ font-size: 1rem;
145
+ top: calc(1.5rem - var(--input-border-width));
146
+ }
147
+
148
+ /* is not disabled AND has focus AND is empty */
149
+ :host(:not([disabled], :focus-within)) .input-wrapper--empty .label {
150
+ --input-label-color: var(--input-label-color-empty);
151
+ }
152
+
153
+ /* is size small AND has no focus AND is empty */
154
+ :host(:not(:focus-within)[size="small"]) .input-wrapper--empty .label {
155
+ top: calc(0.75rem - var(--input-border-width));
156
+ opacity: 1;
157
+ visibility: visible;
158
+ }
159
+
160
+ /* The label has to behave a bit different when the input has a suffix or a prefix */
161
+ :host(:is([suffix], [prefix]))
162
+ .input-wrapper--empty
163
+ .input:not(:focus)
164
+ + .label {
165
+ top: calc(0.75rem - var(--input-border-width));
166
+
167
+ font-family: var(--input-font-black);
168
+ font-size: 0.75rem;
169
+ }
170
+
171
+ .error {
172
+ list-style: none;
173
+ padding: 0.0625rem 1rem 0.1875rem;
174
+ margin: 0;
175
+
176
+ color: var(--input-error-color);
177
+ font-size: 0.75rem;
178
+ line-height: 1.5;
179
+
180
+ border: 2px solid var(--input-color-invalid);
181
+ border-radius: 0 0 2px 2px;
182
+
183
+ background-color: var(--input-color-invalid);
184
+ }
185
+
186
+ .clear-button {
187
+ --_length: 1.5rem;
188
+
189
+ align-self: center;
190
+
191
+ width: var(--_length);
192
+ height: var(--_length);
193
+ padding: 0;
194
+
195
+ cursor: pointer;
196
+
197
+ background: none;
198
+ color: var(--input-clear-color);
199
+ border: none;
200
+
201
+ /* border-radius is only defined for a nice focus outline */
202
+ border-radius: 2px;
203
+ }
204
+
205
+ .clear-button:focus-visible {
206
+ outline: 2px solid var(--input-color-focus);
207
+ outline-offset: 2px;
208
+ }
209
+
210
+ .clear-button:disabled {
211
+ cursor: default;
212
+ color: var(--input-color-disabled);
213
+ }
214
+
215
+ .icon {
216
+ align-self: center;
217
+ color: var(--input-color);
218
+ }
219
+
220
+ :host(:not([disabled], :focus-within)) .input-wrapper--empty .icon {
221
+ color: var(--input-label-color-empty);
222
+ }
223
+
224
+ .error-icon {
225
+ align-self: center;
226
+ color: var(--input-color-invalid);
227
+ }
228
+
229
+ :is(.icon, .error-icon) svg {
230
+ display: block;
231
+ }
@@ -0,0 +1,3 @@
1
+ import { defineInputElements } from "./Input.js"
2
+
3
+ defineInputElements()