@oslokommune/punkt-elements 14.2.0 → 14.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/{checkbox-CnhA52o_.js → checkbox-DfVUNTjH.js} +1 -1
  3. package/dist/{checkbox-C0TPnShf.cjs → checkbox-uxeHrTLH.cjs} +1 -1
  4. package/dist/{combobox-C1xwAju5.cjs → combobox-CcyHcqdW.cjs} +13 -13
  5. package/dist/{combobox-Dcp_fHcL.js → combobox-MZsqmVL-.js} +45 -45
  6. package/dist/{datepicker-COIRRau0.cjs → datepicker-BeMs_vsm.cjs} +25 -25
  7. package/dist/{datepicker-Bjb9GK1E.js → datepicker-a2LvhbRb.js} +215 -234
  8. package/dist/index.d.ts +236 -34
  9. package/dist/input-element-CARcDzQB.js +840 -0
  10. package/dist/input-element-CiaV6jln.cjs +1 -0
  11. package/dist/pkt-checkbox.cjs +1 -1
  12. package/dist/pkt-checkbox.js +1 -1
  13. package/dist/pkt-combobox.cjs +1 -1
  14. package/dist/pkt-combobox.js +1 -1
  15. package/dist/pkt-datepicker.cjs +1 -1
  16. package/dist/pkt-datepicker.js +2 -2
  17. package/dist/pkt-header.cjs +9 -7
  18. package/dist/pkt-header.js +137 -123
  19. package/dist/pkt-index.cjs +1 -1
  20. package/dist/pkt-index.js +7 -7
  21. package/dist/pkt-options-controller-DjBCEHU4.cjs +1 -0
  22. package/dist/{pkt-options-controller-CZO1nxZ8.js → pkt-options-controller-zn5cmMvL.js} +3 -3
  23. package/dist/pkt-radiobutton.cjs +1 -1
  24. package/dist/pkt-radiobutton.js +1 -1
  25. package/dist/pkt-select.cjs +1 -1
  26. package/dist/pkt-select.js +1 -1
  27. package/dist/pkt-textarea.cjs +1 -1
  28. package/dist/pkt-textarea.js +1 -1
  29. package/dist/pkt-textinput.cjs +1 -1
  30. package/dist/pkt-textinput.js +1 -1
  31. package/dist/{radiobutton-Caq8-GhM.js → radiobutton-BmgdSpYf.js} +1 -1
  32. package/dist/{radiobutton-BkqaqO5E.cjs → radiobutton-DVe09YxP.cjs} +1 -1
  33. package/dist/select-7KFOnLln.cjs +49 -0
  34. package/dist/select-CKqz-JKZ.js +228 -0
  35. package/dist/{textarea-a6T4aJJU.js → textarea-Bmrv_vve.js} +1 -1
  36. package/dist/{textarea-DyUy8u7X.cjs → textarea-VBUXPS1O.cjs} +1 -1
  37. package/dist/{textinput-IN3b0nSH.cjs → textinput-BkYKotc1.cjs} +1 -1
  38. package/dist/{textinput-DIuM70dd.js → textinput-Lp1crOmj.js} +1 -1
  39. package/package.json +2 -2
  40. package/src/components/checkbox/checkbox.ts +1 -1
  41. package/src/components/combobox/combobox.ts +2 -2
  42. package/src/components/datepicker/datepicker-utils.test.ts +0 -25
  43. package/src/components/datepicker/datepicker-utils.ts +0 -28
  44. package/src/components/datepicker/datepicker.ts +0 -6
  45. package/src/components/header/header-service.ts +12 -8
  46. package/src/components/header/header.ts +8 -2
  47. package/src/components/header/index.ts +4 -1
  48. package/src/components/header/types.ts +18 -22
  49. package/src/components/index.ts +4 -1
  50. package/src/components/radiobutton/radiobutton.ts +1 -1
  51. package/src/components/select/select.ts +12 -47
  52. package/src/components/textarea/textarea.ts +1 -1
  53. package/src/components/textinput/textinput.ts +1 -1
  54. package/dist/input-element-B8M8Nppd.js +0 -708
  55. package/dist/input-element-D697OAJo.cjs +0 -1
  56. package/dist/pkt-options-controller-CiuBG6Lt.cjs +0 -1
  57. package/dist/select-3dwlk22G.cjs +0 -49
  58. package/dist/select-_C-yztI0.js +0 -173
