@jswork/react-selection
Version:
Selection component for react.
66 lines (63 loc) • 1.65 kB
TypeScript
import React from 'react';
import { ReactListProps, KeyExtractor, Slot } from '@jswork/react-list';
export { Slot } from '@jswork/react-list';
declare enum ErrorCode {
MAX_LIMIT_EXCEED = "MAX_LIMIT_EXCEED"
}
type StdError = {
code: ErrorCode;
};
interface SelectionItemSlotProps<T> {
item: T;
index: number;
data: T[];
active: boolean;
disabled: boolean;
onClick: () => void;
}
type ReactSelectionProps<T> = Omit<ReactListProps<T>, 'slots' | 'keyExtractor'> & {
/**
* If true, the selection can be deselected.
* @default false
*/
allowDeselect?: boolean;
/**
* The maximum number of selection.
* @default 1000
*/
max?: number;
/**
* The value of selection.
* @default null
*/
value?: any;
/**
* Extract the value from an item. Uses the same signature as KeyExtractor.
* @default 'value'
*/
valueExtractor?: KeyExtractor<T>;
/**
* The change handler.
*/
onChange?: (value: any) => void;
/**
* The error handler.
*/
onError?: (error: StdError) => void;
/**
* If true, multiple selection is allowed.
* @default false
*/
multiple?: boolean;
/**
* Slot configuration for rendering items and empty state.
*/
slots: {
item: Slot<SelectionItemSlotProps<T>>;
empty?: Slot<{
data: T[];
}>;
};
};
declare const ReactSelection: <T>(props: ReactSelectionProps<T>) => React.JSX.Element;
export { ErrorCode, ReactSelection, type ReactSelectionProps, type SelectionItemSlotProps, type StdError, ReactSelection as default };