@oslokommune/punkt-elements 13.5.13 → 13.6.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 +17 -0
- package/dist/{calendar-CJSxvwAq.js → calendar-DJVaC_zI.js} +3 -3
- package/dist/datepicker-CA1a4oIH.cjs +169 -0
- package/dist/{datepicker-F3TwE9o7.js → datepicker-X2o0j5kW.js} +144 -107
- package/dist/index.d.ts +23 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +3 -3
- package/dist/pkt-index.cjs +3 -3
- package/dist/pkt-index.js +48 -47
- package/package.json +2 -2
- package/src/components/datepicker/date-tags.test.ts +126 -0
- package/src/components/datepicker/date-tags.ts +59 -0
- package/src/components/datepicker/datepicker.ts +13 -35
- package/src/components/index.ts +1 -0
- package/dist/datepicker-DonUad47.cjs +0 -164
package/dist/pkt-index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { P as A } from "./alert-cUBtwi2k.js";
|
|
2
|
-
import { P as
|
|
3
|
-
import { P as
|
|
4
|
-
import { P as
|
|
5
|
-
import { c as
|
|
6
|
-
import { P as
|
|
2
|
+
import { P as w, a as B } from "./accordionitem-C9T3nlM0.js";
|
|
3
|
+
import { P as E } from "./backlink-C2jbzu0U.js";
|
|
4
|
+
import { P as O } from "./button-DhispFOY.js";
|
|
5
|
+
import { c as d } from "./calendar-DJVaC_zI.js";
|
|
6
|
+
import { P as j } from "./calendar-DJVaC_zI.js";
|
|
7
7
|
import { P as G } from "./card-BDz4RWxK.js";
|
|
8
8
|
import { P as K } from "./combobox-BXP1PL0M.js";
|
|
9
9
|
import { P as U } from "./consent-BpcQFvbi.js";
|
|
10
10
|
import { P as q } from "./checkbox-ym7z6cpt.js";
|
|
11
|
-
import { P as
|
|
11
|
+
import { P as f, t as h, x as P, n, a as c } from "./element-CgEWt74-.js";
|
|
12
12
|
import { P as x } from "./pkt-slot-controller-BPGj-LC5.js";
|
|
13
|
-
import { e as m, n as
|
|
13
|
+
import { e as m, n as k } from "./ref-BBYSqgeW.js";
|
|
14
14
|
import { e as u } from "./class-map-BpTj9gtz.js";
|
|
15
|
-
import { P as F } from "./datepicker-
|
|
16
|
-
import { P as
|
|
17
|
-
import { P as
|
|
18
|
-
import { P as
|
|
19
|
-
import { P as
|
|
20
|
-
import { P as
|
|
21
|
-
import { P as
|
|
22
|
-
import { P as
|
|
23
|
-
import { P as
|
|
24
|
-
import { P as
|
|
15
|
+
import { P as F, a as J } from "./datepicker-X2o0j5kW.js";
|
|
16
|
+
import { P as V } from "./helptext-B7eI0iBQ.js";
|
|
17
|
+
import { P as Y } from "./heading-Bdh9absf.js";
|
|
18
|
+
import { P as tt } from "./icon-CC1js8eR.js";
|
|
19
|
+
import { P as rt } from "./input-wrapper-Dr__Sxql.js";
|
|
20
|
+
import { P as st } from "./link-AIyVfcyH.js";
|
|
21
|
+
import { P as nt } from "./linkcard-9CNlyT0S.js";
|
|
22
|
+
import { P as pt } from "./loader-h3d-3D7s.js";
|
|
23
|
+
import { P as Pt } from "./messagebox-C8KQgCl_.js";
|
|
24
|
+
import { P as kt } from "./modal-Zj8yRX3K.js";
|
|
25
25
|
import { P as ft } from "./progressbar-Dj_mI_A6.js";
|
|
26
|
-
import { P as
|
|
27
|
-
import { P as
|
|
28
|
-
import { P as
|
|
29
|
-
import { P as
|
|
30
|
-
import { P as
|
|
26
|
+
import { P as ct, P as xt } from "./radiobutton-CWxiIVfA.js";
|
|
27
|
+
import { P as gt } from "./tag-DyXzTY68.js";
|
|
28
|
+
import { P as St } from "./textarea-BZL8Mkm0.js";
|
|
29
|
+
import { P as Ct } from "./textinput-DjPhmmkB.js";
|
|
30
|
+
import { P as yt } from "./select-VpX_cjMM.js";
|
|
31
31
|
var g = Object.defineProperty, v = Object.getOwnPropertyDescriptor, s = (t, e, i, a) => {
|
|
32
32
|
for (var r = a > 1 ? void 0 : a ? v(e, i) : e, p = t.length - 1, l; p >= 0; p--)
|
|
33
33
|
(l = t[p]) && (r = (a ? l(e, i, r) : l(r)) || r);
|
|
34
34
|
return a && r && g(e, i, r), r;
|
|
35
35
|
};
|
|
36
|
-
let o = class extends
|
|
36
|
+
let o = class extends f {
|
|
37
37
|
constructor() {
|
|
38
38
|
super(), this.string = "", this.strings = [], this.darkmode = !1, this._list = [], this.defaultSlot = m(), this.namedSlot = m(), this.slotController = new x(this, this.defaultSlot, this.namedSlot);
|
|
39
39
|
}
|
|
@@ -63,11 +63,11 @@ let o = class extends k {
|
|
|
63
63
|
<div>${this.renderList(this.doStuff(this._list))}</div>
|
|
64
64
|
|
|
65
65
|
<h2 class="pkt-txt-22">Slot</h2>
|
|
66
|
-
<div ${
|
|
66
|
+
<div ${k(this.defaultSlot)}>defaultSlotRef</div>
|
|
67
67
|
<h2 class="pkt-txt-22">Named slot</h2>
|
|
68
68
|
<select
|
|
69
69
|
name="named-slot"
|
|
70
|
-
${
|
|
70
|
+
${k(this.namedSlot)}
|
|
71
71
|
@change=${(e) => alert(e.target.value)}
|
|
72
72
|
>
|
|
73
73
|
namedSlotRef
|
|
@@ -108,7 +108,7 @@ s([
|
|
|
108
108
|
n({ type: String })
|
|
109
109
|
], o.prototype, "string", 2);
|
|
110
110
|
s([
|
|
111
|
-
n({ converter:
|
|
111
|
+
n({ converter: d })
|
|
112
112
|
], o.prototype, "strings", 2);
|
|
113
113
|
s([
|
|
114
114
|
n({ type: Boolean })
|
|
@@ -120,32 +120,33 @@ o = s([
|
|
|
120
120
|
c("pkt-component")
|
|
121
121
|
], o);
|
|
122
122
|
export {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
w as PktAccordion,
|
|
124
|
+
B as PktAccordionItem,
|
|
125
125
|
A as PktAlert,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
E as PktBackLink,
|
|
127
|
+
O as PktButton,
|
|
128
|
+
j as PktCalendar,
|
|
129
129
|
G as PktCard,
|
|
130
130
|
q as PktCheckbox,
|
|
131
131
|
K as PktCombobox,
|
|
132
132
|
o as PktComponent,
|
|
133
133
|
U as PktConsent,
|
|
134
|
-
F as
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
F as PktDateTags,
|
|
135
|
+
J as PktDatepicker,
|
|
136
|
+
Y as PktHeading,
|
|
137
|
+
V as PktHelptext,
|
|
138
|
+
tt as PktIcon,
|
|
139
|
+
rt as PktInputWrapper,
|
|
140
|
+
st as PktLink,
|
|
141
|
+
nt as PktLinkCard,
|
|
142
|
+
pt as PktLoader,
|
|
143
|
+
Pt as PktMessagebox,
|
|
144
|
+
kt as PktModal,
|
|
144
145
|
ft as PktProgressbar,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
ct as PktRadioButton,
|
|
147
|
+
xt as PktRadiobutton,
|
|
148
|
+
yt as PktSelect,
|
|
149
|
+
gt as PktTag,
|
|
150
|
+
St as PktTextarea,
|
|
151
|
+
Ct as PktTextinput
|
|
151
152
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.6.0",
|
|
4
4
|
"description": "Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
74
74
|
},
|
|
75
75
|
"license": "MIT",
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "02be3699565d6e962bf2a28742428505c2922363"
|
|
77
77
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import { axe, toHaveNoViolations } from 'jest-axe'
|
|
3
|
+
import { vi } from 'vitest'
|
|
4
|
+
import { createElementTest, BaseTestConfig } from '../../tests/test-framework'
|
|
5
|
+
import './date-tags'
|
|
6
|
+
import { PktDateTags } from './date-tags'
|
|
7
|
+
|
|
8
|
+
expect.extend(toHaveNoViolations)
|
|
9
|
+
|
|
10
|
+
export interface IDateTagsTest extends BaseTestConfig {
|
|
11
|
+
dates?: string[]
|
|
12
|
+
idBase?: string
|
|
13
|
+
className?: string
|
|
14
|
+
dateformat?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const createDateTagsTest = async (config: IDateTagsTest = {}) => {
|
|
18
|
+
const { container, element } = await createElementTest('pkt-date-tags' as any, config)
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
container,
|
|
22
|
+
dateTags: element as PktDateTags,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
document.body.innerHTML = ''
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
describe('PktDateTags', () => {
|
|
31
|
+
test('renders nothing when no dates provided', async () => {
|
|
32
|
+
const { dateTags } = await createDateTagsTest()
|
|
33
|
+
await dateTags.updateComplete
|
|
34
|
+
|
|
35
|
+
expect(dateTags.querySelectorAll('time').length).toBe(0)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('renders provided ISO dates and formats them', async () => {
|
|
39
|
+
const iso = '2025-09-17'
|
|
40
|
+
const { dateTags } = await createDateTagsTest()
|
|
41
|
+
|
|
42
|
+
dateTags.dates = [iso]
|
|
43
|
+
dateTags.idBase = 'base-'
|
|
44
|
+
await dateTags.updateComplete
|
|
45
|
+
|
|
46
|
+
const time = dateTags.querySelector('time')
|
|
47
|
+
expect(time).toBeTruthy()
|
|
48
|
+
expect(time?.getAttribute('datetime')).toBe(iso)
|
|
49
|
+
|
|
50
|
+
expect(time?.textContent?.trim()).toBe('17.09.2025')
|
|
51
|
+
|
|
52
|
+
const tag = dateTags.querySelector('pkt-tag')
|
|
53
|
+
expect(tag).toBeTruthy()
|
|
54
|
+
expect(tag?.id).toBe(`base-${iso}-tag`)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('applies custom unicode-style dateformat', async () => {
|
|
58
|
+
const iso = '2025-09-17'
|
|
59
|
+
const { dateTags } = await createDateTagsTest()
|
|
60
|
+
|
|
61
|
+
dateTags.dates = [iso]
|
|
62
|
+
dateTags.dateformat = 'yyyy/MM/dd'
|
|
63
|
+
await dateTags.updateComplete
|
|
64
|
+
|
|
65
|
+
const time = dateTags.querySelector('time')
|
|
66
|
+
expect(time).toBeTruthy()
|
|
67
|
+
expect(time?.textContent?.trim()).toBe('2025/09/17')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('normalizes overflow ISO dates (e.g. 2025-02-30 -> 02.03.2025)', async () => {
|
|
71
|
+
const iso = '2025-02-30'
|
|
72
|
+
const { dateTags } = await createDateTagsTest()
|
|
73
|
+
|
|
74
|
+
dateTags.dates = [iso]
|
|
75
|
+
await dateTags.updateComplete
|
|
76
|
+
|
|
77
|
+
const time = dateTags.querySelector('time')
|
|
78
|
+
expect(time).toBeTruthy()
|
|
79
|
+
|
|
80
|
+
// JS Date normalizes invalid dates; 2025-02-30 becomes 02.03.2025
|
|
81
|
+
expect(time?.textContent?.trim()).toBe('02.03.2025')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('Moment-style tokens (DD.MM.YYYY) do not match date-fns tokens', async () => {
|
|
85
|
+
const iso = '2025-09-17'
|
|
86
|
+
const { dateTags } = await createDateTagsTest()
|
|
87
|
+
|
|
88
|
+
// Moment-style tokens are uppercase; date-fns expects lowercase (yyyy, dd)
|
|
89
|
+
dateTags.dates = [iso]
|
|
90
|
+
dateTags.dateformat = 'DD.MM.YYYY'
|
|
91
|
+
|
|
92
|
+
const spyWarn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
93
|
+
try {
|
|
94
|
+
await expect(dateTags.updateComplete).rejects.toThrow(/Use `dd` instead of `DD`/)
|
|
95
|
+
} finally {
|
|
96
|
+
spyWarn.mockRestore()
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('emits date-tag-removed when child pkt-tag dispatches close', async () => {
|
|
101
|
+
const iso = '2025-09-17'
|
|
102
|
+
const { dateTags } = await createDateTagsTest()
|
|
103
|
+
dateTags.dates = [iso]
|
|
104
|
+
await dateTags.updateComplete
|
|
105
|
+
|
|
106
|
+
const handler = vi.fn()
|
|
107
|
+
dateTags.addEventListener('date-tag-removed', (e: any) => handler(e.detail))
|
|
108
|
+
|
|
109
|
+
const tag = dateTags.querySelector('pkt-tag')
|
|
110
|
+
expect(tag).toBeTruthy()
|
|
111
|
+
|
|
112
|
+
// Simulate close event on child tag
|
|
113
|
+
tag?.dispatchEvent(new CustomEvent('close', { bubbles: true, composed: true }))
|
|
114
|
+
|
|
115
|
+
expect(handler).toHaveBeenCalledWith(iso)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('is accessible (WCAG) with dates', async () => {
|
|
119
|
+
const iso = '2025-09-17'
|
|
120
|
+
const { container } = await createDateTagsTest({ dates: [iso] })
|
|
121
|
+
|
|
122
|
+
// Run axe on the rendered container
|
|
123
|
+
const results = await axe(container)
|
|
124
|
+
expect(results).toHaveNoViolations()
|
|
125
|
+
})
|
|
126
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { PktElement } from '@/base-elements/element'
|
|
2
|
+
import { html, nothing } from 'lit'
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
4
|
+
import { classMap } from 'lit/directives/class-map.js'
|
|
5
|
+
import { repeat } from 'lit/directives/repeat.js'
|
|
6
|
+
|
|
7
|
+
import '@/components/tag'
|
|
8
|
+
import { fromISOtoLocal } from '@/utils/dateutils'
|
|
9
|
+
import { uuidish } from '@/utils/stringutils'
|
|
10
|
+
|
|
11
|
+
type TYear = `${number}${number}${number}${number}`
|
|
12
|
+
type TMonth = `${number}${number}`
|
|
13
|
+
type TDay = `${number}${number}`
|
|
14
|
+
export type TISODate = `${TYear}-${TMonth}-${TDay}`
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* OBS! `dateformat` er standard formatteringsstreng for visning av datoer.
|
|
18
|
+
* Denne brukes for å sette "menneskeleselig" format på datoene i tags.
|
|
19
|
+
*
|
|
20
|
+
* Følger denne unicode-standarden:
|
|
21
|
+
* https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
@customElement('pkt-date-tags')
|
|
25
|
+
export class PktDateTags extends PktElement {
|
|
26
|
+
@property({ type: Array }) dates: TISODate[] = []
|
|
27
|
+
@property({ type: String }) dateformat: string = 'dd.MM.yyyy' // se kommentar over
|
|
28
|
+
@property({ type: String, attribute: 'class' }) className: string = 'pkt-datepicker__tags'
|
|
29
|
+
@property({ type: String, attribute: 'id-base' }) idBase: string = uuidish()
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
this.classes = {
|
|
33
|
+
'pkt-date-tags': true,
|
|
34
|
+
[this.className]: true,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return html`
|
|
38
|
+
<div class=${classMap(this.classes)} aria-live="polite">
|
|
39
|
+
${Array.isArray(this.dates) && !!this.dates[0]
|
|
40
|
+
? repeat(
|
|
41
|
+
(this.dates ?? []).filter(Boolean).sort(),
|
|
42
|
+
(date) => date,
|
|
43
|
+
(date) =>
|
|
44
|
+
html` <pkt-tag
|
|
45
|
+
id=${this.idBase + date + '-tag'}
|
|
46
|
+
closeTag
|
|
47
|
+
@close=${() => {
|
|
48
|
+
this.dispatchEvent(new CustomEvent('date-tag-removed', { detail: date }))
|
|
49
|
+
}}
|
|
50
|
+
.ariaLabel=${`${this.strings?.calendar.deleteDate} ${fromISOtoLocal(date, this.dateformat)}`}
|
|
51
|
+
>
|
|
52
|
+
<time datetime=${date}>${fromISOtoLocal(date, this.dateformat)}</time>
|
|
53
|
+
</pkt-tag>`,
|
|
54
|
+
)
|
|
55
|
+
: nothing}
|
|
56
|
+
</div>
|
|
57
|
+
`
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { classMap } from 'lit/directives/class-map.js'
|
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js'
|
|
3
3
|
import { customElement, property, state } from 'lit/decorators.js'
|
|
4
|
-
import {
|
|
5
|
-
formatISODate,
|
|
6
|
-
fromISOToDate,
|
|
7
|
-
fromISOtoLocal,
|
|
8
|
-
newDate,
|
|
9
|
-
parseISODateString,
|
|
10
|
-
} from '@/utils/dateutils'
|
|
4
|
+
import { formatISODate, fromISOToDate, newDate, parseISODateString } from '@/utils/dateutils'
|
|
11
5
|
import { html, nothing, PropertyValues } from 'lit'
|
|
12
6
|
import { PktCalendar } from '@/components/calendar/calendar'
|
|
13
7
|
import { PktInputElement } from '@/base-elements/input-element'
|
|
14
8
|
import { Ref, createRef, ref } from 'lit/directives/ref.js'
|
|
15
|
-
import { repeat } from 'lit/directives/repeat.js'
|
|
16
9
|
import converters from '@/helpers/converters'
|
|
17
10
|
import specs from 'componentSpecs/datepicker.json'
|
|
18
11
|
import '@/components/calendar'
|
|
19
12
|
import '@/components/icon'
|
|
20
13
|
import '@/components/input-wrapper'
|
|
21
|
-
import '
|
|
14
|
+
import './date-tags'
|
|
22
15
|
import { PktSlotController } from '@/controllers/pkt-slot-controller'
|
|
23
16
|
|
|
24
17
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
@@ -527,31 +520,6 @@ export class PktDatepicker extends PktInputElement {
|
|
|
527
520
|
`
|
|
528
521
|
}
|
|
529
522
|
|
|
530
|
-
renderTags() {
|
|
531
|
-
return html`
|
|
532
|
-
<div class="pkt-datepicker__tags" aria-live="polite">
|
|
533
|
-
${!!this._value[0]
|
|
534
|
-
? repeat(
|
|
535
|
-
(this._value ?? []).filter(Boolean).sort(),
|
|
536
|
-
(date) => date,
|
|
537
|
-
(date) => html`
|
|
538
|
-
<pkt-tag
|
|
539
|
-
.id="${this.id + date + '-tag'}"
|
|
540
|
-
closeTag
|
|
541
|
-
ariaLabel="${this.strings.calendar.deleteDate} ${fromISOtoLocal(
|
|
542
|
-
date,
|
|
543
|
-
this.dateformat,
|
|
544
|
-
)}"
|
|
545
|
-
@close=${() => this.calRef.value?.handleDateSelect(fromISOToDate(date))}
|
|
546
|
-
><time datetime="${date}">${fromISOtoLocal(date, this.dateformat)}</time></pkt-tag
|
|
547
|
-
>
|
|
548
|
-
`,
|
|
549
|
-
)
|
|
550
|
-
: nothing}
|
|
551
|
-
</div>
|
|
552
|
-
`
|
|
553
|
-
}
|
|
554
|
-
|
|
555
523
|
renderCalendar() {
|
|
556
524
|
return html`<div
|
|
557
525
|
class="pkt-calendar-popup pkt-${this.calendarOpen ? 'show' : 'hide'}"
|
|
@@ -651,7 +619,17 @@ export class PktDatepicker extends PktInputElement {
|
|
|
651
619
|
class="pkt-datepicker"
|
|
652
620
|
>
|
|
653
621
|
<div class="pkt-contents" ${ref(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
654
|
-
${this.multiple
|
|
622
|
+
${this.multiple
|
|
623
|
+
? html`<pkt-date-tags
|
|
624
|
+
.dates=${this._value}
|
|
625
|
+
dateformat=${this.dateformat}
|
|
626
|
+
strings=${this.strings}
|
|
627
|
+
id-base=${this.id}
|
|
628
|
+
@date-tag-removed=${(e: CustomEvent) => {
|
|
629
|
+
this.calRef.value?.handleDateSelect(fromISOToDate(e.detail))
|
|
630
|
+
}}
|
|
631
|
+
></pkt-date-tags>`
|
|
632
|
+
: nothing}
|
|
655
633
|
<div
|
|
656
634
|
class="pkt-datepicker__inputs ${this.range && this.showRangeLabels
|
|
657
635
|
? 'pkt-input__range-inputs'
|
package/src/components/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { PktCombobox } from './combobox'
|
|
|
9
9
|
export { PktConsent } from './consent'
|
|
10
10
|
export { PktCheckbox } from '@/components/checkbox'
|
|
11
11
|
export { PktComponent } from '../base-elements/component-template.js'
|
|
12
|
+
export { PktDateTags } from '@/components/datepicker/date-tags.js'
|
|
12
13
|
export { PktDatepicker } from '@/components/datepicker/datepicker.js'
|
|
13
14
|
export { PktHelptext } from '@/components/helptext'
|
|
14
15
|
export { PktHeading } from '@/components/heading'
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";const d=require("./class-map-BBG2gMX4.cjs"),h=require("./if-defined-Cni-RHLS.cjs"),s=require("./element-6DBpyGQm.cjs"),v=require("./state-DPobt-Yz.cjs"),o=require("./calendar-32W9p9uc.cjs"),m=require("./input-element-C4xJoM-X.cjs"),r=require("./ref-iJtiv3o2.cjs"),y=require("./repeat-CDsZqct8.cjs");require("./icon-B_ryAy4Q.cjs");require("./input-wrapper-CZ-a00V7.cjs");require("./tag-Bbs0U_Au.cjs");const k=require("./pkt-slot-controller-BzddBp7z.cjs"),$={dateformat:{default:"dd.MM.yyyy"},min:{default:null},max:{default:null},weeknumbers:{default:!1},withcontrols:{default:!1},multiple:{default:!1},range:{default:!1}},p={props:$};var b=Object.defineProperty,x=Object.getOwnPropertyDescriptor,n=(c,t,e,i)=>{for(var a=i>1?void 0:i?x(t,e):t,l=c.length-1,u;l>=0;l--)(u=c[l])&&(a=(i?u(t,e,a):u(a))||a);return i&&a&&b(t,e,a),a};const g=c=>new Promise(t=>setTimeout(t,c));exports.PktDatepicker=class extends m.PktInputElement{constructor(){super(),this._valueProperty="",this._value=[],this.label="Datovelger",this.dateformat=p.props.dateformat.default,this.multiple=p.props.multiple.default,this.maxlength=null,this.range=p.props.range.default,this.showRangeLabels=!1,this.min=null,this.max=null,this.weeknumbers=p.props.weeknumbers.default,this.withcontrols=p.props.withcontrols.default,this.excludedates=[],this.excludeweekdays=[],this.currentmonth=null,this.calendarOpen=!1,this.timezone="Europe/Oslo",this.inputClasses={},this.buttonClasses={},this.inputRef=r.e(),this.inputRefTo=r.e(),this.btnRef=r.e(),this.calRef=r.e(),this.popupRef=r.e(),this.helptextSlot=r.e(),this.addToSelected=t=>{const e=t.target;if(!e.value)return;const i=this.min?o.newDate(this.min):null,a=this.max?o.newDate(this.max):null,l=o.newDate(e.value.split(",")[0]);l&&!isNaN(l.getTime())&&(!i||l>=i)&&(!a||l<=a)&&this.calRef.value&&this.calRef.value.handleDateSelect(l),e.value=""},this.slotController=new k.PktSlotController(this,this.helptextSlot)}get value(){return this._valueProperty}set value(t){const e=this._valueProperty;this._valueProperty=Array.isArray(t)?t.join(","):t||"",this.valueChanged(this._valueProperty,e),this.requestUpdate("value",e)}async connectedCallback(){super.connectedCallback();const t=navigator.userAgent,e=/iP(hone|od|ad)/.test(t);this.inputType=e?"text":"date",document&&document.body.addEventListener("click",i=>{var a,l;(a=this.inputRef)!=null&&a.value&&((l=this.btnRef)!=null&&l.value)&&!this.inputRef.value.contains(i.target)&&!(this.inputRefTo.value&&this.inputRefTo.value.contains(i.target))&&!this.btnRef.value.contains(i.target)&&!i.target.closest(".pkt-calendar-popup")&&this.calendarOpen&&(this.onBlur(),this.hideCalendar())}),document&&document.body.addEventListener("keydown",i=>{i.key==="Escape"&&this.calendarOpen&&this.hideCalendar()}),this.value&&(this._value=Array.isArray(this.value)?this.value.filter(Boolean):this.value.split(",").filter(Boolean)),this.min=this.min||p.props.min.default,this.max=this.max||p.props.max.default,typeof this.excludedates=="string"&&(this.excludedates=this.excludedates.split(",")),typeof this.excludeweekdays=="string"&&(this.excludeweekdays=this.excludeweekdays.split(",")),(this.multiple||this.range)&&this.name&&!this.name.endsWith("[]")&&(this.name=this.name+"[]"),this.calendarOpen&&(await g(20),this.handleCalendarPosition())}disconnectedCallback(){super.disconnectedCallback(),document&&document.body.removeEventListener("click",t=>{var e,i;(e=this.inputRef)!=null&&e.value&&((i=this.btnRef)!=null&&i.value)&&!this.inputRef.value.contains(t.target)&&!this.btnRef.value.contains(t.target)&&this.hideCalendar()})}onInput(){this.dispatchEvent(new Event("input",{bubbles:!0}))}valueChanged(t,e){if(t===e)return;let i=[];t&&(typeof t=="string"?i=t.split(",").filter(Boolean):i=String(t).split(",").filter(Boolean)),this._value=i;const a=i.join(",");this._valueProperty!==a&&(this._valueProperty=a),super.valueChanged(a,e)}attributeChangedCallback(t,e,i){t==="value"&&this.value!==e&&this.valueChanged(i,e),t==="excludedates"&&typeof this.excludedates=="string"&&(this.excludedates=(i==null?void 0:i.split(","))??[]),t==="excludeweekdays"&&typeof this.excludeweekdays=="string"&&(this.excludeweekdays=(i==null?void 0:i.split(","))??[]),super.attributeChangedCallback(t,e,i)}updated(t){if(t.has("value")){const e=Array.isArray(this.value)?this.value.join(","):this.value,i=t.get("value"),a=Array.isArray(i)?i.join(","):i;this.valueChanged(e,a)}t.has("multiple")&&(this.multiple&&!Array.isArray(this._value)?this._value=typeof this.value=="string"?this.value?this.value.split(",").filter(Boolean):[]:[]:!this.multiple&&Array.isArray(this._value)&&(this._value=this._value.filter(Boolean)),!this.multiple&&!this.range&&Array.isArray(this._value)&&(this._value=[this._value[0]??""])),super.updated(t)}renderInput(){return s.x`
|
|
2
|
-
<input
|
|
3
|
-
class="${d.e(this.inputClasses)}"
|
|
4
|
-
.type=${this.inputType}
|
|
5
|
-
id="${this.id}-input"
|
|
6
|
-
.value=${this._value[0]??""}
|
|
7
|
-
min=${h.o(this.min)}
|
|
8
|
-
max=${h.o(this.max)}
|
|
9
|
-
placeholder=${h.o(this.placeholder)}
|
|
10
|
-
?readonly=${this.readonly}
|
|
11
|
-
aria-describedby="${this.id}-helptext"
|
|
12
|
-
@click=${t=>{t.preventDefault(),this.showCalendar()}}
|
|
13
|
-
?disabled=${this.disabled}
|
|
14
|
-
@keydown=${t=>{var e,i;if(t.key===","&&((e=this.inputRef.value)==null||e.blur()),(t.key==="Space"||t.key===" ")&&(t.preventDefault(),this.toggleCalendar(t)),t.key==="Enter"){const a=this.internals.form;a?a.requestSubmit():(i=this.inputRef.value)==null||i.blur()}}}
|
|
15
|
-
@input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
|
|
16
|
-
@focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
|
|
17
|
-
@blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.manageValidity(t.target),this.value=t.target.value}}
|
|
18
|
-
@change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
|
|
19
|
-
${r.n(this.inputRef)}
|
|
20
|
-
/>
|
|
21
|
-
`}renderRangeInput(){const t={"pkt-input-prefix":this.showRangeLabels,"pkt-hide":!this.showRangeLabels};return s.x`
|
|
22
|
-
${this.showRangeLabels?s.x` <div class="pkt-input-prefix">${this.strings.generic.from}</div> `:s.E}
|
|
23
|
-
<input
|
|
24
|
-
class=${d.e(this.inputClasses)}
|
|
25
|
-
.type=${this.inputType}
|
|
26
|
-
id="${this.id}-input"
|
|
27
|
-
.value=${this._value[0]??""}
|
|
28
|
-
min=${h.o(this.min)}
|
|
29
|
-
max=${h.o(this.max)}
|
|
30
|
-
placeholder=${h.o(this.placeholder)}
|
|
31
|
-
?readonly=${this.readonly}
|
|
32
|
-
?disabled=${this.disabled}
|
|
33
|
-
@click=${e=>{e.preventDefault(),this.showCalendar()}}
|
|
34
|
-
@keydown=${e=>{var i,a;if(e.key===","&&((i=this.inputRef.value)==null||i.blur()),(e.key==="Space"||e.key===" ")&&(e.preventDefault(),this.toggleCalendar(e)),e.key==="Enter"){const l=this.internals.form;l?l.requestSubmit():(a=this.inputRefTo.value)==null||a.focus()}}}
|
|
35
|
-
@input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
|
|
36
|
-
@focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
|
|
37
|
-
@blur=${e=>{var i,a;if(e.target.value){this.manageValidity(e.target);const l=o.fromISOToDate(e.target.value);l&&this._value[0]!==e.target.value&&this._value[1]&&(this.clearInputValue(),(a=(i=this.calRef)==null?void 0:i.value)==null||a.handleDateSelect(l))}else this._value[0]&&this.clearInputValue()}}
|
|
38
|
-
@change=${e=>{e.stopImmediatePropagation()}}
|
|
39
|
-
${r.n(this.inputRef)}
|
|
40
|
-
/>
|
|
41
|
-
<div class="${d.e(t)}" id="${this.id}-to-label">
|
|
42
|
-
${this.strings.generic.to}
|
|
43
|
-
</div>
|
|
44
|
-
${this.showRangeLabels?s.E:s.x` <div class="pkt-input-separator">–</div> `}
|
|
45
|
-
<input
|
|
46
|
-
class=${d.e(this.inputClasses)}
|
|
47
|
-
.type=${this.inputType}
|
|
48
|
-
id="${this.id}-to"
|
|
49
|
-
aria-labelledby="${this.id}-to-label"
|
|
50
|
-
.value=${this._value[1]??""}
|
|
51
|
-
min=${h.o(this.min)}
|
|
52
|
-
max=${h.o(this.max)}
|
|
53
|
-
placeholder=${h.o(this.placeholder)}
|
|
54
|
-
?readonly=${this.readonly}
|
|
55
|
-
?disabled=${this.disabled}
|
|
56
|
-
@click=${e=>{e.preventDefault(),this.showCalendar()}}
|
|
57
|
-
@keydown=${e=>{var i,a;if(e.key===","&&((i=this.inputRefTo.value)==null||i.blur()),(e.key==="Space"||e.key===" ")&&(e.preventDefault(),this.toggleCalendar(e)),e.key==="Enter"){const l=this.internals.form;l?l.requestSubmit():(a=this.inputRefTo.value)==null||a.blur()}}}
|
|
58
|
-
@input=${e=>{this.onInput(),e.stopImmediatePropagation()}}
|
|
59
|
-
@focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
|
|
60
|
-
@blur=${e=>{var i,a,l;if((i=this.calRef.value)!=null&&i.contains(e.relatedTarget)||this.onBlur(),e.target.value){this.manageValidity(e.target);const u=e.target.value;this.min&&this.min>u?this.internals.setValidity({rangeUnderflow:!0},this.strings.forms.messages.rangeUnderflow,e.target):this.max&&this.max<u&&this.internals.setValidity({rangeOverflow:!0},this.strings.forms.messages.rangeOverflow,e.target);const f=o.fromISOToDate(e.target.value);f&&this._value[1]!==o.formatISODate(f)&&((l=(a=this.calRef)==null?void 0:a.value)==null||l.handleDateSelect(f))}}}
|
|
61
|
-
@change=${e=>{this.touched=!0,e.stopImmediatePropagation()}}
|
|
62
|
-
${r.n(this.inputRefTo)}
|
|
63
|
-
/>
|
|
64
|
-
`}renderMultipleInput(){return s.x`
|
|
65
|
-
<input
|
|
66
|
-
class=${d.e(this.inputClasses)}
|
|
67
|
-
.type=${this.inputType}
|
|
68
|
-
id="${this.id}-input"
|
|
69
|
-
min=${h.o(this.min)}
|
|
70
|
-
max=${h.o(this.max)}
|
|
71
|
-
placeholder=${h.o(this.placeholder)}
|
|
72
|
-
?readonly=${this.readonly}
|
|
73
|
-
?disabled=${this.disabled||this.maxlength&&this._value.length>=this.maxlength}
|
|
74
|
-
@click=${t=>{t.preventDefault(),this.showCalendar()}}
|
|
75
|
-
@blur=${t=>{var e;(e=this.calRef.value)!=null&&e.contains(t.relatedTarget)||this.onBlur(),this.addToSelected(t)}}
|
|
76
|
-
@input=${t=>{this.onInput(),t.stopImmediatePropagation()}}
|
|
77
|
-
@focus=${()=>{this.onFocus(),this.isMobileSafari&&this.showCalendar()}}
|
|
78
|
-
@keydown=${t=>{var e;if(t.key===","&&(t.preventDefault(),this.addToSelected(t)),(t.key==="Space"||t.key===" ")&&(t.preventDefault(),this.toggleCalendar(t)),t.key==="Enter"){const i=this.internals.form;i?i.requestSubmit():(e=this.inputRef.value)==null||e.blur()}}}
|
|
79
|
-
@change=${t=>{this.touched=!0,t.stopImmediatePropagation()}}
|
|
80
|
-
${r.n(this.inputRef)}
|
|
81
|
-
/>
|
|
82
|
-
`}renderTags(){return s.x`
|
|
83
|
-
<div class="pkt-datepicker__tags" aria-live="polite">
|
|
84
|
-
${this._value[0]?y.c((this._value??[]).filter(Boolean).sort(),t=>t,t=>s.x`
|
|
85
|
-
<pkt-tag
|
|
86
|
-
.id="${this.id+t+"-tag"}"
|
|
87
|
-
closeTag
|
|
88
|
-
ariaLabel="${this.strings.calendar.deleteDate} ${o.fromISOtoLocal(t,this.dateformat)}"
|
|
89
|
-
@close=${()=>{var e;return(e=this.calRef.value)==null?void 0:e.handleDateSelect(o.fromISOToDate(t))}}
|
|
90
|
-
><time datetime="${t}">${o.fromISOtoLocal(t,this.dateformat)}</time></pkt-tag
|
|
91
|
-
>
|
|
92
|
-
`):s.E}
|
|
93
|
-
</div>
|
|
94
|
-
`}renderCalendar(){return s.x`<div
|
|
95
|
-
class="pkt-calendar-popup pkt-${this.calendarOpen?"show":"hide"}"
|
|
96
|
-
@focusout=${t=>{this.calendarOpen&&this.handleFocusOut(t)}}
|
|
97
|
-
id="${this.id}-popup"
|
|
98
|
-
${r.n(this.popupRef)}
|
|
99
|
-
>
|
|
100
|
-
<pkt-calendar
|
|
101
|
-
id="${this.id}-calendar"
|
|
102
|
-
?multiple=${this.multiple}
|
|
103
|
-
?range=${this.range}
|
|
104
|
-
?weeknumbers=${this.weeknumbers}
|
|
105
|
-
?withcontrols=${this.withcontrols}
|
|
106
|
-
.maxMultiple=${this.maxlength}
|
|
107
|
-
.selected=${this._value}
|
|
108
|
-
.earliest=${this.min}
|
|
109
|
-
.latest=${this.max}
|
|
110
|
-
.excludedates=${Array.isArray(this.excludedates)?this.excludedates:this.excludedates.split(",")}
|
|
111
|
-
.excludeweekdays=${this.excludeweekdays}
|
|
112
|
-
.currentmonth=${this.currentmonth?o.parseISODateString(this.currentmonth):null}
|
|
113
|
-
@date-selected=${t=>{this.value=!this.multiple&&!this.range?t.detail[0]:Array.isArray(t.detail)?t.detail.join(","):t.detail,this._value=t.detail,this.inputRef.value&&(this.range&&this.inputRefTo.value?(this.inputRef.value.value=this._value[0]??"",this.inputRefTo.value.value=this._value[1]??"",this.manageValidity(this.inputRef.value),this.manageValidity(this.inputRefTo.value)):this.multiple||(this.inputRef.value.value=this._value.length?this._value[0]:"",this.manageValidity(this.inputRef.value)))}}
|
|
114
|
-
@close=${()=>{this.onBlur(),this.hideCalendar()}}
|
|
115
|
-
${r.n(this.calRef)}
|
|
116
|
-
></pkt-calendar>
|
|
117
|
-
</div>`}render(){return this.inputClasses={"pkt-input":!0,"pkt-datepicker__input":!0,"pkt-input--fullwidth":this.fullwidth,"pkt-datepicker--hasrangelabels":this.showRangeLabels,"pkt-datepicker--multiple":this.multiple,"pkt-datepicker--range":this.range},this.buttonClasses={"pkt-input-icon":!0,"pkt-btn":!0,"pkt-btn--icon-only":!0,"pkt-btn--tertiary":!0,"pkt-datepicker__calendar-button":!0},s.x`
|
|
118
|
-
<pkt-input-wrapper
|
|
119
|
-
label="${this.label}"
|
|
120
|
-
forId="${this.id}-input"
|
|
121
|
-
?counter=${this.multiple&&!!this.maxlength}
|
|
122
|
-
.counterCurrent=${this.value?this._value.length:0}
|
|
123
|
-
.counterMaxLength=${this.maxlength}
|
|
124
|
-
?disabled=${this.disabled}
|
|
125
|
-
?hasError=${this.hasError}
|
|
126
|
-
?hasFieldset=${this.hasFieldset}
|
|
127
|
-
?inline=${this.inline}
|
|
128
|
-
?required=${this.required}
|
|
129
|
-
?optionalTag=${this.optionalTag}
|
|
130
|
-
?requiredTag=${this.requiredTag}
|
|
131
|
-
?useWrapper=${this.useWrapper}
|
|
132
|
-
.optionalText=${this.optionalText}
|
|
133
|
-
.requiredText=${this.requiredText}
|
|
134
|
-
.tagText=${this.tagText}
|
|
135
|
-
.errorMessage=${this.errorMessage}
|
|
136
|
-
.helptext=${this.helptext}
|
|
137
|
-
.helptextDropdown=${this.helptextDropdown}
|
|
138
|
-
.helptextDropdownButton=${this.helptextDropdownButton}
|
|
139
|
-
.ariaDescribedBy=${this.ariaDescribedBy}
|
|
140
|
-
class="pkt-datepicker"
|
|
141
|
-
>
|
|
142
|
-
<div class="pkt-contents" ${r.n(this.helptextSlot)} name="helptext" slot="helptext"></div>
|
|
143
|
-
${this.multiple?this.renderTags():s.E}
|
|
144
|
-
<div
|
|
145
|
-
class="pkt-datepicker__inputs ${this.range&&this.showRangeLabels?"pkt-input__range-inputs":""}"
|
|
146
|
-
>
|
|
147
|
-
<div class="pkt-input__container">
|
|
148
|
-
${this.range?this.renderRangeInput():this.multiple?this.renderMultipleInput():this.renderInput()}
|
|
149
|
-
<button
|
|
150
|
-
class="${d.e(this.buttonClasses)}"
|
|
151
|
-
type="button"
|
|
152
|
-
@click=${this.toggleCalendar}
|
|
153
|
-
@keydown=${t=>{(t.key==="Enter"||t.key===" "||t.key==="Space")&&(t.preventDefault(),this.toggleCalendar(t))}}
|
|
154
|
-
?disabled=${this.disabled}
|
|
155
|
-
${r.n(this.btnRef)}
|
|
156
|
-
>
|
|
157
|
-
<pkt-icon name="calendar"></pkt-icon>
|
|
158
|
-
<span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
|
|
159
|
-
</button>
|
|
160
|
-
</div>
|
|
161
|
-
</div>
|
|
162
|
-
</pkt-input-wrapper>
|
|
163
|
-
${this.renderCalendar()}
|
|
164
|
-
`}handleCalendarPosition(){var t;if(this.popupRef.value&&this.inputRef.value){const e=this.multiple&&!!this.maxlength,i=((t=this.inputRef.value.parentElement)==null?void 0:t.getBoundingClientRect())||this.inputRef.value.getBoundingClientRect(),a=e?i.height+30:i.height,l=this.popupRef.value.getBoundingClientRect().height;let u=e?"calc(100% - 30px)":"100%";i&&i.top+l>window.innerHeight&&i.top-l>0&&(u=`calc(100% - ${a}px - ${l}px)`),this.popupRef.value.style.top=u}}handleFocusOut(t){this.contains(t.target)||(this.onBlur(),this.hideCalendar())}async showCalendar(){var t;this.calendarOpen=!0,await g(20),this.handleCalendarPosition(),this.isMobileSafari&&((t=this.calRef.value)==null||t.focusOnCurrentDate())}hideCalendar(){this.calendarOpen=!1}async toggleCalendar(t){t.preventDefault(),this.calendarOpen?this.hideCalendar():this.showCalendar()}clearInputValue(){this._value=[],this.value=""}};n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"value",1);n([s.n({type:Array})],exports.PktDatepicker.prototype,"_value",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"label",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"dateformat",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"multiple",2);n([s.n({type:Number,reflect:!0})],exports.PktDatepicker.prototype,"maxlength",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"range",2);n([s.n({type:Boolean})],exports.PktDatepicker.prototype,"showRangeLabels",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"min",2);n([s.n({type:String,reflect:!0})],exports.PktDatepicker.prototype,"max",2);n([s.n({type:Boolean})],exports.PktDatepicker.prototype,"weeknumbers",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"withcontrols",2);n([s.n({converter:o.converters.csvToArray})],exports.PktDatepicker.prototype,"excludedates",2);n([s.n({converter:o.converters.csvToArray})],exports.PktDatepicker.prototype,"excludeweekdays",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"currentmonth",2);n([s.n({type:Boolean,reflect:!0})],exports.PktDatepicker.prototype,"calendarOpen",2);n([s.n({type:String})],exports.PktDatepicker.prototype,"timezone",2);n([v.r()],exports.PktDatepicker.prototype,"inputClasses",2);n([v.r()],exports.PktDatepicker.prototype,"buttonClasses",2);exports.PktDatepicker=n([s.t("pkt-datepicker")],exports.PktDatepicker);
|