Props

Configure the React PPTX editor document, mode, fonts, chrome, callbacks, and ref.

Configure the editor

This example loads .pptx bytes, keeps the instance, and saves the edited deck:

import { useState } from 'react';
import { PptxEditor, type PptxEditorInstance } from '@pptx-editor.dev/react';
import '@pptx-editor.dev/core/styles/editor.css';

export function DeckEditor({
  bytes,
  upload,
}: {
  bytes: Uint8Array;
  upload: (bytes: Uint8Array) => Promise<void>;
}) {
  const [editor, setEditor] = useState<PptxEditorInstance | null>(null);

  async function save() {
    const saved = editor?.save();
    if (saved) await upload(saved);
  }

  return (
    <div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
      <button onClick={save} disabled={!editor}>
        Save
      </button>
      <div style={{ flex: 1, minHeight: 0 }}>
        <PptxEditor document={bytes} mode="edit" onReady={setEditor} />
      </div>
    </div>
  );
}

For generated signatures, see docs/api/react/index.api.md in the repository.

Set props

Document

PropTypeDescription
documentUint8ArrayThe .pptx bytes. A new array loads a new deck. Without it, the editor shows its loading sheet.
autoCorrectbooleanEnables AutoCorrect for symbols, ellipses, fractions, and typed list starts. The editor makes no automatic capitals, curly quotes, or dashes; keyboards and systems that offer them apply them. Defaults to true. Read when the editor is created; remount to change it.
mode'edit' | 'view'Edit the deck, or only show it. Defaults to 'edit'. Changes apply without a reload.
readClipboardDrawingClipboardDrawingReaderReads copied shapes from the system clipboard in a desktop host, so they paste as editable shapes. Read when the editor is created. See Copy and paste.

Fonts

PropTypeDescription
fontsFontConfiguration | FontConfigurationFragment | FontResolverFont bytes for layout. A change replaces the fonts in place; the deck, the selection, and the undo history stay. Wrap a resolver in useFonts() to keep one identity.
fontFamiliesreadonly string[]Families the font picker offers besides the standard ones and the deck's own. A change updates the picker in place; the deck and the undo history stay.

Without fonts, the editor measures with the deck's embedded fonts and then the packaged substitutes, and it fetches nothing. See Fonts.

Capability modules

PropTypeDescription
modulesreadonly EditorModule[]Capability modules, such as the review, collaboration, and drawing modules of @pptx-editor.dev/pro. Read once, when the editor is created. A later change has no effect and prints a development warning.

Create the list once, outside the component, so each render passes the same modules:

import { PptxEditor } from '@pptx-editor.dev/react';
import { reviewModule } from '@pptx-editor.dev/pro';

const modules = [reviewModule()];

export function ReviewedDeck({ bytes }: { bytes: Uint8Array }) {
  return <PptxEditor document={bytes} modules={modules} />;
}

@pptx-editor.dev/pro is under the EigenPal Pro License. To use other modules after mount, change the key of PptxEditor to create a new editor.

Appearance and language

PropTypeDescription
colorMode'light' | 'dark' | 'system'The chrome color mode. Defaults to 'light'. The slides keep the deck's own colors. See Appearance.
localeLocaleCatalogThe interface strings. English when you omit it. See Language.
classNamestringAdded after the pptx-default class of the viewport.

Packaged parts

Set a part to false to hide it, or pass its props object to configure it.

PropTypeDefault
toolbarboolean | ToolbarPropstrue
menuboolean | MenuPropsfalse
contextMenuboolean | PptxEditorContextMenuPropstrue
hyperlinkPopupbooleantrue
slideRailboolean | SlideRailPropstrue
notesPaneboolean | NotesPanePropstrue

A popups.contextMenu or popups.hyperlink entry takes precedence over the corresponding part prop. Hiding a control does not disable its editing command. For examples, see Change one part of the packaged editor.

Chrome

PropTypeDescription
popupsPptxEditorPopupsReplaces or turns off the dialogs and popups the editor mounts. See Dialogs.
openFailureboolean | PptxEditorOpenFailurePropsThe notice for a file that does not open. false removes it. Defaults to true. See Open failure.
renderOpenFailureActions(context: OpenFailureContext) => ReactNodeYour own buttons in the open-failure notice, before Close. context has failure, message, and dismiss().
childrenReactNodeExtra content inside the viewport, after the slide show.

Handle callbacks

CallbackPayloadDescription
onReadyeditor: PptxEditorInstanceCalled once for each instance, after the editor mounts. This does not mean the document has loaded.
onChangeeditor: PptxEditorInstanceCalled after every change of editor state, also for selection changes.
onFontErrorerror: EditorFontErrorCalled for each font failure: a failed origin, a refused face, or a failed resolution. Without it, each failure prints one warning.

Use the instance from onReady for actions and one-time reads:

MemberReturnsDescription
save()Uint8Array<ArrayBuffer> | nullSerializes the deck to .pptx. Returns null when no deck is open. new Blob([bytes]) takes the bytes as they are.
load(bytes)Promise<CommandResult>Opens other .pptx bytes in the same instance.
exec(command, options?)CommandResultRuns a typed EditorCommand. A refusal returns ok: false with a reason.
can(command, options?)CanResultSays whether a command can run now, without running it.
snapshot()EditorSnapshotReads the current state. A direct call does not subscribe; use useEditorState in components.
focus()voidGives the keyboard back to the slide: the text caret, else the slide surface.

Use the ref

<PptxEditor> and PptxEditor.Root take a ref to a PptxEditorRef. Use it to reach the editor from a parent component:

import { useRef } from 'react';
import { PptxEditor, type PptxEditorRef } from '@pptx-editor.dev/react';
import '@pptx-editor.dev/core/styles/editor.css';

export function DeckEditor({
  bytes,
  upload,
}: {
  bytes: Uint8Array;
  upload: (bytes: Uint8Array) => Promise<void>;
}) {
  const editorRef = useRef<PptxEditorRef>(null);

  async function save() {
    const saved = editorRef.current?.save();
    if (saved) await upload(saved);
  }

  return (
    <div style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
      <button onClick={save}>Save</button>
      <div style={{ flex: 1, minHeight: 0 }}>
        <PptxEditor ref={editorRef} document={bytes} />
      </div>
    </div>
  );
}
MethodReturnsDescription
load(bytes)Promise<CommandResult>Opens .pptx bytes. Resolves when the deck is open, or with the refusal.
save()Uint8Array<ArrayBuffer> | nullSerializes the deck to .pptx. Returns null when no deck is open. new Blob([bytes]) takes the bytes as they are.
getEditor()PptxEditorInstance | nullReturns the editor instance, or null before it mounts.
focus()voidGives the keyboard back to the slide: the text caret, else the slide surface.
exec(command, options?)CommandResultRuns a typed EditorCommand, as editor.exec.
snapshot()EditorSnapshotReads the current state, as editor.snapshot().

Every method is safe before the editor mounts: load and exec refuse with disabled.noEditor, save and getEditor return null, focus does nothing, and snapshot returns an empty snapshot. Everything else is on the instance that getEditor() returns.

Limits

  • onReady runs once for each instance. A new document reuses the instance, so onReady does not run again.
  • save() returns the bytes only. Your application owns any download or upload.
  • modules applies when the instance is created. To change it, remount with a different key.
  • locale follows the content of the catalog, not its identity, so an inline object does not reload the strings on each render.
  • popups entries set to false turn off that dialog's interface. The operation stays available to the API.

Next steps