@@ -7,8 +7,11 @@ export type {
7
7
  Representing,
8
8
  UserMenuItem,
9
9
  TInternalMenuItem,
10
- TPktHeaderMenu,
10
+ THeaderMenu,
11
11
  TLogOutButtonPlacement,
12
+ THeaderPosition,
13
+ THeaderScrollBehavior,
14
+ TSlotMenuVariant,
12
15
  IPktHeader,
13
16
  } from './types'
14
17
 
@@ -6,10 +6,22 @@ import type {
6
6
  Representing as SharedRepresenting,
7
7
  UserMenuItem as SharedUserMenuItem,
8
8
  TInternalMenuItem as SharedTInternalMenuItem,
9
+ TSlotMenuVariant,
10
+ THeaderMenu,
11
+ TLogOutButtonPlacement,
12
+ THeaderPosition,
13
+ THeaderScrollBehavior,
9
14
  } from 'shared-types'
10
15
  import { convertUserMenuItem as sharedConvertUserMenuItem } from 'shared-types'
11
16
 
12
- export type { Booleanish }
17
+ export type {
18
+ Booleanish,
19
+ TSlotMenuVariant,
20
+ THeaderMenu,
21
+ TLogOutButtonPlacement,
22
+ THeaderPosition,
23
+ THeaderScrollBehavior,
24
+ }
13
25
  export { booleanishConverter }
14
26
 
15
27
  // Re-export with PktIconName typing
@@ -25,26 +37,6 @@ export const convertUserMenuItem = (item: UserMenuItem): TInternalMenuItem => {
25
37
  return sharedConvertUserMenuItem(item)
26
38
  }
27
39
 
28
- /**
29
- * Type for which menu is currently open
30
- */
31
- export type TPktHeaderMenu = 'none' | 'slot' | 'search' | 'user'
32
-
33
- /**
34
- * Type for logout button placement
35
- */
36
- export type TLogOutButtonPlacement = 'userMenu' | 'header' | 'both' | 'none'
37
-
38
- /**
39
- * Position options for header
40
- */
41
- export type THeaderPosition = 'fixed' | 'relative'
42
-
43
- /**
44
- * Scroll behavior options for header
45
- */
46
- export type THeaderScrollBehavior = 'hide' | 'none'
47
-
48
40
  /**
49
41
  * Interface for the Header component props
50
42
  */
@@ -86,5 +78,9 @@ export interface IPktHeader {
86
78
  /** Custom breakpoint for tablet responsive behavior in pixels. Default: 1280 */
87
79
  tabletBreakpoint?: number
88
80
  /** Which menu is initially open */
89
- openedMenu?: TPktHeaderMenu
81
+ openedMenu?: THeaderMenu
82
+ /** Variant for the slot menu button. Default: 'icon-only' */
83
+ slotMenuVariant?: TSlotMenuVariant
84
+ /** Text for the slot menu button. Default: 'Meny' */
85
+ slotMenuText?: string
90
86
  }
@@ -49,8 +49,11 @@ export type {
49
49
  User as IPktHeaderUser,
50
50
  Representing as IPktHeaderRepresenting,
51
51
  UserMenuItem as IPktHeaderUserMenuItem,
52
- TPktHeaderMenu,
52
+ THeaderMenu,
53
53
  TLogOutButtonPlacement as TPktHeaderLogOutButtonPlacement,
54
+ THeaderPosition,
55
+ THeaderScrollBehavior,
56
+ TSlotMenuVariant,
54
57
  IPktHeader,
55
58
  } from '@/components/header'
56
59
 
@@ -20,7 +20,7 @@ type Props = ElementProps<
20
20
 
21
21
  @customElement('pkt-radiobutton')
