@oslokommune/punkt-react 19.6.0 → 19.7.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.
@@ -2,14 +2,17 @@
2
2
  * combobox.ts
3
3
  *
4
4
  * Type definitions for the combobox and listbox components.
5
- * Used by both Elements and React implementations
6
- * and by the shared combobox helper functions.
5
+ * Used by both Elements and React implementations,
6
+ * the shared combobox helper functions, and typed component specs.
7
7
  */
8
+ import type { IFormFieldErrorProps, IFormFieldLabelProps, IHelptextProps, ITagOptionalRequiredProps } from './form-field';
9
+ import type { TPktInputSize } from './size';
8
10
  /**
9
11
  * Tag skin colors available for combobox option tags.
10
12
  * Matches the TTagSkin values from the tag component.
11
13
  */
12
- export type TPktComboboxTagSkin = 'blue' | 'blue-dark' | 'blue-light' | 'green' | 'red' | 'yellow' | 'beige' | 'gray' | 'grey';
14
+ export declare const COMBOBOX_TAG_SKINS: readonly ['blue', 'blue-dark', 'blue-light', 'green', 'red', 'yellow', 'beige', 'gray', 'grey'];
15
+ export type TPktComboboxTagSkin = (typeof COMBOBOX_TAG_SKINS)[number];
13
16
  /**
14
17
  * Represents a single option in a combobox or listbox.
15
18
  */
