[react-table] fix select table props, add tests

This commit is contained in:
Grzegorz Rozdzialik
2018-12-04 11:10:20 +01:00
parent bc05cf0431
commit 1180f3973a
3 changed files with 32 additions and 7 deletions
+5 -1
View File
@@ -1,6 +1,10 @@
// Type definitions for react-table 6.7
// Project: https://github.com/react-tools/react-table
// Definitions by: Roy Xue <https://github.com/royxue>, Pavel Sakalo <https://github.com/psakalo>, Krzysztof Porębski <https://github.com/Havret>, Andy S <https://github.com/andys8>
// Definitions by: Roy Xue <https://github.com/royxue>,
// Pavel Sakalo <https://github.com/psakalo>,
// Krzysztof Porębski <https://github.com/Havret>,
// Andy S <https://github.com/andys8>,
// Grzegorz Rozdzialik <https://github.com/Gelio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
+2 -4
View File
@@ -37,10 +37,8 @@ export interface SelectTableAdditionalProps {
*/
selectType?: SelectType;
SelectInputComponent?: ComponentType<Partial<SelectInputComponentProps>>;
SelectAllInputComponent?: ComponentType<
Partial<SelectAllInputComponentProps>
>;
SelectInputComponent?: ComponentType<SelectInputComponentProps>;
SelectAllInputComponent?: ComponentType<SelectAllInputComponentProps>;
}
export interface SelectTableHOCOptions {
+25 -2
View File
@@ -3,18 +3,41 @@ import * as ReactDOM from 'react-dom';
import ReactTable, { Column } from 'react-table';
import selectTableHOC, {
SelectTableAdditionalProps
SelectTableAdditionalProps,
SelectInputComponentProps,
SelectAllInputComponentProps
} from 'react-table/lib/hoc/selectTable';
const SelectTable = selectTableHOC(ReactTable);
const SelectInput: React.StatelessComponent<SelectInputComponentProps> = ({
onClick,
id,
checked,
row
}) => (
<input
type="checkbox"
onClick={e => onClick(id, e.shiftKey, row)}
checked={checked}
/>
);
const SelectAllInput: React.StatelessComponent<
SelectAllInputComponentProps
> = ({ onClick, checked }) => (
<input type="checkbox" onClick={onClick} checked={checked} />
);
const selectTableAdditionalProps: SelectTableAdditionalProps = {
isSelected: () => true,
keyField: 'id',
selectAll: true,
selectType: 'checkbox',
toggleAll: () => null,
toggleSelection: () => null
toggleSelection: () => null,
SelectInputComponent: SelectInput,
SelectAllInputComponent: SelectAllInput
};
const data = [{ id: 1, name: 'Foo' }, { id: 2, name: 'Bar' }];