@proximus/lavender-fieldset 1.0.0-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,22 @@
1
+ import { PxElement } from '@proximus/lavender-common';
2
+ export declare class Fieldset extends PxElement<HTMLFieldSetElement> {
3
+ static nativeName: string;
4
+ private template;
5
+ constructor();
6
+ static get observedAttributes(): string[];
7
+ connectedCallback(): void;
8
+ attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
9
+ setupErrorState(): void;
10
+ get $slotLegend(): HTMLSlotElement;
11
+ get $slotError(): HTMLSlotElement;
12
+ get inverted(): boolean;
13
+ set inverted(value: boolean);
14
+ get role(): string;
15
+ set role(value: string);
16
+ get ariaRequired(): string;
17
+ set ariaRequired(value: string);
18
+ get ariaDisabled(): string;
19
+ set ariaDisabled(value: string);
20
+ get state(): string;
21
+ set state(value: string);
22
+ }
@@ -0,0 +1 @@
1
+ export * from './Fieldset';
@@ -0,0 +1,109 @@
1
+ import { PxElement as a, transferAccessibilityAttributes as d } from "@proximus/lavender-common";
2
+ const n = ':host{display:block}:host *{box-sizing:border-box}fieldset{display:flex;flex-direction:column;margin:0;padding:0;border:0;font-family:var(--px-font-family)}fieldset legend{padding:0}fieldset ::slotted([slot="legend"]:not([shown--sr])){display:block;margin-bottom:var(--px-spacing-xs-mobile)}fieldset ::slotted([slot="error-text"]){display:none;font-size:var(--px-text-size-body-m-mobile);line-height:var(--px-line-height-ratio-l);color:var(--px-color-text-purpose-error-default);margin-bottom:var(--px-spacing-xs-mobile)}:host([state="error"]) ::slotted([slot="error-text"]){display:block}@media only screen and (min-width: 48em){fieldset ::slotted([slot="legend"]:not([shown--sr])){margin-bottom:var(--px-spacing-xs-tablet)}fieldset ::slotted([slot="error-text"]){font-size:var(--px-text-size-body-m-tablet)}}@media only screen and (min-width: 64.0625em){fieldset ::slotted([slot="legend"]:not([shown--sr])){margin-bottom:var(--px-spacing-xs-laptop)}fieldset ::slotted([slot="error-text"]){font-size:var(--px-text-size-body-m-laptop)}}@media only screen and (min-width: 90.0625em){fieldset ::slotted([slot="legend"]:not([shown--sr])){margin-bottom:var(--px-spacing-xs-desktop)}fieldset ::slotted([slot="error-text"]){font-size:var(--px-text-size-body-m-desktop)}}:host([inverted]) fieldset ::slotted([slot="error-text"]){color:var(--px-color-text-purpose-error-inverted)}', o = new CSSStyleSheet();
3
+ o.replaceSync(n);
4
+ const i = class i extends a {
5
+ constructor() {
6
+ super(o), this.template = () => `<fieldset >
7
+ <legend><slot name="legend"></slot></legend>
8
+ <slot name="error-text"></slot>
9
+ <slot></slot>
10
+ </fieldset>`, this.shadowRoot.innerHTML = this.template();
11
+ }
12
+ static get observedAttributes() {
13
+ return [
14
+ ...super.observedAttributes,
15
+ "inverted",
16
+ "role",
17
+ "aria-required",
18
+ "aria-disabled",
19
+ "state"
20
+ ];
21
+ }
22
+ connectedCallback() {
23
+ var t;
24
+ ((t = this.$slotLegend) == null ? void 0 : t.assignedNodes().length) > 0 || console.error(
25
+ '<px-fieldset> requires a slot="legend" containing the description of the fieldset.'
26
+ ), this.setupErrorState(), d(this, this.$el, !1);
27
+ }
28
+ attributeChangedCallback(e, t, r) {
29
+ if (t !== r)
30
+ switch (e) {
31
+ case "disabled": {
32
+ this.querySelectorAll(
33
+ "px-radio-group, px-radio, px-checkbox, px-fileupload, px-input, px-textarea, px-select, px-switch"
34
+ ).forEach((l) => {
35
+ l.setAttribute(e, "true");
36
+ });
37
+ break;
38
+ }
39
+ case "role":
40
+ case "aria-required":
41
+ case "aria-disabled":
42
+ r !== null && (this.$el.setAttribute(e, this.getAttribute(e)), this.removeAttribute(e));
43
+ break;
44
+ case "state":
45
+ this.setupErrorState();
46
+ break;
47
+ default:
48
+ super.attributeChangedCallback(e, t, r);
49
+ break;
50
+ }
51
+ }
52
+ setupErrorState() {
53
+ var t;
54
+ const e = ((t = this.$slotError) == null ? void 0 : t.assignedNodes().length) > 0;
55
+ if (this.state === "error" && !e && console.error(
56
+ '<px-fieldset> with state="error" requires a slot="error-text" containing the error description.'
57
+ ), this.state === "error" && e) {
58
+ const r = Math.random().toString(36).substr(2, 9);
59
+ this.$el.setAttribute("id", r), this.$el.setAttribute("aria-describedby", `${r}-error-text`), this.$el.setAttribute("aria-invalid", "true"), this.$slotError.setAttribute("id", `${r}-error-text`);
60
+ } else
61
+ this.$el.removeAttribute("id"), this.$el.removeAttribute("aria-describedby"), this.$el.removeAttribute("aria-invalid"), this.$slotError.removeAttribute("id");
62
+ }
63
+ get $slotLegend() {
64
+ return this.shadowRoot.querySelector(
65
+ 'slot[name="legend"]'
66
+ );
67
+ }
68
+ get $slotError() {
69
+ return this.shadowRoot.querySelector(
70
+ 'slot[name="error-text"]'
71
+ );
72
+ }
73
+ get inverted() {
74
+ return this.hasAttribute("inverted");
75
+ }
76
+ set inverted(e) {
77
+ e ? this.setAttribute("inverted", "") : this.removeAttribute("inverted");
78
+ }
79
+ get role() {
80
+ return this.getAttribute("role");
81
+ }
82
+ set role(e) {
83
+ e ? this.setAttribute("role", e) : this.removeAttribute("role");
84
+ }
85
+ get ariaRequired() {
86
+ return this.getAttribute("aria-required");
87
+ }
88
+ set ariaRequired(e) {
89
+ e ? this.setAttribute("aria-required", e) : this.removeAttribute("aria-required");
90
+ }
91
+ get ariaDisabled() {
92
+ return this.getAttribute("aria-disabled");
93
+ }
94
+ set ariaDisabled(e) {
95
+ e ? this.setAttribute("aria-disabled", e) : this.removeAttribute("aria-disabled");
96
+ }
97
+ get state() {
98
+ return this.getAttribute("state");
99
+ }
100
+ set state(e) {
101
+ e ? this.setAttribute("state", e) : this.removeAttribute("state");
102
+ }
103
+ };
104
+ i.nativeName = "fieldset";
105
+ let s = i;
106
+ customElements.get("px-fieldset") || customElements.define("px-fieldset", s);
107
+ export {
108
+ s as Fieldset
109
+ };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@proximus/lavender-fieldset",
3
+ "version": "1.0.0-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
+ "gitHead": "460ebd4c7e0171baabc0871a7058f475b5c9adbb"
24
+ }