@@ -27,8 +30,73 @@ export interface IPktComboboxOption {
27
30
  /**
28
31
  * How the selected value is displayed in the combobox input.
29
32
  */
30
- export type TPktComboboxDisplayValue = 'label' | 'value' | 'prefixAndValue';
33
+ export declare const COMBOBOX_DISPLAY_VALUES: readonly ['label', 'value', 'prefixAndValue'];
34
+ export type TPktComboboxDisplayValue = (typeof COMBOBOX_DISPLAY_VALUES)[number];
31
35
  /**
32
36
  * Placement of selected value tags in multiple selection mode.
33
37
  */
34
- export type TPktComboboxTagPlacement = 'inside' | 'outside';
38
+ export declare const COMBOBOX_TAG_PLACEMENTS: readonly ['inside', 'outside'];
39
+ export type TPktComboboxTagPlacement = (typeof COMBOBOX_TAG_PLACEMENTS)[number];
40
+ /**
41
+ * Combobox props shared by React, Elements, and typed component specs.
42
+ *
43
+ * @remarks Both frameworks extend this with `Omit<>` and widen a few props:
44
+ * - React widens `helptext`, `helptextDropdown` and `errorMessage` to `ReactNode`.
45
+ * - Elements widens string/number props to `| null` (Lit uses `null` for an unset attribute,
46
+ * see `PktInputElement`) and `useWrapper` to `Booleanish`. Elements omits `form`, which is
47
+ * a getter returning the associated `HTMLFormElement`, not the form id.
48
+ *
49
+ * `hasFieldset` and `counter` are tri-state: `null` means the component derives the value.
50
+ */
51
+ export interface IPktComboboxBase extends IFormFieldLabelProps, IHelptextProps, IFormFieldErrorProps, ITagOptionalRequiredProps {
52
+ id?: string;
53
+ name?: string;
54
+ form?: string;
55
+ ariaDescribedby?: string;
56
+ placeholder?: string;
57
+ required?: boolean;
58
+ value?: string | string[];
59
+ defaultValue?: string | string[];
60
+ options?: IPktComboboxOption[];
61
+ defaultOptions?: IPktComboboxOption[];
62
+ multiple?: boolean;
63
+ maxlength?: number;
64
+ typeahead?: boolean;
65
+ includeSearch?: boolean;
66
+ allowUserInput?: boolean;
67
+ searchPlaceholder?: string;
68
+ displayValueAs?: TPktComboboxDisplayValue;
69
+ tagPlacement?: TPktComboboxTagPlacement;
70
+ inputSize?: TPktInputSize;
71
+ fullwidth?: boolean;
72
+ inline?: boolean;
73
+ useWrapper?: boolean;
74
+ hasFieldset?: boolean | null;
75
+ counter?: boolean | null;
76
+ }
77
+ /**
78
+ * Documented Combobox props (subset of `IPktComboboxBase`).
79
+ * Used for typed component specs in documentation.
80
+ */
81
+ export type IComboboxSpecProps = Pick<IPktComboboxBase, 'name' | 'form' | 'ariaDescribedby' | 'id' | 'label' | 'placeholder' | 'multiple' | 'tagPlacement' | 'maxlength' | 'typeahead' | 'includeSearch' | 'allowUserInput' | 'searchPlaceholder' | 'displayValueAs' | 'inputSize' | 'value' | 'helptext' | 'helptextDropdown' | 'helptextDropdownButton' | 'disabled' | 'hasError' | 'errorMessage' | 'required' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText' | 'fullwidth' | 'defaultOptions' | 'options' | 'inline' | 'useWrapper' | 'hasFieldset' | 'counter' | 'defaultValue'>;
82
+ /**
83
+ * Default values for pkt-combobox. Single source of truth for both frameworks.
84
+ * Array defaults (`options`, `defaultOptions`) are intentionally absent — a shared array
85
+ * instance would be mutated across component instances.
86
+ */
87
+ export declare const COMBOBOX_DEFAULTS: {
88
+ readonly multiple: false;
89
+ readonly typeahead: false;
90
+ readonly includeSearch: false;
91
+ readonly allowUserInput: false;
92
+ readonly displayValueAs: 'label';
93
+ readonly inputSize: 'medium';
94
+ readonly disabled: false;
95
+ readonly hasError: false;
96
+ readonly required: false;
97
+ readonly requiredTag: false;
98
+ readonly optionalTag: false;
99
+ readonly fullwidth: false;
100
+ readonly inline: false;
101
+ readonly useWrapper: true;
102
+ };
@@ -20,6 +20,7 @@ export type { TIconSizeClass, IPktIconBase, IIconSpecProps } from './icon';
20
20
  export { LAYOUT_DIRECTIONS } from './layout';
21
21
  export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
22
22
  export type { THTMLButtonType, TSelectionMode } from './form';
23
+ export { INPUT_SIZES } from './size';
23
24
  export type { TPktInputSize, TSize3, TSize5, TSize7 } from './size';
24
25
  export { ACCORDION_SKINS } from './accordion';
25
26
  export type { TAccordionSkin, IPktAccordionBase, IPktAccordionItemBase, IAccordionSpecProps, IAccordionItemSpecProps, IAccordionVisualProps, } from './accordion';
@@ -41,7 +42,8 @@ export { defaultSingleStrings, defaultRangeStrings } from './datepicker';
41
42
  export type { ITimepickerStrings } from './timepicker';
42
43
  export { defaultTimepickerStrings } from './timepicker';
43
44
  export type { TProgressbarRole, TProgressbarSkin, TProgressbarStatusPlacement, TProgressbarStatusType, TProgressbarTitlePosition, } from './progressbar';
44
- export type { IPktComboboxOption, TPktComboboxTagSkin, TPktComboboxDisplayValue, TPktComboboxTagPlacement, } from './combobox';
45
+ export { COMBOBOX_TAG_SKINS, COMBOBOX_DISPLAY_VALUES, COMBOBOX_TAG_PLACEMENTS, COMBOBOX_DEFAULTS, } from './combobox';
46
+ export type { IPktComboboxOption, TPktComboboxTagSkin, TPktComboboxDisplayValue, TPktComboboxTagPlacement, IPktComboboxBase, IComboboxSpecProps, } from './combobox';
45
47
  export type { IPktSelectOption, TSelectOption } from './select';
46
48
  export type { TPktSearchInputAppearance, TPktSearchInputMethod, IPktSearchInputSuggestion, IPktSearchInput, } from './searchinput';
47
49
  export { UPLOAD_STRATEGIES, FILE_UPLOAD_ITEM_RENDERERS, PREVIEW_UPLOAD_STATUS, } from './fileupload';
@@ -17,7 +17,7 @@ export type TSize5 = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
17
17
  */
18
18
  export type TSize7 = 'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge';
19
19
  /**
20
- * Sizes used in our input components
20
+ * Sizes used in our input components — shared runtime source for types, specs, and Preview.
21
21
  */
22
- export declare const InputSize: readonly ['xsmall', 'small', 'medium'];
23
- export type TPktInputSize = (typeof InputSize)[number];
22
+ export declare const INPUT_SIZES: readonly ['xsmall', 'small', 'medium'];
23
+ export type TPktInputSize = (typeof INPUT_SIZES)[number];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.6.0",
3
+ "version": "19.7.0",
4
4
  "description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
5
5
  "homepage": "https://punkt.oslo.kommune.no",
6
6
  "author": "Team Designsystem, Oslo kommune",
@@ -101,5 +101,5 @@
101
101
  "url": "https://github.com/oslokommune/punkt/issues"
102
102
  },
