Cell Format Editor

Component to edit cell format. It can be shown in a modal dialog or embedded in your own component.

import { CanvasGrid, defaultSpreadsheetTheme } from "@rowsncolumns/spreadsheet"
import { useSpreadsheetState, CellFormatEditor, CellFormatEditorDialog } from "@rowsncolumns/spreadsheet-state"

const App = () => {
  const activeSheetId = 1
  const [theme, onChangeTheme] = useState<SpreadsheetTheme>(
    defaultSpreadsheetTheme
  );
  const {
    activeCell,
    selections,
    theme,
    onMergeCells,
    onChangeFormatting,
    onChangeBorder,
    onRequestFormatCells,
    getUserEnteredFormat,
    getEffectiveValue
  } = useSpreadsheetState({
    ...
  })
  
  const currentCellFormat = useMemo(
    () =>
      getUserEnteredFormat(
        activeSheetId,
        activeCell.rowIndex,
        activeCell.columnIndex
      ),
    [activeSheetId, activeCell, getUserEnteredFormat]
  );
  return (
    <>
      <CanvasGrid
        // Binds to keyboard shortcut and context menu
        onRequestFormatCells={onRequestFormatCells}
      />
      <CellFormatEditorDialog>
        <CellFormatEditor
          sheetId={activeSheetId}
          activeCell={activeCell}
          selections={selections}
          onChangeFormatting={onChangeFormatting}
          cellFormat={currentCellFormat}
          getEffectiveValue={getEffectiveValue}
          onMergeCells={onMergeCells}
          theme={theme}
          onChangeBorder={onChangeBorder}
        />
      </CellFormatEditorDialog>

    </>
  )
}

Last updated