-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathselectionCellRenderer.js
37 lines (33 loc) · 1.09 KB
/
selectionCellRenderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @flow strict
* @file Function to render the checkbox or radio table cell
* @author Box
*/
import * as React from 'react';
import Checkbox from '../../components/checkbox';
import RadioButton from '../../components/radio/RadioButton';
import isRowSelectable from './cellRendererHelper';
import type { BoxItem } from '../../common/types/core';
export default (
onItemSelect: (rowData: BoxItem) => {},
selectableType: string,
extensionsWhitelist: string[],
hasHitSelectionLimit: boolean,
isRadio: boolean,
): (({ rowData: BoxItem }) => {}) => ({ rowData }: { rowData: BoxItem }) => {
const { name = '', selected = false } = rowData;
const Component = isRadio ? RadioButton : Checkbox;
if (!isRowSelectable(selectableType, extensionsWhitelist, hasHitSelectionLimit, rowData)) {
return <span />;
}
return (
<Component
hideLabel
label={name}
name={name}
onChange={() => onItemSelect(rowData)}
value={name}
{...{ [isRadio ? 'isSelected' : 'isChecked']: selected }}
/>
);
};