Skip to content

Commit

Permalink
refactor(useSelectRows): implement types (carbon-design-system#5462)
Browse files Browse the repository at this point in the history
  • Loading branch information
makafsal authored Jun 13, 2024
1 parent 608e9b1 commit bf7c0c8
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { SelectAll } from './Datagrid/DatagridSelectAll';
import { selectionColumnId } from './common-column-ids';
import { pkg, carbon } from '../../settings';
import { handleToggleRowSelected } from './Datagrid/addons/stateReducer';
import { ColumnInstance, Hooks, TableInstance } from 'react-table';
import { DataGridState } from './types';

const blockClass = `${pkg.prefix}--datagrid`;
const checkboxClass = `${pkg.prefix}--datagrid__checkbox-cell`;

const useSelectRows = (hooks) => {
const useSelectRows = (hooks: Hooks) => {
useHighlightSelection(hooks);
const useInstance = (instance) => {
const useInstance = (instance: TableInstance) => {
const { rows } = instance;
const rowsWithSelect = rows.map((row) => ({ ...row, isSelectable: true }));
Object.assign(instance, { rows: rowsWithSelect });
Expand Down Expand Up @@ -46,11 +48,11 @@ const useSelectRows = (hooks) => {
: []),
{
id: selectionColumnId,
Header: (gridState) => <SelectAll {...gridState} />,
Header: (gridState: DataGridState<any>) => <SelectAll {...gridState} />,
Cell: (gridState) => <SelectRow {...gridState} />,
},
...newColOrder,
];
] as ColumnInstance[];
});
};

Expand Down Expand Up @@ -115,6 +117,7 @@ const SelectRow = (datagridState) => {
rowData: row,
isChecked: event.target.checked,
getRowId,
selectAll: null,
});
};

Expand All @@ -140,7 +143,7 @@ const SelectRow = (datagridState) => {
cellProps.className,
{
[`${checkboxClass}-sticky-left`]:
isFirstColumnStickyLeft && windowSize > 671,
isFirstColumnStickyLeft && Number(windowSize) > 671,
},
])}
ariaLabel={title}
Expand Down

0 comments on commit bf7c0c8

Please sign in to comment.