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 install the Quest react-sdk into your project, follow these steps:

  • Open your terminal/command prompt.

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

  • 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.

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


The Search component accepts the following props

Usage

To integrate the Search component into your React application, follow these steps

  • Import the CSS: In your JavaScript or TypeScript file where you're using the Search, import the CSS styles for the component. This ensures that the component's styling is applied correctly.

import '@questlabs/react-sdk/dist/style.css'
  • Import the TutorialComponent: Import the Searchcomponent from the @questlabs/react-sdk package.

  • Import the QuestProvider Component: Import the QuestProvider component from the @questlabs/react-sdk package.

import { QuestProvider, Search } from '@questlabs/react-sdk';
  • Pass the Required Props: Pass the required props to the QuestProvider. The required props are apiKey, and entityId. and required props for the Searchcomponent are userId, questId, token

Replace "your-api-key" and "your-entity-id" with your actual Quest API credentials

Replace "your-token", "your-user-id", "your-questId" with your actual configuration details.

Code & Steps

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

function App() {
  return (
      <QuestProvider
        apiKey="your-apikey"
        entityId="your-entity-Id" 
        apiType= "PRODUCTION" // STAGING 
      >
      <Search> </Search>
      </QuestProvider>
  );
}

export default App;

Example Usage

Here's an example of how to use the Searchcomponent within your React application

Props

The Search component accepts the following props:

Prop Name
Type
Required
Details

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.

placeholder

string

optional

search bar placeholder text

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 .

icons

array

optional

array of icon url's in string

buttonText

string

optional

set the button text

searchDetails

boolean

optional

true: show search details false: not show

width

string

string

give the width of your search component

iconColor

string

string

give the icon color

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.

Icon

string

optional

CSS Properties

listHover

objeact

optional

an object contain values background,iconBackground,Heading,Description

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 = {{
    CommandButton: { },
    Description: { },
    Footer: { },
    Form: { },
    Heading: { },
    Icon: { },
    Input: { },
    Label: { },
    listHover: { },
    Topbar: { }
}}

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


Demo

Last updated