### Basic SlidingPanel Usage in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SlidingPanel.md Demonstrates the fundamental setup of the SlidingPanel component in a React application. It shows how to manage the panel's open/close state and integrate its sub-components like Wrapper, Backdrop, Content, and Close. This example assumes a React environment with necessary imports. ```tsx import { SlidingPanel } from "@orama/ui/components"; import React from "react"; function Example() { const [open, setOpen] = React.useState(false); return ( <> setOpen(false)}>

Panel Title

Your panel content goes here.

); } ``` -------------------------------- ### Install Dependencies with PNPM Source: https://github.com/oramasearch/orama-ui/blob/main/README.md Installs project dependencies using the PNPM package manager. This is a foundational step for setting up the project locally. ```sh pnpm install ``` -------------------------------- ### Complete Search Page Example with Orama UI React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Provides a comprehensive example of a search page using Orama UI React components. It features a toggle for switching between regular keyword search and NLP search, dynamic labels and placeholders, and handles both search types. Includes necessary imports and state management. This snippet is specific to React. ```tsx import { SearchInput } from "@orama/ui-react"; function SearchPage() { const [searchMode, setSearchMode] = useState<"search" | "nlp">("search"); const handleSearch = (term: string) => { console.log("Regular search:", term); }; const handleNlpSearch = (query: string) => { console.log("NLP search:", query); }; return (
{/* Mode toggle */}
{/* Search interface */} {searchMode === "nlp" ? "Ask a question" : "Search our content"}
{searchMode === "nlp" ? "Ask AI" : "Search"}
); } ``` -------------------------------- ### Basic Modal Usage with Modal.Root Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/Modal.md Demonstrates the basic implementation of the Modal component using `Modal.Root` and `Modal.Trigger` for opening the modal. It showcases how to structure modal content and a close button within the component hierarchy. This example assumes a standard setup where `Modal.Root` manages the state. ```tsx import { Modal } from "@orama/ui/components"; // Basic usage with Modal.Trigger function ExampleModal() { return ( Open Modal

Modal Title

