@felleslosninger/minid-elements 0.0.138 → 0.1.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/README.md +69 -4
- package/dist/components/alert.component.d.ts +6 -4
- package/dist/components/alert.component.d.ts.map +1 -1
- package/dist/components/alert.js +33 -61
- package/dist/components/alert.js.map +1 -1
- package/dist/components/button.component.d.ts +1 -1
- package/dist/components/checkbox.component.d.ts +1 -2
- package/dist/components/checkbox.component.d.ts.map +1 -1
- package/dist/components/checkbox.js +25 -55
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/code-input-old.component.d.ts +1 -1
- package/dist/components/code-input-old.js +1 -1
- package/dist/components/code-input.component.d.ts +2 -1
- package/dist/components/code-input.component.d.ts.map +1 -1
- package/dist/components/code-input.js +247 -98
- package/dist/components/code-input.js.map +1 -1
- package/dist/components/combobox.component.d.ts +1 -1
- package/dist/components/countdown.component.d.ts +1 -1
- package/dist/components/dialog.component.d.ts +1 -1
- package/dist/components/dropdown.component.d.ts +1 -1
- package/dist/components/heading.component.d.ts +1 -1
- package/dist/components/heading.component.d.ts.map +1 -1
- package/dist/components/heading.js +1 -11
- package/dist/components/heading.js.map +1 -1
- package/dist/components/helptext.component.d.ts +1 -1
- package/dist/components/icon/icon.component.d.ts +1 -0
- package/dist/components/icon/icon.component.d.ts.map +1 -1
- package/dist/components/icon/icon.js +13 -9
- package/dist/components/icon/icon.js.map +1 -1
- package/dist/components/label.component.d.ts +1 -1
- package/dist/components/label.component.d.ts.map +1 -1
- package/dist/components/label.js +3 -12
- package/dist/components/label.js.map +1 -1
- package/dist/components/link.component.d.ts +1 -1
- package/dist/components/link.js +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/menu-item.component.d.ts +1 -1
- package/dist/components/menu.component.d.ts +1 -1
- package/dist/components/paragraph.component.d.ts +1 -1
- package/dist/components/paragraph.component.d.ts.map +1 -1
- package/dist/components/paragraph.js +2 -8
- package/dist/components/paragraph.js.map +1 -1
- package/dist/components/phone-input.component.d.ts +27 -4
- package/dist/components/phone-input.component.d.ts.map +1 -1
- package/dist/components/phone-input.js +91 -22
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popup.component.d.ts +1 -1
- package/dist/components/qr-code.component.d.ts +1 -1
- package/dist/components/radio-button.component.d.ts +1 -1
- package/dist/components/radio-group.component.d.ts +1 -1
- package/dist/components/radio.component.d.ts +1 -1
- package/dist/components/radio.component.d.ts.map +1 -1
- package/dist/components/radio.js +12 -16
- package/dist/components/radio.js.map +1 -1
- package/dist/components/search.component.d.ts +11 -4
- package/dist/components/search.component.d.ts.map +1 -1
- package/dist/components/search.js +75 -31
- package/dist/components/search.js.map +1 -1
- package/dist/components/spinner.component.d.ts +1 -1
- package/dist/components/step-indicator.component.d.ts +1 -1
- package/dist/components/textfield.component.d.ts +2 -2
- package/dist/components/textfield.component.d.ts.map +1 -1
- package/dist/components/textfield.js +75 -86
- package/dist/components/textfield.js.map +1 -1
- package/dist/components/tooltip.component.d.ts +1 -1
- package/dist/components/validation-message.component.d.ts +1 -1
- package/dist/controllers/lang.controller.d.ts +14 -0
- package/dist/controllers/lang.controller.d.ts.map +1 -0
- package/dist/designsystemet-tailwind.css +355 -297
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lang.controller-P4W-9ipy.js +32 -0
- package/dist/lang.controller-P4W-9ipy.js.map +1 -0
- package/dist/styles.css +5 -0
- package/dist/theme.css +1155 -0
- package/dist/utilities/lang.d.ts +6 -0
- package/dist/utilities/lang.d.ts.map +1 -0
- package/dist/utilities/lang.js +18 -0
- package/dist/utilities/lang.js.map +1 -0
- package/dist/utilities/translations.d.ts +42 -0
- package/dist/utilities/translations.d.ts.map +1 -0
- package/dist/utilities/translations.js +45 -0
- package/dist/utilities/translations.js.map +1 -0
- package/package.json +34 -16
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { css, LitElement, nothing, html } from "lit";
|
|
2
2
|
import { query, property, state, customElement } from "lit/decorators.js";
|
|
3
3
|
import { classMap } from "lit/directives/class-map.js";
|
|
4
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
4
5
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
5
|
-
import { AsYouType, getCountryCallingCode, formatIncompletePhoneNumber, parsePhoneNumberCharacter } from "libphonenumber-js";
|
|
6
|
+
import { AsYouType, getCountryCallingCode, formatIncompletePhoneNumber, parsePhoneNumberCharacter, parsePhoneNumberFromString } from "libphonenumber-js";
|
|
6
7
|
import "./icon/icon.js";
|
|
7
8
|
import { templateParser, templateFormatter, onKeyDown, onChange } from "input-format";
|
|
8
9
|
import { watch } from "../internal/watch.js";
|
|
9
10
|
import { HasSlotController } from "../internal/slot.js";
|
|
10
11
|
import { FormControlMixin } from "../mixins/form-control.mixin.js";
|
|
11
12
|
import { requiredValidator } from "../mixins/validators.js";
|
|
13
|
+
import { L as LangController } from "../lang.controller-P4W-9ipy.js";
|
|
14
|
+
import { getLang } from "../utilities/lang.js";
|
|
15
|
+
import { getTranslations } from "../utilities/translations.js";
|
|
12
16
|
var __defProp = Object.defineProperty;
|
|
13
17
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
18
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -26,11 +30,13 @@ const styles = [
|
|
|
26
30
|
}
|
|
27
31
|
`
|
|
28
32
|
];
|
|
33
|
+
let nextUniqueId = 0;
|
|
29
34
|
let MinidPhoneInput = class extends FormControlMixin(
|
|
30
35
|
styled(LitElement, styles)
|
|
31
36
|
) {
|
|
32
37
|
constructor() {
|
|
33
|
-
super(
|
|
38
|
+
super();
|
|
39
|
+
this.labelId = `mid-code-input-label-${nextUniqueId++}`;
|
|
34
40
|
this.formatter = new AsYouType();
|
|
35
41
|
this.skipCountryUpdate = false;
|
|
36
42
|
this.currentEvent = new Event("");
|
|
@@ -41,7 +47,9 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
41
47
|
this.countrycode = "";
|
|
42
48
|
this.label = "";
|
|
43
49
|
this.hidelabel = false;
|
|
50
|
+
this.autocomplete = "tel";
|
|
44
51
|
this.invalid = false;
|
|
52
|
+
this.invalidmessage = "";
|
|
45
53
|
this.required = false;
|
|
46
54
|
this.readonly = false;
|
|
47
55
|
this.hasFocus = false;
|
|
@@ -59,10 +67,23 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
59
67
|
}
|
|
60
68
|
this.dispatchEvent(this.currentEvent);
|
|
61
69
|
};
|
|
70
|
+
new LangController(this);
|
|
71
|
+
nextUniqueId++;
|
|
72
|
+
this.inputId = `mid-phone-input-input-${nextUniqueId}`;
|
|
73
|
+
this.validationId = `mid-phone-input-validation-${nextUniqueId}`;
|
|
62
74
|
}
|
|
63
75
|
static get formControlValidators() {
|
|
64
76
|
return [requiredValidator];
|
|
65
77
|
}
|
|
78
|
+
get validationTarget() {
|
|
79
|
+
return this.input;
|
|
80
|
+
}
|
|
81
|
+
validationMessageCallback(message) {
|
|
82
|
+
this.invalidmessage = message;
|
|
83
|
+
}
|
|
84
|
+
resetFormControl() {
|
|
85
|
+
this.invalidmessage = "";
|
|
86
|
+
}
|
|
66
87
|
handleCountryClick() {
|
|
67
88
|
this.dispatchEvent(
|
|
68
89
|
new CustomEvent("mid-country-click", { composed: true, bubbles: true })
|
|
@@ -136,11 +157,32 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
136
157
|
});
|
|
137
158
|
this.handleNewValue(event);
|
|
138
159
|
}
|
|
160
|
+
getCountryCodePrefix() {
|
|
161
|
+
if (this.country) {
|
|
162
|
+
return `+${getCountryCallingCode(this.country)}`;
|
|
163
|
+
}
|
|
164
|
+
return this.countrycode;
|
|
165
|
+
}
|
|
166
|
+
applyAutocompletePrefix(value) {
|
|
167
|
+
if (value.startsWith("+")) {
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
const countryCodePrefix = this.getCountryCodePrefix();
|
|
171
|
+
if (this.autocomplete === "tel-national" && countryCodePrefix) {
|
|
172
|
+
return `${countryCodePrefix}${value}`;
|
|
173
|
+
}
|
|
174
|
+
if (this.autocomplete === "tel" && this.country) {
|
|
175
|
+
const phoneNumber = parsePhoneNumberFromString(value, this.country);
|
|
176
|
+
const valueWithPlus = `+${value.replaceAll(/\D/g, "")}`;
|
|
177
|
+
if (phoneNumber?.isValid() && phoneNumber.number !== valueWithPlus) {
|
|
178
|
+
return phoneNumber.number;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return `+${value}`;
|
|
182
|
+
}
|
|
139
183
|
handleNewValue(event) {
|
|
140
184
|
this.formatter.reset();
|
|
141
|
-
|
|
142
|
-
this.input.value = `+${this.input.value}`;
|
|
143
|
-
}
|
|
185
|
+
this.input.value = this.applyAutocompletePrefix(this.input.value);
|
|
144
186
|
this.formatter.input(this.input.value);
|
|
145
187
|
this.currentTemplate = this.formatter.getTemplate();
|
|
146
188
|
onChange(
|
|
@@ -166,14 +208,8 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
166
208
|
}
|
|
167
209
|
return value;
|
|
168
210
|
}
|
|
169
|
-
focus() {
|
|
170
|
-
this.input.focus();
|
|
171
|
-
setTimeout(() => {
|
|
172
|
-
this.input.setSelectionRange(
|
|
173
|
-
(this.countrycode?.length ?? 0) + 1,
|
|
174
|
-
this.input.value.length
|
|
175
|
-
);
|
|
176
|
-
}, 0);
|
|
211
|
+
focus(options) {
|
|
212
|
+
this.input.focus(options);
|
|
177
213
|
}
|
|
178
214
|
handleCountryChange() {
|
|
179
215
|
if (this.skipCountryUpdate) {
|
|
@@ -193,9 +229,19 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
193
229
|
const lg = false;
|
|
194
230
|
const md = true;
|
|
195
231
|
const sm = false;
|
|
232
|
+
const lang = getLang(this);
|
|
233
|
+
const t = getTranslations(lang);
|
|
196
234
|
const hasLabelSlot = this.hasSlotControler.test("label");
|
|
197
235
|
const hasLabel = !!this.label || !!hasLabelSlot;
|
|
236
|
+
const hasError = this.invalid || !!this.invalidmessage;
|
|
237
|
+
const describedBy = this.invalidmessage ? this.validationId : void 0;
|
|
198
238
|
return html`
|
|
239
|
+
<label
|
|
240
|
+
id="${this.labelId}"
|
|
241
|
+
class="${classMap({
|
|
242
|
+
"sr-only": this.hidelabel || !hasLabel
|
|
243
|
+
})} mb-2 block items-center gap-1 font-medium"
|
|
244
|
+
>
|
|
199
245
|
<div
|
|
200
246
|
part="field"
|
|
201
247
|
class="${classMap({
|
|
@@ -205,7 +251,7 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
205
251
|
})}"
|
|
206
252
|
>
|
|
207
253
|
<label
|
|
208
|
-
for="
|
|
254
|
+
for="${this.inputId}"
|
|
209
255
|
class="${classMap({
|
|
210
256
|
"sr-only": this.hidelabel || !hasLabel
|
|
211
257
|
})} mb-2 inline-flex items-center gap-1 font-medium"
|
|
@@ -220,7 +266,7 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
220
266
|
<div part="base" class="flex h-12">
|
|
221
267
|
<button
|
|
222
268
|
part="country-button"
|
|
223
|
-
aria-label
|
|
269
|
+
aria-label=${t.openCountrySelector}
|
|
224
270
|
class="${classMap({
|
|
225
271
|
"border-neutral": !this.readonly,
|
|
226
272
|
"border-neutral-subtle": this.readonly,
|
|
@@ -246,21 +292,26 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
246
292
|
</button>
|
|
247
293
|
|
|
248
294
|
<input
|
|
249
|
-
id="
|
|
295
|
+
id="${this.inputId}"
|
|
250
296
|
class="${classMap({
|
|
251
|
-
"border-neutral": !
|
|
252
|
-
"border-danger":
|
|
297
|
+
"border-neutral": !hasError && !this.readonly,
|
|
298
|
+
"border-danger": hasError && !this.readonly,
|
|
253
299
|
"border-neutral-subtle": this.readonly,
|
|
254
300
|
"bg-neutral-surface-tinted": this.readonly,
|
|
255
301
|
"bg-neutral-surface": !this.readonly,
|
|
256
|
-
"border-2":
|
|
257
|
-
border: !
|
|
302
|
+
"border-2": hasError,
|
|
303
|
+
border: !hasError
|
|
258
304
|
})} focus-visible:focus-ring grow rounded-r px-3"
|
|
259
305
|
part="phone-number"
|
|
260
306
|
type="tel"
|
|
261
|
-
autocomplete
|
|
307
|
+
autocomplete=${this.autocomplete}
|
|
262
308
|
?readonly=${this.readonly}
|
|
263
309
|
value=${this.value}
|
|
310
|
+
aria-describedby=${ifDefined(describedBy)}
|
|
311
|
+
aria-invalid=${hasError ? "true" : "false"}
|
|
312
|
+
aria-errormessage=${ifDefined(
|
|
313
|
+
this.invalidmessage ? this.validationId : void 0
|
|
314
|
+
)}
|
|
264
315
|
@input=${this.handleInput}
|
|
265
316
|
@focus=${this.handleFocus}
|
|
266
317
|
@blur=${this.handleBlur}
|
|
@@ -268,12 +319,24 @@ let MinidPhoneInput = class extends FormControlMixin(
|
|
|
268
319
|
@change=${this.handleChange}
|
|
269
320
|
/>
|
|
270
321
|
</div>
|
|
322
|
+
<div
|
|
323
|
+
class="text-danger-subtle mt-2 flex gap-1"
|
|
324
|
+
id="${this.validationId}"
|
|
325
|
+
aria-live="polite"
|
|
326
|
+
?hidden=${!this.invalidmessage}
|
|
327
|
+
>
|
|
328
|
+
<mid-icon
|
|
329
|
+
name="xmark-octagon-fill"
|
|
330
|
+
class="mt-1 min-h-5 min-w-5"
|
|
331
|
+
></mid-icon>
|
|
332
|
+
${this.invalidmessage}
|
|
333
|
+
</div>
|
|
271
334
|
</div>
|
|
272
335
|
`;
|
|
273
336
|
}
|
|
274
337
|
};
|
|
275
338
|
__decorateClass([
|
|
276
|
-
query("
|
|
339
|
+
query("input")
|
|
277
340
|
], MinidPhoneInput.prototype, "input", 2);
|
|
278
341
|
__decorateClass([
|
|
279
342
|
property({ reflect: true })
|
|
@@ -293,9 +356,15 @@ __decorateClass([
|
|
|
293
356
|
__decorateClass([
|
|
294
357
|
property({ reflect: true })
|
|
295
358
|
], MinidPhoneInput.prototype, "country", 2);
|
|
359
|
+
__decorateClass([
|
|
360
|
+
property()
|
|
361
|
+
], MinidPhoneInput.prototype, "autocomplete", 2);
|
|
296
362
|
__decorateClass([
|
|
297
363
|
property({ type: Boolean })
|
|
298
364
|
], MinidPhoneInput.prototype, "invalid", 2);
|
|
365
|
+
__decorateClass([
|
|
366
|
+
property()
|
|
367
|
+
], MinidPhoneInput.prototype, "invalidmessage", 2);
|
|
299
368
|
__decorateClass([
|
|
300
369
|
property({ type: Boolean })
|
|
301
370
|
], MinidPhoneInput.prototype, "required", 2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone-input.js","sources":["../../src/components/phone-input.component.ts"],"sourcesContent":["import { css, html, LitElement, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styled } from '../mixins/tailwind.mixin';\nimport {\n AsYouType,\n formatIncompletePhoneNumber,\n getCountryCallingCode,\n type CountryCode,\n parsePhoneNumberCharacter,\n} from 'libphonenumber-js';\nimport './icon/icon.component';\nimport {\n onChange,\n onKeyDown,\n templateFormatter,\n templateParser,\n} from 'input-format';\nimport { watch } from '../internal/watch';\nimport { HasSlotController } from '../internal/slot';\nimport { FormControlMixin } from '../mixins/form-control.mixin';\nimport { requiredValidator } from '../mixins/validators';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-phone-input': MinidPhoneInput;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: block;\n }\n `,\n];\n\n/**\n * @event {Event} mid-country-click - Emitted when the country button is clicked\n * @event {Event} mid-change - Emitted when the value is modified by the user\n * @event {Event} mid-input - Emitted after a new user input\n * @event {Event} mid-blur - Emitted after focus is moved away from input\n * @event {Event} mid-focus - Emitted after input gains focus\n *\n * @part base - Select the container outside the country button and phone number input\n * @part field - Select the container around the label and the inputs\n * @part label - Select the label element\n * @part country-button - Select the country button\n * @part input - Select the phone number input\n */\n@customElement('mid-phone-input')\nexport class MinidPhoneInput extends FormControlMixin(\n styled(LitElement, styles)\n) {\n private formatter = new AsYouType();\n private skipCountryUpdate = false; // avoids unwanted update loop\n private currentEvent = new Event(''); // the event to be emitted after value is set\n private currentTemplate = '';\n private hasSlotControler = new HasSlotController(this, 'label');\n\n @query('#input')\n input!: HTMLInputElement;\n\n /**\n * The value of the phone number in E.164 format. Example: `\"+4799999999\"`\n *\n */\n @property({ reflect: true })\n value = '';\n\n /**\n * The phone number without the country code prefix. Example: `\"99999999\"`\n */\n @property({ reflect: true })\n nationalnumber = '';\n\n /**\n * The country code of the current phone number value. Example: `\"+47\"`\n */\n @property({ reflect: true })\n countrycode = '';\n\n /**\n * Label for the phone input.\n * Passed label will be encapsulated by a label element.\n */\n @property()\n label = '';\n\n /**\n * Hide label visually. Still available for screen readers\n */\n @property({ type: Boolean })\n hidelabel = false;\n\n /**\n * The country selected. A two letter ISO country code like: `\"NO\"`\n */\n @property({ reflect: true })\n country?: CountryCode;\n\n /**\n * Activates invalid styling\n */\n @property({ type: Boolean })\n invalid = false;\n\n /**\n * Makes the input required\n */\n @property({ type: Boolean })\n required = false;\n\n /**\n * Makes the input read-only, meaning the user cannot change the value.\n */\n @property({ type: Boolean })\n readonly = false;\n\n @state()\n hasFocus = false;\n\n static get formControlValidators() {\n return [requiredValidator];\n }\n\n handleCountryClick() {\n this.dispatchEvent(\n new CustomEvent('mid-country-click', { composed: true, bubbles: true })\n );\n }\n\n handleCountryKeyDown(event: KeyboardEvent) {\n if ([' ', 'Enter'].includes(event.key)) {\n this.dispatchEvent(\n new CustomEvent('mid-country-click', { composed: true, bubbles: true })\n );\n }\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n this.formatter.input(this.value);\n this.country = this.formatter.getCountry() ?? this.country;\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n\n this.value = formatIncompletePhoneNumber(this.value);\n this.value ||= this.countrycode;\n this.nationalnumber = this.removePhonePrefix(this.value);\n this.setValue(this.value.replaceAll(' ', ''));\n\n setTimeout(() => {\n this.input.value = `${this.countrycode} ${this.nationalnumber}`;\n });\n }\n\n get parseTemplate() {\n return templateParser(this.currentTemplate, parsePhoneNumberCharacter);\n }\n\n get formatTemplate() {\n return templateFormatter(this.currentTemplate);\n }\n\n private handleBlur() {\n this.hasFocus = false;\n this.dispatchEvent(\n new Event('mid-blur', { bubbles: true, composed: true })\n );\n }\n\n private handleChange(event: Event) {\n // Event is dispatched after value is set\n this.currentEvent = new Event('mid-change', {\n bubbles: true,\n composed: true,\n });\n\n this.handleNewValue(event);\n }\n\n private handleKeydown(event: KeyboardEvent) {\n if (event.key === 'Backspace' && this.input.selectionStart === 1) {\n // don't remove '+' symbol which is the first character\n event.preventDefault();\n return;\n }\n\n const hasModifier =\n event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n\n // Pressing enter when focused on an input should submit the form like a native input, but we wait a tick before\n // submitting to allow users to cancel the keydown event if they need to\n if (event.key === 'Enter' && !hasModifier) {\n setTimeout(() => {\n //\n // When using an Input Method Editor (IME), pressing enter will cause the form to submit unexpectedly. One way\n // to check for this is to look at event.isComposing, which will be true when the IME is open.\n if (!event.defaultPrevented && !event.isComposing) {\n this.form.requestSubmit();\n }\n });\n return;\n }\n\n onKeyDown(\n event as any,\n this.input,\n this.parseTemplate,\n this.formatTemplate,\n this.valueChangeCallback\n );\n }\n\n private handleInput(event: InputEvent) {\n // Event is dispatched after value is set\n this.currentEvent = new Event('mid-input', {\n composed: true,\n bubbles: true,\n });\n this.handleNewValue(event);\n }\n\n private handleNewValue(event: Event) {\n this.formatter.reset();\n\n if (!this.input.value.startsWith('+')) {\n this.input.value = `+${this.input.value}`;\n }\n this.formatter.input(this.input.value);\n this.currentTemplate = this.formatter.getTemplate();\n\n onChange(\n event as any,\n this.input,\n this.parseTemplate,\n this.formatTemplate,\n this.valueChangeCallback\n );\n }\n\n private valueChangeCallback = (value: string) => {\n const country =\n value.length < 2\n ? undefined\n : (this.formatter.getCountry() ?? this.country);\n\n if (country !== this.country) {\n this.country = country;\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n this.skipCountryUpdate = true;\n }\n\n if (value !== this.value) {\n this.value = value;\n this.setValue(this.value.replaceAll(' ', ''));\n this.nationalnumber = this.removePhonePrefix(value);\n }\n\n this.dispatchEvent(this.currentEvent);\n };\n\n private handleFocus() {\n this.hasFocus = true;\n this.dispatchEvent(\n new Event('mid-focus', { composed: true, bubbles: true })\n );\n }\n\n private removePhonePrefix(value: string) {\n if (this.countrycode) {\n value = value.slice(this.countrycode.length);\n if (value[0] === ' ') {\n value = value.slice(1);\n }\n }\n return value;\n }\n\n focus() {\n this.input.focus();\n setTimeout(() => {\n this.input.setSelectionRange(\n (this.countrycode?.length ?? 0) + 1,\n this.input.value.length\n );\n }, 0);\n }\n\n @watch('country', { waitUntilFirstUpdate: true })\n handleCountryChange() {\n if (this.skipCountryUpdate) {\n this.skipCountryUpdate = false;\n return;\n }\n\n this.formatter = new AsYouType(this.country);\n this.nationalnumber = this.removePhonePrefix(this.input.value);\n\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n this.input.value = formatIncompletePhoneNumber(\n `${this.countrycode}${this.nationalnumber}`\n );\n this.input.dispatchEvent(new Event('input', { bubbles: true }));\n this.input.dispatchEvent(new Event('change', { bubbles: true }));\n }\n\n override render() {\n const lg = false;\n const md = true;\n const sm = false;\n\n const hasLabelSlot = this.hasSlotControler.test('label');\n const hasLabel = !!this.label || !!hasLabelSlot;\n\n return html`\n <div\n part=\"field\"\n class=\"${classMap({\n 'text-body-sm': sm,\n 'text-body-md': md,\n 'text-body-lg': lg,\n })}\"\n >\n <label\n for=\"input\"\n class=\"${classMap({\n 'sr-only': this.hidelabel || !hasLabel,\n })} mb-2 inline-flex items-center gap-1 font-medium\"\n >\n ${this.readonly\n ? html`<mid-icon\n class=\"size-5\"\n library=\"system\"\n name=\"padlock-locked-fill\"\n ></mid-icon>`\n : nothing}\n <slot name=\"label\"> ${this.label} </slot>\n </label>\n <div part=\"base\" class=\"flex h-12\">\n <button\n part=\"country-button\"\n aria-label=\"Open country selector\"\n class=\"${classMap({\n 'border-neutral': !this.readonly,\n 'border-neutral-subtle': this.readonly,\n 'bg-neutral-surface-tinted': this.readonly,\n 'bg-neutral-surface': !this.readonly,\n })} focus-visible:focus-ring flex h-full items-center rounded-l border border-r-0 pl-3\"\n iconstyled\n variant=\"tertiary\"\n ?disabled=${this.readonly}\n @click=${this.handleCountryClick}\n @keydown=${this.handleCountryKeyDown}\n >\n ${this.country\n ? html`\n <mid-icon\n class=\"h-4 w-6 overflow-hidden rounded\"\n library=\"country\"\n name=\"${this.country}\"\n ></mid-icon>\n `\n : html`<div\n class=\"bg-neutral-surface-active h-4 w-6 overflow-hidden rounded\"\n ></div>`}\n <mid-icon name=\"chevron-down\"></mid-icon>\n </button>\n\n <input\n id=\"input\"\n class=\"${classMap({\n 'border-neutral': !this.invalid && !this.readonly,\n 'border-danger': this.invalid && !this.readonly,\n 'border-neutral-subtle': this.readonly,\n 'bg-neutral-surface-tinted': this.readonly,\n 'bg-neutral-surface': !this.readonly,\n 'border-2': this.invalid,\n border: !this.invalid,\n })} focus-visible:focus-ring grow rounded-r px-3\"\n part=\"phone-number\"\n type=\"tel\"\n autocomplete=\"tel\"\n ?readonly=${this.readonly}\n value=${this.value}\n @input=${this.handleInput}\n @focus=${this.handleFocus}\n @blur=${this.handleBlur}\n @keydown=${this.handleKeydown}\n @change=${this.handleChange}\n />\n </div>\n </div>\n `;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAKF;AAgBO,IAAM,kBAAN,cAA8B;AAAA,EACnC,OAAO,YAAY,MAAM;AAC3B,EAAE;AAAA,EAFK,cAAA;AAAA,UAAA,GAAA,SAAA;AAGL,SAAQ,YAAY,IAAI,UAAA;AACxB,SAAQ,oBAAoB;AAC5B,SA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AAA,WAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GA3DhB,gBA4DX,WAAA,YAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GAjEhB,gBAkEX,WAAA,YAAA,CAAA;AAGA,gBAAA;AAAA,EADC,MAAA;AAAM,GApEI,gBAqEX,WAAA,YAAA,CAAA;AA+KA,gBAAA;AAAA,EADC,MAAM,WAAW,EAAE,sBAAsB,MAAM;AAAA,GAnPrC,gBAoPX,WAAA,uBAAA,CAAA;AApPW,kBAAN,gBAAA;AAAA,EADN,cAAc,iBAAiB;AAAA,GACnB,eAAA;"}
|
|
1
|
+
{"version":3,"file":"phone-input.js","sources":["../../src/components/phone-input.component.ts"],"sourcesContent":["import { css, html, LitElement, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { styled } from '../mixins/tailwind.mixin';\nimport {\n AsYouType,\n formatIncompletePhoneNumber,\n getCountryCallingCode,\n type CountryCode,\n parsePhoneNumberFromString,\n parsePhoneNumberCharacter,\n} from 'libphonenumber-js';\nimport './icon/icon.component';\nimport {\n onChange,\n onKeyDown,\n templateFormatter,\n templateParser,\n} from 'input-format';\nimport { watch } from '../internal/watch';\nimport { HasSlotController } from '../internal/slot';\nimport { FormControlMixin } from '../mixins/form-control.mixin';\nimport { requiredValidator } from '../mixins/validators';\nimport { LangController } from '../controllers/lang.controller.js';\nimport { getLang } from '../utilities/lang';\nimport { getTranslations } from '../utilities/translations';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-phone-input': MinidPhoneInput;\n }\n}\n\ntype PhoneAutocomplete = 'tel' | 'tel-national';\n\nconst styles = [\n css`\n :host {\n display: block;\n }\n `,\n];\n\nlet nextUniqueId = 0;\n\n/**\n * @event {Event} mid-country-click - Emitted when the country button is clicked\n * @event {Event} mid-change - Emitted when the value is modified by the user\n * @event {Event} mid-input - Emitted after a new user input\n * @event {Event} mid-blur - Emitted after focus is moved away from input\n * @event {Event} mid-focus - Emitted after input gains focus\n *\n * @part base - Select the container outside the country button and phone number input\n * @part field - Select the container around the label and the inputs\n * @part label - Select the label element\n * @part country-button - Select the country button\n * @part input - Select the phone number input\n */\n@customElement('mid-phone-input')\nexport class MinidPhoneInput extends FormControlMixin(\n styled(LitElement, styles)\n) {\n private readonly inputId: string;\n private readonly validationId: string;\n private readonly labelId = `mid-code-input-label-${nextUniqueId++}`;\n private formatter = new AsYouType();\n private skipCountryUpdate = false; // avoids unwanted update loop\n private currentEvent = new Event(''); // the event to be emitted after value is set\n private currentTemplate = '';\n private hasSlotControler = new HasSlotController(this, 'label');\n\n @query('input')\n input!: HTMLInputElement;\n\n /**\n * The value of the phone number in E.164 format. Example: `\"+4799999999\"`\n *\n */\n @property({ reflect: true })\n value = '';\n\n /**\n * The phone number without the country code prefix. Example: `\"99999999\"`\n */\n @property({ reflect: true })\n nationalnumber = '';\n\n /**\n * The country code of the current phone number value. Example: `\"+47\"`\n */\n @property({ reflect: true })\n countrycode = '';\n\n /**\n * Label for the phone input.\n * Passed label will be encapsulated by a label element.\n */\n @property()\n label = '';\n\n /**\n * Hide label visually. Still available for screen readers\n */\n @property({ type: Boolean })\n hidelabel = false;\n\n /**\n * The country selected. A two letter ISO country code like: `\"NO\"`\n */\n @property({ reflect: true })\n country?: CountryCode;\n\n /**\n * Controls the native browser autofill token used for the phone number input.\n *\n * `tel` expects a full phone number, including country code when available.\n * If a value without a country code matches the selected country, the country\n * prefix is added.\n * `tel-national` expects the national number and prefixes the selected country.\n */\n @property()\n autocomplete: PhoneAutocomplete = 'tel';\n\n /**\n * Activates invalid styling\n */\n @property({ type: Boolean })\n invalid = false;\n\n /**\n * Error message to display when the input is invalid, also activates invalid styling\n */\n @property()\n invalidmessage = '';\n\n /**\n * Makes the input required\n */\n @property({ type: Boolean })\n required = false;\n\n /**\n * Makes the input read-only, meaning the user cannot change the value.\n */\n @property({ type: Boolean })\n readonly = false;\n\n @state()\n hasFocus = false;\n\n static get formControlValidators() {\n return [requiredValidator];\n }\n\n constructor() {\n super();\n new LangController(this);\n nextUniqueId++;\n this.inputId = `mid-phone-input-input-${nextUniqueId}`;\n this.validationId = `mid-phone-input-validation-${nextUniqueId}`;\n }\n\n get validationTarget() {\n return this.input;\n }\n\n validationMessageCallback(message: string) {\n this.invalidmessage = message;\n }\n\n resetFormControl() {\n this.invalidmessage = '';\n }\n\n handleCountryClick() {\n this.dispatchEvent(\n new CustomEvent('mid-country-click', { composed: true, bubbles: true })\n );\n }\n\n handleCountryKeyDown(event: KeyboardEvent) {\n if ([' ', 'Enter'].includes(event.key)) {\n this.dispatchEvent(\n new CustomEvent('mid-country-click', { composed: true, bubbles: true })\n );\n }\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n this.formatter.input(this.value);\n this.country = this.formatter.getCountry() ?? this.country;\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n\n this.value = formatIncompletePhoneNumber(this.value);\n this.value ||= this.countrycode;\n this.nationalnumber = this.removePhonePrefix(this.value);\n this.setValue(this.value.replaceAll(' ', ''));\n\n setTimeout(() => {\n this.input.value = `${this.countrycode} ${this.nationalnumber}`;\n });\n }\n\n get parseTemplate() {\n return templateParser(this.currentTemplate, parsePhoneNumberCharacter);\n }\n\n get formatTemplate() {\n return templateFormatter(this.currentTemplate);\n }\n\n private handleBlur() {\n this.hasFocus = false;\n this.dispatchEvent(\n new Event('mid-blur', { bubbles: true, composed: true })\n );\n }\n\n private handleChange(event: Event) {\n // Event is dispatched after value is set\n this.currentEvent = new Event('mid-change', {\n bubbles: true,\n composed: true,\n });\n\n this.handleNewValue(event);\n }\n\n private handleKeydown(event: KeyboardEvent) {\n if (event.key === 'Backspace' && this.input.selectionStart === 1) {\n // don't remove '+' symbol which is the first character\n event.preventDefault();\n return;\n }\n\n const hasModifier =\n event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n\n // Pressing enter when focused on an input should submit the form like a native input, but we wait a tick before\n // submitting to allow users to cancel the keydown event if they need to\n if (event.key === 'Enter' && !hasModifier) {\n setTimeout(() => {\n //\n // When using an Input Method Editor (IME), pressing enter will cause the form to submit unexpectedly. One way\n // to check for this is to look at event.isComposing, which will be true when the IME is open.\n if (!event.defaultPrevented && !event.isComposing) {\n this.form.requestSubmit();\n }\n });\n return;\n }\n\n onKeyDown(\n event as any,\n this.input,\n this.parseTemplate,\n this.formatTemplate,\n this.valueChangeCallback\n );\n }\n\n private handleInput(event: InputEvent) {\n // Event is dispatched after value is set\n this.currentEvent = new Event('mid-input', {\n composed: true,\n bubbles: true,\n });\n this.handleNewValue(event);\n }\n\n private getCountryCodePrefix() {\n if (this.country) {\n return `+${getCountryCallingCode(this.country)}`;\n }\n\n return this.countrycode;\n }\n\n private applyAutocompletePrefix(value: string) {\n if (value.startsWith('+')) {\n return value;\n }\n\n const countryCodePrefix = this.getCountryCodePrefix();\n if (this.autocomplete === 'tel-national' && countryCodePrefix) {\n return `${countryCodePrefix}${value}`;\n }\n\n if (this.autocomplete === 'tel' && this.country) {\n const phoneNumber = parsePhoneNumberFromString(value, this.country);\n const valueWithPlus = `+${value.replaceAll(/\\D/g, '')}`;\n\n if (phoneNumber?.isValid() && phoneNumber.number !== valueWithPlus) {\n return phoneNumber.number;\n }\n }\n\n return `+${value}`;\n }\n\n private handleNewValue(event: Event) {\n this.formatter.reset();\n\n this.input.value = this.applyAutocompletePrefix(this.input.value);\n\n this.formatter.input(this.input.value);\n this.currentTemplate = this.formatter.getTemplate();\n\n onChange(\n event as any,\n this.input,\n this.parseTemplate,\n this.formatTemplate,\n this.valueChangeCallback\n );\n }\n\n private valueChangeCallback = (value: string) => {\n const country =\n value.length < 2\n ? undefined\n : (this.formatter.getCountry() ?? this.country);\n\n if (country !== this.country) {\n this.country = country;\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n this.skipCountryUpdate = true;\n }\n\n if (value !== this.value) {\n this.value = value;\n this.setValue(this.value.replaceAll(' ', ''));\n this.nationalnumber = this.removePhonePrefix(value);\n }\n\n this.dispatchEvent(this.currentEvent);\n };\n\n private handleFocus() {\n this.hasFocus = true;\n this.dispatchEvent(\n new Event('mid-focus', { composed: true, bubbles: true })\n );\n }\n\n private removePhonePrefix(value: string) {\n if (this.countrycode) {\n value = value.slice(this.countrycode.length);\n if (value[0] === ' ') {\n value = value.slice(1);\n }\n }\n return value;\n }\n\n focus(options?: FocusOptions): void {\n this.input.focus(options);\n }\n\n @watch('country', { waitUntilFirstUpdate: true })\n handleCountryChange() {\n if (this.skipCountryUpdate) {\n this.skipCountryUpdate = false;\n return;\n }\n\n this.formatter = new AsYouType(this.country);\n this.nationalnumber = this.removePhonePrefix(this.input.value);\n\n this.countrycode = this.country\n ? `+${getCountryCallingCode(this.country)}`\n : '+';\n this.input.value = formatIncompletePhoneNumber(\n `${this.countrycode}${this.nationalnumber}`\n );\n this.input.dispatchEvent(new Event('input', { bubbles: true }));\n this.input.dispatchEvent(new Event('change', { bubbles: true }));\n }\n\n override render() {\n const lg = false;\n const md = true;\n const sm = false;\n\n const lang = getLang(this);\n const t = getTranslations(lang);\n const hasLabelSlot = this.hasSlotControler.test('label');\n const hasLabel = !!this.label || !!hasLabelSlot;\n const hasError = this.invalid || !!this.invalidmessage;\n const describedBy = this.invalidmessage ? this.validationId : undefined;\n\n return html`\n <label\n id=\"${this.labelId}\"\n class=\"${classMap({\n 'sr-only': this.hidelabel || !hasLabel,\n })} mb-2 block items-center gap-1 font-medium\"\n > \n <div\n part=\"field\"\n class=\"${classMap({\n 'text-body-sm': sm,\n 'text-body-md': md,\n 'text-body-lg': lg,\n })}\"\n >\n <label\n for=\"${this.inputId}\"\n class=\"${classMap({\n 'sr-only': this.hidelabel || !hasLabel,\n })} mb-2 inline-flex items-center gap-1 font-medium\"\n >\n ${this.readonly\n ? html`<mid-icon\n class=\"size-5\"\n library=\"system\"\n name=\"padlock-locked-fill\"\n ></mid-icon>`\n : nothing}\n <slot name=\"label\"> ${this.label} </slot>\n </label>\n <div part=\"base\" class=\"flex h-12\">\n <button\n part=\"country-button\"\n aria-label=${t.openCountrySelector}\n class=\"${classMap({\n 'border-neutral': !this.readonly,\n 'border-neutral-subtle': this.readonly,\n 'bg-neutral-surface-tinted': this.readonly,\n 'bg-neutral-surface': !this.readonly,\n })} focus-visible:focus-ring flex h-full items-center rounded-l border border-r-0 pl-3\"\n iconstyled\n variant=\"tertiary\"\n ?disabled=${this.readonly}\n @click=${this.handleCountryClick}\n @keydown=${this.handleCountryKeyDown}\n >\n ${this.country\n ? html`\n <mid-icon\n class=\"h-4 w-6 overflow-hidden rounded\"\n library=\"country\"\n name=\"${this.country}\"\n ></mid-icon>\n `\n : html`<div\n class=\"bg-neutral-surface-active h-4 w-6 overflow-hidden rounded\"\n ></div>`}\n <mid-icon name=\"chevron-down\"></mid-icon>\n </button>\n\n <input\n id=\"${this.inputId}\"\n class=\"${classMap({\n 'border-neutral': !hasError && !this.readonly,\n 'border-danger': hasError && !this.readonly,\n 'border-neutral-subtle': this.readonly,\n 'bg-neutral-surface-tinted': this.readonly,\n 'bg-neutral-surface': !this.readonly,\n 'border-2': hasError,\n border: !hasError,\n })} focus-visible:focus-ring grow rounded-r px-3\"\n part=\"phone-number\"\n type=\"tel\"\n autocomplete=${this.autocomplete}\n ?readonly=${this.readonly}\n value=${this.value}\n aria-describedby=${ifDefined(describedBy)}\n aria-invalid=${hasError ? 'true' : 'false'}\n aria-errormessage=${ifDefined(\n this.invalidmessage ? this.validationId : undefined\n )}\n @input=${this.handleInput}\n @focus=${this.handleFocus}\n @blur=${this.handleBlur}\n @keydown=${this.handleKeydown}\n @change=${this.handleChange}\n />\n </div>\n <div\n class=\"text-danger-subtle mt-2 flex gap-1\"\n id=\"${this.validationId}\"\n aria-live=\"polite\"\n ?hidden=${!this.invalidmessage}\n >\n <mid-icon\n name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AAA,SAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,SAAS,KAAA,CAAM;AAAA,GAzBhB,gBA0BX,WAAA,kBAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,SAAS,KAAA,CAAM;AAAA,GA/BhB,gBAgCX,WAAA,eAAA,CAAA;AAOA,gBAAA;AAAA,EADC,SAAA;AAAS,GAtCC,gBAuCX,WAAA,SAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GA5ChB,gBA6CX,WAAA,aAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,SAAS,KAAA,CAAM;AAAA,GAlDhB,gBAmDX,WAAA,WAAA,CAAA;AAWA,gBAAA;AAAA,EADC,SAAA;AAAS,GA7DC,gBA8DX,WAAA,gBAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GAnEhB,gBAoEX,WAAA,WAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAA;AAAS,GAzEC,gBA0EX,WAAA,kBAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GA/EhB,gBAgFX,WAAA,YAAA,CAAA;AAMA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,QAAA,CAAS;AAAA,GArFhB,gBAsFX,WAAA,YAAA,CAAA;AAGA,gBAAA;AAAA,EADC,MAAA;AAAM,GAxFI,gBAyFX,WAAA,YAAA,CAAA;AA0NA,gBAAA;AAAA,EADC,MAAM,WAAW,EAAE,sBAAsB,MAAM;AAAA,GAlTrC,gBAmTX,WAAA,uBAAA,CAAA;AAnTW,kBAAN,gBAAA;AAAA,EADN,cAAc,iBAAiB;AAAA,GACnB,eAAA;"}
|
|
@@ -166,7 +166,7 @@ export declare class MinidPopup extends MinidPopup_base {
|
|
|
166
166
|
/** Forces the popup to recalculate and reposition itself. */
|
|
167
167
|
reposition(): void;
|
|
168
168
|
private updateHoverBridge;
|
|
169
|
-
render(): import('lit
|
|
169
|
+
render(): import('lit').TemplateResult<1>;
|
|
170
170
|
}
|
|
171
171
|
export {};
|
|
172
172
|
//# sourceMappingURL=popup.component.d.ts.map
|
|
@@ -35,7 +35,7 @@ export declare class MinidQrCode extends MinidQrCode_base {
|
|
|
35
35
|
background: string;
|
|
36
36
|
margin: number;
|
|
37
37
|
protected updated(): void;
|
|
38
|
-
render(): import('lit
|
|
38
|
+
render(): import('lit').TemplateResult<1>;
|
|
39
39
|
}
|
|
40
40
|
export {};
|
|
41
41
|
//# sourceMappingURL=qr-code.component.d.ts.map
|
|
@@ -46,7 +46,7 @@ export declare class MinidRadioButton extends MinidRadioButton_base {
|
|
|
46
46
|
* Removes focus from the radio button.
|
|
47
47
|
*/
|
|
48
48
|
blur(): void;
|
|
49
|
-
render(): import('lit
|
|
49
|
+
render(): import('lit').TemplateResult<1>;
|
|
50
50
|
}
|
|
51
51
|
export {};
|
|
52
52
|
//# sourceMappingURL=radio-button.component.d.ts.map
|
|
@@ -55,7 +55,7 @@ export declare class MinidRadioGroup extends MinidRadioGroup_base {
|
|
|
55
55
|
* Sets focus on the radio-group.
|
|
56
56
|
*/
|
|
57
57
|
focus(options?: FocusOptions): void;
|
|
58
|
-
render(): import('lit
|
|
58
|
+
render(): import('lit').TemplateResult<1>;
|
|
59
59
|
}
|
|
60
60
|
export {};
|
|
61
61
|
//# sourceMappingURL=radio-group.component.d.ts.map
|
|
@@ -48,7 +48,7 @@ export declare class MinidRadio extends MinidRadio_base {
|
|
|
48
48
|
* Sets focus on the radio button.
|
|
49
49
|
*/
|
|
50
50
|
focus(options?: FocusOptions): void;
|
|
51
|
-
render(): import('lit
|
|
51
|
+
render(): import('lit').TemplateResult<1>;
|
|
52
52
|
}
|
|
53
53
|
export {};
|
|
54
54
|
//# sourceMappingURL=radio.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.component.d.ts","sourceRoot":"","sources":["../../src/components/radio.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"radio.component.d.ts","sourceRoot":"","sources":["../../src/components/radio.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAM5C,OAAO,0BAA0B,CAAC;AAElC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,UAAU,CAAC;KACzB;CACF;;AAcD;;;;;;;;;GASG;AACH,qBACa,UAAW,SAAQ,eAA4C;IAE1E,KAAK,EAAG,gBAAgB,CAAC;IAEzB;;OAEG;IAEH,IAAI,SAAY;IAEhB;;OAEG;IAEH,OAAO,UAAS;IAEhB;;OAEG;IAEH,KAAK,SAAM;IAEX;;OAEG;IAEH,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAEhB,qBAAqB,IAAI,OAAO;IAIhC,IAAI,gBAAgB,qBAEnB;;IASD,iBAAiB;IAQjB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,WAAW;IAYnB,oBAAoB;IAKpB,iBAAiB;IAIjB;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY;IAInB,MAAM;CAqBhB"}
|
package/dist/components/radio.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { css, LitElement, html } from "lit";
|
|
2
2
|
import { query, property, customElement } from "lit/decorators.js";
|
|
3
3
|
import { live } from "lit/directives/live.js";
|
|
4
|
-
import { classMap } from "lit/directives/class-map.js";
|
|
5
4
|
import { watch } from "../internal/watch.js";
|
|
6
5
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
7
6
|
import { FormControlMixin } from "../mixins/form-control.mixin.js";
|
|
@@ -99,26 +98,23 @@ let MinidRadio = class extends FormControlMixin(styled(LitElement, styles)) {
|
|
|
99
98
|
}
|
|
100
99
|
render() {
|
|
101
100
|
return html`
|
|
101
|
+
<ds-field class="ds-field">
|
|
102
|
+
<input
|
|
103
|
+
type="radio"
|
|
104
|
+
part="radio"
|
|
105
|
+
name="${this.name}"
|
|
106
|
+
class="ds-input"
|
|
107
|
+
?checked=${live(this.checked)}
|
|
108
|
+
?disabled=${this.disabled}
|
|
109
|
+
@keydown=${this.handleKeydown}
|
|
110
|
+
/>
|
|
102
111
|
<label
|
|
103
112
|
part="label"
|
|
104
|
-
class="
|
|
113
|
+
class="ds-label"
|
|
105
114
|
>
|
|
106
|
-
<input
|
|
107
|
-
type="radio"
|
|
108
|
-
part="radio"
|
|
109
|
-
name="${this.name}"
|
|
110
|
-
class="${classMap({
|
|
111
|
-
"bg-neutral": !this.invalid,
|
|
112
|
-
"border-neutral": !this.invalid,
|
|
113
|
-
"bg-danger-tinted": this.invalid,
|
|
114
|
-
"border-danger-base": this.invalid
|
|
115
|
-
})} checked:bg-accent-base checked:before:bg-neutral focus-visible:focus-ring-sm checked:border-accent-base my-0.5 grid size-6 cursor-pointer appearance-none place-content-center rounded-full border-2 p-0.5 shadow-none before:size-2.5 before:scale-0 before:rounded-full before:transition-transform before:duration-100 checked:before:scale-100 disabled:cursor-not-allowed"
|
|
116
|
-
?checked=${live(this.checked)}
|
|
117
|
-
?disabled=${this.disabled}
|
|
118
|
-
@keydown=${this.handleKeydown}
|
|
119
|
-
/>
|
|
120
115
|
<slot></slot>
|
|
121
116
|
</label>
|
|
117
|
+
</ds-field>
|
|
122
118
|
`;
|
|
123
119
|
}
|
|
124
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio.js","sources":["../../src/components/radio.component.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\nimport {
|
|
1
|
+
{"version":3,"file":"radio.js","sources":["../../src/components/radio.component.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\nimport { watch } from '../internal/watch';\nimport { styled } from '../mixins/tailwind.mixin';\nimport { FormControlMixin } from '../mixins/form-control.mixin';\nimport './icon/icon.component.ts';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-radio': MinidRadio;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: inline-flex;\n cursor: pointer;\n }\n :host:has(input:disabled) {\n cursor: not-allowed;\n }\n `,\n];\n\n/**\n *\n * @slot -- The radio's label\n *\n * @event mid-blur - Emitted when the control loses focus.\n * @event mid-focus - Emitted when the control gains focus.\n *\n * @csspart radio - Select the radio input element\n * @csspart label - Select the label element\n */\n@customElement('mid-radio')\nexport class MinidRadio extends FormControlMixin(styled(LitElement, styles)) {\n @query('input[type=\"radio\"]')\n input!: HTMLInputElement;\n\n /**\n * The name of the radio, used to bind together multiple radios.\n */\n @property()\n name = 'option';\n\n /**\n * The radio button's checked state.\n */\n @property({ type: Boolean, reflect: true })\n checked = false;\n\n /**\n * The radio's value. When selected, the radio group will receive this value.\n */\n @property()\n value = '';\n\n /**\n * Disables the radio button.\n */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n\n @property({ type: Boolean })\n invalid = false;\n\n shouldFormValueUpdate(): boolean {\n return this.checked;\n }\n\n get validationTarget() {\n return this.input;\n }\n\n constructor() {\n super();\n this.addEventListener('blur', this.handleBlur);\n this.addEventListener('click', this.handleClick);\n this.addEventListener('focus', this.handleFocus);\n }\n\n connectedCallback() {\n super.connectedCallback();\n this.setAttribute('role', 'presentation');\n this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false');\n\n this.classList.add('rounded');\n }\n\n private handleKeydown(event: KeyboardEvent) {\n const hasModifier =\n event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n\n // Pressing enter when focused on an input should submit the form like a native input, but we wait a tick before\n // submitting to allow users to cancel the keydown event if they need to\n if (event.key === 'Enter' && !hasModifier) {\n setTimeout(() => {\n //\n // When using an Input Method Editor (IME), pressing enter will cause the form to submit unexpectedly. One way\n // to check for this is to look at event.isComposing, which will be true when the IME is open.\n if (!event.defaultPrevented && !event.isComposing) {\n this.form.requestSubmit();\n }\n });\n }\n }\n\n private handleBlur() {\n this.classList.remove('shadow-focus-visible');\n this.dispatchEvent(\n new Event('mid-blur', { composed: true, bubbles: true })\n );\n }\n\n private handleFocus() {\n if (this.disabled) {\n return;\n }\n\n this.focus();\n this.dispatchEvent(\n new Event('mid-focus', { composed: true, bubbles: true })\n );\n }\n\n private handleClick(event: MouseEvent) {\n if (this.disabled) {\n event.preventDefault();\n event.stopPropagation();\n return;\n }\n\n this.checked = true;\n this.dispatchEvent(new Event('mid-change'));\n }\n\n @watch('disabled', { waitUntilFirstUpdate: true })\n handleDisabledChange() {\n this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false');\n }\n\n @watch('checked', { waitUntilFirstUpdate: true })\n handleCheckChange() {\n this.input.checked = this.checked;\n }\n\n /**\n * Sets focus on the radio button.\n */\n focus(options?: FocusOptions) {\n this.input.focus(options);\n }\n\n override render() {\n return html`\n <ds-field class=\"ds-field\">\n <input\n type=\"radio\"\n part=\"radio\"\n name=\"${this.name}\"\n class=\"ds-input\"\n ?checked=${live(this.checked)}\n ?disabled=${this.disabled}\n @keydown=${this.handleKeydown}\n />\n <label\n part=\"label\"\n class=\"ds-label\"\n >\n <slot></slot>\n </label>\n </ds-field>\n `;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASF;AAaO,IAAM,aAAN,cAAyB,iBAAiB,OAAO,YAAY,MAAM,CAAC,EAAE;AAAA,EAuC3E,cAAc;AACZ,UAAA;AAhCF,SAAA,OAAO;AAMP,SAAA,UAAU;AAMV,SAAA,QAAQ;AAMR,SAAA,WAAW;AAGX,SAAA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Element } from 'lit';
|
|
2
|
-
import { MinidTextfield } from './textfield.component.ts';
|
|
3
2
|
declare global {
|
|
4
3
|
interface HTMLElementTagNameMap {
|
|
5
4
|
'mid-search': MinidSearch;
|
|
@@ -12,10 +11,14 @@ declare const MinidSearch_base: typeof LitElement;
|
|
|
12
11
|
* @event mid-clear - Emitted when the input value is cleared
|
|
13
12
|
* @event mid-focus - Emitted when input element is focused
|
|
14
13
|
* @event mid-blur - Emitted when focus moves away from input element
|
|
14
|
+
*
|
|
15
|
+
* @csspart base - The search wrapper element
|
|
16
|
+
* @csspart input - The internal `<input>` element
|
|
17
|
+
* @csspart clear-button - The clear button
|
|
15
18
|
*/
|
|
16
19
|
export declare class MinidSearch extends MinidSearch_base {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
constructor();
|
|
21
|
+
input: HTMLInputElement;
|
|
19
22
|
label: string;
|
|
20
23
|
placeholder: string;
|
|
21
24
|
value: string;
|
|
@@ -24,8 +27,12 @@ export declare class MinidSearch extends MinidSearch_base {
|
|
|
24
27
|
*/
|
|
25
28
|
debounce: number;
|
|
26
29
|
private handleInput;
|
|
30
|
+
private handleChange;
|
|
31
|
+
private handleFocus;
|
|
32
|
+
private handleBlur;
|
|
33
|
+
private handleClear;
|
|
27
34
|
focus(): void;
|
|
28
|
-
render(): import('lit
|
|
35
|
+
render(): import('lit').TemplateResult<1>;
|
|
29
36
|
}
|
|
30
37
|
export {};
|
|
31
38
|
//# sourceMappingURL=search.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.component.d.ts","sourceRoot":"","sources":["../../src/components/search.component.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"search.component.d.ts","sourceRoot":"","sources":["../../src/components/search.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAW,MAAM,KAAK,CAAC;AAUrD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,WAAW,CAAC;KAC3B;CACF;;AAUD;;;;;;;;;;GAUG;AACH,qBACa,WAAY,SAAQ,gBAA0B;;IAOzD,KAAK,EAAG,gBAAgB,CAAC;IAGzB,KAAK,SAAM;IAGX,WAAW,SAAM;IAGjB,KAAK,SAAM;IAEX;;OAEG;IAEH,QAAQ,SAAK;IAEb,OAAO,CAAC,WAAW,CAKjB;IAEF,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;IAanB,KAAK;IAII,MAAM;CAoChB"}
|