@oslokommune/punkt-elements 13.17.0 → 13.18.1
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/CHANGELOG.md +18 -0
- package/dist/{checkbox-CCFBIf44.js → checkbox-CCmRUWTH.js} +28 -25
- package/dist/checkbox-CqoOG2KJ.cjs +31 -0
- package/dist/index.d.ts +1 -0
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +1 -1
- package/package.json +3 -3
- package/src/components/checkbox/checkbox.test.ts +73 -0
- package/src/components/checkbox/checkbox.ts +14 -0
- package/dist/checkbox-UT6D1Wi0.cjs +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [13.18.0](https://github.com/oslokommune/punkt/compare/13.17.0...13.18.0) (2025-12-22)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
* Checkbox med state "indeterminate" som prop (#3148).
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
Ingen
|
|
19
|
+
|
|
20
|
+
### Chores
|
|
21
|
+
Ingen
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
|
|
8
26
|
## [13.15.4](https://github.com/oslokommune/punkt/compare/13.15.3...13.15.4) (2025-11-11)
|
|
9
27
|
|
|
10
28
|
### ⚠ BREAKING CHANGES
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { E as
|
|
1
|
+
import { E as r, x as p, n as s, a as d } from "./element-CRDRygXu.js";
|
|
2
2
|
import { P as k } from "./input-element-Dqu8udwd.js";
|
|
3
|
-
import { e as f, n as
|
|
4
|
-
import { e as
|
|
5
|
-
var
|
|
6
|
-
for (var h = l > 1 ? void 0 : l ?
|
|
7
|
-
(
|
|
8
|
-
return l && h &&
|
|
3
|
+
import { e as f, n as b } from "./ref-Xa5dbh--.js";
|
|
4
|
+
import { e as u } from "./class-map-wy7PUk0P.js";
|
|
5
|
+
var g = Object.defineProperty, m = Object.getOwnPropertyDescriptor, i = (t, a, n, l) => {
|
|
6
|
+
for (var h = l > 1 ? void 0 : l ? m(a, n) : a, c = t.length - 1, o; c >= 0; c--)
|
|
7
|
+
(o = t[c]) && (h = (l ? o(a, n, h) : o(h)) || h);
|
|
8
|
+
return l && h && g(a, n, h), h;
|
|
9
9
|
};
|
|
10
10
|
let e = class extends k {
|
|
11
11
|
constructor() {
|
|
12
|
-
super(...arguments), this.inputRef = f(), this.value = "", this.checkHelptext = null, this.defaultChecked = !1, this.hasTile = !1, this.isSwitch = !1, this.labelPosition = "right", this.hideLabel = !1, this.checked = null, this.type = "checkbox", this.tagText = null, this.optionalTag = !1, this.optionalText = "Valgfritt", this.requiredTag = !1, this.requiredText = "Må fylles ut";
|
|
12
|
+
super(...arguments), this.inputRef = f(), this.value = "", this.checkHelptext = null, this.defaultChecked = !1, this.hasTile = !1, this.isSwitch = !1, this.labelPosition = "right", this.hideLabel = !1, this.checked = null, this.indeterminate = !1, this.type = "checkbox", this.tagText = null, this.optionalTag = !1, this.optionalText = "Valgfritt", this.requiredTag = !1, this.requiredText = "Må fylles ut";
|
|
13
13
|
}
|
|
14
14
|
connectedCallback() {
|
|
15
15
|
super.connectedCallback();
|
|
16
16
|
}
|
|
17
|
-
attributeChangedCallback(t, a,
|
|
18
|
-
t === "defaultChecked" && !this.checked && (this.checked = this.defaultChecked), t === "checked" && (this.checked = this.checked === "" || this.checked === "true" || this.checked === !0, this.inputRef.value && (this.inputRef.value.checked = this.checked)), super.attributeChangedCallback(t, a,
|
|
17
|
+
attributeChangedCallback(t, a, n) {
|
|
18
|
+
t === "defaultChecked" && !this.checked && (this.checked = this.defaultChecked), t === "checked" && (this.checked = this.checked === "" || this.checked === "true" || this.checked === !0, this.inputRef.value && (this.inputRef.value.checked = this.checked)), t === "indeterminate" && (this.indeterminate = this.indeterminate === "" || this.indeterminate === "true" || this.indeterminate === !0, this.inputRef.value && (this.inputRef.value.indeterminate = this.indeterminate)), super.attributeChangedCallback(t, a, n);
|
|
19
19
|
}
|
|
20
20
|
firstUpdated(t) {
|
|
21
|
-
t.has("defaultChecked") && !this.checked && (this.checked = this.defaultChecked), super.firstUpdated(t);
|
|
21
|
+
t.has("defaultChecked") && !this.checked && (this.checked = this.defaultChecked), this.inputRef.value && (this.inputRef.value.indeterminate = this.indeterminate === "" || this.indeterminate === "true" || this.indeterminate === !0), super.firstUpdated(t);
|
|
22
22
|
}
|
|
23
23
|
updated(t) {
|
|
24
|
-
t.has("defaultChecked") && !this.checked && (this.checked = this.defaultChecked), t.has("checked") && this.inputRef.value && (this.inputRef.value.checked = this.checked === "" || this.checked === "true" || this.checked === !0), super.updated(t);
|
|
24
|
+
t.has("defaultChecked") && !this.checked && (this.checked = this.defaultChecked), t.has("checked") && this.inputRef.value && (this.inputRef.value.checked = this.checked === "" || this.checked === "true" || this.checked === !0), t.has("indeterminate") && this.inputRef.value && (this.inputRef.value.indeterminate = this.indeterminate === "" || this.indeterminate === "true" || this.indeterminate === !0), super.updated(t);
|
|
25
25
|
}
|
|
26
26
|
render() {
|
|
27
|
-
const t =
|
|
27
|
+
const t = u({
|
|
28
28
|
"pkt-input-check__input": !0,
|
|
29
29
|
"pkt-input-check__input--tile": this.hasTile,
|
|
30
30
|
"pkt-input-check__input--tile-disabled": this.disabled && this.hasTile
|
|
31
|
-
}), a =
|
|
31
|
+
}), a = u({
|
|
32
32
|
"pkt-input-check__input-checkbox": !0,
|
|
33
33
|
"pkt-input-check__input-checkbox--error": this.hasError
|
|
34
|
-
}),
|
|
34
|
+
}), n = u({
|
|
35
35
|
"pkt-input-check__input-label": !0,
|
|
36
36
|
"pkt-input-check__input-label--disabled": this.disabled,
|
|
37
37
|
"pkt-input-check__input-label--left": this.labelPosition === "left",
|
|
38
38
|
"pkt-input-check__input-label--right": this.labelPosition === "right",
|
|
39
39
|
"pkt-sr-only": this.hideLabel
|
|
40
40
|
}), l = "pkt-tag pkt-tag--small pkt-tag--thin-text", h = () => p`
|
|
41
|
-
${this.tagText ? p`<span class=${l + " pkt-tag--gray"}>${this.tagText}</span>` :
|
|
42
|
-
${this.optionalTag ? p`<span class=${l + " pkt-tag--blue-light"}>${this.optionalText}</span>` :
|
|
43
|
-
${this.requiredTag ? p`<span class=${l + " pkt-tag--beige"}>${this.requiredText}</span>` :
|
|
44
|
-
`,
|
|
45
|
-
<label class=${
|
|
41
|
+
${this.tagText ? p`<span class=${l + " pkt-tag--gray"}>${this.tagText}</span>` : r}
|
|
42
|
+
${this.optionalTag ? p`<span class=${l + " pkt-tag--blue-light"}>${this.optionalText}</span>` : r}
|
|
43
|
+
${this.requiredTag ? p`<span class=${l + " pkt-tag--beige"}>${this.requiredText}</span>` : r}
|
|
44
|
+
`, c = () => p`
|
|
45
|
+
<label class=${n} for=${this.id + "-internal"}>
|
|
46
46
|
${this.label} ${h()}
|
|
47
|
-
${this.checkHelptext ? p`<div class="pkt-input-check__input-helptext">${this.checkHelptext}</div>` :
|
|
47
|
+
${this.checkHelptext ? p`<div class="pkt-input-check__input-helptext">${this.checkHelptext}</div>` : r}
|
|
48
48
|
</label>
|
|
49
49
|
`;
|
|
50
50
|
return p`
|
|
51
51
|
<div class="pkt-input-check">
|
|
52
52
|
<div class=${t}>
|
|
53
|
-
${this.labelPosition === "left" ?
|
|
53
|
+
${this.labelPosition === "left" ? c() : r}
|
|
54
54
|
<input
|
|
55
55
|
id=${this.id + "-internal"}
|
|
56
56
|
class=${a}
|
|
57
57
|
type="checkbox"
|
|
58
58
|
?disabled=${this.disabled}
|
|
59
59
|
name=${this.name + "-internal"}
|
|
60
|
-
${
|
|
60
|
+
${b(this.inputRef)}
|
|
61
61
|
@change=${this.handleChange}
|
|
62
62
|
@click=${this.handleClick}
|
|
63
63
|
@blur=${this.onBlur}
|
|
@@ -65,7 +65,7 @@ let e = class extends k {
|
|
|
65
65
|
?checked=${this.checked}
|
|
66
66
|
role=${this.isSwitch ? "switch" : "checkbox"}
|
|
67
67
|
/>
|
|
68
|
-
${this.labelPosition === "right" ?
|
|
68
|
+
${this.labelPosition === "right" ? c() : r}
|
|
69
69
|
</div>
|
|
70
70
|
</div>
|
|
71
71
|
`;
|
|
@@ -116,6 +116,9 @@ i([
|
|
|
116
116
|
i([
|
|
117
117
|
s({ type: Boolean, reflect: !0 })
|
|
118
118
|
], e.prototype, "checked", 2);
|
|
119
|
+
i([
|
|
120
|
+
s({ type: Boolean, reflect: !0 })
|
|
121
|
+
], e.prototype, "indeterminate", 2);
|
|
119
122
|
i([
|
|
120
123
|
s({ type: String, reflect: !0 })
|
|
121
124
|
], e.prototype, "type", 2);
|
|
@@ -135,7 +138,7 @@ i([
|
|
|
135
138
|
s({ type: String })
|
|
136
139
|
], e.prototype, "requiredText", 2);
|
|
137
140
|
e = i([
|
|
138
|
-
|
|
141
|
+
d("pkt-checkbox")
|
|
139
142
|
], e);
|
|
140
143
|
export {
|
|
141
144
|
e as P
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";const t=require("./element-CJ_QKaki.cjs"),o=require("./input-element-KUsQQ-1d.cjs"),r=require("./ref-BFa5Utho.cjs"),p=require("./class-map-C_erArZz.cjs");var u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,i=(l,e,h,a)=>{for(var s=a>1?void 0:a?d(e,h):e,c=l.length-1,n;c>=0;c--)(n=l[c])&&(s=(a?n(e,h,s):n(s))||s);return a&&s&&u(e,h,s),s};exports.PktCheckbox=class extends o.PktInputElement{constructor(){super(...arguments),this.inputRef=r.e(),this.value="",this.checkHelptext=null,this.defaultChecked=!1,this.hasTile=!1,this.isSwitch=!1,this.labelPosition="right",this.hideLabel=!1,this.checked=null,this.indeterminate=!1,this.type="checkbox",this.tagText=null,this.optionalTag=!1,this.optionalText="Valgfritt",this.requiredTag=!1,this.requiredText="Må fylles ut"}connectedCallback(){super.connectedCallback()}attributeChangedCallback(e,h,a){e==="defaultChecked"&&!this.checked&&(this.checked=this.defaultChecked),e==="checked"&&(this.checked=this.checked===""||this.checked==="true"||this.checked===!0,this.inputRef.value&&(this.inputRef.value.checked=this.checked)),e==="indeterminate"&&(this.indeterminate=this.indeterminate===""||this.indeterminate==="true"||this.indeterminate===!0,this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate)),super.attributeChangedCallback(e,h,a)}firstUpdated(e){e.has("defaultChecked")&&!this.checked&&(this.checked=this.defaultChecked),this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate===""||this.indeterminate==="true"||this.indeterminate===!0),super.firstUpdated(e)}updated(e){e.has("defaultChecked")&&!this.checked&&(this.checked=this.defaultChecked),e.has("checked")&&this.inputRef.value&&(this.inputRef.value.checked=this.checked===""||this.checked==="true"||this.checked===!0),e.has("indeterminate")&&this.inputRef.value&&(this.inputRef.value.indeterminate=this.indeterminate===""||this.indeterminate==="true"||this.indeterminate===!0),super.updated(e)}render(){const e=p.e({"pkt-input-check__input":!0,"pkt-input-check__input--tile":this.hasTile,"pkt-input-check__input--tile-disabled":this.disabled&&this.hasTile}),h=p.e({"pkt-input-check__input-checkbox":!0,"pkt-input-check__input-checkbox--error":this.hasError}),a=p.e({"pkt-input-check__input-label":!0,"pkt-input-check__input-label--disabled":this.disabled,"pkt-input-check__input-label--left":this.labelPosition==="left","pkt-input-check__input-label--right":this.labelPosition==="right","pkt-sr-only":this.hideLabel}),s="pkt-tag pkt-tag--small pkt-tag--thin-text",c=()=>t.x`
|
|
2
|
+
${this.tagText?t.x`<span class=${s+" pkt-tag--gray"}>${this.tagText}</span>`:t.E}
|
|
3
|
+
${this.optionalTag?t.x`<span class=${s+" pkt-tag--blue-light"}>${this.optionalText}</span>`:t.E}
|
|
4
|
+
${this.requiredTag?t.x`<span class=${s+" pkt-tag--beige"}>${this.requiredText}</span>`:t.E}
|
|
5
|
+
`,n=()=>t.x`
|
|
6
|
+
<label class=${a} for=${this.id+"-internal"}>
|
|
7
|
+
${this.label} ${c()}
|
|
8
|
+
${this.checkHelptext?t.x`<div class="pkt-input-check__input-helptext">${this.checkHelptext}</div>`:t.E}
|
|
9
|
+
</label>
|
|
10
|
+
`;return t.x`
|
|
11
|
+
<div class="pkt-input-check">
|
|
12
|
+
<div class=${e}>
|
|
13
|
+
${this.labelPosition==="left"?n():t.E}
|
|
14
|
+
<input
|
|
15
|
+
id=${this.id+"-internal"}
|
|
16
|
+
class=${h}
|
|
17
|
+
type="checkbox"
|
|
18
|
+
?disabled=${this.disabled}
|
|
19
|
+
name=${this.name+"-internal"}
|
|
20
|
+
${r.n(this.inputRef)}
|
|
21
|
+
@change=${this.handleChange}
|
|
22
|
+
@click=${this.handleClick}
|
|
23
|
+
@blur=${this.onBlur}
|
|
24
|
+
@focus=${this.onFocus}
|
|
25
|
+
?checked=${this.checked}
|
|
26
|
+
role=${this.isSwitch?"switch":"checkbox"}
|
|
27
|
+
/>
|
|
28
|
+
${this.labelPosition==="right"?n():t.E}
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
`}handleClick(e){if(this.disabled)return e.preventDefault(),e.stopImmediatePropagation(),!1}handleChange(e){if(this.disabled)return e.preventDefault(),e.stopImmediatePropagation(),!1;this.toggleChecked(e)}toggleChecked(e){if(this.disabled){e.preventDefault(),e.stopImmediatePropagation();return}const h=e.target;if(h&&h.disabled){e.preventDefault(),e.stopImmediatePropagation();return}e.stopImmediatePropagation(),this.touched=!0,this.inputRef.value&&(this.checked=this.inputRef.value.matches(":checked"),this.valueChecked(this.checked))}};i([t.n({type:String,reflect:!0})],exports.PktCheckbox.prototype,"value",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"checkHelptext",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"defaultChecked",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"hasTile",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"isSwitch",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"labelPosition",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"hideLabel",2);i([t.n({type:Boolean,reflect:!0})],exports.PktCheckbox.prototype,"checked",2);i([t.n({type:Boolean,reflect:!0})],exports.PktCheckbox.prototype,"indeterminate",2);i([t.n({type:String,reflect:!0})],exports.PktCheckbox.prototype,"type",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"tagText",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"optionalTag",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"optionalText",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"requiredTag",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"requiredText",2);exports.PktCheckbox=i([t.t("pkt-checkbox")],exports.PktCheckbox);
|
package/dist/index.d.ts
CHANGED
|
@@ -534,6 +534,7 @@ export declare class PktCheckbox extends PktInputElement<Props_3> {
|
|
|
534
534
|
labelPosition: 'right' | 'left';
|
|
535
535
|
hideLabel: boolean;
|
|
536
536
|
checked: boolean | string | null;
|
|
537
|
+
indeterminate: boolean | 'true' | 'false' | '';
|
|
537
538
|
type: string;
|
|
538
539
|
tagText: string | null;
|
|
539
540
|
optionalTag: boolean;
|
package/dist/pkt-checkbox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./checkbox-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./checkbox-CqoOG2KJ.cjs"),t=e.PktCheckbox;Object.defineProperty(exports,"PktCheckbox",{enumerable:!0,get:()=>e.PktCheckbox});exports.default=t;
|
package/dist/pkt-checkbox.js
CHANGED
package/dist/pkt-index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./alert-BXbmjri0.cjs"),l=require("./accordionitem-DCZrHVNR.cjs"),m=require("./backlink-BzEvli8m.cjs"),g=require("./button-1jYzMALk.cjs"),P=require("./calendar-Dz1Cnzx5.cjs"),h=require("./card-Cf-UcGAP.cjs"),f=require("./combobox-6WP1urZS.cjs"),y=require("./consent-Cgc6nuiP.cjs"),O=require("./checkbox-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./alert-BXbmjri0.cjs"),l=require("./accordionitem-DCZrHVNR.cjs"),m=require("./backlink-BzEvli8m.cjs"),g=require("./button-1jYzMALk.cjs"),P=require("./calendar-Dz1Cnzx5.cjs"),h=require("./card-Cf-UcGAP.cjs"),f=require("./combobox-6WP1urZS.cjs"),y=require("./consent-Cgc6nuiP.cjs"),O=require("./checkbox-CqoOG2KJ.cjs"),t=require("./element-CJ_QKaki.cjs"),j=require("./pkt-slot-controller-BzddBp7z.cjs"),s=require("./ref-BFa5Utho.cjs"),q=require("./class-map-C_erArZz.cjs"),k=require("./datepicker-DEO1C69C.cjs"),x=require("./helptext-EPTR9AIl.cjs"),C=require("./heading--JKFppLS.cjs"),v=require("./icon-BGuizDwk.cjs"),S=require("./input-wrapper-B-Qseywc.cjs"),T=require("./link-Da3pZ_CW.cjs"),$=require("./linkcard-BM23gzhS.cjs"),L=require("./loader-Bo8RCbCJ.cjs"),_=require("./messagebox-C76IcXTl.cjs"),I=require("./modal-Cdz9JcCX.cjs"),A=require("./progressbar-8gzOtJyh.cjs"),p=require("./radiobutton-FwxpKELo.cjs"),B=require("./tag-EFUKrc8q.cjs"),d=require("./tabitem-D5zyipN1.cjs"),D=require("./textarea-CzN0E0TV.cjs"),M=require("./textinput-D8v6D6ie.cjs"),R=require("./select-BbmLn1qh.cjs");var H=Object.defineProperty,w=Object.getOwnPropertyDescriptor,o=(a,e,r,i)=>{for(var n=i>1?void 0:i?w(e,r):e,u=a.length-1,c;u>=0;u--)(c=a[u])&&(n=(i?c(e,r,n):c(n))||n);return i&&n&&H(e,r,n),n};exports.PktComponent=class extends t.PktElement{constructor(){super(),this.string="",this.strings=[],this.darkmode=!1,this._list=[],this.defaultSlot=s.e(),this.namedSlot=s.e(),this.slotController=new j.PktSlotController(this,this.defaultSlot,this.namedSlot)}connectedCallback(){this.strings.length&&this.strings.forEach(e=>{this._list.push(e.toUpperCase())}),super.connectedCallback()}render(){const e={"pkt-component":!0,"pkt-component--has-list":this.strings.length>0,"pkt-darkmode":this.darkmode};return t.x`
|
|
2
2
|
<div class="${q.e(e)}">
|
|
3
3
|
<h1 class="pkt-txt-28">${this.string}</h1>
|
|
4
4
|
|
package/dist/pkt-index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { P as j } from "./calendar-Bz27nuTP.js";
|
|
|
7
7
|
import { P as G } from "./card-M1X36b6i.js";
|
|
8
8
|
import { P as K } from "./combobox-CtHgl1n2.js";
|
|
9
9
|
import { P as U } from "./consent-CYFXjOXF.js";
|
|
10
|
-
import { P as q } from "./checkbox-
|
|
10
|
+
import { P as q } from "./checkbox-CCmRUWTH.js";
|
|
11
11
|
import { P as d, t as h, x as P, n, a as c } from "./element-CRDRygXu.js";
|
|
12
12
|
import { P as x } from "./pkt-slot-controller-BPGj-LC5.js";
|
|
13
13
|
import { e as m, n as k } from "./ref-Xa5dbh--.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.18.1",
|
|
4
4
|
"description": "Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/preset-env": "^7.28.3",
|
|
43
43
|
"@babel/preset-typescript": "^7.25.9",
|
|
44
44
|
"@oslokommune/punkt-assets": "^13.16.0",
|
|
45
|
-
"@oslokommune/punkt-css": "^13.
|
|
45
|
+
"@oslokommune/punkt-css": "^13.18.1",
|
|
46
46
|
"@testing-library/jest-dom": "^6.6.3",
|
|
47
47
|
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
48
48
|
"@typescript-eslint/parser": "^8.46.0",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
80
80
|
},
|
|
81
81
|
"license": "MIT",
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "3a29f3b3de9cced943ed4cd7de3d6c8a02e75040"
|
|
83
83
|
}
|
|
@@ -241,6 +241,79 @@ describe('PktCheckbox', () => {
|
|
|
241
241
|
expect(input?.getAttribute('role')).toBe('switch')
|
|
242
242
|
})
|
|
243
243
|
|
|
244
|
+
test('handles indeterminate property correctly', async () => {
|
|
245
|
+
const { checkbox } = await createCheckboxTest({
|
|
246
|
+
id: 'test',
|
|
247
|
+
name: 'test',
|
|
248
|
+
label: 'Test',
|
|
249
|
+
})
|
|
250
|
+
await checkbox.updateComplete
|
|
251
|
+
|
|
252
|
+
const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
|
|
253
|
+
expect(input.indeterminate).toBe(false)
|
|
254
|
+
|
|
255
|
+
// Set indeterminate to true
|
|
256
|
+
checkbox.indeterminate = true
|
|
257
|
+
await checkbox.updateComplete
|
|
258
|
+
|
|
259
|
+
expect(checkbox.indeterminate).toBe(true)
|
|
260
|
+
expect(input.indeterminate).toBe(true)
|
|
261
|
+
|
|
262
|
+
// Set indeterminate back to false
|
|
263
|
+
checkbox.indeterminate = false
|
|
264
|
+
await checkbox.updateComplete
|
|
265
|
+
|
|
266
|
+
expect(checkbox.indeterminate).toBe(false)
|
|
267
|
+
expect(input.indeterminate).toBe(false)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('handles indeterminate attribute changes', async () => {
|
|
271
|
+
const { checkbox } = await createCheckboxTest({
|
|
272
|
+
id: 'test',
|
|
273
|
+
name: 'test',
|
|
274
|
+
label: 'Test',
|
|
275
|
+
})
|
|
276
|
+
await checkbox.updateComplete
|
|
277
|
+
|
|
278
|
+
const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
|
|
279
|
+
expect(input.indeterminate).toBe(false)
|
|
280
|
+
|
|
281
|
+
// Set via attribute
|
|
282
|
+
checkbox.setAttribute('indeterminate', '')
|
|
283
|
+
await checkbox.updateComplete
|
|
284
|
+
|
|
285
|
+
expect(checkbox.indeterminate).toBe(true)
|
|
286
|
+
expect(input.indeterminate).toBe(true)
|
|
287
|
+
|
|
288
|
+
// Remove attribute
|
|
289
|
+
checkbox.removeAttribute('indeterminate')
|
|
290
|
+
await checkbox.updateComplete
|
|
291
|
+
|
|
292
|
+
expect(checkbox.indeterminate).toBe(false)
|
|
293
|
+
expect(input.indeterminate).toBe(false)
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
test('clicking checkbox clears indeterminate state', async () => {
|
|
297
|
+
const { checkbox } = await createCheckboxTest({
|
|
298
|
+
id: 'test',
|
|
299
|
+
name: 'test',
|
|
300
|
+
label: 'Test',
|
|
301
|
+
})
|
|
302
|
+
checkbox.indeterminate = true
|
|
303
|
+
await checkbox.updateComplete
|
|
304
|
+
|
|
305
|
+
const input = checkbox.querySelector('input[type="checkbox"]') as HTMLInputElement
|
|
306
|
+
expect(input.indeterminate).toBe(true)
|
|
307
|
+
|
|
308
|
+
// Click the checkbox
|
|
309
|
+
fireEvent.click(input)
|
|
310
|
+
await checkbox.updateComplete
|
|
311
|
+
|
|
312
|
+
// Indeterminate should be cleared by the browser when clicked
|
|
313
|
+
expect(input.indeterminate).toBe(false)
|
|
314
|
+
expect(input.checked).toBe(true)
|
|
315
|
+
})
|
|
316
|
+
|
|
244
317
|
test('handles hasTile property correctly', async () => {
|
|
245
318
|
const { checkbox } = await createCheckboxTest({
|
|
246
319
|
id: 'test',
|
|
@@ -33,6 +33,7 @@ export class PktCheckbox extends PktInputElement<Props> {
|
|
|
33
33
|
@property({ type: String }) labelPosition: 'right' | 'left' = 'right'
|
|
34
34
|
@property({ type: Boolean }) hideLabel: boolean = false
|
|
35
35
|
@property({ type: Boolean, reflect: true }) checked: boolean | string | null = null
|
|
36
|
+
@property({ type: Boolean, reflect: true }) indeterminate: boolean | 'true' | 'false' | '' = false
|
|
36
37
|
@property({ type: String, reflect: true }) type: string = 'checkbox'
|
|
37
38
|
@property({ type: String }) tagText: string | null = null
|
|
38
39
|
@property({ type: Boolean }) optionalTag: boolean = false
|
|
@@ -52,6 +53,11 @@ export class PktCheckbox extends PktInputElement<Props> {
|
|
|
52
53
|
this.checked = this.checked === '' || this.checked === 'true' || this.checked === true
|
|
53
54
|
if (this.inputRef.value) this.inputRef.value.checked = this.checked as boolean
|
|
54
55
|
}
|
|
56
|
+
if (name === 'indeterminate') {
|
|
57
|
+
this.indeterminate =
|
|
58
|
+
this.indeterminate === '' || this.indeterminate === 'true' || this.indeterminate === true
|
|
59
|
+
if (this.inputRef.value) this.inputRef.value.indeterminate = this.indeterminate as boolean
|
|
60
|
+
}
|
|
55
61
|
super.attributeChangedCallback(name, _old, value)
|
|
56
62
|
}
|
|
57
63
|
|
|
@@ -59,6 +65,10 @@ export class PktCheckbox extends PktInputElement<Props> {
|
|
|
59
65
|
if (_changedProperties.has('defaultChecked') && !this.checked) {
|
|
60
66
|
this.checked = this.defaultChecked
|
|
61
67
|
}
|
|
68
|
+
if (this.inputRef.value) {
|
|
69
|
+
this.inputRef.value.indeterminate =
|
|
70
|
+
this.indeterminate === '' || this.indeterminate === 'true' || this.indeterminate === true
|
|
71
|
+
}
|
|
62
72
|
super.firstUpdated(_changedProperties)
|
|
63
73
|
}
|
|
64
74
|
|
|
@@ -70,6 +80,10 @@ export class PktCheckbox extends PktInputElement<Props> {
|
|
|
70
80
|
this.inputRef.value.checked =
|
|
71
81
|
this.checked === '' || this.checked === 'true' || this.checked === true
|
|
72
82
|
}
|
|
83
|
+
if (changedProperties.has('indeterminate') && this.inputRef.value) {
|
|
84
|
+
this.inputRef.value.indeterminate =
|
|
85
|
+
this.indeterminate === '' || this.indeterminate === 'true' || this.indeterminate === true
|
|
86
|
+
}
|
|
73
87
|
super.updated(changedProperties)
|
|
74
88
|
}
|
|
75
89
|
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";const t=require("./element-CJ_QKaki.cjs"),r=require("./input-element-KUsQQ-1d.cjs"),o=require("./ref-BFa5Utho.cjs"),n=require("./class-map-C_erArZz.cjs");var k=Object.defineProperty,u=Object.getOwnPropertyDescriptor,i=(p,e,h,c)=>{for(var s=c>1?void 0:c?u(e,h):e,l=p.length-1,a;l>=0;l--)(a=p[l])&&(s=(c?a(e,h,s):a(s))||s);return c&&s&&k(e,h,s),s};exports.PktCheckbox=class extends r.PktInputElement{constructor(){super(...arguments),this.inputRef=o.e(),this.value="",this.checkHelptext=null,this.defaultChecked=!1,this.hasTile=!1,this.isSwitch=!1,this.labelPosition="right",this.hideLabel=!1,this.checked=null,this.type="checkbox",this.tagText=null,this.optionalTag=!1,this.optionalText="Valgfritt",this.requiredTag=!1,this.requiredText="Må fylles ut"}connectedCallback(){super.connectedCallback()}attributeChangedCallback(e,h,c){e==="defaultChecked"&&!this.checked&&(this.checked=this.defaultChecked),e==="checked"&&(this.checked=this.checked===""||this.checked==="true"||this.checked===!0,this.inputRef.value&&(this.inputRef.value.checked=this.checked)),super.attributeChangedCallback(e,h,c)}firstUpdated(e){e.has("defaultChecked")&&!this.checked&&(this.checked=this.defaultChecked),super.firstUpdated(e)}updated(e){e.has("defaultChecked")&&!this.checked&&(this.checked=this.defaultChecked),e.has("checked")&&this.inputRef.value&&(this.inputRef.value.checked=this.checked===""||this.checked==="true"||this.checked===!0),super.updated(e)}render(){const e=n.e({"pkt-input-check__input":!0,"pkt-input-check__input--tile":this.hasTile,"pkt-input-check__input--tile-disabled":this.disabled&&this.hasTile}),h=n.e({"pkt-input-check__input-checkbox":!0,"pkt-input-check__input-checkbox--error":this.hasError}),c=n.e({"pkt-input-check__input-label":!0,"pkt-input-check__input-label--disabled":this.disabled,"pkt-input-check__input-label--left":this.labelPosition==="left","pkt-input-check__input-label--right":this.labelPosition==="right","pkt-sr-only":this.hideLabel}),s="pkt-tag pkt-tag--small pkt-tag--thin-text",l=()=>t.x`
|
|
2
|
-
${this.tagText?t.x`<span class=${s+" pkt-tag--gray"}>${this.tagText}</span>`:t.E}
|
|
3
|
-
${this.optionalTag?t.x`<span class=${s+" pkt-tag--blue-light"}>${this.optionalText}</span>`:t.E}
|
|
4
|
-
${this.requiredTag?t.x`<span class=${s+" pkt-tag--beige"}>${this.requiredText}</span>`:t.E}
|
|
5
|
-
`,a=()=>t.x`
|
|
6
|
-
<label class=${c} for=${this.id+"-internal"}>
|
|
7
|
-
${this.label} ${l()}
|
|
8
|
-
${this.checkHelptext?t.x`<div class="pkt-input-check__input-helptext">${this.checkHelptext}</div>`:t.E}
|
|
9
|
-
</label>
|
|
10
|
-
`;return t.x`
|
|
11
|
-
<div class="pkt-input-check">
|
|
12
|
-
<div class=${e}>
|
|
13
|
-
${this.labelPosition==="left"?a():t.E}
|
|
14
|
-
<input
|
|
15
|
-
id=${this.id+"-internal"}
|
|
16
|
-
class=${h}
|
|
17
|
-
type="checkbox"
|
|
18
|
-
?disabled=${this.disabled}
|
|
19
|
-
name=${this.name+"-internal"}
|
|
20
|
-
${o.n(this.inputRef)}
|
|
21
|
-
@change=${this.handleChange}
|
|
22
|
-
@click=${this.handleClick}
|
|
23
|
-
@blur=${this.onBlur}
|
|
24
|
-
@focus=${this.onFocus}
|
|
25
|
-
?checked=${this.checked}
|
|
26
|
-
role=${this.isSwitch?"switch":"checkbox"}
|
|
27
|
-
/>
|
|
28
|
-
${this.labelPosition==="right"?a():t.E}
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
`}handleClick(e){if(this.disabled)return e.preventDefault(),e.stopImmediatePropagation(),!1}handleChange(e){if(this.disabled)return e.preventDefault(),e.stopImmediatePropagation(),!1;this.toggleChecked(e)}toggleChecked(e){if(this.disabled){e.preventDefault(),e.stopImmediatePropagation();return}const h=e.target;if(h&&h.disabled){e.preventDefault(),e.stopImmediatePropagation();return}e.stopImmediatePropagation(),this.touched=!0,this.inputRef.value&&(this.checked=this.inputRef.value.matches(":checked"),this.valueChecked(this.checked))}};i([t.n({type:String,reflect:!0})],exports.PktCheckbox.prototype,"value",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"checkHelptext",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"defaultChecked",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"hasTile",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"isSwitch",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"labelPosition",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"hideLabel",2);i([t.n({type:Boolean,reflect:!0})],exports.PktCheckbox.prototype,"checked",2);i([t.n({type:String,reflect:!0})],exports.PktCheckbox.prototype,"type",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"tagText",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"optionalTag",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"optionalText",2);i([t.n({type:Boolean})],exports.PktCheckbox.prototype,"requiredTag",2);i([t.n({type:String})],exports.PktCheckbox.prototype,"requiredText",2);exports.PktCheckbox=i([t.t("pkt-checkbox")],exports.PktCheckbox);
|