diff --git a/packages/atomic-react/src/components/commerce/components.ts b/packages/atomic-react/src/components/commerce/components.ts index 6bcfecff5f8..2039889d4f2 100644 --- a/packages/atomic-react/src/components/commerce/components.ts +++ b/packages/atomic-react/src/components/commerce/components.ts @@ -31,6 +31,7 @@ import { AtomicIcon as LitAtomicIcon, AtomicInsightGenerateAnswerButton as LitAtomicInsightGenerateAnswerButton, AtomicInsightInterface as LitAtomicInsightInterface, + AtomicInsightResultTemplate as LitAtomicInsightResultTemplate, AtomicLayoutSection as LitAtomicLayoutSection, AtomicNumericRange as LitAtomicNumericRange, AtomicProduct as LitAtomicProduct, @@ -251,6 +252,12 @@ export const AtomicInsightInterface = createComponent({ elementClass: LitAtomicInsightInterface, }); +export const AtomicInsightResultTemplate = createComponent({ + tagName: 'atomic-insight-result-template', + react: React, + elementClass: LitAtomicInsightResultTemplate, +}); + export const AtomicLayoutSection = createComponent({ tagName: 'atomic-layout-section', react: React, diff --git a/packages/atomic-react/src/components/search/components.ts b/packages/atomic-react/src/components/search/components.ts index db3743b8a99..4e46ff2c3a8 100644 --- a/packages/atomic-react/src/components/search/components.ts +++ b/packages/atomic-react/src/components/search/components.ts @@ -20,6 +20,7 @@ import { AtomicIcon as LitAtomicIcon, AtomicInsightGenerateAnswerButton as LitAtomicInsightGenerateAnswerButton, AtomicInsightInterface as LitAtomicInsightInterface, + AtomicInsightResultTemplate as LitAtomicInsightResultTemplate, AtomicLayoutSection as LitAtomicLayoutSection, AtomicLoadMoreResults as LitAtomicLoadMoreResults, AtomicNoResults as LitAtomicNoResults, @@ -207,6 +208,12 @@ export const AtomicInsightInterface = createComponent({ elementClass: LitAtomicInsightInterface, }); +export const AtomicInsightResultTemplate = createComponent({ + tagName: 'atomic-insight-result-template', + react: React, + elementClass: LitAtomicInsightResultTemplate, +}); + export const AtomicLayoutSection = createComponent({ tagName: 'atomic-layout-section', react: React, diff --git a/packages/atomic/src/components.d.ts b/packages/atomic/src/components.d.ts index 83074a36a0f..841f460da5d 100644 --- a/packages/atomic/src/components.d.ts +++ b/packages/atomic/src/components.d.ts @@ -6,7 +6,7 @@ */ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; import { DateFilterRange, DateRangeRequest, FacetResultsMustMatch, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition } from "@coveo/headless"; -import { FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, ResultTemplate as InsightResultTemplate, ResultTemplateCondition as InsightResultTemplateCondition, UserAction as IUserAction } from "@coveo/headless/insight"; +import { FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, UserAction as IUserAction } from "@coveo/headless/insight"; import { ItemDisplayBasicLayout, ItemDisplayDensity, ItemDisplayImageSize, ItemDisplayLayout } from "./components/common/layout/display-options"; import { ItemRenderingFunction } from "./components/common/item-list/stencil-item-list-common"; import { NumberInputType } from "./components/common/facets/facet-number-input/number-input-type"; @@ -20,7 +20,7 @@ import { AnyBindings } from "./components/common/interface/bindings"; import { i18n } from "i18next"; import { SearchBoxSuggestionElement } from "./components/common/suggestions/suggestions-types"; export { DateFilterRange, DateRangeRequest, FacetResultsMustMatch, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition } from "@coveo/headless"; -export { FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, ResultTemplate as InsightResultTemplate, ResultTemplateCondition as InsightResultTemplateCondition, UserAction as IUserAction } from "@coveo/headless/insight"; +export { FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, UserAction as IUserAction } from "@coveo/headless/insight"; export { ItemDisplayBasicLayout, ItemDisplayDensity, ItemDisplayImageSize, ItemDisplayLayout } from "./components/common/layout/display-options"; export { ItemRenderingFunction } from "./components/common/item-list/stencil-item-list-common"; export { NumberInputType } from "./components/common/facets/facet-number-input/number-input-type"; @@ -397,38 +397,6 @@ export namespace Components { */ "sandbox": string; } - interface AtomicInsightResultTemplate { - /** - * A function that must return true on results for the result template to apply. Set programmatically before initialization, not via attribute. For example, the following targets a template and sets a condition to make it apply only to results whose `title` contains `singapore`: `document.querySelector('#target-template').conditions = [(result) => /singapore/i.test(result.title)];` - */ - "conditions": InsightResultTemplateCondition[]; - /** - * Gets the appropriate result template based on conditions applied. - */ - "getTemplate": () => Promise | null>; - /** - * The field that, when defined on a result item, would allow the template to be applied. For example, a template with the following attribute only applies to result items whose `filetype` and `sourcetype` fields are defined: `if-defined="filetype,sourcetype"` - */ - "ifDefined"?: string; - /** - * The field that, when defined on a result item, would prevent the template from being applied. For example, a template with the following attribute only applies to result items whose `filetype` and `sourcetype` fields are NOT defined: `if-not-defined="filetype,sourcetype"` - */ - "ifNotDefined"?: string; - /** - * The field and values that define which result items the condition must be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is `lithiummessage` or `YouTubePlaylist`: `must-match-filetype="lithiummessage,YouTubePlaylist"` - */ - "mustMatch": Record< - string, - string[] - >; - /** - * The field and values that define which result items the condition must not be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is not `lithiummessage`: `must-not-match-filetype="lithiummessage"` - */ - "mustNotMatch": Record< - string, - string[] - >; - } interface AtomicInsightSearchBox { /** * Whether to prevent the user from triggering a search from the component. Perfect for use cases where you need to disable the search conditionally, like when the input is empty. @@ -1343,12 +1311,6 @@ declare global { prototype: HTMLAtomicInsightResultQuickviewActionElement; new (): HTMLAtomicInsightResultQuickviewActionElement; }; - interface HTMLAtomicInsightResultTemplateElement extends Components.AtomicInsightResultTemplate, HTMLStencilElement { - } - var HTMLAtomicInsightResultTemplateElement: { - prototype: HTMLAtomicInsightResultTemplateElement; - new (): HTMLAtomicInsightResultTemplateElement; - }; interface HTMLAtomicInsightSearchBoxElement extends Components.AtomicInsightSearchBox, HTMLStencilElement { } var HTMLAtomicInsightSearchBoxElement: { @@ -1789,7 +1751,6 @@ declare global { "atomic-insight-result-children-template": HTMLAtomicInsightResultChildrenTemplateElement; "atomic-insight-result-list": HTMLAtomicInsightResultListElement; "atomic-insight-result-quickview-action": HTMLAtomicInsightResultQuickviewActionElement; - "atomic-insight-result-template": HTMLAtomicInsightResultTemplateElement; "atomic-insight-search-box": HTMLAtomicInsightSearchBoxElement; "atomic-insight-smart-snippet": HTMLAtomicInsightSmartSnippetElement; "atomic-insight-smart-snippet-feedback-modal": HTMLAtomicInsightSmartSnippetFeedbackModalElement; @@ -2181,34 +2142,6 @@ declare namespace LocalJSX { */ "sandbox"?: string; } - interface AtomicInsightResultTemplate { - /** - * A function that must return true on results for the result template to apply. Set programmatically before initialization, not via attribute. For example, the following targets a template and sets a condition to make it apply only to results whose `title` contains `singapore`: `document.querySelector('#target-template').conditions = [(result) => /singapore/i.test(result.title)];` - */ - "conditions"?: InsightResultTemplateCondition[]; - /** - * The field that, when defined on a result item, would allow the template to be applied. For example, a template with the following attribute only applies to result items whose `filetype` and `sourcetype` fields are defined: `if-defined="filetype,sourcetype"` - */ - "ifDefined"?: string; - /** - * The field that, when defined on a result item, would prevent the template from being applied. For example, a template with the following attribute only applies to result items whose `filetype` and `sourcetype` fields are NOT defined: `if-not-defined="filetype,sourcetype"` - */ - "ifNotDefined"?: string; - /** - * The field and values that define which result items the condition must be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is `lithiummessage` or `YouTubePlaylist`: `must-match-filetype="lithiummessage,YouTubePlaylist"` - */ - "mustMatch"?: Record< - string, - string[] - >; - /** - * The field and values that define which result items the condition must not be applied to. For example, a template with the following attribute only applies to result items whose `filetype` is not `lithiummessage`: `must-not-match-filetype="lithiummessage"` - */ - "mustNotMatch"?: Record< - string, - string[] - >; - } interface AtomicInsightSearchBox { /** * Whether to prevent the user from triggering a search from the component. Perfect for use cases where you need to disable the search conditionally, like when the input is empty. @@ -2878,7 +2811,6 @@ declare namespace LocalJSX { "atomic-insight-result-children-template": AtomicInsightResultChildrenTemplate; "atomic-insight-result-list": AtomicInsightResultList; "atomic-insight-result-quickview-action": AtomicInsightResultQuickviewAction; - "atomic-insight-result-template": AtomicInsightResultTemplate; "atomic-insight-search-box": AtomicInsightSearchBox; "atomic-insight-smart-snippet": AtomicInsightSmartSnippet; "atomic-insight-smart-snippet-feedback-modal": AtomicInsightSmartSnippetFeedbackModal; @@ -2949,7 +2881,6 @@ declare module "@stencil/core" { "atomic-insight-result-children-template": LocalJSX.AtomicInsightResultChildrenTemplate & JSXBase.HTMLAttributes; "atomic-insight-result-list": LocalJSX.AtomicInsightResultList & JSXBase.HTMLAttributes; "atomic-insight-result-quickview-action": LocalJSX.AtomicInsightResultQuickviewAction & JSXBase.HTMLAttributes; - "atomic-insight-result-template": LocalJSX.AtomicInsightResultTemplate & JSXBase.HTMLAttributes; "atomic-insight-search-box": LocalJSX.AtomicInsightSearchBox & JSXBase.HTMLAttributes; "atomic-insight-smart-snippet": LocalJSX.AtomicInsightSmartSnippet & JSXBase.HTMLAttributes; "atomic-insight-smart-snippet-feedback-modal": LocalJSX.AtomicInsightSmartSnippetFeedbackModal & JSXBase.HTMLAttributes; diff --git a/packages/atomic/src/components/insight/atomic-insight-result-template/atomic-insight-result-template.mdx b/packages/atomic/src/components/insight/atomic-insight-result-template/atomic-insight-result-template.mdx new file mode 100644 index 00000000000..64542518f90 --- /dev/null +++ b/packages/atomic/src/components/insight/atomic-insight-result-template/atomic-insight-result-template.mdx @@ -0,0 +1,147 @@ +import { Meta } from '@storybook/addon-docs/blocks'; +import * as AtomicInsightResultTemplateStories from './atomic-insight-result-template.new.stories'; +import { AtomicDocTemplate } from '@/storybook-utils/documentation/atomic-doc-template'; + + + + + +This component defines the UI display of your search results within an Insight interface. +A `template` element must be the child of an `atomic-insight-result-template`. Furthermore, an `atomic-insight-result-list` or `atomic-insight-folded-result-list` must be the parent of each `atomic-insight-result-template`. + +**Note:** Any `