This is the modal content.

); } ``` -------------------------------- ### Complete Search Results UI Example (React) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchResults.md This example demonstrates a complete search results UI using Orama UI components, including handling loading, error, no results, and displaying results with item-specific actions. ```tsx import { SearchResults } from "@orama/ui-react"; function SearchPage() { return ( {/* Loading state */}
Searching...
{/* Error state */} {(error) => (

Something went wrong

{error.message}

)}
{/* No results state */} {(term) => (

No results found

No results found for "{term}". Try different keywords.

)}
{/* Results list */} {(result, index) => (

{result.document.title}

{result.document.description}

Relevance: {Math.round(result.score * 100)}%
)}
); } ``` -------------------------------- ### ChatRoot Usage with Configuration and Callbacks Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/ChatRoot.md Shows how to configure the ChatRoot component with default ask options (including throttle_delay) and provide callbacks for start, completion, and error events of ask operations. ```tsx console.log("Starting:", options)} onAskComplete={() => console.log("Completed")} onAskError={(error) => console.error("Error:", error)> ``` -------------------------------- ### Complete Orama UI Search Example in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md A comprehensive example of the SearchRoot component in React, demonstrating scoped search context with a namespace, custom search handler with analytics tracking, pre-populated search term, and rendering search results. The language is set to English. ```tsx { // Analytics tracking analytics.track("search_performed", { query: params.term, filters: params.filterBy, namespace: "help-center", language: "en", }); // Custom search logic console.log("Searching with:", params); }, searchTerm: "Getting started", selectedFacet: "All", count: 0, }}> Search Documentation {(hit) => (

{hit.document.title}

{hit.document.content}

)}
``` -------------------------------- ### Install Orama UI Packages Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/README.md Installs the necessary Orama UI and Orama core packages using npm, pnpm, or yarn. These packages are essential for using Orama's search and chat functionalities within a React application. ```bash npm install @orama/ui @orama/core # or pnpm install @orama/ui @orama/core # or yarn add @orama/ui @orama/core ``` -------------------------------- ### Run Development Server (Bash) Source: https://github.com/oramasearch/orama-ui/blob/main/apps/docs/README.md Starts the local development server for the Orama UI project. This command is typically run from the project's root directory. It allows for live preview and auto-updates as code changes. ```bash yarn dev ``` -------------------------------- ### SearchInput.Submit Component Usage Examples Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Provides examples of using the SearchInput.Submit component for triggering search actions. It covers basic usage, including an icon, and applying custom styling and disabling the button. ```tsx Search Search Find Results ``` -------------------------------- ### SearchInput.Label Component Usage Examples Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Illustrates how to use the SearchInput.Label component for accessibility and semantic structure. Examples show basic label usage, rendering as a heading, and applying custom styling. ```tsx Search Products Find What You Need Search ``` -------------------------------- ### Basic ChatRoot Usage Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/ChatRoot.md Demonstrates the basic setup of the ChatRoot component, wrapping a ChatComponent and providing the Orama client instance. ```tsx import { ChatRoot } from "@orama/ui/components"; import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); function App() { return ( ); } ``` -------------------------------- ### RecentSearches.Provider Integration Example (TypeScript) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/RecentSearches.md Demonstrates how to integrate RecentSearches.Provider with SearchRoot to manage separate recent search histories based on namespace. This ensures distinct search contexts have their own isolated search history. ```tsx import { SearchRoot, RecentSearches } from "@/components"; // Different namespaces create separate search histories function ProductSearch() { return ( {/* This will save searches under "recent_searches_products" */} {(term) => ( {term} )} ); } function DocumentSearch() { return ( {/* This will save searches under "recent_searches_documents" */} {(term) => ( {term} )} ); } ``` -------------------------------- ### React: Initialize and Use useClipboard Hook Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/hooks/useClipboard.md Provides a concise example of initializing and using the 'useClipboard' hook to copy a string. It shows the direct call to 'copyToClipboard' and the potential for 'copied' and 'error' states. This snippet is a simplified illustration of the hook's core functionality. ```tsx const { copyToClipboard, copied, error } = useClipboard(); copyToClipboard("Hello world!"); ``` -------------------------------- ### SearchRoot with Language Support Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md This example demonstrates how to enable language-specific search behavior by providing the 'lang' prop to the SearchRoot component. This example specifically sets the language to 'italian'. ```tsx Cerca... ``` -------------------------------- ### React Provider for SearchContext with Custom Initialization Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/context/SearchContext.md Example of setting up a custom provider for SearchContext and SearchDispatchContext in a React application. It initializes the Orama client and uses React's useReducer hook to manage the search state. ```tsx import { SearchContext, SearchDispatchContext, useSearchContext, useSearchDispatch, searchReducer, initialSearchState, } from "@orama/ui/contexts"; import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); function SearchProvider({ children }) { const [state, dispatch] = React.useReducer(searchReducer, { ...initialSearchState, client: orama, }); return ( {children} ); } ``` -------------------------------- ### Basic SearchRoot Usage Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md This example shows the basic integration of the SearchRoot component, wrapping a SearchInput.Wrapper to provide Orama search context to the search input elements. ```tsx Search {/* Other search-related components */} ``` -------------------------------- ### Basic Usage of RecentSearches Component Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/RecentSearches.md Demonstrates the fundamental usage of the RecentSearches component, including setting up the provider, rendering a list of recent searches, and a clear button. This example showcases the basic integration flow for displaying and managing recent search history. ```tsx import { RecentSearches } from "@/components/RecentSearches"; function SearchInterface() { return ( console.log("Searched:", query)} onClear={() => console.log("Cleared recent searches")} > {(term, index) => ( {term} )} Clear All ); } ``` -------------------------------- ### Run Development Servers with PNPM Source: https://github.com/oramasearch/orama-ui/blob/main/README.md Starts all applications within the monorepo using PNPM. This command is used to run the development servers for the Next.js apps and other services. ```sh pnpm dev ``` -------------------------------- ### RecentSearches.List Styling Example (TypeScript) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/RecentSearches.md Shows how to apply custom CSS classes to the RecentSearches.List and its items for tailored styling. This allows for flexible design integration using utility-first CSS frameworks like Tailwind CSS. ```tsx {(term) => ( {term} )} ``` -------------------------------- ### SearchInput.Input Component Usage Examples Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Demonstrates the various ways to use the SearchInput.Input component, including default search-on-type behavior, disabling search-on-type for form submission, and configuring Orama search parameters. ```tsx console.log('Typed:', value)} /> ``` -------------------------------- ### Chat Interactions Wrapper Usage Example (React) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/ChatInteractions.md A comprehensive example demonstrating the usage of the `ChatInteractions.Wrapper` component. This wrapper likely manages chat state and provides interaction data to its children, including user prompts, assistant messages, and action buttons like copy message. ```tsx import { ChatInteractions } from "./ChatInteractions"; {(interaction) => ( <> {interaction.query} {interaction.response} )} ``` -------------------------------- ### Basic Tabs Component Usage in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/Tabs.md Demonstrates the fundamental usage of the Tabs component, including setting up a wrapper, tab list with buttons, and corresponding content panels. This example shows how to create a simple static tab interface. ```tsx import { Tabs } from "@orama/ui"; Tab 1 Tab 2 Content for Tab 1 Content for Tab 2 ``` -------------------------------- ### SearchInput Usage Pattern: Real-time Search Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Example of implementing real-time search functionality using SearchInput.Wrapper, SearchInput.Label, and SearchInput.Input with `searchOnType={true}`. ```tsx Quick Search ``` -------------------------------- ### Basic PromptTextArea Usage in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/PromptTextArea.md Demonstrates how to import and use the PromptTextArea component's wrapper, field, and button in a React application. This setup allows for a basic chat input experience. ```tsx import { PromptTextArea } from "@orama/ui"; Send ``` -------------------------------- ### Advanced Usage of RecentSearches Component Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/RecentSearches.md Illustrates advanced configuration of the RecentSearches component, including custom search handlers, styling for the list and items, and additional search parameters. This example highlights how to tailor the component's behavior and appearance for complex search scenarios. ```tsx import { RecentSearches } from "@/components/RecentSearches"; function AdvancedSearchInterface() { const handleSearch = (query: string) => { // Additional logic doSomething(query); }; return (

