Files
rowy/src/components/Table/editors/withNullEditor.tsx
2022-06-08 14:32:54 +10:00

45 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { get } from "lodash-es";
import { EditorProps } from "react-data-grid";
import { IHeavyCellProps } from "@src/components/fields/types";
/**
* Allow the cell to be editable, but disable react-data-grids default
* text editor to show.
*
* Hides the editor container so the cell below remains editable inline.
*
* Use for cells that have inline editing and dont need to be double-clicked.
*/
export default function withNullEditor(
HeavyCell?: React.ComponentType<IHeavyCellProps>
) {
return function NullEditor(props: EditorProps<any, any>) {
const { row, column } = props;
return HeavyCell ? (
<div
style={{
width: "100%",
height: "100%",
padding: "var(--cell-padding)",
position: "relative",
overflow: "hidden",
contain: "strict",
display: "flex",
alignItems: "center",
}}
>
<HeavyCell
{...(props as any)}
value={get(row, column.key)}
name={column.name as string}
type={(column as any).type}
docRef={props.row._rowy_ref}
onSubmit={() => {}}
disabled={props.column.editable === false}
/>
</div>
) : null;
};
}