@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
package/dist/index.d.ts CHANGED
@@ -15,12 +15,17 @@ import { TAriaLive } from '../../../../../shared-types';
15
15
  import { TCardSkin } from '../../../../../shared-types';
16
16
  import { TemplateResult } from 'lit-html';
17
17
  import { TemplateResult as TemplateResult_2 } from 'lit';
18
+ import { THeaderMenu } from '../../../../../shared-types';
19
+ import { THeaderPosition } from '../../../../../shared-types';
20
+ import { THeaderScrollBehavior } from '../../../../../shared-types';
18
21
  import { THeadingLevel } from '../../../../../shared-types';
19
22
  import { THeadingSize } from '../../../../../shared-types';
20
23
  import { THeadingWeight } from '../../../../../shared-types';
21
24
  import { THTMLButtonType } from '../../../../../shared-types';
22
25
  import { TLayout } from '../../../../../shared-types';
23
26
  import { TMessageboxSkin } from '../../../../../shared-types';
27
+ import { TLogOutButtonPlacement as TPktHeaderLogOutButtonPlacement } from '../../../../../shared-types';
28
+ import { TSlotMenuVariant } from '../../../../../shared-types';
24
29
  import { User } from '../../../../../shared-types';
25
30
  import { UserMenuItem } from '../../../../../shared-types';
26
31
 
@@ -251,7 +256,11 @@ export declare interface IPktHeader {
251
256
  /** Custom breakpoint for tablet responsive behavior in pixels. Default: 1280 */
252
257
  tabletBreakpoint?: number;
253
258
  /** Which menu is initially open */
254
- openedMenu?: TPktHeaderMenu;
259
+ openedMenu?: THeaderMenu;
260
+ /** Variant for the slot menu button. Default: 'icon-only' */
261
+ slotMenuVariant?: TSlotMenuVariant;
262
+ /** Text for the slot menu button. Default: 'Meny' */
263
+ slotMenuText?: string;
255
264
  }
256
265
 
257
266
  export declare type IPktHeaderRepresenting = Representing;
@@ -612,7 +621,7 @@ export declare class PktCard extends PktElement implements IPktCard {
612
621
  }
613
622
 
