@oslokommune/punkt-elements 19.14.2 → 19.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/base-elements/input-element.d.ts +1 -0
  3. package/dist/{checkbox-CmosufvS.js → checkbox-BDwOYcNM.js} +1 -1
  4. package/dist/{checkbox-C1ax-sLh.cjs → checkbox-BwI9QNSh.cjs} +1 -1
  5. package/dist/{checkbox-group-BhivKFgO.js → checkbox-group-C8mo9dkO.js} +1 -1
  6. package/dist/{checkbox-group-BYNl7VNJ.cjs → checkbox-group-adbFTj8y.cjs} +1 -1
  7. package/dist/{combobox-BoA7AUZ2.js → combobox-B8IeuEF0.js} +1 -1
  8. package/dist/{combobox-oZoauZTz.cjs → combobox-jsPpImVF.cjs} +1 -1
  9. package/dist/components/modal/modal.d.ts +7 -0
  10. package/dist/components/modal/modal.test.d.ts +9 -0
  11. package/dist/{datepicker-BPxydYDE.cjs → datepicker-CZYpIyJd.cjs} +1 -1
  12. package/dist/{datepicker-BUevmbMe.js → datepicker-CjUY_mLR.js} +1 -1
  13. package/dist/docs/components/modal.d.ts +2 -0
  14. package/dist/{fileupload-BmfFC748.js → fileupload-BKk03Dq-.js} +1 -1
  15. package/dist/{fileupload-CyLRyoVU.cjs → fileupload-CnjtgTlF.cjs} +1 -1
  16. package/dist/{header-D5FK0J-j.js → header-20rqKJFb.js} +1 -1
  17. package/dist/{header-DfhjtbtK.cjs → header-BCrefip0.cjs} +1 -1
  18. package/dist/{input-element-BMEyYMGT.cjs → input-element-BjnKPikY.cjs} +1 -1
  19. package/dist/{input-element-CHSaC4Vl.js → input-element-mTphzs9b.js} +4 -1
  20. package/dist/{modal-B3CQEBBB.js → modal-0D0paY70.js} +42 -23
  21. package/dist/modal-wEEmCcUx.cjs +39 -0
  22. package/dist/pkt-checkbox-group.cjs +1 -1
  23. package/dist/pkt-checkbox-group.js +1 -1
  24. package/dist/pkt-checkbox.cjs +1 -1
  25. package/dist/pkt-checkbox.js +1 -1
  26. package/dist/pkt-combobox.cjs +1 -1
  27. package/dist/pkt-combobox.js +1 -1
  28. package/dist/pkt-datepicker.cjs +1 -1
  29. package/dist/pkt-datepicker.js +1 -1
  30. package/dist/pkt-fileupload.cjs +1 -1
  31. package/dist/pkt-fileupload.js +1 -1
  32. package/dist/pkt-header.cjs +1 -1
  33. package/dist/pkt-header.js +1 -1
  34. package/dist/pkt-index.cjs +1 -1
  35. package/dist/pkt-index.js +13 -13
  36. package/dist/pkt-modal.cjs +1 -1
  37. package/dist/pkt-modal.js +1 -1
  38. package/dist/pkt-radio-group.cjs +1 -1
  39. package/dist/pkt-radio-group.js +1 -1
  40. package/dist/pkt-radiobutton.cjs +1 -1
  41. package/dist/pkt-radiobutton.js +1 -1
  42. package/dist/pkt-select.cjs +1 -1
  43. package/dist/pkt-select.js +1 -1
  44. package/dist/pkt-textarea.cjs +1 -1
  45. package/dist/pkt-textarea.js +1 -1
  46. package/dist/pkt-textinput.cjs +1 -1
  47. package/dist/pkt-textinput.js +1 -1
  48. package/dist/pkt-timepicker.cjs +1 -1
  49. package/dist/pkt-timepicker.js +1 -1
  50. package/dist/{radio-group-DtsCD1Mf.js → radio-group-CtZhXMF8.js} +1 -1
  51. package/dist/{radio-group-Bzj5t0OJ.cjs → radio-group-MxNLGu-0.cjs} +1 -1
  52. package/dist/{radiobutton-DCncPKTW.js → radiobutton-BK-V6Itu.js} +1 -1
  53. package/dist/{radiobutton-Dcql5zNz.cjs → radiobutton-DwDErNo5.cjs} +1 -1
  54. package/dist/{select-BdljPpah.js → select-Bs-Z5Thd.js} +1 -1
  55. package/dist/{select-Dilcsvkk.cjs → select-Czz1y2nI.cjs} +1 -1
  56. package/dist/{textarea-DQU2ec3B.cjs → textarea-C-sdNBRk.cjs} +1 -1
  57. package/dist/{textarea-Jicug3YH.js → textarea-COHaMHpP.js} +1 -1
  58. package/dist/{textinput-Dqad6Kni.js → textinput-0DZeMqBr.js} +1 -1
  59. package/dist/{textinput-CkEqZRLx.cjs → textinput-BqBgsBZF.cjs} +1 -1
  60. package/dist/{timepicker-D-uPUK-n.cjs → timepicker-C_k-K1jA.cjs} +1 -1
  61. package/dist/{timepicker-wenCQ3LT.js → timepicker-CvdI7jDN.js} +1 -1
  62. package/package.json +2 -2
  63. package/src/components/combobox/combobox.selection.test.ts +45 -0
  64. package/src/components/datepicker/datepicker.selection.test.ts +12 -0
  65. package/src/components/modal/modal.test.ts +141 -0
  66. package/src/components/modal/modal.ts +24 -5
  67. package/dist/modal-BKeSXrzi.cjs +0 -35
