-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove InteractionMask #2061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove InteractionMask #2061
Changes from all commits
1b998a3
2eaa5a0
b085271
1bc4eca
54de1df
85d95a2
66b0dfc
526fa66
0600a9f
a596653
888dd59
362414e
36d0ce9
ff7d61e
34f11c1
c024ae7
f9b9151
5e355ed
c4b6ad7
787ab44
9404987
1b8c3a5
a9a2613
336c793
ac2c630
57ec91d
0504d29
3cc29bd
de4248a
3acd681
1c53773
689c727
a4beb50
86ca94b
ba7d7e3
5a5b9fe
a4ecddf
eda56d0
9011686
421d265
6ffb06a
4eb1100
c8cb194
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,118 @@ | ||
import React, { forwardRef, memo } from 'react'; | ||
import React, { forwardRef, memo, useRef } from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { EditorContainer, EditorPortal } from './editors'; | ||
import { CellRendererProps } from './common/types'; | ||
import { preventDefault, wrapEvent } from './utils'; | ||
import { wrapEvent } from './utils'; | ||
import { useCombinedRefs } from './hooks'; | ||
|
||
function Cell<R, SR>({ | ||
className, | ||
column, | ||
isCopied, | ||
isDraggedOver, | ||
isRowSelected, | ||
lastFrozenColumnIndex, | ||
row, | ||
rowIdx, | ||
eventBus, | ||
selectedCellProps, | ||
onRowClick, | ||
onKeyDown, | ||
onClick, | ||
onDoubleClick, | ||
onContextMenu, | ||
onDragOver, | ||
...props | ||
}: CellRendererProps<R, SR>, ref: React.Ref<HTMLDivElement>) { | ||
const cellRef = useRef<HTMLDivElement>(null); | ||
const isSelected = selectedCellProps !== undefined; | ||
const isEditing = selectedCellProps?.mode === 'EDIT'; | ||
|
||
const { cellClass } = column; | ||
className = clsx( | ||
'rdg-cell', | ||
{ | ||
'rdg-cell-frozen': column.frozen, | ||
'rdg-cell-frozen-last': column.idx === lastFrozenColumnIndex, | ||
'rdg-cell-selected': isSelected, | ||
'rdg-cell-copied': isCopied, | ||
'rdg-cell-dragged-over': isDraggedOver | ||
}, | ||
typeof cellClass === 'function' ? cellClass(row) : cellClass, | ||
className | ||
); | ||
|
||
function selectCell(openEditor?: boolean) { | ||
eventBus.dispatch('SELECT_CELL', { idx: column.idx, rowIdx }, openEditor); | ||
} | ||
|
||
function handleCellClick() { | ||
function handleClick() { | ||
selectCell(); | ||
onRowClick?.(rowIdx, row, column); | ||
} | ||
|
||
function handleCellContextMenu() { | ||
function handleContextMenu() { | ||
selectCell(); | ||
} | ||
|
||
function handleCellDoubleClick() { | ||
function handleDoubleClick() { | ||
selectCell(true); | ||
} | ||
|
||
function onRowSelectionChange(checked: boolean, isShiftClick: boolean) { | ||
eventBus.dispatch('SELECT_ROW', { rowIdx, checked, isShiftClick }); | ||
} | ||
|
||
const { cellClass } = column; | ||
className = clsx( | ||
'rdg-cell', | ||
{ | ||
'rdg-cell-frozen': column.frozen, | ||
'rdg-cell-frozen-last': column.idx === lastFrozenColumnIndex | ||
}, | ||
typeof cellClass === 'function' ? cellClass(row) : cellClass, | ||
className | ||
); | ||
function getCellContent() { | ||
if (selectedCellProps && selectedCellProps.mode === 'EDIT') { | ||
const { editorPortalTarget, ...editorProps } = selectedCellProps.editorContainerProps; | ||
const { left, top } = cellRef.current!.getBoundingClientRect(); | ||
|
||
return ( | ||
<EditorPortal target={editorPortalTarget}> | ||
<EditorContainer<R, SR> | ||
{...editorProps} | ||
rowIdx={rowIdx} | ||
row={row} | ||
column={column} | ||
left={left} | ||
top={top} | ||
/> | ||
</EditorPortal> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<column.formatter | ||
column={column} | ||
rowIdx={rowIdx} | ||
row={row} | ||
isRowSelected={isRowSelected} | ||
onRowSelectionChange={onRowSelectionChange} | ||
/> | ||
{selectedCellProps?.dragHandleProps && ( | ||
<div className="rdg-cell-drag-handle" {...selectedCellProps.dragHandleProps} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is difficult to style it from what I can tell, @nstepien is there a way to make it look like the old drag handle? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't make it overflow without degrading performance, we could use a portal but then it wouldn't be in perfect sync when scrolling. |
||
)} | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
ref={useCombinedRefs(cellRef, ref)} | ||
className={className} | ||
style={{ | ||
width: column.width, | ||
left: column.left | ||
}} | ||
onClick={wrapEvent(handleCellClick, onClick)} | ||
onDoubleClick={wrapEvent(handleCellDoubleClick, onDoubleClick)} | ||
onContextMenu={wrapEvent(handleCellContextMenu, onContextMenu)} | ||
onDragOver={wrapEvent(preventDefault, onDragOver)} | ||
onKeyDown={selectedCellProps ? wrapEvent(selectedCellProps.onKeyDown, onKeyDown) : onKeyDown} | ||
onClick={isEditing ? onClick : wrapEvent(handleClick, onClick)} | ||
onDoubleClick={isEditing ? onDoubleClick : wrapEvent(handleDoubleClick, onDoubleClick)} | ||
onContextMenu={isEditing ? onContextMenu : wrapEvent(handleContextMenu, onContextMenu)} | ||
{...props} | ||
> | ||
<column.formatter | ||
column={column} | ||
rowIdx={rowIdx} | ||
row={row} | ||
isRowSelected={isRowSelected} | ||
onRowSelectionChange={onRowSelectionChange} | ||
/> | ||
{getCellContent()} | ||
</div> | ||
); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.