614
623
  export declare class PktCheckbox extends PktInputElement<Props_3> {
615
- private inputRef;
624
+ inputRef: Ref<HTMLInputElement>;
616
625
  value: string;
617
626
  checkHelptext: string | null;
618
627
  defaultChecked: boolean;
@@ -653,8 +662,8 @@ export declare class PktCombobox extends PktInputElement implements IPktCombobox
653
662
  displayValueAs: string;
654
663
  tagPlacement: TPktComboboxTagPlacement | null;
655
664
  _options: IPktComboboxOption[];
665
+ _value: string[];
656
666
  private _isOptionsOpen;
657
- private _value;
658
667
  private _userInfoMessage;
659
668
  private _addValueText;
660
669
  private _maxIsReached;
@@ -976,10 +985,12 @@ export declare class PktHeader extends PktElement<IPktHeader> implements IPktHea
976
985
  searchValue: string;
977
986
  mobileBreakpoint: number;
978
987
  tabletBreakpoint: number;
979
- openedMenu: TPktHeaderMenu;
988
+ openedMenu: THeaderMenu;
980
989
  logOutButtonPlacement: TPktHeaderLogOutButtonPlacement;
981
990
  position: THeaderPosition;
982
991
  scrollBehavior: THeaderScrollBehavior;
992
+ slotMenuVariant: TSlotMenuVariant;
993
+ slotMenuText: string;
983
994
  hideLogo: Booleanish;
984
995
  compact: Booleanish;
985
996
  showSearch: Booleanish;
@@ -1008,10 +1019,12 @@ export declare class PktHeaderService extends PktElement<IPktHeader> implements
1008
1019
  searchValue: string;
1009
1020
  mobileBreakpoint: number;
1010
1021
  tabletBreakpoint: number;
1011
- openedMenu: TPktHeaderMenu;
1022
+ openedMenu: THeaderMenu;
1012
1023
  logOutButtonPlacement: TPktHeaderLogOutButtonPlacement;
1013
1024
  position: THeaderPosition;
1014
1025
  scrollBehavior: THeaderScrollBehavior;
1026
+ slotMenuVariant: TSlotMenuVariant;
1027
+ slotMenuText: string;
1015
1028
  hideLogo: Booleanish;
1016
1029
  compact: Booleanish;
1017
1030
  showSearch: Booleanish;
@@ -1142,8 +1155,18 @@ export declare class PktIcon extends PktElement<Props_5> {
1142
1155
  * Base class for all Punkt input elements
1143
1156
  * @extends PktElement
1144
1157
  */
1145
- declare class PktInputElement<T = {}> extends PktElement<Props_2 & T> {
1158
+ declare class PktInputElement<T = {}, TOption extends PktInputOption = PktInputOption> extends PktElement<Props_2 & T> {
1146
1159
  static get formAssociated(): boolean;
1160
+ internals: any;
1161
+ form: HTMLFormElement | null;
1162
+ checked?: boolean | string | null;
1163
+ defaultChecked?: boolean;
1164
+ multiple?: boolean;
1165
+ range?: boolean;
1166
+ type?: string;
1167
+ slotController?: PktSlotController;
1168
+ optionsController?: PktOptionsSlotController;
1169
+ _options?: TOption[];
1147
1170
  defaultValue: string | string[] | null;
1148
1171
  disabled: boolean;
1149
1172
  readonly: boolean;
@@ -1179,22 +1202,124 @@ declare class PktInputElement<T = {}> extends PktElement<Props_2 & T> {
1179
1202
  tagText: string | null;
1180
1203
  dataTestid: string;
1181
1204
  touched: boolean;
1182
- _options?: any[];
1183
1205
  constructor();
1184
- protected manageValidity(input: HTMLInputElement): void;
1206
+ /**
1207
+ * Manages form validation state based on input validity
1208
+ * Called automatically by onChange, but can be called manually if needed
1209
+ *
1210
+ * @param input - The input element to validate (optional)
1211
+ * @protected
1212
+ */
1213
+ protected manageValidity(input?: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): void;
1214
+ /**
1215
+ * Updates the form value for this input
1216
+ * Handles both single values and arrays (for multi-select)
1217
+ *
1218
+ * @param value - The value(s) to set in the form
1219
+ * @protected
1220
+ */
1185
1221
  protected setFormValue(value: string | string[]): void;
1222
+ /**
1223
+ * Coordinates radio button group by unchecking other radios with the same name
1224
+ * Only affects radio inputs within the same form
1225
+ *
1226
+ * @protected
1227
+ */
1228
+ protected coordinateRadioGroup(): void;
1229
+ /**
1230
+ * Updates checked state and form value for checkbox and radio inputs
1231
+ * Triggers this when you want to set the value of the radio or checkbox input to the form
1232
+ * Do not use valueChanged or onChange for radios and checkboxes!
1233
+ *
1234
+ * @param value - The checked state (string 'true'/'false', or boolean)
1235
+ * @protected
1236
+ */
1186
1237
  protected valueChecked(value: string | boolean | null): void;
1238
+ /**
1239
+ * Called when value changes (text inputs, select, etc.)
1240
+ * Subclasses can override to add custom value transformation logic
1241
+ *
1242
+ * @param value - The new value
1243
+ * @param _old - The previous value
1244
+ * @protected
1245
+ * @example
1246
+ * ```typescript
1247
+ * protected valueChanged(value: string, old: string): void {
1248
+ * const transformed = this.transformValue(value)
1249
+ * super.valueChanged(transformed, old)
1250
+ * }
1251
+ * ```
1252
+ */
1187
1253
  protected valueChanged(value: string | string[] | null, _old: string | string[] | null): void;
1254
+ /**
1255
+ * Dispatches change and value-change events
1256
+ *
1257
+ * @param value - The value to include in the event detail
1258
+ * @protected
1259
+ */
1260
+ protected dispatchChangeEvents(value: unknown): void;
1261
+ /**
1262
+ * When input goes from content to no content
1263
+ * @protected
1264
+ */
1188
1265
  protected clearInputValue(): void;
1266
+ /**
1267
+ * When user enters the input, dispatch focus event
1268
+ * @protected
1269
+ */
1189
1270
  protected onFocus(): void;
1271
+ /**
1272
+ * When user leaves the input, dispatch blur event
1273
+ * @protected
1274
+ */
1190
1275
  protected onBlur(): void;
1276
+ /**
1277
+ * Trigger this when user types in the input
1278
+ * @protected
1279
+ */
1191
1280
  protected onInput(): void;
1281
+ /**
1282
+ * Normalizes value format based on multiple/range settings
1283
+ *
1284
+ * @param value - The value to normalize
1285
+ * @returns Normalized value (array if multiple/range, string otherwise)
1286
+ * @private
1287
+ */
1288
+ private normalizeValue;
1289
+ /**
1290
+ * Validates the input element(s)
1291
+ * @private
1292
+ */
1293
+ private validate;
1294
+ /**
1295
+ * Trigger this when you want to set the value of the input out to the form
1296
+ * Handles value normalization, form updates, validation, and event dispatching
1297
+ *
1298
+ * @param value - The value to set
1299
+ * @protected
1300
+ */
1192
1301
  protected onChange(value: string | string[]): void;
1302
+ /**
1303
+ * Called when the form is reset
1304
+ * Resets the input to its default state
1305
+ * @protected
1306
+ */
1193
1307
  protected formResetCallback(): void;
1194
1308
  protected updated(_changedProperties: PropertyValues): void;
1195
1309
  protected firstUpdated(_changedProperties: PropertyValues): void;
1196
1310
  }
1197
1311
 
1312
+ /**
1313
+ * Base interface for input options used in select, combobox, etc.
1314
+ */
1315
+ declare interface PktInputOption {
1316
+ value: string;
1317
+ label?: string;
1318
+ selected?: boolean;
1319
+ disabled?: boolean;
1320
+ hidden?: boolean;
1321
+ }
1322
+
1198
1323
  export declare class PktInputWrapper extends PktElement<Props_6> {
1199
1324
  defaultSlot: Ref<HTMLElement>;
1200
1325
  helptextSlot: Ref<HTMLElement>;
@@ -1358,6 +1483,88 @@ export declare class PktModal extends PktElement implements IPktModal {
1358
1483
  render(): TemplateResult<1>;
1359
1484
  }
1360
1485
 
1486
+ /**
1487
+ * Base class for input elements that have options (select, combobox, etc.)
1488
+ * Provides common functionality for managing options from props or slots
1489
+ * @extends PktInputElement
1490
+ */
1491
+ declare abstract class PktOptionsInputElement<T = {}, TOption extends PktInputOption = PktInputOption> extends PktInputElement<Props_10 & T, TOption> {
1492
+ /**
1493
+ * Options passed as a prop
1494
+ * @private
1495
+ */
1496
+ protected _optionsProp: TOption[];
1497
+ /**
1498
+ * Internal state for parsed options
1499
+ * @protected
1500
+ */
1501
+ _options: TOption[];
1502
+ /**
1503
+ * Controller for managing options from slots
1504
+ */
1505
+ optionsController: PktOptionsSlotController;
1506
+ /**
1507
+ * Public getter for options that includes selected state
1508
+ * Override this in subclasses to customize the selected state logic
1509
+ */
1510
+ get options(): TOption[];
1511
+ /**
1512
+ * Public setter for options
1513
+ */
1514
+ set options(value: TOption[]);
1515
+ /**
1516
+ * Determines if an option is selected
1517
+ * Subclasses should override this to implement their selection logic
1518
+ *
1519
+ * @param option - The option to check
1520
+ * @returns True if the option is selected
1521
+ * @protected
1522
+ */
1523
+ protected isOptionSelected(option: TOption): boolean;
1524
+ /**
1525
+ * Finds an option by its value
1526
+ *
1527
+ * @param value - The value to search for
1528
+ * @returns The option if found, undefined otherwise
1529
+ * @protected
1530
+ */
1531
+ protected findOptionByValue(value: string): TOption | undefined;
1532
+ /**
1533
+ * Gets all currently selected options
1534
+ *
1535
+ * @returns Array of selected options
1536
+ * @protected
1537
+ */
1538
+ protected getSelectedOptions(): TOption[];
1539
+ /**
1540
+ * Parses options from either props or slot controller
1541
+ * Call this in connectedCallback to initialize options
1542
+ *
1543
+ * @protected
1544
+ */
1545
+ protected parseOptions(): void;
1546
+ /**
1547
+ * Re-parse options when the component updates
1548
+ * This ensures options stay in sync when they change dynamically
1549
+ *
1550
+ * @protected
1551
+ */
1552
+ protected willUpdate(_changedProperties: Map<PropertyKey, unknown>): void;
1553
+ }
1554
+
1555
+ declare class PktOptionsSlotController implements ReactiveController {
1556
+ host: LitElement & ReactiveControllerHost;
1557
+ nodes: Element[];
1558
+ options: TOption[];
1559
+ observer: MutationObserver;
1560
+ constructor(host: LitElement & ReactiveControllerHost);
1561
+ hostConnected(): void;
1562
+ hostDisconnected(): void;
1563
+ private addNode;
1564
+ private createOptions;
1565
+ private handleMutations;
1566
+ }
1567
+
1361
1568
  export declare class PktProgressbar extends PktElement implements IPktProgressbar {
1362
1569
  constructor();
1363
1570
  ariaLabel: string | null;
@@ -1389,7 +1596,7 @@ export declare class PktProgressbar extends PktElement implements IPktProgressba
1389
1596
  }
1390
1597
 
1391
1598
  declare class PktRadioButton extends PktInputElement<Props_7> {
1392
- private inputRef;
1599
+ inputRef: Ref<HTMLInputElement>;
1393
1600
  value: string;
1394
1601
  checkHelptext: string | null;
1395
1602
  defaultChecked: boolean;
@@ -1410,16 +1617,12 @@ declare class PktRadioButton extends PktInputElement<Props_7> {
1410
1617
  export { PktRadioButton }
1411
1618
  export { PktRadioButton as PktRadiobutton }
1412
1619
 
1413
- export declare class PktSelect extends PktInputElement implements IPktSelect {
1414
- private inputRef;
1620
+ export declare class PktSelect extends PktOptionsInputElement<{}, TSelectOption> implements IPktSelect {
1621
+ inputRef: Ref<HTMLSelectElement>;
1415
1622
  private helptextSlot;
1416
- private _optionsProp;
1417
1623
  value: string;
1418
- _options: TSelectOption[];
1419
1624
  selectedIndex: number | null;
1420
1625
  selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined;
1421
- get options(): TSelectOption[];
1422
- set options(value: TSelectOption[]);
1423
1626
  constructor();
1424
1627
  connectedCallback(): void;
1425
1628
  add(item: HTMLOptionElement, before?: HTMLOptionElement | number): void;
@@ -1545,7 +1748,7 @@ export declare class PktTag extends PktElement<IPktTag> implements IPktTag {
1545
1748
  }
1546
1749
 
1547
1750
  export declare class PktTextarea extends PktInputElement<Props_8> {
1548
- private inputRef;
1751
+ inputRef: Ref<HTMLTextAreaElement>;
1549
1752
  private helptextSlot;
1550
1753
  value: string;
1551
1754
  autocomplete: string;
@@ -1558,7 +1761,7 @@ export declare class PktTextarea extends PktInputElement<Props_8> {
1558
1761
  }
1559
1762
 
1560
1763
  export declare class PktTextinput extends PktInputElement<Props_9> {
1561
- private inputRef;
1764
+ inputRef: Ref<HTMLTextAreaElement>;
1562
1765
  private helptextSlot;
1563
1766
  value: string;
1564
1767
  type: string;
@@ -1577,6 +1780,8 @@ export declare class PktTextinput extends PktInputElement<Props_9> {
1577
1780
 
1578
1781
  declare type Props = ElementProps<PktElement, 'strings' | 'role'>;
1579
1782
 
1783
+ declare type Props_10 = ElementProps<PktOptionsInputElement, 'options'>;
1784
+
1580
1785
  declare type Props_2 = ElementProps<PktInputElement, 'defaultValue' | 'disabled' | 'readonly' | 'required' | 'max' | 'maxlength' | 'min' | 'minlength' | 'ariaDescribedBy' | 'ariaLabelledby' | 'name' | 'pattern' | 'placeholder' | 'id' | 'counter' | 'hasError' | 'hasFieldset' | 'inline' | 'optionalTag' | 'requiredTag' | 'skipForwardTestid' | 'useWrapper' | 'fullwidth' | 'counterMaxLength' | 'errorMessage' | 'helptext' | 'helptextDropdown' | 'helptextDropdownButton' | 'label' | 'optionalText' | 'requiredText' | 'dataTestid'>;
1581
1786
 
1582
1787
  declare type Props_3 = ElementProps<PktCheckbox, 'checkHelptext' | 'defaultChecked' | 'hasTile' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'tagText' | 'optionalTag' | 'optionalText' | 'requiredTag' | 'requiredText'>;
@@ -1622,15 +1827,11 @@ declare type TCounterPosition = 'top' | 'bottom';
1622
1827
 
1623
1828
  declare type TDay = `${number}${number}`;
1624
1829
 
1625
- /**
1626
- * Position options for header
1627
- */
1628
- declare type THeaderPosition = 'fixed' | 'relative';
1830
+ export { THeaderMenu }
1629
1831
 
1630
- /**
1631
- * Scroll behavior options for header
1632
- */
1633
- declare type THeaderScrollBehavior = 'hide' | 'none';
1832
+ export { THeaderPosition }
1833
+
1834
+ export { THeaderScrollBehavior }
1634
1835
 
1635
1836
  declare type TISODate = `${TYear}-${TMonth}-${TDay}`;
1636
1837
 
@@ -1638,6 +1839,13 @@ declare type TLinkCardSkin = 'normal' | 'no-padding' | 'blue' | 'beige' | 'green
1638
1839
 
1639
1840
  declare type TMonth = `${number}${number}`;
1640
1841
 
1842
+ declare type TOption = {
1843
+ value: string;
1844
+ label: string;
1845
+ selected?: boolean;
1846
+ disabled?: boolean;
1847
+ };
1848
+
1641
1849
  export declare type TPktAccordionSkin = TAccordionSkin;
1642
1850
 
1643
1851
  export declare type TPktButtonColor = 'blue' | 'blue-outline' | 'green' | 'green-outline' | 'green-dark' | 'green-dark-outline' | 'beige-light' | 'beige-dark-outline' | 'yellow' | 'yellow-outline' | 'red' | 'red-outline';
@@ -1656,15 +1864,7 @@ export declare type TPktButtonVariant = 'label-only' | 'icon-left' | 'icon-right
1656
1864
 
1657
1865
  export declare type TPktComboboxTagPlacement = 'inside' | 'outside';
1658
1866
 
1659
- /**
1660
- * Type for logout button placement
1661
- */
1662
- export declare type TPktHeaderLogOutButtonPlacement = 'userMenu' | 'header' | 'both' | 'none';
1663
-
1664
- /**
1665
- * Type for which menu is currently open
1666
- */
1667
- export declare type TPktHeaderMenu = 'none' | 'slot' | 'search' | 'user';
1867
+ export { TPktHeaderLogOutButtonPlacement }
1668
1868
 
1669
1869
  export declare type TPktHeadingLevel = THeadingLevel;
1670
1870
 
@@ -1694,6 +1894,8 @@ export declare type TSelectOption = {
1694
1894
  hidden?: boolean;
1695
1895
  };
1696
1896
 
1897
+ export { TSlotMenuVariant }
1898
+
1697
1899
  export declare type TTabItemSkin = 'blue' | 'green' | 'red' | 'beige' | 'yellow' | 'grey' | 'gray' | 'blue-light';
1698
1900
 
1699
1901
  export declare type TTagSkin = 'blue' | 'blue-dark' | 'blue-light' | 'green' | 'red' | 'yellow' | 'beige' | 'gray' | 'grey';