import React from "react"; import styled from "styled-components"; import { usePropsRef } from "../context/PropsContext"; import { IColumnProps } from "../IColumnProps"; import { useEditorKeyHandlers } from "../hooks/useEditorKeyHandlers"; import { editingCellContext } from "../context/EditorContext"; /** * This component is absolutely positioned on the grid when a cell is being * edited. It renders the column prop's editor for that cell */ export const Editor = ({ columnProps, rows, numHeaders, }: { columnProps: IColumnProps[]; rows: TRow[]; numHeaders: number; }) => { const editingCell = editingCellContext.useState(); const setEditingCell = editingCellContext.useSetter(); const propsRef = usePropsRef(); useEditorKeyHandlers(); if (editingCell) { return ( {columnProps[editingCell.x].renderEditor({ row: rows[editingCell.y], onChange: (row) => propsRef.current.onChange([row]), onBlur: () => { setEditingCell(null); }, })} ); } return null; }; const Container = styled.div` position: absolute; top: -1px; left: -1px; bottom: 0; right: 0; z-index: 4; box-shadow: 0 2px 6px 2px rgba(60, 64, 67, 0.15); `;