@felleslosninger/minid-elements 0.0.107 → 0.0.108

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.
@@ -60,6 +60,10 @@ export declare class MinidPhoneInput extends MinidPhoneInput_base {
60
60
  * Makes the input required
61
61
  */
62
62
  required: boolean;
63
+ /**
64
+ * Makes the input read-only, meaning the user cannot change the value.
65
+ */
66
+ readonly: boolean;
63
67
  hasFocus: boolean;
64
68
  static get formControlValidators(): import('../types/validator.type').Validator[];
65
69
  handleCountryClick(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"phone-input.component.d.ts","sourceRoot":"","sources":["../../src/components/phone-input.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,EAIL,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,uBAAuB,CAAC;AAY/B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,eAAe,CAAC;KACpC;CACF;;AAUD;;;;;;;;;;;;GAYG;AACH,qBACa,eAAgB,SAAQ,oBAEpC;IACC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,gBAAgB,CAAwC;IAGhE,KAAK,EAAG,gBAAgB,CAAC;IAEzB;;;OAGG;IAEH,KAAK,SAAM;IAEX;;OAEG;IAEH,cAAc,SAAM;IAEpB;;OAEG;IAEH,WAAW,SAAM;IAEjB;;;OAGG;IAEH,KAAK,SAAM;IAEX;;OAEG;IAEH,SAAS,UAAS;IAElB;;OAEG;IAEH,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;OAEG;IAEH,OAAO,UAAS;IAEhB;;OAEG;IAEH,QAAQ,UAAS;IAGjB,QAAQ,UAAS;IAEjB,M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IAEH,OAAO,UAAS;IAEhB;;OAEG;IAEH,QAAQ,UAAS;IAEjB;;OAEG;IAEH,QAAQ,UAAS;IAGjB,QAAQ,UAAS;IAEjB,MAAM,KAAK,qBAAqB,kDAE/B;IAED,kBAAkB;IAMlB,oBAAoB,CAAC,KAAK,EAAE,aAAa;IAQzC,iBAAiB,IAAI,IAAI;IAkBzB,IAAI,aAAa,yCAEhB;IAED,IAAI,cAAc,0CAEjB;IAED,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,mBAAmB,CAiBzB;IAEF,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,iBAAiB;IAUzB,KAAK;IAWL,mBAAmB;IAoBnB,iBAAiB;IAIR,MAAM;CAuFhB"}
@@ -1,4 +1,4 @@
1
- import { css, LitElement, html } from "lit";
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
4
  import { styled } from "../mixins/tailwind.mixin.js";
@@ -43,6 +43,7 @@ let MinidPhoneInput = class extends FormControlMixin(
43
43
  this.hidelabel = false;
44
44
  this.invalid = false;
45
45
  this.required = false;
46
+ this.readonly = false;
46
47
  this.hasFocus = false;
47
48
  this.valueChangeCallback = (value) => {
48
49
  const country = value.length < 2 ? void 0 : this.formatter.getCountry() ?? this.country;
@@ -208,14 +209,25 @@ let MinidPhoneInput = class extends FormControlMixin(
208
209
  "sr-only": this.hidelabel || !hasLabel
209
210
  })} mb-2 inline-flex items-center gap-1 font-medium"
210
211
  >
212
+ ${this.readonly ? html`<mid-icon
213
+ class="size-5"
214
+ library="system"
215
+ name="padlock-locked-fill"
216
+ ></mid-icon>` : nothing}
211
217
  <slot name="label"> ${this.label} </slot>
212
218
  </label>
213
219
  <div part="base" class="flex h-12">
214
220
  <button
215
221
  part="country-button"
216
- class="border-neutral focus-visible:focus-ring flex h-full items-center rounded-l border border-r-0 pl-3"
222
+ class="${classMap({
223
+ "border-neutral": !this.readonly,
224
+ "border-neutral-subtle": this.readonly,
225
+ "bg-neutral-surface-tinted": this.readonly,
226
+ "bg-neutral-surface": !this.readonly
227
+ })} focus-visible:focus-ring flex h-full items-center rounded-l border border-r-0 pl-3"
217
228
  iconstyled
218
229
  variant="tertiary"
230
+ ?disabled=${this.readonly}
219
231
  @click=${this.handleCountryClick}
220
232
  @keydown=${this.handleCountryKeyDown}
221
233
  >
