-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #469 from icflorescu/next
Implement selectionTrigger property
- Loading branch information
Showing
14 changed files
with
218 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
import { Checkbox, TableTd, type CheckboxProps } from '@mantine/core'; | ||
import clsx from 'clsx'; | ||
import type { DataTableSelectionTrigger } from './types'; | ||
import { POINTER_CURSOR } from './utilityClasses'; | ||
|
||
type DataTableRowSelectorCellProps<T> = { | ||
record: T; | ||
index: number; | ||
trigger: DataTableSelectionTrigger; | ||
withRightShadow: boolean; | ||
checked: boolean; | ||
disabled: boolean; | ||
onChange: React.ChangeEventHandler<HTMLInputElement> | undefined; | ||
onChange: React.MouseEventHandler | undefined; | ||
getCheckboxProps: (record: T, index: number) => CheckboxProps; | ||
}; | ||
|
||
export function DataTableRowSelectorCell<T>({ | ||
record, | ||
index, | ||
trigger, | ||
onChange, | ||
withRightShadow, | ||
getCheckboxProps, | ||
...otherProps | ||
}: DataTableRowSelectorCellProps<T>) { | ||
const checkboxProps = getCheckboxProps(record, index); | ||
const enabled = !otherProps.disabled && !checkboxProps.disabled; | ||
|
||
const handleClick: React.MouseEventHandler = (e) => { | ||
e.stopPropagation(); | ||
if (trigger === 'cell' && enabled) { | ||
onChange?.(e); | ||
} | ||
}; | ||
|
||
return ( | ||
<TableTd | ||
className="mantine-datatable-row-selector-cell" | ||
className={clsx('mantine-datatable-row-selector-cell', { [POINTER_CURSOR]: trigger === 'cell' && enabled })} | ||
data-shadow-visible={withRightShadow || undefined} | ||
onClick={(e) => e.stopPropagation()} | ||
onClick={handleClick} | ||
> | ||
<Checkbox classNames={{ input: POINTER_CURSOR }} {...otherProps} {...getCheckboxProps(record, index)} /> | ||
<Checkbox | ||
classNames={enabled ? { input: POINTER_CURSOR } : undefined} | ||
onChange={onChange as unknown as React.ChangeEventHandler} | ||
{...otherProps} | ||
{...checkboxProps} | ||
/> | ||
</TableTd> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type DataTableSelectionTrigger = 'cell' | 'checkbox'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.