@proximus/lavender-phone-number 1.4.15-alpha.10

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.
@@ -0,0 +1,36 @@
1
+ import { PxElement } from '@proximus/lavender-common';
2
+ import '@proximus/lavender-layout';
3
+ import '@proximus/lavender-fieldset';
4
+ export declare class PhoneNumber extends PxElement<HTMLElement> {
5
+ static nativeName: string;
6
+ template: () => string;
7
+ private selectStateObserver?;
8
+ private inputStateObserver?;
9
+ private readonly onSelectSlotChange;
10
+ private readonly onInputSlotChange;
11
+ private readonly onHelperSlotChange;
12
+ constructor();
13
+ connectedCallback(): void;
14
+ disconnectedCallback(): void;
15
+ static get observedAttributes(): string[];
16
+ attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
17
+ setupErrorState(): void;
18
+ ensureHelperId(): string;
19
+ updateAriaDescribedBy(element: HTMLElement | null, helperId: string, errorId: string): void;
20
+ applyHiddenLabel(): void;
21
+ observeSlottedFieldState(): void;
22
+ get $fieldset(): Element;
23
+ get $slottedHelper(): HTMLElement | null;
24
+ get $slotStateText(): HTMLSlotElement | null;
25
+ get $slotHelper(): HTMLSlotElement | null;
26
+ get $slotSelect(): HTMLSlotElement | null;
27
+ get $slotInput(): HTMLSlotElement | null;
28
+ get $slottedSelect(): HTMLElement | null;
29
+ get $slottedInput(): HTMLElement | null;
30
+ get $slottedSelectLabel(): HTMLElement | null;
31
+ get $slottedInputLabel(): HTMLElement | null;
32
+ get state(): string;
33
+ set state(value: string | null);
34
+ get inverted(): boolean;
35
+ set inverted(value: string | null);
36
+ }
@@ -0,0 +1 @@
1
+ export * from './PhoneNumber';
@@ -0,0 +1,120 @@
1
+ import { PxElement as e, log as t } from "@proximus/lavender-common";
2
+ import "@proximus/lavender-layout";
3
+ import "@proximus/lavender-fieldset";
4
+ //#region src/phone-number.css?inline
5
+ var n = ":host{display:block}:host *{box-sizing:border-box}::slotted([slot=label]){font-family:var(--px-font-family);font-size:var(--px-text-size-label-m-mobile);font-weight:var(--px-font-weight-body);line-height:var(--px-line-height-ratio-l);text-align:left;color:var(--px-color-text-neutral-default);margin-bottom:var(--px-spacing-2xs-mobile);display:block}@media screen and (width>=48rem){::slotted([slot=label]){font-size:var(--px-text-size-label-m-tablet);margin-bottom:var(--px-spacing-2xs-tablet)}}@media screen and (width>=64.0625rem){::slotted([slot=label]){font-size:var(--px-text-size-label-m-laptop);margin-bottom:var(--px-spacing-2xs-laptop)}}@media screen and (width>=90.0625rem){::slotted([slot=label]){font-size:var(--px-text-size-label-m-desktop);margin-bottom:var(--px-spacing-2xs-desktop)}}", r = new CSSStyleSheet();
6
+ r.replaceSync(n);
7
+ var i = class extends e {
8
+ static {
9
+ this.nativeName = "div";
10
+ }
11
+ constructor() {
12
+ super(r), this.template = () => "<px-fieldset>\n <slot name=\"label\" slot=\"legend\"></slot>\n <slot name=\"helper\" slot=\"helper\"></slot>\n <slot name=\"state-text\" slot=\"error-text\"></slot>\n <px-hstack gap=\"xs\">\n <slot name=\"select\"></slot>\n <slot name=\"input\"></slot>\n </px-hstack>\n </px-fieldset>", this.onSelectSlotChange = () => {
13
+ this.applyHiddenLabel(), this.observeSlottedFieldState(), this.setupErrorState();
14
+ }, this.onInputSlotChange = () => {
15
+ this.applyHiddenLabel(), this.observeSlottedFieldState(), this.setupErrorState();
16
+ }, this.onHelperSlotChange = () => {
17
+ this.setupErrorState();
18
+ }, this.shadowRoot.innerHTML = this.template();
19
+ }
20
+ connectedCallback() {
21
+ this.$slotSelect?.addEventListener("slotchange", this.onSelectSlotChange), this.$slotInput?.addEventListener("slotchange", this.onInputSlotChange), this.$slotHelper?.addEventListener("slotchange", this.onHelperSlotChange), this.applyHiddenLabel(), this.observeSlottedFieldState(), this.setupErrorState();
22
+ }
23
+ disconnectedCallback() {
24
+ this.$slotSelect?.removeEventListener("slotchange", this.onSelectSlotChange), this.$slotInput?.removeEventListener("slotchange", this.onInputSlotChange), this.$slotHelper?.removeEventListener("slotchange", this.onHelperSlotChange), this.selectStateObserver?.disconnect(), this.inputStateObserver?.disconnect();
25
+ }
26
+ static get observedAttributes() {
27
+ return [...super.observedAttributes, "state"];
28
+ }
29
+ attributeChangedCallback(e, t, n) {
30
+ if (t !== n) switch (e) {
31
+ case "state":
32
+ this.setupErrorState();
33
+ break;
34
+ default: super.attributeChangedCallback(e, t, n);
35
+ }
36
+ }
37
+ setupErrorState() {
38
+ let e = this.$slotStateText, n = (e?.assignedNodes().length ?? 0) > 0, r = this.ensureHelperId(), i = "";
39
+ if (this.state === "error" && !n && t("<px-fieldset> with state=\"error\" requires a slot=\"error-text\" containing the error description."), this.state === "error" && n) {
40
+ this.$fieldset.setAttribute("state", "error");
41
+ let t = Math.random().toString(36).substr(2, 9);
42
+ e?.setAttribute("id", `${t}-state-text`), i = `${t}-state-text`, this.$slottedSelect?.getAttribute("state") === "error" ? this.$slottedSelect.setAttribute("aria-invalid", "true") : this.$slottedSelect?.removeAttribute("aria-invalid"), this.$slottedInput?.getAttribute("state") === "error" ? this.$slottedInput.setAttribute("aria-invalid", "true") : this.$slottedInput?.removeAttribute("aria-invalid");
43
+ } else this.$fieldset.removeAttribute("state"), this.$slottedSelect?.removeAttribute("aria-invalid"), this.$slottedInput?.removeAttribute("aria-invalid"), e?.removeAttribute("id");
44
+ this.updateAriaDescribedBy(this.$slottedSelect, r, this.$slottedSelect?.getAttribute("state") === "error" ? i : ""), this.updateAriaDescribedBy(this.$slottedInput, r, this.$slottedInput?.getAttribute("state") === "error" ? i : "");
45
+ }
46
+ ensureHelperId() {
47
+ if (!this.$slottedHelper) return "";
48
+ if (!this.$slottedHelper.id) {
49
+ let e = Math.random().toString(36).substr(2, 9);
50
+ this.$slottedHelper.setAttribute("id", `${e}-helper`);
51
+ }
52
+ return this.$slottedHelper.id;
53
+ }
54
+ updateAriaDescribedBy(e, t, n) {
55
+ if (!e) return;
56
+ let r = [t, n].filter(Boolean).join(" ");
57
+ r ? e.setAttribute("aria-describedby", r) : e.removeAttribute("aria-describedby");
58
+ }
59
+ applyHiddenLabel() {
60
+ this.$slottedSelect?.setAttribute("hidden-label", ""), this.$slottedInput?.setAttribute("hidden-label", ""), this.$slottedSelectLabel?.setAttribute("shown--sr", ""), this.$slottedInputLabel?.setAttribute("shown--sr", "");
61
+ }
62
+ observeSlottedFieldState() {
63
+ this.selectStateObserver?.disconnect(), this.inputStateObserver?.disconnect(), this.$slottedSelect && (this.selectStateObserver = new MutationObserver(() => {
64
+ this.setupErrorState();
65
+ }), this.selectStateObserver.observe(this.$slottedSelect, {
66
+ attributes: !0,
67
+ attributeFilter: ["state"]
68
+ })), this.$slottedInput && (this.inputStateObserver = new MutationObserver(() => {
69
+ this.setupErrorState();
70
+ }), this.inputStateObserver.observe(this.$slottedInput, {
71
+ attributes: !0,
72
+ attributeFilter: ["state"]
73
+ }));
74
+ }
75
+ get $fieldset() {
76
+ return this.shadowRoot.querySelector("px-fieldset");
77
+ }
78
+ get $slottedHelper() {
79
+ return this.querySelector("[slot=\"helper\"]");
80
+ }
81
+ get $slotStateText() {
82
+ return this.shadowRoot.querySelector("slot[name=\"state-text\"]");
83
+ }
84
+ get $slotHelper() {
85
+ return this.shadowRoot.querySelector("slot[name=\"helper\"]");
86
+ }
87
+ get $slotSelect() {
88
+ return this.shadowRoot.querySelector("slot[name=\"select\"]");
89
+ }
90
+ get $slotInput() {
91
+ return this.shadowRoot.querySelector("slot[name=\"input\"]");
92
+ }
93
+ get $slottedSelect() {
94
+ return this.querySelector("[slot=\"select\"]");
95
+ }
96
+ get $slottedInput() {
97
+ return this.querySelector("[slot=\"input\"]");
98
+ }
99
+ get $slottedSelectLabel() {
100
+ return this.$slottedSelect?.querySelector("[slot=\"label\"]");
101
+ }
102
+ get $slottedInputLabel() {
103
+ return this.$slottedInput?.querySelector("[slot=\"label\"]");
104
+ }
105
+ get state() {
106
+ return this.getAttribute("state") || "";
107
+ }
108
+ set state(e) {
109
+ super._updateAttribute("state", e);
110
+ }
111
+ get inverted() {
112
+ return this.hasAttribute("inverted");
113
+ }
114
+ set inverted(e) {
115
+ super._updateAttribute("inverted", e);
116
+ }
117
+ };
118
+ customElements.get("px-phone-number") || customElements.define("px-phone-number", i);
119
+ //#endregion
120
+ export { i as PhoneNumber };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@proximus/lavender-phone-number",
3
+ "version": "1.4.15-alpha.10",
4
+ "description": "",
5
+ "main": "dist/index.es.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "type": "module",
11
+ "scripts": {
12
+ "transform-package-json": "node ../../../scripts/tranformPackageJson.js package.json dist/far/away",
13
+ "clean": "rm -rf dist",
14
+ "build": "npm run clean && NODE_ENV=development vite build && tsc && npm run transform-package-json && npm run wc-manifest",
15
+ "test": "vitest run --coverage",
16
+ "wc-manifest": "cem analyze --globs \"src/*\" --config ../../custom-elements-manifest.config.js --outdir dist"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "customElements": "dist/custom-elements.json",
22
+ "web-types": "./dist/web-types.json"
23
+ }