Skip to content
7 changes: 7 additions & 0 deletions packages/atomic-react/src/components/search/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
AtomicResultSectionVisual as LitAtomicResultSectionVisual,
AtomicResultsPerPage as LitAtomicResultsPerPage,
AtomicResultText as LitAtomicResultText,
AtomicSearchBox as LitAtomicSearchBox,
AtomicSearchBoxInstantResults as LitAtomicSearchBoxInstantResults,
AtomicSearchBoxQuerySuggestions as LitAtomicSearchBoxQuerySuggestions,
AtomicSearchBoxRecentQueries as LitAtomicSearchBoxRecentQueries,
Expand Down Expand Up @@ -255,6 +256,12 @@ export const AtomicResultText = createComponent({
elementClass: LitAtomicResultText,
});

export const AtomicSearchBox = createComponent({
tagName: 'atomic-search-box',
react: React,
elementClass: LitAtomicSearchBox,
});

export const AtomicSearchBoxInstantResults = createComponent({
tagName: 'atomic-search-box-instant-results',
react: React,
Expand Down
110 changes: 0 additions & 110 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Actions, InsightResultActionClickedEvent } from "./components/insight/a
import { InsightResultAttachToCaseEvent } from "./components/insight/atomic-insight-result-attach-to-case-action/atomic-insight-result-attach-to-case-action";
import { InteractiveResult as RecsInteractiveResult, Result as RecsResult, ResultTemplate as RecsResultTemplate, ResultTemplateCondition as RecsResultTemplateCondition } from "@coveo/headless/recommendation";
import { RecsStore } from "./components/recommendations/atomic-recs-interface/store";
import { RedirectionPayload } from "./components/common/search-box/redirection-payload";
import { i18n } from "i18next";
import { SearchBoxSuggestionElement } from "./components/common/suggestions/suggestions-types";
export { CategoryFacetSortCriterion, DateFilterRange, DateRangeRequest, FacetResultsMustMatch, FacetSortCriterion, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, NumericFilter, NumericFilterState, RangeFacetRangeAlgorithm, RangeFacetSortCriterion, RelativeDateUnit, Result, ResultTemplate, ResultTemplateCondition } from "@coveo/headless";
Expand All @@ -30,7 +29,6 @@ export { Actions, InsightResultActionClickedEvent } from "./components/insight/a
export { InsightResultAttachToCaseEvent } from "./components/insight/atomic-insight-result-attach-to-case-action/atomic-insight-result-attach-to-case-action";
export { InteractiveResult as RecsInteractiveResult, Result as RecsResult, ResultTemplate as RecsResultTemplate, ResultTemplateCondition as RecsResultTemplateCondition } from "@coveo/headless/recommendation";
export { RecsStore } from "./components/recommendations/atomic-recs-interface/store";
export { RedirectionPayload } from "./components/common/search-box/redirection-payload";
export { i18n } from "i18next";
export { SearchBoxSuggestionElement } from "./components/common/suggestions/suggestions-types";
export namespace Components {
Expand Down Expand Up @@ -1662,43 +1660,6 @@ export namespace Components {
*/
"unit": string;
}
/**
* The `atomic-search-box` component creates a search box with built-in support for suggestions.
*/
interface AtomicSearchBox {
/**
* Whether to clear all active query filters when the end user submits a new query from the search box. Setting this option to "false" is not recommended and can lead to an increasing number of queries returning no results.
*/
"clearFilters": boolean;
/**
* Whether to prevent the user from triggering searches and query suggestions from the component. Perfect for use cases where you need to disable the search conditionally. For the specific case when you need to disable the search based on the length of the query, refer to {@link minimumQueryLength}.
*/
"disableSearch": boolean;
/**
* Whether to interpret advanced [Coveo query syntax](https://docs.coveo.com/en/1552/) in the query. You should only enable query syntax in the search box if you have good reasons to do so, as it requires end users to be familiar with Coveo query syntax, otherwise they will likely be surprised by the search box behaviour. When the `redirection-url` property is set and redirects to a page with more `atomic-search-box` components, all `atomic-search-box` components need to have the same `enable-query-syntax` value.
*/
"enableQuerySyntax": boolean;
/**
* The minimum query length required to enable search. For example, to disable the search for empty queries, set this to `1`.
*/
"minimumQueryLength": number;
/**
* The amount of queries displayed when the user interacts with the search box. By default, a mix of query suggestions and recent queries will be shown. You can configure those settings using the following components as children: - atomic-search-box-query-suggestions - atomic-search-box-recent-queries
*/
"numberOfQueries": number;
/**
* Defining this option makes the search box standalone (see [Use a Standalone Search Box](https://docs.coveo.com/en/atomic/latest/usage/ssb/)). This option defines the default URL the user should be redirected to, when a query is submitted. If a query pipeline redirect is triggered, it will redirect to that URL instead (see [query pipeline triggers](https://docs.coveo.com/en/1458)).
*/
"redirectionUrl"?: string;
/**
* The delay for suggestion queries on input, in milliseconds. The suggestion request will be delayed until the end user stops typing for at least the specified amount of time. This delay is used to avoid sending too many requests to the Coveo Platform when the user is typing, as well as reducing potential input lag on low end devices. A higher delay will reduce input lag, at the cost of suggestions freshness.
*/
"suggestionDelay": number;
/**
* The timeout for suggestion queries, in milliseconds. If a suggestion query times out, the suggestions from that particular query won't be shown.
*/
"suggestionTimeout": number;
}
/**
* The `atomic-segmented-facet` displays a horizontal facet of the results for the current query.
*/
Expand Down Expand Up @@ -2084,10 +2045,6 @@ export interface AtomicQuickviewModalCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLAtomicQuickviewModalElement;
}
export interface AtomicSearchBoxCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLAtomicSearchBoxElement;
}
export interface AtomicSmartSnippetAnswerCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLAtomicSmartSnippetAnswerElement;
Expand Down Expand Up @@ -2916,26 +2873,6 @@ declare global {
prototype: HTMLAtomicResultTimespanElement;
new (): HTMLAtomicResultTimespanElement;
};
interface HTMLAtomicSearchBoxElementEventMap {
"redirect": RedirectionPayload;
}
/**
* The `atomic-search-box` component creates a search box with built-in support for suggestions.
*/
interface HTMLAtomicSearchBoxElement extends Components.AtomicSearchBox, HTMLStencilElement {
addEventListener<K extends keyof HTMLAtomicSearchBoxElementEventMap>(type: K, listener: (this: HTMLAtomicSearchBoxElement, ev: AtomicSearchBoxCustomEvent<HTMLAtomicSearchBoxElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLAtomicSearchBoxElementEventMap>(type: K, listener: (this: HTMLAtomicSearchBoxElement, ev: AtomicSearchBoxCustomEvent<HTMLAtomicSearchBoxElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
var HTMLAtomicSearchBoxElement: {
prototype: HTMLAtomicSearchBoxElement;
new (): HTMLAtomicSearchBoxElement;
};
/**
* The `atomic-segmented-facet` displays a horizontal facet of the results for the current query.
*/
Expand Down Expand Up @@ -3278,7 +3215,6 @@ declare global {
"atomic-result-rating": HTMLAtomicResultRatingElement;
"atomic-result-table-placeholder": HTMLAtomicResultTablePlaceholderElement;
"atomic-result-timespan": HTMLAtomicResultTimespanElement;
"atomic-search-box": HTMLAtomicSearchBoxElement;
"atomic-segmented-facet": HTMLAtomicSegmentedFacetElement;
"atomic-segmented-facet-scrollable": HTMLAtomicSegmentedFacetScrollableElement;
"atomic-smart-snippet": HTMLAtomicSmartSnippetElement;
Expand Down Expand Up @@ -4881,47 +4817,6 @@ declare namespace LocalJSX {
*/
"unit"?: string;
}
/**
* The `atomic-search-box` component creates a search box with built-in support for suggestions.
*/
interface AtomicSearchBox {
/**
* Whether to clear all active query filters when the end user submits a new query from the search box. Setting this option to "false" is not recommended and can lead to an increasing number of queries returning no results.
*/
"clearFilters"?: boolean;
/**
* Whether to prevent the user from triggering searches and query suggestions from the component. Perfect for use cases where you need to disable the search conditionally. For the specific case when you need to disable the search based on the length of the query, refer to {@link minimumQueryLength}.
*/
"disableSearch"?: boolean;
/**
* Whether to interpret advanced [Coveo query syntax](https://docs.coveo.com/en/1552/) in the query. You should only enable query syntax in the search box if you have good reasons to do so, as it requires end users to be familiar with Coveo query syntax, otherwise they will likely be surprised by the search box behaviour. When the `redirection-url` property is set and redirects to a page with more `atomic-search-box` components, all `atomic-search-box` components need to have the same `enable-query-syntax` value.
*/
"enableQuerySyntax"?: boolean;
/**
* The minimum query length required to enable search. For example, to disable the search for empty queries, set this to `1`.
*/
"minimumQueryLength"?: number;
/**
* The amount of queries displayed when the user interacts with the search box. By default, a mix of query suggestions and recent queries will be shown. You can configure those settings using the following components as children: - atomic-search-box-query-suggestions - atomic-search-box-recent-queries
*/
"numberOfQueries"?: number;
/**
* Event that is emitted when a standalone search box redirection is triggered. By default, the search box will directly change the URL and redirect accordingly, so if you want to handle the redirection differently, use this event. Example: ```html <script> document.querySelector('atomic-search-box').addEventListener((e) => { e.preventDefault(); // handle redirection }); </script> ... <atomic-search-box redirection-url="/search"></atomic-search-box> ```
*/
"onRedirect"?: (event: AtomicSearchBoxCustomEvent<RedirectionPayload>) => void;
/**
* Defining this option makes the search box standalone (see [Use a Standalone Search Box](https://docs.coveo.com/en/atomic/latest/usage/ssb/)). This option defines the default URL the user should be redirected to, when a query is submitted. If a query pipeline redirect is triggered, it will redirect to that URL instead (see [query pipeline triggers](https://docs.coveo.com/en/1458)).
*/
"redirectionUrl"?: string;
/**
* The delay for suggestion queries on input, in milliseconds. The suggestion request will be delayed until the end user stops typing for at least the specified amount of time. This delay is used to avoid sending too many requests to the Coveo Platform when the user is typing, as well as reducing potential input lag on low end devices. A higher delay will reduce input lag, at the cost of suggestions freshness.
*/
"suggestionDelay"?: number;
/**
* The timeout for suggestion queries, in milliseconds. If a suggestion query times out, the suggestions from that particular query won't be shown.
*/
"suggestionTimeout"?: number;
}
/**
* The `atomic-segmented-facet` displays a horizontal facet of the results for the current query.
*/
Expand Down Expand Up @@ -5363,7 +5258,6 @@ declare namespace LocalJSX {
"atomic-result-rating": AtomicResultRating;
"atomic-result-table-placeholder": AtomicResultTablePlaceholder;
"atomic-result-timespan": AtomicResultTimespan;
"atomic-search-box": AtomicSearchBox;
"atomic-segmented-facet": AtomicSegmentedFacet;
"atomic-segmented-facet-scrollable": AtomicSegmentedFacetScrollable;
"atomic-smart-snippet": AtomicSmartSnippet;
Expand Down Expand Up @@ -5660,10 +5554,6 @@ declare module "@stencil/core" {
* The `atomic-result-timespan` component renders a target result number field value as a duration.
*/
"atomic-result-timespan": LocalJSX.AtomicResultTimespan & JSXBase.HTMLAttributes<HTMLAtomicResultTimespanElement>;
/**
* The `atomic-search-box` component creates a search box with built-in support for suggestions.
*/
"atomic-search-box": LocalJSX.AtomicSearchBox & JSXBase.HTMLAttributes<HTMLAtomicSearchBoxElement>;
/**
* The `atomic-segmented-facet` displays a horizontal facet of the results for the current query.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Meta } from '@storybook/addon-docs/blocks';
import * as AtomicSearchBoxStories from './atomic-search-box.new.stories';
import { AtomicDocTemplate } from '../../../../storybook-utils/documentation/atomic-doc-template';


<Meta of={AtomicSearchBoxStories} />

<AtomicDocTemplate
stories={AtomicSearchBoxStories}
githubPath="search/atomic-search-box/atomic-search-box.ts"
tagName="atomic-search-box"
className="AtomicSearchBox"
>
This component is typically placed within the "search" section of the layout.
```html
<atomic-search-interface>
...
<atomic-search-layout>
...
<atomic-layout-section section="search">

<atomic-search-box></atomic-search-box>

</atomic-layout-section>
</atomic-search-layout>
</atomic-search-interface>
```

By default, [atomic-search-box-recent-queries](/docs/atomic-search-box-recent-queries--docs) and [atomic-search-box-query-suggestions](/docs/atomic-search-box-query-suggestions--docs) are enabled.
You can include them inside the search box to customize their properties.

To enable instant results, you must explicitly include the [atomic-search-box-instant-results](/docs/atomic-search-box-instant-results--docs) component inside the search box.


```html
<atomic-search-box>
<atomic-search-box-recent-queries max-queries="8"></atomic-search-box-recent-queries>
<atomic-search-box-query-suggestions max-suggestions="6"></atomic-search-box-query-suggestions>
<atomic-search-box-instant-results image-size="small">
<atomic-result-template>
...
</atomic-result-template>
</atomic-search-box-instant-results>
</atomic-search-box>
```

## Standalone Search Box

You can use the `atomic-search-box` as a standalone search box by setting the `redirection-url` property. This allows you to use the search box on a page that is not a search results page.

```html
<atomic-search-box redirection-url="/search"></atomic-search-box>
```

When a user submits a query in the standalone search box, they will be redirected to the URL specified in the `redirection-url` property with the query parameters appended.
</AtomicDocTemplate>
Loading
Loading