@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
51 lines (50 loc) • 2.29 kB
TypeScript
/**
* Shared combobox option utility functions used by both Elements and React packages.
* Only framework-agnostic functions belong here.
*/
import type { IPktComboboxOption, TPktComboboxDisplayValue } from '../../shared-types/combobox';
/**
* Finds an option by its value, falling back to label match.
* Value matches are prioritized over label matches to avoid ambiguity
* when an option's label matches another option's value.
*/
export declare const findOptionByValue: (options: IPktComboboxOption[], value: string | null) => IPktComboboxOption | null;
/**
* Finds the index of an option by its value, falling back to label match.
*/
export declare const findOptionIndex: (options: IPktComboboxOption[], value: string | null) => number;
/**
* Filters options by a search string, matching against fulltext.
*/
export declare const filterOptionsBySearch: (options: IPktComboboxOption[], search: string | null) => IPktComboboxOption[];
/**
* Builds the fulltext search string for an option.
*/
export declare const buildFulltext: (option: IPktComboboxOption) => string;
/**
* Checks if the maximum number of selections has been reached.
*/
export declare const isMaxSelectionReached: (selectedCount: number, maxlength: number | null) => boolean;
/**
* Returns the display text for an option based on the displayValueAs setting.
*/
export declare const getOptionDisplayText: (option: IPktComboboxOption | null, displayValueAs: TPktComboboxDisplayValue) => string;
/**
* Parses a value prop (string or string[]) into a normalized array.
*/
export declare const parseValueToArray: (value: string | string[] | null | undefined, multiple: boolean) => string[];
/**
* Finds typeahead matches from options based on search input.
* Returns filtered options and the best autocomplete suggestion.
*/
export declare const findTypeaheadMatches: (options: IPktComboboxOption[], search: string) => {
filtered: IPktComboboxOption[];
suggestion: IPktComboboxOption | null;
};
/**
* Determines the user info message based on search state and matches.
*/
export declare const getSearchInfoMessage: (searchValue: string, selectedValues: string[], options: IPktComboboxOption[], allowUserInput: boolean) => {
addValueText: string | null;
userInfoMessage: string;
};