Skip to content

Commit cc7095a

Browse files
Adds readonly prop to grid.
1 parent ea91fa2 commit cc7095a

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

src/components/Grid/Cell.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const Cell = memo(
2121
rowStart,
2222
rowAutoHeight,
2323
updateRowHeight,
24+
readOnly = false,
2425
} = data;
2526

2627
const currentRowIndex = rowIndex + rowStart;
@@ -96,6 +97,7 @@ export const Cell = memo(
9697
$height={rowHeight}
9798
data-grid-row={currentRowIndex}
9899
data-grid-column={columnIndex}
100+
$readOnly={readOnly}
99101
$showBorder
100102
$rowAutoHeight={rowAutoHeight}
101103
{...props}

src/components/Grid/Grid.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface Props {
2828
column: number;
2929
};
3030
rowAutoHeight?: boolean;
31+
readOnly?: boolean;
3132
}
3233
const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
3334
const [focus, setFocus] = useState(focusProp);
@@ -79,6 +80,7 @@ const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
7980
});
8081
}}
8182
getMenuOptions={getMenuOptions}
83+
readOnly={props.readOnly}
8284
rowAutoHeight={props.rowAutoHeight}
8385
{...props}
8486
/>
@@ -97,6 +99,7 @@ export const Playground = {
9799
rowCount: 120,
98100
columnCount: 200,
99101
rowStart: 0,
102+
readOnly: false,
100103
},
101104
parameters: {
102105
docs: {

src/components/Grid/Grid.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
149149
onContextMenu: onContextMenuProp,
150150
forwardedGridRef,
151151
onItemsRendered: onItemsRenderedProp,
152+
readOnly = false,
152153
rowAutoHeight,
153154
...props
154155
},
@@ -439,6 +440,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
439440
rowAutoHeight,
440441
updateRowHeight,
441442
getRowHeight,
443+
readOnly,
442444
};
443445

444446
const InnerElementType = forwardRef<HTMLDivElement, InnerElementTypeTypes>(

src/components/Grid/StyledCell.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const StyledCell = styled.div<{
1313
$height: number;
1414
$type?: "body" | "header";
1515
$showBorder: boolean;
16+
$readOnly?: boolean;
1617
$rowAutoHeight?: boolean;
1718
}>`
1819
display: block;
@@ -35,6 +36,7 @@ export const StyledCell = styled.div<{
3536
$height,
3637
$type = "body",
3738
$showBorder,
39+
$readOnly,
3840
$rowAutoHeight,
3941
}) => `
4042
height: ${$rowAutoHeight ? "100%" : `${$height}px`};
@@ -64,7 +66,7 @@ export const StyledCell = styled.div<{
6466
: ""
6567
}
6668
${
67-
$isFocused
69+
$isFocused && !$readOnly
6870
? `box-shadow: inset 0 0 0 1px ${theme.click.grid[$type].cell.color.stroke.selectDirect};`
6971
: ""
7072
}
@@ -84,7 +86,7 @@ export const StyledCell = styled.div<{
8486
? `
8587
border-right-color: ${
8688
theme.click.grid[$type].cell.color.stroke[
87-
$isFocused ? "selectDirect" : $selectionType
89+
$isFocused && !$readOnly ? "selectDirect" : $selectionType
8890
]
8991
};
9092
`

src/components/Grid/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export interface ItemDataType {
160160
rowAutoHeight?: boolean;
161161
updateRowHeight: (rowIndex: number, height: number) => void;
162162
getRowHeight: (index: number) => number;
163+
readOnly?: boolean;
163164
}
164165

165166
export interface GridContextMenuItemProps extends Omit<ContextMenuItemProps, "children"> {
@@ -207,6 +208,7 @@ export interface GridProps
207208
onCopyCallback?: (copied: boolean) => void;
208209
onContextMenu?: MouseEventHandler<HTMLDivElement>;
209210
forwardedGridRef?: MutableRefObject<VariableSizeGrid>;
211+
readOnly?: boolean;
210212
rowAutoHeight?: boolean;
211213
}
212214

0 commit comments

Comments
 (0)