@vtex/ads-stories 0.4.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +44 -88
- package/dist/cdn/vtex-ads-stories.js +1313 -74
- package/dist/cdn/vtex-ads-stories.js.map +1 -1
- package/dist/cjs/index.cjs +3744 -513
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +46 -15
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/cjs/react.d.cts +51 -5
- package/dist/cjs/story-DAiAN9v-.d.cts +260 -0
- package/dist/esm/index.d.ts +46 -15
- package/dist/esm/index.js +3348 -217
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react.d.ts +51 -5
- package/dist/esm/story-DAiAN9v-.d.ts +260 -0
- package/package.json +18 -4
- package/src/cdn.ts +7 -3
- package/src/commerce-events.ts +93 -0
- package/src/components/card/card.ts +79 -14
- package/src/components/carousel/carousel-skeleton.ts +113 -0
- package/src/components/carousel/carousel.ts +715 -0
- package/src/components/carousel/index.ts +22 -0
- package/src/components/events/events-controller.ts +222 -0
- package/src/components/events/index.ts +6 -0
- package/src/components/icons/assets/caret-left-bold.svg +1 -0
- package/src/components/icons/assets/caret-right-bold.svg +1 -0
- package/src/components/icons/assets/caret-up-bold.svg +1 -0
- package/src/components/icons/assets/minus.svg +1 -0
- package/src/components/icons/assets/plus.svg +1 -0
- package/src/components/icons/assets/trash.svg +1 -0
- package/src/components/icons/assets/warning-circle-fill.svg +1 -0
- package/src/components/icons/index.ts +14 -0
- package/src/components/media/index.ts +8 -1
- package/src/components/media/media.styles.ts +113 -0
- package/src/components/media/media.ts +124 -23
- package/src/components/media/video-controller.ts +127 -6
- package/src/components/player/index.ts +6 -2
- package/src/components/player/player.ts +824 -50
- package/src/components/product/cta.ts +56 -0
- package/src/components/product/index.ts +22 -0
- package/src/components/product/price.ts +86 -0
- package/src/components/product/product.styles.ts +426 -0
- package/src/components/product/product.ts +336 -0
- package/src/index.ts +17 -1
- package/src/locales/en.ts +39 -0
- package/src/locales/es.ts +40 -0
- package/src/locales/index.ts +36 -0
- package/src/locales/pt.ts +39 -0
- package/src/locales/types.ts +44 -0
- package/src/react.ts +55 -7
- package/src/story/index.ts +5 -1
- package/src/story/story.ts +679 -49
- package/src/tag-name.ts +1 -0
- package/src/types.ts +8 -12
- package/src/utils/fetch-story.ts +113 -0
- package/src/utils/hydrate-products.ts +112 -0
- package/src/utils/media-ready.ts +58 -0
- package/src/utils/safe-url.ts +36 -0
- package/src/utils/send-event.ts +71 -0
- package/src/utils/with-timeout.ts +43 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { html, nothing } from "lit";
|
|
2
|
+
import type { StoryLabels } from "../../locales";
|
|
3
|
+
import { icon } from "../icons";
|
|
4
|
+
import { destinationUrl, httpUrl } from "../../utils/safe-url";
|
|
5
|
+
import type { StoryAd } from "../../types";
|
|
6
|
+
import type { StoryProductDetails } from "../../utils/hydrate-products";
|
|
7
|
+
import { readProductPrice, type ProductPrice } from "./price";
|
|
8
|
+
|
|
9
|
+
/** What the card shows of the Story's product, with the prices formatted. */
|
|
10
|
+
export interface CardProduct {
|
|
11
|
+
name: string;
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
price?: string;
|
|
14
|
+
/** The "from" price, struck through. Only with a price. */
|
|
15
|
+
listPrice?: string;
|
|
16
|
+
/** The product page, opened by view product link button. */
|
|
17
|
+
url?: string;
|
|
18
|
+
/** The SKU added to the cart. Without one, there is no add to cart. */
|
|
19
|
+
sku?: string;
|
|
20
|
+
/** The product's seller, sent with the SKU when known. */
|
|
21
|
+
seller?: string;
|
|
22
|
+
/** Accessible name of the product button: name and prices. */
|
|
23
|
+
label: string;
|
|
24
|
+
/**
|
|
25
|
+
* The product's details are being fetched: placeholders show in their
|
|
26
|
+
* place (for now, the price's).
|
|
27
|
+
*/
|
|
28
|
+
isLoading?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Set when the fetched product can't be bought: add to cart becomes a
|
|
31
|
+
* disabled button, and without a price this text ("Esgotado") shows in its
|
|
32
|
+
* place.
|
|
33
|
+
*/
|
|
34
|
+
soldOut?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The Story's product as fetched: `"loading"` while the request runs, its
|
|
39
|
+
* details once found, or undefined without them (no request, not found,
|
|
40
|
+
* failed). Without a fetched price, the ad server's shows.
|
|
41
|
+
*/
|
|
42
|
+
export type FetchedProduct = StoryProductDetails | "loading" | undefined;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The card's view of a Story's product, or undefined when the Story has none
|
|
46
|
+
* (its destination is a link) or the product has no name.
|
|
47
|
+
*
|
|
48
|
+
* The price is the fetched one when there is one; while the product loads,
|
|
49
|
+
* none; and otherwise the ad server's, from `product_metadata`. A fetched
|
|
50
|
+
* product that can't be bought still shows its price, or `labels.soldOut`
|
|
51
|
+
* when it has none. Its price of 0 is no price: Intelligent Search gives one
|
|
52
|
+
* to a SKU out of stock.
|
|
53
|
+
*/
|
|
54
|
+
export function toCardProduct(
|
|
55
|
+
story: Pick<StoryAd, "product" | "destination_url">,
|
|
56
|
+
format: (amount: number) => string,
|
|
57
|
+
labels: StoryLabels,
|
|
58
|
+
fetched?: FetchedProduct,
|
|
59
|
+
): CardProduct | undefined {
|
|
60
|
+
const product = story.product;
|
|
61
|
+
const name = product?.product_name?.trim();
|
|
62
|
+
if (!product || !name) return undefined;
|
|
63
|
+
|
|
64
|
+
const base = {
|
|
65
|
+
name,
|
|
66
|
+
imageUrl: httpUrl(product.image_url) ?? undefined,
|
|
67
|
+
url: destinationUrl(story.destination_url) ?? undefined,
|
|
68
|
+
sku: product.product_sku?.trim() || undefined,
|
|
69
|
+
seller: product.seller_id?.trim() || undefined,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (fetched === "loading") {
|
|
73
|
+
return { ...base, label: labels.product(name), isLoading: true };
|
|
74
|
+
}
|
|
75
|
+
const soldOut = fetched?.available === false ? labels.soldOut : undefined;
|
|
76
|
+
const shown = (amounts: ProductPrice | undefined) =>
|
|
77
|
+
soldOut && amounts?.price === 0 ? undefined : amounts;
|
|
78
|
+
const amounts =
|
|
79
|
+
shown(fetched?.price) ?? shown(readProductPrice(product.product_metadata));
|
|
80
|
+
const price = amounts && format(amounts.price);
|
|
81
|
+
const listPrice =
|
|
82
|
+
amounts?.listPrice === undefined ? undefined : format(amounts.listPrice);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...base,
|
|
86
|
+
price,
|
|
87
|
+
listPrice,
|
|
88
|
+
soldOut,
|
|
89
|
+
label: labels.product(name, price, listPrice, soldOut),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const priceSkeleton = html`
|
|
94
|
+
<span
|
|
95
|
+
class="product-price product-loading product-price-loading"
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
></span>
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// The add to cart button's place, while the product loads. Hidden from
|
|
101
|
+
// assistive technology, as the price's.
|
|
102
|
+
const addToCartSkeleton = html`
|
|
103
|
+
<span
|
|
104
|
+
class="product-loading product-add-to-cart-loading"
|
|
105
|
+
aria-hidden="true"
|
|
106
|
+
></span>
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
// The price and, on sale, the "from" price struck through beside it. While
|
|
110
|
+
// the product loads, its placeholder; sold out without a price, the sold out
|
|
111
|
+
// text; otherwise without a price, nothing.
|
|
112
|
+
function renderPrice({ isLoading, soldOut, price, listPrice }: CardProduct) {
|
|
113
|
+
if (isLoading) return priceSkeleton;
|
|
114
|
+
if (!price) {
|
|
115
|
+
return soldOut
|
|
116
|
+
? html`<span class="product-price product-sold-out">${soldOut}</span>`
|
|
117
|
+
: nothing;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return html`
|
|
121
|
+
<span class="product-price">
|
|
122
|
+
<span>${price}</span>
|
|
123
|
+
${listPrice
|
|
124
|
+
? html`<s class="product-list-price">${listPrice}</s>`
|
|
125
|
+
: nothing}
|
|
126
|
+
</span>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Image, name and prices: what the pill shows.
|
|
131
|
+
function renderSummary(product: CardProduct) {
|
|
132
|
+
return html`
|
|
133
|
+
${product.imageUrl
|
|
134
|
+
? html`<img class="product-image" alt="" src=${product.imageUrl} />`
|
|
135
|
+
: nothing}
|
|
136
|
+
<span class="product-info">
|
|
137
|
+
<span class="product-name">${product.name}</span>
|
|
138
|
+
${renderPrice(product)}
|
|
139
|
+
</span>
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The product pill on the carousel card: image, name (up to two lines),
|
|
145
|
+
* price and, on sale, the "from" price struck through. Without a price, only
|
|
146
|
+
* the name. A button of its own, beside the card's (a button can't contain
|
|
147
|
+
* another).
|
|
148
|
+
*/
|
|
149
|
+
export function renderProduct(product: CardProduct, onSelect: () => void) {
|
|
150
|
+
return html`
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
class="card-product"
|
|
154
|
+
aria-label=${product.label}
|
|
155
|
+
@click=${onSelect}
|
|
156
|
+
>
|
|
157
|
+
${renderSummary(product)}
|
|
158
|
+
</button>
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** What the panel does with the cart. Without `onAddToCart`, no add to cart. */
|
|
163
|
+
export interface ProductCartActions {
|
|
164
|
+
/**
|
|
165
|
+
* How many of the product were added from the element. Above 0, a stepper
|
|
166
|
+
* shows in place of add to cart.
|
|
167
|
+
*/
|
|
168
|
+
cartQuantity?: number;
|
|
169
|
+
/** Called by add to cart and the stepper's plus. */
|
|
170
|
+
onAddToCart?: () => void;
|
|
171
|
+
/** Called by the stepper's minus, a trash with one left. */
|
|
172
|
+
onRemoveFromCart?: () => void;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface ExpandableProductOptions extends ProductCartActions {
|
|
176
|
+
/** Whether the panel with the actions shows. */
|
|
177
|
+
open: boolean;
|
|
178
|
+
/** Called by the pill's button, to open or close the panel. */
|
|
179
|
+
onToggle: () => void;
|
|
180
|
+
/** Id of the panel, for the button's aria-controls. */
|
|
181
|
+
panelId: string;
|
|
182
|
+
/** The texts: add to cart, its disabled "unavailable" and view product. */
|
|
183
|
+
labels: StoryLabels;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const STEPPER_ADD_CLASS = "product-stepper-add";
|
|
187
|
+
const ADD_TO_CART_CLASS = "product-add-to-cart";
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Moves the focus to the control that takes the place of the one clicked
|
|
191
|
+
* when add to cart and the stepper swap: the stepper's plus (`"stepper"`) or
|
|
192
|
+
* add to cart (`"add"`). Does nothing if the panel isn't in `root`.
|
|
193
|
+
*/
|
|
194
|
+
export function focusCartAction(root: ParentNode, action: "add" | "stepper") {
|
|
195
|
+
const className =
|
|
196
|
+
action === "stepper" ? STEPPER_ADD_CLASS : ADD_TO_CART_CLASS;
|
|
197
|
+
root.querySelector<HTMLElement>(`.${className}`)?.focus();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// In the cart: minus (a trash with one left), the quantity and plus, in the
|
|
201
|
+
// add to cart button's place.
|
|
202
|
+
function renderStepper(
|
|
203
|
+
quantity: number,
|
|
204
|
+
{
|
|
205
|
+
labels,
|
|
206
|
+
onAddToCart,
|
|
207
|
+
onRemoveFromCart,
|
|
208
|
+
}: Pick<
|
|
209
|
+
ExpandableProductOptions,
|
|
210
|
+
"labels" | "onAddToCart" | "onRemoveFromCart"
|
|
211
|
+
>,
|
|
212
|
+
) {
|
|
213
|
+
const last = quantity === 1;
|
|
214
|
+
|
|
215
|
+
return html`
|
|
216
|
+
<div
|
|
217
|
+
class="product-action product-stepper"
|
|
218
|
+
role="group"
|
|
219
|
+
aria-label=${labels.cartQuantity}
|
|
220
|
+
>
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
class="product-stepper-button product-stepper-remove"
|
|
224
|
+
aria-label=${last ? labels.removeFromCart : labels.decreaseQuantity}
|
|
225
|
+
@click=${onRemoveFromCart}
|
|
226
|
+
>
|
|
227
|
+
${icon(last ? "trash" : "minus")}
|
|
228
|
+
</button>
|
|
229
|
+
<span class="product-quantity">${quantity}</span>
|
|
230
|
+
<button
|
|
231
|
+
type="button"
|
|
232
|
+
class="product-stepper-button ${STEPPER_ADD_CLASS}"
|
|
233
|
+
aria-label=${labels.increaseQuantity}
|
|
234
|
+
@click=${onAddToCart}
|
|
235
|
+
>
|
|
236
|
+
${icon("plus")}
|
|
237
|
+
</button>
|
|
238
|
+
</div>
|
|
239
|
+
`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Add to cart: its placeholder while the product loads, a disabled button
|
|
243
|
+
// when sold out, and the stepper once in the cart. Nothing without a SKU or
|
|
244
|
+
// an `onAddToCart` to call.
|
|
245
|
+
function renderAddToCart(
|
|
246
|
+
{ isLoading, soldOut, sku }: CardProduct,
|
|
247
|
+
options: ExpandableProductOptions,
|
|
248
|
+
) {
|
|
249
|
+
const { labels, onAddToCart, cartQuantity = 0 } = options;
|
|
250
|
+
if (!sku || !onAddToCart) return nothing;
|
|
251
|
+
if (isLoading) return addToCartSkeleton;
|
|
252
|
+
if (soldOut) {
|
|
253
|
+
return html`
|
|
254
|
+
<button type="button" class="product-action product-unavailable" disabled>
|
|
255
|
+
${labels.unavailable}
|
|
256
|
+
</button>
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
if (cartQuantity > 0) return renderStepper(cartQuantity, options);
|
|
260
|
+
return html`
|
|
261
|
+
<button
|
|
262
|
+
type="button"
|
|
263
|
+
class="product-action ${ADD_TO_CART_CLASS}"
|
|
264
|
+
@click=${onAddToCart}
|
|
265
|
+
>
|
|
266
|
+
${labels.addToCart}
|
|
267
|
+
</button>
|
|
268
|
+
`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Announces the quantity in the cart. It stays in the panel while the stepper
|
|
272
|
+
// comes and goes, so the first value is announced too.
|
|
273
|
+
function renderCartStatus(
|
|
274
|
+
{ sku }: CardProduct,
|
|
275
|
+
{ labels, cartQuantity = 0, onAddToCart }: ExpandableProductOptions,
|
|
276
|
+
) {
|
|
277
|
+
if (!sku || !onAddToCart) return nothing;
|
|
278
|
+
|
|
279
|
+
return html`
|
|
280
|
+
<span class="product-cart-status" role="status">
|
|
281
|
+
${cartQuantity > 0 ? `${labels.cartQuantity}: ${cartQuantity}` : ""}
|
|
282
|
+
</span>
|
|
283
|
+
`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The product pill in the player. The pill is a button that opens a panel
|
|
288
|
+
* below it, as in the prototype, with "Adicionar ao carrinho" (a placeholder
|
|
289
|
+
* while the product loads, a disabled "Produto indisponível" when sold out)
|
|
290
|
+
* and "Ver produto" (the product page, in a new tab; only with a URL). Open,
|
|
291
|
+
* the pill turns white.
|
|
292
|
+
*
|
|
293
|
+
* Add to cart calls `onAddToCart` and leaves the panel open. With
|
|
294
|
+
* `cartQuantity` above 0, a stepper takes its place: minus (a trash with one
|
|
295
|
+
* left) calls `onRemoveFromCart`, plus `onAddToCart`.
|
|
296
|
+
*/
|
|
297
|
+
export function renderExpandableProduct(
|
|
298
|
+
product: CardProduct,
|
|
299
|
+
options: ExpandableProductOptions,
|
|
300
|
+
) {
|
|
301
|
+
const { open } = options;
|
|
302
|
+
|
|
303
|
+
return html`
|
|
304
|
+
<div class="card-product product-expandable" ?data-open=${open}>
|
|
305
|
+
<button
|
|
306
|
+
type="button"
|
|
307
|
+
class="product-summary"
|
|
308
|
+
aria-label=${product.label}
|
|
309
|
+
aria-expanded=${open ? "true" : "false"}
|
|
310
|
+
aria-controls=${options.panelId}
|
|
311
|
+
@click=${options.onToggle}
|
|
312
|
+
>
|
|
313
|
+
${renderSummary(product)}
|
|
314
|
+
<span class="product-toggle">${icon("caretUp")}</span>
|
|
315
|
+
</button>
|
|
316
|
+
<div id=${options.panelId} class="product-panel" ?inert=${!open}>
|
|
317
|
+
<div class="product-actions">
|
|
318
|
+
${renderCartStatus(product, options)}
|
|
319
|
+
${renderAddToCart(product, options)}
|
|
320
|
+
${product.url
|
|
321
|
+
? html`
|
|
322
|
+
<a
|
|
323
|
+
class="product-action product-view"
|
|
324
|
+
href=${product.url}
|
|
325
|
+
target="_blank"
|
|
326
|
+
rel="noopener noreferrer"
|
|
327
|
+
>
|
|
328
|
+
${options.labels.viewProduct}
|
|
329
|
+
</a>
|
|
330
|
+
`
|
|
331
|
+
: nothing}
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
`;
|
|
336
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
VtexAdsStoryCarouselElement,
|
|
3
|
+
defineVtexAdsStoryCarousel,
|
|
4
|
+
TAG_NAME,
|
|
5
|
+
} from "./story";
|
|
6
|
+
export type {
|
|
7
|
+
StoryHydration,
|
|
8
|
+
StoryProductDetails,
|
|
9
|
+
} from "./utils/hydrate-products";
|
|
10
|
+
export {
|
|
11
|
+
ADD_TO_CART_EVENT,
|
|
12
|
+
REMOVE_FROM_CART_EVENT,
|
|
13
|
+
type StoryAddToCartDetail,
|
|
14
|
+
type StoryAddToCartEvent,
|
|
15
|
+
type StoryRemoveFromCartDetail,
|
|
16
|
+
type StoryRemoveFromCartEvent,
|
|
17
|
+
} from "./commerce-events";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StoryLabels } from "./types";
|
|
2
|
+
|
|
3
|
+
/** The texts in English. */
|
|
4
|
+
export const en: StoryLabels = {
|
|
5
|
+
watch: "Watch video",
|
|
6
|
+
show: "Show video",
|
|
7
|
+
carousel: "Videos",
|
|
8
|
+
carouselRole: "carousel",
|
|
9
|
+
previous: "Previous video",
|
|
10
|
+
next: "Next video",
|
|
11
|
+
player: "Video",
|
|
12
|
+
expand: "Expand video",
|
|
13
|
+
collapse: "Collapse video",
|
|
14
|
+
close: "Close video",
|
|
15
|
+
play: "Play video",
|
|
16
|
+
pause: "Pause video",
|
|
17
|
+
soundOn: "Turn sound on",
|
|
18
|
+
soundOff: "Turn sound off",
|
|
19
|
+
addToCart: "Add to cart",
|
|
20
|
+
cartQuantity: "Quantity in cart",
|
|
21
|
+
decreaseQuantity: "Decrease quantity",
|
|
22
|
+
removeFromCart: "Remove from cart",
|
|
23
|
+
increaseQuantity: "Increase quantity",
|
|
24
|
+
unavailable: "Product unavailable",
|
|
25
|
+
soldOut: "Sold out",
|
|
26
|
+
viewProduct: "View product",
|
|
27
|
+
videoUnavailable: "Video unavailable",
|
|
28
|
+
videoFailed: "Couldn't load the video",
|
|
29
|
+
retry: "Try again",
|
|
30
|
+
videoLoading: "Loading video",
|
|
31
|
+
product: (name, price, listPrice, soldOut) => {
|
|
32
|
+
let text = name;
|
|
33
|
+
if (price && listPrice) text = `${name}, was ${listPrice}, now ${price}`;
|
|
34
|
+
else if (price) text = `${name}, ${price}`;
|
|
35
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
36
|
+
},
|
|
37
|
+
position: (label, index, count) =>
|
|
38
|
+
count > 1 ? `${label} ${index + 1} of ${count}` : label,
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { StoryLabels } from "./types";
|
|
2
|
+
|
|
3
|
+
/** The texts in Spanish. */
|
|
4
|
+
export const es: StoryLabels = {
|
|
5
|
+
watch: "Ver video",
|
|
6
|
+
show: "Mostrar video",
|
|
7
|
+
carousel: "Videos",
|
|
8
|
+
carouselRole: "carrusel",
|
|
9
|
+
previous: "Video anterior",
|
|
10
|
+
next: "Video siguiente",
|
|
11
|
+
player: "Video",
|
|
12
|
+
expand: "Ampliar video",
|
|
13
|
+
collapse: "Reducir video",
|
|
14
|
+
close: "Cerrar video",
|
|
15
|
+
play: "Reproducir video",
|
|
16
|
+
pause: "Pausar video",
|
|
17
|
+
soundOn: "Activar sonido",
|
|
18
|
+
soundOff: "Desactivar sonido",
|
|
19
|
+
addToCart: "Agregar al carrito",
|
|
20
|
+
cartQuantity: "Cantidad en el carrito",
|
|
21
|
+
decreaseQuantity: "Disminuir cantidad",
|
|
22
|
+
removeFromCart: "Quitar del carrito",
|
|
23
|
+
increaseQuantity: "Aumentar cantidad",
|
|
24
|
+
unavailable: "Producto no disponible",
|
|
25
|
+
soldOut: "Agotado",
|
|
26
|
+
viewProduct: "Ver producto",
|
|
27
|
+
videoUnavailable: "Video no disponible",
|
|
28
|
+
videoFailed: "No se pudo cargar el video",
|
|
29
|
+
retry: "Intentar de nuevo",
|
|
30
|
+
videoLoading: "Cargando video",
|
|
31
|
+
product: (name, price, listPrice, soldOut) => {
|
|
32
|
+
let text = name;
|
|
33
|
+
if (price && listPrice)
|
|
34
|
+
text = `${name}, antes ${listPrice}, ahora ${price}`;
|
|
35
|
+
else if (price) text = `${name}, ${price}`;
|
|
36
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
37
|
+
},
|
|
38
|
+
position: (label, index, count) =>
|
|
39
|
+
count > 1 ? `${label} ${index + 1} de ${count}` : label,
|
|
40
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { en } from "./en";
|
|
2
|
+
import { es } from "./es";
|
|
3
|
+
import { pt } from "./pt";
|
|
4
|
+
import type { StoryLabels } from "./types";
|
|
5
|
+
|
|
6
|
+
export type { StoryLabels } from "./types";
|
|
7
|
+
export { en } from "./en";
|
|
8
|
+
export { es } from "./es";
|
|
9
|
+
export { pt } from "./pt";
|
|
10
|
+
|
|
11
|
+
export interface StoryLabelOverrides {
|
|
12
|
+
addToCart?: string;
|
|
13
|
+
viewProduct?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const BY_LANGUAGE = new Map<string, StoryLabels>([
|
|
17
|
+
["pt", pt],
|
|
18
|
+
["es", es],
|
|
19
|
+
["en", en],
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export function labelsFor(
|
|
23
|
+
locale: string,
|
|
24
|
+
overrides: StoryLabelOverrides = {},
|
|
25
|
+
): StoryLabels {
|
|
26
|
+
const language = locale.split("-")[0].toLowerCase();
|
|
27
|
+
const labels = BY_LANGUAGE.get(language) ?? pt;
|
|
28
|
+
const addToCart = overrides.addToCart?.trim();
|
|
29
|
+
const viewProduct = overrides.viewProduct?.trim();
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...labels,
|
|
33
|
+
...(addToCart && { addToCart }),
|
|
34
|
+
...(viewProduct && { viewProduct }),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StoryLabels } from "./types";
|
|
2
|
+
|
|
3
|
+
/** The texts in Portuguese, the default. */
|
|
4
|
+
export const pt: StoryLabels = {
|
|
5
|
+
watch: "Assistir vídeo",
|
|
6
|
+
show: "Mostrar vídeo",
|
|
7
|
+
carousel: "Vídeos",
|
|
8
|
+
carouselRole: "carrossel",
|
|
9
|
+
previous: "Vídeo anterior",
|
|
10
|
+
next: "Próximo vídeo",
|
|
11
|
+
player: "Vídeo",
|
|
12
|
+
expand: "Expandir vídeo",
|
|
13
|
+
collapse: "Reduzir vídeo",
|
|
14
|
+
close: "Fechar vídeo",
|
|
15
|
+
play: "Reproduzir vídeo",
|
|
16
|
+
pause: "Pausar vídeo",
|
|
17
|
+
soundOn: "Ativar som",
|
|
18
|
+
soundOff: "Desativar som",
|
|
19
|
+
addToCart: "Adicionar ao carrinho",
|
|
20
|
+
cartQuantity: "Quantidade no carrinho",
|
|
21
|
+
decreaseQuantity: "Diminuir quantidade",
|
|
22
|
+
removeFromCart: "Remover do carrinho",
|
|
23
|
+
increaseQuantity: "Aumentar quantidade",
|
|
24
|
+
unavailable: "Produto indisponível",
|
|
25
|
+
soldOut: "Esgotado",
|
|
26
|
+
viewProduct: "Ver produto",
|
|
27
|
+
videoUnavailable: "Vídeo indisponível",
|
|
28
|
+
videoFailed: "Não foi possível carregar o vídeo",
|
|
29
|
+
retry: "Tentar de novo",
|
|
30
|
+
videoLoading: "Carregando vídeo",
|
|
31
|
+
product: (name, price, listPrice, soldOut) => {
|
|
32
|
+
let text = name;
|
|
33
|
+
if (price && listPrice) text = `${name}, de ${listPrice} por ${price}`;
|
|
34
|
+
else if (price) text = `${name}, ${price}`;
|
|
35
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
36
|
+
},
|
|
37
|
+
position: (label, index, count) =>
|
|
38
|
+
count > 1 ? `${label} ${index + 1} de ${count}` : label,
|
|
39
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface StoryLabels {
|
|
2
|
+
watch: string;
|
|
3
|
+
show: string;
|
|
4
|
+
carousel: string;
|
|
5
|
+
carouselRole: string;
|
|
6
|
+
previous: string;
|
|
7
|
+
next: string;
|
|
8
|
+
player: string;
|
|
9
|
+
expand: string;
|
|
10
|
+
collapse: string;
|
|
11
|
+
close: string;
|
|
12
|
+
play: string;
|
|
13
|
+
pause: string;
|
|
14
|
+
soundOn: string;
|
|
15
|
+
soundOff: string;
|
|
16
|
+
addToCart: string;
|
|
17
|
+
cartQuantity: string;
|
|
18
|
+
decreaseQuantity: string;
|
|
19
|
+
removeFromCart: string;
|
|
20
|
+
increaseQuantity: string;
|
|
21
|
+
unavailable: string;
|
|
22
|
+
soldOut: string;
|
|
23
|
+
viewProduct: string;
|
|
24
|
+
/** Over the card's cover when its video can't load. */
|
|
25
|
+
videoUnavailable: string;
|
|
26
|
+
/** Over the player's cover when its video can't load. */
|
|
27
|
+
videoFailed: string;
|
|
28
|
+
/** While the player loads the video. */
|
|
29
|
+
videoLoading: string;
|
|
30
|
+
/** The player's button to load the video again. */
|
|
31
|
+
retry: string;
|
|
32
|
+
/**
|
|
33
|
+
* The product button: "Tênis, de R$ 159,90 por R$ 129,90", followed by
|
|
34
|
+
* `soldOut` when the product can't be bought.
|
|
35
|
+
*/
|
|
36
|
+
product: (
|
|
37
|
+
name: string,
|
|
38
|
+
price?: string,
|
|
39
|
+
listPrice?: string,
|
|
40
|
+
soldOut?: string,
|
|
41
|
+
) => string;
|
|
42
|
+
/** Tells the cards apart: "Mostrar vídeo 2 de 4". */
|
|
43
|
+
position: (label: string, index: number, count: number) => string;
|
|
44
|
+
}
|
package/src/react.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React JSX types for <vtex-ads-story>. Types only: the JS output
|
|
2
|
+
* React JSX types for <vtex-ads-story-carousel>. Types only: the JS output
|
|
3
|
+
* is empty.
|
|
3
4
|
*
|
|
4
5
|
* Opt in once per project, so non-React projects never need @types/react:
|
|
5
6
|
*
|
|
@@ -8,18 +9,65 @@
|
|
|
8
9
|
* or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
|
|
9
10
|
*/
|
|
10
11
|
import type { DetailedHTMLProps, HTMLAttributes } from "react";
|
|
11
|
-
import type {
|
|
12
|
+
import type { Channel } from "@vtex/ads-core";
|
|
13
|
+
import type { TAG_NAME, VtexAdsStoryCarouselElement } from "./story";
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The element's own attributes. The required ones match the README: without
|
|
17
|
+
* them, the element requests nothing and renders nothing.
|
|
18
|
+
*/
|
|
19
|
+
export interface VtexAdsStoryCarouselAttributes {
|
|
20
|
+
/** The publisher the ads are requested for. */
|
|
21
|
+
"publisher-id": string;
|
|
22
|
+
/** The store's session, also used to deduplicate events. */
|
|
23
|
+
"session-id": string;
|
|
24
|
+
/** The Story placement configured for the publisher. */
|
|
25
|
+
placement: string;
|
|
26
|
+
"user-id"?: string;
|
|
27
|
+
"account-name"?: string;
|
|
28
|
+
/** `site` or `app`. */
|
|
29
|
+
channel?: Channel;
|
|
30
|
+
/** Time limit for the ad request, in milliseconds (default 2000). */
|
|
31
|
+
timeout?: number;
|
|
32
|
+
/** How many Stories to ask for: the carousel positions (default 8). */
|
|
33
|
+
quantity?: number;
|
|
34
|
+
/** Currency of the prices, ISO 4217 ("BRL"). Default BRL. */
|
|
35
|
+
currency?: string;
|
|
36
|
+
/** The add to cart button's text. Default in the element's language. */
|
|
37
|
+
"label-add-to-cart"?: string;
|
|
38
|
+
/** The view product button's text. Default in the element's language. */
|
|
39
|
+
"label-view-product"?: string;
|
|
40
|
+
/**
|
|
41
|
+
* "none": no product request. To set a strategy, assign the element's
|
|
42
|
+
* `hydration` property. Missing: Intelligent Search with `account-name`.
|
|
43
|
+
*/
|
|
44
|
+
hydration?: "none";
|
|
45
|
+
/** Time limit for the product request, in milliseconds (default 5000). */
|
|
46
|
+
"hydration-timeout"?: number;
|
|
47
|
+
/**
|
|
48
|
+
* With more than one Story, the cards without the highlight also play
|
|
49
|
+
* their video, muted. Off by default.
|
|
50
|
+
*/
|
|
51
|
+
"inactive-autoplay"?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* With more than one Story, how long each one stays highlighted, in
|
|
54
|
+
* milliseconds (default 5000). 0: no automatic advance. Never advances on
|
|
55
|
+
* its own for people who prefer reduced motion.
|
|
56
|
+
*/
|
|
57
|
+
"slide-duration"?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type VtexAdsStoryCarouselProps = DetailedHTMLProps<
|
|
61
|
+
HTMLAttributes<VtexAdsStoryCarouselElement>,
|
|
62
|
+
VtexAdsStoryCarouselElement
|
|
63
|
+
> &
|
|
64
|
+
VtexAdsStoryCarouselAttributes;
|
|
17
65
|
|
|
18
66
|
declare module "react" {
|
|
19
67
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
20
68
|
namespace JSX {
|
|
21
69
|
interface IntrinsicElements {
|
|
22
|
-
|
|
70
|
+
[TAG_NAME]: VtexAdsStoryCarouselProps;
|
|
23
71
|
}
|
|
24
72
|
}
|
|
25
73
|
}
|
package/src/story/index.ts
CHANGED