Search Bar Component

This component provides a search bar with customizable appearance and interactive search results. Users can navigate through search results using keyboard shortcuts and open relevant links.

Component Visuals

To unlock early access to the component Get Access

Installation

To integrate the Quest Search component into your project, follow these steps:

  1. Open your terminal/command prompt.

  2. Navigate to your project's root directory using the cd command if you're not already there.

  3. Run the following command to install the quest-sdk package using npm:

npm install @questlabs/react-sdk

This command will download and install the package and its dependencies into your project.

Note: Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.

Props

The Search component accepts the following props:

Prop NameTypeRequiredDetails

userId

string

required

User ID for authentication.

questId

string

required

ID of the Quest.

token

string

required

An authentication token or API key necessary for accessing Survey or quest data.

wholerScreen

boolean

optional

If true, renders the search bar in full screen.

open

boolean

optional

If true, the search bar is initially open. when it is set to ON_CTRL_K_KEY it will be open when user press control or command k .

defaultResultLength

number

optional

Limit the number of search results.

onResultClick

function

optional

Callback which will be called when user clicks on any result.

onSearch

function

optional

A function to be executed when searching. Receives the user input as a parameter.

uniqueUserId

string

optional

Unique user identifier.

uniqueEmailId

string

optional

Unique email identifier.

styleConfig

object

optional

An object containing CSS properties for styling various components within the search bar process, including body, headings, descriptions, input, label, footer, icon.

You can customize the UI with type of styleConfig would be

styleConfig?: {
    Form?: CSSProperties;
    Heading?: CSSProperties;
    Description?: CSSProperties;
    Input?: CSSProperties;
    Label?: CSSProperties;
    Footer?: CSSProperties;
    Icon?: CSSProperties;
    listHover?: {
      background?: string;
      iconBackground?: string;
      Heading?: string;
      Description?: string;
    };
 
  };
        

Component Behavior

  • Users can open and close the search bar using the keyboard shortcut (Ctrl + K).

  • Navigation through search results is possible using arrow keys (up and down).

  • Pressing Enter opens the selected search result in a new tab.

Customization

You can customize the appearance of the Search component by providing optional props such as color, backgroundColor, inputColor, and defaultResult,defaultResult


Feel free to adjust the wording or add more details as needed! If you have specific requirements or if there's anything else you'd like to include, let me know.

Usage

Here's an example of how to use the Search component in your React application:

import { QuestProvider, Search } from "@questlabs/react-sdk"
import '@questlabs/react-sdk/dist/style.css'

function App() {
  return (
 <QuestProvider apiKey={"your api key"} entityId={"your entity id"} featureFlags={{}}>
            <Search
                wholerScreen={false}
                open={"ON_CTRL_K_KEY"}
                defulatResultLength={5}
                questId={questId}
                userId={userId}
                token={token}
                onResultClick={ link => { window.location.href = link } }\
                styleConfig= {{
                    Form: {},
                    Heading: {},
                    Description: {},
                    Input: {},
                    Label: {},
                    Footer: {},
                    Icon: {},
                    listHover: {
                      background: '',
                      iconBackground: '',
                      Heading: '',
                      Description: ''
                    }
                  }}
            />
        </QuestProvider>
  );
}

export default App;

Demo

Last updated