@@ -5,7 +5,7 @@ import { n as c } from "./element-with-slot-CVmm0_IE.js";
5
5
  import "./icon-Bao96Zb8.js";
6
6
  import { t as l } from "./if-defined-O59_I-e-.js";
7
7
  import { n as u, t as d } from "./ref-y_5qv9vU.js";
8
- import { t as f } from "./input-element-CHSaC4Vl.js";
8
+ import { t as f } from "./input-element-mTphzs9b.js";
9
9
  import { r as p } from "./input-wrapper-Bb6CZxmg.js";
10
10
  //#region ../../shared-utils/timepicker/time-utils.ts
11
11
  var m = (e) => /^\d{2}:\d{2}$/.test(e) && parseInt(e.slice(0, 2), 10) <= 23 && parseInt(e.slice(3), 10) <= 59, h = (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-elements",
3
- "version": "19.14.2",
3
+ "version": "19.15.0",
4
4
  "description": "Komponentbiblioteket til Punkt, designsystem for Oslo kommune",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo kommune",
@@ -84,5 +84,5 @@
84
84
  "engines": {
85
85
  "node": "^22.19.0 || ^24.0.0 || ^26.0.0"
86
86
  },
87
- "gitHead": "6d0937b0b2b5c9257079680b17248ad702419c53"
87
+ "gitHead": "3d719ef8a2e368d08d6111be152f9a6c1b64da1e"
88
88
  }
@@ -302,6 +302,51 @@ describe('PktCombobox', () => {
302
302
  })
303
303
  })
304
304
 