Recent Searches

{(term, index) => ( {term} #{index + 1} )} Clear History
); } ``` -------------------------------- ### Basic FacetTabs Usage in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/FacetTabs.md This example shows the basic implementation of the FacetTabs component in a React application. It includes importing the necessary components from '@orama/ui/components' and structuring the tabs with a wrapper, list, and individual items, utilizing a render function to display facet information. ```tsx import { FacetTabs } from "@orama/ui/components"; function Example() { return ( {(group, isSelected) => ( {group.name} ({group.count}) )} ); } ``` -------------------------------- ### Using ChatRoot Context and useChat Hook in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/hooks/useChat.md Demonstrates how `ChatRoot` provides base configuration that is inherited by the `useChat` hook. It shows how to override context defaults at the hook level and further refine options during an `ask` call. The example illustrates the priority order of configuration merging. ```tsx // ChatRoot provides base configuration console.error("Global error:", error)> ; function ChatComponent() { // Inherits ChatRoot configuration, can override per operation const { ask } = useChat( { throttle_delay: 100 }, // Hook defaults override context { onAskComplete: () => console.log("Local completion handler") }, ); const handleAsk = async () => { // Priority: ChatRoot < Hook defaults < Call options await ask({ query: "Question", throttle_delay: 200, // Highest priority }); }; } ``` -------------------------------- ### Import and Use Orama UI Components Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/README.md Demonstrates importing core search components and their associated CSS from the Orama UI library. It shows how to wrap the application with `SearchRoot` and compose a basic search interface using `SearchInput` and `SearchResults`. ```tsx import { SearchRoot, SearchInput, SearchResults, } from "@orama/ui/components"; import "@orama/ui/styles.css";
{(result) => (

{result.title}

{result.description}

)}
``` -------------------------------- ### Accessible PromptTextArea Example Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/PromptTextArea.md An example demonstrating the use of accessibility attributes like `aria-label` for the PromptTextArea field and its associated button, ensuring better usability for screen reader users. ```tsx Send ``` -------------------------------- ### Initialize Orama Client Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md This snippet demonstrates how to initialize an OramaCloud client instance, which is required for the SearchRoot component. It takes project and API keys as arguments. ```tsx import { SearchRoot, SearchInput } from "@orama/ui/components"; import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); ``` -------------------------------- ### Multiple Search Contexts with Namespaces in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md Illustrates how to set up multiple, independent search contexts within the same application by utilizing different namespaces for product and documentation searches. Each context can have its own language configuration. ```tsx { /* Product search context */ } ; { /* Documentation search context */ } ; ``` -------------------------------- ### FacetTabs Example with Different Filter Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/FacetTabs.md This is an alternative example of the FacetTabs component, demonstrating its flexibility. It shows how to use FacetTabs.Item with a different filter property ('type' instead of 'category') and displays the group name and count as the tab label. ```tsx {(group, isSelected) => ( {group.name} ({group.count}) )} ``` -------------------------------- ### Configuring SearchInput Provider Context in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Demonstrates setting up the SearchInput.Provider to manage search mode and local input state. It shows how to wrap child components, enabling NLP search mode and defining a callback for NLP search submissions. This provider is optional but enhances functionality for specific scenarios like `searchOnType={false}`. ```tsx console.log("NLP:", term)> Search ``` -------------------------------- ### Chat UI with Smooth Scroll using useScrollableContainer Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/hooks/useScrollableContainer.md Shows an example of integrating `useScrollableContainer` with `@orama/ui/components.ChatInteractions` to create a chat interface with smooth scroll-to-bottom behavior. This example automatically scrolls to the bottom when new messages arrive and recalculates button visibility on scroll or streaming events. It requires React, `@orama/ui/hooks`, and `@orama/ui/components`. ```tsx import React, { useEffect } from "react"; import { useScrollableContainer } from "@orama/ui/hooks"; import { ChatInteractions } from "@orama/ui/components"; function ChatBox() { const { containerRef, showGoToBottomButton, scrollToBottom, recalculateGoToBottomButton, } = useScrollableContainer(); // Automatically scrolls to the bottom when new messages arrive useEffect(() => { if (interactions.length > 0) { scrollToBottom({ animated: true }); } recalculateGoToBottomButton(); }, [interactions, scrollToBottom, recalculateGoToBottomButton]); return (
Chatbox header...
{ scrollToBottom({ animated: true }); }} > {(interaction) => (
{interaction.response}
)}
Chatbox footer...
); } ``` -------------------------------- ### Pre-populating Search State in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchRoot.md Demonstrates how to pre-populate the search state using the `initialState` prop in the SearchRoot component. This includes setting the search term, selected facet, and initial results for a French language search context. ```tsx {/* Search UI starts with pre-populated data */} ``` -------------------------------- ### Set Up Orama Cloud Client Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/README.md Initializes the Orama Cloud JavaScript client using your project ID and API key. This client is required to connect your React application to your Orama Cloud project for search and data retrieval. ```tsx import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); ``` -------------------------------- ### TypeScript Interface for UseChatCallbacks Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/hooks/useChat.md Defines the structure for optional callbacks that can be provided to the useChat hook to react to different stages of the ask operation (start, completion, error). ```typescript interface UseChatCallbacks { onAskStart?: (options: ExtendedAnswerConfig) => void; onAskComplete?: () => void; onAskError?: (error: Error) => void; } ``` -------------------------------- ### Configure Search Mode with Provider (React) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchResults.md The SearchResults.Provider component allows setting the search mode ('search' or 'nlp') for its descendants. This example shows how to set the mode to 'nlp'. ```tsx import { SearchResults } from "@orama/ui-react"; {(result) =>
{result.document.title}
}
``` -------------------------------- ### ChatRoot Usage with Pre-populated State Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/ChatRoot.md Illustrates how to initialize the ChatRoot component with a pre-populated state, including previous interactions and an initial user prompt. ```tsx ``` -------------------------------- ### Configuring Search Modes with SearchInput.Provider Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Demonstrates how to set the search mode ('search' or 'nlp') using the SearchInput.Provider component. Examples show a standard Orama search and an NLP-based search. ```tsx console.log('Search:', term)}> Search console.log('NLP:', term)}> Ask AI ``` -------------------------------- ### Configure Search Mode with Wrapper (React) Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchResults.md The SearchResults.Wrapper component can also be used to set the search mode ('search' or 'nlp') for its child components. This example demonstrates setting the mode to 'nlp'. ```tsx import { SearchResults } from "@orama/ui-react"; {(result) =>
{result.document.title}
}
``` -------------------------------- ### React Hook Usage: useRecentSearches Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/hooks/useRecentSearches.md Example of how to use the useRecentSearches hook in a React component to manage recent search queries. It demonstrates initializing the hook, handling search input, and displaying recent searches. ```tsx import { useRecentSearches } from "@/hooks/useRecentSearches"; function SearchComponent() { const { recentSearches, addSearch, clearSearches } = useRecentSearches( "english", "products", ); const handleSearch = (query: string) => { // Add search immediately addSearch()(query); // Or add search with debounce addSearch(300)(query); }; return (
handleSearch(e.target.value)} />

Recent Searches

{recentSearches.map((search) => (
{search.term} - {new Date(search.timestamp).toLocaleString()}
))}
); } ``` -------------------------------- ### Create API Routes (TypeScript) Source: https://github.com/oramasearch/orama-ui/blob/main/apps/docs/README.md Demonstrates how to create API routes within a Next.js application. API routes are defined within the `app/api/` directory using `route.ts` files. Subfolders define specific endpoints. ```typescript // Example: app/api/hello/route.ts export async function GET(request: Request) { return new Response('Hello, Next.js!') } ``` -------------------------------- ### Set Global Callbacks for Ask Operations in ChatRoot Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/ChatRoot.md The `ChatRoot` component provides global callback handlers for ask operations to manage different stages of the process. `onAskStart` is called when an ask operation begins, `onAskComplete` when it finishes successfully, and `onAskError` when an error occurs. These callbacks are essential for tracking analytics, managing loading states, and handling errors. ```tsx { console.log('Ask started with options:', options) // Track analytics, show loading states, etc. }} onAskComplete={() => { console.log('Ask completed successfully') // Hide loading states, track success, etc. }} onAskError={(error) => { console.error('Ask failed:', error) // Show error notifications, track failures, etc. }} > ``` -------------------------------- ### FacetTabs Component: Faceted Search Example Source: https://context7.com/oramasearch/orama-ui/llms.txt Implements a tab-based filtering system for search results using the FacetTabs component. It allows users to filter results by categories and displays them using SearchResults. ```tsx import { SearchRoot, SearchInput, FacetTabs, SearchResults } from "@orama/ui/components"; import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); function FacetedSearch() { return ( {(group, isSelected) => ( {group.name} ({group.count}) )} {(result) => (

{result.document.title}

{result.document.category}
)}
); } ``` -------------------------------- ### Implementing NLP Search Form Submission in React Source: https://github.com/oramasearch/orama-ui/blob/main/packages/ui/docs/components/SearchInput.md Demonstrates configuring the SearchInput.Form for Natural Language Processing (NLP) searches. This example utilizes the SearchInput.Provider to set the mode to 'nlp', defines specific search parameters, and provides an `onNlpSearch` callback to handle the NLP query and its results. ```tsx console.log('NLP search:', term)} searchParams={{ limit: 20, boost: { title: 2 } }}> Ask AI ``` -------------------------------- ### SearchInput Component: Live Search Example Source: https://context7.com/oramasearch/orama-ui/llms.txt Implements a search-as-you-type input field using the SearchInput component. It connects to Orama Cloud for real-time search suggestions and supports advanced search parameters. ```tsx import { SearchRoot, SearchInput } from "@orama/ui/components"; import { OramaCloud } from "@orama/core"; const orama = new OramaCloud({ projectId: "your-project-id", apiKey: "your-api-key", }); // Search-as-you-type implementation function LiveSearch() { return ( Search ); } ```