@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
74 lines (73 loc) • 2.41 kB
TypeScript
import { PktInputElement, PktInputOption } from './input-element';
import { PktOptionsSlotController } from '../controllers/pkt-options-controller';
import { ElementProps } from '../types/typeUtils';
export type { PktInputOption } from './input-element';
type Props = ElementProps<PktOptionsInputElement, 'options'>;
/**
* Base class for input elements that have options (select, combobox, etc.)
* Provides common functionality for managing options from props or slots
* @extends PktInputElement
*/
export declare abstract class PktOptionsInputElement<T = {}, TOption extends PktInputOption = PktInputOption> extends PktInputElement<Props & T, TOption> {
/**
* Options passed as a prop
* @private
*/
protected _optionsProp: TOption[];
/**
* Internal state for parsed options
* @protected
*/
_options: TOption[];
/**
* Controller for managing options from slots
*/
optionsController: PktOptionsSlotController;
/**
* Public getter for options that includes selected state
* Override this in subclasses to customize the selected state logic
*/
get options(): TOption[];
/**
* Public setter for options
*/
set options(value: TOption[]);
/**
* Determines if an option is selected
* Subclasses should override this to implement their selection logic
*
* @param option - The option to check
* @returns True if the option is selected
* @protected
*/
protected isOptionSelected(option: TOption): boolean;
/**
* Finds an option by its value
*
* @param value - The value to search for
* @returns The option if found, undefined otherwise
* @protected
*/
protected findOptionByValue(value: string): TOption | undefined;
/**
* Gets all currently selected options
*
* @returns Array of selected options
* @protected
*/
protected getSelectedOptions(): TOption[];
/**
* Parses options from either props or slot controller
* Call this in connectedCallback to initialize options
*
* @protected
*/
protected parseOptions(): void;
/**
* Re-parse options when the component updates
* This ensures options stay in sync when they change dynamically
*
* @protected
*/
protected willUpdate(_changedProperties: Map<PropertyKey, unknown>): void;
}