305
+ describe('Maxlength validity', () => {
306
+ const mount = async (props: string) => {
307
+ const container = await createCombobox(`id="test" name="test" label="Test" ${props}`)
308
+ const combobox = container.querySelector('pkt-combobox') as PktCombobox
309
+ combobox.options = getDefaultOptions()
310
+ await combobox.updateComplete
311
+ return combobox
312
+ }
313
+
314
+ test('is valid when the number of selected options is within maxlength', async () => {
315
+ const combobox = await mount('multiple maxlength="2"')
316
+ ;(combobox as any).toggleValue('apple')
317
+ await combobox.updateComplete
318
+ ;(combobox as any).toggleValue('banana')
319
+ await combobox.updateComplete
320
+
321
+ expect(combobox['_value']).toEqual(['apple', 'banana'])
322
+ expect(combobox.internals.validity.tooLong).toBe(false)
323
+ expect(combobox.internals.validity.valid).toBe(true)
324
+ })
325
+
326
+ test('is too long when more options are selected than maxlength', async () => {
327
+ const combobox = await mount('multiple maxlength="2"')
328
+ combobox.value = 'apple,banana,cherry'
329
+ await combobox.updateComplete
330
+
331
+ expect(combobox['_value']).toEqual(['apple', 'banana', 'cherry'])
332
+ expect(combobox.internals.validity.tooLong).toBe(true)
333
+ })
334
+
335
+ test('is too short when fewer options are selected than minlength', async () => {
336
+ const combobox = await mount('multiple minlength="2"')
337
+ ;(combobox as any).toggleValue('banana')
338
+ await combobox.updateComplete
339
+
340
+ expect(combobox.internals.validity.tooShort).toBe(true)
341
+
342
+ ;(combobox as any).toggleValue('cherry')
343
+ await combobox.updateComplete
344
+
345
+ expect(combobox.internals.validity.tooShort).toBe(false)
346
+ expect(combobox.internals.validity.valid).toBe(true)
347
+ })
348
+ })
349
+
305
350
  describe('Disabled options', () => {
306
351
  test('does not select disabled options', async () => {
307
352
  const optionsWithDisabled: IPktComboboxOption[] = [
@@ -110,6 +110,18 @@ describe('PktDatepicker', () => {
110
110
  expect(tags.length).toBeLessThanOrEqual(2)
111
111
  })
112
112
 
113
+ test('validates maxlength against the number of dates in multiple mode', async () => {
114
+ const container = await createDatepicker('multiple maxlength="2"')
115
+ const datepicker = container.querySelector('pkt-datepicker') as PktDatepicker
116
+ await datepicker.updateComplete
117
+
118
+ datepicker.value = '2024-06-15,2024-06-20'
119
+ await datepicker.updateComplete
120
+
121
+ expect(datepicker.internals.validity.tooLong).toBe(false)
122
+ expect(datepicker.internals.validity.valid).toBe(true)
123
+ })
124
+
113
125
  test('sorts multiple dates chronologically', async () => {
114
126
  const unsortedDates = '2024-06-25,2024-06-15,2024-06-20'
115
127
  const container = await createDatepicker(`value="${unsortedDates}" multiple`)
@@ -0,0 +1,141 @@
1
+ import '@testing-library/jest-dom'
2
+ import { axe, toHaveNoViolations } from 'jest-axe'
3
+ import { createElementTest, BaseTestConfig } from '../../tests/test-framework'
4
+ import { CustomElementFor } from '../../tests/component-registry'
5
+ import type { IPktModal } from './modal'
6
+ import './modal'
7
+
8
+ expect.extend(toHaveNoViolations)
9
+
10
+ export interface ModalTestConfig extends IPktModal, BaseTestConfig {}
11
+
12
+ export const createModalTest = async (config: ModalTestConfig = {}) => {
13
+ const { container, element } = await createElementTest<
14
+ CustomElementFor<'pkt-modal'>,
15
+ ModalTestConfig
16
+ >('pkt-modal', config)
17
+
18
+ return {
19
+ container,
20
+ modal: element,
21
+ heading: element.querySelector('.pkt-modal__headingText'),
22
+ }
23
+ }
24
+
25
+ afterEach(() => {
26
+ document.body.innerHTML = ''
27
+ })
28
+
29
+ describe('PktModal', () => {
30
+ describe('heading icon', () => {
31
+ test('renders no icon by default', async () => {
32
+ const { heading } = await createModalTest({ headingText: 'Historikk' })
33
+ expect(heading).not.toHaveClass('pkt-modal__headingText--hasIcon')
34
+ expect(heading?.querySelector('pkt-icon')).toBeNull()
35
+ })
36
+
37
+ test('renders the icon before the heading text', async () => {
38
+ const { heading } = await createModalTest({
39
+ headingText: 'Historikk',
40
+ headingIconName: 'clock-history',
41
+ })
42
+ expect(heading).toHaveClass('pkt-modal__headingText--hasIcon')
43
+ const icon = heading?.firstElementChild
44
+ expect(icon?.tagName.toLowerCase()).toBe('pkt-icon')
45
+ expect(icon).toHaveClass('pkt-modal__headingIcon')
46
+ expect(icon).toHaveAttribute('name', 'clock-history')
47
+ expect(heading).toHaveTextContent('Historikk')
48
+ })
49
+
50
+ test('passes headingIconPath to the icon', async () => {
51
+ const customPath = 'https://custom-cdn.example.com/icons/'
52
+ const { modal } = await createModalTest({
53
+ headingText: 'Historikk',
54
+ headingIconName: 'clock-history',
55
+ headingIconPath: customPath,
56
+ })
57
+ expect(modal.headingIconPath).toBe(customPath)
58
+ const icon = modal.querySelector('.pkt-modal__headingIcon')
59
+ expect(icon).toHaveAttribute('path', customPath)
60
+ })
61
+
62
+ test('does not set the path attribute when headingIconPath is not provided', async () => {
63
+ const { modal } = await createModalTest({
64
+ headingText: 'Historikk',
65
+ headingIconName: 'clock-history',
66
+ })
67
+ const icon = modal.querySelector('.pkt-modal__headingIcon')
68
+ expect(icon).not.toHaveAttribute('path')
69
+ })
70
+
71
+ test('does not render the icon without headingText', async () => {
72
+ const { modal } = await createModalTest({ headingIconName: 'clock-history' })
73
+ expect(modal.querySelector('.pkt-modal__headingIcon')).toBeNull()
74
+ })
75
+
76
+ test('updates the icon when headingIconName changes', async () => {
77
+ const { modal } = await createModalTest({
78
+ headingText: 'Historikk',
79
+ headingIconName: 'clock-history',
80
+ })
81
+ modal.headingIconName = 'user'
82
+ await modal.updateComplete
83
+ expect(modal.querySelector('.pkt-modal__headingIcon')).toHaveAttribute('name', 'user')
84
+
85
+ modal.headingIconName = undefined
86
+ await modal.updateComplete
87
+ expect(modal.querySelector('.pkt-modal__headingIcon')).toBeNull()
88
+ expect(modal.querySelector('.pkt-modal__headingText')).not.toHaveClass(
89
+ 'pkt-modal__headingText--hasIcon',
90
+ )
91
+ })
92
+
93
+ test('renders with no wcag errors with axe', async () => {
94
+ const { container } = await createModalTest({
95
+ headingText: 'Historikk',
96
+ headingIconName: 'clock-history',
97
+ })
98
+ const results = await axe(container)
99
+ expect(results).toHaveNoViolations()
100
+ })
101
+ })
102
+
103
+ describe('ids', () => {
104
+ test('labels and describes the dialog with its own heading and content', async () => {
105
+ const { modal } = await createModalTest({ headingText: 'Historikk' })
106
+ const dialog = modal.querySelector('dialog')!
107
+ const heading = modal.querySelector('h1.pkt-modal__headingText')!
108
+ const content = modal.querySelector('.pkt-modal__content')!
109
+ expect(heading.id).toMatch(/^pkt-modal__headingText-/)
110
+ expect(content.id).toMatch(/^pkt-modal__content-/)
111
+ expect(dialog).toHaveAttribute('aria-labelledby', heading.id)
112
+ expect(dialog).toHaveAttribute('aria-describedby', content.id)
113
+ })
114
+
115
+ test('gives each modal on the page unique ids', async () => {
116
+ const { modal: first } = await createModalTest({ headingText: 'Første' })
117
+ const { modal: second } = await createModalTest({ headingText: 'Andre' })
118
+ const firstHeading = first.querySelector('h1')!
119
+ const secondHeading = second.querySelector('h1')!
120
+ expect(firstHeading.id).not.toBe(secondHeading.id)
121
+ expect(first.querySelector('dialog')).toHaveAttribute('aria-labelledby', firstHeading.id)
122
+ expect(second.querySelector('dialog')).toHaveAttribute('aria-labelledby', secondHeading.id)
123
+ expect(first.querySelector('dialog')!.getAttribute('aria-describedby')).not.toBe(
124
+ second.querySelector('dialog')!.getAttribute('aria-describedby'),
125
+ )
126
+ })
127
+
128
+ test('keeps the ids stable across re-renders', async () => {
129
+ const { modal } = await createModalTest({ headingText: 'Historikk' })
130
+ const before = modal.querySelector('h1')!.id
131
+ modal.headingText = 'Endret'
132
+ await modal.updateComplete
133
+ expect(modal.querySelector('h1')!.id).toBe(before)
134
+ })
135
+
136
+ test('omits aria-labelledby without headingText', async () => {
137
+ const { modal } = await createModalTest()
138
+ expect(modal.querySelector('dialog')).not.toHaveAttribute('aria-labelledby')
139
+ })
140
+ })
141
+ })
@@ -1,4 +1,5 @@
1
1
  import { classMap } from 'lit/directives/class-map.js'
2
+ import { ifDefined } from 'lit/directives/if-defined.js'
2
3
  import { customElement, property, state } from 'lit/decorators.js'
3
4
  import { html, nothing, PropertyValues } from 'lit'
4
5
  import { PktElementWithSlot } from '@/base-elements/element-with-slot'
@@ -11,6 +12,7 @@ import {
11
12
  setScrollLock,
12
13
  type ScrollLockToken,
13
14
  } from 'shared-utils/scroll-lock'
15
+ import { uuidish } from 'shared-utils/utils'
14
16
  import specs from 'componentSpecs/modal.json'
15
17
  import '@/components/icon'
16
18
 
@@ -19,6 +21,8 @@ type ModalSize = TPktSize | 'fit-content'
19
21
  export interface IPktModal {
20
22
  open?: boolean
21
23
  headingText?: string
24
+ headingIconName?: string
25
+ headingIconPath?: string
22
26
  removePadding?: boolean
23
27
  hideCloseButton?: boolean
24
28
  closeOnBackdropClick?: boolean
@@ -33,6 +37,8 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
33
37
  // Public properties
34
38
  @property({ type: Boolean, reflect: true }) open?: boolean = false
35
39
  @property({ type: String }) headingText?: string = ''
40
+ @property({ type: String }) headingIconName?: string
41
+ @property({ type: String }) headingIconPath?: string
36
42
  @property({ type: Boolean }) removePadding?: boolean = false
37
43
  @property({ type: Boolean }) hideCloseButton?: boolean = specs.props.hideCloseButton.default
38
44
  @property({ type: Boolean })
@@ -47,6 +53,10 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
47
53
 
48
54
  private _scrollLockToken: ScrollLockToken = createScrollLockToken()
49
55
 
56
+ private readonly _idSuffix = uuidish()
57
+ private readonly _headingId = `pkt-modal__headingText-${this._idSuffix}`
58
+ private readonly _contentId = `pkt-modal__content-${this._idSuffix}`
59
+
50
60
  @state() _isOpen: boolean = false
51
61
 
52
62
  constructor() {
@@ -164,8 +174,17 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
164
174
  const headingClasses = {
165
175
  'pkt-modal__headingText': true,
166
176
  'pkt-txt-24': true,
177
+ 'pkt-modal__headingText--hasIcon': !!this.headingIconName,
167
178
  }
168
179
 
180
+ const headingIcon = this.headingIconName
181
+ ? html`<pkt-icon
182
+ class="pkt-modal__headingIcon"
183
+ name=${this.headingIconName}
184
+ path=${ifDefined(this.headingIconPath)}
185
+ ></pkt-icon>`
186
+ : nothing
187
+
169
188
  const contentClasses = {
170
189
  'pkt-modal__content': true,
171
190
  'pkt-txt-18-light': true,
@@ -181,8 +200,8 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
181
200
  <dialog
182
201
  class=${classMap(classes)}
183
202
  ${ref(this.dialogRef)}
184
- aria-labelledby=${this.headingText ? 'pkt-modal__headingText' : nothing}
185
- aria-describedby="pkt-modal__content"
203
+ aria-labelledby=${this.headingText ? this._headingId : nothing}
204
+ aria-describedby=${this._contentId}
186
205
  @close=${(event: Event) => this.close(event, true)}
187
206
  >
188
207
  <div class="pkt-modal__wrapper">
@@ -190,8 +209,8 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
190
209
  ? html`<div class="pkt-modal__header">
191
210
  <div class="pkt-modal__header-background"></div>
192
211
  ${this.headingText
193
- ? html`<h1 id="pkt-modal__headingText" class=${classMap(headingClasses)}>
194
- ${this.headingText}
212
+ ? html`<h1 id=${this._headingId} class=${classMap(headingClasses)}>
213
+ ${headingIcon}${this.headingText}
195
214
  </h1>`
196
215
  : html`<div class="pkt-modal__headingText"></div>`}
197
216
  ${!this.hideCloseButton
@@ -211,7 +230,7 @@ export class PktModal extends PktElementWithSlot implements IPktModal {
211
230
  </div>`
212
231
  : nothing}
213
232
  <div class="pkt-modal__container">
214
- <div id="pkt-modal__content" class=${classMap(contentClasses)}>
233
+ <div id=${this._contentId} class=${classMap(contentClasses)}>
215
234
  ${slotContent(this)}
216
235
  </div>
217
236
  </div>
@@ -1,35 +0,0 @@
1
- const e=require("./element-C6WTyJFE.cjs"),t=require("./class-map-Bh6toDeV.cjs"),n=require("./element-with-slot-CcJPCLgn.cjs");require("./icon-jPhyZD1z.cjs");const r=require("./ref-CB7e9nMY.cjs"),i=require("./scroll-lock-B46ur0FF.cjs");var a={name:`pkt-modal`,react:`PktModal`,"css-class":`pkt-modal`,isElement:!0,isPureReact:!0,events:{"background-click":{description:`Event som trigges når bakgrunnen trykkes på`},close:{description:`Event som trigges når meldingsboksen lukkes`}},props:{open:{name:`Åpen`,description:`Deklarativ styring av modalens åpen/lukket-tilstand. Kan brukes i stedet for showModal()/close()-metodene.`,type:`boolean`,category:`tech`,default:!1},headingText:{name:`Heading text`,description:`Heading tekst på modalen`,type:`string`,category:`contents`},hideCloseButton:{name:`Gjem 'Lukk'-knapp`,description:`Gjemmer lukkeknappen. Dersom denne er satt til true, vil ikke lukkeknappen vises, og dermed er det viktig at man tilbyr en annen måte som f.eks. en knapp for å lukke modalen på.`,type:`boolean`,category:`ui`,default:!1},closeOnBackdropClick:{name:`Lukk modalen når bakgrunnen trykkes på`,description:`Lukk modalen når bakgrunnen trykkes på`,type:`boolean`,category:`tech`,default:!1},closeButtonSkin:{name:`Stil på lukkeknappen`,description:`Stil på lukkeknappen`,type:[`blue`,`yellow-filled`],category:`ui`,default:`blue`},size:{name:`Størrelse`,description:`Størrelsen på modalen`,type:[`small`,`medium`,`large`,`fit-content`],category:`ui`,default:`medium`},variant:{name:`Variant`,description:`Standard dialog eller skuff`,type:[`dialog`,`drawer`],category:`ui`,default:`dialog`},drawerPosition:{name:`Skuffposisjon`,description:`Posisjonen til skuffen`,type:[`left`,`right`],category:`ui`,default:`right`},transparentBackdrop:{name:`Gjennomsiktig bakgrunn`,description:`Bakgrunnen er gjennomsiktig`,type:`boolean`,category:`ui`,default:!1},removePadding:{name:`Fjern padding`,description:`Fjerner paddingen rundt innholdet i modalen`,type:`boolean`,category:`ui`,default:!1}},slots:{default:{description:`Innholdet i meldingen. Her tilbyr vi støtteklasser for å style 1-3 knapper i modalen.`}}},o=class extends n.t{constructor(){super(),this.open=!1,this.headingText=``,this.removePadding=!1,this.hideCloseButton=a.props.hideCloseButton.default,this.closeOnBackdropClick=a.props.closeOnBackdropClick.default,this.closeButtonSkin=`blue`,this.size=a.props.size.default,this.variant=`dialog`,this.drawerPosition=`right`,this.transparentBackdrop=!1,this.dialogRef=r.t(),this._scrollLockToken=i.t(),this._isOpen=!1,this.close=(e,t=!1)=>{if(!this._isOpen)return;this._isOpen=!1,this.open=!1,i.n(this._scrollLockToken,!1);let n=document.activeElement;n&&!this.isElementInViewport(n)&&n.scrollIntoView({behavior:`smooth`,block:`nearest`}),this.dispatchEvent(new CustomEvent(`close`,{detail:{origin:e},bubbles:!0,composed:!0})),t||this.dialogRef.value?.close(),this.requestUpdate()},this.showModal=(e=null)=>{this._isOpen=!0,this.open=!0,this.dialogRef.value?.showModal(),i.n(this._scrollLockToken,!0),this.dispatchEvent(new CustomEvent(`showModal`,{detail:{origin:e},bubbles:!0,composed:!0})),this.requestUpdate()},this._isOpen=!1}async connectedCallback(){super.connectedCallback(),document.addEventListener(`keydown`,this.handleKeyDown.bind(this)),document.addEventListener(`click`,this.handleBackdropClick.bind(this))}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`click`,this.handleBackdropClick),i.n(this._scrollLockToken,!1)}updated(e){super.updated(e),e.has(`open`)&&(this.open&&!this._isOpen?this.showModal():!this.open&&this._isOpen&&this.close(new Event(`close`),!1))}async firstUpdated(e){super.firstUpdated(e),this.dialogRef.value&&!window.HTMLDialogElement&&!this.dialogRef.value.showModal&&(`document`in window&&`createElement`in document&&(await Promise.resolve().then(()=>require("./dialog-polyfill.esm-B-g35ove.cjs")).then(e=>e.default)).registerDialog(this.dialogRef.value),this.dialogRef.value.addEventListener(`close`,()=>{this.close(new Event(`close`),!0)}))}handleKeyDown(e){e.key===`Escape`&&this.close(e)}handleBackdropClick(e){this.closeOnBackdropClick&&e.target===this.dialogRef?.value&&this.close(e)}isElementInViewport(e){let 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(){let i={"pkt-modal":!0,"pkt-modal--removePadding":this.removePadding??!1,"pkt-modal--noHeadingText":this.headingText===``||this.headingText===void 0,"pkt-modal--noShadow":this.closeButtonSkin===`yellow-filled`,"pkt-modal--transparentBackdrop":this.transparentBackdrop??!1,[`pkt-modal--${this.size}`]:this.size!==void 0,[`pkt-modal__${this.variant}`]:this.variant!==void 0,[`pkt-modal__drawer--${this.drawerPosition}`]:this.variant===`drawer`},a={"pkt-modal__headingText":!0,"pkt-txt-24":!0},o={"pkt-modal__content":!0,"pkt-txt-18-light":!0},s=this.closeButtonSkin===`blue`,c={"pkt-modal__closeButton":!0,[`pkt-modal__closeButton--${this.closeButtonSkin}`]:!0};return e._`
2
- <dialog
3
- class=${t.t(i)}
4
- ${r.n(this.dialogRef)}
5
- aria-labelledby=${this.headingText?`pkt-modal__headingText`:e.h}
6
- aria-describedby="pkt-modal__content"
7
- @close=${e=>this.close(e,!0)}
8
- >
9
- <div class="pkt-modal__wrapper">
10
- ${this.headingText||!this.hideCloseButton?e._`<div class="pkt-modal__header">
11
- <div class="pkt-modal__header-background"></div>
12
- ${this.headingText?e._`<h1 id="pkt-modal__headingText" class=${t.t(a)}>
13
- ${this.headingText}
14
- </h1>`:e._`<div class="pkt-modal__headingText"></div>`}
15
- ${this.hideCloseButton?e._`<div class="pkt-modal__noCloseButton"></div>`:e._`<div class="${t.t(c)}">
16
- <pkt-button
17
- @click=${e=>this.close(e)}
18
- aria-label=${this.pktStrings.get(`generic`).close}
19
- iconname="close"
20
- variant="icon-only"
21
- size="medium"
22
- skin=${s?`tertiary`:`primary`}
23
- >
24
- ${this.pktStrings.get(`generic`).close}
25
- </pkt-button>
26
- </div>`}
27
- </div>`:e.h}
28
- <div class="pkt-modal__container">
29
- <div id="pkt-modal__content" class=${t.t(o)}>
30
- ${n.i(this)}
31
- </div>
32
- </div>
33
- </div>
34
- </dialog>
35
- `}};e.n([e.u({type:Boolean,reflect:!0})],o.prototype,`open`,void 0),e.n([e.u({type:String})],o.prototype,`headingText`,void 0),e.n([e.u({type:Boolean})],o.prototype,`removePadding`,void 0),e.n([e.u({type:Boolean})],o.prototype,`hideCloseButton`,void 0),e.n([e.u({type:Boolean})],o.prototype,`closeOnBackdropClick`,void 0),e.n([e.u({type:String})],o.prototype,`closeButtonSkin`,void 0),e.n([e.u({type:String})],o.prototype,`size`,void 0),e.n([e.u({type:String})],o.prototype,`variant`,void 0),e.n([e.u({type:String})],o.prototype,`drawerPosition`,void 0),e.n([e.u({type:Boolean})],o.prototype,`transparentBackdrop`,void 0),e.n([e.l()],o.prototype,`_isOpen`,void 0);try{e.d(`pkt-modal`)(o)}catch{console.warn(`Forsøker å definere <pkt-modal>, men den er allerede definert`)}var s=o;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});