-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update tokens * Update tokens * Add grid changes * Update tokens * Add Grid Changes * Feature: Add grid changes * Optimise: Remove unwanted code * Fix types * Add grid changes * Fix Grid optimization * Add Grid changes * Fix header resize indicator * Add grid changes * Fix select all * remove unwanted content * Fix selction border not showing fix * Fix resize pointer issue * Fix grid selection border styling * Add Grid Context Changes * Add grid changes * Update story * Update tests * Fix lint error * Clear selection on page change * Fix type error * Remove console log * fix typo * Fix tests * Fix Grid changes * Add grid scroll changes * Add scroll fix * Add column resize changes * Update grid resize logic * Update token values * Update token values * Fix tests
- Loading branch information
1 parent
9ab8c42
commit b7b9c06
Showing
26 changed files
with
2,745 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ export default { | |
moduleNameMapper: { | ||
"^@/(.*)$": "<rootDir>/src/$1", | ||
}, | ||
setupFiles: ["./setupTests.ts"], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
import { TextEncoder } from "util"; | ||
|
||
global.TextEncoder = TextEncoder; |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { memo } from "react"; | ||
import { GridChildComponentProps, areEqual } from "react-window"; | ||
import { ItemDataType } from "./types"; | ||
import { StyledCell } from "./StyledCell"; | ||
|
||
export const Cell = memo( | ||
({ | ||
data, | ||
rowIndex, | ||
columnIndex, | ||
style, | ||
...props | ||
}: GridChildComponentProps<ItemDataType>) => { | ||
const { | ||
cell: CellData, | ||
getSelectionType, | ||
focus, | ||
columnCount, | ||
rowCount, | ||
showRowNumber, | ||
showHeader, | ||
rowHeight, | ||
rounded, | ||
} = data; | ||
|
||
const { row: focusedRow, column: focusedColumn } = focus; | ||
const isFocused = columnIndex === focusedColumn && rowIndex === focusedRow; | ||
const rightOfFocus = columnIndex - 1 === focusedColumn && rowIndex === focusedRow; | ||
const belowFocus = columnIndex === focusedColumn && rowIndex - 1 === focusedRow; | ||
|
||
const selectionType = getSelectionType({ | ||
row: rowIndex, | ||
column: columnIndex, | ||
type: "cell", | ||
}); | ||
const rightSelection = getSelectionType({ | ||
row: rowIndex, | ||
column: columnIndex - 1, | ||
type: "cell", | ||
}); | ||
const belowSelection = getSelectionType({ | ||
row: rowIndex - 1, | ||
column: columnIndex, | ||
type: "cell", | ||
}); | ||
const rightOfSelectionBorder = | ||
(selectionType === "selectDirect" || rightSelection === "selectDirect") && | ||
selectionType !== rightSelection; | ||
const belowSelectionBorder = | ||
(selectionType === "selectDirect" || belowSelection === "selectDirect") && | ||
selectionType !== belowSelection; | ||
|
||
const selectionBorderLeft = rightOfSelectionBorder || rightOfFocus || isFocused; | ||
const selectionBorderTop = belowSelectionBorder || belowFocus || isFocused; | ||
return ( | ||
<div | ||
style={style} | ||
data-row={rowIndex} | ||
data-column={columnIndex} | ||
> | ||
<StyledCell | ||
as={CellData} | ||
rowIndex={rowIndex} | ||
columnIndex={columnIndex} | ||
type="row-cell" | ||
data-selected={isFocused || selectionType === "selectDirect"} | ||
data-focused={isFocused} | ||
$isSelectedTop={selectionBorderTop} | ||
$isSelectedLeft={selectionBorderLeft} | ||
$isFocused={isFocused} | ||
$isLastRow={rowCount - 1 === rowIndex} | ||
$isLastColumn={columnCount - 1 === columnIndex} | ||
$isFirstColumn={columnIndex === 0 && !showRowNumber} | ||
$isFirstRow={rowIndex === 0 && !showHeader} | ||
$selectionType={selectionType} | ||
$height={rowHeight} | ||
$rounded={rounded} | ||
data-grid-row={rowIndex} | ||
data-grid-column={columnIndex} | ||
{...props} | ||
/> | ||
</div> | ||
); | ||
}, | ||
areEqual | ||
); |
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,127 @@ | ||
import { MouseEventHandler, PointerEventHandler, useCallback, useRef } from "react"; | ||
import styled from "styled-components"; | ||
import { ColumnResizeFn, SetResizeCursorPositionFn } from "./types"; | ||
import throttle from "lodash/throttle"; | ||
|
||
const ResizeSpan = styled.div<{ $height: number }>` | ||
top: 0; | ||
left: calc(100% - 4px); | ||
z-index: 1; | ||
position: absolute; | ||
height: ${({ $height }) => $height}px; | ||
cursor: col-resize; | ||
width: 4px; | ||
overflow: auto; | ||
&:hover, | ||
&:active, | ||
&:hover { | ||
background: ${({ theme }) => theme.click.grid.header.cell.color.stroke.selectDirect}; | ||
} | ||
&:active { | ||
height: 100%; | ||
position: fixed; | ||
} | ||
`; | ||
type PointerRefType = { | ||
width: number; | ||
pointerId: number; | ||
initialClientX: number; | ||
}; | ||
|
||
interface Props { | ||
height: number; | ||
onColumnResize: ColumnResizeFn; | ||
columnIndex: number; | ||
setResizeCursorPosition: SetResizeCursorPositionFn; | ||
} | ||
const ColumnResizer = ({ | ||
height, | ||
onColumnResize: onColumnResizeProp, | ||
columnIndex, | ||
setResizeCursorPosition, | ||
}: Props) => { | ||
const resizeRef = useRef<HTMLDivElement>(null); | ||
const pointerRef = useRef<PointerRefType | null>(null); | ||
const onColumnResize = throttle(onColumnResizeProp, 1000); | ||
|
||
const onMouseDown: MouseEventHandler<HTMLDivElement> = useCallback( | ||
e => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
if (e.detail > 1) { | ||
onColumnResize(columnIndex, 0, "auto"); | ||
} | ||
}, | ||
[columnIndex, onColumnResize] | ||
); | ||
const onPointerDown: PointerEventHandler<HTMLDivElement> = useCallback( | ||
e => { | ||
e.stopPropagation(); | ||
if (resizeRef.current) { | ||
resizeRef.current.setPointerCapture(e.pointerId); | ||
const header = resizeRef.current.closest(`[data-header="${columnIndex}"]`); | ||
if (header) { | ||
pointerRef.current = { | ||
pointerId: e.pointerId, | ||
initialClientX: e.clientX, | ||
width: header.clientWidth, | ||
}; | ||
|
||
setResizeCursorPosition( | ||
resizeRef.current, | ||
e.clientX, | ||
header.clientWidth, | ||
columnIndex | ||
); | ||
} | ||
} | ||
}, | ||
[columnIndex, setResizeCursorPosition] | ||
); | ||
|
||
const onMouseMove: MouseEventHandler<HTMLDivElement> = useCallback( | ||
e => { | ||
e.stopPropagation(); | ||
if (resizeRef.current && pointerRef.current) { | ||
const header = resizeRef.current.closest(`[data-header="${columnIndex}"]`); | ||
if (header) { | ||
resizeRef.current.setPointerCapture(pointerRef.current.pointerId); | ||
const width = | ||
header.scrollWidth + (e.clientX - pointerRef.current.initialClientX); | ||
setResizeCursorPosition(resizeRef.current, e.clientX, width, columnIndex); | ||
pointerRef.current.width = Math.max(width, 50); | ||
} | ||
} | ||
}, | ||
[columnIndex, setResizeCursorPosition] | ||
); | ||
|
||
return ( | ||
<ResizeSpan | ||
ref={resizeRef} | ||
$height={height} | ||
onPointerDown={onPointerDown} | ||
onPointerUp={e => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
if (resizeRef.current && pointerRef.current?.pointerId) { | ||
resizeRef.current.releasePointerCapture(pointerRef.current.pointerId); | ||
const shouldCallResize = e.clientX !== pointerRef.current.initialClientX; | ||
if (shouldCallResize) { | ||
onColumnResize(columnIndex, pointerRef.current.width, "manual"); | ||
} | ||
resizeRef.current.style.top = "0"; | ||
resizeRef.current.style.left = "calc(100% - 4px)"; | ||
pointerRef.current = null; | ||
} | ||
}} | ||
onMouseMove={onMouseMove} | ||
onMouseDown={onMouseDown} | ||
onClick={e => e.stopPropagation()} | ||
onMouseUp={e => e.stopPropagation()} | ||
data-resize | ||
/> | ||
); | ||
}; | ||
|
||
export default ColumnResizer; |
Oops, something went wrong.
b7b9c06
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
click-ui – ./
click-ui.vercel.app
click-ui-git-main-clickhouse.vercel.app
click-ui-clickhouse.vercel.app