@proximus/lavender-radio-group 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +170 -0
  2. package/package.json +41 -0
package/dist/index.js ADDED
@@ -0,0 +1,170 @@
1
+ import { PxElement as c } from "@proximus/lavender-common";
2
+ const b = `:host{display:block}.radio{display:flex;align-items:center;gap:var(--px-spacing-after-element-s-mobile);align-items:flex-start}label{font-family:var(--px-font-family);font-size:var(--px-text-size-label-m-mobile);line-height:calc(var(--px-line-height-m) * 1rem);font-weight:400;color:var(--px-text-color-heading-neutral-default)}input{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0;border-radius:var(--px-radius-pill);border:var(--px-border-size-m) solid var(--px-border-color-action-neutral-default);width:var(--px-action-size-m);height:var(--px-action-size-m);flex-shrink:0;transition:box-shadow .3s ease-out,background-color .3s;animation:anim-pop .2s cubic-bezier(.9,-.13,.61,.99) forwards .1s}input:checked{background-color:var(--px-background-color-action-primary-default);border-color:var(--px-border-color-none);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='white'/%3E%3C/svg%3E");background-position:center center}input:hover:not([disabled]){border:var(--px-border-size-l) solid var(--px-border-color-action-hover-default)}input:checked:not([disabled]):hover{box-shadow:inset 0 0 0 var(--px-border-size-s) var(--px-border-color-action-hover-default),0 0 0 var(--px-border-size-s) var(--px-border-color-action-hover-default)}input:disabled{background-color:var(--px-background-color-action-disabled-default);border-color:var(--px-border-color-container-main-default)}input:disabled:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='black' fill-opacity='0.12'/%3E%3C/svg%3E")}input:disabled+label{color:var(--px-text-color-action-disabled-default)}input.error:not(:disabled){border-color:var(--px-border-color-purpose-error-default)}input.error:not(:disabled):checked{background-color:var(--px-background-color-purpose-error-default)}input.error:not(:disabled):checked:hover{background-color:var(--px-background-color-action-primary-default)}input[inverted]{border-color:var(--px-border-color-action-neutral-inverted)}input[inverted]:checked{background-color:var(--px-background-color-action-primary-inverted);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='%235C2D91'/%3E%3C/svg%3E")}input[inverted]:hover:not([disabled]){border-color:var(--px-border-color-action-hover-inverted)}input[inverted]:checked:not([disabled]):hover{box-shadow:inset 0 0 0 var(--px-border-size-s) var(--px-border-color-action-hover-inverted),0 0 0 var(--px-border-size-s) var(--px-border-color-action-hover-inverted)}input[inverted]:disabled{background-color:var(--px-background-color-action-disabled-inverted);border-color:var(--px-border-color-container-main-inverted)}input[inverted]:disabled:checked{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='white' fill-opacity='0.16'/%3E%3C/svg%3E")}input[inverted]:disabled+label{color:var(--px-text-color-action-disabled-inverted)}input[inverted].error:not(:disabled){border-color:var(--px-border-color-purpose-error-inverted)}input[inverted].error:not(:disabled):checked{background-color:var(--px-background-color-purpose-error-inverted);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='white'/%3E%3C/svg%3E")}input[inverted].error:not(:disabled):checked:hover{background-color:var(--px-background-color-action-primary-inverted);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Ccircle cx='12' cy='12' r='4' fill='%235C2D91'/%3E%3C/svg%3E")}input[inverted]+label{color:var(--px-text-color-heading-neutral-inverted)}@media only screen and (min-width: 768px){.radio{gap:var(--px-spacing-after-element-s-tablet)}label{font-size:var(--px-text-size-label-m-tablet)}}@media only screen and (min-width: 1025px){.radio{gap:var(--px-spacing-after-element-s-desktop)}label{font-size:var(--px-text-size-label-m-desktop)}}@keyframes anim-pop{0%{transform:scale(0)}to{transform:scale(1)}}`, h = new CSSStyleSheet();
3
+ h.replaceSync(b);
4
+ var u = /* @__PURE__ */ ((o) => (o.ERROR = "error", o.SUCCESS = "success", o))(u || {});
5
+ const l = class l extends c {
6
+ constructor() {
7
+ var e;
8
+ super(h), this.template = () => `<div class="radio" tabindex="0" role="radio">
9
+ <input type="radio" tabindex="-1" />
10
+ <label><slot name="label"></slot></label>
11
+ </div>`, this.shadowRoot && (this.shadowRoot.innerHTML = this.template()), this.internals = (e = this.attachInternals) == null ? void 0 : e.call(this);
12
+ }
13
+ static get observedAttributes() {
14
+ return [...super.observedAttributes, "state", "inverted"];
15
+ }
16
+ connectedCallback() {
17
+ this.$el.addEventListener("change", () => {
18
+ var t;
19
+ const e = new Event("change", {
20
+ bubbles: !0,
21
+ composed: !0
22
+ // Allow the event to pass through shadow DOM boundaries
23
+ });
24
+ this.dispatchEvent(e), (t = this.internals) == null || t.setFormValue(this.formData());
25
+ }), this.addEventListener("keypress", (e) => {
26
+ (e.code === "Space" || e.code === "Enter") && this.$el.click();
27
+ }), this.setupForId(), this.hasAttribute("checked") && (this.checked = !0);
28
+ }
29
+ attributeChangedCallback(e, t, r) {
30
+ e === "state" && t !== r ? this.stateChangeCallback(t, r) : super.attributeChangedCallback(e, t, r);
31
+ }
32
+ stateChangeCallback(e, t) {
33
+ e !== null && this.$el.classList.toggle(e), t !== null && this.$el.classList.toggle(t);
34
+ }
35
+ formData() {
36
+ if (this.$el.name) {
37
+ const e = new FormData(), t = this.getAttribute("name");
38
+ return t && e.append(t, this.$el.value), e;
39
+ }
40
+ }
41
+ // Form-associated callbacks
42
+ static get formAssociated() {
43
+ return !0;
44
+ }
45
+ // Set default behavior when the element is attached to a form
46
+ formResetCallback() {
47
+ this.$el.value = "";
48
+ }
49
+ formStateRestoreCallback(e) {
50
+ this.$el.value = e;
51
+ }
52
+ setupForId() {
53
+ const e = Math.random().toString(36).substr(2, 9);
54
+ this.$el.setAttribute("id", e), this.$label && this.$label.setAttribute("for", e);
55
+ }
56
+ get state() {
57
+ return this.getAttribute("state");
58
+ }
59
+ set state(e) {
60
+ this.setAttribute("state", e);
61
+ }
62
+ get disabled() {
63
+ return this.getAttribute("disabled");
64
+ }
65
+ set disabled(e) {
66
+ this.setAttribute("disabled", e);
67
+ }
68
+ get $label() {
69
+ return this.shadowRoot.querySelector("label");
70
+ }
71
+ get inverted() {
72
+ return this.getAttribute("inverted");
73
+ }
74
+ set inverted(e) {
75
+ this.setAttribute("inverted", e);
76
+ }
77
+ get checked() {
78
+ return this.$el.checked;
79
+ }
80
+ set checked(e) {
81
+ this.$el.checked = e, e ? this.setAttribute("checked", "") : this.removeAttribute("checked");
82
+ }
83
+ get $radio() {
84
+ return this.shadowRoot.querySelector('div[role="radio"]');
85
+ }
86
+ };
87
+ l.nativeName = "input";
88
+ let s = l;
89
+ customElements.define("px-radio", s);
90
+ const d = class d extends c {
91
+ constructor() {
92
+ var e;
93
+ super(), this.template = () => `<div role="radiogroup">
94
+ <slot></slot>
95
+ </div>`, this.handleRadioChange = (t) => {
96
+ const r = t.target;
97
+ if (r.localName === "px-radio") {
98
+ const i = r.getAttribute("name");
99
+ i && this.uncheckOtherRadios(i, r);
100
+ }
101
+ }, this.shadowRoot.innerHTML = this.template(), this.internals = (e = this.attachInternals) == null ? void 0 : e.call(this);
102
+ }
103
+ static get observedAttributes() {
104
+ return [
105
+ ...super.observedAttributes,
106
+ "name",
107
+ "required",
108
+ "disabled",
109
+ "state",
110
+ "inverted"
111
+ ];
112
+ }
113
+ connectedCallback() {
114
+ (!this.hasAttribute("name") || this.getAttribute("name") === "") && console.error(
115
+ '<px-radio-group> requires a "name" attribute to function properly.'
116
+ ), this.addEventListener("change", this.handleRadioChange);
117
+ }
118
+ disconnectedCallback() {
119
+ this.removeEventListener("change", this.handleRadioChange);
120
+ }
121
+ attributeChangedCallback(e, t, r) {
122
+ t !== r && this.querySelectorAll("px-radio").forEach((a) => {
123
+ if (r === null)
124
+ a.removeAttribute(e);
125
+ else
126
+ switch (e) {
127
+ case "required":
128
+ this.$el.ariaRequired = "true";
129
+ break;
130
+ case "state":
131
+ r === "error" && (this.$el.ariaInvalid = "true", a.setAttribute(e, r));
132
+ break;
133
+ case "disabled":
134
+ this.$el.ariaDisabled = "true", a.setAttribute(e, r);
135
+ break;
136
+ default:
137
+ a.setAttribute(e, r);
138
+ break;
139
+ }
140
+ });
141
+ }
142
+ uncheckOtherRadios(e, t) {
143
+ this.querySelectorAll(`px-radio[name="${e}"]`).forEach((i) => {
144
+ i !== t ? (i.checked = !1, i.$radio.ariaChecked = "false") : (i.checked = !0, i.$radio.ariaChecked = "true");
145
+ });
146
+ }
147
+ get state() {
148
+ return this.getAttribute("state");
149
+ }
150
+ set state(e) {
151
+ this.setAttribute("state", e);
152
+ }
153
+ get $label() {
154
+ return this.shadowRoot.querySelector("label");
155
+ }
156
+ get inverted() {
157
+ return this.getAttribute("inverted");
158
+ }
159
+ set inverted(e) {
160
+ this.setAttribute("inverted", e);
161
+ }
162
+ };
163
+ d.nativeName = "div";
164
+ let n = d;
165
+ customElements.define("px-radio-group", n);
166
+ export {
167
+ u as InputState,
168
+ s as Radio,
169
+ n as Radiogroup
170
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@proximus/lavender-radio-group",
3
+ "version": "1.0.0-alpha.2",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "development": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./src/*.css": {
13
+ "development": "src/*.css"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "type": "module",
20
+ "scripts": {
21
+ "build": "rm -rf dist;tsc; vite build",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "gitHead": "bad89d519c6fc1d431ebc46bee89fcd80cf18b83",
28
+ "lerna": {
29
+ "command": {
30
+ "publish": {
31
+ "assets": [
32
+ "CHANGELOG.md",
33
+ "package.json",
34
+ "dist/*.js",
35
+ "dist/*.cjs",
36
+ "dist/css/**/*.css"
37
+ ]
38
+ }
39
+ }
40
+ }
41
+ }