@jswork/react-selection
Version:
Selection component for react.
65 lines (62 loc) • 1.5 kB
text/typescript
import React, { HTMLAttributes } from 'react';
import { TemplateCallback, ReactListProps } from '@jswork/react-list';
type StdError = {
code: string;
};
type ReactSelectionProps<T extends {
value: any;
}> = {
/**
* If true, the selection can be deselected.
* @default false
*/
allowDeselect?: boolean;
/**
* The maximum number of selection.
* @default 0(unlimited)
*/
max?: number;
/**
* The items(data) to be selected.
* @default []
*/
items: T[];
/**
* The value of selection.
* @default null
*/
value?: any;
/**
* The change handler.
* @param value
*/
onChange?: (value: any) => void;
/**
* The error handler.
* @param error
*/
onError?: (error: StdError) => void;
/**
* If true, multiple selection is allowed.
* @default false
*/
multiple?: boolean;
/**
* The template for rendering each item.
* @param args
*/
template?: TemplateCallback;
/**
* The extra options for template function.
*/
options?: any;
/**
* The props for ReactList component.
* @default {}
*/
listProps?: Omit<ReactListProps, 'template' | 'items' | 'options'>;
} & HTMLAttributes<HTMLDivElement>;
declare const ReactSelection: <T extends {
value: any;
}>(props: ReactSelectionProps<T>) => React.JSX.Element;
export { type ReactSelectionProps, type StdError, ReactSelection as default };