Skip to content

Grid: add 'readonly' prop #599

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/Grid/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const Cell = memo(
rowStart,
rowAutoHeight,
updateRowHeight,
readOnly = false,
} = data;

const currentRowIndex = rowIndex + rowStart;
Expand Down Expand Up @@ -96,6 +97,7 @@ export const Cell = memo(
$height={rowHeight}
data-grid-row={currentRowIndex}
data-grid-column={columnIndex}
$readOnly={readOnly}
$showBorder
$rowAutoHeight={rowAutoHeight}
{...props}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Grid/Grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
column: number;
};
rowAutoHeight?: boolean;
readOnly?: boolean;
}
const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
const [focus, setFocus] = useState(focusProp);
Expand Down Expand Up @@ -79,6 +80,7 @@ const Grid = ({ columnCount, rowCount, focus: focusProp, ...props }: Props) => {
});
}}
getMenuOptions={getMenuOptions}
readOnly={props.readOnly}
rowAutoHeight={props.rowAutoHeight}
{...props}
/>
Expand All @@ -97,6 +99,7 @@ export const Playground = {
rowCount: 120,
columnCount: 200,
rowStart: 0,
readOnly: false,
},
parameters: {
docs: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
onContextMenu: onContextMenuProp,
forwardedGridRef,
onItemsRendered: onItemsRenderedProp,
readOnly = false,
rowAutoHeight,
...props
},
Expand Down Expand Up @@ -439,6 +440,7 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
rowAutoHeight,
updateRowHeight,
getRowHeight,
readOnly,
};

const InnerElementType = forwardRef<HTMLDivElement, InnerElementTypeTypes>(
Expand Down
6 changes: 4 additions & 2 deletions src/components/Grid/StyledCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const StyledCell = styled.div<{
$height: number;
$type?: "body" | "header";
$showBorder: boolean;
$readOnly?: boolean;
$rowAutoHeight?: boolean;
}>`
display: block;
Expand All @@ -35,6 +36,7 @@ export const StyledCell = styled.div<{
$height,
$type = "body",
$showBorder,
$readOnly,
$rowAutoHeight,
}) => `
height: ${$rowAutoHeight ? "100%" : `${$height}px`};
Expand Down Expand Up @@ -64,7 +66,7 @@ export const StyledCell = styled.div<{
: ""
}
${
$isFocused
$isFocused && !$readOnly
? `box-shadow: inset 0 0 0 1px ${theme.click.grid[$type].cell.color.stroke.selectDirect};`
: ""
}
Expand All @@ -84,7 +86,7 @@ export const StyledCell = styled.div<{
? `
border-right-color: ${
theme.click.grid[$type].cell.color.stroke[
$isFocused ? "selectDirect" : $selectionType
$isFocused && !$readOnly ? "selectDirect" : $selectionType
]
};
`
Expand Down
2 changes: 2 additions & 0 deletions src/components/Grid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface ItemDataType {
rowAutoHeight?: boolean;
updateRowHeight: (rowIndex: number, height: number) => void;
getRowHeight: (index: number) => number;
readOnly?: boolean;
}

export interface GridContextMenuItemProps extends Omit<ContextMenuItemProps, "children"> {
Expand Down Expand Up @@ -207,6 +208,7 @@ export interface GridProps
onCopyCallback?: (copied: boolean) => void;
onContextMenu?: MouseEventHandler<HTMLDivElement>;
forwardedGridRef?: MutableRefObject<VariableSizeGrid>;
readOnly?: boolean;
rowAutoHeight?: boolean;
}

Expand Down