@oslokommune/punkt-elements 12.36.2 → 12.37.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 +35 -0
- package/dist/{button-B6uRE7uT.js → button-BYZHwPtW.js} +1 -1
- package/dist/{button-BNdVIhUp.cjs → button-iCBnadXj.cjs} +1 -1
- package/dist/{checkbox-CyYfA2fu.js → checkbox-Cz3sIWt0.js} +1 -1
- package/dist/{checkbox-CqatE-eX.cjs → checkbox-U8aPrLjG.cjs} +1 -1
- package/dist/{combobox-D9NKnao2.cjs → combobox-AbD1tkKx.cjs} +1 -1
- package/dist/{combobox-CELUAZxF.js → combobox-Bsaj6Z6Y.js} +1 -1
- package/dist/consent-B888aPfK.js +161 -0
- package/dist/consent-CFgCfRsF.cjs +11 -0
- package/dist/consent.d.ts +1 -0
- package/dist/{datepicker-cR9MtXOh.cjs → datepicker-BAn16Z8U.cjs} +16 -16
- package/dist/{datepicker-CpkTwszH.js → datepicker-cNYYOtBI.js} +116 -103
- package/dist/index.d.ts +24 -1
- package/dist/input-element-XmmyUZmB.cjs +1 -0
- package/dist/{input-element-Bic-t96S.js → input-element-aQDMXDVQ.js} +31 -26
- package/dist/{modal-B-varrJT.js → modal-DIwagdAc.js} +1 -1
- package/dist/modal-OC0efchb.cjs +33 -0
- package/dist/pkt-button.cjs +1 -1
- package/dist/pkt-button.js +1 -1
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-consent.cjs +1 -0
- package/dist/pkt-consent.js +6 -0
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-index.cjs +3 -3
- package/dist/pkt-index.js +42 -40
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/pkt-radiobutton.cjs +1 -1
- package/dist/pkt-radiobutton.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- 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/{radiobutton-CIW0FvT8.cjs → radiobutton-DtL-nc1b.cjs} +1 -1
- package/dist/{radiobutton-DtHuz7qn.js → radiobutton-DtpGqoci.js} +1 -1
- package/dist/{select-DbRLz-7l.js → select-BO7s0ym6.js} +1 -1
- package/dist/{select-BJziJVde.cjs → select-CsrHon8V.cjs} +1 -1
- package/dist/{textarea-CiA4IzMs.js → textarea-BdjszjRh.js} +1 -1
- package/dist/{textarea-qX4Inr1X.cjs → textarea-vr4tUfJ3.cjs} +1 -1
- package/dist/{textinput-CrxjZNEq.js → textinput-D-hYhwtS.js} +31 -24
- package/dist/{textinput-BlsgLNwW.cjs → textinput-DTKG8h7M.cjs} +4 -3
- package/package.json +5 -4
- package/src/components/button/button.ts +1 -0
- package/src/components/consent/consent.ts +146 -0
- package/src/components/consent/index.ts +6 -0
- package/src/components/consent/strings.ts +125 -0
- package/src/components/datepicker/datepicker.ts +36 -4
- package/src/components/index.ts +3 -0
- package/src/components/modal/modal.ts +1 -1
- package/src/components/textinput/textinput.ts +10 -0
- package/dist/input-element-C9ma8cdz.cjs +0 -1
- package/dist/modal-cPcTJriW.cjs +0 -33
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
2
|
+
import { html, PropertyValues } from 'lit'
|
|
3
|
+
import { PktElement } from '@/base-elements/element'
|
|
4
|
+
import { consentStrings } from './strings'
|
|
5
|
+
import { CookieEvents } from '@oslokommune/cookie-manager'
|
|
6
|
+
import '../button'
|
|
7
|
+
import '../icon'
|
|
8
|
+
|
|
9
|
+
// Extend the Window interface to include googleAnalyticsId
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
googleAnalyticsId?: string | null
|
|
13
|
+
hotjarId?: string | null
|
|
14
|
+
cookieBanner?: any
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IPktConsent {
|
|
19
|
+
hotjarId?: string | null
|
|
20
|
+
googleAnalyticsId?: string | null
|
|
21
|
+
triggerType?: 'button' | 'link' | 'footerlink' | 'icon' | null
|
|
22
|
+
triggerText?: string | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@customElement('pkt-consent')
|
|
26
|
+
export class PktConsent extends PktElement<IPktConsent> implements IPktConsent {
|
|
27
|
+
@property({ type: String }) hotjarId: string | null = null
|
|
28
|
+
@property({ type: String }) googleAnalyticsId: string | null = null
|
|
29
|
+
@property({ type: String }) triggerType: 'button' | 'link' | 'footerlink' | 'icon' | null =
|
|
30
|
+
'button'
|
|
31
|
+
@property({ type: String }) triggerText: string | null = null
|
|
32
|
+
@property({ type: String }) i18nLanguage: string = 'nb'
|
|
33
|
+
|
|
34
|
+
constructor() {
|
|
35
|
+
super()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
super.connectedCallback()
|
|
40
|
+
this.triggerText =
|
|
41
|
+
this.triggerText ||
|
|
42
|
+
consentStrings.i18n[this.i18nLanguage as keyof typeof consentStrings.i18n].contentPresentation
|
|
43
|
+
.buttons.settings
|
|
44
|
+
|
|
45
|
+
if (this.googleAnalyticsId) {
|
|
46
|
+
window.googleAnalyticsId = this.googleAnalyticsId
|
|
47
|
+
}
|
|
48
|
+
if (this.hotjarId) {
|
|
49
|
+
window.hotjarId = this.hotjarId
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
CookieEvents.on('CookieManager.setCookie', (consent: any) => {
|
|
53
|
+
this.emitCookieConsents(consent)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
emitCookieConsents(consent: any) {
|
|
58
|
+
const consents = JSON.parse(consent.value)
|
|
59
|
+
|
|
60
|
+
const consentDetails = consents.items.reduce((acc: any, item: any) => {
|
|
61
|
+
acc[item.name] = item.consent
|
|
62
|
+
return acc
|
|
63
|
+
}, {})
|
|
64
|
+
this.dispatchEvent(
|
|
65
|
+
new CustomEvent('toggle-consent', {
|
|
66
|
+
detail: consentDetails,
|
|
67
|
+
bubbles: true,
|
|
68
|
+
composed: true,
|
|
69
|
+
}),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected firstUpdated(_changedProperties: PropertyValues): void {
|
|
74
|
+
if (
|
|
75
|
+
!document.querySelector('#oslo-consent-script') &&
|
|
76
|
+
window.location.hostname !== 'localhost'
|
|
77
|
+
) {
|
|
78
|
+
window.googleAnalyticsId = this.googleAnalyticsId
|
|
79
|
+
window.hotjarId = this.hotjarId
|
|
80
|
+
|
|
81
|
+
const script = document.createElement('script')
|
|
82
|
+
script.src = 'https://cdn.web.oslo.kommune.no/cb/cb-v1.0.0.js'
|
|
83
|
+
script.id = 'oslo-consent-script'
|
|
84
|
+
script.onload = () => {
|
|
85
|
+
this.triggerInit()
|
|
86
|
+
}
|
|
87
|
+
document.head.appendChild(script)
|
|
88
|
+
|
|
89
|
+
const styles = document.createElement('link')
|
|
90
|
+
styles.href = 'https://cdn.web.oslo.kommune.no/cb/cb-v1.0.0.css'
|
|
91
|
+
styles.type = 'text/css'
|
|
92
|
+
styles.rel = 'stylesheet'
|
|
93
|
+
styles.id = 'oslo-consent-styles'
|
|
94
|
+
document.head.appendChild(styles)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
triggerInit() {
|
|
99
|
+
// Slight hack since we can't access the right methods to do this “properly”
|
|
100
|
+
window.document.dispatchEvent(
|
|
101
|
+
new Event('DOMContentLoaded', {
|
|
102
|
+
bubbles: true,
|
|
103
|
+
cancelable: true,
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
window.cookieBanner.cookieConsent.validateConsentCookie().then((response: boolean) => {
|
|
108
|
+
if (response) {
|
|
109
|
+
const cookie = window.cookieBanner.cookieConsent.getConsentCookie()
|
|
110
|
+
const consents = { value: cookie.items }
|
|
111
|
+
this.emitCookieConsents(consents)
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
openModal(e: Event) {
|
|
117
|
+
e.preventDefault()
|
|
118
|
+
if (!window.cookieBanner.cookieConsent) {
|
|
119
|
+
this.triggerInit()
|
|
120
|
+
}
|
|
121
|
+
setTimeout(() => window.cookieBanner.openCookieModal())
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
render() {
|
|
125
|
+
if (this.triggerType === 'link') {
|
|
126
|
+
return html`<a href="#" class="pkt-link" @click=${this.openModal}>${this.triggerText}</a>`
|
|
127
|
+
}
|
|
128
|
+
if (this.triggerType === 'footerlink') {
|
|
129
|
+
return html`<a href="#" class="pkt-footer__link" @click=${this.openModal}>
|
|
130
|
+
<pkt-icon name="chevron-right" class="pkt-footer__link-icon"></pkt-icon>
|
|
131
|
+
${this.triggerText}
|
|
132
|
+
</a>`
|
|
133
|
+
}
|
|
134
|
+
if (this.triggerType === 'icon') {
|
|
135
|
+
return html`<pkt-button
|
|
136
|
+
skin="tertiary"
|
|
137
|
+
variant="icon-only"
|
|
138
|
+
iconName="cookie"
|
|
139
|
+
@click=${this.openModal}
|
|
140
|
+
>
|
|
141
|
+
>${this.triggerText}</pkt-button
|
|
142
|
+
>`
|
|
143
|
+
}
|
|
144
|
+
return html`<pkt-button @click=${this.openModal}>${this.triggerText}</pkt-button>`
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export const consentStrings = {
|
|
2
|
+
i18n: {
|
|
3
|
+
nb: {
|
|
4
|
+
contentPresentation: {
|
|
5
|
+
title: 'Oslo kommune bruker informasjonskapsler',
|
|
6
|
+
description: [
|
|
7
|
+
'For at nettstedet skal fungere og være trygt, bruker Oslo kommune informasjonskapsler. Noen er teknisk nødvendige, mens andre sikrer ulik funksjonalitet.',
|
|
8
|
+
'Godtar du alle informasjonskapsler, tillater du også at vi samler inn data om statistikk og brukeradferd. Da hjelper du oss med å lage et bedre nettsted uten at du trenger å dele noe personlig informasjon med oss.',
|
|
9
|
+
],
|
|
10
|
+
buttons: {
|
|
11
|
+
accept: 'Godta alle',
|
|
12
|
+
reject: 'Kun nødvendige',
|
|
13
|
+
settings: 'Innstillinger for informasjonskapsler',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
contentSettings: {
|
|
17
|
+
title: 'Innstillinger for informasjonskapsler',
|
|
18
|
+
description: [
|
|
19
|
+
'Her kan du velge hvilke typer informasjonskapsler du vil tillate. Tillatelsen gjelder i 90 dager. Husk at nødvendige informasjonskapsler ikke kan velges bort.',
|
|
20
|
+
'Du kan når som helst endre innstillingene og finne mer informasjon nederst på nettstedet under «Innstillinger for informasjonskapsler» og «Personvern og informasjonskapsler».',
|
|
21
|
+
],
|
|
22
|
+
buttons: {
|
|
23
|
+
back: 'Tilbake',
|
|
24
|
+
save: 'Lagre innstillinger',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
en: {
|
|
29
|
+
contentPresentation: {
|
|
30
|
+
title: 'Before you visit Oslo kommune ...',
|
|
31
|
+
description: [
|
|
32
|
+
'This website uses cookies to make improvements. In this context, we need your consent to measure the traffic on the website in relation to statistics and feedback.',
|
|
33
|
+
'To read more about what we use cookies for, go to our privacy declaration which you will find at the bottom of our websites.',
|
|
34
|
+
],
|
|
35
|
+
buttons: {
|
|
36
|
+
accept: 'Yes, I accept',
|
|
37
|
+
reject: 'Only necessary',
|
|
38
|
+
settings: 'Go to settings',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
contentSettings: {
|
|
42
|
+
title: 'Her kan du aktivt velge mellom ulike informasjonskapsler',
|
|
43
|
+
description: [
|
|
44
|
+
'For å lese mer om hva vi bruker informasjonskapsler til gå til vår personvernserklering som du finner på våre nettsider',
|
|
45
|
+
],
|
|
46
|
+
buttons: {
|
|
47
|
+
back: 'Back',
|
|
48
|
+
save: 'Save settings',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
cookies: [
|
|
54
|
+
{
|
|
55
|
+
name: 'statistics',
|
|
56
|
+
defaultValue: null,
|
|
57
|
+
i18n: {
|
|
58
|
+
nb: {
|
|
59
|
+
title: 'Statistikk og analyse',
|
|
60
|
+
description:
|
|
61
|
+
'Jeg godtar at Oslo kommune bruker informasjonskapsler til å innhente data om statistikk og brukeradferd.',
|
|
62
|
+
buttons: {
|
|
63
|
+
yes: 'Ja',
|
|
64
|
+
no: 'Nei',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
en: {
|
|
68
|
+
title: 'Statistics and analytics',
|
|
69
|
+
description: 'Select your preference for statistics and analytics',
|
|
70
|
+
buttons: {
|
|
71
|
+
yes: 'Yes',
|
|
72
|
+
no: 'No',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'survey',
|
|
79
|
+
defaultValue: null,
|
|
80
|
+
i18n: {
|
|
81
|
+
nb: {
|
|
82
|
+
title: 'Skriftlige tilbakemeldinger',
|
|
83
|
+
description:
|
|
84
|
+
'Jeg godtar at Oslo kommune bruker informasjonskapsler til å vise responsfelt og registrere tilbakemeldinger.',
|
|
85
|
+
buttons: {
|
|
86
|
+
yes: 'Ja',
|
|
87
|
+
no: 'Nei',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
en: {
|
|
91
|
+
title: 'Survey',
|
|
92
|
+
description: 'Select your preference for survey',
|
|
93
|
+
buttons: {
|
|
94
|
+
yes: 'Yes',
|
|
95
|
+
no: 'No',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'functional',
|
|
102
|
+
defaultValue: true,
|
|
103
|
+
i18n: {
|
|
104
|
+
nb: {
|
|
105
|
+
title: 'Funksjonelle informasjonskapsler',
|
|
106
|
+
description:
|
|
107
|
+
'Jeg godtar at Oslo kommune bruker informasjonskapsler for å gjøre ulike funksjoner på nettstedet mulige (for eksempel skjemaer og barnehagevelger).',
|
|
108
|
+
buttons: {
|
|
109
|
+
yes: 'Ja',
|
|
110
|
+
no: 'Nei',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
en: {
|
|
114
|
+
title: 'Functional cookies',
|
|
115
|
+
description:
|
|
116
|
+
'For the website to function optimally, we recommend that you accept these cookies',
|
|
117
|
+
buttons: {
|
|
118
|
+
yes: 'Yes',
|
|
119
|
+
no: 'No',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}
|
|
@@ -205,13 +205,21 @@ export class PktDatepicker extends PktInputElement {
|
|
|
205
205
|
}}
|
|
206
206
|
?disabled=${this.disabled}
|
|
207
207
|
@keydown=${(e: KeyboardEvent) => {
|
|
208
|
-
if (e.key === ','
|
|
208
|
+
if (e.key === ',') {
|
|
209
209
|
this.inputRef.value?.blur()
|
|
210
210
|
}
|
|
211
211
|
if (e.key === 'Space' || e.key === ' ') {
|
|
212
212
|
e.preventDefault()
|
|
213
213
|
this.toggleCalendar(e)
|
|
214
214
|
}
|
|
215
|
+
if (e.key === 'Enter') {
|
|
216
|
+
const form = this.internals.form as HTMLFormElement
|
|
217
|
+
if (form) {
|
|
218
|
+
form.requestSubmit()
|
|
219
|
+
} else {
|
|
220
|
+
this.inputRef.value?.blur()
|
|
221
|
+
}
|
|
222
|
+
}
|
|
215
223
|
}}
|
|
216
224
|
@input=${(e: Event) => {
|
|
217
225
|
this.onInput()
|
|
@@ -260,13 +268,21 @@ export class PktDatepicker extends PktInputElement {
|
|
|
260
268
|
this.showCalendar()
|
|
261
269
|
}}
|
|
262
270
|
@keydown=${(e: KeyboardEvent) => {
|
|
263
|
-
if (e.key === ','
|
|
271
|
+
if (e.key === ',') {
|
|
264
272
|
this.inputRef.value?.blur()
|
|
265
273
|
}
|
|
266
274
|
if (e.key === 'Space' || e.key === ' ') {
|
|
267
275
|
e.preventDefault()
|
|
268
276
|
this.toggleCalendar(e)
|
|
269
277
|
}
|
|
278
|
+
if (e.key === 'Enter') {
|
|
279
|
+
const form = this.internals.form as HTMLFormElement
|
|
280
|
+
if (form) {
|
|
281
|
+
form.requestSubmit()
|
|
282
|
+
} else {
|
|
283
|
+
this.inputRefTo.value?.focus()
|
|
284
|
+
}
|
|
285
|
+
}
|
|
270
286
|
}}
|
|
271
287
|
@input=${(e: Event) => {
|
|
272
288
|
this.onInput()
|
|
@@ -315,13 +331,21 @@ export class PktDatepicker extends PktInputElement {
|
|
|
315
331
|
this.showCalendar()
|
|
316
332
|
}}
|
|
317
333
|
@keydown=${(e: KeyboardEvent) => {
|
|
318
|
-
if (e.key === ','
|
|
334
|
+
if (e.key === ',') {
|
|
319
335
|
this.inputRefTo.value?.blur()
|
|
320
336
|
}
|
|
321
337
|
if (e.key === 'Space' || e.key === ' ') {
|
|
322
338
|
e.preventDefault()
|
|
323
339
|
this.toggleCalendar(e)
|
|
324
340
|
}
|
|
341
|
+
if (e.key === 'Enter') {
|
|
342
|
+
const form = this.internals.form as HTMLFormElement
|
|
343
|
+
if (form) {
|
|
344
|
+
form.requestSubmit()
|
|
345
|
+
} else {
|
|
346
|
+
this.inputRefTo.value?.blur()
|
|
347
|
+
}
|
|
348
|
+
}
|
|
325
349
|
}}
|
|
326
350
|
@input=${(e: Event) => {
|
|
327
351
|
this.onInput()
|
|
@@ -399,7 +423,7 @@ export class PktDatepicker extends PktInputElement {
|
|
|
399
423
|
}
|
|
400
424
|
}}
|
|
401
425
|
@keydown=${(e: KeyboardEvent) => {
|
|
402
|
-
if (e.key === ','
|
|
426
|
+
if (e.key === ',') {
|
|
403
427
|
e.preventDefault()
|
|
404
428
|
this.addToSelected(e)
|
|
405
429
|
}
|
|
@@ -407,6 +431,14 @@ export class PktDatepicker extends PktInputElement {
|
|
|
407
431
|
e.preventDefault()
|
|
408
432
|
this.toggleCalendar(e)
|
|
409
433
|
}
|
|
434
|
+
if (e.key === 'Enter') {
|
|
435
|
+
const form = this.internals.form as HTMLFormElement
|
|
436
|
+
if (form) {
|
|
437
|
+
form.requestSubmit()
|
|
438
|
+
} else {
|
|
439
|
+
this.inputRef.value?.blur()
|
|
440
|
+
}
|
|
441
|
+
}
|
|
410
442
|
}}
|
|
411
443
|
@change=${(e: Event) => {
|
|
412
444
|
e.stopImmediatePropagation()
|
package/src/components/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { PktButton } from '@/components/button'
|
|
|
6
6
|
export { PktCalendar } from '@/components/calendar'
|
|
7
7
|
export { PktCard } from '@/components/card'
|
|
8
8
|
export { PktCombobox } from './combobox'
|
|
9
|
+
export { PktConsent } from './consent'
|
|
9
10
|
export { PktCheckbox } from '@/components/checkbox'
|
|
10
11
|
export { PktComponent } from '../base-elements/component-template.js'
|
|
11
12
|
export { PktDatepicker } from '@/components/datepicker/datepicker.js'
|
|
@@ -65,3 +66,5 @@ export type { TSelectOption } from '@/components/select'
|
|
|
65
66
|
export type { IPktBackLink } from '@/components/backlink'
|
|
66
67
|
|
|
67
68
|
export type { IPktLoader, TPktLoaderVariant } from '@/components/loader'
|
|
69
|
+
|
|
70
|
+
export type { IPktConsent } from '@/components/consent'
|
|
@@ -97,7 +97,7 @@ export class PktModal extends PktElement implements IPktModal {
|
|
|
97
97
|
this.requestUpdate()
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
public showModal = (event: Event) => {
|
|
100
|
+
public showModal = (event: Event | null = null) => {
|
|
101
101
|
this._isOpen = true
|
|
102
102
|
this.dialogRef.value?.showModal()
|
|
103
103
|
const modal = document.querySelector('.pkt-modal')
|
|
@@ -152,6 +152,16 @@ export class PktTextinput extends PktInputElement<Props> {
|
|
|
152
152
|
this.onBlur()
|
|
153
153
|
e.stopImmediatePropagation()
|
|
154
154
|
}}
|
|
155
|
+
@keydown=${(e: KeyboardEvent) => {
|
|
156
|
+
if (e.key === 'Enter') {
|
|
157
|
+
const form = this.internals.form as HTMLFormElement
|
|
158
|
+
if (form) {
|
|
159
|
+
form.requestSubmit()
|
|
160
|
+
} else {
|
|
161
|
+
this.inputRef.value?.blur()
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}}
|
|
155
165
|
/>
|
|
156
166
|
${this.suffix
|
|
157
167
|
? html`<div class="pkt-input-suffix">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("./element-BSypUpzA.cjs"),f=require("./state-B5KCNjEd.cjs"),c=require("./stringutils-CkVRq4jP.cjs"),y=require("./input-wrapper-EoSAbU-U.cjs");var m=Object.defineProperty,s=(o,t,r,n)=>{for(var a=void 0,l=o.length-1,h;l>=0;l--)(h=o[l])&&(a=h(t,r,a)||a);return a&&m(t,r,a),a};class i extends e.PktElement{constructor(){super(),this.defaultValue=null,this.disabled=!1,this.readonly=!1,this.required=!1,this.max=null,this.maxlength=null,this.min=null,this.minlength=null,this.ariaDescribedBy=null,this.ariaLabelledby=null,this.name="",this.pattern=null,this.placeholder=null,this.id=c.uuidish(),this.counter=!1,this.hasError=!1,this.inline=!1,this.hasFieldset=!1,this.optionalTag=!1,this.requiredTag=!1,this.skipForwardTestid=!1,this.useWrapper=!0,this.fullwidth=!1,this.counterMaxLength=0,this.errorMessage="",this.helptext="",this.helptextDropdown="",this.helptextDropdownButton=y.specs.props.helptextDropdownButton.default,this.label=null,this.optionalText=e.translations.forms.labels.optional,this.requiredText=e.translations.forms.labels.required,this.dataTestid="",this.touched=!1,this.internals=this.attachInternals()}static get formAssociated(){return!0}manageValidity(t){var r,n,a,l,h,u,p,d;t&&(this.required&&!this.value?this.internals.setValidity({valueMissing:!0},e.translations.forms.messages.required,t):(r=t.validity)!=null&&r.typeMismatch||(n=t.validity)!=null&&n.badInput?this.internals.setValidity({typeMismatch:!0},e.translations.forms.messages.invalid,t):(a=t.validity)!=null&&a.patternMismatch?this.internals.setValidity({patternMismatch:!0},e.translations.forms.messages.invalidPattern,t):(l=t.validity)!=null&&l.tooShort||this.minlength&&this.minlength>0&&this.value.length<this.minlength?this.internals.setValidity({tooShort:!0},e.translations.forms.messages.tooShort,t):(h=t.validity)!=null&&h.tooLong||this.maxlength&&this.maxlength>0&&this.value.length>this.maxlength?this.internals.setValidity({tooLong:!0},e.translations.forms.messages.tooLong,t):(u=t.validity)!=null&&u.rangeUnderflow?this.internals.setValidity({rangeUnderflow:!0},e.translations.forms.messages.rangeUnderflow,t):(p=t.validity)!=null&&p.rangeOverflow?this.internals.setValidity({rangeOverflow:!0},e.translations.forms.messages.rangeOverflow,t):(d=t.validity)!=null&&d.customError?this.internals.setValidity({customError:!0},t.validationMessage,t):this.internals.setValidity({}))}setFormValue(t){if(this.internals)if(Array.isArray(t)){const r=new FormData;t.forEach(n=>{r.append(this.name,n)}),this.internals.setFormValue(r)}else this.internals.setFormValue(t)}valueChecked(t){if(!this.touched)return;const r=this.internals.form||this.closest("form");r&&r.querySelectorAll(`pkt-radiobutton[name=${this.name}], input[type=radio][name=${this.name}]`).forEach(n=>{const a=n;a.name===this.name&&a.value!==this.value&&a.checked&&(a.checked=!1)}),typeof t=="string"?(this.checked=t==="true",this.internals.ariaChecked=t==="true"):typeof t=="boolean"&&(this.checked=t,this.internals.ariaChecked=t),this.checked?(this.internals.setFormValue(this.value||"on",this.value||"on"),this.internals.states.add("--checked")):(this.internals.setFormValue("",""),this.internals.states.delete("--checked")),this.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("value-change",{detail:this.checked,bubbles:!0,composed:!0})),this.internals.reportValidity()}valueChanged(t,r){(r!==this.value||r!==this._value)&&(typeof t=="string"?((this.multiple||this.range)&&t.includes(",")&&(t=t.split(",")),this.value=t,this._value=Array.isArray(t)?t:[t]):Array.isArray(t)?(this.value=this.multiple||this.range?t:t[0],this._value=t):(this.value="",this._value=[]),(!this.value||this.value.length===0)&&r&&r.length!==0?this.clearInputValue():this.value&&this.value.toString()!==(r==null?void 0:r.toString())&&this.onChange(this.value),this.updateComplete.then(()=>this.requestUpdate()))}clearInputValue(){const t=this.multiple||this.range?[]:"";this.value=t,this.internals.setFormValue(t),this.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("value-change",{detail:t,bubbles:!0,composed:!0}))}onFocus(){this.dispatchEvent(new FocusEvent("focus"))}onBlur(){this.dispatchEvent(new FocusEvent("blur"))}onInput(){this.dispatchEvent(new InputEvent("input"))}onChange(t){if(!this.touched){this.touched=!0,t&&this.setFormValue(t);return}typeof t!="string"&&!Array.isArray(t)||((this.range||this.multiple)&&!Array.isArray(t)&&t.includes(",")&&(t=t.split(",")),!this.multiple&&!this.range&&Array.isArray(t)&&(t=t[0]),this.setFormValue(t),this.manageValidity(this.inputRef.value),this.inputRefTo&&this.manageValidity(this.inputRefTo.value),this.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("value-change",{detail:t,bubbles:!0,composed:!0})),this.internals.reportValidity())}updated(t){super.updated(t),t.has("dataTestid")&&this.dataTestid&&this.inputRef.value&&(this.skipForwardTestid?this.hasAttribute("data-testid")||this.setAttribute("data-testid",this.dataTestid):(this.inputRef.value.dataset.testid=this.dataTestid,this.removeAttribute("data-testid")))}firstUpdated(t){if(super.firstUpdated(t),this.value&&this.defaultValue!==null&&(this.defaultValue=this.value),this.defaultValue!==null&&!this.value&&this.valueChanged(this.defaultValue,null),this.defaultChecked&&(this.internals.ariaChecked=!0,this.checked=!0),this.required&&(this.internals.ariaRequired=!0),this.disabled&&(this.internals.ariaDisabled=!0),this.id&&!this.name&&(this.name=this.id),this.checked!==void 0){const r=this.checked===""||this.checked==="true"||this.checked===!0;this.internals.ariaChecked=r,this.internals.setFormValue(r?this.value||"on":"",r?this.value||"on":"")}else this.internals.setFormValue(this.value);this.inputRef&&this.inputRef.value&&(this.inputRef.value.setAttribute("form",""),this.manageValidity(this.inputRef.value)),this.inputRefTo&&this.inputRefTo.value&&(this.inputRefTo.value.setAttribute("form",""),this.manageValidity(this.inputRefTo.value))}}s([e.n()],i.prototype,"defaultValue");s([e.n({type:Boolean,reflect:!0})],i.prototype,"disabled");s([e.n({type:Boolean,reflect:!0})],i.prototype,"readonly");s([e.n({type:Boolean,reflect:!0})],i.prototype,"required");s([e.n({type:Number,reflect:!0})],i.prototype,"max");s([e.n({type:Number,reflect:!0})],i.prototype,"maxlength");s([e.n({type:Number,reflect:!0})],i.prototype,"min");s([e.n({type:Number,reflect:!0})],i.prototype,"minlength");s([e.n({type:String})],i.prototype,"ariaDescribedBy");s([e.n({type:String})],i.prototype,"ariaLabelledby");s([e.n({type:String,reflect:!0})],i.prototype,"name");s([e.n({type:String,reflect:!0})],i.prototype,"pattern");s([e.n({type:String,reflect:!0})],i.prototype,"placeholder");s([e.n({type:String,reflect:!0})],i.prototype,"id");s([e.n({type:Boolean})],i.prototype,"counter");s([e.n({type:Boolean})],i.prototype,"hasError");s([e.n({type:Boolean})],i.prototype,"inline");s([e.n({type:Boolean})],i.prototype,"hasFieldset");s([e.n({type:Boolean})],i.prototype,"optionalTag");s([e.n({type:Boolean})],i.prototype,"requiredTag");s([e.n({type:Boolean})],i.prototype,"skipForwardTestid");s([e.n({type:Boolean,reflect:!1})],i.prototype,"useWrapper");s([e.n({type:Boolean,reflect:!0})],i.prototype,"fullwidth");s([e.n({type:Number})],i.prototype,"counterMaxLength");s([e.n({type:String})],i.prototype,"errorMessage");s([e.n({type:String})],i.prototype,"helptext");s([e.n({type:String})],i.prototype,"helptextDropdown");s([e.n({type:String,reflect:!1})],i.prototype,"helptextDropdownButton");s([e.n({type:String})],i.prototype,"label");s([e.n({type:String,reflect:!1})],i.prototype,"optionalText");s([e.n({type:String,reflect:!1})],i.prototype,"requiredText");s([e.n({type:String,attribute:"data-testid"})],i.prototype,"dataTestid");s([f.r()],i.prototype,"touched");exports.PktInputElement=i;
|
package/dist/modal-cPcTJriW.cjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";const d=require("./class-map-DCyaICmy.cjs"),i=require("./element-BSypUpzA.cjs"),h=require("./state-B5KCNjEd.cjs"),k=require("./pkt-slot-controller-plQxXRvV.cjs"),r=require("./ref-BvbyvXRH.cjs");require("./icon-BnKGwYjj.cjs");const m={hideCloseButton:{default:!1},closeOnBackdropClick:{default:!1},size:{default:"medium"}},p={props:m};var f=Object.defineProperty,v=Object.getOwnPropertyDescriptor,l=(c,e,t,s)=>{for(var o=s>1?void 0:s?v(e,t):e,n=c.length-1,a;n>=0;n--)(a=c[n])&&(o=(s?a(e,t,o):a(o))||o);return s&&o&&f(e,t,o),o};exports.PktModal=class extends i.PktElement{constructor(){super(),this.headingText="",this.removePadding=!1,this.hideCloseButton=p.props.hideCloseButton.default,this.closeOnBackdropClick=p.props.closeOnBackdropClick.default,this.closeButtonSkin="blue",this.size=p.props.size.default,this.defaultSlot=r.e(),this.dialogRef=r.e(),this._isOpen=!1,this.close=(e,t=!1)=>{var o;if(!this._isOpen)return;this._isOpen=!1,document.body.classList.remove("pkt-modal--open");const s=document.activeElement;s&&!this.isElementInViewport(s)&&s.scrollIntoView({behavior:"smooth",block:"nearest"}),this.dispatchEvent(new CustomEvent("close",{detail:{origin:e},bubbles:!0,composed:!0})),t||(o=this.dialogRef.value)==null||o.close(),this.requestUpdate()},this.showModal=e=>{var s;this._isOpen=!0,(s=this.dialogRef.value)==null||s.showModal();const t=document.querySelector(".pkt-modal");requestAnimationFrame(()=>{var o;this.dialogRef.value&&((o=this.dialogRef.value)==null||o.focus())}),t&&document.body.classList.add("pkt-modal--open"),this.dispatchEvent(new CustomEvent("showModal",{detail:{origin:e},bubbles:!0,composed:!0})),this.requestUpdate()},this.slotController=new k.PktSlotController(this,this.defaultSlot),this._isOpen=!1}async connectedCallback(){super.connectedCallback(),document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("click",this.handleBackdropClick)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("click",this.handleBackdropClick)}handleKeyDown(e){e.key==="Escape"&&this.close(e)}handleBackdropClick(e){var t;this.closeOnBackdropClick&&e.target===((t=this.dialogRef)==null?void 0:t.value)&&this.close(e)}isElementInViewport(e){const t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}render(){const e={"pkt-modal":!0,"pkt-modal--removePadding":this.removePadding??!1,"pkt-modal--noHeadingText":this.headingText===""||this.headingText===void 0,[`pkt-modal--${this.size}`]:this.size!==void 0},t={"pkt-modal__headingText":!0,"pkt-txt-24":!0},s={"pkt-modal__content":!0,"pkt-txt-18-light":!0},o=this.closeButtonSkin==="blue",n={"pkt-modal__closeButton":!0,[`pkt-modal__closeButton--${this.closeButtonSkin}`]:!0},a={"pkt-btn":!0,[`pkt-btn--${o?"tertiary":"primary"}`]:!0,"pkt-btn--icon-only":!0,"pkt-btn--medium":!0};return i.x`
|
|
2
|
-
<dialog
|
|
3
|
-
class=${d.e(e)}
|
|
4
|
-
${r.n(this.dialogRef)}
|
|
5
|
-
aria-labelledby="pkt-modal__headingText"
|
|
6
|
-
aria-describedby="pkt-modal__content"
|
|
7
|
-
@close=${u=>this.close(u,!0)}
|
|
8
|
-
>
|
|
9
|
-
<div class="pkt-modal__header">
|
|
10
|
-
<div class="pkt-modal__header-background"></div>
|
|
11
|
-
${this.headingText?i.x`<h1 id="pkt-modal__headingText" class=${d.e(t)}>
|
|
12
|
-
${this.headingText}
|
|
13
|
-
</h1>`:i.E}
|
|
14
|
-
${this.hideCloseButton?i.E:i.x`<div class="${d.e(n)}">
|
|
15
|
-
<pkt-button
|
|
16
|
-
@click=${u=>this.close(u)}
|
|
17
|
-
class=${d.e(a)}
|
|
18
|
-
aria-label="close"
|
|
19
|
-
iconname="close"
|
|
20
|
-
variant="icon-only"
|
|
21
|
-
>
|
|
22
|
-
</pkt-button>
|
|
23
|
-
</div>`}
|
|
24
|
-
</div>
|
|
25
|
-
<div class="pkt-modal__container">
|
|
26
|
-
<div
|
|
27
|
-
id="pkt-modal__content"
|
|
28
|
-
class=${d.e(s)}
|
|
29
|
-
${r.n(this.defaultSlot)}
|
|
30
|
-
></div>
|
|
31
|
-
</div>
|
|
32
|
-
</dialog>
|
|
33
|
-
`}};l([i.n({type:String,reflect:!0})],exports.PktModal.prototype,"headingText",2);l([i.n({type:Boolean,reflect:!0})],exports.PktModal.prototype,"removePadding",2);l([i.n({type:Boolean,reflect:!0})],exports.PktModal.prototype,"hideCloseButton",2);l([i.n({type:Boolean,reflect:!0})],exports.PktModal.prototype,"closeOnBackdropClick",2);l([i.n({type:String,reflect:!0})],exports.PktModal.prototype,"closeButtonSkin",2);l([i.n({type:String,reflect:!0})],exports.PktModal.prototype,"size",2);l([h.r()],exports.PktModal.prototype,"_isOpen",2);exports.PktModal=l([i.t("pkt-modal")],exports.PktModal);
|