IntegrationsNextjs

Add Custom Modal Trigger to Next.js

Integrate Inkeep's custom modal trigger into your Next.js application for flexible user interactions.

What is Next.js

Next.js is a React full-stack app development framework. You can use Inkeep's React component library to Add AI Search & Chat functionality to apps or documentation and marketing sites built with Next.js.

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

npm install @inkeep/cxkit-react
yarn add @inkeep/cxkit-react

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.

Note
Note

For Next.js apps that use App Router, use the "use client" directive at the top of the file to load the widget client side.

import dynamic from "next/dynamic";
import { useCallback, useState } from "react";
 
const ModalSearchAndChat = dynamic(
  () => import("@inkeep/cxkit-react").then((mod) => mod.InkeepModalSearchAndChat),
  {
    ssr: false,
  }
);
 
function InkeepModalSearchAndChat() {
  const [isOpen, setIsOpen] = useState(false);
  //...
 
  const handleOpenChange = useCallback((isOpen: boolean) => {
    setIsOpen(isOpen);
  }, []);
 
  const customTriggerProps = {
    baseSettings,
    aiChatSettings,
    searchSettings,
      modalSettings: {
      ...modalSettings,
      onOpenChange: handleOpenChange,
      isOpen,
    },
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      <ModalSearchAndChat {...customTriggerProps} />
    </div>
  );
}
 
export default InkeepModalSearchAndChat;
import dynamic from "next/dynamic";
import { useCallback, useState } from "react";
import { InkeepModalSearchAndChatProps } from "@inkeep/cxkit-react";
 
const ModalSearchAndChat = dynamic(
  () =>
    import("@inkeep/cxkit-react").then((mod) => mod.InkeepModalSearchAndChat),
  {
    ssr: false,
  }
);
 
function InkeepModalSearchAndChat() {
  const [isOpen, setIsOpen] = useState(false);
  //...
 
  const handleOpenChange = useCallback((isOpen: boolean) => {
    setIsOpen(isOpen);
  }, []);
 
  const customTriggerProps: InkeepModalSearchAndChatProps = {
    baseSettings,
    aiChatSettings,
    searchSettings,
    modalSettings: {
      ...modalSettings,
      onOpenChange: handleOpenChange,
      isOpen,
    },
  };
 
  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Modal</button>
      <ModalSearchAndChat {...customTriggerProps} />
    </div>
  );
}
 
export default InkeepModalSearchAndChat;

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

On this page