@sajari/sdk-react
Version:
React SDK for the Sajari API
82 lines (81 loc) • 2.46 kB
TypeScript
export declare type OptionsFn = () => string;
export interface Options {
[k: string]: string | OptionsFn;
}
export declare type CallbackFn = (filter: Filter) => void;
/**
* Filter is a helper class for building filters from UI components.
*/
export declare class Filter {
private current;
private options;
private multi;
private joinOperator;
private listeners;
/**
* Constructs an instance of Filter.
*
* @example
* const filter = new Filter({});
*/
constructor(options: Options, // Dictionary of name -> filter pairs
initial?: string | string[], // List of initially selected items
multi?: boolean, // Multiple selections allowed?
joinOperator?: "OR" | "AND");
/**
* Register a listener for a specific event.
*/
listen(event: string, callback: CallbackFn): () => void;
/**
* Set the state of the filter.
*/
set(name: string, on: boolean): void;
/**
* returns whether the filter is set or not.
*/
isSet(name: string): boolean;
/**
* Merge options into the filter options.
*
* Set an option to null to remove it.
*/
setOptions(options: {
[k: string]: string | null;
}): void;
/**
* Get all the options defined in this filter.
*/
getOptions(...fields: string[]): Options;
/**
* Get the current selection in this filter.
*/
get(...fields: string[]): string[];
/**
* Builds up the filter string from the current filter and it's children.
*/
filter(): string;
/**
* Emits a selection updated event to the selection updated listener.
* @private
*/
protected _emitSelectionUpdated(): void;
/**
* Emits an options updated event to the options updated listener.
* @private
*/
protected _emitOptionsUpdated(): void;
/** @private */
private _setMulti;
}
/**
* CombineFilters is a helper for combining multiple Filter instances
* into one.
*
* Whenever any of the combined filters are updated, the events are
* propagated up to the returned "root" filter.
*
* @param filters Array of filters to combine.
* @param [operator="AND"] Operator to apply between them ("AND" | "OR").
* @return The resulting Filter.
*/
export declare const CombineFilters: (filters: Filter[], operator?: "OR" | "AND") => Filter;