@@ -234,14 +246,18 @@ let MinidPhoneInput = class extends FormControlMixin(
234
246
  <input
235
247
  id="input"
236
248
  class="${classMap({
237
- "border-neutral": !this.invalid,
238
- "border-danger": this.invalid,
249
+ "border-neutral": !this.invalid && !this.readonly,
250
+ "border-danger": this.invalid && !this.readonly,
251
+ "border-neutral-subtle": this.readonly,
252
+ "bg-neutral-surface-tinted": this.readonly,
253
+ "bg-neutral-surface": !this.readonly,
239
254
  "border-2": this.invalid,
240
255
  border: !this.invalid
241
256
  })} focus-visible:focus-ring grow rounded-r px-3"
242
257
  part="phone-number"
243
258
  type="tel"
244
259
  autocomplete="tel"
260
+ ?readonly=${this.readonly}
245
261
  value=${this.value}
246
262
  @input=${this.handleInput}
247
263
  @focus=${this.handleFocus}
@@ -281,6 +297,9 @@ __decorateClass([
281
297
  __decorateClass([
282
298
  property({ type: Boolean })
283
299
  ], MinidPhoneInput.prototype, "required", 2);
300
+ __decorateClass([
301
+ property({ type: Boolean })
302
+ ], MinidPhoneInput.prototype, "readonly", 2);
284
303
  __decorateClass([
285
304
  state()
286
305
  ], MinidPhoneInput.prototype, "hasFocus", 2);
@@ -1 +1 @@
1
- {"version":3,"file":"phone-input.js","sources":["../../src/components/phone-input.component.ts"],"sourcesContent":["import { css, html, LitElement } 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 @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\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,\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,\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 this.value = value;\n this.nationalnumber = this.removePhonePrefix(value);\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 @watch('value')\n handleValueChange() {\n this.setValue(this.value.replaceAll(' ', ''));\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 <slot name=\"label\"> ${this.label} </slot>\n </label>\n <div part=\"base\" class=\"flex h-12\">\n <button\n part=\"country-button\"\n class=\"border-neutral focus-visible:focus-ring flex h-full items-center rounded-l border border-r-0 pl-3\"\n iconstyled\n variant=\"tertiary\"\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,\n 'border-danger': this.invalid,\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 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":";;;;;;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AAE,sBAAsB,KAAM,CAAA;AAAA,GAxOrC,gBAyOX,WAAA,uBAAA,CAAA;AAoBA,gBAAA;AAAA,EADC,MAAM,OAAO;AAAA,GA5PH,gBA6PX,WAAA,qBAAA,CAAA;AA7PW,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 { 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\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,\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,\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 this.value = value;\n this.nationalnumber = this.removePhonePrefix(value);\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 @watch('value')\n handleValueChange() {\n this.setValue(this.value.replaceAll(' ', ''));\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 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;AAGG,SAAA,YAAY,IAAI,UAAU;AAClC,SAAQ,oBAAoB;AACpB,SAAA,eAAe,IAAI,MAAM,EAAE;AACnC,SAAQ,kBAAkB;AAC1B,SAAQ,mBAAmB,IAAI,kBAAkB,MAAM,OAAO;AAUtD,SAAA,QAAA;AAMS,SAAA,iBAAA;AAMH,SAAA,cAAA;AAON,SAAA,QAAA;AAMI,SAAA,YAAA;AAYF,SAAA,UAAA;A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AA;AA0KA,gBAAA;AAAA,EADC,MAAM,WAAW,EAAE,sBAAsB,KAAM,CAAA;AAAA,GA9OrC,gBA+OX,WAAA,uBAAA,CAAA;AAoBA,gBAAA;AAAA,EADC,MAAM,OAAO;AAAA,GAlQH,gBAmQX,WAAA,qBAAA,CAAA;AAnQW,kBAAN,gBAAA;AAAA,EADN,cAAc,iBAAiB;AAAA,GACnB,eAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"step-indicator.component.d.ts","sourceRoot":"","sources":["../../src/components/step-indicator.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAK5C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,kBAAkB,CAAC;KAC1C;CACF;;AAWD,qBACa,kBAAmB,SAAQ,uBAA0B;IAEhE,KAAK,SAAK;IAGV,OAAO,SAAK;IAEH,MAAM;CAyBhB"}
1
+ {"version":3,"file":"step-indicator.component.d.ts","sourceRoot":"","sources":["../../src/components/step-indicator.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAM5C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,kBAAkB,CAAC;KAC1C;CACF;;AAWD,qBACa,kBAAmB,SAAQ,uBAA0B;IAEhE,KAAK,SAAK;IAGV,OAAO,SAAK;IAEH,MAAM;CA0BhB"}
@@ -2,6 +2,7 @@ import { css, LitElement, html } from "lit";
2
2
  import { styled } from "../mixins/tailwind.mixin.js";
3
3
  import { property, customElement } from "lit/decorators.js";
4
4
  import { classMap } from "lit/directives/class-map.js";
5
+ import { ifDefined } from "lit/directives/if-defined.js";
5
6
  var __defProp = Object.defineProperty;
6
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
8
  var __decorateClass = (decorators, target, key, kind) => {
@@ -28,13 +29,14 @@ let MinidStepIndicator = class extends styled(LitElement, styles) {
28
29
  }
29
30
  render() {
30
31
  return html`
31
- <ul class="flex gap-8">
32
+ <ol class="flex gap-8">
32
33
  ${Array.from({ length: this.steps }).map((_, index) => {
33
34
  const step = index + 1;
34
35
  const isActive = step === this.current;
35
36
  const isCompleted = step < this.current;
36
37
  const isUpcoming = step > this.current;
37
38
  return html`<li
39
+ aria-current="${ifDefined(isActive ? "step" : void 0)}"
38
40
  class="${classMap({
39
41
  "after:bg-accent-base": isActive || isCompleted,
40
42
  "border-accent-base": isActive || isCompleted,
@@ -48,7 +50,7 @@ let MinidStepIndicator = class extends styled(LitElement, styles) {
48
50
  })} relative rounded-full border-4 p-1.5 after:absolute after:-left-1 after:block after:h-1 after:w-8 after:-translate-x-full after:-translate-y-1/2"
49
51
  ></li>`;
50
52
  })}
51
- </ul>
53
+ </ol>
52
54
  `;
53
55
  }
54
56
  };
@@ -1 +1 @@
1
- {"version":3,"file":"step-indicator.js","sources":["../../src/components/step-indicator.component.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { styled } from '../mixins/tailwind.mixin';\nimport { customElement, property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-step-indicator': MinidStepIndicator;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: flex;\n justify-content: center;\n }\n `,\n];\n\n@customElement('mid-step-indicator')\nexport class MinidStepIndicator extends styled(LitElement, styles) {\n @property({ type: Number })\n steps = 0;\n\n @property({ type: Number })\n current = 0;\n\n override render() {\n return html`\n <ul class=\"flex gap-8\">\n ${Array.from({ length: this.steps }).map((_, index) => {\n const step = index + 1;\n const isActive = step === this.current;\n const isCompleted = step < this.current;\n const isUpcoming = step > this.current;\n return html`<li\n class=\"${classMap({\n 'after:bg-accent-base': isActive || isCompleted,\n 'border-accent-base': isActive || isCompleted,\n 'after:bg-neutral-surface-active': isUpcoming,\n 'border-neutral-surface-active': isUpcoming,\n 'bg-neutral-surface-active': isUpcoming,\n 'after:bg-transparent': step === 1,\n 'bg-neutral-surface': isCompleted,\n 'bg-accent-base': isActive,\n 'bg-accent': isUpcoming,\n })} relative rounded-full border-4 p-1.5 after:absolute after:-left-1 after:block after:h-1 after:w-8 after:-translate-x-full after:-translate-y-1/2\"\n ></li>`;\n })}\n </ul>\n `;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAWA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAMF;AAGO,IAAM,qBAAN,cAAiC,OAAO,YAAY,MAAM,EAAE;AAAA,EAA5D,cAAA;AAAA,UAAA,GAAA,SAAA;AAEG,SAAA,QAAA;AAGE,SAAA,UAAA;AAAA,EAAA;AAAA,EAED,SAAS;AACT,WAAA;AAAA;AAAA,UAED,MAAM,KAAK,EAAE,QAAQ,KAAK,MAAO,CAAA,EAAE,IAAI,CAAC,GAAG,UAAU;AACrD,YAAM,OAAO,QAAQ;AACf,YAAA,WAAW,SAAS,KAAK;AACzB,YAAA,cAAc,OAAO,KAAK;AAC1B,YAAA,aAAa,OAAO,KAAK;AACxB,aAAA;AAAA,qBACI,SAAS;AAAA,QAChB,wBAAwB,YAAY;AAAA,QACpC,sBAAsB,YAAY;AAAA,QAClC,mCAAmC;AAAA,QACnC,iCAAiC;AAAA,QACjC,6BAA6B;AAAA,QAC7B,wBAAwB,SAAS;AAAA,QACjC,sBAAsB;AAAA,QACtB,kBAAkB;AAAA,QAClB,aAAa;AAAA,MAAA,CACd,CAAC;AAAA;AAAA,IAAA,CAEL,CAAC;AAAA;AAAA;AAAA,EAAA;AAIV;AA9BE,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,OAAQ,CAAA;AAAA,GADf,mBAEX,WAAA,SAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,OAAQ,CAAA;AAAA,GAJf,mBAKX,WAAA,WAAA,CAAA;AALW,qBAAN,gBAAA;AAAA,EADN,cAAc,oBAAoB;AAAA,GACtB,kBAAA;"}
1
+ {"version":3,"file":"step-indicator.js","sources":["../../src/components/step-indicator.component.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { styled } from '../mixins/tailwind.mixin';\nimport { customElement, property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-step-indicator': MinidStepIndicator;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: flex;\n justify-content: center;\n }\n `,\n];\n\n@customElement('mid-step-indicator')\nexport class MinidStepIndicator extends styled(LitElement, styles) {\n @property({ type: Number })\n steps = 0;\n\n @property({ type: Number })\n current = 0;\n\n override render() {\n return html`\n <ol class=\"flex gap-8\">\n ${Array.from({ length: this.steps }).map((_, index) => {\n const step = index + 1;\n const isActive = step === this.current;\n const isCompleted = step < this.current;\n const isUpcoming = step > this.current;\n return html`<li\n aria-current=\"${ifDefined(isActive ? 'step' : undefined)}\"\n class=\"${classMap({\n 'after:bg-accent-base': isActive || isCompleted,\n 'border-accent-base': isActive || isCompleted,\n 'after:bg-neutral-surface-active': isUpcoming,\n 'border-neutral-surface-active': isUpcoming,\n 'bg-neutral-surface-active': isUpcoming,\n 'after:bg-transparent': step === 1,\n 'bg-neutral-surface': isCompleted,\n 'bg-accent-base': isActive,\n 'bg-accent': isUpcoming,\n })} relative rounded-full border-4 p-1.5 after:absolute after:-left-1 after:block after:h-1 after:w-8 after:-translate-x-full after:-translate-y-1/2\"\n ></li>`;\n })}\n </ol>\n `;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAMF;AAGO,IAAM,qBAAN,cAAiC,OAAO,YAAY,MAAM,EAAE;AAAA,EAA5D,cAAA;AAAA,UAAA,GAAA,SAAA;AAEG,SAAA,QAAA;AAGE,SAAA,UAAA;AAAA,EAAA;AAAA,EAED,SAAS;AACT,WAAA;AAAA;AAAA,UAED,MAAM,KAAK,EAAE,QAAQ,KAAK,MAAO,CAAA,EAAE,IAAI,CAAC,GAAG,UAAU;AACrD,YAAM,OAAO,QAAQ;AACf,YAAA,WAAW,SAAS,KAAK;AACzB,YAAA,cAAc,OAAO,KAAK;AAC1B,YAAA,aAAa,OAAO,KAAK;AACxB,aAAA;AAAA,4BACW,UAAU,WAAW,SAAS,MAAS,CAAC;AAAA,qBAC/C,SAAS;AAAA,QAChB,wBAAwB,YAAY;AAAA,QACpC,sBAAsB,YAAY;AAAA,QAClC,mCAAmC;AAAA,QACnC,iCAAiC;AAAA,QACjC,6BAA6B;AAAA,QAC7B,wBAAwB,SAAS;AAAA,QACjC,sBAAsB;AAAA,QACtB,kBAAkB;AAAA,QAClB,aAAa;AAAA,MAAA,CACd,CAAC;AAAA;AAAA,IAAA,CAEL,CAAC;AAAA;AAAA;AAAA,EAAA;AAIV;AA/BE,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,OAAQ,CAAA;AAAA,GADf,mBAEX,WAAA,SAAA,CAAA;AAGA,gBAAA;AAAA,EADC,SAAS,EAAE,MAAM,OAAQ,CAAA;AAAA,GAJf,mBAKX,WAAA,WAAA,CAAA;AALW,qBAAN,gBAAA;AAAA,EADN,cAAc,oBAAoB;AAAA,GACtB,kBAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felleslosninger/minid-elements",
3
- "version": "0.0.107",
3
+ "version": "0.0.108",
4
4
  "description": "MinID Web Components",
5
5
  "author": "Digitaliseringsdirektoratet",
6
6
  "license": "MIT",