@oslokommune/punkt-elements 12.40.10 → 12.41.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 +34 -0
- package/dist/button-KzBZ-Bff.cjs +19 -0
- package/dist/button-OLSvT2Im.js +100 -0
- package/dist/combobox-CavDENt-.js +514 -0
- package/dist/{combobox-lds6Lryq.cjs → combobox-DMkMUJfx.cjs} +12 -12
- package/dist/{consent-CkDh30xr.cjs → consent-D1r9LYda.cjs} +1 -1
- package/dist/{consent-B_cBTKCZ.js → consent-a09DlJZT.js} +1 -1
- package/dist/index.d.ts +3 -8
- package/dist/pkt-button.cjs +1 -1
- package/dist/pkt-button.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-consent.cjs +1 -1
- package/dist/pkt-consent.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +3 -3
- package/package.json +3 -3
- package/src/components/button/button.ts +28 -124
- package/src/components/combobox/combobox.ts +27 -1
- package/dist/button-BSTI5da6.js +0 -121
- package/dist/button-oZThyRNI.cjs +0 -12
- package/dist/combobox-Ct7-a2Vy.js +0 -495
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,40 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [12.41.1](https://github.com/oslokommune/punkt/compare/12.41.0...12.41.1) (2025-06-11)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
Ingen
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
Ingen
|
|
18
|
+
|
|
19
|
+
### Chores
|
|
20
|
+
Ingen
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [12.41.0](https://github.com/oslokommune/punkt/compare/12.40.10...12.41.0) (2025-06-10)
|
|
26
|
+
|
|
27
|
+
### ⚠ BREAKING CHANGES
|
|
28
|
+
Ingen
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
Ingen
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
Ingen
|
|
35
|
+
|
|
36
|
+
### Chores
|
|
37
|
+
Ingen
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
|
|
8
42
|
## [12.40.10](https://github.com/oslokommune/punkt/compare/12.40.9...12.40.10) (2025-06-10)
|
|
9
43
|
|
|
10
44
|
### ⚠ BREAKING CHANGES
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";const t=require("./element-90YeMNbV.cjs"),h=require("./pkt-slot-controller-Da-RgXfS.cjs"),u=require("./class-map-DWDPOqjO.cjs"),a=require("./if-defined-C8eotHpL.cjs"),d=require("./ref-B-w1vCo8.cjs");var c=Object.defineProperty,k=Object.getOwnPropertyDescriptor,i=(r,n,o,e)=>{for(var s=e>1?void 0:e?k(n,o):n,p=r.length-1,l;p>=0;p--)(l=r[p])&&(s=(e?l(n,o,s):l(s))||s);return e&&s&&c(n,o,s),s};window.pktAnimationPath=window.pktAnimationPath||"https://punkt-cdn.oslo.kommune.no/latest/animations/";exports.PktButton=class extends t.PktElement{constructor(){super(),this.defaultSlot=d.e(),this.iconName="user",this.secondIconName="user",this.mode="light",this.size="medium",this.skin="primary",this.variant="label-only",this.state="normal",this.type="button",this.form=void 0,this.isLoading=!1,this.disabled=!1,this.loadingAnimationPath=window.pktAnimationPath,this.slotController=new h.PktSlotController(this,this.defaultSlot)}attributeChangedCallback(n,o,e){super.attributeChangedCallback(n,o,e),n==="disabled"&&e==="false"&&(this.disabled=!1),(n==="isloading"||n==="isLoading")&&e==="false"&&(this.isLoading=!1)}firstUpdated(n){super.firstUpdated(n),this.disabled==="false"&&(this.disabled=!1),this.isLoading==="false"&&(this.isLoading=!1)}render(){const n=this.form??this.getAttribute("form")??void 0,o={"pkt-btn":!0,[`pkt-btn--${this.size}`]:!!this.size,[`pkt-btn--${this.skin}`]:!!this.skin,[`pkt-btn--${this.variant}`]:!!this.variant,[`pkt-btn--${this.color}`]:!!this.color,[`pkt-btn--${this.state}`]:!!this.state,"pkt-btn--disabled":!!this.disabled,"pkt-btn--isLoading":!!this.isLoading};return t.x`
|
|
2
|
+
<button
|
|
3
|
+
class=${u.e(o)}
|
|
4
|
+
type=${this.type}
|
|
5
|
+
?disabled=${!!this.disabled}
|
|
6
|
+
aria-busy=${a.o(this.isLoading?"true":void 0)}
|
|
7
|
+
aria-disabled=${a.o(this.disabled?"true":void 0)}
|
|
8
|
+
form=${a.o(n)}
|
|
9
|
+
>
|
|
10
|
+
${this.isLoading?t.x`<pkt-icon
|
|
11
|
+
class="pkt-btn__icon pkt-btn__spinner"
|
|
12
|
+
name="spinner-blue"
|
|
13
|
+
path=${a.o(this.loadingAnimationPath)}
|
|
14
|
+
></pkt-icon>`:t.E}
|
|
15
|
+
${this.variant!=="label-only"?t.x`<pkt-icon class="pkt-btn__icon pkt-icon" name=${this.iconName}></pkt-icon>`:t.E}
|
|
16
|
+
<span class="pkt-btn__text" ${d.n(this.defaultSlot)}></span>
|
|
17
|
+
${this.variant==="icons-right-and-left"?t.x`<pkt-icon class="pkt-btn__icon" name=${this.secondIconName}></pkt-icon>`:t.E}
|
|
18
|
+
</button>
|
|
19
|
+
`}};i([t.n({type:String})],exports.PktButton.prototype,"iconName",2);i([t.n({type:String})],exports.PktButton.prototype,"secondIconName",2);i([t.n({type:String})],exports.PktButton.prototype,"mode",2);i([t.n({type:String})],exports.PktButton.prototype,"size",2);i([t.n({type:String})],exports.PktButton.prototype,"color",2);i([t.n({type:String})],exports.PktButton.prototype,"skin",2);i([t.n({type:String})],exports.PktButton.prototype,"variant",2);i([t.n({type:String,reflect:!0})],exports.PktButton.prototype,"state",2);i([t.n({type:String})],exports.PktButton.prototype,"type",2);i([t.n({type:String})],exports.PktButton.prototype,"form",2);i([t.n({type:Boolean,reflect:!0})],exports.PktButton.prototype,"isLoading",2);i([t.n({type:Boolean,reflect:!0})],exports.PktButton.prototype,"disabled",2);i([t.n({type:String})],exports.PktButton.prototype,"loadingAnimationPath",2);exports.PktButton=i([t.t("pkt-button")],exports.PktButton);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { P as b, E as c, x as p, n as s, a as f } from "./element-gAd63VwC.js";
|
|
2
|
+
import { P as m } from "./pkt-slot-controller-DtDaD9q_.js";
|
|
3
|
+
import { e as y } from "./class-map-m7ZCZ49w.js";
|
|
4
|
+
import { o as l } from "./if-defined-Cj-3Kdsr.js";
|
|
5
|
+
import { e as g, n as k } from "./ref-DnSbnXsj.js";
|
|
6
|
+
var u = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, i = (e, o, n, r) => {
|
|
7
|
+
for (var a = r > 1 ? void 0 : r ? $(o, n) : o, d = e.length - 1, h; d >= 0; d--)
|
|
8
|
+
(h = e[d]) && (a = (r ? h(o, n, a) : h(a)) || a);
|
|
9
|
+
return r && a && u(o, n, a), a;
|
|
10
|
+
};
|
|
11
|
+
window.pktAnimationPath = window.pktAnimationPath || "https://punkt-cdn.oslo.kommune.no/latest/animations/";
|
|
12
|
+
let t = class extends b {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this.defaultSlot = g(), this.iconName = "user", this.secondIconName = "user", this.mode = "light", this.size = "medium", this.skin = "primary", this.variant = "label-only", this.state = "normal", this.type = "button", this.form = void 0, this.isLoading = !1, this.disabled = !1, this.loadingAnimationPath = window.pktAnimationPath, this.slotController = new m(this, this.defaultSlot);
|
|
15
|
+
}
|
|
16
|
+
// Lifecycle
|
|
17
|
+
attributeChangedCallback(e, o, n) {
|
|
18
|
+
super.attributeChangedCallback(e, o, n), e === "disabled" && n === "false" && (this.disabled = !1), (e === "isloading" || e === "isLoading") && n === "false" && (this.isLoading = !1);
|
|
19
|
+
}
|
|
20
|
+
firstUpdated(e) {
|
|
21
|
+
super.firstUpdated(e), this.disabled === "false" && (this.disabled = !1), this.isLoading === "false" && (this.isLoading = !1);
|
|
22
|
+
}
|
|
23
|
+
// Render
|
|
24
|
+
render() {
|
|
25
|
+
const e = this.form ?? this.getAttribute("form") ?? void 0, o = {
|
|
26
|
+
"pkt-btn": !0,
|
|
27
|
+
[`pkt-btn--${this.size}`]: !!this.size,
|
|
28
|
+
[`pkt-btn--${this.skin}`]: !!this.skin,
|
|
29
|
+
[`pkt-btn--${this.variant}`]: !!this.variant,
|
|
30
|
+
[`pkt-btn--${this.color}`]: !!this.color,
|
|
31
|
+
[`pkt-btn--${this.state}`]: !!this.state,
|
|
32
|
+
"pkt-btn--disabled": !!this.disabled,
|
|
33
|
+
"pkt-btn--isLoading": !!this.isLoading
|
|
34
|
+
};
|
|
35
|
+
return p`
|
|
36
|
+
<button
|
|
37
|
+
class=${y(o)}
|
|
38
|
+
type=${this.type}
|
|
39
|
+
?disabled=${!!this.disabled}
|
|
40
|
+
aria-busy=${l(this.isLoading ? "true" : void 0)}
|
|
41
|
+
aria-disabled=${l(this.disabled ? "true" : void 0)}
|
|
42
|
+
form=${l(e)}
|
|
43
|
+
>
|
|
44
|
+
${this.isLoading ? p`<pkt-icon
|
|
45
|
+
class="pkt-btn__icon pkt-btn__spinner"
|
|
46
|
+
name="spinner-blue"
|
|
47
|
+
path=${l(this.loadingAnimationPath)}
|
|
48
|
+
></pkt-icon>` : c}
|
|
49
|
+
${this.variant !== "label-only" ? p`<pkt-icon class="pkt-btn__icon pkt-icon" name=${this.iconName}></pkt-icon>` : c}
|
|
50
|
+
<span class="pkt-btn__text" ${k(this.defaultSlot)}></span>
|
|
51
|
+
${this.variant === "icons-right-and-left" ? p`<pkt-icon class="pkt-btn__icon" name=${this.secondIconName}></pkt-icon>` : c}
|
|
52
|
+
</button>
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
i([
|
|
57
|
+
s({ type: String })
|
|
58
|
+
], t.prototype, "iconName", 2);
|
|
59
|
+
i([
|
|
60
|
+
s({ type: String })
|
|
61
|
+
], t.prototype, "secondIconName", 2);
|
|
62
|
+
i([
|
|
63
|
+
s({ type: String })
|
|
64
|
+
], t.prototype, "mode", 2);
|
|
65
|
+
i([
|
|
66
|
+
s({ type: String })
|
|
67
|
+
], t.prototype, "size", 2);
|
|
68
|
+
i([
|
|
69
|
+
s({ type: String })
|
|
70
|
+
], t.prototype, "color", 2);
|
|
71
|
+
i([
|
|
72
|
+
s({ type: String })
|
|
73
|
+
], t.prototype, "skin", 2);
|
|
74
|
+
i([
|
|
75
|
+
s({ type: String })
|
|
76
|
+
], t.prototype, "variant", 2);
|
|
77
|
+
i([
|
|
78
|
+
s({ type: String, reflect: !0 })
|
|
79
|
+
], t.prototype, "state", 2);
|
|
80
|
+
i([
|
|
81
|
+
s({ type: String })
|
|
82
|
+
], t.prototype, "type", 2);
|
|
83
|
+
i([
|
|
84
|
+
s({ type: String })
|
|
85
|
+
], t.prototype, "form", 2);
|
|
86
|
+
i([
|
|
87
|
+
s({ type: Boolean, reflect: !0 })
|
|
88
|
+
], t.prototype, "isLoading", 2);
|
|
89
|
+
i([
|
|
90
|
+
s({ type: Boolean, reflect: !0 })
|
|
91
|
+
], t.prototype, "disabled", 2);
|
|
92
|
+
i([
|
|
93
|
+
s({ type: String })
|
|
94
|
+
], t.prototype, "loadingAnimationPath", 2);
|
|
95
|
+
t = i([
|
|
96
|
+
f("pkt-button")
|
|
97
|
+
], t);
|
|
98
|
+
export {
|
|
99
|
+
t as P
|
|
100
|
+
};
|
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { E as y, x as d, n as r, a as k } from "./element-gAd63VwC.js";
|
|
2
|
+
import { o as f } from "./if-defined-Cj-3Kdsr.js";
|
|
3
|
+
import { r as c } from "./state-BxrO4zNJ.js";
|
|
4
|
+
import { e as _, n as v } from "./ref-DnSbnXsj.js";
|
|
5
|
+
import { e as w } from "./class-map-m7ZCZ49w.js";
|
|
6
|
+
import { c as R } from "./repeat-lUFq9w5d.js";
|
|
7
|
+
import { P as V } from "./input-element-BEvaQK4g.js";
|
|
8
|
+
import { P as C } from "./pkt-options-controller-DepYQBqb.js";
|
|
9
|
+
import { P as A } from "./pkt-slot-controller-DtDaD9q_.js";
|
|
10
|
+
import "./input-wrapper-CDgnd3WJ.js";
|
|
11
|
+
import "./icon-CO1TLSs5.js";
|
|
12
|
+
import "./tag-CX-zbR-7.js";
|
|
13
|
+
import "./listbox-DCWdrjFp.js";
|
|
14
|
+
const S = {
|
|
15
|
+
displayValueAs: {
|
|
16
|
+
default: "label"
|
|
17
|
+
}
|
|
18
|
+
}, T = {
|
|
19
|
+
props: S
|
|
20
|
+
};
|
|
21
|
+
var M = Object.defineProperty, F = Object.getOwnPropertyDescriptor, o = (t, e, i, s) => {
|
|
22
|
+
for (var l = s > 1 ? void 0 : s ? F(e, i) : e, n = t.length - 1, a; n >= 0; n--)
|
|
23
|
+
(a = t[n]) && (l = (s ? a(e, i, l) : a(l)) || l);
|
|
24
|
+
return s && l && M(e, i, l), l;
|
|
25
|
+
};
|
|
26
|
+
let h = class extends V {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(), this.helptextSlot = _(), this.value = "", this.options = [], this.defaultOptions = [], this.allowUserInput = !1, this.typeahead = !1, this.includeSearch = !1, this.searchPlaceholder = "", this.multiple = !1, this.maxlength = null, this.displayValueAs = T.props.displayValueAs.default, this.tagPlacement = null, this._options = [], this._isOptionsOpen = !1, this._value = [], this._userInfoMessage = "", this._addValueText = null, this._maxIsReached = !1, this._search = "", this._inputFocus = !1, this._editingSingleValue = !1, this.inputRef = _(), this.arrowRef = _(), this.listboxRef = _(), this.focusRef = _(), this.optionTagRef = _(), this.optionsController = new C(this), this.slotController = new A(this, this.helptextSlot), this.slotController.skipOptions = !0;
|
|
29
|
+
}
|
|
30
|
+
// Lifecycle methods
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
var t;
|
|
33
|
+
if (super.connectedCallback(), document && document.body.addEventListener("click", (e) => {
|
|
34
|
+
this._isOptionsOpen && !this.contains(e.target) && this.handleFocusOut(e);
|
|
35
|
+
}), this._options = [], this.defaultOptions && this.defaultOptions.length) {
|
|
36
|
+
const e = ((t = this.options) == null ? void 0 : t.filter((i) => i.userAdded)) || [];
|
|
37
|
+
this.options = [...e, ...structuredClone(this.defaultOptions)], this._options = [...this.options];
|
|
38
|
+
}
|
|
39
|
+
if (this.optionsController.nodes.length) {
|
|
40
|
+
const e = [];
|
|
41
|
+
this.optionsController.nodes.forEach((i) => {
|
|
42
|
+
if (!i.textContent && !i.getAttribute("value")) return null;
|
|
43
|
+
const s = {
|
|
44
|
+
value: i.getAttribute("value") || i.textContent || "",
|
|
45
|
+
label: i.textContent || i.getAttribute("value") || ""
|
|
46
|
+
};
|
|
47
|
+
i.getAttribute("data-prefix") && (s.prefix = i.getAttribute("data-prefix") || void 0), i.getAttribute("tagskincolor") && (s.tagSkinColor = i.getAttribute("tagskincolor")), i.getAttribute("description") && (s.description = i.getAttribute("description") || void 0), s.fulltext = s.value + s.label + (s.prefix || ""), e.push(s);
|
|
48
|
+
}), e.length && (this.options = [...e], this._options = [...e]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
updated(t) {
|
|
52
|
+
var e;
|
|
53
|
+
if (t.has("_value") && this.valueChanged(this._value, t.get("_value")), t.has("value") && (this._value = Array.isArray(this.value) ? this.value : this.value ? this.value.split(",") : [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]]), this.isMaxItemsReached()), t.has("defaultOptions") && this.defaultOptions.length) {
|
|
54
|
+
const i = ((e = this.options) == null ? void 0 : e.filter((s) => s.userAdded)) || [];
|
|
55
|
+
this.options = [...i, ...structuredClone(this.defaultOptions)], this._options = [...this.options];
|
|
56
|
+
}
|
|
57
|
+
if (t.has("options") && this.options.length) {
|
|
58
|
+
const s = this._options.filter((l) => l.userAdded).filter(
|
|
59
|
+
(l) => !this.options.some((n) => n.value === l.value)
|
|
60
|
+
);
|
|
61
|
+
this._options = [...s, ...this.options], this._options.forEach((l) => {
|
|
62
|
+
if (l.value && !l.label && (l.label = l.value), l.selected && !this._value.includes(l.value)) {
|
|
63
|
+
const n = [...this._value];
|
|
64
|
+
this._value = [...this._value, l.value], this.valueChanged(this._value, n);
|
|
65
|
+
}
|
|
66
|
+
l.fulltext = l.value + l.label + (l.prefix || ""), l.selected = l.selected || this._value.includes(l.value);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
t.has("_search") && this.dispatchEvent(
|
|
70
|
+
new CustomEvent("search", {
|
|
71
|
+
detail: this._search,
|
|
72
|
+
bubbles: !1
|
|
73
|
+
})
|
|
74
|
+
), super.updated(t);
|
|
75
|
+
}
|
|
76
|
+
attributeChangedCallback(t, e, i) {
|
|
77
|
+
t === "value" && (this._value = Array.isArray(this.value) ? this.value : this.value ? this.value.split(",") : [], !this.multiple && this._value.length > 1 && (this._value = [this._value[0]])), t === "options" && (this._options = this.options, this._options.forEach((s) => {
|
|
78
|
+
s.value && !s.label && (s.label = s.value), s.selected && !this._value.includes(s.value) && (this._value = [...this._value, s.value]), s.fulltext = s.value + s.label + (s.prefix || "");
|
|
79
|
+
}), this._search = ""), super.attributeChangedCallback(t, e, i);
|
|
80
|
+
}
|
|
81
|
+
// Render methods
|
|
82
|
+
render() {
|
|
83
|
+
return d`
|
|
84
|
+
<pkt-input-wrapper
|
|
85
|
+
.label=${this.label}
|
|
86
|
+
.helptext=${this.helptext}
|
|
87
|
+
.helptextDropdown=${f(this.helptextDropdown)}
|
|
88
|
+
.helptextDropdownButton=${f(this.helptextDropdownButton)}
|
|
89
|
+
?fullwidth=${this.fullwidth}
|
|
90
|
+
?hasError=${this.hasError}
|
|
91
|
+
?inline=${this.inline}
|
|
92
|
+
?disabled=${this.disabled}
|
|
93
|
+
.errorMessage=${this.errorMessage}
|
|
94
|
+
?optionalTag=${this.optionalTag}
|
|
95
|
+
.optionalText=${this.optionalText}
|
|
96
|
+
?requiredTag=${this.requiredTag}
|
|
97
|
+
.requiredText=${this.requiredText}
|
|
98
|
+
?useWrapper=${this.useWrapper}
|
|
99
|
+
.forId=${this.allowUserInput || this.typeahead ? this.id + "-input" : this.id + "-arrow"}
|
|
100
|
+
class="pkt-combobox__wrapper"
|
|
101
|
+
@labelClick=${this.handleInputClick}
|
|
102
|
+
>
|
|
103
|
+
<div class="pkt-contents" ${v(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
104
|
+
<div class="pkt-combobox" @focusout=${this.handleFocusOut}>
|
|
105
|
+
<div
|
|
106
|
+
class=${w({
|
|
107
|
+
"pkt-combobox__input": !0,
|
|
108
|
+
"pkt-combobox__input--fullwidth": this.fullwidth,
|
|
109
|
+
"pkt-combobox__input--open": this._isOptionsOpen,
|
|
110
|
+
"pkt-combobox__input--error": this.hasError,
|
|
111
|
+
"pkt-combobox__input--disabled": this.disabled
|
|
112
|
+
})}
|
|
113
|
+
tabindex="-1"
|
|
114
|
+
@click=${this.handleInputClick}
|
|
115
|
+
>
|
|
116
|
+
${this.placeholder && (!this._value.length || this.multiple && this.tagPlacement == "outside") && !this._inputFocus ? d`<span class="pkt-combobox__placeholder">${this.placeholder}</span>` : this.tagPlacement !== "outside" ? this.renderSingleOrMultipleValues() : y}
|
|
117
|
+
${this.renderInputField()}
|
|
118
|
+
<div
|
|
119
|
+
class="pkt-btn pkt-btn--tertiary pkt-combobox__arrow"
|
|
120
|
+
@click=${this.handleArrowClick}
|
|
121
|
+
@keydown=${this.handleArrowClick}
|
|
122
|
+
id="${this.id}-arrow"
|
|
123
|
+
${v(this.arrowRef)}
|
|
124
|
+
aria-expanded=${this._isOptionsOpen}
|
|
125
|
+
aria-controls="${this.id}-listbox"
|
|
126
|
+
aria-haspopup="listbox"
|
|
127
|
+
aria-label="Åpne liste"
|
|
128
|
+
?disabled=${this.disabled}
|
|
129
|
+
?data-disabled=${this.disabled}
|
|
130
|
+
role="button"
|
|
131
|
+
tabindex="${this.disabled ? "-1" : "0"}"
|
|
132
|
+
>
|
|
133
|
+
<pkt-icon
|
|
134
|
+
class=${w({
|
|
135
|
+
"pkt-combobox__arrow-icon": !0,
|
|
136
|
+
"pkt-combobox__arrow-icon--open": this._isOptionsOpen
|
|
137
|
+
})}
|
|
138
|
+
name="chevron-thin-down"
|
|
139
|
+
></pkt-icon>
|
|
140
|
+
</div>
|
|
141
|
+
<div ${v(this.focusRef)} tabindex="-1" @keydown=${this.handleArrowClick}></div>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<pkt-listbox
|
|
145
|
+
id="${this.id}-listbox"
|
|
146
|
+
.options=${this._options}
|
|
147
|
+
.isOpen=${this._isOptionsOpen}
|
|
148
|
+
.searchPlaceholder=${this.searchPlaceholder}
|
|
149
|
+
.label="Liste: ${this.label || ""}"
|
|
150
|
+
?includeSearch=${this.includeSearch}
|
|
151
|
+
?isMultiSelect=${this.multiple}
|
|
152
|
+
?allowUserInput=${this.allowUserInput && !this._maxIsReached}
|
|
153
|
+
?maxIsReached=${this._maxIsReached}
|
|
154
|
+
.customUserInput=${f(this._addValueText)}
|
|
155
|
+
.userMessage=${this._userInfoMessage}
|
|
156
|
+
@search=${this.handleSearch}
|
|
157
|
+
@option-toggle=${this.handleOptionToggled}
|
|
158
|
+
@select-all=${this.addAllOptions}
|
|
159
|
+
@close-options=${() => this._isOptionsOpen = !1}
|
|
160
|
+
.searchValue=${this._search || null}
|
|
161
|
+
.maxLength=${this.maxlength || 0}
|
|
162
|
+
${v(this.listboxRef)}
|
|
163
|
+
></pkt-listbox>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
${this.tagPlacement === "outside" && this.multiple ? d`<div class="pkt-combobox__tags-outside">
|
|
167
|
+
${this.renderSingleOrMultipleValues()}
|
|
168
|
+
</div>` : y}
|
|
169
|
+
</pkt-input-wrapper>
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
renderInputField() {
|
|
173
|
+
return this.typeahead || this.allowUserInput ? d`
|
|
174
|
+
<div class="pkt-combobox__input-div combobox__input">
|
|
175
|
+
<input
|
|
176
|
+
type="text"
|
|
177
|
+
id="${this.id}-input"
|
|
178
|
+
name=${(this.name || this.id) + "-input"}
|
|
179
|
+
@input=${this.handleInput}
|
|
180
|
+
@keydown=${this.handleInputKeydown}
|
|
181
|
+
@focus=${this.handleFocus}
|
|
182
|
+
@blur=${this.handleBlur}
|
|
183
|
+
autocomplete="off"
|
|
184
|
+
role="combobox"
|
|
185
|
+
aria-label=${f(this.label)}
|
|
186
|
+
aria-autocomplete=${this.typeahead ? "both" : "list"}
|
|
187
|
+
aria-controls="${this.id}-listbox"
|
|
188
|
+
aria-multiselectable=${f(this.multiple ? "true" : void 0)}
|
|
189
|
+
aria-activedescendant=${f(
|
|
190
|
+
this._value[0] && this.findValueInOptions(this._value[0]) ? `${this.id}-listbox-${this.findIndexInOptions(this._value[0])}` : void 0
|
|
191
|
+
)}
|
|
192
|
+
${v(this.inputRef)}
|
|
193
|
+
/>
|
|
194
|
+
</div>
|
|
195
|
+
` : d`
|
|
196
|
+
<input
|
|
197
|
+
type="hidden"
|
|
198
|
+
id="${this.id}-input"
|
|
199
|
+
name=${(this.name || this.id) + "-input"}
|
|
200
|
+
.value=${this._value.join(",")}
|
|
201
|
+
${v(this.inputRef)}
|
|
202
|
+
/>
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
renderSingleOrMultipleValues() {
|
|
206
|
+
const t = !this.multiple, e = this._editingSingleValue ? null : this.renderValueTag(this.findValueInOptions(this._value[0])), i = R(
|
|
207
|
+
this._value,
|
|
208
|
+
(s) => s,
|
|
209
|
+
(s) => {
|
|
210
|
+
var a;
|
|
211
|
+
const l = this.findValueInOptions(s), n = (a = this.options.find((u) => u.value === s)) == null ? void 0 : a.tagSkinColor;
|
|
212
|
+
return d`
|
|
213
|
+
<pkt-tag
|
|
214
|
+
skin=${n || "blue-dark"}
|
|
215
|
+
?closeTag=${!this.disabled}
|
|
216
|
+
@close=${() => this.handleTagRemove(s)}
|
|
217
|
+
>
|
|
218
|
+
${this.renderValueTag(l)}
|
|
219
|
+
</pkt-tag>
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
return t ? e : i;
|
|
224
|
+
}
|
|
225
|
+
renderValueTag(t) {
|
|
226
|
+
if (!t) return "";
|
|
227
|
+
switch (this.displayValueAs) {
|
|
228
|
+
case "prefixAndValue":
|
|
229
|
+
return d`<span data-focusfix=${this.id}>${t.prefix || ""} ${t.value}</span>`;
|
|
230
|
+
case "value":
|
|
231
|
+
return d`<span data-focusfix=${this.id}>${t.value}</span>`;
|
|
232
|
+
case "label":
|
|
233
|
+
default:
|
|
234
|
+
return d`<span data-focusfix=${this.id}>${t.label || t.value}</span>`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Event handlers
|
|
238
|
+
handleInput(t) {
|
|
239
|
+
if (t.stopPropagation(), t.stopImmediatePropagation(), this.disabled) return;
|
|
240
|
+
this.touched = !0;
|
|
241
|
+
const e = t.target;
|
|
242
|
+
if (this._search = e.value, this.checkForMatches(), this.typeahead)
|
|
243
|
+
if (this._search) {
|
|
244
|
+
if (this._options = this.options.filter(
|
|
245
|
+
(i) => {
|
|
246
|
+
var s;
|
|
247
|
+
return (s = i.fulltext) == null ? void 0 : s.toLowerCase().includes(this._search.toLowerCase());
|
|
248
|
+
}
|
|
249
|
+
), t.inputType !== "deleteContentBackward") {
|
|
250
|
+
const i = this._options.filter(
|
|
251
|
+
(s) => {
|
|
252
|
+
var l;
|
|
253
|
+
return !s.selected && ((l = s.label) == null ? void 0 : l.toLowerCase().startsWith(this._search.toLowerCase()));
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
if (i.length > 0 && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
257
|
+
const s = i[0];
|
|
258
|
+
s != null && s.label && (e.value = s.label, window.setTimeout(
|
|
259
|
+
() => e.setSelectionRange(this._search.length, e.value.length),
|
|
260
|
+
0
|
|
261
|
+
), e.selectionDirection = "backward");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} else
|
|
265
|
+
this._options = [...this.options];
|
|
266
|
+
}
|
|
267
|
+
handleFocus() {
|
|
268
|
+
if (!this.disabled) {
|
|
269
|
+
if (!this.multiple && this._value[0] && this.inputRef.value && this.inputRef.value.type !== "hidden") {
|
|
270
|
+
const t = this.findValueInOptions(this._value[0]);
|
|
271
|
+
this._editingSingleValue = !0, this.inputRef.value.value = this.displayValueAs === "label" && (t != null && t.label) ? t.label : this._value[0];
|
|
272
|
+
}
|
|
273
|
+
this._inputFocus = !0, this._search = "", this._options = [...this.options], this._isOptionsOpen = !0, this.onFocus(), this.requestUpdate();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
handleFocusOut(t) {
|
|
277
|
+
var e, i, s, l, n;
|
|
278
|
+
if (!this.disabled && ((i = (e = t.relatedTarget) == null ? void 0 : e.closest("pkt-combobox")) == null ? void 0 : i.id) !== this.id && ((l = (s = t.relatedTarget) == null ? void 0 : s.closest("pkt-combobox")) == null ? void 0 : l.id) !== this.id && ((n = t.target) == null ? void 0 : n.getAttribute("data-focusfix")) !== this.id && t.relatedTarget !== this.focusRef.value && t.relatedTarget !== this.inputRef.value && t.relatedTarget !== this.arrowRef.value && this._isOptionsOpen) {
|
|
279
|
+
if (this._inputFocus = !1, this._addValueText = null, this._userInfoMessage = "", this._search = "", this.inputRef.value && this.inputRef.value.type !== "hidden" && this.inputRef.value.value !== "") {
|
|
280
|
+
const a = this.inputRef.value.value, u = this.findValueInOptions(a);
|
|
281
|
+
!this._value.includes(a) && !u ? this.allowUserInput ? this.addNewUserValue(a) : this.multiple || this.removeValue(this._value[0]) : u && !this._value.includes(u.value) && this.setSelected(u.value), this.inputRef.value.value = "";
|
|
282
|
+
}
|
|
283
|
+
this._isOptionsOpen = !1, this.onBlur();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
handleBlur() {
|
|
287
|
+
this._inputFocus = !1, this._editingSingleValue = !1, this.onBlur();
|
|
288
|
+
}
|
|
289
|
+
handleInputClick(t) {
|
|
290
|
+
var e, i;
|
|
291
|
+
this.disabled || (t.currentTarget && t.currentTarget !== this.arrowRef.value && ((e = this.inputRef.value) == null ? void 0 : e.type) !== "hidden" ? (i = this.inputRef.value) == null || i.focus() : this.handleArrowClick(t));
|
|
292
|
+
}
|
|
293
|
+
handleArrowClick(t) {
|
|
294
|
+
var e, i;
|
|
295
|
+
this.disabled || t instanceof KeyboardEvent && t.key && t.key !== "Enter" && t.key !== " " && t.key !== "ArrowDown" || (t.stopImmediatePropagation(), t.preventDefault(), this._isOptionsOpen = !this._isOptionsOpen, this._isOptionsOpen ? (e = this.listboxRef.value) == null || e.focusFirstOrSelectedOption() : (i = this.arrowRef.value) == null || i.focus());
|
|
296
|
+
}
|
|
297
|
+
handleOptionToggled(t) {
|
|
298
|
+
this.toggleValue(t.detail);
|
|
299
|
+
}
|
|
300
|
+
handleSearch(t) {
|
|
301
|
+
t.stopPropagation(), this._search = t.detail.toLowerCase();
|
|
302
|
+
}
|
|
303
|
+
handleInputKeydown(t) {
|
|
304
|
+
var e, i, s;
|
|
305
|
+
switch (t.key) {
|
|
306
|
+
case ",":
|
|
307
|
+
case "Enter":
|
|
308
|
+
t.preventDefault(), this.addValue();
|
|
309
|
+
break;
|
|
310
|
+
case "Backspace":
|
|
311
|
+
!this._search && ((e = this.inputRef.value) == null ? void 0 : e.type) === "hidden" && this.removeLastValue(t);
|
|
312
|
+
break;
|
|
313
|
+
case "Tab":
|
|
314
|
+
case "ArrowDown":
|
|
315
|
+
t.shiftKey || ((i = this.listboxRef.value) == null || i.focusFirstOrSelectedOption(), t.preventDefault());
|
|
316
|
+
break;
|
|
317
|
+
case "Escape":
|
|
318
|
+
this._isOptionsOpen = !1, (s = this.arrowRef.value) == null || s.focus(), t.preventDefault();
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
handleTagRemove(t) {
|
|
323
|
+
this.removeSelected(t);
|
|
324
|
+
}
|
|
325
|
+
blurInput() {
|
|
326
|
+
this.inputRef.value && this.inputRef.value.matches(":focus") && this.inputRef.value.blur();
|
|
327
|
+
}
|
|
328
|
+
checkForMatches() {
|
|
329
|
+
var n;
|
|
330
|
+
const t = ((n = this.inputRef.value) == null ? void 0 : n.value) || this._search || "", e = t.trim().toLowerCase() || "";
|
|
331
|
+
if (!e) {
|
|
332
|
+
!this.multiple && this._value[0] && this.removeValue(this._value[0]), this.resetComboboxInput(!1);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const i = this._value.find((a) => a.toLowerCase() === e), s = this._options.filter(
|
|
336
|
+
(a) => {
|
|
337
|
+
var u;
|
|
338
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase().includes(e)) ?? !1;
|
|
339
|
+
}
|
|
340
|
+
), l = s.find(
|
|
341
|
+
(a) => {
|
|
342
|
+
var u;
|
|
343
|
+
return ((u = a.label) == null ? void 0 : u.toLowerCase()) === e || a.value.toLowerCase() === e;
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
switch (!0) {
|
|
347
|
+
case ((s.length === 0 || !l) && this.allowUserInput):
|
|
348
|
+
this._addValueText = t, this._userInfoMessage = "";
|
|
349
|
+
break;
|
|
350
|
+
case (s.length === 0 && !this.allowUserInput):
|
|
351
|
+
this._addValueText = null, this._userInfoMessage = "Ingen match i søket";
|
|
352
|
+
break;
|
|
353
|
+
case !!i:
|
|
354
|
+
this._addValueText = null, this._userInfoMessage = "Verdien er allerede valgt";
|
|
355
|
+
break;
|
|
356
|
+
case s.length > 1:
|
|
357
|
+
this._addValueText = null, this._userInfoMessage = "";
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
this._addValueText = null, this._userInfoMessage = "";
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
findValueInOptions(t) {
|
|
364
|
+
return this.options.find((e) => e.value === t || e.label === t) || null;
|
|
365
|
+
}
|
|
366
|
+
findIndexInOptions(t) {
|
|
367
|
+
return this._options.findIndex((e) => e.value === t || e.label === t);
|
|
368
|
+
}
|
|
369
|
+
isMaxItemsReached() {
|
|
370
|
+
const t = this.maxlength !== null && this._value.length >= this.maxlength;
|
|
371
|
+
return t ? this._maxIsReached = !0 : this._maxIsReached = !1, t;
|
|
372
|
+
}
|
|
373
|
+
toggleValue(t) {
|
|
374
|
+
var I, O;
|
|
375
|
+
if (this.disabled) return;
|
|
376
|
+
this.touched = !0, this._userInfoMessage = "", this._addValueText = null;
|
|
377
|
+
const e = ((I = this.findValueInOptions(t)) == null ? void 0 : I.value) || null, i = this._value.includes(t || e || ""), s = !!e, l = ((O = this._options.find((m) => m.value === t)) == null ? void 0 : O.disabled) || !1, n = !(t != null && t.trim()), a = !this.multiple, u = this.multiple, $ = this.isMaxItemsReached();
|
|
378
|
+
let p = !1, b = !0, g = "", x = "";
|
|
379
|
+
l || (!s && this.allowUserInput && !n ? (this.addNewUserValue(t), g = "Ny verdi lagt til", p = !u) : !s && !this.allowUserInput ? (a && this._value[0] && this.removeValue(this._value[0]), b = !1, p = !0, g = "Ingen treff i søket") : i ? (this.removeValue(e), p = !0) : n && a ? (this.removeAllSelected(), p = !0) : a ? (this._value[0] && this.removeSelected(this._value[0]), this.setSelected(e), p = !1, this.inputRef.value && this.inputRef.value.type !== "hidden" && (this.inputRef.value.value = "", this.inputRef.value.blur())) : u && !$ ? (this.setSelected(e), p = !0) : u && $ ? (this._userInfoMessage = "Maks antall valg nådd", b = !1, x = t) : (a && this.removeAllSelected(), this._userInfoMessage = "Ingen gyldig verdi valgt", b = !1, p = !0, x = t), this._isOptionsOpen = p, p || window.setTimeout(() => {
|
|
380
|
+
var m;
|
|
381
|
+
(m = this.focusRef.value) == null || m.focus();
|
|
382
|
+
}, 0), this._userInfoMessage = g, this._search = x || "", this.resetComboboxInput(b), u && this.isMaxItemsReached());
|
|
383
|
+
}
|
|
384
|
+
setSelected(t) {
|
|
385
|
+
if (!this._value.includes(t)) {
|
|
386
|
+
if (this.multiple && this.isMaxItemsReached()) {
|
|
387
|
+
this._userInfoMessage = "Maks antall valg nådd";
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
!this.multiple && this.removeAllSelected(), this._value = t ? [...this._value, t] : this._value, this._options = this._options.map((e) => (e.value === t && (e.selected = !0), e)), this.resetComboboxInput(!0);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
removeSelected(t) {
|
|
394
|
+
if (!t) return;
|
|
395
|
+
this._value = this._value.filter((i) => i !== t);
|
|
396
|
+
const e = this.findValueInOptions(t);
|
|
397
|
+
e ? (e.selected = !1, e.userAdded ? (this._options = [...this._options.filter((i) => i.value !== t)], this.options = [...this.options.filter((i) => i.value !== t)]) : this._options = [...this._options, e]) : !t && !this.multiple && (this._options = this._options.map((i) => (i.selected = !1, i)));
|
|
398
|
+
}
|
|
399
|
+
addAllOptions() {
|
|
400
|
+
if (this.multiple) {
|
|
401
|
+
if (this.maxlength && this._options.length > this.maxlength) {
|
|
402
|
+
this._userInfoMessage = "For mange valgt";
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this._value = this._options.map((t) => t.value), this._options = this._options.map((t) => (t.selected = !0, t)), this.requestUpdate();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
removeAllSelected() {
|
|
409
|
+
this._value = [], this._options = this._options.map((t) => (t.selected = !1, t)), this._options = this._options.filter((t) => !t.userAdded), this.requestUpdate();
|
|
410
|
+
}
|
|
411
|
+
addValue() {
|
|
412
|
+
var e;
|
|
413
|
+
const t = ((e = this.inputRef.value) == null ? void 0 : e.value.trim()) || "";
|
|
414
|
+
this._search = t, this.toggleValue(t);
|
|
415
|
+
}
|
|
416
|
+
removeValue(t) {
|
|
417
|
+
this._value = this.multiple ? this._value.filter((e) => e !== t) : [], this.removeSelected(t);
|
|
418
|
+
}
|
|
419
|
+
addNewUserValue(t) {
|
|
420
|
+
if (!t || t.trim() === "") return;
|
|
421
|
+
if (!this.multiple)
|
|
422
|
+
this._value[0] && this.removeSelected(this._value[0]), this._value = [t], this._isOptionsOpen = !1, this.blurInput();
|
|
423
|
+
else if (!this.findValueInOptions(t)) {
|
|
424
|
+
if (this.isMaxItemsReached()) return;
|
|
425
|
+
this._value = [...this._value, t];
|
|
426
|
+
}
|
|
427
|
+
const e = { value: t, label: t, userAdded: !0 };
|
|
428
|
+
this.options = [e, ...this.options], this._options = [e, ...this._options], this.setSelected(t), this.requestUpdate();
|
|
429
|
+
}
|
|
430
|
+
resetComboboxInput(t = !0) {
|
|
431
|
+
if (this._addValueText = null, this.inputRef.value && this.inputRef.value.type !== "hidden" && t)
|
|
432
|
+
if (this._search = "", this.multiple)
|
|
433
|
+
this.inputRef.value.value = "";
|
|
434
|
+
else {
|
|
435
|
+
const e = this.findValueInOptions(this._value[0]);
|
|
436
|
+
window.setTimeout(() => {
|
|
437
|
+
!this.inputRef.value || this.inputRef.value.type === "hidden" || (this.inputRef.value.value = this.displayValueAs === "label" && (e != null && e.label) ? e.label : this._value[0] || "");
|
|
438
|
+
}, 0), this._userInfoMessage = "";
|
|
439
|
+
}
|
|
440
|
+
this._options = [...this.options];
|
|
441
|
+
}
|
|
442
|
+
removeLastValue(t) {
|
|
443
|
+
if (this._value.length === 0) return;
|
|
444
|
+
t.preventDefault();
|
|
445
|
+
const e = this._value[this._value.length - 1];
|
|
446
|
+
e && this.removeSelected(e), this.isMaxItemsReached();
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
o([
|
|
450
|
+
r({ type: String, reflect: !0 })
|
|
451
|
+
], h.prototype, "value", 2);
|
|
452
|
+
o([
|
|
453
|
+
r({ type: Array })
|
|
454
|
+
], h.prototype, "options", 2);
|
|
455
|
+
o([
|
|
456
|
+
r({ type: Array })
|
|
457
|
+
], h.prototype, "defaultOptions", 2);
|
|
458
|
+
o([
|
|
459
|
+
r({ type: Boolean })
|
|
460
|
+
], h.prototype, "allowUserInput", 2);
|
|
461
|
+
o([
|
|
462
|
+
r({ type: Boolean })
|
|
463
|
+
], h.prototype, "typeahead", 2);
|
|
464
|
+
o([
|
|
465
|
+
r({ type: Boolean })
|
|
466
|
+
], h.prototype, "includeSearch", 2);
|
|
467
|
+
o([
|
|
468
|
+
r({ type: String })
|
|
469
|
+
], h.prototype, "searchPlaceholder", 2);
|
|
470
|
+
o([
|
|
471
|
+
r({ type: Boolean })
|
|
472
|
+
], h.prototype, "multiple", 2);
|
|
473
|
+
o([
|
|
474
|
+
r({ type: Number })
|
|
475
|
+
], h.prototype, "maxlength", 2);
|
|
476
|
+
o([
|
|
477
|
+
r({ type: String })
|
|
478
|
+
], h.prototype, "displayValueAs", 2);
|
|
479
|
+
o([
|
|
480
|
+
r({ type: String })
|
|
481
|
+
], h.prototype, "tagPlacement", 2);
|
|
482
|
+
o([
|
|
483
|
+
c()
|
|
484
|
+
], h.prototype, "_options", 2);
|
|
485
|
+
o([
|
|
486
|
+
c()
|
|
487
|
+
], h.prototype, "_isOptionsOpen", 2);
|
|
488
|
+
o([
|
|
489
|
+
c()
|
|
490
|
+
], h.prototype, "_value", 2);
|
|
491
|
+
o([
|
|
492
|
+
c()
|
|
493
|
+
], h.prototype, "_userInfoMessage", 2);
|
|
494
|
+
o([
|
|
495
|
+
c()
|
|
496
|
+
], h.prototype, "_addValueText", 2);
|
|
497
|
+
o([
|
|
498
|
+
c()
|
|
499
|
+
], h.prototype, "_maxIsReached", 2);
|
|
500
|
+
o([
|
|
501
|
+
c()
|
|
502
|
+
], h.prototype, "_search", 2);
|
|
503
|
+
o([
|
|
504
|
+
c()
|
|
505
|
+
], h.prototype, "_inputFocus", 2);
|
|
506
|
+
o([
|
|
507
|
+
c()
|
|
508
|
+
], h.prototype, "_editingSingleValue", 2);
|
|
509
|
+
h = o([
|
|
510
|
+
k("pkt-combobox")
|
|
511
|
+
], h);
|
|
512
|
+
export {
|
|
513
|
+
h as P
|
|
514
|
+
};
|