@oslokommune/punkt-elements 13.6.12 → 13.7.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.
- package/CHANGELOG.md +40 -0
- package/dist/{accordionitem-B_h5XGCo.js → accordionitem-C_URrDjP.js} +4 -4
- package/dist/{accordionitem-BOmnm80g.cjs → accordionitem-DCZrHVNR.cjs} +1 -1
- package/dist/{alert-ZP5-fqlt.cjs → alert-Ci7WvRXi.cjs} +1 -1
- package/dist/{alert-CTTm6ugp.js → alert-Dh1YhaBq.js} +13 -26
- package/dist/{backlink-BT7DO6rV.cjs → backlink-BzEvli8m.cjs} +1 -1
- package/dist/{backlink-Bq8O2bt8.js → backlink-CI_jMGzZ.js} +3 -3
- package/dist/{button-x6Xw-5w0.js → button-CCFAUJa0.js} +5 -5
- package/dist/{button-BfqxLnMT.cjs → button-CXJQ_Wgl.cjs} +1 -1
- package/dist/calendar-BaMrdMDZ.cjs +115 -0
- package/dist/{calendar-CodWwTHM.js → calendar-DtJh7UYD.js} +532 -480
- package/dist/{card-B9RPShvV.cjs → card-Cf-UcGAP.cjs} +1 -1
- package/dist/{card-en2KhOPO.js → card-M1X36b6i.js} +8 -26
- package/dist/{checkbox-CH8xeK-0.cjs → checkbox-CTxc8wQe.cjs} +1 -1
- package/dist/{checkbox-DSAcMC-D.js → checkbox-_5LbXU7N.js} +4 -4
- package/dist/class-map-C_erArZz.cjs +5 -0
- package/dist/{class-map-Dw6Wrxwi.js → class-map-wy7PUk0P.js} +3 -3
- package/dist/{combobox-BFOjlFIj.cjs → combobox-BJ1gA0f0.cjs} +1 -1
- package/dist/{combobox-DaiEdUKx.js → combobox-Ct0NNY1p.js} +12 -16
- package/dist/{consent-CXp0bLvg.js → consent-B2hIQh4b.js} +3 -3
- package/dist/{consent-DFrsiYGQ.cjs → consent-BeOjxQdR.cjs} +1 -1
- package/dist/datepicker-B8mifBAm.js +1374 -0
- package/dist/datepicker-DVqmQAOe.cjs +289 -0
- package/dist/directive-helpers-4oOjKnGY.cjs +5 -0
- package/dist/directive-helpers-BzAtj9by.js +38 -0
- package/dist/{element-D62wHiNU.cjs → element-CJ_QKaki.cjs} +6 -6
- package/dist/{element-DJZPsA_J.js → element-CRDRygXu.js} +47 -132
- package/dist/{heading-H_FWjo2k.cjs → heading--JKFppLS.cjs} +1 -1
- package/dist/{heading-DQ0R34j4.js → heading-Cs5yGnJg.js} +1 -1
- package/dist/{helptext-D1fkGmfT.cjs → helptext-CVQP3pis.cjs} +1 -1
- package/dist/{helptext-8ykxyegi.js → helptext-DuvVSH7d.js} +6 -6
- package/dist/icon-1dy7UZcu.js +89 -0
- package/dist/icon-BGuizDwk.cjs +9 -0
- package/dist/{if-defined-D3lgJqT7.js → if-defined-BWZGb3bh.js} +1 -1
- package/dist/{if-defined-CkVc_RJD.cjs → if-defined-Bc9-_I01.cjs} +1 -1
- package/dist/index.d.ts +98 -6
- package/dist/input-element-BcFmygSF.js +707 -0
- package/dist/input-element-j9znzLWz.cjs +1 -0
- package/dist/{input-wrapper-DVjNwf8-.cjs → input-wrapper-BsQ7oFMd.cjs} +1 -1
- package/dist/input-wrapper-CDgenrYA.js +6 -0
- package/dist/{input-wrapper-CQzXG44g.js → input-wrapper-CKJU0QWG.js} +8 -8
- package/dist/{link-CyiVlb-7.cjs → link-Da3pZ_CW.cjs} +1 -1
- package/dist/{link-DSSJYrtn.js → link-DzZCw8j2.js} +9 -16
- package/dist/{linkcard-fH9uydjS.cjs → linkcard-BM23gzhS.cjs} +1 -1
- package/dist/{linkcard-g8JtooPU.js → linkcard-RIK5xqbd.js} +4 -4
- package/dist/{listbox-L-iOSF7M.cjs → listbox-CsGiqzD0.cjs} +1 -1
- package/dist/{listbox-n4wjlLqD.js → listbox-DlJevu8O.js} +5 -5
- package/dist/{loader-Bzf1sPSg.js → loader-BVvBzaPI.js} +5 -5
- package/dist/{loader-C-3l7kb9.cjs → loader-Bo8RCbCJ.cjs} +1 -1
- package/dist/{messagebox---xPIAwR.cjs → messagebox-C76IcXTl.cjs} +1 -1
- package/dist/{messagebox-okJLeSpj.js → messagebox-DwdMXoAe.js} +6 -16
- package/dist/{modal-pohCsr_x.js → modal-BGXk3f9u.js} +6 -16
- package/dist/{modal-IjDRQfX1.cjs → modal-Cdz9JcCX.cjs} +1 -1
- package/dist/pkt-accordion.cjs +1 -1
- package/dist/pkt-accordion.js +2 -2
- package/dist/pkt-alert.cjs +1 -1
- package/dist/pkt-alert.js +1 -1
- package/dist/pkt-backlink.cjs +1 -1
- package/dist/pkt-backlink.js +1 -1
- package/dist/pkt-button.cjs +1 -1
- package/dist/pkt-button.js +1 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-card.cjs +1 -1
- package/dist/pkt-card.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 -1
- package/dist/pkt-consent.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +8 -4
- package/dist/pkt-heading.cjs +1 -1
- package/dist/pkt-heading.js +1 -1
- 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 +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +29 -29
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-link.cjs +1 -1
- package/dist/pkt-link.js +1 -1
- package/dist/pkt-linkcard.cjs +1 -1
- package/dist/pkt-linkcard.js +1 -1
- package/dist/pkt-listbox.cjs +1 -1
- package/dist/pkt-listbox.js +1 -1
- package/dist/pkt-loader.cjs +1 -1
- package/dist/pkt-loader.js +1 -1
- package/dist/pkt-messagebox.cjs +1 -1
- package/dist/pkt-messagebox.js +1 -1
- 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-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-tag.cjs +1 -1
- package/dist/pkt-tag.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/{progressbar-DjsupQ7Y.js → progressbar-BbVei20_.js} +7 -7
- package/dist/{progressbar-DJzEC7cx.cjs → progressbar-CazcIzVT.cjs} +2 -2
- package/dist/{radiobutton-DEboKECm.cjs → radiobutton-D1fihs8R.cjs} +1 -1
- package/dist/{radiobutton-Bz_qApF3.js → radiobutton-DODROIBF.js} +5 -5
- package/dist/{ref-BfgcOXko.cjs → ref-BFa5Utho.cjs} +1 -1
- package/dist/{ref-BCGCor-j.js → ref-Xa5dbh--.js} +2 -2
- package/dist/repeat-BZb41H64.cjs +5 -0
- package/dist/{repeat-B6qPUgAq.js → repeat-CJ79egkN.js} +8 -8
- package/dist/{select-DKkoxmgj.js → select-BG2MBQbh.js} +6 -6
- package/dist/{select-DynzsPo0.cjs → select-D-m1PhpA.cjs} +1 -1
- package/dist/{state-CPQXJ4Ct.js → state-DS_kr2Fy.js} +1 -1
- package/dist/{state-BkE_Rxl7.cjs → state-DSjcvzDN.cjs} +1 -1
- package/dist/{tag-NZ5oeGfw.js → tag-CqMgt01I.js} +7 -20
- package/dist/{tag-BKq07hGI.cjs → tag-EFUKrc8q.cjs} +2 -2
- package/dist/{textarea-COG1CH_s.js → textarea-DCKKhs1B.js} +9 -9
- package/dist/{textarea-BS1tgktz.cjs → textarea-aUG3S7C2.cjs} +1 -1
- package/dist/{textinput-CTOtfcTR.js → textinput-B5Ai5R8L.js} +8 -8
- package/dist/{textinput-CCK8ti2y.cjs → textinput-mUERucRy.cjs} +1 -1
- package/package.json +15 -7
- package/src/components/combobox/combobox.ts +1 -1
- package/src/components/datepicker/datepicker-multiple.ts +202 -0
- package/src/components/datepicker/datepicker-range.ts +281 -0
- package/src/components/datepicker/datepicker-single.ts +198 -0
- package/src/components/datepicker/datepicker-utils.ts +9 -1
- package/src/components/datepicker/datepicker.ts +141 -213
- package/src/components/datepicker/index.ts +5 -1
- package/src/components/icon/icon.ts +16 -7
- package/src/components/select/select.ts +1 -1
- package/dist/calendar-DH-fCGyW.cjs +0 -115
- package/dist/class-map-CG3vIaNm.cjs +0 -5
- package/dist/datepicker-C244h82t.cjs +0 -190
- package/dist/datepicker-DwOkktaP.js +0 -859
- package/dist/directive-helpers-_qHew-gi.cjs +0 -5
- package/dist/directive-helpers-cAOIHg9K.js +0 -45
- package/dist/icon-B1-mkmwB.js +0 -88
- package/dist/icon-__Hjt2XZ.cjs +0 -9
- package/dist/input-element-DQOVrqUZ.js +0 -703
- package/dist/input-element-Y8sdrq9C.cjs +0 -1
- package/dist/input-wrapper-8iKEzDRZ.js +0 -40
- package/dist/repeat-DzibMwhi.cjs +0 -5
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { classMap } from 'lit/directives/class-map.js'
|
|
2
|
-
import { ifDefined } from 'lit/directives/if-defined.js'
|
|
3
1
|
import { customElement, property, state } from 'lit/decorators.js'
|
|
4
2
|
import { formatISODate, fromISOToDate, parseISODateString } from '@/utils/dateutils'
|
|
5
3
|
import { html, nothing, PropertyValues } from 'lit'
|
|
@@ -13,8 +11,10 @@ import '@/components/icon'
|
|
|
13
11
|
import '@/components/input-wrapper'
|
|
14
12
|
import './date-tags'
|
|
15
13
|
import './datepicker-popup'
|
|
14
|
+
import './datepicker-single'
|
|
15
|
+
import './datepicker-range'
|
|
16
|
+
import './datepicker-multiple'
|
|
16
17
|
import { PktSlotController } from '@/controllers/pkt-slot-controller'
|
|
17
|
-
import { keyboardUtils } from './datepicker-utils'
|
|
18
18
|
import {
|
|
19
19
|
sleep,
|
|
20
20
|
deviceDetection,
|
|
@@ -26,6 +26,9 @@ import {
|
|
|
26
26
|
formUtils,
|
|
27
27
|
} from './datepicker-utils'
|
|
28
28
|
import { PktDatepickerPopup } from './datepicker-popup'
|
|
29
|
+
import { PktDatepickerSingle } from './datepicker-single'
|
|
30
|
+
import { PktDatepickerRange } from './datepicker-range'
|
|
31
|
+
import { PktDatepickerMultiple } from './datepicker-multiple'
|
|
29
32
|
import { ElementProps } from '@/types/typeUtils'
|
|
30
33
|
|
|
31
34
|
type Props = ElementProps<
|
|
@@ -116,7 +119,6 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
116
119
|
timezone: string = 'Europe/Oslo'
|
|
117
120
|
|
|
118
121
|
@state() inputClasses = {}
|
|
119
|
-
@state() buttonClasses = {}
|
|
120
122
|
|
|
121
123
|
/**
|
|
122
124
|
* Computed properties
|
|
@@ -229,239 +231,178 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
229
231
|
* Element references
|
|
230
232
|
*/
|
|
231
233
|
|
|
232
|
-
//
|
|
233
|
-
inputRef: Ref<HTMLInputElement>
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
// Override the inputRef and inputRefTo for compatibility
|
|
235
|
+
get inputRef(): Ref<HTMLInputElement> {
|
|
236
|
+
const element = this.currentInputElement
|
|
237
|
+
return { value: element } as Ref<HTMLInputElement>
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
get inputRefTo(): Ref<HTMLInputElement> {
|
|
241
|
+
const element = this.currentInputElementTo
|
|
242
|
+
return { value: element } as Ref<HTMLInputElement>
|
|
243
|
+
}
|
|
244
|
+
|
|
236
245
|
calRef: Ref<PktCalendar> = createRef()
|
|
237
246
|
popupRef: Ref<HTMLDivElement> = createRef()
|
|
238
247
|
helptextSlot: Ref<HTMLElement> = createRef()
|
|
239
248
|
|
|
249
|
+
// Child component refs
|
|
250
|
+
singleInputRef: Ref<PktDatepickerSingle> = createRef()
|
|
251
|
+
rangeInputRef: Ref<PktDatepickerRange> = createRef()
|
|
252
|
+
multipleInputRef: Ref<PktDatepickerMultiple> = createRef()
|
|
253
|
+
|
|
254
|
+
// Getters for backward compatibility with input refs
|
|
255
|
+
get currentInputElement(): HTMLInputElement | undefined {
|
|
256
|
+
if (this.multiple) {
|
|
257
|
+
return this.multipleInputRef.value?.inputElement
|
|
258
|
+
} else if (this.range) {
|
|
259
|
+
return this.rangeInputRef.value?.inputElement
|
|
260
|
+
} else {
|
|
261
|
+
return this.singleInputRef.value?.inputElement
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
get currentInputElementTo(): HTMLInputElement | undefined {
|
|
266
|
+
if (this.range) {
|
|
267
|
+
return this.rangeInputRef.value?.inputElementTo
|
|
268
|
+
}
|
|
269
|
+
return undefined
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
get currentButtonElement(): HTMLButtonElement | undefined {
|
|
273
|
+
if (this.multiple) {
|
|
274
|
+
return this.multipleInputRef.value?.buttonElement
|
|
275
|
+
} else if (this.range) {
|
|
276
|
+
return this.rangeInputRef.value?.buttonElement
|
|
277
|
+
} else {
|
|
278
|
+
return this.singleInputRef.value?.buttonElement
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Override btnRef for compatibility
|
|
283
|
+
get btnRef(): Ref<HTMLButtonElement> {
|
|
284
|
+
const element = this.currentButtonElement
|
|
285
|
+
return { value: element } as Ref<HTMLButtonElement>
|
|
286
|
+
}
|
|
287
|
+
|
|
240
288
|
/**
|
|
241
289
|
* Rendering
|
|
242
290
|
*/
|
|
243
291
|
renderInput() {
|
|
244
292
|
return html`
|
|
245
|
-
<
|
|
246
|
-
class="${classMap(this.inputClasses)}"
|
|
247
|
-
.type=${this.inputType}
|
|
248
|
-
id="${this.id}-input"
|
|
293
|
+
<pkt-datepicker-single
|
|
249
294
|
.value=${this._value[0] ?? ''}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
@
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
() => formUtils.submitFormOrFallback(this.internals, () => this.inputRef.value?.blur()),
|
|
266
|
-
undefined,
|
|
267
|
-
() => this.inputRef.value?.blur(),
|
|
268
|
-
)}
|
|
269
|
-
@input=${(e: Event) => {
|
|
270
|
-
this.onInput()
|
|
271
|
-
e.stopImmediatePropagation()
|
|
272
|
-
}}
|
|
273
|
-
@focus=${() => {
|
|
274
|
-
this.onFocus()
|
|
275
|
-
if (deviceDetection.isIOS()) {
|
|
276
|
-
this.showCalendar()
|
|
277
|
-
}
|
|
278
|
-
}}
|
|
279
|
-
@blur=${(e: FocusEvent) => {
|
|
280
|
-
if (!this.calRef.value?.contains(e.relatedTarget as Node)) {
|
|
295
|
+
.inputType=${this.inputType}
|
|
296
|
+
.id=${this.id}
|
|
297
|
+
.min=${this.min}
|
|
298
|
+
.max=${this.max}
|
|
299
|
+
.placeholder=${this.placeholder}
|
|
300
|
+
.readonly=${this.readonly}
|
|
301
|
+
.disabled=${this.disabled}
|
|
302
|
+
.inputClasses=${this.inputClasses}
|
|
303
|
+
.internals=${this.internals}
|
|
304
|
+
.strings=${this.strings}
|
|
305
|
+
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
306
|
+
@input-change=${() => this.onInput()}
|
|
307
|
+
@input-focus=${() => this.onFocus()}
|
|
308
|
+
@input-blur=${(e: CustomEvent) => {
|
|
309
|
+
if (!this.calRef.value?.contains(e.detail.relatedTarget as Node)) {
|
|
281
310
|
this.onBlur()
|
|
282
311
|
}
|
|
283
|
-
this.manageValidity(e.target as HTMLInputElement)
|
|
284
|
-
this.value = (e.target as HTMLInputElement).value
|
|
285
312
|
}}
|
|
286
|
-
@
|
|
313
|
+
@manage-validity=${(e: CustomEvent) => this.manageValidity(e.detail)}
|
|
314
|
+
@value-change=${(e: CustomEvent) => {
|
|
315
|
+
this.value = e.detail
|
|
316
|
+
}}
|
|
317
|
+
@input-changed=${() => {
|
|
287
318
|
this.touched = true
|
|
288
|
-
e.stopImmediatePropagation()
|
|
289
319
|
}}
|
|
290
|
-
${ref(this.
|
|
291
|
-
|
|
320
|
+
${ref(this.singleInputRef)}
|
|
321
|
+
></pkt-datepicker-single>
|
|
292
322
|
`
|
|
293
323
|
}
|
|
294
324
|
|
|
295
325
|
renderRangeInput() {
|
|
296
|
-
const rangeLabelClasses = cssUtils.getRangeLabelClasses(this.showRangeLabels)
|
|
297
326
|
return html`
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
.
|
|
304
|
-
|
|
305
|
-
.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
@
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// event, toggleCalendar, submitForm, focusNext, blur, comma
|
|
318
|
-
e,
|
|
319
|
-
(event) => this.toggleCalendar(event),
|
|
320
|
-
() =>
|
|
321
|
-
formUtils.submitFormOrFallback(this.internals, () => this.inputRefTo.value?.focus()),
|
|
322
|
-
() => this.inputRefTo.value?.focus(),
|
|
323
|
-
() => this.inputRef.value?.blur(),
|
|
324
|
-
)}
|
|
325
|
-
@input=${(e: Event) => {
|
|
326
|
-
this.onInput()
|
|
327
|
-
e.stopImmediatePropagation()
|
|
328
|
-
}}
|
|
329
|
-
@focus=${() => {
|
|
330
|
-
this.onFocus()
|
|
331
|
-
if (deviceDetection.isIOS()) {
|
|
332
|
-
this.showCalendar()
|
|
327
|
+
<pkt-datepicker-range
|
|
328
|
+
.value=${this._value}
|
|
329
|
+
.inputType=${this.inputType}
|
|
330
|
+
.id=${this.id}
|
|
331
|
+
.min=${this.min}
|
|
332
|
+
.max=${this.max}
|
|
333
|
+
.placeholder=${this.placeholder}
|
|
334
|
+
.readonly=${this.readonly}
|
|
335
|
+
.disabled=${this.disabled}
|
|
336
|
+
.showRangeLabels=${this.showRangeLabels}
|
|
337
|
+
.inputClasses=${this.inputClasses}
|
|
338
|
+
.internals=${this.internals}
|
|
339
|
+
.strings=${this.strings}
|
|
340
|
+
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
341
|
+
@input-change=${() => this.onInput()}
|
|
342
|
+
@input-focus=${() => this.onFocus()}
|
|
343
|
+
@input-blur=${(e: CustomEvent) => {
|
|
344
|
+
if (!this.calRef.value?.contains(e.detail.relatedTarget as Node)) {
|
|
345
|
+
this.onBlur()
|
|
333
346
|
}
|
|
334
347
|
}}
|
|
335
|
-
@blur=${(e:
|
|
348
|
+
@range-blur=${(e: CustomEvent) => {
|
|
336
349
|
dateProcessingUtils.processRangeBlur(
|
|
337
|
-
e,
|
|
338
|
-
|
|
350
|
+
e.detail.event,
|
|
351
|
+
e.detail.values,
|
|
339
352
|
this.calRef,
|
|
340
353
|
() => this.clearInputValue(),
|
|
341
354
|
(input) => this.manageValidity(input),
|
|
342
355
|
)
|
|
343
356
|
}}
|
|
344
|
-
@
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
${ref(this.inputRef)}
|
|
348
|
-
/>
|
|
349
|
-
<div class="${classMap(rangeLabelClasses)}" id="${this.id}-to-label">
|
|
350
|
-
${this.strings.generic.to}
|
|
351
|
-
</div>
|
|
352
|
-
${!this.showRangeLabels ? html` <div class="pkt-input-separator">–</div> ` : nothing}
|
|
353
|
-
<input
|
|
354
|
-
class=${classMap(this.inputClasses)}
|
|
355
|
-
.type=${this.inputType}
|
|
356
|
-
id="${this.id}-to"
|
|
357
|
-
aria-labelledby="${this.id}-to-label"
|
|
358
|
-
.value=${this._value[1] ?? ''}
|
|
359
|
-
min=${ifDefined(this.min)}
|
|
360
|
-
max=${ifDefined(this.max)}
|
|
361
|
-
placeholder=${ifDefined(this.placeholder)}
|
|
362
|
-
?readonly=${this.readonly}
|
|
363
|
-
?disabled=${this.disabled}
|
|
364
|
-
@click=${(e: MouseEvent) => {
|
|
365
|
-
e.preventDefault()
|
|
366
|
-
this.showCalendar()
|
|
357
|
+
@manage-validity=${(e: CustomEvent) => this.manageValidity(e.detail)}
|
|
358
|
+
@validate-date-input=${(e: CustomEvent) => {
|
|
359
|
+
formUtils.validateDateInput(e.detail, this.internals, this.min, this.max, this.strings)
|
|
367
360
|
}}
|
|
368
|
-
@
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
() =>
|
|
374
|
-
formUtils.submitFormOrFallback(this.internals, () => this.inputRefTo.value?.blur()),
|
|
375
|
-
undefined,
|
|
376
|
-
() => this.inputRefTo.value?.blur(),
|
|
377
|
-
)}
|
|
378
|
-
@input=${(e: Event) => {
|
|
379
|
-
this.onInput()
|
|
380
|
-
e.stopImmediatePropagation()
|
|
381
|
-
}}
|
|
382
|
-
@focus=${() => {
|
|
383
|
-
this.onFocus()
|
|
384
|
-
if (deviceDetection.isIOS()) {
|
|
385
|
-
this.showCalendar()
|
|
386
|
-
}
|
|
387
|
-
}}
|
|
388
|
-
@blur=${(e: FocusEvent) => {
|
|
389
|
-
if (!this.calRef.value?.contains(e.relatedTarget as Node)) {
|
|
390
|
-
this.onBlur()
|
|
391
|
-
}
|
|
392
|
-
if ((e.target as HTMLInputElement).value) {
|
|
393
|
-
this.manageValidity(e.target as HTMLInputElement)
|
|
394
|
-
formUtils.validateDateInput(
|
|
395
|
-
e.target as HTMLInputElement,
|
|
396
|
-
this.internals,
|
|
397
|
-
this.min,
|
|
398
|
-
this.max,
|
|
399
|
-
this.strings,
|
|
400
|
-
)
|
|
401
|
-
const date = fromISOToDate((e.target as HTMLInputElement).value)
|
|
402
|
-
if (date) {
|
|
403
|
-
if (this._value[1] !== formatISODate(date)) {
|
|
404
|
-
this.calRef?.value?.handleDateSelect(date)
|
|
405
|
-
}
|
|
361
|
+
@handle-date-select=${(e: CustomEvent) => {
|
|
362
|
+
const date = fromISOToDate(e.detail)
|
|
363
|
+
if (date) {
|
|
364
|
+
if (this._value[1] !== formatISODate(date)) {
|
|
365
|
+
this.calRef?.value?.handleDateSelect(date)
|
|
406
366
|
}
|
|
407
367
|
}
|
|
408
368
|
}}
|
|
409
|
-
@
|
|
369
|
+
@input-changed=${() => {
|
|
410
370
|
this.touched = true
|
|
411
|
-
e.stopImmediatePropagation()
|
|
412
371
|
}}
|
|
413
|
-
${ref(this.
|
|
414
|
-
|
|
372
|
+
${ref(this.rangeInputRef)}
|
|
373
|
+
></pkt-datepicker-range>
|
|
415
374
|
`
|
|
416
375
|
}
|
|
417
376
|
|
|
418
377
|
renderMultipleInput() {
|
|
419
378
|
return html`
|
|
420
|
-
<
|
|
421
|
-
|
|
422
|
-
.
|
|
423
|
-
id
|
|
424
|
-
min=${
|
|
425
|
-
max=${
|
|
426
|
-
placeholder=${
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
@
|
|
434
|
-
|
|
379
|
+
<pkt-datepicker-multiple
|
|
380
|
+
.value=${this._value}
|
|
381
|
+
.inputType=${this.inputType}
|
|
382
|
+
.id=${this.id}
|
|
383
|
+
.min=${this.min}
|
|
384
|
+
.max=${this.max}
|
|
385
|
+
.placeholder=${this.placeholder}
|
|
386
|
+
.readonly=${this.readonly}
|
|
387
|
+
.disabled=${this.disabled}
|
|
388
|
+
.maxlength=${this.maxlength}
|
|
389
|
+
.inputClasses=${this.inputClasses}
|
|
390
|
+
.internals=${this.internals}
|
|
391
|
+
.strings=${this.strings}
|
|
392
|
+
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
393
|
+
@input-change=${() => this.onInput()}
|
|
394
|
+
@input-focus=${() => this.onFocus()}
|
|
395
|
+
@input-blur=${(e: CustomEvent) => {
|
|
396
|
+
if (!this.calRef.value?.contains(e.detail.relatedTarget as Node)) {
|
|
435
397
|
this.onBlur()
|
|
436
398
|
}
|
|
437
|
-
this.addToSelected(e)
|
|
438
|
-
}}
|
|
439
|
-
@input=${(e: Event) => {
|
|
440
|
-
this.onInput()
|
|
441
|
-
e.stopImmediatePropagation()
|
|
442
|
-
}}
|
|
443
|
-
@focus=${() => {
|
|
444
|
-
this.onFocus()
|
|
445
|
-
if (deviceDetection.isIOS()) {
|
|
446
|
-
this.showCalendar()
|
|
447
|
-
}
|
|
448
399
|
}}
|
|
449
|
-
@
|
|
450
|
-
|
|
451
|
-
// event, toggleCalendar, submitForm, focusNext, blur, comma
|
|
452
|
-
e,
|
|
453
|
-
(event) => this.toggleCalendar(event),
|
|
454
|
-
() => formUtils.submitFormOrFallback(this.internals, () => this.inputRef.value?.blur()),
|
|
455
|
-
undefined,
|
|
456
|
-
undefined,
|
|
457
|
-
(event) => this.addToSelected(event),
|
|
458
|
-
)}
|
|
459
|
-
@change=${(e: Event) => {
|
|
400
|
+
@add-to-selected=${(e: CustomEvent) => this.addToSelected(e.detail)}
|
|
401
|
+
@input-changed=${() => {
|
|
460
402
|
this.touched = true
|
|
461
|
-
e.stopImmediatePropagation()
|
|
462
403
|
}}
|
|
463
|
-
${ref(this.
|
|
464
|
-
|
|
404
|
+
${ref(this.multipleInputRef)}
|
|
405
|
+
></pkt-datepicker-multiple>
|
|
465
406
|
`
|
|
466
407
|
}
|
|
467
408
|
|
|
@@ -510,8 +451,9 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
510
451
|
this.showRangeLabels,
|
|
511
452
|
this.multiple,
|
|
512
453
|
this.range,
|
|
454
|
+
this.readonly,
|
|
455
|
+
this.inputType,
|
|
513
456
|
)
|
|
514
|
-
this.buttonClasses = cssUtils.getButtonClasses()
|
|
515
457
|
|
|
516
458
|
return html`
|
|
517
459
|
<pkt-input-wrapper
|
|
@@ -561,25 +503,11 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
561
503
|
? 'pkt-input__range-inputs'
|
|
562
504
|
: ''}"
|
|
563
505
|
>
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
: this.renderInput()}
|
|
570
|
-
<button
|
|
571
|
-
class="${classMap(this.buttonClasses)}"
|
|
572
|
-
type="button"
|
|
573
|
-
@click=${this.toggleCalendar}
|
|
574
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
575
|
-
keyboardUtils.handleButtonKeydown(e, (event) => this.toggleCalendar(event))}
|
|
576
|
-
?disabled=${this.disabled}
|
|
577
|
-
${ref(this.btnRef)}
|
|
578
|
-
>
|
|
579
|
-
<pkt-icon name="calendar"></pkt-icon>
|
|
580
|
-
<span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
|
|
581
|
-
</button>
|
|
582
|
-
</div>
|
|
506
|
+
${this.range
|
|
507
|
+
? this.renderRangeInput()
|
|
508
|
+
: this.multiple
|
|
509
|
+
? this.renderMultipleInput()
|
|
510
|
+
: this.renderInput()}
|
|
583
511
|
</div>
|
|
584
512
|
</pkt-input-wrapper>
|
|
585
513
|
${this.renderCalendar()}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { PktDatepicker } from './datepicker'
|
|
2
|
-
|
|
2
|
+
import { PktDatepickerSingle } from './datepicker-single'
|
|
3
|
+
import { PktDatepickerRange } from './datepicker-range'
|
|
4
|
+
import { PktDatepickerMultiple } from './datepicker-multiple'
|
|
5
|
+
|
|
6
|
+
export { PktDatepicker, PktDatepickerSingle, PktDatepickerRange, PktDatepickerMultiple }
|
|
3
7
|
export default PktDatepicker
|
|
@@ -5,9 +5,13 @@ import { html, PropertyValues } from 'lit'
|
|
|
5
5
|
import { customElement, property } from 'lit/decorators.js'
|
|
6
6
|
import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
|
|
7
7
|
|
|
8
|
+
const defaultPath = 'https://punkt-cdn.oslo.kommune.no/latest/icons/'
|
|
9
|
+
|
|
8
10
|
// Allow global override of icon fetch
|
|
9
|
-
|
|
10
|
-
window.
|
|
11
|
+
if (typeof window !== 'undefined') {
|
|
12
|
+
window.pktFetch = window.pktFetch === undefined ? fetch : window.pktFetch
|
|
13
|
+
window.pktIconPath = window.pktIconPath || defaultPath
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
13
17
|
const errorSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"></svg>'
|
|
@@ -23,9 +27,14 @@ const downloadIconOrGetFromCache = async (
|
|
|
23
27
|
if (i > 50) break
|
|
24
28
|
await sleep(50)
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
// Check if localStorage is available before using it
|
|
32
|
+
const isLocalStorageAvailable =
|
|
33
|
+
typeof Storage !== 'undefined' && typeof localStorage !== 'undefined'
|
|
34
|
+
|
|
35
|
+
if (isLocalStorageAvailable && localStorage.getItem(path + name + '.svg')) {
|
|
27
36
|
return Promise.resolve(localStorage.getItem(path + name + '.svg'))
|
|
28
|
-
} else if (typeof window.pktFetch === 'function') {
|
|
37
|
+
} else if (typeof window !== 'undefined' && typeof window.pktFetch === 'function') {
|
|
29
38
|
dlStatus[path + name + '.svg'] = 'fetching'
|
|
30
39
|
return Promise.resolve(
|
|
31
40
|
window
|
|
@@ -40,7 +49,7 @@ const downloadIconOrGetFromCache = async (
|
|
|
40
49
|
}
|
|
41
50
|
})
|
|
42
51
|
.then((text) => {
|
|
43
|
-
if (text !== errorSvg) {
|
|
52
|
+
if (text !== errorSvg && isLocalStorageAvailable) {
|
|
44
53
|
localStorage.setItem(path + name + '.svg', text)
|
|
45
54
|
}
|
|
46
55
|
dlStatus[path + name + '.svg'] = 'fetched'
|
|
@@ -56,7 +65,7 @@ type Props = ElementProps<PktIcon, 'path' | 'name'>
|
|
|
56
65
|
@customElement('pkt-icon')
|
|
57
66
|
export class PktIcon extends PktElement<Props> {
|
|
58
67
|
@property({ type: String, reflect: false })
|
|
59
|
-
path: string | undefined = window.pktIconPath
|
|
68
|
+
path: string | undefined = typeof window !== 'undefined' ? window.pktIconPath : defaultPath
|
|
60
69
|
|
|
61
70
|
@property({ type: String, reflect: true })
|
|
62
71
|
name: PktIconName = ''
|
|
@@ -85,7 +94,7 @@ export class PktIcon extends PktElement<Props> {
|
|
|
85
94
|
|
|
86
95
|
protected async getIcon(name: PktIconName = '') {
|
|
87
96
|
if (this._updatedProps.length > 0) {
|
|
88
|
-
if (!this.path) this.path
|
|
97
|
+
if (!this.path) this.path = typeof window !== 'undefined' ? window.pktIconPath : defaultPath
|
|
89
98
|
this.icon = unsafeSVG(
|
|
90
99
|
await downloadIconOrGetFromCache(this.name || '', this.path).then((res) => res),
|
|
91
100
|
) as SVGElement
|
|
@@ -46,7 +46,7 @@ export class PktSelect extends PktInputElement implements IPktSelect {
|
|
|
46
46
|
@property({ type: Array, attribute: 'options' }) private _optionsProp: TSelectOption[] = []
|
|
47
47
|
@property({ type: String }) value: string = ''
|
|
48
48
|
|
|
49
|
-
@state()
|
|
49
|
+
@state() _options: TSelectOption[] = []
|
|
50
50
|
|
|
51
51
|
public selectedIndex: number | null = -1
|
|
52
52
|
public selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined = undefined
|