@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
72 lines (71 loc) • 2.38 kB
TypeScript
/**
* Shared combobox selection management functions used by both Elements and React packages.
* Only framework-agnostic functions belong here.
*/
import type { IPktComboboxOption } from '../../shared-types/combobox';
/**
* Configuration for the toggleSelection function.
*/
export interface IToggleSelectionConfig {
multiple: boolean;
allowUserInput: boolean;
maxlength: number | null;
}
/**
* Result of a toggle selection operation.
* Describes what happened and what the new state should be.
*/
export interface IToggleSelectionResult {
values: string[];
options: IPktComboboxOption[];
shouldOptionsBeOpen: boolean;
shouldResetInput: boolean;
userInfoMessage: string;
searchValue: string;
newUserOption: IPktComboboxOption | null;
}
/**
* Marks an option as selected in the options array.
* Returns new arrays (immutable).
*/
export declare const selectOption: (value: string | null, currentValues: string[], options: IPktComboboxOption[], maxlength: number | null, multiple: boolean) => {
values: string[];
options: IPktComboboxOption[];
};
/**
* Removes an option from the selection.
* Returns new arrays (immutable).
*/
export declare const deselectOption: (value: string | null, currentValues: string[], options: IPktComboboxOption[]) => {
values: string[];
options: IPktComboboxOption[];
};
/**
* Selects all options (for multiple mode).
* Returns new arrays (immutable).
*/
export declare const selectAllOptions: (options: IPktComboboxOption[], maxlength: number | null) => {
values: string[];
options: IPktComboboxOption[];
userInfoMessage: string;
};
/**
* Clears all selections.
* Returns new arrays (immutable).
*/
export declare const clearAllSelections: (options: IPktComboboxOption[]) => {
values: string[];
options: IPktComboboxOption[];
};
/**
* Creates a new user-added option object.
*/
export declare const createUserOption: (value: string) => IPktComboboxOption;
/**
* Core toggle selection logic.
*
* Given a value to toggle and the current state, returns the new state
* describing what happened. This is the framework-agnostic version of
* the combobox's toggleValue method.
*/
export declare const toggleSelection: (value: string | null, currentValues: string[], options: IPktComboboxOption[], config: IToggleSelectionConfig) => IToggleSelectionResult;