@vtex/ads-stories 0.5.0 → 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 +27 -0
- package/README.md +29 -297
- package/dist/cdn/vtex-ads-stories.js +438 -113
- package/dist/cdn/vtex-ads-stories.js.map +1 -1
- package/dist/cjs/index.cjs +909 -186
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +42 -196
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/cjs/react.d.cts +7 -1
- package/dist/cjs/story-DAiAN9v-.d.cts +260 -0
- package/dist/esm/index.d.ts +42 -196
- package/dist/esm/index.js +933 -209
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react.d.ts +7 -1
- package/dist/esm/story-DAiAN9v-.d.ts +260 -0
- package/package.json +1 -1
- package/src/commerce-events.ts +93 -0
- package/src/components/card/card.ts +16 -3
- package/src/components/carousel/carousel-skeleton.ts +113 -0
- package/src/components/carousel/carousel.ts +53 -8
- package/src/components/carousel/index.ts +7 -0
- package/src/components/events/events-controller.ts +23 -13
- 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 +8 -0
- package/src/components/media/index.ts +7 -1
- package/src/components/media/media.styles.ts +113 -0
- package/src/components/media/media.ts +108 -11
- package/src/components/media/video-controller.ts +80 -6
- package/src/components/player/player.ts +42 -17
- package/src/components/product/cta.ts +3 -3
- package/src/components/product/index.ts +2 -0
- package/src/components/product/product.styles.ts +63 -6
- package/src/components/product/product.ts +130 -29
- package/src/index.ts +8 -0
- package/src/locales/en.ts +13 -3
- package/src/locales/es.ts +13 -3
- package/src/locales/pt.ts +13 -3
- package/src/locales/types.ts +22 -2
- package/src/react.ts +6 -0
- package/src/story/story.ts +188 -16
- package/src/utils/hydrate-products.ts +30 -6
- package/src/utils/media-ready.ts +58 -0
- package/src/utils/safe-url.ts +36 -0
- package/src/utils/send-event.ts +1 -1
- package/src/utils/http-url.ts +0 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { html } from "lit";
|
|
2
2
|
import { icon } from "../icons";
|
|
3
|
-
import {
|
|
3
|
+
import { destinationUrl } from "../../utils/safe-url";
|
|
4
4
|
import type { StoryAd } from "../../types";
|
|
5
5
|
|
|
6
6
|
/** The call to action of a Story whose destination is a link. */
|
|
@@ -14,7 +14,7 @@ export interface CardCta {
|
|
|
14
14
|
/**
|
|
15
15
|
* The call to action of a Story without a product (its destination is a
|
|
16
16
|
* link), with the text set in the campaign. Undefined when the Story has a
|
|
17
|
-
* product, no text or no http(s) destination.
|
|
17
|
+
* product, no text or no http(s) or same-store path destination.
|
|
18
18
|
*/
|
|
19
19
|
export function toCardCta(
|
|
20
20
|
story: Pick<StoryAd, "product" | "destination_url" | "call_to_action">,
|
|
@@ -22,7 +22,7 @@ export function toCardCta(
|
|
|
22
22
|
if (story.product) return undefined;
|
|
23
23
|
|
|
24
24
|
const label = story.call_to_action?.trim();
|
|
25
|
-
const url =
|
|
25
|
+
const url = destinationUrl(story.destination_url);
|
|
26
26
|
|
|
27
27
|
return label && url ? { label, url } : undefined;
|
|
28
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export {
|
|
2
|
+
focusCartAction,
|
|
2
3
|
renderExpandableProduct,
|
|
3
4
|
renderProduct,
|
|
4
5
|
toCardProduct,
|
|
@@ -10,6 +11,7 @@ export type {
|
|
|
10
11
|
CardProduct,
|
|
11
12
|
ExpandableProductOptions,
|
|
12
13
|
FetchedProduct,
|
|
14
|
+
ProductCartActions,
|
|
13
15
|
} from "./product";
|
|
14
16
|
export {
|
|
15
17
|
DEFAULT_CURRENCY,
|
|
@@ -14,9 +14,9 @@ export const productStyles = css`
|
|
|
14
14
|
gap: 8px;
|
|
15
15
|
align-items: center;
|
|
16
16
|
box-sizing: border-box;
|
|
17
|
-
padding:
|
|
17
|
+
padding: var(--_pill-inset);
|
|
18
18
|
border: 0;
|
|
19
|
-
border-radius:
|
|
19
|
+
border-radius: var(--_pill-radius);
|
|
20
20
|
background: rgba(255, 255, 255, 0.15);
|
|
21
21
|
backdrop-filter: blur(5px);
|
|
22
22
|
color: #fff;
|
|
@@ -111,7 +111,7 @@ export const productStyles = css`
|
|
|
111
111
|
align-items: center;
|
|
112
112
|
box-sizing: border-box;
|
|
113
113
|
width: 100%;
|
|
114
|
-
padding:
|
|
114
|
+
padding: var(--_pill-inset);
|
|
115
115
|
border: 0;
|
|
116
116
|
border-radius: inherit;
|
|
117
117
|
background: transparent;
|
|
@@ -174,7 +174,7 @@ export const productStyles = css`
|
|
|
174
174
|
height: 48px;
|
|
175
175
|
padding: 0 16px;
|
|
176
176
|
border: 1px solid var(--vtex-ads-story-color-accent, #1b75a8);
|
|
177
|
-
border-radius:
|
|
177
|
+
border-radius: var(--_button-radius);
|
|
178
178
|
font: inherit;
|
|
179
179
|
font-size: 14px;
|
|
180
180
|
font-weight: 700;
|
|
@@ -201,6 +201,62 @@ export const productStyles = css`
|
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
/* In the cart: the add to cart button's pill, with minus and plus at its
|
|
205
|
+
ends and the quantity between them. */
|
|
206
|
+
.product-stepper {
|
|
207
|
+
justify-content: space-between;
|
|
208
|
+
padding: 0;
|
|
209
|
+
background: var(--vtex-ads-story-color-accent, #1b75a8);
|
|
210
|
+
color: var(--vtex-ads-story-color-accent-contrast, #fff);
|
|
211
|
+
cursor: auto;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.product-stepper-button {
|
|
215
|
+
display: grid;
|
|
216
|
+
flex: none;
|
|
217
|
+
place-items: center;
|
|
218
|
+
width: 46px;
|
|
219
|
+
height: 46px;
|
|
220
|
+
padding: 0;
|
|
221
|
+
border: 0;
|
|
222
|
+
border-radius: var(--_button-radius);
|
|
223
|
+
background: transparent;
|
|
224
|
+
color: inherit;
|
|
225
|
+
cursor: pointer;
|
|
226
|
+
transition: background-color 0.2s ease;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.product-stepper-button .icon {
|
|
230
|
+
width: 18px;
|
|
231
|
+
height: 18px;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.product-stepper-button:hover {
|
|
235
|
+
background: rgba(0, 0, 0, 0.15);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.product-stepper-button:focus-visible {
|
|
239
|
+
outline: 2px solid var(--vtex-ads-story-color-accent-contrast, #fff);
|
|
240
|
+
outline-offset: -4px;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.product-quantity {
|
|
244
|
+
flex: 1;
|
|
245
|
+
min-width: 0;
|
|
246
|
+
font-size: 16px;
|
|
247
|
+
text-align: center;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.product-cart-status {
|
|
251
|
+
position: absolute;
|
|
252
|
+
width: 1px;
|
|
253
|
+
height: 1px;
|
|
254
|
+
margin: -1px;
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
clip-path: inset(50%);
|
|
257
|
+
white-space: nowrap;
|
|
258
|
+
}
|
|
259
|
+
|
|
204
260
|
/* Sold out: add to cart, disabled and grayed. */
|
|
205
261
|
.product-unavailable {
|
|
206
262
|
border-color: transparent;
|
|
@@ -290,11 +346,12 @@ export const productStyles = css`
|
|
|
290
346
|
}
|
|
291
347
|
}
|
|
292
348
|
|
|
349
|
+
/* Its corners follow the pill's, one inset in from them: 8px by default. */
|
|
293
350
|
.product-image {
|
|
294
351
|
flex: none;
|
|
295
352
|
width: 60px;
|
|
296
353
|
height: 60px;
|
|
297
|
-
border-radius:
|
|
354
|
+
border-radius: max(0px, var(--_pill-radius) - var(--_pill-inset));
|
|
298
355
|
background: #fff;
|
|
299
356
|
object-fit: contain;
|
|
300
357
|
}
|
|
@@ -358,7 +415,7 @@ export const productStyles = css`
|
|
|
358
415
|
.product-add-to-cart-loading {
|
|
359
416
|
display: block;
|
|
360
417
|
height: 48px;
|
|
361
|
-
border-radius:
|
|
418
|
+
border-radius: var(--_button-radius);
|
|
362
419
|
}
|
|
363
420
|
|
|
364
421
|
@media (prefers-reduced-motion: reduce) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { html, nothing } from "lit";
|
|
2
2
|
import type { StoryLabels } from "../../locales";
|
|
3
3
|
import { icon } from "../icons";
|
|
4
|
-
import { httpUrl } from "../../utils/
|
|
4
|
+
import { destinationUrl, httpUrl } from "../../utils/safe-url";
|
|
5
5
|
import type { StoryAd } from "../../types";
|
|
6
6
|
import type { StoryProductDetails } from "../../utils/hydrate-products";
|
|
7
|
-
import { readProductPrice } from "./price";
|
|
7
|
+
import { readProductPrice, type ProductPrice } from "./price";
|
|
8
8
|
|
|
9
9
|
/** What the card shows of the Story's product, with the prices formatted. */
|
|
10
10
|
export interface CardProduct {
|
|
@@ -15,6 +15,10 @@ export interface CardProduct {
|
|
|
15
15
|
listPrice?: string;
|
|
16
16
|
/** The product page, opened by view product link button. */
|
|
17
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;
|
|
18
22
|
/** Accessible name of the product button: name and prices. */
|
|
19
23
|
label: string;
|
|
20
24
|
/**
|
|
@@ -23,8 +27,9 @@ export interface CardProduct {
|
|
|
23
27
|
*/
|
|
24
28
|
isLoading?: boolean;
|
|
25
29
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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.
|
|
28
33
|
*/
|
|
29
34
|
soldOut?: string;
|
|
30
35
|
}
|
|
@@ -42,7 +47,9 @@ export type FetchedProduct = StoryProductDetails | "loading" | undefined;
|
|
|
42
47
|
*
|
|
43
48
|
* The price is the fetched one when there is one; while the product loads,
|
|
44
49
|
* none; and otherwise the ad server's, from `product_metadata`. A fetched
|
|
45
|
-
* product that can't be bought shows `labels.soldOut`
|
|
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.
|
|
46
53
|
*/
|
|
47
54
|
export function toCardProduct(
|
|
48
55
|
story: Pick<StoryAd, "product" | "destination_url">,
|
|
@@ -57,21 +64,19 @@ export function toCardProduct(
|
|
|
57
64
|
const base = {
|
|
58
65
|
name,
|
|
59
66
|
imageUrl: httpUrl(product.image_url) ?? undefined,
|
|
60
|
-
url:
|
|
67
|
+
url: destinationUrl(story.destination_url) ?? undefined,
|
|
68
|
+
sku: product.product_sku?.trim() || undefined,
|
|
69
|
+
seller: product.seller_id?.trim() || undefined,
|
|
61
70
|
};
|
|
62
71
|
|
|
63
72
|
if (fetched === "loading") {
|
|
64
73
|
return { ...base, label: labels.product(name), isLoading: true };
|
|
65
74
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const amounts = fetched?.price ?? readProductPrice(product.product_metadata);
|
|
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));
|
|
75
80
|
const price = amounts && format(amounts.price);
|
|
76
81
|
const listPrice =
|
|
77
82
|
amounts?.listPrice === undefined ? undefined : format(amounts.listPrice);
|
|
@@ -80,7 +85,8 @@ export function toCardProduct(
|
|
|
80
85
|
...base,
|
|
81
86
|
price,
|
|
82
87
|
listPrice,
|
|
83
|
-
|
|
88
|
+
soldOut,
|
|
89
|
+
label: labels.product(name, price, listPrice, soldOut),
|
|
84
90
|
};
|
|
85
91
|
}
|
|
86
92
|
|
|
@@ -101,14 +107,15 @@ const addToCartSkeleton = html`
|
|
|
101
107
|
`;
|
|
102
108
|
|
|
103
109
|
// The price and, on sale, the "from" price struck through beside it. While
|
|
104
|
-
// the product loads, its placeholder; sold out, the sold out
|
|
105
|
-
// price, nothing.
|
|
110
|
+
// the product loads, its placeholder; sold out without a price, the sold out
|
|
111
|
+
// text; otherwise without a price, nothing.
|
|
106
112
|
function renderPrice({ isLoading, soldOut, price, listPrice }: CardProduct) {
|
|
107
113
|
if (isLoading) return priceSkeleton;
|
|
108
|
-
if (
|
|
109
|
-
return
|
|
114
|
+
if (!price) {
|
|
115
|
+
return soldOut
|
|
116
|
+
? html`<span class="product-price product-sold-out">${soldOut}</span>`
|
|
117
|
+
: nothing;
|
|
110
118
|
}
|
|
111
|
-
if (!price) return nothing;
|
|
112
119
|
|
|
113
120
|
return html`
|
|
114
121
|
<span class="product-price">
|
|
@@ -152,7 +159,20 @@ export function renderProduct(product: CardProduct, onSelect: () => void) {
|
|
|
152
159
|
`;
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
|
|
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 {
|
|
156
176
|
/** Whether the panel with the actions shows. */
|
|
157
177
|
open: boolean;
|
|
158
178
|
/** Called by the pill's button, to open or close the panel. */
|
|
@@ -163,12 +183,71 @@ export interface ExpandableProductOptions {
|
|
|
163
183
|
labels: StoryLabels;
|
|
164
184
|
}
|
|
165
185
|
|
|
166
|
-
|
|
167
|
-
|
|
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.
|
|
168
245
|
function renderAddToCart(
|
|
169
|
-
{ isLoading, soldOut }: CardProduct,
|
|
170
|
-
|
|
246
|
+
{ isLoading, soldOut, sku }: CardProduct,
|
|
247
|
+
options: ExpandableProductOptions,
|
|
171
248
|
) {
|
|
249
|
+
const { labels, onAddToCart, cartQuantity = 0 } = options;
|
|
250
|
+
if (!sku || !onAddToCart) return nothing;
|
|
172
251
|
if (isLoading) return addToCartSkeleton;
|
|
173
252
|
if (soldOut) {
|
|
174
253
|
return html`
|
|
@@ -177,13 +256,33 @@ function renderAddToCart(
|
|
|
177
256
|
</button>
|
|
178
257
|
`;
|
|
179
258
|
}
|
|
259
|
+
if (cartQuantity > 0) return renderStepper(cartQuantity, options);
|
|
180
260
|
return html`
|
|
181
|
-
<button
|
|
261
|
+
<button
|
|
262
|
+
type="button"
|
|
263
|
+
class="product-action ${ADD_TO_CART_CLASS}"
|
|
264
|
+
@click=${onAddToCart}
|
|
265
|
+
>
|
|
182
266
|
${labels.addToCart}
|
|
183
267
|
</button>
|
|
184
268
|
`;
|
|
185
269
|
}
|
|
186
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
|
+
|
|
187
286
|
/**
|
|
188
287
|
* The product pill in the player. The pill is a button that opens a panel
|
|
189
288
|
* below it, as in the prototype, with "Adicionar ao carrinho" (a placeholder
|
|
@@ -191,8 +290,9 @@ function renderAddToCart(
|
|
|
191
290
|
* and "Ver produto" (the product page, in a new tab; only with a URL). Open,
|
|
192
291
|
* the pill turns white.
|
|
193
292
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
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`.
|
|
196
296
|
*/
|
|
197
297
|
export function renderExpandableProduct(
|
|
198
298
|
product: CardProduct,
|
|
@@ -215,6 +315,7 @@ export function renderExpandableProduct(
|
|
|
215
315
|
</button>
|
|
216
316
|
<div id=${options.panelId} class="product-panel" ?inert=${!open}>
|
|
217
317
|
<div class="product-actions">
|
|
318
|
+
${renderCartStatus(product, options)}
|
|
218
319
|
${renderAddToCart(product, options)}
|
|
219
320
|
${product.url
|
|
220
321
|
? html`
|
package/src/index.ts
CHANGED
|
@@ -7,3 +7,11 @@ export type {
|
|
|
7
7
|
StoryHydration,
|
|
8
8
|
StoryProductDetails,
|
|
9
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";
|
package/src/locales/en.ts
CHANGED
|
@@ -17,12 +17,22 @@ export const en: StoryLabels = {
|
|
|
17
17
|
soundOn: "Turn sound on",
|
|
18
18
|
soundOff: "Turn sound off",
|
|
19
19
|
addToCart: "Add to cart",
|
|
20
|
+
cartQuantity: "Quantity in cart",
|
|
21
|
+
decreaseQuantity: "Decrease quantity",
|
|
22
|
+
removeFromCart: "Remove from cart",
|
|
23
|
+
increaseQuantity: "Increase quantity",
|
|
20
24
|
unavailable: "Product unavailable",
|
|
21
25
|
soldOut: "Sold out",
|
|
22
26
|
viewProduct: "View product",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
36
|
},
|
|
27
37
|
position: (label, index, count) =>
|
|
28
38
|
count > 1 ? `${label} ${index + 1} of ${count}` : label,
|
package/src/locales/es.ts
CHANGED
|
@@ -17,13 +17,23 @@ export const es: StoryLabels = {
|
|
|
17
17
|
soundOn: "Activar sonido",
|
|
18
18
|
soundOff: "Desactivar sonido",
|
|
19
19
|
addToCart: "Agregar al carrito",
|
|
20
|
+
cartQuantity: "Cantidad en el carrito",
|
|
21
|
+
decreaseQuantity: "Disminuir cantidad",
|
|
22
|
+
removeFromCart: "Quitar del carrito",
|
|
23
|
+
increaseQuantity: "Aumentar cantidad",
|
|
20
24
|
unavailable: "Producto no disponible",
|
|
21
25
|
soldOut: "Agotado",
|
|
22
26
|
viewProduct: "Ver producto",
|
|
23
|
-
|
|
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;
|
|
24
33
|
if (price && listPrice)
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
text = `${name}, antes ${listPrice}, ahora ${price}`;
|
|
35
|
+
else if (price) text = `${name}, ${price}`;
|
|
36
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
27
37
|
},
|
|
28
38
|
position: (label, index, count) =>
|
|
29
39
|
count > 1 ? `${label} ${index + 1} de ${count}` : label,
|
package/src/locales/pt.ts
CHANGED
|
@@ -17,12 +17,22 @@ export const pt: StoryLabels = {
|
|
|
17
17
|
soundOn: "Ativar som",
|
|
18
18
|
soundOff: "Desativar som",
|
|
19
19
|
addToCart: "Adicionar ao carrinho",
|
|
20
|
+
cartQuantity: "Quantidade no carrinho",
|
|
21
|
+
decreaseQuantity: "Diminuir quantidade",
|
|
22
|
+
removeFromCart: "Remover do carrinho",
|
|
23
|
+
increaseQuantity: "Aumentar quantidade",
|
|
20
24
|
unavailable: "Produto indisponível",
|
|
21
25
|
soldOut: "Esgotado",
|
|
22
26
|
viewProduct: "Ver produto",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
36
|
},
|
|
27
37
|
position: (label, index, count) =>
|
|
28
38
|
count > 1 ? `${label} ${index + 1} de ${count}` : label,
|
package/src/locales/types.ts
CHANGED
|
@@ -14,11 +14,31 @@ export interface StoryLabels {
|
|
|
14
14
|
soundOn: string;
|
|
15
15
|
soundOff: string;
|
|
16
16
|
addToCart: string;
|
|
17
|
+
cartQuantity: string;
|
|
18
|
+
decreaseQuantity: string;
|
|
19
|
+
removeFromCart: string;
|
|
20
|
+
increaseQuantity: string;
|
|
17
21
|
unavailable: string;
|
|
18
22
|
soldOut: string;
|
|
19
23
|
viewProduct: string;
|
|
20
|
-
/**
|
|
21
|
-
|
|
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;
|
|
22
42
|
/** Tells the cards apart: "Mostrar vídeo 2 de 4". */
|
|
23
43
|
position: (label: string, index: number, count: number) => string;
|
|
24
44
|
}
|
package/src/react.ts
CHANGED
|
@@ -49,6 +49,12 @@ export interface VtexAdsStoryCarouselAttributes {
|
|
|
49
49
|
* their video, muted. Off by default.
|
|
50
50
|
*/
|
|
51
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;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
export type VtexAdsStoryCarouselProps = DetailedHTMLProps<
|