22
22
  export class PktRadioButton extends PktInputElement<Props> {
23
- private inputRef: Ref<HTMLInputElement> = createRef()
23
+ inputRef: Ref<HTMLInputElement> = createRef()
24
24
 
25
25
  @property({ type: String, reflect: true }) value: string = ''
26
26
  @property({ type: String }) checkHelptext: string | null = null
@@ -1,8 +1,8 @@
1
1
  import { html, PropertyValues } from 'lit'
2
- import { customElement, property, state } from 'lit/decorators.js'
2
+ import { customElement, property } from 'lit/decorators.js'
3
3
  import { Ref, createRef, ref } from 'lit/directives/ref.js'
4
4
  import { ifDefined } from 'lit/directives/if-defined.js'
5
- import { PktInputElement } from '@/base-elements/input-element'
5
+ import { PktOptionsInputElement } from '@/base-elements/options-input-element'
6
6
  import { PktOptionsSlotController } from '@/controllers/pkt-options-controller'
7
7
  import { PktSlotController } from '@/controllers/pkt-slot-controller'
8
8
  import '@/components/input-wrapper'
@@ -39,31 +39,15 @@ declare global {
39
39
  }
40
40
 
41
41
  @customElement('pkt-select')
42
- export class PktSelect extends PktInputElement implements IPktSelect {
43
- private inputRef: Ref<HTMLSelectElement> = createRef()
42
+ export class PktSelect extends PktOptionsInputElement<{}, TSelectOption> implements IPktSelect {
43
+ inputRef: Ref<HTMLSelectElement> = createRef()
44
44
  private helptextSlot: Ref<HTMLElement> = createRef()
45
45
 
46
- @property({ type: Array, attribute: 'options' }) private _optionsProp: TSelectOption[] = []
47
46
  @property({ type: String }) value: string = ''
48
47
 
49
- @state() _options: TSelectOption[] = []
50
-
51
48
  public selectedIndex: number | null = -1
52
49
  public selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined = undefined
53
50
 
54
- // Getter and setter for options to expose the actual parsed options
55
- public get options(): TSelectOption[] {
56
- return this._options.map((option) => ({
57
- ...option,
58
- selected: option.value === this.value,
59
- }))
60
- }
61
-
62
- public set options(value: TSelectOption[]) {
63
- this._optionsProp = value
64
- this.requestUpdate('_optionsProp', this._options)
65
- }
66
-
67
51
  constructor() {
68
52
  super()
69
53
  this.optionsController = new PktOptionsSlotController(this)
@@ -74,34 +58,15 @@ export class PktSelect extends PktInputElement implements IPktSelect {
74
58
  connectedCallback(): void {
75
59
  super.connectedCallback()
76
60
 
77
- const optionsReceivedFromProps = this._optionsProp.length > 0
78
- const checkIfOptionNodesInSlot =
79
- this.optionsController.nodes.length && this.optionsController.nodes.length > 0
61
+ // Parse options from props or slots
62
+ this.parseOptions()
80
63
 
81
- if (!optionsReceivedFromProps && checkIfOptionNodesInSlot) {
82
- this.optionsController.nodes.forEach((node: Element) => {
83
- const option: TSelectOption = {
84
- value: node.hasAttribute('value')
85
- ? (node.getAttribute('value') ?? '')
86
- : (node.textContent ?? ''),
87
- label: node.textContent || node.getAttribute('value') || '',
88
- disabled: node.hasAttribute('disabled'),
89
- selected: node.hasAttribute('selected'),
90
- hidden: node.hasAttribute('data-hidden'),
91
- }
92
- if (node.getAttribute('selected') && !this.value) {
93
- this.value = option.value
94
- }
95
- this._options.push(option)
96
- })
97
- } else {
98
- this._options = this._optionsProp
99
- this._options.forEach((option) => {
100
- if (option.selected && !this.value) {
101
- this.value = option.value
102
- }
103
- })
104
- }
64
+ // Set initial value from selected option
65
+ this._options.forEach((option) => {
66
+ if (option.selected && !this.value) {
67
+ this.value = option.value
68
+ }
69
+ })
105
70
  }
106
71
 
107
72
  // Support native Select method `add`
@@ -15,7 +15,7 @@ type Props = ElementProps<PktTextarea, 'autocomplete' | 'rows'>
15
15
 
16
16
  @customElement('pkt-textarea')
17
17
  export class PktTextarea extends PktInputElement<Props> {
18
- private inputRef: Ref<HTMLTextAreaElement> = createRef()
18
+ inputRef: Ref<HTMLTextAreaElement> = createRef()
19
19
  private helptextSlot: Ref<HTMLElement> = createRef()
20
20
 
21
21
  @property({ type: String, reflect: true }) value: string = ''
@@ -24,7 +24,7 @@ type Props = ElementProps<
24
24
 
25
25
  @customElement('pkt-textinput')
26
26
  export class PktTextinput extends PktInputElement<Props> {
27
- private inputRef: Ref<HTMLTextAreaElement> = createRef()
27
+ inputRef: Ref<HTMLTextAreaElement> = createRef()
28
28
  private helptextSlot: Ref<HTMLElement> = createRef()
29
29
 
30
30
  @property({ type: String, reflect: true }) value: string = ''