IntegrationsNextra

Add Custom Modal Trigger to Nextra

Copy page

Integrate Inkeep's custom modal trigger into your Nextra documentation for flexible user interactions.

What is Nextra

Nextra is a framework for creating content-focused websites using Next.js and markdown.

Get an API key

Follow these steps to create an API key for your web integration.

Copy and add the apiKey to your environment variables:

.env
NEXT_PUBLIC_INKEEP_API_KEY="INKEEP_API_KEY"

Install the component library

Customize your settings

Define your Inkeep settings.

const baseSettings = {
  apiKey,
  primaryBrandColor: "#26D6FF", // your brand color, widget color scheme is derived from this
  organizationDisplayName: "Inkeep",
  // ...optional settings
};
 
const modalSettings = {
  // optional settings
};
 
const searchSettings = {
  // optional settings
};
 
const aiChatSettings = {
  // optional settings
  aiAssistantAvatar: "/img/logo.svg", // use your own AI assistant avatar
  exampleQuestions: [
    "Example question 1?",
    "Example question 2?",
    "Example question 3?",
  ],
};
import type {
  InkeepAIChatSettings,
  InkeepSearchSettings,
  InkeepBaseSettings,
  InkeepModalSettings,
} from "@inkeep/cxkit-react";
 
const baseSettings: InkeepBaseSettings = {
  apiKey,
  primaryBrandColor: "#26D6FF", // your brand color, widget color scheme is derived from this
  organizationDisplayName: "Inkeep",
  // ...optional settings
};
 
const modalSettings: InkeepModalSettings = {
  // optional settings
};
 
const searchSettings: InkeepSearchSettings = {
  // optional settings
};
 
const aiChatSettings: InkeepAIChatSettings = {
  // optional settings
  aiAssistantAvatar: "/img/logo.svg", // use your own AI assistant avatar
  exampleQuestions: [
    "Example question 1?",
    "Example question 2?",
    "Example question 3?",
  ],
};

Define the component

We'll use the Modal Search and Chat component to create a custom trigger.

Create a ModalSearchAndChat.tsx file for our Custom Modal Trigger component. <button> represents whatever UI element you'd like to use to trigger the Inkeep Modal.

import { useCallback, useEffect, useState } from "react";
 
export default function Widget() {
  const [isOpen, setIsOpen] = useState(false);
  const [ModalSearchAndChat, setModalSearchAndChat] = useState();
 
  const handleOpenChange = useCallback((isOpen: boolean) => {
    setIsOpen(isOpen);
  }, []);
 
  //...
 
  // load the library asynchronously
  useEffect(() => {
    const loadModalSearchAndChat = async () => {
      try {
        const { InkeepModalSearchAndChat } = await import("@inkeep/cxkit-react");
        setModalSearchAndChat(() => InkeepModalSearchAndChat);
      } catch (error) {
        console.error("Failed to load ModalSearchAndChat:", error);
      }
    };
 
    loadModalSearchAndChat();
  }, []);
 
  const modalSearchAndChatProps = {
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings: {
      ...modalSettings,
      onOpenChange: handleOpenChange,
      isOpen,
    },
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      {ModalSearchAndChat && <ModalSearchAndChat {...modalSearchAndChatProps} />}
    </div>
  );
}
import { useCallback, useEffect, useState } from "react";
import type { InkeepModalSearchAndChatProps } from "@inkeep/cxkit-react";
 
export default function Widget() {
  const [isOpen, setIsOpen] = useState(false);
  const [ModalSearchAndChat, setModalSearchAndChat] =
    useState<(e: InkeepModalSearchAndChatProps) => JSX.Element>();
 
  const handleOpenChange = useCallback((isOpen: boolean) => {
    setIsOpen(isOpen);
  }, []);
 
  //...
 
  // load the library asynchronously
  useEffect(() => {
    const loadModalSearchAndChat = async () => {
      try {
        const { InkeepModalSearchAndChat } = await import(
          "@inkeep/cxkit-react"
        );
        setModalSearchAndChat(() => InkeepModalSearchAndChat);
      } catch (error) {
        console.error("Failed to load ModalSearchAndChat:", error);
      }
    };
 
    loadModalSearchAndChat();
  }, []);
 
  const modalSearchAndChatProps: InkeepModalSearchAndChatProps = {
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings: {
      ...modalSettings,
      onOpenChange: handleOpenChange,
      isOpen,
    },
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      {ModalSearchAndChat && (
        <ModalSearchAndChat {...modalSearchAndChatProps} />
      )}
    </div>
  );
}

Use the component

Add a widget component to the page:

import InkeepModalSearchAndChat from "@/components/InkeepModalSearchAndChat";
 
export default function MyApp() {
  return (
    <>
      <InkeepModalSearchAndChat />
    </>
  );
}

For a full list of customizations, check out the Custom Modal Trigger documentation.

On this page