UNPKG

@appbuckets/react-ui

Version:
79 lines (73 loc) 2.02 kB
'use strict'; var React = require('react'); var Checkbox = require('../../Checkbox/Checkbox.js'); var RxTable_context = require('../RxTable.context.js'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty( n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; }, } ); } }); } n['default'] = e; return Object.freeze(n); } var React__namespace = /*#__PURE__*/ _interopNamespace(React); /* -------- * Component Definition * -------- */ var AllRowsSelector = function () { // ---- // Get data from Context // ---- var _a = RxTable_context.useRxTable().selection, areAllRowsSelected = _a.areAllRowsSelected, selectedCount = _a.selectedCount, selectAllRows = _a.selectAllRows, deselectAllRows = _a.deselectAllRows; // ---- // Handle Select All Change // ---- var handleSelectCheckboxChange = React__namespace.useCallback( function () { /** If all rows are selected, deselect */ if (areAllRowsSelected) { deselectAllRows(); } else { /** Else, select all rows */ selectAllRows(); } }, [areAllRowsSelected, deselectAllRows, selectAllRows] ); // ---- // Return the Checkbox as Memoized Component // ---- return React__namespace.useMemo( function () { return React__namespace.createElement(Checkbox, { checked: areAllRowsSelected, indeterminate: !areAllRowsSelected && selectedCount > 0, onClick: handleSelectCheckboxChange, }); }, [areAllRowsSelected, selectedCount, handleSelectCheckboxChange] ); }; AllRowsSelector.displayName = 'AllRowsSelector'; module.exports = AllRowsSelector;