-
Notifications
You must be signed in to change notification settings - Fork 33
/
SelectContentSelectionCheckbox.jsx
43 lines (36 loc) · 1.24 KB
/
SelectContentSelectionCheckbox.jsx
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
38
39
40
41
42
43
import React from 'react';
import { useContextSelector } from 'use-context-selector';
import PropTypes from 'prop-types';
import { CheckboxControl } from '@edx/paragon';
import { MAX_CONTENT_ITEMS_PER_HIGHLIGHT_SET } from '../data/constants';
import { ContentHighlightsContext } from '../ContentHighlightsContext';
const SelectContentSelectionCheckbox = ({ row }) => {
const {
indeterminate,
checked,
...toggleRowSelectedProps
} = row.getToggleRowSelectedProps();
const currentSelectedRowsCount = useContextSelector(
ContentHighlightsContext,
v => Object.keys(v[0].stepperModal.currentSelectedRowIds).length,
);
const isDisabled = !checked && currentSelectedRowsCount === MAX_CONTENT_ITEMS_PER_HIGHLIGHT_SET;
return (
<div>
<CheckboxControl
{...toggleRowSelectedProps}
checked={checked}
title={!isDisabled ? 'Toggle row selected' : undefined}
isIndeterminate={indeterminate}
disabled={isDisabled}
style={{ cursor: !isDisabled ? 'pointer' : undefined }}
/>
</div>
);
};
SelectContentSelectionCheckbox.propTypes = {
row: PropTypes.shape({
getToggleRowSelectedProps: PropTypes.func.isRequired,
}).isRequired,
};
export default SelectContentSelectionCheckbox;