Skip to content

Commit 4b6574d

Browse files
chore (atomic): migrated atomic-result-template to lit (#6159)
Co-authored-by: developer-experience-bot[bot] <91079284+developer-experience-bot[bot]@users.noreply.github.com>
1 parent 1bc5f19 commit 4b6574d

File tree

16 files changed

+901
-202
lines changed

16 files changed

+901
-202
lines changed

packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/atomic-angular.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ AtomicResultSectionExcerpt,
6969
AtomicResultSectionTitle,
7070
AtomicResultSectionTitleMetadata,
7171
AtomicResultSectionVisual,
72+
AtomicResultTemplate,
7273
AtomicResultsPerPage,
7374
AtomicSearchBoxInstantResults,
7475
AtomicSearchBoxQuerySuggestions,
@@ -129,7 +130,6 @@ AtomicResultMultiValueText,
129130
AtomicResultNumber,
130131
AtomicResultPrintableUri,
131132
AtomicResultRating,
132-
AtomicResultTemplate,
133133
AtomicResultText,
134134
AtomicResultTimespan,
135135
AtomicSearchBox,
@@ -214,6 +214,7 @@ AtomicResultSectionExcerpt,
214214
AtomicResultSectionTitle,
215215
AtomicResultSectionTitleMetadata,
216216
AtomicResultSectionVisual,
217+
AtomicResultTemplate,
217218
AtomicResultsPerPage,
218219
AtomicSearchBoxInstantResults,
219220
AtomicSearchBoxQuerySuggestions,
@@ -274,7 +275,6 @@ AtomicResultMultiValueText,
274275
AtomicResultNumber,
275276
AtomicResultPrintableUri,
276277
AtomicResultRating,
277-
AtomicResultTemplate,
278278
AtomicResultText,
279279
AtomicResultTimespan,
280280
AtomicSearchBox,

packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts

Lines changed: 28 additions & 25 deletions
Large diffs are not rendered by default.

packages/atomic/src/components.d.ts

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,37 +2099,6 @@ export namespace Components {
20992099
"imageSize": ItemDisplayImageSize;
21002100
"rows": number;
21012101
}
2102-
/**
2103-
* A [result template](https://docs.coveo.com/en/atomic/latest/usage/displaying-results#defining-a-result-template) determines the format of the query results, depending on the conditions that are defined for each template.
2104-
* @MapProp name: mustMatch;attr: must-match;docs: 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"`;type: Record<string, string[]> ;default: {}
2105-
* @MapProp name: mustNotMatch;attr: must-not-match;docs: 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";type: Record<string, string[]> ;default: {}
2106-
*/
2107-
interface AtomicResultTemplate {
2108-
/**
2109-
* 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)];`
2110-
*/
2111-
"conditions": ResultTemplateCondition[];
2112-
/**
2113-
* Gets the appropriate result template based on conditions applied.
2114-
*/
2115-
"getTemplate": () => Promise<ResultTemplate<DocumentFragment> | null>;
2116-
/**
2117-
* Verifies whether the specified fields match the specified values.
2118-
* @type {Record<string, string[]>}
2119-
*/
2120-
"mustMatch": Record<
2121-
string,
2122-
string[]
2123-
>;
2124-
/**
2125-
* Verifies whether the specified fields do not match the specified values.
2126-
* @type {Record<string, string[]>}
2127-
*/
2128-
"mustNotMatch": Record<
2129-
string,
2130-
string[]
2131-
>;
2132-
}
21332102
/**
21342103
* The `atomic-result-text` component renders the value of a string result field.
21352104
*/
@@ -3628,17 +3597,6 @@ declare global {
36283597
prototype: HTMLAtomicResultTablePlaceholderElement;
36293598
new (): HTMLAtomicResultTablePlaceholderElement;
36303599
};
3631-
/**
3632-
* A [result template](https://docs.coveo.com/en/atomic/latest/usage/displaying-results#defining-a-result-template) determines the format of the query results, depending on the conditions that are defined for each template.
3633-
* @MapProp name: mustMatch;attr: must-match;docs: 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"`;type: Record<string, string[]> ;default: {}
3634-
* @MapProp name: mustNotMatch;attr: must-not-match;docs: 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";type: Record<string, string[]> ;default: {}
3635-
*/
3636-
interface HTMLAtomicResultTemplateElement extends Components.AtomicResultTemplate, HTMLStencilElement {
3637-
}
3638-
var HTMLAtomicResultTemplateElement: {
3639-
prototype: HTMLAtomicResultTemplateElement;
3640-
new (): HTMLAtomicResultTemplateElement;
3641-
};
36423600
/**
36433601
* The `atomic-result-text` component renders the value of a string result field.
36443602
*/
@@ -4054,7 +4012,6 @@ declare global {
40544012
"atomic-result-printable-uri": HTMLAtomicResultPrintableUriElement;
40554013
"atomic-result-rating": HTMLAtomicResultRatingElement;
40564014
"atomic-result-table-placeholder": HTMLAtomicResultTablePlaceholderElement;
4057-
"atomic-result-template": HTMLAtomicResultTemplateElement;
40584015
"atomic-result-text": HTMLAtomicResultTextElement;
40594016
"atomic-result-timespan": HTMLAtomicResultTimespanElement;
40604017
"atomic-search-box": HTMLAtomicSearchBoxElement;
@@ -6072,33 +6029,6 @@ declare namespace LocalJSX {
60726029
"imageSize": ItemDisplayImageSize;
60736030
"rows": number;
60746031
}
6075-
/**
6076-
* A [result template](https://docs.coveo.com/en/atomic/latest/usage/displaying-results#defining-a-result-template) determines the format of the query results, depending on the conditions that are defined for each template.
6077-
* @MapProp name: mustMatch;attr: must-match;docs: 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"`;type: Record<string, string[]> ;default: {}
6078-
* @MapProp name: mustNotMatch;attr: must-not-match;docs: 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";type: Record<string, string[]> ;default: {}
6079-
*/
6080-
interface AtomicResultTemplate {
6081-
/**
6082-
* 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)];`
6083-
*/
6084-
"conditions"?: ResultTemplateCondition[];
6085-
/**
6086-
* Verifies whether the specified fields match the specified values.
6087-
* @type {Record<string, string[]>}
6088-
*/
6089-
"mustMatch"?: Record<
6090-
string,
6091-
string[]
6092-
>;
6093-
/**
6094-
* Verifies whether the specified fields do not match the specified values.
6095-
* @type {Record<string, string[]>}
6096-
*/
6097-
"mustNotMatch"?: Record<
6098-
string,
6099-
string[]
6100-
>;
6101-
}
61026032
/**
61036033
* The `atomic-result-text` component renders the value of a string result field.
61046034
*/
@@ -6662,7 +6592,6 @@ declare namespace LocalJSX {
66626592
"atomic-result-printable-uri": AtomicResultPrintableUri;
66636593
"atomic-result-rating": AtomicResultRating;
66646594
"atomic-result-table-placeholder": AtomicResultTablePlaceholder;
6665-
"atomic-result-template": AtomicResultTemplate;
66666595
"atomic-result-text": AtomicResultText;
66676596
"atomic-result-timespan": AtomicResultTimespan;
66686597
"atomic-search-box": AtomicSearchBox;
@@ -7063,12 +6992,6 @@ declare module "@stencil/core" {
70636992
* The `atomic-result-table-placeholder` component provides an intermediate visual state that is rendered before the first results are available.
70646993
*/
70656994
"atomic-result-table-placeholder": LocalJSX.AtomicResultTablePlaceholder & JSXBase.HTMLAttributes<HTMLAtomicResultTablePlaceholderElement>;
7066-
/**
7067-
* A [result template](https://docs.coveo.com/en/atomic/latest/usage/displaying-results#defining-a-result-template) determines the format of the query results, depending on the conditions that are defined for each template.
7068-
* @MapProp name: mustMatch;attr: must-match;docs: 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"`;type: Record<string, string[]> ;default: {}
7069-
* @MapProp name: mustNotMatch;attr: must-not-match;docs: 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";type: Record<string, string[]> ;default: {}
7070-
*/
7071-
"atomic-result-template": LocalJSX.AtomicResultTemplate & JSXBase.HTMLAttributes<HTMLAtomicResultTemplateElement>;
70726995
/**
70736996
* The `atomic-result-text` component renders the value of a string result field.
70746997
*/

packages/atomic/src/components/commerce/atomic-product-template/atomic-product-template.mdx

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { AtomicDocTemplate } from '../../../../storybook-utils/documentation/ato
1414
>
1515

1616
This component defines the UI display of your products.
17-
It can be used inside `atomic-commerce-product-list`, `atomic-commerce-recommendation-list`, or `atomic-search-box-instant-products`, and it must have a `<template>` as its child.
17+
A `template` element must be the child of an `atomic-product-template`. Furthermore, an `atomic-commerce-product-list`, `atomic-commerce-recommendation-list`, or `atomic-commerce-search-box-instant-products` must be the parent of each `atomic-product-template`.
18+
* **Note:** Any `<script>` tags that are defined inside a `<template>` element will not be executed when the products are being rendered.
1819

1920
Example using the `atomic-commerce-product-list`:
2021
```html
@@ -53,5 +54,110 @@ Example using the `atomic-commerce-product-list`:
5354
</atomic-commerce-product-list>
5455
```
5556

57+
## Template Conditions
58+
59+
You can use conditions to display different templates based on product properties. You can specify as many `must-match-*` and `must-not-match-*` attributes as you want on a template, each targeting a different field. Each attribute can accept multiple comma-separated values.
60+
61+
**Comma represents OR:** Within a single attribute, comma-separated values represent a logical OR. For example, `must-match-ec_brand="Nike,Adidas"` means the brand must be Nike OR Adidas.
62+
63+
**Multiple attributes represent AND:** All conditions from different attributes must be met (logical AND) for the template to apply to a product.
64+
65+
If you set both `must-match-*` and `must-not-match-*` for the same field and there is any overlap in values, the template will be ignored (it will never match any product).
66+
67+
**Order of declaration matters:** The first template whose conditions are met will be applied. If a default template (without conditions) is declared first, it will apply to all products, even if other templates with conditions are declared later.
68+
69+
**Examples:**
70+
71+
```html
72+
<!-- Template applies if brand is Nike or Adidas, and product is in stock -->
73+
<atomic-product-template
74+
must-match-ec_brand="Nike,Adidas"
75+
must-match-ec_in_stock="true"
76+
>
77+
<template>
78+
<!-- ... -->
79+
</template>
80+
</atomic-product-template>
81+
82+
<!-- This template will never apply, because the same value is required and forbidden -->
83+
<atomic-product-template
84+
must-match-ec_brand="Nike"
85+
must-not-match-ec_brand="Nike"
86+
>
87+
<template>
88+
<!-- ... -->
89+
</template>
90+
</atomic-product-template>
91+
```
92+
93+
```html
94+
<atomic-commerce-product-list>
95+
<!-- Template for luxury brands -->
96+
<atomic-product-template must-match-ec_brand="Gucci,Prada,Louis Vuitton">
97+
<template>
98+
<atomic-product-section-name>
99+
<atomic-product-link class="font-bold text-gold"></atomic-product-link>
100+
</atomic-product-section-name>
101+
102+
<atomic-product-section-metadata>
103+
<atomic-product-text field="ec_brand" class="block text-luxury-gold"></atomic-product-text>
104+
<span class="luxury-badge">✨ Luxury</span>
105+
</atomic-product-section-metadata>
106+
107+
<atomic-product-section-emphasized>
108+
<atomic-product-price currency="USD" class="text-gold"></atomic-product-price>
109+
</atomic-product-section-emphasized>
110+
</template>
111+
</atomic-product-template>
112+
113+
<!-- Template for out-of-stock products -->
114+
<atomic-product-template must-match-ec_in_stock="false">
115+
<template>
116+
<atomic-product-section-name>
117+
<atomic-product-link class="font-bold opacity-60"></atomic-product-link>
118+
</atomic-product-section-name>
119+
120+
<atomic-product-section-metadata>
121+
<atomic-product-field-condition if-defined="ec_brand">
122+
<atomic-product-text field="ec_brand" class="block text-neutral-dark"></atomic-product-text>
123+
</atomic-product-field-condition>
124+
<span class="out-of-stock-badge text-red-600">Out of Stock</span>
125+
</atomic-product-section-metadata>
126+
127+
<atomic-product-section-emphasized>
128+
<atomic-product-price currency="USD" class="opacity-60"></atomic-product-price>
129+
</atomic-product-section-emphasized>
130+
</template>
131+
</atomic-product-template>
132+
133+
<!-- Default template for all other products -->
134+
<atomic-product-template>
135+
<template>
136+
<atomic-product-section-name>
137+
<atomic-product-link class="font-bold"></atomic-product-link>
138+
</atomic-product-section-name>
139+
140+
<atomic-product-section-metadata>
141+
<atomic-product-field-condition if-defined="ec_brand">
142+
<atomic-product-text field="ec_brand" class="block text-neutral-dark"></atomic-product-text>
143+
</atomic-product-field-condition>
144+
145+
<atomic-product-field-condition if-defined="ec_rating">
146+
<atomic-product-rating field="ec_rating"></atomic-product-rating>
147+
</atomic-product-field-condition>
148+
</atomic-product-section-metadata>
149+
150+
<atomic-product-section-description>
151+
<atomic-product-text field="excerpt" class="block text-neutral-dark"></atomic-product-text>
152+
</atomic-product-section-description>
153+
154+
<atomic-product-section-emphasized>
155+
<atomic-product-price currency="USD"></atomic-product-price>
156+
</atomic-product-section-emphasized>
157+
</template>
158+
</atomic-product-template>
159+
</atomic-commerce-product-list>
160+
```
161+
56162
</AtomicDocTemplate>
57163

packages/atomic/src/components/commerce/atomic-product-template/atomic-product-template.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ import '../atomic-product/atomic-product';
1414
import {arrayConverter} from '@/src/converters/array-converter';
1515

1616
/**
17-
* * A product template determines the format of the products, depending on the conditions that are defined for each template.
17+
* A product template determines the format of the products, depending on the conditions that are defined for each template.
1818
*
19-
* A `template` element must be the child of an `atomic-product-template`. Furthermore, an `atomic-commerce-product-list`, `atomic-commerce-recommendation-list`, or `atomic-commerce-search-box-instant-products` must be the parent of each `atomic-product-template`.
20-
*
21-
* **Note:** Any `<script>` tags that are defined inside a `<template>` element will not be executed when the products are being rendered.
2219
* @MapProp name: mustMatch;attr: must-match;docs: The field and values that must be matched by a product item for the template to apply. For example, a template with the following attribute only applies to product items whose `filetype` is `lithiummessage` or `YouTubePlaylist`: `must-match-filetype="lithiummessage,YouTubePlaylist"`;type: Record<string, string[]> ;default: {}
2320
* @MapProp name: mustNotMatch;attr: must-not-match;docs: The field and values that must not be matched by a product item for the template to apply. For example, a template with the following attribute only applies to product items whose `filetype` is not `lithiummessage`: `must-not-match-filetype="lithiummessage";type: Record<string, string[]> ;default: {}
2421
* @slot default - The default slot where to insert the template element.

0 commit comments

Comments
 (0)