@oslokommune/punkt-elements 16.26.7 → 17.0.2
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 +110 -0
- package/dist/accordion-CbXDxOho.cjs +47 -0
- package/dist/{accordion-CBdIk9gw.js → accordion-DEUHQ4JD.js} +45 -35
- package/dist/{alert-HHTGY0sp.js → alert-CbtVGrHD.js} +31 -17
- package/dist/{alert-B8dLsiTz.cjs → alert-CkUnbPdA.cjs} +5 -5
- package/dist/base-elements/input-element.d.ts +1 -0
- package/dist/button-Cod17rKo.js +115 -0
- package/dist/{button-B5tQpKeG.cjs → button-gvDXtBMC.cjs} +5 -2
- package/dist/{calendar-DIzGBdbh.cjs → calendar-BVXW8DqC.cjs} +1 -1
- package/dist/{calendar-CjlUA-Lb.js → calendar-CjC4qlh6.js} +1 -1
- package/dist/{checkbox-Bt_sC_90.cjs → checkbox-8uxbeU30.cjs} +1 -1
- package/dist/{checkbox-D03BC2Va.js → checkbox-DJDphhqz.js} +1 -1
- package/dist/{combobox-CoQBTWqL.js → combobox-Du5yr-xM.js} +16 -2
- package/dist/combobox-hKrbYLUe.cjs +136 -0
- package/dist/components/accordion/accordion-context.d.ts +7 -0
- package/dist/components/accordion/accordion.d.ts +2 -0
- package/dist/components/accordion/accordionitem.d.ts +1 -0
- package/dist/components/alert/alert.d.ts +5 -0
- package/dist/components/alert/alert.test.d.ts +1 -0
- package/dist/components/button/button.d.ts +4 -1
- package/dist/components/datepicker/datepicker-base.d.ts +2 -0
- package/dist/components/datepicker/datepicker-utils.d.ts +2 -2
- package/dist/components/footer/footer-base.d.ts +44 -0
- package/dist/components/footer/footer-simple.d.ts +20 -0
- package/dist/components/footer/footer.accessibility.test.d.ts +0 -0
- package/dist/components/footer/footer.d.ts +22 -0
- package/dist/components/footer/footer.test.d.ts +0 -0
- package/dist/components/footer/index.d.ts +3 -0
- package/dist/components/footer/types.d.ts +16 -0
- package/dist/components/header/header-chrome-controller.d.ts +44 -0
- package/dist/components/header/header-global.accessibility.test.d.ts +0 -0
- package/dist/components/header/header-global.d.ts +78 -0
- package/dist/components/header/header-global.test.d.ts +0 -0
- package/dist/components/header/header-service.accessibility.test.d.ts +0 -0
- package/dist/components/header/header-service.d.ts +6 -21
- package/dist/components/header/header-service.test.d.ts +1 -1
- package/dist/components/header/header.d.ts +11 -3
- package/dist/components/header/header.test.d.ts +0 -0
- package/dist/components/header/index.d.ts +2 -1
- package/dist/components/header/types.d.ts +28 -2
- package/dist/components/header-menu/header-menu.d.ts +4 -5
- package/dist/components/header-menu/types.d.ts +1 -1
- package/dist/components/index.d.ts +5 -3
- package/dist/components/input-wrapper/input-wrapper.d.ts +2 -0
- package/dist/components/input-wrapper/input-wrapper.test.d.ts +1 -0
- package/dist/components/searchinput/searchinput.d.ts +5 -0
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/select.d.ts +2 -2
- package/dist/components/select/select.test.d.ts +1 -0
- package/dist/components/textarea/textarea.test.d.ts +2 -0
- package/dist/components/textinput/textinput.test.d.ts +1 -0
- package/dist/components/timepicker/timepicker.d.ts +2 -0
- package/dist/components/timepicker/timepicker.test.d.ts +3 -0
- package/dist/consent--Nw43WFU.cjs +18 -0
- package/dist/{consent-D5sY6JK3.js → consent-B2hSTCGC.js} +14 -7
- package/dist/consume-BiOhrhEy.js +167 -0
- package/dist/consume-DKf5SmP9.cjs +1 -0
- package/dist/{converters-BKGBRBpS.js → converters-BBfsEJV5.js} +25 -25
- package/dist/{converters-9jHlXDyy.cjs → converters-Cd0fPEly.cjs} +1 -1
- package/dist/{datepicker-BE5Ll0W4.js → datepicker--Fq8q-J3.js} +30 -12
- package/dist/{datepicker-x4xM3KQz.cjs → datepicker-CEoBYTBU.cjs} +11 -7
- package/dist/docs/components/alert.d.ts +3 -0
- package/dist/docs/components/footer.d.ts +9 -0
- package/dist/docs/components/form-sizes.d.ts +10 -0
- package/dist/docs/components/header-global-full.d.ts +20 -0
- package/dist/docs/components/header-global.d.ts +14 -0
- package/dist/docs/components/searchinput.d.ts +6 -3
- package/dist/fetch-header-footer-data-Pc32etrk.js +88 -0
- package/dist/fetch-header-footer-data-xohWFmYC.cjs +1 -0
- package/dist/fileupload-CGKUJrlj.cjs +401 -0
- package/dist/{fileupload-2hf8YNhO.js → fileupload-D4gQN64T.js} +156 -176
- package/dist/focus-trap-DG3pEuyJ.js +60 -0
- package/dist/focus-trap-DSv4Ifqm.cjs +1 -0
- package/dist/footer-BIrJeRuZ.js +303 -0
- package/dist/footer-Ber-jqM1.cjs +114 -0
- package/dist/footer.d.ts +1 -0
- package/dist/header-BFk1an4z.cjs +465 -0
- package/dist/header-Deg_LGJo.js +1287 -0
- package/dist/header-menu-BHqK4QA6.cjs +126 -0
- package/dist/{header-menu-C8b5vd3n.js → header-menu-GFtJKM4j.js} +25 -97
- package/dist/{helptext-OfqH5npD.js → helptext-C_brWCIT.js} +1 -1
- package/dist/{helptext-eckq4JEX.cjs → helptext-Cq5rNaAC.cjs} +1 -1
- package/dist/{input-element-ZGOWsvKM.cjs → input-element-B0qLbEdF.cjs} +1 -1
- package/dist/{input-element-BFHpeoV8.js → input-element-C0RnXi-J.js} +5 -2
- package/dist/{input-wrapper-DwwE0JcO.js → input-wrapper-BweP6t3O.js} +12 -0
- package/dist/{input-wrapper-BRjQB4zM.cjs → input-wrapper-DPkkiG7S.cjs} +13 -11
- package/dist/{input-wrapper-DaA98B5l.js → input-wrapper-fWV5P4MN.js} +22 -15
- package/dist/{input-wrapper-LcZjpt0L.cjs → input-wrapper-wh3fWIhk.cjs} +1 -1
- package/dist/modal-CPnFteYS.cjs +35 -0
- package/dist/{modal-C6pScpdG.js → modal-xNK_wpHk.js} +11 -20
- package/dist/pkt-accordion.cjs +1 -1
- package/dist/pkt-accordion.js +1 -1
- package/dist/pkt-alert.cjs +1 -1
- package/dist/pkt-alert.js +1 -1
- package/dist/pkt-button.cjs +1 -1
- package/dist/pkt-button.js +1 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-checkbox.cjs +1 -1
- package/dist/pkt-checkbox.js +1 -1
- package/dist/pkt-combobox.cjs +1 -1
- package/dist/pkt-combobox.js +1 -1
- package/dist/pkt-consent.cjs +1 -1
- package/dist/pkt-consent.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-fileupload.cjs +1 -1
- package/dist/pkt-fileupload.js +1 -1
- package/dist/pkt-footer.cjs +1 -0
- package/dist/pkt-footer.js +2 -0
- package/dist/pkt-header-menu.cjs +1 -1
- package/dist/pkt-header-menu.js +1 -1
- package/dist/pkt-header.cjs +1 -1
- package/dist/pkt-header.js +2 -2
- package/dist/pkt-helptext.cjs +1 -1
- package/dist/pkt-helptext.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +27 -26
- package/dist/pkt-input-wrapper.cjs +1 -1
- package/dist/pkt-input-wrapper.js +1 -1
- package/dist/pkt-modal.cjs +1 -1
- package/dist/pkt-modal.js +1 -1
- package/dist/pkt-radiobutton.cjs +1 -1
- package/dist/pkt-radiobutton.js +1 -1
- package/dist/pkt-searchinput.cjs +1 -1
- package/dist/pkt-searchinput.js +1 -1
- package/dist/pkt-select.cjs +1 -1
- package/dist/pkt-select.js +1 -1
- package/dist/pkt-tabs.cjs +1 -1
- package/dist/pkt-tabs.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/{radiobutton-DGO6H2Ki.js → radiobutton-C6htwDrT.js} +1 -1
- package/dist/{radiobutton-DY1WWepJ.cjs → radiobutton-DjWBoSHv.cjs} +1 -1
- package/dist/scroll-lock-BN8lOhV5.cjs +1 -0
- package/dist/scroll-lock-DAbNKAUy.js +18 -0
- package/dist/searchinput-CfUVfpqL.js +156 -0
- package/dist/searchinput-DGjeN1YI.cjs +60 -0
- package/dist/{select-D4_HQFkh.cjs → select-CZvAW7W2.cjs} +2 -1
- package/dist/{select-BwHUIlwQ.js → select-CsBXXbLP.js} +4 -3
- package/dist/setupTests.d.ts +0 -0
- package/dist/shared-types/footer.d.ts +95 -0
- package/dist/shared-types/{header-menu.d.ts → header-footer.d.ts} +51 -4
- package/dist/shared-types/header.d.ts +1 -1
- package/dist/shared-types/index.d.ts +6 -4
- package/dist/shared-types/searchinput.d.ts +2 -0
- package/dist/shared-types/select.d.ts +3 -2
- package/dist/shared-types/size.d.ts +4 -0
- package/dist/shared-types/timepicker.d.ts +0 -6
- package/dist/shared-utils/datepicker-utils.d.ts +5 -4
- package/dist/shared-utils/fileupload/focus-trap.d.ts +4 -10
- package/dist/shared-utils/focus-trap/index.d.ts +22 -0
- package/dist/shared-utils/{header-menu → header-footer}/example-data.d.ts +5 -4
- package/dist/shared-utils/header-footer/external-domain.d.ts +26 -0
- package/dist/shared-utils/{header-menu → header-footer}/fetch-header-footer-data.d.ts +6 -2
- package/dist/shared-utils/{header-menu → header-footer}/index.d.ts +2 -1
- package/dist/shared-utils/{header-menu → header-footer}/select-megamenu.d.ts +1 -1
- package/dist/shared-utils/scroll-lock/index.d.ts +24 -0
- package/dist/tabs-BqrKLCjd.js +214 -0
- package/dist/tabs-q62MK_-r.cjs +40 -0
- package/dist/{textarea-D6M7ZhtA.js → textarea-Cm392CEI.js} +5 -3
- package/dist/{textarea-Bt_Zs8gq.cjs → textarea-sTcZxOIB.cjs} +3 -2
- package/dist/{textinput-EDKjcUdg.cjs → textinput-DqJbTglM.cjs} +3 -2
- package/dist/{textinput-oU2EvFsi.js → textinput-TSPcBcih.js} +5 -3
- package/dist/{timepicker-CgOL2sd9.cjs → timepicker-CqFYMV8q.cjs} +8 -7
- package/dist/{timepicker-_G0V_HV3.js → timepicker-DWbgTDKq.js} +10 -9
- package/package.json +3 -3
- package/src/components/accordion/accordion-context.ts +8 -0
- package/src/components/accordion/accordion.test.ts +44 -0
- package/src/components/accordion/accordion.ts +13 -3
- package/src/components/accordion/accordionitem.ts +9 -1
- package/src/components/alert/alert.test.ts +51 -2
- package/src/components/alert/alert.ts +11 -5
- package/src/components/breadcrumbs/breadcrumbs.test.ts +11 -3
- package/src/components/button/button.test.ts +23 -0
- package/src/components/button/button.ts +28 -3
- package/src/components/combobox/combobox.core.test.ts +20 -0
- package/src/components/combobox/combobox.ts +2 -0
- package/src/components/consent/consent.test.ts +6 -3
- package/src/components/consent/consent.ts +15 -7
- package/src/components/datepicker/datepicker-base.ts +5 -1
- package/src/components/datepicker/datepicker-utils.test.ts +10 -0
- package/src/components/datepicker/datepicker.core.test.ts +17 -0
- package/src/components/datepicker/datepicker.ts +8 -0
- package/src/components/footer/footer-base.ts +238 -0
- package/src/components/footer/footer-simple.ts +71 -0
- package/src/components/footer/footer.accessibility.test.ts +66 -0
- package/src/components/footer/footer.test.ts +238 -0
- package/src/components/footer/footer.ts +81 -0
- package/src/components/footer/index.ts +4 -0
- package/src/components/footer/types.ts +21 -0
- package/src/components/header/header-chrome-controller.ts +123 -0
- package/src/components/header/header-global.accessibility.test.ts +110 -0
- package/src/components/header/header-global.test.ts +329 -0
- package/src/components/header/header-global.ts +648 -0
- package/src/components/header/header-service.accessibility.test.ts +79 -0
- package/src/components/header/header-service.test.ts +32 -12
- package/src/components/header/header-service.ts +38 -162
- package/src/components/header/header-user-menu.ts +0 -1
- package/src/components/header/header.test.ts +84 -0
- package/src/components/header/header.ts +52 -5
- package/src/components/header/index.ts +6 -0
- package/src/components/header/types.ts +38 -0
- package/src/components/header-menu/header-menu.test.ts +131 -10
- package/src/components/header-menu/header-menu.ts +23 -24
- package/src/components/header-menu/types.ts +1 -1
- package/src/components/index.ts +18 -2
- package/src/components/input-wrapper/input-wrapper.test.ts +45 -0
- package/src/components/input-wrapper/input-wrapper.ts +17 -9
- package/src/components/modal/modal.ts +8 -9
- package/src/components/searchinput/searchinput.test.ts +43 -0
- package/src/components/searchinput/searchinput.ts +29 -12
- package/src/components/select/index.ts +1 -1
- package/src/components/select/select.test.ts +28 -0
- package/src/components/select/select.ts +4 -3
- package/src/components/textarea/textarea.test.ts +16 -0
- package/src/components/textarea/textarea.ts +3 -1
- package/src/components/textinput/textinput.test.ts +28 -0
- package/src/components/textinput/textinput.ts +3 -1
- package/src/components/timepicker/timepicker.test.ts +26 -0
- package/src/components/timepicker/timepicker.ts +12 -6
- package/dist/accordion-FISAiAbX.cjs +0 -47
- package/dist/button-C_YzTSuU.js +0 -96
- package/dist/combobox-D6H9rWPV.cjs +0 -135
- package/dist/consent-X3wvhteO.cjs +0 -10
- package/dist/fileupload-BLVrslUX.cjs +0 -401
- package/dist/header-CFrsaq0c.cjs +0 -310
- package/dist/header-D_xvPR4R.js +0 -801
- package/dist/header-menu-DMdP_c6X.cjs +0 -126
- package/dist/modal-DKU7PnjJ.cjs +0 -35
- package/dist/searchinput-CyO5k4Q4.js +0 -148
- package/dist/searchinput-DG6YetL1.cjs +0 -60
- package/dist/shared-utils/modal-scroll-lock.d.ts +0 -10
- package/dist/tabs-CGo0ODPa.cjs +0 -40
- package/dist/tabs-ChdR0D1C.js +0 -379
- /package/dist/shared-utils/{header-menu → header-footer}/icon-map.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.2",
|
|
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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@babel/plugin-transform-private-property-in-object": "^7.27.1",
|
|
42
42
|
"@babel/preset-env": "^7.28.3",
|
|
43
43
|
"@babel/preset-typescript": "^7.28.3",
|
|
44
|
-
"@oslokommune/punkt-assets": "^
|
|
44
|
+
"@oslokommune/punkt-assets": "^17.0.0",
|
|
45
45
|
"@testing-library/dom": "^10.4.1",
|
|
46
46
|
"@testing-library/jest-dom": "^6.9.1",
|
|
47
47
|
"@types/jest-axe": "^3.5.9",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
81
81
|
},
|
|
82
82
|
"license": "MIT",
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "53b7f70c8773eaf41b4d216be78bbaa6ea1e48ff"
|
|
84
84
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext } from '@lit/context'
|
|
2
|
+
import type { TAccordionSkin } from 'shared-types'
|
|
3
|
+
|
|
4
|
+
export interface AccordionContext {
|
|
5
|
+
skin?: TAccordionSkin
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const accordionContext = createContext<AccordionContext>(Symbol('pkt-accordion-context'))
|
|
@@ -170,6 +170,50 @@ describe('PktAccordion', () => {
|
|
|
170
170
|
})
|
|
171
171
|
})
|
|
172
172
|
|
|
173
|
+
test('propagates plus-minus skin to items via context', async () => {
|
|
174
|
+
const container = await createAccordion('skin="plus-minus"')
|
|
175
|
+
|
|
176
|
+
const accordion = container.querySelector('pkt-accordion') as PktAccordion
|
|
177
|
+
const item = container.querySelector('pkt-accordion-item') as PktAccordionItem
|
|
178
|
+
await accordion.updateComplete
|
|
179
|
+
await item.updateComplete
|
|
180
|
+
|
|
181
|
+
expect(container.querySelector('.pkt-accordion-item__icon--plus')).toBeInTheDocument()
|
|
182
|
+
expect(container.querySelector('.pkt-accordion-item__icon--minus')).toBeInTheDocument()
|
|
183
|
+
expect(container.querySelector('[name="chevron-thin-down"]')).not.toBeInTheDocument()
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('updates item icons when skin property changes', async () => {
|
|
187
|
+
const container = await createAccordion('skin="outlined"')
|
|
188
|
+
|
|
189
|
+
const accordion = container.querySelector('pkt-accordion') as PktAccordion
|
|
190
|
+
const item = container.querySelector('pkt-accordion-item') as PktAccordionItem
|
|
191
|
+
await accordion.updateComplete
|
|
192
|
+
await item.updateComplete
|
|
193
|
+
|
|
194
|
+
expect(container.querySelector('[name="chevron-thin-down"]')).toBeInTheDocument()
|
|
195
|
+
expect(container.querySelector('.pkt-accordion-item__icon--plus')).not.toBeInTheDocument()
|
|
196
|
+
|
|
197
|
+
accordion.skin = 'plus-minus'
|
|
198
|
+
await accordion.updateComplete
|
|
199
|
+
await item.updateComplete
|
|
200
|
+
|
|
201
|
+
expect(container.querySelector('[name="chevron-thin-down"]')).not.toBeInTheDocument()
|
|
202
|
+
expect(container.querySelector('.pkt-accordion-item__icon--plus')).toBeInTheDocument()
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('item skin property overrides accordion skin', async () => {
|
|
206
|
+
const container = await createAccordion('skin="plus-minus"', 'skin="outlined"')
|
|
207
|
+
|
|
208
|
+
const accordion = container.querySelector('pkt-accordion') as PktAccordion
|
|
209
|
+
const item = container.querySelector('pkt-accordion-item') as PktAccordionItem
|
|
210
|
+
await accordion.updateComplete
|
|
211
|
+
await item.updateComplete
|
|
212
|
+
|
|
213
|
+
expect(container.querySelector('[name="chevron-thin-down"]')).toBeInTheDocument()
|
|
214
|
+
expect(container.querySelector('.pkt-accordion-item__icon--plus')).not.toBeInTheDocument()
|
|
215
|
+
})
|
|
216
|
+
|
|
173
217
|
test('updates accordion item names when name property changes', async () => {
|
|
174
218
|
const container = await createAccordionWithMultipleItems()
|
|
175
219
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { provide } from '@lit/context'
|
|
1
2
|
import { html, LitElement } from 'lit'
|
|
2
|
-
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
3
4
|
import { classMap } from 'lit/directives/class-map.js'
|
|
4
5
|
import type { TAccordionSkin } from 'shared-types'
|
|
5
6
|
|
|
7
|
+
import { accordionContext, type AccordionContext } from './accordion-context'
|
|
8
|
+
|
|
6
9
|
export type TPktAccordionSkin = TAccordionSkin
|
|
7
10
|
|
|
8
11
|
export interface IPktAccordion {
|
|
@@ -24,11 +27,18 @@ export class PktAccordion extends LitElement implements IPktAccordion {
|
|
|
24
27
|
'borderless'
|
|
25
28
|
@property({ type: String, reflect: true, attribute: 'name' }) name: string = ''
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
// Deler skin med pkt-accordion-item-children via context
|
|
31
|
+
@provide({ context: accordionContext })
|
|
32
|
+
@state()
|
|
33
|
+
private context: AccordionContext = { skin: this.skin }
|
|
34
|
+
|
|
35
|
+
willUpdate(changedProperties: Map<string, any>) {
|
|
28
36
|
if (changedProperties.has('skin')) {
|
|
29
|
-
this.
|
|
37
|
+
this.context = { ...this.context, skin: this.skin }
|
|
30
38
|
}
|
|
39
|
+
}
|
|
31
40
|
|
|
41
|
+
updated(changedProperties: Map<string, any>) {
|
|
32
42
|
if (changedProperties.has('name')) {
|
|
33
43
|
this.updateAccordionItemNames()
|
|
34
44
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { PktElementWithSlot } from '@/base-elements/element-with-slot'
|
|
2
2
|
import { slotContent } from '@/directives/slot-content'
|
|
3
|
+
import { consume } from '@lit/context'
|
|
3
4
|
import { html, PropertyValues } from 'lit'
|
|
4
5
|
import { customElement, property } from 'lit/decorators.js'
|
|
5
6
|
import { createRef, Ref, ref } from 'lit/directives/ref.js'
|
|
6
7
|
import { TPktAccordionSkin } from './accordion'
|
|
8
|
+
import { accordionContext, type AccordionContext } from './accordion-context'
|
|
7
9
|
import { classMap } from 'lit/directives/class-map.js'
|
|
8
10
|
import { ifDefined } from 'lit/directives/if-defined.js'
|
|
9
11
|
|
|
@@ -32,6 +34,11 @@ export class PktAccordionItem extends PktElementWithSlot implements IPktAccordio
|
|
|
32
34
|
@property({ type: Boolean, reflect: true }) isOpen: boolean = false
|
|
33
35
|
@property({ type: String, reflect: true }) name: string | undefined = undefined
|
|
34
36
|
|
|
37
|
+
// Skin fra pkt-accordion-forelder; egen skin-property overstyrer
|
|
38
|
+
@consume({ context: accordionContext, subscribe: true })
|
|
39
|
+
@property({ attribute: false })
|
|
40
|
+
private context?: AccordionContext
|
|
41
|
+
|
|
35
42
|
accordionItemRef: Ref<HTMLDivElement> = createRef()
|
|
36
43
|
|
|
37
44
|
constructor() {
|
|
@@ -51,7 +58,8 @@ export class PktAccordionItem extends PktElementWithSlot implements IPktAccordio
|
|
|
51
58
|
[`pkt-accordion-item--${this.skin}`]: !!this.skin,
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
const
|
|
61
|
+
const actualSkin = this.skin ?? this.context?.skin
|
|
62
|
+
const isPlusMinus = actualSkin === 'plus-minus'
|
|
55
63
|
|
|
56
64
|
return html`
|
|
57
65
|
<details
|
|
@@ -15,6 +15,7 @@ export interface AlertTestConfig extends BaseTestConfig {
|
|
|
15
15
|
date?: string
|
|
16
16
|
closeAlert?: boolean
|
|
17
17
|
ariaLive?: string
|
|
18
|
+
size?: string
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
// Use shared framework
|
|
@@ -104,7 +105,7 @@ describe('PktAlert', () => {
|
|
|
104
105
|
const alertDiv = alert.querySelector('.pkt-alert')
|
|
105
106
|
expect(alertDiv).toHaveClass('pkt-alert')
|
|
106
107
|
expect(alertDiv).toHaveClass('pkt-alert--info')
|
|
107
|
-
expect(alertDiv).
|
|
108
|
+
expect(alertDiv).toHaveClass('pkt-alert--medium')
|
|
108
109
|
})
|
|
109
110
|
|
|
110
111
|
test('applies different skin properties correctly', async () => {
|
|
@@ -130,7 +131,55 @@ describe('PktAlert', () => {
|
|
|
130
131
|
expect(alert.compact).toBe(true)
|
|
131
132
|
|
|
132
133
|
const alertDiv = alert.querySelector('.pkt-alert')
|
|
133
|
-
expect(alertDiv).toHaveClass('pkt-alert--
|
|
134
|
+
expect(alertDiv).toHaveClass('pkt-alert--small')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('applies pkt-alert--medium by default', async () => {
|
|
138
|
+
const { alert } = await createAlertTest()
|
|
139
|
+
|
|
140
|
+
await alert.updateComplete
|
|
141
|
+
|
|
142
|
+
const alertDiv = alert.querySelector('.pkt-alert')
|
|
143
|
+
expect(alertDiv).toHaveClass('pkt-alert--medium')
|
|
144
|
+
expect(alertDiv).not.toHaveClass('pkt-alert--compact')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('applies size classes for small and xsmall', async () => {
|
|
148
|
+
const { alert: smallAlert } = await createAlertTest({ size: 'small' })
|
|
149
|
+
await smallAlert.updateComplete
|
|
150
|
+
|
|
151
|
+
const smallDiv = smallAlert.querySelector('.pkt-alert')
|
|
152
|
+
expect(smallDiv).toHaveClass('pkt-alert--small')
|
|
153
|
+
expect(smallDiv).not.toHaveClass('pkt-alert--medium')
|
|
154
|
+
|
|
155
|
+
const { alert: xsmallAlert } = await createAlertTest({ size: 'xsmall' })
|
|
156
|
+
await xsmallAlert.updateComplete
|
|
157
|
+
|
|
158
|
+
const xsmallDiv = xsmallAlert.querySelector('.pkt-alert')
|
|
159
|
+
expect(xsmallDiv).toHaveClass('pkt-alert--xsmall')
|
|
160
|
+
expect(xsmallDiv).not.toHaveClass('pkt-alert--medium')
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test('applies pkt-alert--small when compact is set without size', async () => {
|
|
164
|
+
const { alert } = await createAlertTest({ compact: true })
|
|
165
|
+
|
|
166
|
+
await alert.updateComplete
|
|
167
|
+
|
|
168
|
+
const alertDiv = alert.querySelector('.pkt-alert')
|
|
169
|
+
expect(alertDiv).toHaveClass('pkt-alert--small')
|
|
170
|
+
expect(alertDiv).not.toHaveClass('pkt-alert--compact')
|
|
171
|
+
expect(alertDiv).not.toHaveClass('pkt-alert--medium')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('explicit size wins over compact', async () => {
|
|
175
|
+
const { alert } = await createAlertTest({ compact: true, size: 'xsmall' })
|
|
176
|
+
|
|
177
|
+
await alert.updateComplete
|
|
178
|
+
|
|
179
|
+
const alertDiv = alert.querySelector('.pkt-alert')
|
|
180
|
+
expect(alertDiv).toHaveClass('pkt-alert--xsmall')
|
|
181
|
+
expect(alertDiv).not.toHaveClass('pkt-alert--compact')
|
|
182
|
+
expect(alertDiv).not.toHaveClass('pkt-alert--small')
|
|
134
183
|
})
|
|
135
184
|
|
|
136
185
|
test('handles title property', async () => {
|
|
@@ -18,8 +18,12 @@ export interface IPktAlert {
|
|
|
18
18
|
title?: string
|
|
19
19
|
date?: string | null
|
|
20
20
|
ariaLive?: TAriaLive | null
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Bruk size i stedet. Uten eksplisitt size gir compact størrelsen 'small'.
|
|
23
|
+
*/
|
|
21
24
|
compact?: boolean
|
|
22
25
|
role?: string
|
|
26
|
+
size?: 'medium' | 'small' | 'xsmall'
|
|
23
27
|
}
|
|
24
28
|
export class PktAlert extends PktElementWithSlot implements IPktAlert {
|
|
25
29
|
constructor() {
|
|
@@ -29,7 +33,7 @@ export class PktAlert extends PktElementWithSlot implements IPktAlert {
|
|
|
29
33
|
|
|
30
34
|
// Properties
|
|
31
35
|
|
|
32
|
-
@property({ type: Boolean, reflect: false }) compact = specs.
|
|
36
|
+
@property({ type: Boolean, reflect: false }) compact = specs.deprecated.compact.default
|
|
33
37
|
@property({ type: String, reflect: true }) title: string = ''
|
|
34
38
|
@property({ type: String, reflect: true }) skin: TAlertSkin = specs.props.skin
|
|
35
39
|
.default as TAlertSkin
|
|
@@ -39,7 +43,8 @@ export class PktAlert extends PktElementWithSlot implements IPktAlert {
|
|
|
39
43
|
@property({ type: Boolean, reflect: true }) closeAlert = specs.props.closeAlert.default
|
|
40
44
|
@property({ type: String, reflect: true }) date: string | null = null
|
|
41
45
|
@property({ type: String, reflect: true }) role: string = 'status'
|
|
42
|
-
|
|
46
|
+
@property({ type: String, attribute: 'size' })
|
|
47
|
+
size?: 'medium' | 'small' | 'xsmall'
|
|
43
48
|
@state() _isClosed: boolean = false
|
|
44
49
|
|
|
45
50
|
// Lifecycle
|
|
@@ -69,10 +74,11 @@ export class PktAlert extends PktElementWithSlot implements IPktAlert {
|
|
|
69
74
|
// Render
|
|
70
75
|
|
|
71
76
|
render() {
|
|
77
|
+
const alertSize = this.size ?? (this.compact ? 'small' : 'medium')
|
|
72
78
|
const classes = {
|
|
73
79
|
'pkt-alert': true,
|
|
74
|
-
|
|
75
|
-
[`pkt-alert--${this.skin}`]:
|
|
80
|
+
[`pkt-alert--${alertSize}`]: true,
|
|
81
|
+
[`pkt-alert--${this.skin}`]: true,
|
|
76
82
|
'pkt-hide': this._isClosed,
|
|
77
83
|
}
|
|
78
84
|
|
|
@@ -97,7 +103,7 @@ export class PktAlert extends PktElementWithSlot implements IPktAlert {
|
|
|
97
103
|
<pkt-button
|
|
98
104
|
tabindex="0"
|
|
99
105
|
aria-label="close"
|
|
100
|
-
size=${
|
|
106
|
+
size=${alertSize}
|
|
101
107
|
type="button"
|
|
102
108
|
skin="tertiary"
|
|
103
109
|
iconName="close"
|
|
@@ -61,7 +61,9 @@ describe('PktBreadcrumbs', () => {
|
|
|
61
61
|
document.body.appendChild(container)
|
|
62
62
|
container.innerHTML = `<pkt-breadcrumbs breadcrumbs='${JSON.stringify(defaultBreadcrumbs)}'></pkt-breadcrumbs>`
|
|
63
63
|
|
|
64
|
-
const element = container.querySelector(
|
|
64
|
+
const element = container.querySelector(
|
|
65
|
+
'pkt-breadcrumbs',
|
|
66
|
+
) as CustomElementFor<'pkt-breadcrumbs'>
|
|
65
67
|
await customElements.whenDefined('pkt-breadcrumbs')
|
|
66
68
|
await element.updateComplete
|
|
67
69
|
|
|
@@ -141,7 +143,10 @@ describe('PktBreadcrumbs', () => {
|
|
|
141
143
|
test('dispatches navigate event on link click', async () => {
|
|
142
144
|
const { breadcrumbs } = await createBreadcrumbsTest({ breadcrumbs: defaultBreadcrumbs })
|
|
143
145
|
const navigateSpy = vi.fn()
|
|
144
|
-
breadcrumbs.addEventListener('navigate',
|
|
146
|
+
breadcrumbs.addEventListener('navigate', (e: Event) => {
|
|
147
|
+
e.preventDefault()
|
|
148
|
+
navigateSpy(e)
|
|
149
|
+
})
|
|
145
150
|
|
|
146
151
|
const link = breadcrumbs.querySelector('.pkt-breadcrumbs__link') as HTMLAnchorElement
|
|
147
152
|
fireEvent.click(link)
|
|
@@ -154,7 +159,10 @@ describe('PktBreadcrumbs', () => {
|
|
|
154
159
|
test('dispatches navigate event on mobile back-link click', async () => {
|
|
155
160
|
const { breadcrumbs } = await createBreadcrumbsTest({ breadcrumbs: defaultBreadcrumbs })
|
|
156
161
|
const navigateSpy = vi.fn()
|
|
157
|
-
breadcrumbs.addEventListener('navigate',
|
|
162
|
+
breadcrumbs.addEventListener('navigate', (e: Event) => {
|
|
163
|
+
e.preventDefault()
|
|
164
|
+
navigateSpy(e)
|
|
165
|
+
})
|
|
158
166
|
|
|
159
167
|
const mobileLink = breadcrumbs.querySelector('.pkt-breadcrumbs--mobile') as HTMLAnchorElement
|
|
160
168
|
fireEvent.click(mobileLink)
|
|
@@ -83,6 +83,29 @@ describe('PktButton', () => {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
describe('Properties and attributes', () => {
|
|
86
|
+
test('flytter aria-haspopup/-expanded/-controls fra verten til den indre knappen', async () => {
|
|
87
|
+
const { button } = await createButtonTest({ content: 'Meny' })
|
|
88
|
+
button.setAttribute('aria-haspopup', 'dialog')
|
|
89
|
+
button.setAttribute('aria-expanded', 'false')
|
|
90
|
+
button.setAttribute('aria-controls', 'meny-panel')
|
|
91
|
+
button.requestUpdate()
|
|
92
|
+
await button.updateComplete
|
|
93
|
+
|
|
94
|
+
const inner = button.querySelector('button')
|
|
95
|
+
expect(inner).toHaveAttribute('aria-haspopup', 'dialog')
|
|
96
|
+
expect(inner).toHaveAttribute('aria-expanded', 'false')
|
|
97
|
+
expect(inner).toHaveAttribute('aria-controls', 'meny-panel')
|
|
98
|
+
expect(button).not.toHaveAttribute('aria-haspopup')
|
|
99
|
+
expect(button).not.toHaveAttribute('aria-expanded')
|
|
100
|
+
expect(button).not.toHaveAttribute('aria-controls')
|
|
101
|
+
|
|
102
|
+
// Ny verdi plukkes opp ved neste oppdatering
|
|
103
|
+
button.setAttribute('aria-expanded', 'true')
|
|
104
|
+
button.requestUpdate()
|
|
105
|
+
await button.updateComplete
|
|
106
|
+
expect(inner).toHaveAttribute('aria-expanded', 'true')
|
|
107
|
+
})
|
|
108
|
+
|
|
86
109
|
test('applies default properties correctly', async () => {
|
|
87
110
|
const { button } = await createButtonTest({ content: 'Test Button' })
|
|
88
111
|
await button.updateComplete
|
|
@@ -3,7 +3,7 @@ import { slotContent } from '@/directives/slot-content'
|
|
|
3
3
|
import { PktIconName } from '@oslokommune/punkt-assets/dist/icons/icon'
|
|
4
4
|
import type { Booleanish, THTMLButtonType } from 'shared-types'
|
|
5
5
|
import { html, nothing, PropertyValues } from 'lit'
|
|
6
|
-
import { property, customElement } from 'lit/decorators.js'
|
|
6
|
+
import { property, customElement, state } from 'lit/decorators.js'
|
|
7
7
|
import { classMap } from 'lit/directives/class-map.js'
|
|
8
8
|
import { ifDefined } from 'lit/directives/if-defined.js'
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ if (typeof window !== 'undefined') {
|
|
|
16
16
|
window.pktAnimationPath = window.pktAnimationPath || defaultAnimationPath
|
|
17
17
|
}
|
|
18
18
|
export type TPktButtonMode = 'light' | 'dark'
|
|
19
|
-
export type TPktButtonSize = 'small' | 'medium' | 'large'
|
|
19
|
+
export type TPktButtonSize = 'xsmall' | 'small' | 'medium' | 'large'
|
|
20
20
|
export type TPktButtonColor =
|
|
21
21
|
| 'blue'
|
|
22
22
|
| 'blue-outline'
|
|
@@ -59,7 +59,6 @@ export interface IPktButton {
|
|
|
59
59
|
loadingAnimationPath?: string
|
|
60
60
|
}
|
|
61
61
|
export class PktButton extends PktElementWithSlot<IPktButton> implements IPktButton {
|
|
62
|
-
|
|
63
62
|
// Properties
|
|
64
63
|
@property({ type: String }) iconName: string = 'user'
|
|
65
64
|
@property({ type: String }) secondIconName: string = 'user'
|
|
@@ -120,6 +119,29 @@ export class PktButton extends PktElementWithSlot<IPktButton> implements IPktBut
|
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
121
|
|
|
122
|
+
private static readonly relocatedAriaAttributes = [
|
|
123
|
+
'aria-haspopup',
|
|
124
|
+
'aria-expanded',
|
|
125
|
+
'aria-controls',
|
|
126
|
+
] as const
|
|
127
|
+
|
|
128
|
+
@state() private relocatedAria: Record<string, string> = {}
|
|
129
|
+
|
|
130
|
+
protected willUpdate(changed: PropertyValues): void {
|
|
131
|
+
super.willUpdate(changed)
|
|
132
|
+
let moved = false
|
|
133
|
+
const next = { ...this.relocatedAria }
|
|
134
|
+
for (const name of PktButton.relocatedAriaAttributes) {
|
|
135
|
+
const value = this.getAttribute(name)
|
|
136
|
+
if (value !== null) {
|
|
137
|
+
next[name] = value
|
|
138
|
+
this.removeAttribute(name)
|
|
139
|
+
moved = true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (moved) this.relocatedAria = next
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
protected firstUpdated(_changedProperties: PropertyValues): void {
|
|
124
146
|
super.firstUpdated(_changedProperties)
|
|
125
147
|
|
|
@@ -156,6 +178,9 @@ export class PktButton extends PktElementWithSlot<IPktButton> implements IPktBut
|
|
|
156
178
|
?disabled=${!!this.disabled}
|
|
157
179
|
aria-busy=${ifDefined(this.isLoading ? 'true' : undefined)}
|
|
158
180
|
aria-disabled=${ifDefined(this.disabled || this.isLoading ? 'true' : undefined)}
|
|
181
|
+
aria-haspopup=${ifDefined(this.relocatedAria['aria-haspopup'])}
|
|
182
|
+
aria-expanded=${ifDefined(this.relocatedAria['aria-expanded'])}
|
|
183
|
+
aria-controls=${ifDefined(this.relocatedAria['aria-controls'])}
|
|
159
184
|
form=${ifDefined(formId)}
|
|
160
185
|
>
|
|
161
186
|
${this.isLoading
|
|
@@ -77,6 +77,26 @@ describe('PktCombobox', () => {
|
|
|
77
77
|
expect(listbox).toBeInTheDocument()
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
+
test('applies input wrapper size classes for small and xsmall', async () => {
|
|
81
|
+
const smallContainer = await createCombobox('id="size-small" label="Test" input-size="small"')
|
|
82
|
+
const smallCombobox = smallContainer.querySelector('pkt-combobox') as PktCombobox
|
|
83
|
+
await smallCombobox.updateComplete
|
|
84
|
+
const smallInner = smallCombobox.querySelector('pkt-input-wrapper .pkt-inputwrapper')
|
|
85
|
+
expect(smallInner?.classList.contains('pkt-inputwrapper--small')).toBe(true)
|
|
86
|
+
expect(smallInner?.classList.contains('pkt-inputwrapper--xsmall')).toBe(false)
|
|
87
|
+
|
|
88
|
+
document.body.innerHTML = ''
|
|
89
|
+
|
|
90
|
+
const xsmallContainer = await createCombobox(
|
|
91
|
+
'id="size-xsmall" label="Test" input-size="xsmall"',
|
|
92
|
+
)
|
|
93
|
+
const xsmallCombobox = xsmallContainer.querySelector('pkt-combobox') as PktCombobox
|
|
94
|
+
await xsmallCombobox.updateComplete
|
|
95
|
+
const xsmallInner = xsmallCombobox.querySelector('pkt-input-wrapper .pkt-inputwrapper')
|
|
96
|
+
expect(xsmallInner?.classList.contains('pkt-inputwrapper--small')).toBe(false)
|
|
97
|
+
expect(xsmallInner?.classList.contains('pkt-inputwrapper--xsmall')).toBe(true)
|
|
98
|
+
})
|
|
99
|
+
|
|
80
100
|
test('renders select-only combobox with correct ARIA attributes', async () => {
|
|
81
101
|
const container = await createCombobox('id="test-arrow" name="test" label="Test"')
|
|
82
102
|
|
|
@@ -278,6 +278,7 @@ export class PktCombobox extends ComboboxHandlers implements IPktCombobox {
|
|
|
278
278
|
render() {
|
|
279
279
|
return html`
|
|
280
280
|
<pkt-input-wrapper
|
|
281
|
+
.size=${this.inputSize}
|
|
281
282
|
.label=${this.label}
|
|
282
283
|
.helptext=${this.helptext}
|
|
283
284
|
.helptextDropdown=${ifDefined(this.helptextDropdown)}
|
|
@@ -303,6 +304,7 @@ export class PktCombobox extends ComboboxHandlers implements IPktCombobox {
|
|
|
303
304
|
<div
|
|
304
305
|
class=${classMap({
|
|
305
306
|
'pkt-combobox__input': true,
|
|
307
|
+
[`pkt-combobox__input--${this.inputSize}`]: true,
|
|
306
308
|
'pkt-combobox__input--fullwidth': this.fullwidth,
|
|
307
309
|
'pkt-combobox__input--open': this._isOptionsOpen,
|
|
308
310
|
'pkt-combobox__input--error': this.hasError,
|
|
@@ -172,6 +172,9 @@ describe('PktConsent', () => {
|
|
|
172
172
|
const button = consent.querySelector('pkt-button')
|
|
173
173
|
expect(button).toBeInTheDocument()
|
|
174
174
|
expect(button?.getAttribute('skin')).toBe(null) // Default button
|
|
175
|
+
// aria-haspopup flyttes fra pkt-button-verten til den indre knappen
|
|
176
|
+
expect(button?.querySelector('button')).toHaveAttribute('aria-haspopup', 'dialog')
|
|
177
|
+
expect(button).not.toHaveAttribute('aria-haspopup')
|
|
175
178
|
})
|
|
176
179
|
|
|
177
180
|
test('renders as link trigger type', async () => {
|
|
@@ -193,10 +196,10 @@ describe('PktConsent', () => {
|
|
|
193
196
|
expect(consent.triggerType).toBe('footerlink')
|
|
194
197
|
const footerLink = consent.querySelector('a.pkt-footer__link')
|
|
195
198
|
expect(footerLink).toBeInTheDocument()
|
|
199
|
+
expect(footerLink).toHaveAttribute('aria-haspopup', 'dialog')
|
|
196
200
|
|
|
197
|
-
|
|
198
|
-
expect(icon).
|
|
199
|
-
expect(icon?.getAttribute('name')).toBe('chevron-right')
|
|
201
|
+
// Ny footer-stil: ren understreket lenke uten ikon.
|
|
202
|
+
expect(footerLink?.querySelector('pkt-icon')).toBeNull()
|
|
200
203
|
})
|
|
201
204
|
|
|
202
205
|
test('renders as icon trigger type', async () => {
|
|
@@ -3,7 +3,6 @@ import { html, PropertyValues } from 'lit'
|
|
|
3
3
|
import { PktElement } from '@/base-elements/element'
|
|
4
4
|
import { consentStrings } from './strings'
|
|
5
5
|
import '../button'
|
|
6
|
-
import '../icon'
|
|
7
6
|
|
|
8
7
|
interface ConsentItem {
|
|
9
8
|
name: string
|
|
@@ -205,25 +204,34 @@ export class PktConsent extends PktElement<IPktConsent> implements IPktConsent {
|
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
render() {
|
|
207
|
+
// aria-haspopup: triggeren åpner consent-dialogen, den navigerer ikke
|
|
208
208
|
if (this.triggerType === 'link') {
|
|
209
|
-
return html`<a href="#" class="pkt-link" @click=${this.openModal}
|
|
209
|
+
return html`<a href="#" class="pkt-link" aria-haspopup="dialog" @click=${this.openModal}
|
|
210
|
+
>${this.triggerText}</a
|
|
211
|
+
>`
|
|
210
212
|
}
|
|
211
213
|
if (this.triggerType === 'footerlink') {
|
|
212
|
-
return html`<a
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
return html`<a
|
|
215
|
+
href="#"
|
|
216
|
+
class="pkt-footer__link"
|
|
217
|
+
aria-haspopup="dialog"
|
|
218
|
+
@click=${this.openModal}
|
|
219
|
+
>${this.triggerText}</a
|
|
220
|
+
>`
|
|
216
221
|
}
|
|
217
222
|
if (this.triggerType === 'icon') {
|
|
218
223
|
return html`<pkt-button
|
|
219
224
|
skin="tertiary"
|
|
220
225
|
variant="icon-only"
|
|
221
226
|
iconName="cookie"
|
|
227
|
+
aria-haspopup="dialog"
|
|
222
228
|
@click=${this.openModal}
|
|
223
229
|
>${this.triggerText}</pkt-button
|
|
224
230
|
>`
|
|
225
231
|
}
|
|
226
|
-
return html`<pkt-button @click=${this.openModal}
|
|
232
|
+
return html`<pkt-button aria-haspopup="dialog" @click=${this.openModal}
|
|
233
|
+
>${this.triggerText}</pkt-button
|
|
234
|
+
>`
|
|
227
235
|
}
|
|
228
236
|
}
|
|
229
237
|
|
|
@@ -5,6 +5,7 @@ import { classMap } from 'lit/directives/class-map.js'
|
|
|
5
5
|
import { PktElement } from '@/base-elements/element'
|
|
6
6
|
import { cssUtils } from './datepicker-utils'
|
|
7
7
|
import { IDatepickerStrings } from './datepicker-types'
|
|
8
|
+
import type { TPktInputSize } from 'shared-types/size'
|
|
8
9
|
import '@/components/icon'
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -43,6 +44,9 @@ export abstract class PktDatepickerBase extends PktElement {
|
|
|
43
44
|
@property({ type: Object })
|
|
44
45
|
inputClasses: Record<string, boolean> = {}
|
|
45
46
|
|
|
47
|
+
@property({ type: String })
|
|
48
|
+
inputSize: TPktInputSize = 'medium'
|
|
49
|
+
|
|
46
50
|
@property({ type: Object })
|
|
47
51
|
internals?: ElementInternals
|
|
48
52
|
|
|
@@ -122,7 +126,7 @@ export abstract class PktDatepickerBase extends PktElement {
|
|
|
122
126
|
protected renderCalendarButton(): TemplateResult {
|
|
123
127
|
return html`
|
|
124
128
|
<button
|
|
125
|
-
class="${classMap(cssUtils.getButtonClasses())}"
|
|
129
|
+
class="${classMap(cssUtils.getButtonClasses(this.inputSize))}"
|
|
126
130
|
type="button"
|
|
127
131
|
@click=${(e: Event) => this.dispatchToggleCalendar(e)}
|
|
128
132
|
@keydown=${(e: KeyboardEvent) => {
|
|
@@ -427,6 +427,11 @@ describe('datepicker-utils', () => {
|
|
|
427
427
|
const classes = cssUtils.getInputClasses(false, false, false, false, false, 'text')
|
|
428
428
|
expect(classes['ios-readonly-hack']).toBe(true)
|
|
429
429
|
})
|
|
430
|
+
|
|
431
|
+
it('should include input size class', () => {
|
|
432
|
+
const classes = cssUtils.getInputClasses(false, false, false, false, false, 'date', 'small')
|
|
433
|
+
expect(classes['pkt-input--small']).toBe(true)
|
|
434
|
+
})
|
|
430
435
|
})
|
|
431
436
|
|
|
432
437
|
describe('getButtonClasses', () => {
|
|
@@ -438,6 +443,11 @@ describe('datepicker-utils', () => {
|
|
|
438
443
|
expect(classes['pkt-btn--tertiary']).toBe(true)
|
|
439
444
|
expect(classes['pkt-datepicker__calendar-button']).toBe(true)
|
|
440
445
|
})
|
|
446
|
+
|
|
447
|
+
it('should include button size class', () => {
|
|
448
|
+
const classes = cssUtils.getButtonClasses('xsmall')
|
|
449
|
+
expect(classes['pkt-btn--xsmall']).toBe(true)
|
|
450
|
+
})
|
|
441
451
|
})
|
|
442
452
|
|
|
443
453
|
describe('getRangeLabelClasses', () => {
|
|
@@ -59,6 +59,23 @@ describe('PktDatepicker', () => {
|
|
|
59
59
|
expect(calendarButton).toBeInTheDocument()
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
+
test.each([
|
|
63
|
+
['small', 'small'],
|
|
64
|
+
['xsmall', 'xsmall'],
|
|
65
|
+
] as const)(
|
|
66
|
+
'input-size="%s" applies size classes on host, input and calendar button',
|
|
67
|
+
async (size, sizeClass) => {
|
|
68
|
+
const container = await createDatepicker(`label="Test" id="size-test" input-size="${size}"`)
|
|
69
|
+
const datepicker = container.querySelector('pkt-datepicker') as PktDatepicker
|
|
70
|
+
await datepicker.updateComplete
|
|
71
|
+
|
|
72
|
+
expect(datepicker.inputSize).toBe(size)
|
|
73
|
+
expect(datepicker.classList.contains(`pkt-datepicker--${sizeClass}`)).toBe(true)
|
|
74
|
+
expect(datepicker.querySelector(`.pkt-input--${sizeClass}`)).toBeTruthy()
|
|
75
|
+
expect(datepicker.querySelector(`.pkt-btn--${sizeClass}`)).toBeTruthy()
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
|
|
62
79
|
test('renders calendar when opened', async () => {
|
|
63
80
|
const container = await createDatepicker('label="Test Datepicker"')
|
|
64
81
|
|
|
@@ -226,6 +226,9 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
226
226
|
this._value = [this._value[0] ?? '']
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
+
this.classList.toggle('pkt-datepicker--medium', this.inputSize === 'medium')
|
|
230
|
+
this.classList.toggle('pkt-datepicker--small', this.inputSize === 'small')
|
|
231
|
+
this.classList.toggle('pkt-datepicker--xsmall', this.inputSize === 'xsmall')
|
|
229
232
|
super.updated(changedProperties)
|
|
230
233
|
}
|
|
231
234
|
|
|
@@ -301,6 +304,7 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
301
304
|
.readonly=${this.readonly}
|
|
302
305
|
.disabled=${this.disabled}
|
|
303
306
|
.inputClasses=${this.inputClasses}
|
|
307
|
+
.inputSize=${this.inputSize}
|
|
304
308
|
.internals=${this.internals}
|
|
305
309
|
.strings=${this.strings}
|
|
306
310
|
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
@@ -337,6 +341,7 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
337
341
|
.disabled=${this.disabled}
|
|
338
342
|
.showRangeLabels=${this.showRangeLabels}
|
|
339
343
|
.inputClasses=${this.inputClasses}
|
|
344
|
+
.inputSize=${this.inputSize}
|
|
340
345
|
.internals=${this.internals}
|
|
341
346
|
.strings=${this.strings}
|
|
342
347
|
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
@@ -416,6 +421,7 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
416
421
|
.disabled=${this.disabled}
|
|
417
422
|
.maxlength=${this.maxlength}
|
|
418
423
|
.inputClasses=${this.inputClasses}
|
|
424
|
+
.inputSize=${this.inputSize}
|
|
419
425
|
.internals=${this.internals}
|
|
420
426
|
.strings=${this.strings}
|
|
421
427
|
@toggle-calendar=${(e: CustomEvent) => this.toggleCalendar(e.detail)}
|
|
@@ -483,6 +489,7 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
483
489
|
this.range,
|
|
484
490
|
this.readonly,
|
|
485
491
|
this.inputType,
|
|
492
|
+
this.inputSize,
|
|
486
493
|
)
|
|
487
494
|
|
|
488
495
|
return html`
|
|
@@ -508,6 +515,7 @@ export class PktDatepicker extends PktInputElement<Props> {
|
|
|
508
515
|
.helptextDropdown=${this.helptextDropdown}
|
|
509
516
|
.helptextDropdownButton=${this.helptextDropdownButton}
|
|
510
517
|
.ariaDescribedBy=${this.ariaDescribedBy}
|
|
518
|
+
.size=${this.inputSize}
|
|
511
519
|
class="pkt-datepicker"
|
|
512
520
|
>
|
|
513
521
|
<div class="pkt-contents" slot="helptext">${slotContent(this, 'helptext')}</div>
|