@oslokommune/punkt-elements 12.17.2 → 12.18.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/dist/alert-BbVWu2lm.cjs +27 -0
- package/dist/alert-Dh6A96vo.js +159 -0
- package/dist/{index-D2jSRMrn.js → calendar-BUqcNvfI.js} +41 -29
- package/dist/calendar-QSulz7im.cjs +108 -0
- package/dist/card-B0GPdG5M.cjs +23 -0
- package/dist/card-kWt0BA2a.js +170 -0
- package/dist/{class-map-a5HUzP83.cjs → class-map-Boa7BqCc.cjs} +2 -2
- package/dist/{class-map-CBvUV2N3.js → class-map-hz16xq5a.js} +9 -10
- package/dist/datepicker-BHepKxof.cjs +154 -0
- package/dist/datepicker-iNCYioZ9.js +659 -0
- package/dist/helptext--4FLdAWi.js +194 -0
- package/dist/helptext-iZEgxz2U.cjs +23 -0
- package/dist/icon-CdMQ6zBT.cjs +250 -0
- package/dist/{index-CFDwiDTU.js → icon-wUXeHiBk.js} +7371 -7559
- package/dist/if-defined-DEDlGbAc.cjs +5 -0
- package/dist/if-defined-ZFE4ti2t.js +10 -0
- package/dist/index.d.ts +96 -51
- package/dist/input-element-D1Vls6A5.js +184 -0
- package/dist/input-element-DPKoFVwJ.cjs +1 -0
- package/dist/{input-wrapper-6vTrKtsW.js → input-wrapper-BTQk3W8T.js} +10 -10
- package/dist/input-wrapper-D-PNRJB_.cjs +46 -0
- package/dist/link-BpqavGSD.cjs +8 -0
- package/dist/link-Bx9nVgZi.js +108 -0
- package/dist/{linkcard-BlWQ8jOv.js → linkcard-CUrbzjLK.js} +16 -17
- package/dist/linkcard-DSu3A4Yx.cjs +13 -0
- package/dist/messagebox-C1aWoQbu.cjs +12 -0
- package/dist/messagebox-LpiVQIoM.js +107 -0
- package/dist/{modal-DYTVJjYh.cjs → modal-Avai5eVz.cjs} +2 -2
- package/dist/{modal-3OZTPqee.js → modal-Co1YFmHi.js} +8 -8
- package/dist/pkt-alert.cjs +1 -27
- package/dist/pkt-alert.js +4 -157
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +4 -7
- package/dist/pkt-card.cjs +1 -23
- package/dist/pkt-card.js +4 -168
- package/dist/pkt-datepicker.cjs +1 -154
- package/dist/pkt-datepicker.js +4 -657
- package/dist/pkt-helptext.cjs +1 -1
- package/dist/pkt-helptext.js +1 -1
- package/dist/pkt-icon.cjs +1 -1
- package/dist/pkt-icon.js +4 -4
- package/dist/pkt-index.cjs +29 -1
- package/dist/pkt-index.js +127 -30
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-link.cjs +1 -8
- package/dist/pkt-link.js +4 -107
- package/dist/pkt-linkcard.cjs +1 -1
- package/dist/pkt-linkcard.js +1 -1
- package/dist/pkt-messagebox.cjs +1 -12
- package/dist/pkt-messagebox.js +4 -105
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/pkt-progressbar.cjs +1 -0
- package/dist/pkt-progressbar.js +6 -0
- package/dist/pkt-slot-controller-Ckk_yV0j.cjs +1 -0
- package/dist/pkt-slot-controller-RJvOnbF4.js +61 -0
- package/dist/pkt-tag.cjs +1 -17
- package/dist/pkt-tag.js +4 -148
- 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-BS_oawSB.js +150 -0
- package/dist/progressbar-CuXkbAhJ.cjs +32 -0
- package/dist/ref-DCOsLZQg.cjs +13 -0
- package/dist/ref-DuFGTLVX.js +142 -0
- package/dist/state-BfyXV7EL.js +12 -0
- package/dist/state-SKYD8kRO.cjs +5 -0
- package/dist/stringutils-CkVRq4jP.cjs +1 -0
- package/dist/stringutils-DJjRa8dG.js +7 -0
- package/dist/tag-CGy2mSLE.cjs +17 -0
- package/dist/tag-DGFgUF3l.js +150 -0
- package/dist/{textarea-BTpJjEhO.js → textarea-BAGWR1Hi.js} +29 -29
- package/dist/textarea-BiUrhAlk.cjs +48 -0
- package/dist/{textinput-BIhQEr8z.cjs → textinput-CHOR5PPp.cjs} +2 -2
- package/dist/{textinput-CVo5wG14.js → textinput-pJ3N8m6g.js} +23 -23
- package/package.json +2 -2
- package/src/components/alert/alert.ts +115 -0
- package/src/components/alert/index.ts +4 -113
- package/src/components/calendar/calendar.ts +711 -0
- package/src/components/calendar/index.ts +3 -711
- package/src/components/card/card.ts +78 -0
- package/src/components/card/index.ts +4 -77
- package/src/components/datepicker/datepicker.ts +619 -0
- package/src/components/datepicker/index.ts +3 -618
- package/src/components/helptext/helptext.ts +2 -2
- package/src/components/icon/icon.ts +99 -0
- package/src/components/icon/index.ts +3 -98
- package/src/components/index.ts +29 -15
- package/src/components/input-wrapper/input-wrapper.ts +2 -2
- package/src/components/link/index.ts +3 -56
- package/src/components/link/link.ts +57 -0
- package/src/components/linkcard/index.ts +1 -1
- package/src/components/linkcard/linkcard.ts +5 -6
- package/src/components/messagebox/index.ts +4 -69
- package/src/components/messagebox/messagebox.ts +69 -0
- package/src/components/modal/index.ts +0 -1
- package/src/components/modal/modal.ts +5 -7
- package/src/components/progressbar/index.ts +12 -0
- package/src/components/progressbar/progressbar.ts +144 -0
- package/src/components/tag/index.ts +4 -109
- package/src/components/tag/tag.ts +118 -0
- package/src/components/textarea/textarea.ts +5 -4
- package/src/components/textinput/textinput.ts +3 -3
- package/dist/converters-DNCwIFwr.js +0 -17
- package/dist/converters-DhM11VlY.cjs +0 -1
- package/dist/custom-element-B-TlBwRu.cjs +0 -9
- package/dist/custom-element-CWfU4dcr.js +0 -38
- package/dist/element.d.ts +0 -8
- package/dist/helptext-DBolvFI4.js +0 -72
- package/dist/helptext-_fMLOOCL.cjs +0 -23
- package/dist/index-CR7t1zY9.cjs +0 -238
- package/dist/index-CmTjXoAb.cjs +0 -9
- package/dist/index-RwtTBIhT.js +0 -88
- package/dist/index-tvpcg-ad.cjs +0 -108
- package/dist/input-wrapper-DX41tnbj.cjs +0 -46
- package/dist/linkcard-Det6CJ5D.cjs +0 -13
- package/dist/pkt-component-template.cjs +0 -29
- package/dist/pkt-component-template.js +0 -99
- package/dist/pkt-element.cjs +0 -1
- package/dist/pkt-element.js +0 -5
- package/dist/ref-C2yPtMJA.cjs +0 -13
- package/dist/ref-CaiKp3S2.js +0 -202
- package/dist/textarea-B45ZZYpx.cjs +0 -48
- package/src/components/component-template/index.ts +0 -129
- package/src/components/element/index.ts +0 -353
- /package/dist/{component-template.d.ts → progressbar.d.ts} +0 -0
|
@@ -1,618 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { classMap } from 'lit/directives/class-map.js'
|
|
5
|
-
import { repeat } from 'lit/directives/repeat.js'
|
|
6
|
-
import { PktInputElement } from '../element'
|
|
7
|
-
import { PktCalendar } from '../calendar'
|
|
8
|
-
import converters from '../../helpers/converters'
|
|
9
|
-
import specs from 'componentSpecs/datepicker.json'
|
|
10
|
-
import { formatISODate, fromISOToDate, fromISOtoLocal, newDate } from '@/utils/dateutils'
|
|
11
|
-
import '../calendar'
|
|
12
|
-
import '../input-wrapper'
|
|
13
|
-
import '../icon'
|
|
14
|
-
import '../tag'
|
|
15
|
-
|
|
16
|
-
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
17
|
-
@customElement('pkt-datepicker')
|
|
18
|
-
export class PktDatepicker extends PktInputElement {
|
|
19
|
-
/**
|
|
20
|
-
* Element attributes and properties
|
|
21
|
-
*/
|
|
22
|
-
@property({ type: String, reflect: true })
|
|
23
|
-
value: string | string[] = ''
|
|
24
|
-
|
|
25
|
-
@property({ type: Array })
|
|
26
|
-
_value: string[] = this.value
|
|
27
|
-
? !Array.isArray(this.value)
|
|
28
|
-
? this.value.split(',')
|
|
29
|
-
: this.value
|
|
30
|
-
: []
|
|
31
|
-
|
|
32
|
-
@property({ type: String, reflect: true })
|
|
33
|
-
label: string = 'Datovelger'
|
|
34
|
-
|
|
35
|
-
@property({ type: String })
|
|
36
|
-
dateformat: string = specs.props.dateformat.default
|
|
37
|
-
|
|
38
|
-
@property({ type: Boolean, reflect: true })
|
|
39
|
-
multiple: boolean = specs.props.multiple.default
|
|
40
|
-
|
|
41
|
-
@property({ type: Number, reflect: true })
|
|
42
|
-
maxlength: number | null = null
|
|
43
|
-
|
|
44
|
-
@property({ type: Boolean, reflect: true })
|
|
45
|
-
range: boolean = specs.props.range.default
|
|
46
|
-
|
|
47
|
-
@property({ type: Boolean })
|
|
48
|
-
showRangeLabels: boolean = false
|
|
49
|
-
|
|
50
|
-
@property({ type: String, reflect: true })
|
|
51
|
-
min: string | null = null
|
|
52
|
-
|
|
53
|
-
@property({ type: String, reflect: true })
|
|
54
|
-
max: string | null = null
|
|
55
|
-
|
|
56
|
-
@property({ type: Boolean })
|
|
57
|
-
weeknumbers: boolean = specs.props.weeknumbers.default
|
|
58
|
-
|
|
59
|
-
@property({ type: Boolean, reflect: true })
|
|
60
|
-
withcontrols: boolean = specs.props.withcontrols.default
|
|
61
|
-
|
|
62
|
-
@property({ converter: converters.csvToArray })
|
|
63
|
-
excludedates: string[] = []
|
|
64
|
-
|
|
65
|
-
@property({ converter: converters.csvToArray })
|
|
66
|
-
excludeweekdays: string[] = []
|
|
67
|
-
|
|
68
|
-
@property({ type: String })
|
|
69
|
-
currentmonth: string | null = null
|
|
70
|
-
|
|
71
|
-
@property({ type: Boolean, reflect: true })
|
|
72
|
-
calendarOpen: boolean = false
|
|
73
|
-
|
|
74
|
-
@property({ type: String })
|
|
75
|
-
timezone: string = 'Europe/Oslo'
|
|
76
|
-
|
|
77
|
-
@state() inputClasses = {}
|
|
78
|
-
@state() buttonClasses = {}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Housekeeping / lifecycle methods
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
async connectedCallback() {
|
|
85
|
-
super.connectedCallback()
|
|
86
|
-
|
|
87
|
-
this.isMobileSafari =
|
|
88
|
-
/iP(ad|od|hone)/i.test(window.navigator.userAgent) &&
|
|
89
|
-
!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)
|
|
90
|
-
this.inputType = this.isMobileSafari ? 'text' : 'date'
|
|
91
|
-
|
|
92
|
-
document &&
|
|
93
|
-
document.body.addEventListener('click', (e: MouseEvent) => {
|
|
94
|
-
if (
|
|
95
|
-
this.inputRef?.value &&
|
|
96
|
-
this.btnRef?.value &&
|
|
97
|
-
!this.inputRef.value.contains(e.target as Node) &&
|
|
98
|
-
!(this.inputRefTo.value && this.inputRefTo.value.contains(e.target as Node)) &&
|
|
99
|
-
!this.btnRef.value.contains(e.target as Node) &&
|
|
100
|
-
!(e.target as Element).closest('.pkt-calendar-popup') &&
|
|
101
|
-
this.calendarOpen
|
|
102
|
-
) {
|
|
103
|
-
this.onBlur()
|
|
104
|
-
this.hideCalendar()
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
if (this.value.length && this._value.length === 0) {
|
|
109
|
-
this._value = !Array.isArray(this.value) ? this.value.split(',') : this.value
|
|
110
|
-
}
|
|
111
|
-
this.min = this.min || specs.props.min.default
|
|
112
|
-
this.max = this.max || specs.props.max.default
|
|
113
|
-
|
|
114
|
-
if (typeof this.excludedates === 'string') {
|
|
115
|
-
this.excludedates = (this.excludedates as unknown as string).split(',')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (typeof this.excludeweekdays === 'string') {
|
|
119
|
-
this.excludeweekdays = (this.excludeweekdays as unknown as string).split(',')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if ((this.multiple || this.range) && this.name && !this.name.endsWith('[]')) {
|
|
123
|
-
this.name = this.name + '[]'
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (this.calendarOpen) {
|
|
127
|
-
await sleep(20)
|
|
128
|
-
this.handleCalendarPosition()
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
disconnectedCallback(): void {
|
|
133
|
-
super.disconnectedCallback()
|
|
134
|
-
document &&
|
|
135
|
-
document.body.removeEventListener('click', (e: MouseEvent) => {
|
|
136
|
-
if (
|
|
137
|
-
this.inputRef?.value &&
|
|
138
|
-
this.btnRef?.value &&
|
|
139
|
-
!this.inputRef.value.contains(e.target as Node) &&
|
|
140
|
-
!this.btnRef.value.contains(e.target as Node)
|
|
141
|
-
) {
|
|
142
|
-
this.hideCalendar()
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
|
|
148
|
-
if (name === 'value') {
|
|
149
|
-
if (this.range && value?.split(',').length === 1) return
|
|
150
|
-
if (this.value !== _old) this.valueChanged(value, _old)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (name === 'excludedates' && typeof this.excludedates === 'string') {
|
|
154
|
-
this.excludedates = value?.split(',') ?? []
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (name === 'excludeweekdays' && typeof this.excludeweekdays === 'string') {
|
|
158
|
-
this.excludeweekdays = value?.split(',') ?? []
|
|
159
|
-
}
|
|
160
|
-
super.attributeChangedCallback(name, _old, value)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
updated(changedProperties: PropertyValues): void {
|
|
164
|
-
if (changedProperties.has('value')) {
|
|
165
|
-
if (this.range && this.value.length === 1) return
|
|
166
|
-
this.valueChanged(this.value, changedProperties.get('value'))
|
|
167
|
-
}
|
|
168
|
-
super.updated(changedProperties)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Element references
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
// When using PktInputElement, we always need to define `inputRef`
|
|
176
|
-
inputRef: Ref<HTMLInputElement> = createRef()
|
|
177
|
-
inputRefTo: Ref<HTMLInputElement> = createRef()
|
|
178
|
-
btnRef: Ref<HTMLButtonElement> = createRef()
|
|
179
|
-
calRef: Ref<PktCalendar> = createRef()
|
|
180
|
-
popupRef: Ref<HTMLDivElement> = createRef()
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Rendering
|
|
184
|
-
*/
|
|
185
|
-
renderInput() {
|
|
186
|
-
return html`
|
|
187
|
-
<input
|
|
188
|
-
class="${classMap(this.inputClasses)}"
|
|
189
|
-
.type=${this.inputType}
|
|
190
|
-
id="${this.id}-input"
|
|
191
|
-
.value=${this._value[0] ?? ''}
|
|
192
|
-
min=${this.min}
|
|
193
|
-
max=${this.max}
|
|
194
|
-
@click=${(e: MouseEvent) => {
|
|
195
|
-
e.preventDefault()
|
|
196
|
-
this.showCalendar()
|
|
197
|
-
}}
|
|
198
|
-
?disabled=${this.disabled}
|
|
199
|
-
@keydown=${(e: KeyboardEvent) => {
|
|
200
|
-
if (e.key === ',' || e.key === 'Enter') {
|
|
201
|
-
this.inputRef.value?.blur()
|
|
202
|
-
}
|
|
203
|
-
if (e.key === 'Space' || e.key === ' ') {
|
|
204
|
-
e.preventDefault()
|
|
205
|
-
this.toggleCalendar(e)
|
|
206
|
-
}
|
|
207
|
-
}}
|
|
208
|
-
@input=${(e: Event) => {
|
|
209
|
-
this.onInput()
|
|
210
|
-
e.stopImmediatePropagation()
|
|
211
|
-
}}
|
|
212
|
-
@focus=${() => {
|
|
213
|
-
this.onFocus()
|
|
214
|
-
if (this.isMobileSafari) {
|
|
215
|
-
this.showCalendar()
|
|
216
|
-
}
|
|
217
|
-
}}
|
|
218
|
-
@blur=${(e: FocusEvent) => {
|
|
219
|
-
if (!this.calRef.value?.contains(e.relatedTarget as Node)) {
|
|
220
|
-
this.onBlur()
|
|
221
|
-
}
|
|
222
|
-
this.manageValidity(e.target as HTMLInputElement)
|
|
223
|
-
this.value = (e.target as HTMLInputElement).value
|
|
224
|
-
}}
|
|
225
|
-
@change=${(e: Event) => {
|
|
226
|
-
e.stopImmediatePropagation()
|
|
227
|
-
}}
|
|
228
|
-
${ref(this.inputRef)}
|
|
229
|
-
/>
|
|
230
|
-
`
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
renderRangeInput() {
|
|
234
|
-
const rangeLabelClasses = {
|
|
235
|
-
'pkt-input-prefix': this.showRangeLabels,
|
|
236
|
-
'pkt-hide': !this.showRangeLabels,
|
|
237
|
-
}
|
|
238
|
-
return html`
|
|
239
|
-
${this.showRangeLabels
|
|
240
|
-
? html` <div class="pkt-input-prefix">${this.strings.generic.from}</div> `
|
|
241
|
-
: nothing}
|
|
242
|
-
<input
|
|
243
|
-
class=${classMap(this.inputClasses)}
|
|
244
|
-
.type=${this.inputType}
|
|
245
|
-
id="${this.id}-input"
|
|
246
|
-
.value=${this._value[0] ?? ''}
|
|
247
|
-
min=${this.min}
|
|
248
|
-
max=${this.max}
|
|
249
|
-
?disabled=${this.disabled}
|
|
250
|
-
@click=${(e: MouseEvent) => {
|
|
251
|
-
e.preventDefault()
|
|
252
|
-
this.showCalendar()
|
|
253
|
-
}}
|
|
254
|
-
@keydown=${(e: KeyboardEvent) => {
|
|
255
|
-
if (e.key === ',' || e.key === 'Enter') {
|
|
256
|
-
this.inputRef.value?.blur()
|
|
257
|
-
}
|
|
258
|
-
if (e.key === 'Space' || e.key === ' ') {
|
|
259
|
-
e.preventDefault()
|
|
260
|
-
this.toggleCalendar(e)
|
|
261
|
-
}
|
|
262
|
-
}}
|
|
263
|
-
@input=${(e: Event) => {
|
|
264
|
-
this.onInput()
|
|
265
|
-
e.stopImmediatePropagation()
|
|
266
|
-
}}
|
|
267
|
-
@focus=${() => {
|
|
268
|
-
this.onFocus()
|
|
269
|
-
if (this.isMobileSafari) {
|
|
270
|
-
this.showCalendar()
|
|
271
|
-
}
|
|
272
|
-
}}
|
|
273
|
-
@blur=${(e: Event) => {
|
|
274
|
-
if ((e.target as HTMLInputElement).value) {
|
|
275
|
-
this.manageValidity(e.target as HTMLInputElement)
|
|
276
|
-
const date = fromISOToDate((e.target as HTMLInputElement).value)
|
|
277
|
-
if (date) {
|
|
278
|
-
if (this._value[0] !== (e.target as HTMLInputElement).value && this._value[1]) {
|
|
279
|
-
this.clearInputValue()
|
|
280
|
-
this.calRef?.value?.handleDateSelect(date)
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
} else if (this._value[0]) {
|
|
284
|
-
this.clearInputValue()
|
|
285
|
-
}
|
|
286
|
-
}}
|
|
287
|
-
@change=${(e: Event) => {
|
|
288
|
-
e.stopImmediatePropagation()
|
|
289
|
-
}}
|
|
290
|
-
${ref(this.inputRef)}
|
|
291
|
-
/>
|
|
292
|
-
<div class="${classMap(rangeLabelClasses)}" id="${this.id}-to-label">
|
|
293
|
-
${this.strings.generic.to}
|
|
294
|
-
</div>
|
|
295
|
-
${!this.showRangeLabels ? html` <div class="pkt-input-separator">–</div> ` : nothing}
|
|
296
|
-
<input
|
|
297
|
-
class=${classMap(this.inputClasses)}
|
|
298
|
-
.type=${this.inputType}
|
|
299
|
-
id="${this.id}-to"
|
|
300
|
-
aria-labelledby="${this.id}-to-label"
|
|
301
|
-
.value=${this._value[1] ?? ''}
|
|
302
|
-
min=${this.min}
|
|
303
|
-
max=${this.max}
|
|
304
|
-
?disabled=${this.disabled}
|
|
305
|
-
@click=${(e: MouseEvent) => {
|
|
306
|
-
e.preventDefault()
|
|
307
|
-
this.showCalendar()
|
|
308
|
-
}}
|
|
309
|
-
@keydown=${(e: KeyboardEvent) => {
|
|
310
|
-
if (e.key === ',' || e.key === 'Enter') {
|
|
311
|
-
this.inputRefTo.value?.blur()
|
|
312
|
-
}
|
|
313
|
-
if (e.key === 'Space' || e.key === ' ') {
|
|
314
|
-
e.preventDefault()
|
|
315
|
-
this.toggleCalendar(e)
|
|
316
|
-
}
|
|
317
|
-
}}
|
|
318
|
-
@input=${(e: Event) => {
|
|
319
|
-
this.onInput()
|
|
320
|
-
e.stopImmediatePropagation()
|
|
321
|
-
}}
|
|
322
|
-
@focus=${() => {
|
|
323
|
-
this.onFocus()
|
|
324
|
-
if (this.isMobileSafari) {
|
|
325
|
-
this.showCalendar()
|
|
326
|
-
}
|
|
327
|
-
}}
|
|
328
|
-
@blur=${(e: FocusEvent) => {
|
|
329
|
-
if (!this.calRef.value?.contains(e.relatedTarget as Node)) {
|
|
330
|
-
this.onBlur()
|
|
331
|
-
}
|
|
332
|
-
if ((e.target as HTMLInputElement).value) {
|
|
333
|
-
this.manageValidity(e.target as HTMLInputElement)
|
|
334
|
-
const val = (e.target as HTMLInputElement).value
|
|
335
|
-
if (this.min && this.min > val) {
|
|
336
|
-
this.internals.setValidity(
|
|
337
|
-
{ rangeUnderflow: true },
|
|
338
|
-
this.strings.forms.messages.rangeUnderflow,
|
|
339
|
-
e.target as HTMLInputElement,
|
|
340
|
-
)
|
|
341
|
-
} else if (this.max && this.max < val) {
|
|
342
|
-
this.internals.setValidity(
|
|
343
|
-
{ rangeOverflow: true },
|
|
344
|
-
this.strings.forms.messages.rangeOverflow,
|
|
345
|
-
e.target as HTMLInputElement,
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
const date = fromISOToDate((e.target as HTMLInputElement).value)
|
|
349
|
-
if (date) {
|
|
350
|
-
if (this._value[1] !== formatISODate(date)) {
|
|
351
|
-
this.calRef?.value?.handleDateSelect(date)
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}}
|
|
356
|
-
@change=${(e: Event) => {
|
|
357
|
-
e.stopImmediatePropagation()
|
|
358
|
-
}}
|
|
359
|
-
${ref(this.inputRefTo)}
|
|
360
|
-
/>
|
|
361
|
-
`
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
renderMultipleInput() {
|
|
365
|
-
return html`
|
|
366
|
-
<input
|
|
367
|
-
class=${classMap(this.inputClasses)}
|
|
368
|
-
.type=${this.inputType}
|
|
369
|
-
id="${this.id}-input"
|
|
370
|
-
min=${this.min || nothing}
|
|
371
|
-
max=${this.max || nothing}
|
|
372
|
-
?disabled=${this.disabled || (this.maxlength && this._value.length >= this.maxlength)}
|
|
373
|
-
@click=${(e: MouseEvent) => {
|
|
374
|
-
e.preventDefault()
|
|
375
|
-
this.showCalendar()
|
|
376
|
-
}}
|
|
377
|
-
@blur=${(e: FocusEvent) => {
|
|
378
|
-
if (!this.calRef.value?.contains(e.relatedTarget as Node)) {
|
|
379
|
-
this.onBlur()
|
|
380
|
-
}
|
|
381
|
-
this.addToSelected(e)
|
|
382
|
-
}}
|
|
383
|
-
@input=${(e: Event) => {
|
|
384
|
-
this.onInput()
|
|
385
|
-
e.stopImmediatePropagation()
|
|
386
|
-
}}
|
|
387
|
-
@focus=${() => {
|
|
388
|
-
this.onFocus()
|
|
389
|
-
if (this.isMobileSafari) {
|
|
390
|
-
this.showCalendar()
|
|
391
|
-
}
|
|
392
|
-
}}
|
|
393
|
-
@keydown=${(e: KeyboardEvent) => {
|
|
394
|
-
if (e.key === ',' || e.key === 'Enter') {
|
|
395
|
-
e.preventDefault()
|
|
396
|
-
this.addToSelected(e)
|
|
397
|
-
}
|
|
398
|
-
if (e.key === 'Space' || e.key === ' ') {
|
|
399
|
-
e.preventDefault()
|
|
400
|
-
this.toggleCalendar(e)
|
|
401
|
-
}
|
|
402
|
-
}}
|
|
403
|
-
@change=${(e: Event) => {
|
|
404
|
-
e.stopImmediatePropagation()
|
|
405
|
-
}}
|
|
406
|
-
${ref(this.inputRef)}
|
|
407
|
-
/>
|
|
408
|
-
`
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
renderTags() {
|
|
412
|
-
return html`
|
|
413
|
-
<div class="pkt-datepicker__tags" aria-live="polite">
|
|
414
|
-
${!!this._value[0]
|
|
415
|
-
? repeat(
|
|
416
|
-
this._value ?? [],
|
|
417
|
-
(date) => date,
|
|
418
|
-
(date) => html`
|
|
419
|
-
<pkt-tag
|
|
420
|
-
.id="${this.id + date + '-tag'}"
|
|
421
|
-
closeTag
|
|
422
|
-
ariaLabel="${this.strings.calendar.deleteDate} ${fromISOtoLocal(
|
|
423
|
-
date,
|
|
424
|
-
this.dateformat,
|
|
425
|
-
)}"
|
|
426
|
-
@close=${() => this.calRef.value?.handleDateSelect(fromISOToDate(date))}
|
|
427
|
-
><time datetime="${date}">${fromISOtoLocal(date, this.dateformat)}</time></pkt-tag
|
|
428
|
-
>
|
|
429
|
-
`,
|
|
430
|
-
)
|
|
431
|
-
: nothing}
|
|
432
|
-
</div>
|
|
433
|
-
`
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
renderCalendar() {
|
|
437
|
-
return html`<div
|
|
438
|
-
class="pkt-calendar-popup pkt-${this.calendarOpen ? 'show' : 'hide'}"
|
|
439
|
-
@focusout=${(e: FocusEvent) => {
|
|
440
|
-
if (this.calendarOpen) this.handleFocusOut(e)
|
|
441
|
-
}}
|
|
442
|
-
id="${this.id}-popup"
|
|
443
|
-
${ref(this.popupRef)}
|
|
444
|
-
>
|
|
445
|
-
<pkt-calendar
|
|
446
|
-
id="${this.id}-calendar"
|
|
447
|
-
?multiple=${this.multiple}
|
|
448
|
-
?range=${this.range}
|
|
449
|
-
?weeknumbers=${this.weeknumbers}
|
|
450
|
-
?withcontrols=${this.withcontrols}
|
|
451
|
-
.maxMultiple=${this.maxlength}
|
|
452
|
-
.selected=${this._value}
|
|
453
|
-
.earliest=${this.min}
|
|
454
|
-
.latest=${this.max}
|
|
455
|
-
.excludedates=${Array.isArray(this.excludedates)
|
|
456
|
-
? this.excludedates
|
|
457
|
-
: (this.excludedates as string).split(',')}
|
|
458
|
-
.excludeweekdays=${this.excludeweekdays}
|
|
459
|
-
.currentmonth=${this.currentmonth ? newDate(this.currentmonth) : null}
|
|
460
|
-
@date-selected=${(e: CustomEvent) => {
|
|
461
|
-
this.value = !this.multiple && !this.range ? e.detail[0] : e.detail
|
|
462
|
-
this._value = e.detail
|
|
463
|
-
if (this.inputRef.value) {
|
|
464
|
-
if (this.range && this.inputRefTo.value) {
|
|
465
|
-
this.inputRef.value.value = this._value[0] ?? ''
|
|
466
|
-
this.inputRefTo.value.value = this._value[1] ?? ''
|
|
467
|
-
} else if (!this.multiple) {
|
|
468
|
-
this.inputRef.value.value = this._value.length ? this._value[0] : ''
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}}
|
|
472
|
-
@close=${() => {
|
|
473
|
-
this.onBlur()
|
|
474
|
-
this.hideCalendar()
|
|
475
|
-
}}
|
|
476
|
-
${ref(this.calRef)}
|
|
477
|
-
></pkt-calendar>
|
|
478
|
-
</div>`
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
render() {
|
|
482
|
-
this.inputClasses = {
|
|
483
|
-
'pkt-input': true,
|
|
484
|
-
'pkt-datepicker__input': true,
|
|
485
|
-
'pkt-input--fullwidth': this.fullwidth,
|
|
486
|
-
'pkt-datepicker--hasrangelabels': this.showRangeLabels,
|
|
487
|
-
'pkt-datepicker--multiple': this.multiple,
|
|
488
|
-
'pkt-datepicker--range': this.range,
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
this.buttonClasses = {
|
|
492
|
-
'pkt-input-icon': true,
|
|
493
|
-
'pkt-btn': true,
|
|
494
|
-
'pkt-btn--icon-only': true,
|
|
495
|
-
'pkt-btn--tertiary': true,
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return html`
|
|
499
|
-
<pkt-input-wrapper
|
|
500
|
-
label="${this.label}"
|
|
501
|
-
forId="${this.id}-input"
|
|
502
|
-
?counter=${this.multiple && !!this.maxlength}
|
|
503
|
-
.counterCurrent=${this.value ? this._value.length : 0}
|
|
504
|
-
.counterMaxLength=${this.maxlength}
|
|
505
|
-
?disabled=${this.disabled}
|
|
506
|
-
?hasError=${this.hasError}
|
|
507
|
-
?required=${this.required}
|
|
508
|
-
?optionalTag=${this.optionalTag}
|
|
509
|
-
?requiredTag=${this.requiredTag}
|
|
510
|
-
?useWrapper=${this.useWrapper}
|
|
511
|
-
.optionalText=${this.optionalText}
|
|
512
|
-
.requiredText=${this.requiredText}
|
|
513
|
-
.errorMessage=${this.errorMessage}
|
|
514
|
-
.helptext=${this.helptext}
|
|
515
|
-
.helptextDropdown=${this.helptextDropdown}
|
|
516
|
-
.helptextDropdownButton=${this.helptextDropdownButton}
|
|
517
|
-
.ariaDescribedBy=${this.ariaDescribedBy}
|
|
518
|
-
class="pkt-datepicker"
|
|
519
|
-
>
|
|
520
|
-
${this.multiple ? this.renderTags() : nothing}
|
|
521
|
-
<div
|
|
522
|
-
class="pkt-datepicker__inputs ${this.range && this.showRangeLabels
|
|
523
|
-
? 'pkt-input__range-inputs'
|
|
524
|
-
: ''}"
|
|
525
|
-
>
|
|
526
|
-
<div class="pkt-input__container">
|
|
527
|
-
${this.range
|
|
528
|
-
? this.renderRangeInput()
|
|
529
|
-
: this.multiple
|
|
530
|
-
? this.renderMultipleInput()
|
|
531
|
-
: this.renderInput()}
|
|
532
|
-
<button
|
|
533
|
-
class="${classMap(this.buttonClasses)}"
|
|
534
|
-
type="button"
|
|
535
|
-
@click=${this.toggleCalendar}
|
|
536
|
-
?disabled=${this.disabled}
|
|
537
|
-
${ref(this.btnRef)}
|
|
538
|
-
>
|
|
539
|
-
<pkt-icon name="calendar"></pkt-icon>
|
|
540
|
-
<span class="pkt-btn__text">${this.strings.calendar.buttonAltText}</span>
|
|
541
|
-
</button>
|
|
542
|
-
</div>
|
|
543
|
-
</div>
|
|
544
|
-
</pkt-input-wrapper>
|
|
545
|
-
${this.renderCalendar()}
|
|
546
|
-
`
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Handlers
|
|
551
|
-
*/
|
|
552
|
-
|
|
553
|
-
handleCalendarPosition() {
|
|
554
|
-
if (this.popupRef.value && this.inputRef.value) {
|
|
555
|
-
const counter = this.multiple && !!this.maxlength
|
|
556
|
-
|
|
557
|
-
const inputRect =
|
|
558
|
-
this.inputRef.value.parentElement?.getBoundingClientRect() ||
|
|
559
|
-
this.inputRef.value.getBoundingClientRect()
|
|
560
|
-
|
|
561
|
-
const inputHeight = counter ? inputRect.height + 30 : inputRect.height
|
|
562
|
-
const popupHeight = this.popupRef.value.getBoundingClientRect().height
|
|
563
|
-
|
|
564
|
-
let top = counter ? 'calc(100% - 30px)' : '100%'
|
|
565
|
-
if (
|
|
566
|
-
inputRect &&
|
|
567
|
-
inputRect.top + popupHeight > window.innerHeight &&
|
|
568
|
-
inputRect.top - popupHeight > 0
|
|
569
|
-
) {
|
|
570
|
-
top = `calc(100% - ${inputHeight}px - ${popupHeight}px)`
|
|
571
|
-
}
|
|
572
|
-
this.popupRef.value.style.top = top
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
addToSelected = (e: Event | KeyboardEvent) => {
|
|
577
|
-
const target = e.target as HTMLInputElement
|
|
578
|
-
if (!target.value) return
|
|
579
|
-
const minAsDate = this.min ? newDate(this.min as string) : null
|
|
580
|
-
const maxAsDate = this.max ? newDate(this.max as string) : null
|
|
581
|
-
const date = newDate(target.value.split(',')[0])
|
|
582
|
-
if (
|
|
583
|
-
date &&
|
|
584
|
-
!isNaN(date.getTime()) &&
|
|
585
|
-
(!minAsDate || date >= minAsDate) &&
|
|
586
|
-
(!maxAsDate || date <= maxAsDate) &&
|
|
587
|
-
this.calRef.value
|
|
588
|
-
) {
|
|
589
|
-
this.calRef.value.handleDateSelect(date)
|
|
590
|
-
}
|
|
591
|
-
target.value = ''
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
private handleFocusOut(e: FocusEvent) {
|
|
595
|
-
if (!this.contains(e.target as Node)) {
|
|
596
|
-
this.onBlur()
|
|
597
|
-
this.hideCalendar()
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
public async showCalendar() {
|
|
602
|
-
this.calendarOpen = true
|
|
603
|
-
await sleep(20)
|
|
604
|
-
this.handleCalendarPosition()
|
|
605
|
-
if (this.isMobileSafari) {
|
|
606
|
-
this.calRef.value?.focusOnCurrentDate()
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
public hideCalendar() {
|
|
611
|
-
this.calendarOpen = false
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
public async toggleCalendar(e: Event) {
|
|
615
|
-
e.preventDefault()
|
|
616
|
-
this.calendarOpen ? this.hideCalendar() : this.showCalendar()
|
|
617
|
-
}
|
|
618
|
-
}
|
|
1
|
+
import { PktDatepicker } from './datepicker'
|
|
2
|
+
export { PktDatepicker }
|
|
3
|
+
export default PktDatepicker
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PktElement } from '
|
|
1
|
+
import { PktElement } from '@/base-elements/element'
|
|
2
2
|
import { html, nothing } from 'lit'
|
|
3
3
|
import { unsafeHTML } from 'lit/directives/unsafe-html.js'
|
|
4
4
|
import { classMap } from 'lit/directives/class-map.js'
|
|
5
5
|
import { customElement, property, state } from 'lit/decorators.js'
|
|
6
6
|
import { uuidish } from '@/utils/stringutils'
|
|
7
7
|
import specs from 'componentSpecs/input-wrapper.json'
|
|
8
|
-
import '../icon'
|
|
8
|
+
import '../icon/icon'
|
|
9
9
|
|
|
10
10
|
@customElement('pkt-helptext')
|
|
11
11
|
export class PktHelptext extends PktElement {
|