Sanity Library Reference Docs
    Preparing search index...

    Interface Tool<Options>

    A tool can be thought of as a top-level "view" or "app". They are available through the global menu bar, and has a URL route associated with them.

    In essence, a tool is a React component that is rendered when the tool is active, along with a title, name (URL segment) and icon.

    Tools can handle intents such as "edit" or "create" by defining a function for the canHandleIntent property, as well as the getIntentState property, which defines what an intent will be mapped to in terms of the tool's URL state.

    interface Tool<Options = any> {
        canHandleIntent?: (
            intent: string,
            params: Record<string, unknown>,
            payload: unknown,
        ) => boolean | { [key: string]: boolean };
        component: ComponentType<{ tool: Tool<Options> }>;
        controlsDocumentTitle?: boolean;
        getIntentState?: (
            intent: string,
            params: Record<string, string>,
            routerState: RouterState,
            payload: unknown,
        ) => unknown;
        icon?: ComponentType;
        name: string;
        options?: Options;
        router?: Router;
        title: string;
    }

    Type Parameters

    • Options = any
    Index

    Properties

    canHandleIntent?: (
        intent: string,
        params: Record<string, unknown>,
        payload: unknown,
    ) => boolean | { [key: string]: boolean }

    Determines whether the tool can handle the given intent.

    Can either return a boolean, or an object where the keys represent the parameters that can/can not be handled. This will be used to determine whether or not a tool is the best suited to handle an intent. Note that an object of only false values (or an empty object) is treated as true, so you want to explicitly return false if you know the intent cannot fulfill the intent request.

    Type declaration

      • (
            intent: string,
            params: Record<string, unknown>,
            payload: unknown,
        ): boolean | { [key: string]: boolean }
      • Parameters

        • intent: string

          The intent to check.

        • params: Record<string, unknown>

          The parameters for the intent.

        • payload: unknown

          The payload for the intent.

        Returns boolean | { [key: string]: boolean }

        Boolean: whether it can handle the intent. Object: Values representing what specific parameters can be handled.

    component: ComponentType<{ tool: Tool<Options> }>

    The React component that renders the tool.

    controlsDocumentTitle?: boolean

    Determines whether the tool will control the document.title.

    getIntentState?: (
        intent: string,
        params: Record<string, string>,
        routerState: RouterState,
        payload: unknown,
    ) => unknown

    Gets the state for the given intent.

    Type declaration

      • (
            intent: string,
            params: Record<string, string>,
            routerState: RouterState,
            payload: unknown,
        ): unknown
      • Parameters

        • intent: string

          The intent to get the state for.

        • params: Record<string, string>

          The parameters for the intent.

        • routerState: RouterState

          The current router state. See router.RouterState

        • payload: unknown

          The payload for the intent.

        Returns unknown

        The state for the intent.

    icon?: ComponentType

    React component for the icon representing the tool.

    name: string

    The name of the tool, used as part of the URL.

    options?: Options

    Options are passed through from the configuration to the component defined by the component

    router?: Router

    The router for the tool. See router.Router

    title: string

    Title of the tool - used for the navigation menu item, along with the icon.