@oslokommune/punkt-elements 12.18.0 → 12.18.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.
- package/dist/alert-BbVWu2lm.cjs +27 -0
- package/dist/alert-Dh6A96vo.js +159 -0
- package/dist/{index-D2jSRMrn.js → calendar-BUqcNvfI.js} +41 -29
- package/dist/calendar-QSulz7im.cjs +108 -0
- package/dist/card-B0GPdG5M.cjs +23 -0
- package/dist/card-kWt0BA2a.js +170 -0
- package/dist/{class-map-a5HUzP83.cjs → class-map-Boa7BqCc.cjs} +2 -2
- package/dist/{class-map-CBvUV2N3.js → class-map-hz16xq5a.js} +9 -10
- package/dist/datepicker-BhavwiBZ.js +659 -0
- package/dist/datepicker-vX74tb3R.cjs +154 -0
- package/dist/helptext--4FLdAWi.js +194 -0
- package/dist/helptext-iZEgxz2U.cjs +23 -0
- package/dist/icon-CdMQ6zBT.cjs +250 -0
- package/dist/{index-CFDwiDTU.js → icon-wUXeHiBk.js} +7371 -7559
- package/dist/if-defined-DEDlGbAc.cjs +5 -0
- package/dist/if-defined-ZFE4ti2t.js +10 -0
- package/dist/index.d.ts +49 -51
- package/dist/input-element-BQTCZtNQ.js +185 -0
- package/dist/input-element-DNklGY_O.cjs +1 -0
- package/dist/{input-wrapper-DVXNuxVu.js → input-wrapper-BTQk3W8T.js} +10 -11
- package/dist/input-wrapper-D-PNRJB_.cjs +46 -0
- package/dist/link-BpqavGSD.cjs +8 -0
- package/dist/link-Bx9nVgZi.js +108 -0
- package/dist/linkcard-CUrbzjLK.js +53 -0
- package/dist/linkcard-DSu3A4Yx.cjs +13 -0
- package/dist/messagebox-C1aWoQbu.cjs +12 -0
- package/dist/messagebox-LpiVQIoM.js +107 -0
- package/dist/modal-Avai5eVz.cjs +30 -0
- package/dist/{modal-lQfiTbGh.js → modal-Co1YFmHi.js} +7 -8
- package/dist/pkt-alert.cjs +1 -27
- package/dist/pkt-alert.js +4 -158
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +4 -7
- package/dist/pkt-card.cjs +1 -23
- package/dist/pkt-card.js +4 -169
- package/dist/pkt-datepicker.cjs +1 -154
- package/dist/pkt-datepicker.js +4 -657
- package/dist/pkt-helptext.cjs +1 -1
- package/dist/pkt-helptext.js +1 -1
- package/dist/pkt-icon.cjs +1 -1
- package/dist/pkt-icon.js +4 -4
- package/dist/pkt-index.cjs +29 -1
- package/dist/pkt-index.js +127 -32
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-link.cjs +1 -8
- package/dist/pkt-link.js +4 -108
- package/dist/pkt-linkcard.cjs +1 -1
- package/dist/pkt-linkcard.js +1 -1
- package/dist/pkt-messagebox.cjs +1 -12
- package/dist/pkt-messagebox.js +4 -106
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/pkt-progressbar.cjs +1 -1
- package/dist/pkt-progressbar.js +2 -2
- package/dist/pkt-tag.cjs +1 -17
- package/dist/pkt-tag.js +4 -149
- package/dist/pkt-textarea.cjs +1 -1
- package/dist/pkt-textarea.js +1 -1
- package/dist/pkt-textinput.cjs +1 -1
- package/dist/pkt-textinput.js +1 -1
- package/dist/{progressbar-1PEs_SMc.js → progressbar-BS_oawSB.js} +42 -47
- package/dist/{progressbar-BlzTFI9U.cjs → progressbar-CuXkbAhJ.cjs} +7 -11
- package/dist/ref-DCOsLZQg.cjs +13 -0
- package/dist/{ref-Dzme4zb6.js → ref-DuFGTLVX.js} +26 -27
- package/dist/state-BfyXV7EL.js +12 -0
- package/dist/state-SKYD8kRO.cjs +5 -0
- package/dist/stringutils-CkVRq4jP.cjs +1 -0
- package/dist/stringutils-DJjRa8dG.js +7 -0
- package/dist/tag-CGy2mSLE.cjs +17 -0
- package/dist/tag-DGFgUF3l.js +150 -0
- package/dist/textarea-BFWHQHLs.cjs +48 -0
- package/dist/{textarea-BXzQA_ub.js → textarea-BYtGXst8.js} +29 -29
- package/dist/{textinput-52G3CfwA.cjs → textinput-33wZwZ4O.cjs} +2 -2
- package/dist/{textinput-CTNWiIaP.js → textinput-IgHewJDJ.js} +23 -23
- package/package.json +2 -2
- package/src/components/alert/alert.ts +115 -0
- package/src/components/alert/index.ts +4 -113
- package/src/components/calendar/calendar.ts +711 -0
- package/src/components/calendar/index.ts +3 -711
- package/src/components/card/card.ts +78 -0
- package/src/components/card/index.ts +4 -77
- package/src/components/datepicker/datepicker.ts +619 -0
- package/src/components/datepicker/index.ts +3 -618
- package/src/components/helptext/helptext.ts +2 -2
- package/src/components/icon/icon.ts +99 -0
- package/src/components/icon/index.ts +3 -98
- package/src/components/index.ts +21 -17
- package/src/components/input-wrapper/input-wrapper.ts +2 -2
- package/src/components/link/index.ts +3 -56
- package/src/components/link/link.ts +57 -0
- package/src/components/linkcard/index.ts +1 -1
- package/src/components/linkcard/linkcard.ts +5 -6
- package/src/components/messagebox/index.ts +4 -69
- package/src/components/messagebox/messagebox.ts +69 -0
- package/src/components/modal/index.ts +0 -1
- package/src/components/modal/modal.ts +5 -7
- package/src/components/progressbar/progressbar.ts +2 -2
- package/src/components/tag/index.ts +4 -109
- package/src/components/tag/tag.ts +118 -0
- package/src/components/textarea/textarea.ts +5 -4
- package/src/components/textinput/textinput.ts +3 -3
- package/dist/component-template.d.ts +0 -8
- package/dist/converters-DNCwIFwr.js +0 -17
- package/dist/converters-DhM11VlY.cjs +0 -1
- package/dist/custom-element-B-TlBwRu.cjs +0 -9
- package/dist/custom-element-CWfU4dcr.js +0 -38
- package/dist/element.d.ts +0 -8
- package/dist/helptext-DBolvFI4.js +0 -72
- package/dist/helptext-_fMLOOCL.cjs +0 -23
- package/dist/index-CR7t1zY9.cjs +0 -238
- package/dist/index-CmTjXoAb.cjs +0 -9
- package/dist/index-RwtTBIhT.js +0 -88
- package/dist/index-tvpcg-ad.cjs +0 -108
- package/dist/input-wrapper-tJE-X4Ac.cjs +0 -46
- package/dist/linkcard-BHokvuVN.js +0 -55
- package/dist/linkcard-CUXMP6BH.cjs +0 -13
- package/dist/modal-CjsQgmmH.cjs +0 -30
- package/dist/pkt-component-template.cjs +0 -29
- package/dist/pkt-component-template.js +0 -100
- package/dist/pkt-element.cjs +0 -1
- package/dist/pkt-element.js +0 -5
- package/dist/ref-CA2-0S_W.cjs +0 -13
- package/dist/textarea-D_ud1Mpa.cjs +0 -48
- package/src/components/component-template/index.ts +0 -129
- package/src/components/element/index.ts +0 -353
package/dist/ref-CA2-0S_W.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";const l=require("./index-CR7t1zY9.cjs"),d=require("./custom-element-B-TlBwRu.cjs");/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/const{I:p}=l.Z,a=t=>t.strings===void 0,u=()=>document.createComment(""),Y=(t,s,e)=>{var h;const i=t._$AA.parentNode,n=s===void 0?t._$AB:s._$AA;if(e===void 0){const r=i.insertBefore(u(),n),$=i.insertBefore(u(),n);e=new p(r,$,t,t.options)}else{const r=e._$AB.nextSibling,$=e._$AM,f=$!==t;if(f){let o;(h=e._$AQ)==null||h.call(e,t),e._$AM=t,e._$AP!==void 0&&(o=t._$AU)!==$._$AU&&e._$AP(o)}if(r!==n||f){let o=e._$AA;for(;o!==r;){const g=o.nextSibling;i.insertBefore(o,n),o=g}}}return e},m=(t,s,e=t)=>(t._$AI(s,e),t),C={},M=(t,s=C)=>t._$AH=s,b=t=>t._$AH,N=t=>{var i;(i=t._$AP)==null||i.call(t,!1,!0);let s=t._$AA;const e=t._$AB.nextSibling;for(;s!==e;){const n=s.nextSibling;s.remove(),s=n}};/**
|
|
6
|
-
* @license
|
|
7
|
-
* Copyright 2017 Google LLC
|
|
8
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const c=(t,s)=>{var i;const e=t._$AN;if(e===void 0)return!1;for(const n of e)(i=n._$AO)==null||i.call(n,s,!1),c(n,s);return!0},A=t=>{let s,e;do{if((s=t._$AM)===void 0)break;e=s._$AN,e.delete(t),t=s}while((e==null?void 0:e.size)===0)},v=t=>{for(let s;s=t._$AM;t=s){let e=s._$AN;if(e===void 0)s._$AN=e=new Set;else if(e.has(t))break;e.add(t),B(s)}};function w(t){this._$AN!==void 0?(A(this),this._$AM=t,v(this)):this._$AM=t}function x(t,s=!1,e=0){const i=this._$AH,n=this._$AN;if(n!==void 0&&n.size!==0)if(s)if(Array.isArray(i))for(let h=e;h<i.length;h++)c(i[h],!1),A(i[h]);else i!=null&&(c(i,!1),A(i));else c(this,t)}const B=t=>{t.type==d.t$1.CHILD&&(t._$AP??(t._$AP=x),t._$AQ??(t._$AQ=w))};class y extends d.i{constructor(){super(...arguments),this._$AN=void 0}_$AT(s,e,i){super._$AT(s,e,i),v(this),this.isConnected=s._$AU}_$AO(s,e=!0){var i,n;s!==this.isConnected&&(this.isConnected=s,s?(i=this.reconnected)==null||i.call(this):(n=this.disconnected)==null||n.call(this)),e&&(c(this,s),A(this))}setValue(s){if(a(this._$Ct))this._$Ct._$AI(s,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=s,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}/**
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright 2020 Google LLC
|
|
12
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
13
|
-
*/const H=()=>new I;class I{}const _=new WeakMap,S=d.e(class extends y{render(t){return l.E}update(t,[s]){var i;const e=s!==this.Y;return e&&this.Y!==void 0&&this.rt(void 0),(e||this.lt!==this.ct)&&(this.Y=s,this.ht=(i=t.options)==null?void 0:i.host,this.rt(this.ct=t.element)),l.E}rt(t){if(this.isConnected||(t=void 0),typeof this.Y=="function"){const s=this.ht??globalThis;let e=_.get(s);e===void 0&&(e=new WeakMap,_.set(s,e)),e.get(this.Y)!==void 0&&this.Y.call(this.ht,void 0),e.set(this.Y,t),t!==void 0&&this.Y.call(this.ht,t)}else this.Y.value=t}get lt(){var t,s;return typeof this.Y=="function"?(t=_.get(this.ht??globalThis))==null?void 0:t.get(this.Y):(s=this.Y)==null?void 0:s.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});exports.M=N;exports.e=H;exports.f=a;exports.m=M;exports.n=S;exports.p=b;exports.r=Y;exports.v=m;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";const a=require("./index-CR7t1zY9.cjs"),s=require("./custom-element-B-TlBwRu.cjs"),u=require("./ref-CA2-0S_W.cjs"),p=require("./class-map-a5HUzP83.cjs");require("./input-wrapper-tJE-X4Ac.cjs");require("./index-CmTjXoAb.cjs");/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/const d=s.e(class extends s.i{constructor(r){if(super(r),r.type!==s.t$1.PROPERTY&&r.type!==s.t$1.ATTRIBUTE&&r.type!==s.t$1.BOOLEAN_ATTRIBUTE)throw Error("The `live` directive is not allowed on child or event bindings");if(!u.f(r))throw Error("`live` bindings can only contain a single expression")}render(r){return r}update(r,[e]){if(e===a.T||e===a.E)return e;const i=r.element,t=r.name;if(r.type===s.t$1.PROPERTY){if(e===i[t])return a.T}else if(r.type===s.t$1.BOOLEAN_ATTRIBUTE){if(!!e===i.hasAttribute(t))return a.T}else if(r.type===s.t$1.ATTRIBUTE&&i.getAttribute(t)===e+"")return a.T;return u.m(r),e}});var c=Object.defineProperty,$=Object.getOwnPropertyDescriptor,o=(r,e,i,t)=>{for(var n=t>1?void 0:t?$(e,i):e,l=r.length-1,h;l>=0;l--)(h=r[l])&&(n=(t?h(e,i,n):h(n))||n);return t&&n&&c(e,i,n),n};exports.PktTextarea=class extends a.PktInputElement{constructor(){super(...arguments),this.value="",this.autocomplete="off",this.placeholder="",this.rows=null,this.counterCurrent=0,this.inputRef=u.e()}attributeChangedCallback(e,i,t){e==="value"&&this.value!==i&&(this.counterCurrent=t?t.length:0,this.valueChanged(t,i)),super.attributeChangedCallback(e,i,t)}updated(e){var i;super.updated(e),e.has("value")&&(this.counterCurrent=((i=this.value)==null?void 0:i.length)||0,this.valueChanged(this.value,e.get("value"))),e.has("id")&&!this.name&&this.id&&(this.name=this.id)}render(){const e=p.e({"pkt-input":!0,"pkt-input--fullwidth":this.fullwidth,"pkt-input--counter-error":this.counter&&this.counterMaxLength&&this.value.length&&this.value.length>this.counterMaxLength}),i=this.ariaLabelledby||`${this.id}-input-label`;return a.x`<pkt-input-wrapper
|
|
6
|
-
label="${this.label}"
|
|
7
|
-
?counter=${this.counter}
|
|
8
|
-
?disabled=${this.disabled}
|
|
9
|
-
?hasError=${this.hasError}
|
|
10
|
-
?inline=${this.inline}
|
|
11
|
-
?optionalTag=${this.optionalTag}
|
|
12
|
-
?required=${this.required}
|
|
13
|
-
?requiredTag=${this.requiredTag}
|
|
14
|
-
?useWrapper=${this.useWrapper}
|
|
15
|
-
.ariaDescribedBy=${this.ariaDescribedBy}
|
|
16
|
-
.counterCurrent=${this.counterCurrent}
|
|
17
|
-
.counterMaxLength=${this.counterMaxLength}
|
|
18
|
-
.errorMessage=${this.errorMessage}
|
|
19
|
-
.forId="${this.id+"-input"}"
|
|
20
|
-
.helptext=${this.helptext}
|
|
21
|
-
.helptextDropdown=${this.helptextDropdown}
|
|
22
|
-
.helptextDropdownButton=${this.helptextDropdownButton}
|
|
23
|
-
.optionalText=${this.optionalText}
|
|
24
|
-
.requiredText=${this.requiredText}
|
|
25
|
-
class="pkt-textarea"
|
|
26
|
-
>
|
|
27
|
-
<textarea
|
|
28
|
-
${u.n(this.inputRef)}
|
|
29
|
-
class=${e}
|
|
30
|
-
id=${this.id+"-input"}
|
|
31
|
-
name=${(this.name||this.id)+"-input"}
|
|
32
|
-
placeholder=${this.placeholder??a.E}
|
|
33
|
-
.value=${d(this.value)}
|
|
34
|
-
minlength=${this.minlength||a.E}
|
|
35
|
-
maxlength=${this.maxlength||a.E}
|
|
36
|
-
?readonly=${this.readonly}
|
|
37
|
-
autocomplete=${this.autocomplete}
|
|
38
|
-
aria-labelledby=${i}
|
|
39
|
-
aria-invalid=${this.hasError}
|
|
40
|
-
aria-errormessage=${`${this.id}-error`}
|
|
41
|
-
rows=${this.rows}
|
|
42
|
-
?disabled=${this.disabled}
|
|
43
|
-
@input=${t=>{this.value=t.target.value,this.onInput(),t.stopImmediatePropagation()}}
|
|
44
|
-
@change=${t=>{t.stopImmediatePropagation()}}
|
|
45
|
-
@focus=${t=>{this.onFocus(),t.stopImmediatePropagation()}}
|
|
46
|
-
@blur=${t=>{this.value=t.target.value,this.onBlur(),t.stopImmediatePropagation()}}
|
|
47
|
-
></textarea>
|
|
48
|
-
</pkt-input-wrapper>`}};o([a.n({type:String,reflect:!0})],exports.PktTextarea.prototype,"value",2);o([a.n({type:String})],exports.PktTextarea.prototype,"autocomplete",2);o([a.n({type:String})],exports.PktTextarea.prototype,"placeholder",2);o([a.n({type:Number})],exports.PktTextarea.prototype,"rows",2);o([a.r()],exports.PktTextarea.prototype,"counterCurrent",2);exports.PktTextarea=o([s.t("pkt-textarea")],exports.PktTextarea);
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { html } from 'lit'
|
|
2
|
-
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
-
import { PktElement } from '../element'
|
|
4
|
-
import { PktSlotController } from '@/controllers/pkt-slot-controller'
|
|
5
|
-
import { ref, Ref, createRef } from 'lit/directives/ref.js'
|
|
6
|
-
|
|
7
|
-
// If you need to convert an object to a list of classes, use classMap
|
|
8
|
-
import { classMap } from 'lit/directives/class-map.js'
|
|
9
|
-
|
|
10
|
-
// If you need text strings add them in this file and include it
|
|
11
|
-
import translations from '../../translations/no.json'
|
|
12
|
-
|
|
13
|
-
// If you need to convert attribute strings to JavaScript objects,
|
|
14
|
-
// use helpers from converters.ts
|
|
15
|
-
import { csvToArray } from '../../helpers/converters'
|
|
16
|
-
|
|
17
|
-
@customElement('pkt-component')
|
|
18
|
-
export class PktComponent extends PktElement {
|
|
19
|
-
/**
|
|
20
|
-
* Element attributes => props
|
|
21
|
-
* Example:
|
|
22
|
-
* <pkt-component string="hei" strings="hei,og,hallo" darkmode>
|
|
23
|
-
* Hei!
|
|
24
|
-
* </pkt-component>
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
@property({ type: String })
|
|
28
|
-
string: string = ''
|
|
29
|
-
|
|
30
|
-
@property({ converter: csvToArray })
|
|
31
|
-
strings: string[] = []
|
|
32
|
-
|
|
33
|
-
@property({ type: Boolean })
|
|
34
|
-
darkmode: boolean = false
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Private properties, for internal use only
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
@property({ type: Array }) private _list: string[] = []
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Runs on mount, used to set up various values and whatever you need to run
|
|
44
|
-
*/
|
|
45
|
-
connectedCallback() {
|
|
46
|
-
this.strings.length &&
|
|
47
|
-
this.strings.forEach((string) => {
|
|
48
|
-
this._list.push(string.toUpperCase())
|
|
49
|
-
})
|
|
50
|
-
super.connectedCallback()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Set up slot support for Light DOM
|
|
55
|
-
*/
|
|
56
|
-
slotController: PktSlotController
|
|
57
|
-
defaultSlot: Ref<HTMLElement> = createRef()
|
|
58
|
-
namedSlot: Ref<HTMLElement> = createRef()
|
|
59
|
-
|
|
60
|
-
constructor() {
|
|
61
|
-
super()
|
|
62
|
-
this.slotController = new PktSlotController(this, this.defaultSlot, this.namedSlot)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Render functions
|
|
67
|
-
*/
|
|
68
|
-
render() {
|
|
69
|
-
const classes = {
|
|
70
|
-
'pkt-component': true,
|
|
71
|
-
'pkt-component--has-list': this.strings.length > 0,
|
|
72
|
-
'pkt-darkmode': this.darkmode,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return html`
|
|
76
|
-
<div class="${classMap(classes)}">
|
|
77
|
-
<h1 class="pkt-txt-28">${this.string}</h1>
|
|
78
|
-
|
|
79
|
-
<h2 class="pkt-txt-22">Innhold fra attributter og funksjoner</h2>
|
|
80
|
-
<div>${this.renderList(this.strings)}</div>
|
|
81
|
-
<div>${this.renderList(this.doStuff(this._list))}</div>
|
|
82
|
-
|
|
83
|
-
<h2 class="pkt-txt-22">Slot</h2>
|
|
84
|
-
<div ${ref(this.defaultSlot)}>defaultSlotRef</div>
|
|
85
|
-
<h2 class="pkt-txt-22">Named slot</h2>
|
|
86
|
-
<select
|
|
87
|
-
name="named-slot"
|
|
88
|
-
${ref(this.namedSlot)}
|
|
89
|
-
@change=${(e: Event) => alert((e.target as HTMLSelectElement).value)}
|
|
90
|
-
>
|
|
91
|
-
namedSlotRef
|
|
92
|
-
</select>
|
|
93
|
-
|
|
94
|
-
<h2 class="pkt-txt-22">Knapp som emitter en event</h2>
|
|
95
|
-
<button type="button" @click=${() => this.handleGreeting()}>
|
|
96
|
-
Si ${translations.example.hi}
|
|
97
|
-
</button>
|
|
98
|
-
</div>
|
|
99
|
-
`
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private renderList(list: string[]) {
|
|
103
|
-
return html`
|
|
104
|
-
<ul>
|
|
105
|
-
${list.map((i) => html`<li>${i}</li>`)}
|
|
106
|
-
</ul>
|
|
107
|
-
`
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Add other functionality under here
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
private doStuff(val: string[]) {
|
|
115
|
-
return val.reverse()
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Handlers for returning data from the component
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
private handleGreeting() {
|
|
123
|
-
this.dispatchEvent(
|
|
124
|
-
new CustomEvent('pkt-greeting', {
|
|
125
|
-
detail: 'Hei på deg!',
|
|
126
|
-
}),
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import { LitElement, PropertyValues } from 'lit'
|
|
2
|
-
import { property, state } from 'lit/decorators.js'
|
|
3
|
-
import { uuidish } from '@/utils/stringutils'
|
|
4
|
-
import { renderReactNode } from '@/helpers/renderers'
|
|
5
|
-
import strings from '../../translations/no.json'
|
|
6
|
-
import inputwrapperspecs from 'componentSpecs/input-wrapper.json'
|
|
7
|
-
import 'element-internals-polyfill'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Base class for all Punkt elements
|
|
11
|
-
* @extends LitElement
|
|
12
|
-
*/
|
|
13
|
-
export class PktElement extends LitElement {
|
|
14
|
-
[key: string]: any
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
@property({ type: Object }) strings: any = strings
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Runs on mount, used to set up various values and whatever you need to run
|
|
20
|
-
*/
|
|
21
|
-
connectedCallback() {
|
|
22
|
-
super.connectedCallback()
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Make sure the component renders in light DOM instead of shadow DOM
|
|
26
|
-
*/
|
|
27
|
-
createRenderRoot() {
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Add support for Hot Module Reloading in dev mode
|
|
33
|
-
*/
|
|
34
|
-
hotReplacedCallback() {
|
|
35
|
-
this.requestUpdate()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Go through changed properties and find ReactNodes to render out
|
|
40
|
-
*/
|
|
41
|
-
protected update(changedProperties: PropertyValues) {
|
|
42
|
-
changedProperties.forEach((_oldValue, propName) => {
|
|
43
|
-
if (
|
|
44
|
-
typeof propName === 'string' &&
|
|
45
|
-
this[propName] &&
|
|
46
|
-
typeof this[propName] === 'object' &&
|
|
47
|
-
this[propName].$$typeof
|
|
48
|
-
) {
|
|
49
|
-
this[propName] = renderReactNode(this[propName])
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
super.update(changedProperties)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Add extra stuff here whenever we decide what should be added here…
|
|
57
|
-
*/
|
|
58
|
-
constructor() {
|
|
59
|
-
super()
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Base class for all Punkt input elements
|
|
65
|
-
* @extends PktElement
|
|
66
|
-
*/
|
|
67
|
-
export class PktInputElement extends PktElement {
|
|
68
|
-
static get formAssociated() {
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@property({ type: String, reflect: true })
|
|
73
|
-
id: string = uuidish()
|
|
74
|
-
|
|
75
|
-
@property({ type: String, reflect: true })
|
|
76
|
-
name: string = ''
|
|
77
|
-
|
|
78
|
-
@property({ type: Boolean, reflect: true })
|
|
79
|
-
required: boolean = false
|
|
80
|
-
|
|
81
|
-
@property({ type: Boolean, reflect: true })
|
|
82
|
-
disabled: boolean = false
|
|
83
|
-
|
|
84
|
-
@property({ type: String, reflect: true })
|
|
85
|
-
placeholder: string = ''
|
|
86
|
-
|
|
87
|
-
@property({ type: Number, reflect: true })
|
|
88
|
-
min: string | number | null = null
|
|
89
|
-
|
|
90
|
-
@property({ type: Number, reflect: true })
|
|
91
|
-
max: string | number | null = null
|
|
92
|
-
|
|
93
|
-
@property({ type: Number, reflect: true })
|
|
94
|
-
minlength: number | null = 0
|
|
95
|
-
|
|
96
|
-
@property({ type: Number, reflect: true })
|
|
97
|
-
maxlength: number | null = 0
|
|
98
|
-
|
|
99
|
-
@property({ type: String, reflect: true })
|
|
100
|
-
pattern: string = ''
|
|
101
|
-
|
|
102
|
-
@property({ type: Boolean, reflect: true })
|
|
103
|
-
readonly: boolean = false
|
|
104
|
-
|
|
105
|
-
@property({ type: String })
|
|
106
|
-
ariaLabelledby: string | null = null
|
|
107
|
-
|
|
108
|
-
@property({ type: String })
|
|
109
|
-
ariaDescribedBy: string | null = null
|
|
110
|
-
|
|
111
|
-
// Properties for InputWrapper
|
|
112
|
-
@property({ type: String })
|
|
113
|
-
label: string | null = null
|
|
114
|
-
|
|
115
|
-
@property({ type: Boolean })
|
|
116
|
-
inline: boolean = false
|
|
117
|
-
|
|
118
|
-
@property({ type: Boolean })
|
|
119
|
-
optionalTag: boolean = false
|
|
120
|
-
|
|
121
|
-
@property({ type: String })
|
|
122
|
-
optionalText: string = strings.forms.labels.optional
|
|
123
|
-
|
|
124
|
-
@property({ type: Boolean })
|
|
125
|
-
requiredTag: boolean = false
|
|
126
|
-
|
|
127
|
-
@property({ type: String })
|
|
128
|
-
requiredText: string = strings.forms.labels.required
|
|
129
|
-
|
|
130
|
-
@property({ type: Boolean })
|
|
131
|
-
hasError: boolean = false
|
|
132
|
-
|
|
133
|
-
@property({ type: String })
|
|
134
|
-
errorMessage: string = ''
|
|
135
|
-
|
|
136
|
-
@property({ type: String })
|
|
137
|
-
helptext: string = ''
|
|
138
|
-
|
|
139
|
-
@property({ type: Boolean })
|
|
140
|
-
counter: boolean = false
|
|
141
|
-
|
|
142
|
-
@property({ type: Number })
|
|
143
|
-
counterMaxLength: number = 0
|
|
144
|
-
|
|
145
|
-
@property({ type: String })
|
|
146
|
-
helptextDropdown: string = ''
|
|
147
|
-
|
|
148
|
-
@property({ type: String })
|
|
149
|
-
helptextDropdownButton: string | null = inputwrapperspecs.props.helptextDropdownButton.default
|
|
150
|
-
|
|
151
|
-
@property({ type: Boolean, reflect: true })
|
|
152
|
-
fullwidth: boolean = false
|
|
153
|
-
|
|
154
|
-
@property({ type: Boolean })
|
|
155
|
-
useWrapper: boolean = true
|
|
156
|
-
|
|
157
|
-
@property({ type: String, attribute: 'data-testid' })
|
|
158
|
-
dataTestid: string = ''
|
|
159
|
-
|
|
160
|
-
@property({ type: Boolean })
|
|
161
|
-
skipForwardTestid: boolean = false
|
|
162
|
-
|
|
163
|
-
@state() touched: boolean = false
|
|
164
|
-
|
|
165
|
-
constructor() {
|
|
166
|
-
super()
|
|
167
|
-
this.internals = this.attachInternals()
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
protected manageValidity(input: HTMLInputElement) {
|
|
171
|
-
/**
|
|
172
|
-
* This is where we define all the various validations and set the validity state
|
|
173
|
-
*/
|
|
174
|
-
if (this.required && !this.value) {
|
|
175
|
-
// If the input is required and the value is empty
|
|
176
|
-
this.internals.setValidity({ valueMissing: true }, strings.forms.messages.required, input)
|
|
177
|
-
} else if (input.validity.typeMismatch || input.validity.badInput) {
|
|
178
|
-
// If the input type is wrong
|
|
179
|
-
this.internals.setValidity({ typeMismatch: true }, strings.forms.messages.invalid, input)
|
|
180
|
-
} else if (input.validity.patternMismatch) {
|
|
181
|
-
// If the input pattern is wrong
|
|
182
|
-
this.internals.setValidity(
|
|
183
|
-
{ patternMismatch: true },
|
|
184
|
-
strings.forms.messages.invalidPattern,
|
|
185
|
-
input,
|
|
186
|
-
)
|
|
187
|
-
} else if (
|
|
188
|
-
input.validity.tooShort ||
|
|
189
|
-
(this.minlength && this.minlength > 0 && this.value.length < this.minlength)
|
|
190
|
-
) {
|
|
191
|
-
// If the input is too short or too few items selected
|
|
192
|
-
this.internals.setValidity({ tooShort: true }, strings.forms.messages.tooShort, input)
|
|
193
|
-
} else if (
|
|
194
|
-
input.validity.tooLong ||
|
|
195
|
-
(this.maxlength && this.maxlength > 0 && this.value.length > this.maxlength)
|
|
196
|
-
) {
|
|
197
|
-
// If the input is too long or too many items selected
|
|
198
|
-
this.internals.setValidity({ tooLong: true }, strings.forms.messages.tooLong, input)
|
|
199
|
-
} else if (input.validity.rangeUnderflow) {
|
|
200
|
-
// If the input is too low or date is too early
|
|
201
|
-
this.internals.setValidity(
|
|
202
|
-
{ rangeUnderflow: true },
|
|
203
|
-
strings.forms.messages.rangeUnderflow,
|
|
204
|
-
input,
|
|
205
|
-
)
|
|
206
|
-
} else if (input.validity.rangeOverflow) {
|
|
207
|
-
// If the input is too high or date is too late
|
|
208
|
-
this.internals.setValidity(
|
|
209
|
-
{ rangeOverflow: true },
|
|
210
|
-
strings.forms.messages.rangeOverflow,
|
|
211
|
-
input,
|
|
212
|
-
)
|
|
213
|
-
} else if (input.validity.customError) {
|
|
214
|
-
// If a custom error is set
|
|
215
|
-
this.internals.setValidity({ customError: true }, input.validationMessage, input)
|
|
216
|
-
} else {
|
|
217
|
-
// If everything is fine
|
|
218
|
-
this.internals.setValidity({})
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
protected setFormValue(value: string | string[]): void {
|
|
223
|
-
if (this.internals) {
|
|
224
|
-
if (Array.isArray(value)) {
|
|
225
|
-
const form = new FormData()
|
|
226
|
-
value.forEach((v) => {
|
|
227
|
-
form.append(this.name, v)
|
|
228
|
-
})
|
|
229
|
-
this.internals.setFormValue(form)
|
|
230
|
-
} else {
|
|
231
|
-
this.internals.setFormValue(value)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
protected valueChanged(value: string | string[] | null, _old: string | string[] | null): void {
|
|
237
|
-
if (_old !== this.value || _old !== this._value) {
|
|
238
|
-
if (typeof value === 'string') {
|
|
239
|
-
if ((this.multiple || this.range) && value.includes(',')) {
|
|
240
|
-
value = value.split(',')
|
|
241
|
-
}
|
|
242
|
-
this.value = value
|
|
243
|
-
this._value = Array.isArray(value) ? value : [value]
|
|
244
|
-
} else if (Array.isArray(value)) {
|
|
245
|
-
this.value = value
|
|
246
|
-
this._value = value
|
|
247
|
-
} else {
|
|
248
|
-
this.value = ''
|
|
249
|
-
this._value = []
|
|
250
|
-
}
|
|
251
|
-
if ((!this.value || this.value.length === 0) && _old && _old.length !== 0) {
|
|
252
|
-
this.clearInputValue()
|
|
253
|
-
} else if (this.value && this.value.toString() !== _old?.toString()) {
|
|
254
|
-
this.onChange(this.value)
|
|
255
|
-
}
|
|
256
|
-
this.updateComplete.then(() => this.requestUpdate())
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// When input goes from content to no content
|
|
261
|
-
protected clearInputValue(): void {
|
|
262
|
-
const value = this.multiple || this.range ? [] : ''
|
|
263
|
-
this.value = value
|
|
264
|
-
this.internals.setFormValue(value)
|
|
265
|
-
this.dispatchEvent(new Event('change'))
|
|
266
|
-
this.dispatchEvent(
|
|
267
|
-
new CustomEvent('value-change', {
|
|
268
|
-
detail: value,
|
|
269
|
-
bubbles: true,
|
|
270
|
-
composed: true,
|
|
271
|
-
}),
|
|
272
|
-
)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// When user enters the input, we need to push that event out to the form
|
|
276
|
-
protected onFocus(): void {
|
|
277
|
-
this.dispatchEvent(new FocusEvent('focus'))
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// And also when the user leaves the input...
|
|
281
|
-
protected onBlur(): void {
|
|
282
|
-
this.dispatchEvent(new FocusEvent('blur'))
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Trigger this when user types in the input
|
|
286
|
-
protected onInput(): void {
|
|
287
|
-
this.dispatchEvent(new InputEvent('input'))
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// Trigger this when you want to set the value of the input out to the form
|
|
291
|
-
protected onChange(value: string | string[]): void {
|
|
292
|
-
if (!this.touched) {
|
|
293
|
-
this.touched = true
|
|
294
|
-
value && this.setFormValue(value)
|
|
295
|
-
return
|
|
296
|
-
}
|
|
297
|
-
if (typeof value !== 'string' && !Array.isArray(value)) {
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if ((this.range || this.multiple) && !Array.isArray(value) && value.includes(',')) {
|
|
302
|
-
value = value.split(',')
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (!this.multiple && !this.range && Array.isArray(value)) {
|
|
306
|
-
value = value[0]
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
this.setFormValue(value)
|
|
310
|
-
|
|
311
|
-
this.manageValidity(this.inputRef.value)
|
|
312
|
-
if (this.inputRef2) {
|
|
313
|
-
this.manageValidity(this.inputRef2.value)
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Change events
|
|
317
|
-
this.dispatchEvent(new Event('change'))
|
|
318
|
-
this.dispatchEvent(
|
|
319
|
-
new CustomEvent('value-change', {
|
|
320
|
-
detail: value,
|
|
321
|
-
bubbles: true,
|
|
322
|
-
composed: true,
|
|
323
|
-
}),
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
this.internals.reportValidity()
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
protected updated(_changedProperties: PropertyValues): void {
|
|
330
|
-
if (_changedProperties.has('dataTestid') && this.dataTestid && this.inputRef.value) {
|
|
331
|
-
if (!this.skipForwardTestid) {
|
|
332
|
-
this.inputRef.value.dataset.testid = this.dataTestid
|
|
333
|
-
this.removeAttribute('data-testid')
|
|
334
|
-
} else if (!this.hasAttribute('data-testid')) {
|
|
335
|
-
this.setAttribute('data-testid', this.dataTestid)
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
protected firstUpdated(_changedProperties: PropertyValues): void {
|
|
341
|
-
super.firstUpdated(_changedProperties)
|
|
342
|
-
|
|
343
|
-
if (this.required) {
|
|
344
|
-
this.internals.ariaRequired = true
|
|
345
|
-
}
|
|
346
|
-
if (this.disabled) {
|
|
347
|
-
this.internals.ariaDisabled = true
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
this.internals.setFormValue(this.value)
|
|
351
|
-
this.inputRef.value && this.manageValidity(this.inputRef.value)
|
|
352
|
-
}
|
|
353
|
-
}
|