103
103
  "license": "MIT",
104
- "gitHead": "52793889285e2b8365c81315dce280062c38a543"
104
+ "gitHead": "f5f319f536d0fcbd3943ed6e191d887112e3c192"
105
105
  }
@@ -44,7 +44,7 @@ export const PktCombobox = forwardRef<HTMLDivElement, IPktCombobox>((props, ref)
44
44
  tagText={state.tagText}
45
45
  useWrapper={state.useWrapper}
46
46
  inline={state.inline}
47
- size={props.inputSize ?? 'medium'}
47
+ size={state.inputSize}
48
48
  counter={state.hasCounter}
49
49
  counterCurrent={state.values.length}
50
50
  counterMaxLength={state.maxlength}
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { useEffect, useRef, type MouseEvent, type KeyboardEvent } from 'react'
4
4
  import { findOptionByValue, getOptionDisplayText } from 'shared-utils/combobox'
5
- import type { TPktComboboxDisplayValue } from 'shared-types/combobox'
6
5
  import { PktTag } from '../tag/Tag'
7
6
  import type { IComboboxState } from './types'
8
7
 
@@ -104,7 +103,7 @@ export const SingleValueDisplay = ({ state }: ISingleValueDisplayProps) => {
104
103
  const option = findOptionByValue(options, values[0])
105
104
  if (!option) return null
106
105
 
107
- const displayText = getOptionDisplayText(option, displayValueAs as TPktComboboxDisplayValue)
106
+ const displayText = getOptionDisplayText(option, displayValueAs)
108
107
 
109
108
  return <span className="pkt-combobox__value">{displayText}</span>
110
109
  }
@@ -12,52 +12,20 @@ import type {
12
12
  ReactNode,
13
13
  RefObject,
14
14
  } from 'react'
15
- import type { IPktComboboxOption, TPktComboboxDisplayValue, TPktComboboxTagPlacement } from 'shared-types/combobox'
16
-
17
- export interface IPktCombobox extends IPktStringsProps<'combobox' | 'listbox' | 'forms' | 'validation'> {
18
- // Values & options
19
- value?: string | string[]
20
- defaultValue?: string | string[]
21
- options?: IPktComboboxOption[]
22
- defaultOptions?: IPktComboboxOption[]
23
-
24
- // Behavior
25
- multiple?: boolean
26
- maxlength?: number
27
- typeahead?: boolean
28
- includeSearch?: boolean
29
- allowUserInput?: boolean
30
- displayValueAs?: TPktComboboxDisplayValue
31
- tagPlacement?: TPktComboboxTagPlacement
32
- searchPlaceholder?: string
33
-
34
- // Form
35
- name?: string
36
- form?: string
37
- ariaDescribedby?: string
38
- id?: string
39
- disabled?: boolean
40
- required?: boolean
41
- placeholder?: string
42
-
43
- // InputWrapper props
44
- label?: string
15
+ import type {
16
+ IPktComboboxBase,
17
+ IPktComboboxOption,
18
+ TPktComboboxDisplayValue,
19
+ TPktComboboxTagPlacement,
20
+ } from 'shared-types/combobox'
21
+
22
+ export interface IPktCombobox
23
+ extends
24
+ Omit<IPktComboboxBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>,
25
+ IPktStringsProps<'combobox' | 'listbox' | 'forms' | 'validation'> {
45
26
  helptext?: string | ReactNode
46
27
  helptextDropdown?: string | ReactNode
47
- helptextDropdownButton?: string
48
- hasError?: boolean
49
28
  errorMessage?: string | ReactNode
50
- fullwidth?: boolean
51
- requiredTag?: boolean
52
- requiredText?: string
53
- optionalTag?: boolean
54
- optionalText?: string
55
- tagText?: string
56
- useWrapper?: boolean
57
- inline?: boolean
58
- counter?: boolean
59
- hasFieldset?: boolean
60
- inputSize?: 'small' | 'medium' | 'xsmall'
61
29
 
62
30
  // Events
63
31
  onChange?: ChangeEventHandler<HTMLInputElement>
@@ -119,7 +87,7 @@ export interface IComboboxState {
119
87
  optionalText?: string
120
88
  requiredTag: boolean
121
89
  requiredText?: string
122
- tagText?: string
90
+ tagText?: string | null
123
91
  useWrapper: boolean
124
92
  inline: boolean
125
93
  inputSize: 'small' | 'medium' | 'xsmall'
@@ -11,7 +11,7 @@ import {
11
11
  useRef,
12
12
  useState,
13
13
  } from 'react'
14
- import type { IPktComboboxOption, TPktComboboxDisplayValue } from 'shared-types/combobox'
14
+ import { COMBOBOX_DEFAULTS, type IPktComboboxOption } from 'shared-types/combobox'
15
15
  import {
16
16
  findOptionByValue,
17
17
  getOptionDisplayText,
@@ -54,32 +54,32 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
54
54
  defaultValue,
55
55
  options: optionsProp,
56
56
  defaultOptions,
57
- multiple = false,
57
+ multiple = COMBOBOX_DEFAULTS.multiple,
58
58
  maxlength,
59
- typeahead = false,
60
- includeSearch = false,
61
- allowUserInput = false,
62
- displayValueAs = 'label' as TPktComboboxDisplayValue,
59
+ typeahead = COMBOBOX_DEFAULTS.typeahead,
60
+ includeSearch = COMBOBOX_DEFAULTS.includeSearch,
61
+ allowUserInput = COMBOBOX_DEFAULTS.allowUserInput,
62
+ displayValueAs = COMBOBOX_DEFAULTS.displayValueAs,
63
63
  tagPlacement,
64
64
  searchPlaceholder,
65
65
  placeholder,
66
- disabled = false,
67
- required = false,
68
- fullwidth = false,
69
- hasError = false,
66
+ disabled = COMBOBOX_DEFAULTS.disabled,
67
+ required = COMBOBOX_DEFAULTS.required,
68
+ fullwidth = COMBOBOX_DEFAULTS.fullwidth,
69
+ hasError = COMBOBOX_DEFAULTS.hasError,
70
70
  errorMessage,
71
71
  helptext,
72
72
  helptextDropdown,
73
73
  helptextDropdownButton,
74
- optionalTag = false,
74
+ optionalTag = COMBOBOX_DEFAULTS.optionalTag,
75
75
  optionalText,
76
- requiredTag = false,
76
+ requiredTag = COMBOBOX_DEFAULTS.requiredTag,
77
77
  requiredText,
78
78
  tagText,
79
- useWrapper = true,
80
- inline = false,
79
+ useWrapper = COMBOBOX_DEFAULTS.useWrapper,
80
+ inline = COMBOBOX_DEFAULTS.inline,
81
81
  counter,
82
- inputSize = 'medium',
82
+ inputSize = COMBOBOX_DEFAULTS.inputSize,
83
83
  name,
84
84
  form,
85
85
  ariaDescribedby,
@@ -427,10 +427,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
427
427
  // The two modes resolve displayValueAs through different helpers.
428
428
  newMessageValue = hasTextInput
429
429
  ? getSingleValueForInput(valueFromOptions || '', options, displayValueAs)
430
- : getOptionDisplayText(
431
- findOptionByValue(options, valueFromOptions),
432
- displayValueAs as TPktComboboxDisplayValue,
433
- )
430
+ : getOptionDisplayText(findOptionByValue(options, valueFromOptions), displayValueAs)
434
431
  }
435
432
  // Multi with room
436
433
  else if (isMultiple && !isMaxItemsReached) {