@oslokommune/punkt-elements 14.3.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 (53) hide show
  1. package/CHANGELOG.md +17 -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 +213 -14
  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 +1 -1
  18. package/dist/pkt-header.js +1 -1
  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/radiobutton/radiobutton.ts +1 -1
  46. package/src/components/select/select.ts +12 -47
  47. package/src/components/textarea/textarea.ts +1 -1
  48. package/src/components/textinput/textinput.ts +1 -1
  49. package/dist/input-element-B8M8Nppd.js +0 -708
  50. package/dist/input-element-D697OAJo.cjs +0 -1
  51. package/dist/pkt-options-controller-CiuBG6Lt.cjs +0 -1
  52. package/dist/select-3dwlk22G.cjs +0 -49
  53. package/dist/select-_C-yztI0.js +0 -173
package/dist/index.d.ts CHANGED
@@ -621,7 +621,7 @@ export declare class PktCard extends PktElement implements IPktCard {
621
621
  }
622
622
 
623
623
  export declare class PktCheckbox extends PktInputElement<Props_3> {
624
- private inputRef;
624
+ inputRef: Ref<HTMLInputElement>;
625
625
  value: string;
626
626
  checkHelptext: string | null;
627
627
  defaultChecked: boolean;
@@ -662,8 +662,8 @@ export declare class PktCombobox extends PktInputElement implements IPktCombobox
662
662
  displayValueAs: string;
663
663
  tagPlacement: TPktComboboxTagPlacement | null;
664
664
  _options: IPktComboboxOption[];
665
+ _value: string[];
665
666
  private _isOptionsOpen;
666
- private _value;
667
667
  private _userInfoMessage;
668
668
  private _addValueText;
669
669
  private _maxIsReached;
@@ -1155,8 +1155,18 @@ export declare class PktIcon extends PktElement<Props_5> {
1155
1155
  * Base class for all Punkt input elements
1156
1156
  * @extends PktElement
1157
1157
  */
1158
- declare class PktInputElement<T = {}> extends PktElement<Props_2 & T> {
1158
+ declare class PktInputElement<T = {}, TOption extends PktInputOption = PktInputOption> extends PktElement<Props_2 & T> {
1159
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[];
1160
1170
  defaultValue: string | string[] | null;
1161
1171
  disabled: boolean;
1162
1172
  readonly: boolean;
@@ -1192,22 +1202,124 @@ declare class PktInputElement<T = {}> extends PktElement<Props_2 & T> {
1192
1202
  tagText: string | null;
1193
1203
  dataTestid: string;
1194
1204
  touched: boolean;
1195
- _options?: any[];
1196
1205
  constructor();
1197
- 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
+ */
1198
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
+ */
1199
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
+ */
1200
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
+ */
1201
1265
  protected clearInputValue(): void;
1266
+ /**
1267
+ * When user enters the input, dispatch focus event
1268
+ * @protected
1269
+ */
1202
1270
  protected onFocus(): void;
1271
+ /**
1272
+ * When user leaves the input, dispatch blur event
1273
+ * @protected
1274
+ */
1203
1275
  protected onBlur(): void;
1276
+ /**
1277
+ * Trigger this when user types in the input
1278
+ * @protected
1279
+ */
1204
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
+ */
1205
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
+ */
1206
1307
  protected formResetCallback(): void;
1207
1308
  protected updated(_changedProperties: PropertyValues): void;
1208
1309
  protected firstUpdated(_changedProperties: PropertyValues): void;
1209
1310
  }
1210
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
+
1211
1323
  export declare class PktInputWrapper extends PktElement<Props_6> {
1212
1324
  defaultSlot: Ref<HTMLElement>;
1213
1325
  helptextSlot: Ref<HTMLElement>;
@@ -1371,6 +1483,88 @@ export declare class PktModal extends PktElement implements IPktModal {
1371
1483
  render(): TemplateResult<1>;
1372
1484
  }
1373
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
+
1374
1568
  export declare class PktProgressbar extends PktElement implements IPktProgressbar {
1375
1569
  constructor();
1376
1570
  ariaLabel: string | null;
@@ -1402,7 +1596,7 @@ export declare class PktProgressbar extends PktElement implements IPktProgressba
1402
1596
  }
1403
1597
 
1404
1598
  declare class PktRadioButton extends PktInputElement<Props_7> {
1405
- private inputRef;
1599
+ inputRef: Ref<HTMLInputElement>;
1406
1600
  value: string;
1407
1601
  checkHelptext: string | null;
1408
1602
  defaultChecked: boolean;
@@ -1423,16 +1617,12 @@ declare class PktRadioButton extends PktInputElement<Props_7> {
1423
1617
  export { PktRadioButton }
1424
1618
  export { PktRadioButton as PktRadiobutton }
1425
1619
 
1426
- export declare class PktSelect extends PktInputElement implements IPktSelect {
1427
- private inputRef;
1620
+ export declare class PktSelect extends PktOptionsInputElement<{}, TSelectOption> implements IPktSelect {
1621
+ inputRef: Ref<HTMLSelectElement>;
1428
1622
  private helptextSlot;
1429
- private _optionsProp;
1430
1623
  value: string;
1431
- _options: TSelectOption[];
1432
1624
  selectedIndex: number | null;
1433
1625
  selectedOptions: HTMLCollectionOf<HTMLOptionElement> | undefined;
1434
- get options(): TSelectOption[];
1435
- set options(value: TSelectOption[]);
1436
1626
  constructor();
1437
1627
  connectedCallback(): void;
1438
1628
  add(item: HTMLOptionElement, before?: HTMLOptionElement | number): void;
@@ -1558,7 +1748,7 @@ export declare class PktTag extends PktElement<IPktTag> implements IPktTag {
1558
1748
  }
1559
1749
 
1560
1750
  export declare class PktTextarea extends PktInputElement<Props_8> {
1561
- private inputRef;
1751
+ inputRef: Ref<HTMLTextAreaElement>;
1562
1752
  private helptextSlot;
1563
1753
  value: string;
1564
1754
  autocomplete: string;
@@ -1571,7 +1761,7 @@ export declare class PktTextarea extends PktInputElement<Props_8> {
1571
1761
  }
1572
1762
 
1573
1763
  export declare class PktTextinput extends PktInputElement<Props_9> {
1574
- private inputRef;
1764
+ inputRef: Ref<HTMLTextAreaElement>;
1575
1765
  private helptextSlot;
1576
1766
  value: string;
1577
1767
  type: string;
@@ -1590,6 +1780,8 @@ export declare class PktTextinput extends PktInputElement<Props_9> {
1590
1780
 
1591
1781
  declare type Props = ElementProps<PktElement, 'strings' | 'role'>;
1592
1782
 
1783
+ declare type Props_10 = ElementProps<PktOptionsInputElement, 'options'>;
1784
+
1593
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'>;
1594
1786
 
1595
1787
  declare type Props_3 = ElementProps<PktCheckbox, 'checkHelptext' | 'defaultChecked' | 'hasTile' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'tagText' | 'optionalTag' | 'optionalText' | 'requiredTag' | 'requiredText'>;
@@ -1647,6 +1839,13 @@ declare type TLinkCardSkin = 'normal' | 'no-padding' | 'blue' | 'beige' | 'green
1647
1839
 
1648
1840
  declare type TMonth = `${number}${number}`;
1649
1841
 
1842
+ declare type TOption = {
1843
+ value: string;
1844
+ label: string;
1845
+ selected?: boolean;
1846
+ disabled?: boolean;
1847
+ };
1848
+
1650
1849
  export declare type TPktAccordionSkin = TAccordionSkin;
1651
1850
 
1652
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';