@oslokommune/punkt-elements 19.15.0 → 19.15.3
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 +23 -0
- package/dist/calendar-5XCeDtZX.cjs +85 -0
- package/dist/{calendar-D9w8M99G.js → calendar-CtWc545R.js} +45 -60
- package/dist/{checkbox-group-adbFTj8y.cjs → checkbox-group-BLurd7sf.cjs} +1 -1
- package/dist/{checkbox-group-C8mo9dkO.js → checkbox-group-Bum7k828.js} +1 -1
- package/dist/{combobox-jsPpImVF.cjs → combobox-BsXDULXd.cjs} +1 -1
- package/dist/{combobox-B8IeuEF0.js → combobox-C7tUHbG4.js} +1 -1
- package/dist/{datepicker-CjUY_mLR.js → datepicker-CJLcIDVk.js} +2 -2
- package/dist/{datepicker-CZYpIyJd.cjs → datepicker-DmZi4CNk.cjs} +1 -1
- package/dist/{fileupload-CnjtgTlF.cjs → fileupload-A_suUEPU.cjs} +1 -1
- package/dist/{fileupload-BKk03Dq-.js → fileupload-DehKWas6.js} +1 -1
- package/dist/{header-BCrefip0.cjs → header-BzAPmAsZ.cjs} +1 -1
- package/dist/{header-20rqKJFb.js → header-C6xhv3Ib.js} +1 -1
- package/dist/{input-wrapper-BwzajfFX.cjs → input-wrapper-BEmV0DGo.cjs} +2 -3
- package/dist/{input-wrapper-Bb6CZxmg.js → input-wrapper-xRJo_iVf.js} +2 -3
- package/dist/{option-group-element-CzehfgVZ.cjs → option-group-element-A2cOZRWA.cjs} +1 -1
- package/dist/{option-group-element-D5PgGNdt.js → option-group-element-fpMneBWa.js} +1 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-checkbox-group.cjs +1 -1
- package/dist/pkt-checkbox-group.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-fileupload.cjs +1 -1
- package/dist/pkt-fileupload.js +1 -1
- package/dist/pkt-header.cjs +1 -1
- package/dist/pkt-header.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +12 -12
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-radio-group.cjs +1 -1
- package/dist/pkt-radio-group.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/pkt-textarea.cjs +1 -1
- package/dist/pkt-textarea.js +1 -1
- package/dist/pkt-textinput.cjs +1 -1
- package/dist/pkt-textinput.js +1 -1
- package/dist/pkt-timepicker.cjs +1 -1
- package/dist/pkt-timepicker.js +1 -1
- package/dist/{radio-group-CtZhXMF8.js → radio-group-BmJ3kcba.js} +1 -1
- package/dist/{radio-group-MxNLGu-0.cjs → radio-group-Q75EtJzu.cjs} +1 -1
- package/dist/{select-Bs-Z5Thd.js → select-ByPSk9WT.js} +1 -1
- package/dist/{select-Czz1y2nI.cjs → select-CCY2_EbI.cjs} +1 -1
- package/dist/shared-types/calendar.d.ts +0 -1
- package/dist/shared-utils/calendar/calendar-grid.d.ts +0 -4
- package/dist/shared-utils/calendar/index.d.ts +1 -1
- package/dist/{textarea-C-sdNBRk.cjs → textarea-D9RWiR6u.cjs} +1 -1
- package/dist/{textarea-COHaMHpP.js → textarea-DB7FMtTf.js} +1 -1
- package/dist/{textinput-0DZeMqBr.js → textinput-Djl_yr1D.js} +1 -1
- package/dist/{textinput-BqBgsBZF.cjs → textinput-l31MdBd4.cjs} +1 -1
- package/dist/{timepicker-C_k-K1jA.cjs → timepicker-Bw8zkwV9.cjs} +1 -1
- package/dist/{timepicker-CvdI7jDN.js → timepicker-D_gNCZ2v.js} +1 -1
- package/package.json +2 -2
- package/src/components/calendar/calendar.constraints.test.ts +15 -0
- package/src/components/calendar/calendar.core.test.ts +15 -0
- package/src/components/calendar/calendar.ts +7 -15
- package/src/components/input-wrapper/input-wrapper.test.ts +1 -0
- package/src/components/input-wrapper/input-wrapper.ts +2 -2
- package/dist/calendar-C5QwPrbk.cjs +0 -91
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "19.15.
|
|
3
|
+
"version": "19.15.3",
|
|
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": "
|
|
87
|
+
"gitHead": "e4314e8b6bd5119bb74094fa2809fc5d389bcd2e"
|
|
88
88
|
}
|
|
@@ -41,6 +41,21 @@ describe('PktCalendar', () => {
|
|
|
41
41
|
expect(disabledDates.length).toBeGreaterThan(0)
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
+
test('marks month navigation as disabled outside earliest and latest', async () => {
|
|
45
|
+
const container = await createCalendar(
|
|
46
|
+
'earliest="2024-10-05" latest="2024-10-25" currentmonth="2024-10-01"',
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
50
|
+
await calendar.updateComplete
|
|
51
|
+
|
|
52
|
+
for (const selector of ['.pkt-calendar__prev-month', '.pkt-calendar__next-month']) {
|
|
53
|
+
const button = calendar.querySelector(selector)
|
|
54
|
+
expect(button).toHaveAttribute('aria-disabled', 'true')
|
|
55
|
+
expect(button).toHaveAttribute('data-disabled', 'disabled')
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
44
59
|
test('handles latest date property correctly', async () => {
|
|
45
60
|
const latestDate = '2024-12-15'
|
|
46
61
|
const container = await createCalendar(`latest="${latestDate}"`)
|
|
@@ -52,6 +52,18 @@ describe('PktCalendar', () => {
|
|
|
52
52
|
expect(monthNav).toBeInTheDocument()
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
+
test('renders days outside the current month as empty cells', async () => {
|
|
56
|
+
const container = await createCalendar('currentmonth="2024-10-01"')
|
|
57
|
+
|
|
58
|
+
const calendar = container.querySelector('pkt-calendar') as PktCalendar
|
|
59
|
+
await calendar.updateComplete
|
|
60
|
+
|
|
61
|
+
const otherCells = calendar.querySelectorAll('.pkt-cal-other')
|
|
62
|
+
expect(otherCells).toHaveLength(4)
|
|
63
|
+
otherCells.forEach((cell) => expect(cell).toBeEmptyDOMElement())
|
|
64
|
+
expect(calendar.querySelectorAll('.pkt-calendar__date')).toHaveLength(31)
|
|
65
|
+
})
|
|
66
|
+
|
|
55
67
|
test('renders month picker when withcontrols is true', async () => {
|
|
56
68
|
const container = await createCalendar('withcontrols')
|
|
57
69
|
|
|
@@ -113,6 +125,7 @@ describe('PktCalendar', () => {
|
|
|
113
125
|
expect(calendar.selected).toEqual([])
|
|
114
126
|
expect(calendar.earliest).toBe(null)
|
|
115
127
|
expect(calendar.latest).toBe(null)
|
|
128
|
+
expect(calendar.querySelector('[role="grid"]')).not.toHaveAttribute('aria-multiselectable')
|
|
116
129
|
})
|
|
117
130
|
|
|
118
131
|
test('handles multiple property correctly', async () => {
|
|
@@ -122,6 +135,7 @@ describe('PktCalendar', () => {
|
|
|
122
135
|
await calendar.updateComplete
|
|
123
136
|
|
|
124
137
|
expect(calendar.multiple).toBe(true)
|
|
138
|
+
expect(calendar.querySelector('[role="grid"]')).toHaveAttribute('aria-multiselectable', 'true')
|
|
125
139
|
})
|
|
126
140
|
|
|
127
141
|
test('handles range property correctly', async () => {
|
|
@@ -131,6 +145,7 @@ describe('PktCalendar', () => {
|
|
|
131
145
|
await calendar.updateComplete
|
|
132
146
|
|
|
133
147
|
expect(calendar.range).toBe(true)
|
|
148
|
+
expect(calendar.querySelector('[role="grid"]')).toHaveAttribute('aria-multiselectable', 'true')
|
|
134
149
|
})
|
|
135
150
|
|
|
136
151
|
test('handles weeknumbers property correctly', async () => {
|
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
DAYS_PER_WEEK,
|
|
26
26
|
calculateCalendarDimensions,
|
|
27
27
|
getCellType,
|
|
28
|
-
getDayNumber,
|
|
29
28
|
} from 'shared-utils/calendar/calendar-grid'
|
|
30
29
|
import {
|
|
31
30
|
convertSelectedToDates,
|
|
@@ -256,7 +255,7 @@ export class PktCalendar extends PktElement<IPktStringsProps<'dates' | 'calendar
|
|
|
256
255
|
<table
|
|
257
256
|
class="pkt-cal-days pkt-txt-12-medium pkt-calendar__body"
|
|
258
257
|
role="grid"
|
|
259
|
-
|
|
258
|
+
aria-multiselectable=${this.range || this.multiple ? 'true' : nothing}
|
|
260
259
|
>
|
|
261
260
|
<thead>
|
|
262
261
|
${this.renderDayNames()}
|
|
@@ -290,8 +289,8 @@ export class PktCalendar extends PktElement<IPktStringsProps<'dates' | 'calendar
|
|
|
290
289
|
}
|
|
291
290
|
}}
|
|
292
291
|
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only ${className} ${isAllowed ? '' : 'pkt-invisible'}"
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
data-disabled=${!isAllowed ? 'disabled' : nothing}
|
|
293
|
+
aria-disabled=${!isAllowed ? 'true' : nothing}
|
|
295
294
|
tabindex=${isAllowed ? '0' : '-1'}
|
|
296
295
|
>
|
|
297
296
|
<pkt-icon class="pkt-btn__icon" name="${iconName}"></pkt-icon>
|
|
@@ -356,6 +355,7 @@ export class PktCalendar extends PktElement<IPktStringsProps<'dates' | 'calendar
|
|
|
356
355
|
const target = e.target as HTMLInputElement
|
|
357
356
|
this.changeMonth(parseInt(target.value), this.month)
|
|
358
357
|
}}
|
|
358
|
+
value=${this.year}
|
|
359
359
|
.value=${this.year}
|
|
360
360
|
/>
|
|
361
361
|
</div>`
|
|
@@ -505,15 +505,8 @@ export class PktCalendar extends PktElement<IPktStringsProps<'dates' | 'calendar
|
|
|
505
505
|
</td>`
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
-
private renderEmptyDayCell(
|
|
509
|
-
return html`<td class="pkt-cal-other"
|
|
510
|
-
<div
|
|
511
|
-
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
512
|
-
data-disabled="disabled"
|
|
513
|
-
>
|
|
514
|
-
<span class="pkt-btn__text pkt-txt-14-light">${day}</span>
|
|
515
|
-
</div>
|
|
516
|
-
</td>`
|
|
508
|
+
private renderEmptyDayCell(): TemplateResult {
|
|
509
|
+
return html`<td class="pkt-cal-other"></td>`
|
|
517
510
|
}
|
|
518
511
|
|
|
519
512
|
private renderWeekRow(cells: TemplateResult[]): TemplateResult {
|
|
@@ -551,8 +544,7 @@ export class PktCalendar extends PktElement<IPktStringsProps<'dates' | 'calendar
|
|
|
551
544
|
cells.push(this.renderDayView(dayCounter, today))
|
|
552
545
|
dayCounter++
|
|
553
546
|
} else {
|
|
554
|
-
|
|
555
|
-
cells.push(this.renderEmptyDayCell(dayNumber))
|
|
547
|
+
cells.push(this.renderEmptyDayCell())
|
|
556
548
|
if (cellType === 'next-month') {
|
|
557
549
|
dayCounter++
|
|
558
550
|
}
|
|
@@ -197,6 +197,7 @@ describe('PktInputWrapper', () => {
|
|
|
197
197
|
|
|
198
198
|
const counter = wrapper.querySelector('.pkt-input__counter')
|
|
199
199
|
expect(counter).toBeInTheDocument()
|
|
200
|
+
expect(counter?.textContent?.trim()).toBe('5/100')
|
|
200
201
|
})
|
|
201
202
|
|
|
202
203
|
test('updates counter current value', async () => {
|
|
@@ -184,9 +184,9 @@ export class PktInputWrapper extends PktElementWithSlot<Props> {
|
|
|
184
184
|
// Den synlige telleren er aria-hidden. Statusregionen under holdes tom
|
|
185
185
|
// til grensa er brutt, så skjermlesere bare varsler når det faktisk er noe å si.
|
|
186
186
|
const exceeded = isCounterExceeded(this.counterCurrent, this.counterMaxLength)
|
|
187
|
+
const count = `${this.counterCurrent || 0}${this.counterMaxLength ? `/${this.counterMaxLength}` : ''}`
|
|
187
188
|
return html`<div class="pkt-input__counter" aria-hidden="true">
|
|
188
|
-
${this.counterError ? this.counterError : nothing}
|
|
189
|
-
${this.counterMaxLength ? `/${this.counterMaxLength}` : nothing}
|
|
189
|
+
${this.counterError ? `${this.counterError} ` : nothing}${count}
|
|
190
190
|
</div>
|
|
191
191
|
<div class="pkt-sr-only" id=${counterStatusId(this.forId)} aria-live="polite">
|
|
192
192
|
${exceeded
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const e=require("./element-C6WTyJFE.cjs"),t=require("./class-map-Bh6toDeV.cjs");require("./icon-jPhyZD1z.cjs");const n=require("./converters-BJ9Fe0kW.cjs");var r={multiple:!1,maxMultiple:0,range:!1,earliest:null,latest:null,weeknumbers:!1,withcontrols:!1};function i(e,t,r){let i=n.y(e,r?.in);return isNaN(t)?n.b(r?.in||e,NaN):(t&&i.setDate(i.getDate()+t),i)}function a(e,t){let[r,i]=n.v(e,t.start,t.end);return{start:r,end:i}}function o(e,t){let{start:r,end:i}=a(t?.in,e),o=+r>+i,s=o?+r:+i,c=o?i:r;c.setHours(0,0,0,0);let l=t?.step??1;if(!l)return[];l<0&&(l=-l,o=!o);let u=[];for(;+c<=s;)u.push(n.b(r,c)),c.setDate(c.getDate()+l),c.setHours(0,0,0,0);return o?u.reverse():u}function s(e,t){let r=n.y(e,t?.in).getDay();return r===0?7:r}function c(e,t){let r=(t.excludedates??[]).map(e=>typeof e==`string`?e:n.a(e));return!n.l(e,t.earliest,t.latest,r,t.excludeweekdays??[])}function l(e,t,n,r){return!!(c(e,n)||!t&&r.multiple&&r.maxMultiple>0&&r.selectedCount>=r.maxMultiple)}function u(e,t,r){let i=n.p(e,t,0);return!(r&&n.d(r)>i)}function d(e,t,r){let i=n.p(t===11?e+1:e,t===11?0:t+1,1);return!(r&&n.d(r)<i)}function f(e,t){let r=n.p(e,t,1),i=n.p(e,t+1,0),a=(r.getDay()+6)%7,o=i.getDate();return{firstDayOfMonth:r,lastDayOfMonth:i,startingDay:a,numDays:o,numRows:Math.ceil((o+a)/7),numDaysPrevMonth:n.p(e,t,0).getDate(),initialWeek:n._(r)}}function p(e,t,n,r){let{startingDay:i,numDays:a}=r;return e===0&&t<i?`prev-month`:n>a?`next-month`:`current-month`}function m(e,t,n,r){let{startingDay:i,numDaysPrevMonth:a,numDays:o}=r;return e===`prev-month`?a-(i-t-1):e===`next-month`?n-o:n}function h(e){return typeof e==`string`&&(e=e.split(`,`)),e.length===1&&e[0]===``?[]:e.map(e=>n.m(e))}function g(e,t){let r=o({start:e,end:t}),i={};if(Array.isArray(r)&&r.length)for(let a=0;a<r.length;a++){let o=r[a],s=o>e&&o<t;i[n.a(o)]=s}return i}function _(e,t,n,r){if(t.length!==1)return!0;let i=o({start:t[0],end:e});if(!Array.isArray(i)||!i.length)return!0;for(let a=0;a<i.length;a++){for(let r of n??[])if(r>t[0]&&r<e)return!1;if((r??[]).includes(s(i[a]).toString()))return!1}return!0}function v(e,t){let r=n.a(e);return t.includes(r)?t:[...t,r]}function y(e,t){let r=n.a(e),i=t.indexOf(r);if(i===-1)return t;if(t.length===1)return[];let a=[...t];return a.splice(i,1),a}function b(e,t,r){let i=n.a(e);return t.includes(i)?y(e,t):r>0&&t.length>=r?t:v(e,t)}function x(e,t,r){let i=n.a(e),a=h(t);return t.includes(i)?t.indexOf(i)===0?[]:y(e,t):t.length>1||t.length===1&&(!_(e,a,r.excludedates,r.excludeweekdays)||a[0]>e)?[i]:v(e,t)}var S={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7};function C(e){let t=e.nodeName;return t===`INPUT`||t===`SELECT`||t===`BUTTON`&&!e.dataset?.date}function w(e,t,r){let a=i(e,t);if(!a)return null;let o=r(`button[data-date="${n.a(a)}"]`);for(;o instanceof HTMLButtonElement&&o.dataset.disabled;)if(a=i(a,t),o=r(`button[data-date="${n.a(a)}"]`),!o)return null;return a}function T(e){return S[e]??null}var E=class extends e.t{constructor(...e){super(...e),this.selected=[],this.multiple=r.multiple,this.maxMultiple=r.maxMultiple,this.range=r.range,this.earliest=r.earliest,this.latest=r.latest,this.excludedates=[],this.excludeweekdays=[],this.weeknumbers=r.weeknumbers,this.withcontrols=r.withcontrols,this.currentmonth=null,this.today=null,this._selected=[],this.inRange={},this.rangeHovered=null,this.year=0,this.month=0,this.week=0,this.currentmonthtouched=!1,this.focusedDate=null,this.selectableDates=[],this.tabIndexSet=0}get calendarStrings(){let e=this.pktStrings.get(`dates`),t=this.pktStrings.get(`calendar`);return{daysShort:this.dayStrings??e.daysShort,days:this.dayStringsLong??e.days,months:this.monthStrings??e.months,week:this.weekString??e.week,prevMonth:this.prevMonthString??t.prevMonth,nextMonth:this.nextMonthString??t.nextMonth}}get todayDate(){return this.today?n.m(this.today):n.g()}firstUpdated(e){this.addEventListener(`keydown`,this.handleKeydown)}disconnectedCallback(){this.removeEventListener(`keydown`,this.handleKeydown),super.disconnectedCallback()}updated(e){super.updated(e),e.has(`selected`)&&this.convertSelected()}convertSelected(){typeof this.selected==`string`&&(this.selected=this.selected.split(`,`)),this.selected.length===1&&this.selected[0]===``&&(this.selected=[]),this._selected=h(this.selected),this.range&&this.selected.length===2&&(this.inRange=g(this._selected[0],this._selected[1])),this.setCurrentMonth()}setCurrentMonth(){if(this.currentmonth===null&&!this.currentmonthtouched&&(this.currentmonthtouched=!0),this.selected.length&&this.selected[0]!==``){let e=n.m(this.selected[this.selected.length-1]);this.currentmonth=isNaN(e.getTime())?n.f(this.todayDate):e}else this.currentmonth===null&&(this.currentmonth=n.f(this.todayDate));(!this.currentmonth||isNaN(this.currentmonth.getTime()))&&(this.currentmonth=n.f(this.todayDate)),this.year=this.currentmonth.getFullYear(),this.month=this.currentmonth.getMonth()}handleKeydown(e){let t=T(e.key);t!==null&&this.handleArrowKey(e,t)}handleArrowKey(e,t){let r=e.target;if(C(r))return;if(e.preventDefault(),!this.focusedDate){this.focusOnCurrentDate();return}let i=w(this.focusedDate?n.d(this.focusedDate):n.p(this.year,this.month,1),t,this.querySelector.bind(this));if(i){let e=this.querySelector(`button[data-date="${n.a(i)}"]`);e instanceof HTMLButtonElement&&!e.dataset.disabled&&(this.focusedDate=n.a(i),e.focus())}}render(){return e._`
|
|
2
|
-
<div
|
|
3
|
-
class="pkt-calendar ${this.weeknumbers?`pkt-cal-weeknumbers`:``}"
|
|
4
|
-
@focusout=${this.closeEvent}
|
|
5
|
-
@keydown=${e=>{e.key===`Escape`&&(e.preventDefault(),this.close())}}
|
|
6
|
-
>
|
|
7
|
-
<nav class="pkt-cal-month-nav">
|
|
8
|
-
${this.renderMonthNavButton(`prev`)} ${this.renderMonthNav()}
|
|
9
|
-
${this.renderMonthNavButton(`next`)}
|
|
10
|
-
</nav>
|
|
11
|
-
<table
|
|
12
|
-
class="pkt-cal-days pkt-txt-12-medium pkt-calendar__body"
|
|
13
|
-
role="grid"
|
|
14
|
-
?aria-multiselectable=${this.range||this.multiple}
|
|
15
|
-
>
|
|
16
|
-
<thead>
|
|
17
|
-
${this.renderDayNames()}
|
|
18
|
-
</thead>
|
|
19
|
-
<tbody>
|
|
20
|
-
${this.renderCalendarBody()}
|
|
21
|
-
</tbody>
|
|
22
|
-
</table>
|
|
23
|
-
</div>
|
|
24
|
-
`}renderMonthNavButton(t){let n=t===`prev`,r=n?this.isPrevMonthAllowed():this.isNextMonthAllowed(),{prevMonth:i,nextMonth:a}=this.calendarStrings,o=n?i:a,s=n?`chevron-thin-left`:`chevron-thin-right`,c=n?`pkt-calendar__prev-month`:`pkt-calendar__next-month`,l=n?()=>this.prevMonth():()=>this.nextMonth();return e._`<div>
|
|
25
|
-
<button
|
|
26
|
-
type="button"
|
|
27
|
-
aria-label="${o}"
|
|
28
|
-
@click=${()=>r&&l()}
|
|
29
|
-
@keydown=${e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r&&l())}}
|
|
30
|
-
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only ${c} ${r?``:`pkt-invisible`}"
|
|
31
|
-
.data-disabled=${r?e.h:`disabled`}
|
|
32
|
-
?aria-disabled=${!r}
|
|
33
|
-
tabindex=${r?`0`:`-1`}
|
|
34
|
-
>
|
|
35
|
-
<pkt-icon class="pkt-btn__icon" name="${s}"></pkt-icon>
|
|
36
|
-
<span class="pkt-btn__text">${o}</span>
|
|
37
|
-
</button>
|
|
38
|
-
</div>`}renderDayNames(){let t=[];this.weeknumbers&&t.push(e._`<th><div class="pkt-calendar__week-number">${this.calendarStrings.week}</div></th>`);let{days:n,daysShort:r}=this.calendarStrings;for(let i=0;i<r.length;i++)t.push(e._`<th>
|
|
39
|
-
<div class="pkt-calendar__day-name" aria-label="${n[i]}">${r[i]}</div>
|
|
40
|
-
</th>`);return e._`<tr class="pkt-cal-week-row">
|
|
41
|
-
${t}
|
|
42
|
-
</tr>`}renderMonthNav(){let t=this.pktStrings.get(`dates`);return this.withcontrols?e._`<div class="pkt-cal-month-picker">
|
|
43
|
-
<label for="${this.id}-monthnav" class="pkt-hide">${t.month}</label>
|
|
44
|
-
<select
|
|
45
|
-
aria-label="${t.month}"
|
|
46
|
-
class="pkt-input pkt-input-compact"
|
|
47
|
-
id="${this.id}-monthnav"
|
|
48
|
-
@change=${e=>{e.stopImmediatePropagation();let t=e.target;this.changeMonth(this.year,parseInt(t.value))}}
|
|
49
|
-
>
|
|
50
|
-
${this.calendarStrings.months.map((t,n)=>e._`<option value=${n} ?selected=${this.month===n}>${t}</option>`)}
|
|
51
|
-
</select>
|
|
52
|
-
<label for="${this.id}-yearnav" class="pkt-hide">${t.year}</label>
|
|
53
|
-
<input
|
|
54
|
-
aria-label="${t.year}"
|
|
55
|
-
class="pkt-input pkt-cal-input-year pkt-input-compact"
|
|
56
|
-
id="${this.id}-yearnav"
|
|
57
|
-
type="number"
|
|
58
|
-
size="4"
|
|
59
|
-
placeholder="0000"
|
|
60
|
-
@change=${e=>{e.stopImmediatePropagation();let t=e.target;this.changeMonth(parseInt(t.value),this.month)}}
|
|
61
|
-
.value=${this.year}
|
|
62
|
-
/>
|
|
63
|
-
</div>`:e._`<div class="pkt-txt-16-medium pkt-calendar__month-title" aria-live="polite">
|
|
64
|
-
${this.calendarStrings.months[this.month]} ${this.year}
|
|
65
|
-
</div>`}getDayViewData(e,t){let r=n.p(this.year,this.month,e),i=n.a(r),a=i===n.a(t),o=this.selected.includes(i),s=this.isDayDisabled(r,o),c=this.calculateTabIndex(i,s,e);return{currentDate:r,currentDateISO:i,isToday:a,isSelected:o,isDisabled:s,ariaLabel:n.o(r),tabindex:c}}getDateConstraints(){return{earliest:this.earliest,latest:this.latest,excludedates:this.excludedates,excludeweekdays:this.excludeweekdays}}isDayDisabled(e,t){return l(e,t,this.getDateConstraints(),{multiple:this.multiple,maxMultiple:this.maxMultiple,selectedCount:this.selected.length})}calculateTabIndex(e,t,n){return this.focusedDate?this.focusedDate===e&&!t?`0`:`-1`:!t&&this.tabIndexSet===0?(this.tabIndexSet=n,`0`):this.tabIndexSet===n?`0`:`-1`}getDayCellClasses(e){let{currentDateISO:t,isToday:r,isSelected:i}=e,a=this.range&&(this.selected.length===2||this.rangeHovered!==null)&&t===this.selected[0],o=this.range&&this.selected.length===2&&t===this.selected[1];return{"pkt-cal-today":r,"pkt-cal-selected":i,"pkt-cal-in-range":this.inRange[t],"pkt-cal-excluded":this.isExcluded(e.currentDate),"pkt-cal-in-range-first":a,"pkt-cal-in-range-last":o,"pkt-cal-range-hover":this.rangeHovered!==null&&t===n.a(this.rangeHovered)}}getDayButtonClasses(e){let{currentDateISO:t,isToday:r,isSelected:i,isDisabled:a}=e,o=this.range&&(this.selected.length===2||this.rangeHovered!==null)&&t===this.selected[0],s=this.range&&this.selected.length===2&&t===this.selected[1];return{"pkt-calendar__date":!0,"pkt-calendar__date--today":r,"pkt-calendar__date--selected":i,"pkt-calendar__date--disabled":a,"pkt-calendar__date--in-range":this.inRange[t],"pkt-calendar__date--in-range-hover":this.rangeHovered!==null&&t===n.a(this.rangeHovered),"pkt-calendar__date--range-start":o,"pkt-calendar__date--range-end":s}}handleDayFocus(e,t){this.range&&!this.isExcluded(e)&&this.handleRangeHover(e),this.focusedDate=t}renderDayView(n,r){let i=this.getDayViewData(n,r),{currentDate:a,currentDateISO:o,isSelected:s,isDisabled:c,ariaLabel:l,tabindex:u}=i;this.selectableDates.push({currentDateISO:o,isDisabled:c,tabindex:u});let d=this.getDayCellClasses(i),f=this.getDayButtonClasses(i);return e._`<td class=${t.t(d)}>
|
|
66
|
-
<button
|
|
67
|
-
type="button"
|
|
68
|
-
aria-pressed=${s?`true`:`false`}
|
|
69
|
-
?disabled=${c}
|
|
70
|
-
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only ${t.t(f)}"
|
|
71
|
-
@mouseover=${()=>this.range&&!this.isExcluded(a)&&this.handleRangeHover(a)}
|
|
72
|
-
@focus=${()=>this.handleDayFocus(a,o)}
|
|
73
|
-
aria-label="${l}"
|
|
74
|
-
tabindex=${u}
|
|
75
|
-
data-disabled=${c?`disabled`:e.h}
|
|
76
|
-
data-date=${o}
|
|
77
|
-
@keydown=${e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.handleDateSelect(a))}}
|
|
78
|
-
@click=${e=>{c||(e.preventDefault(),this.handleDateSelect(a))}}
|
|
79
|
-
>
|
|
80
|
-
<span class="pkt-btn__text pkt-txt-14-light">${n}</span>
|
|
81
|
-
</button>
|
|
82
|
-
</td>`}renderEmptyDayCell(t){return e._`<td class="pkt-cal-other">
|
|
83
|
-
<div
|
|
84
|
-
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
85
|
-
data-disabled="disabled"
|
|
86
|
-
>
|
|
87
|
-
<span class="pkt-btn__text pkt-txt-14-light">${t}</span>
|
|
88
|
-
</div>
|
|
89
|
-
</td>`}renderWeekRow(t){return e._`<tr class="pkt-cal-week-row" role="row">
|
|
90
|
-
${t}
|
|
91
|
-
</tr>`}renderCalendarBody(){let t=this.todayDate,n=f(this.year,this.month);this.selectableDates=[],this.tabIndexSet=0;let r=1;this.week=n.initialWeek;let i=[];for(let a=0;a<n.numRows;a++){let o=[];this.weeknumbers&&o.push(e._`<td class="pkt-cal-week">${this.week}</td>`),this.week++;for(let e=0;e<7;e++){let i=p(a,e,r,n);if(i===`current-month`)o.push(this.renderDayView(r,t)),r++;else{let t=m(i,e,r,n);o.push(this.renderEmptyDayCell(t)),i===`next-month`&&r++}}i.push(this.renderWeekRow(o))}return i}isExcluded(e){return c(e,this.getDateConstraints())}isPrevMonthAllowed(){return u(this.year,this.month,this.earliest)}prevMonth(){let e=this.month===0?11:this.month-1,t=this.month===0?this.year-1:this.year;this.changeMonth(t,e)}isNextMonthAllowed(){return d(this.year,this.month,this.latest)}nextMonth(){let e=this.month===11?0:this.month+1,t=this.month===11?this.year+1:this.year;this.changeMonth(t,e)}changeMonth(e,t){this.year=typeof e==`string`?parseInt(e):e,this.month=typeof t==`string`?parseInt(t):t,this.currentmonth=n.f(new Date(this.year,this.month,1)),this.tabIndexSet=0,this.focusedDate=null,this.selectableDates=[]}emptySelected(){this.selected=[],this._selected=[],this.inRange={}}normalizeSelected(){return typeof this.selected==`string`?this.selected.split(`,`):this.selected}addToSelected(e){this.selected=v(e,this.normalizeSelected()),this._selected=h(this.selected),this.range&&this.selected.length===2&&(this.convertSelected(),this.close())}removeFromSelected(e){this.selected=y(e,this.normalizeSelected()),this._selected=h(this.selected)}toggleSelected(e){this.selected=b(e,this.normalizeSelected(),this.maxMultiple),this._selected=h(this.selected)}isRangeAllowed(e){return _(e,this._selected,this.excludedates,this.excludeweekdays)}handleRangeSelect(e){return this.selected=x(e,this.normalizeSelected(),{excludedates:this.excludedates,excludeweekdays:this.excludeweekdays}),this._selected=h(this.selected),this.selected.length===2?(this.convertSelected(),this.close()):this.selected.length===1&&(this.inRange={}),Promise.resolve()}handleRangeHover(e){if(!this.range||this._selected.length!==1||!this.isRangeAllowed(e)||this._selected[0]>=e){this.rangeHovered=null;return}this.rangeHovered=e,this.inRange=g(this._selected[0],e)}handleDateSelect(e){return e?(this.range?this.handleRangeSelect(e):this.multiple?this.toggleSelected(e):(this.selected.includes(n.a(e))?this.emptySelected():(this.emptySelected(),this.addToSelected(e)),this.close()),this.dispatchEvent(new CustomEvent(`date-selected`,{detail:this.selected,bubbles:!0,composed:!0})),Promise.resolve()):Promise.resolve()}focusOnCurrentDate(){let e=n.a(n.f(this.todayDate)),t=this.querySelector(`button[data-date="${e}"]`);if(t instanceof HTMLButtonElement){this.focusedDate=e,t.focus();return}let r=this.selectableDates.find(e=>!e.isDisabled);if(r){let e=this.querySelector(`button[data-date="${r.currentDateISO}"]`);e instanceof HTMLButtonElement&&(this.focusedDate=r.currentDateISO,e.focus())}}closeEvent(e){let t=e.target,n=e.relatedTarget;this.contains(n)||t.classList.contains(`pkt-invisible`)||t.closest(`.pkt-cal-month-picker`)||this.close()}close(){this.dispatchEvent(new CustomEvent(`close`,{detail:!0,bubbles:!0,composed:!0}))}};e.n([e.u({converter:n.t.csvToArray})],E.prototype,`selected`,void 0),e.n([e.u({type:Boolean})],E.prototype,`multiple`,void 0),e.n([e.u({type:Number,attribute:`max-multiple`})],E.prototype,`maxMultiple`,void 0),e.n([e.u({type:Boolean})],E.prototype,`range`,void 0),e.n([e.u({type:String})],E.prototype,`earliest`,void 0),e.n([e.u({type:String})],E.prototype,`latest`,void 0),e.n([e.u({converter:n.t.stringsToDate})],E.prototype,`excludedates`,void 0),e.n([e.u({converter:n.t.csvToArray})],E.prototype,`excludeweekdays`,void 0),e.n([e.u({type:Boolean})],E.prototype,`weeknumbers`,void 0),e.n([e.u({type:Boolean})],E.prototype,`withcontrols`,void 0),e.n([e.u({converter:n.t.stringToDate})],E.prototype,`currentmonth`,void 0),e.n([e.u({type:String})],E.prototype,`today`,void 0),e.n([e.u({type:Array,attribute:`day-strings`})],E.prototype,`dayStrings`,void 0),e.n([e.u({type:Array,attribute:`day-strings-long`})],E.prototype,`dayStringsLong`,void 0),e.n([e.u({type:Array,attribute:`month-strings`})],E.prototype,`monthStrings`,void 0),e.n([e.u({type:String,attribute:`week-string`})],E.prototype,`weekString`,void 0),e.n([e.u({type:String,attribute:`prev-month-string`})],E.prototype,`prevMonthString`,void 0),e.n([e.u({type:String,attribute:`next-month-string`})],E.prototype,`nextMonthString`,void 0),e.n([e.u({type:Array})],E.prototype,`_selected`,void 0),e.n([e.l()],E.prototype,`inRange`,void 0),e.n([e.u({type:Date})],E.prototype,`rangeHovered`,void 0),e.n([e.u({type:Number})],E.prototype,`year`,void 0),e.n([e.u({type:Number})],E.prototype,`month`,void 0),e.n([e.u({type:Number})],E.prototype,`week`,void 0),e.n([e.l()],E.prototype,`currentmonthtouched`,void 0),e.n([e.l()],E.prototype,`focusedDate`,void 0);try{e.d(`pkt-calendar`)(E)}catch{console.warn(`Forsøker å definere <pkt-calendar>, men den er allerede definert`)}var D=E;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return D}});
|