CommandButton

A built-in React component of Inkdrop that extends Button. When clicked, it dispatches an Inkdrop command, and its tooltip automatically shows the command's keybinding.

To get the class of the CommandButton component:

import type { CommandButtonProps } from '@inkdropapp/types'

const CommandButton =
  inkdrop.components.getComponentClass<CommandButtonProps>('CommandButton')

Props

CommandButton accepts all Button props in addition to the following:

type CommandButtonProps = ButtonProps & {
  // The command to dispatch when the button is clicked.
  command?: string
  // The DOM element to dispatch the command on. Defaults to document.body.
  commandTarget?: HTMLElement
  // The detail payload passed with the dispatched command.
  commandDetail?: any
}

Example

import React from 'react'
import type { CommandButtonProps } from '@inkdropapp/types'

const SaveButton: React.FC = () => {
  const CommandButton =
    inkdrop.components.getComponentClass<CommandButtonProps>('CommandButton')

  return (
    <CommandButton primary command="core:save-note">
      Save
    </CommandButton>
  )
}

export default SaveButton

See also

  • Button — the base button component.
  • Command Registry — how Inkdrop commands are registered and dispatched.
Can you help us improve the docs? 🙏

The source of these docs is here on GitHub. If you see a way these docs can be improved, please fork us!