@vtex/ads-stories 0.5.0 → 0.8.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 +33 -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 +932 -189
- 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 +13 -3
- package/dist/cjs/story-Ba9J0rbL.d.cts +276 -0
- package/dist/esm/index.d.ts +42 -196
- package/dist/esm/index.js +956 -212
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react.d.ts +13 -3
- package/dist/esm/story-Ba9J0rbL.d.ts +276 -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/index.ts +6 -0
- package/src/locales/pt.ts +13 -3
- package/src/locales/types.ts +22 -2
- package/src/react.ts +12 -2
- package/src/story/story.ts +218 -20
- 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
package/dist/esm/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
2
2
|
import { Channel } from '@vtex/ads-core';
|
|
3
|
-
import { TAG_NAME, VtexAdsStoryCarouselElement } from './
|
|
3
|
+
import { T as TAG_NAME, V as VtexAdsStoryCarouselElement } from './story-Ba9J0rbL.js';
|
|
4
4
|
import 'lit';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -35,10 +35,14 @@ interface VtexAdsStoryCarouselAttributes {
|
|
|
35
35
|
quantity?: number;
|
|
36
36
|
/** Currency of the prices, ISO 4217 ("BRL"). Default BRL. */
|
|
37
37
|
currency?: string;
|
|
38
|
-
/**
|
|
38
|
+
/** Add to cart button's text. Default in the element's language. */
|
|
39
39
|
"label-add-to-cart"?: string;
|
|
40
|
-
/**
|
|
40
|
+
/** View product button's text. Default in the element's language. */
|
|
41
41
|
"label-view-product"?: string;
|
|
42
|
+
/** Unavailable product button's text. Default in the element's language. */
|
|
43
|
+
"label-unavailable"?: string;
|
|
44
|
+
/** Sold out text. Default in the element's language. */
|
|
45
|
+
"label-sold-out"?: string;
|
|
42
46
|
/**
|
|
43
47
|
* "none": no product request. To set a strategy, assign the element's
|
|
44
48
|
* `hydration` property. Missing: Intelligent Search with `account-name`.
|
|
@@ -51,6 +55,12 @@ interface VtexAdsStoryCarouselAttributes {
|
|
|
51
55
|
* their video, muted. Off by default.
|
|
52
56
|
*/
|
|
53
57
|
"inactive-autoplay"?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* With more than one Story, how long each one stays highlighted, in
|
|
60
|
+
* milliseconds (default 5000). 0: no automatic advance. Never advances on
|
|
61
|
+
* its own for people who prefer reduced motion.
|
|
62
|
+
*/
|
|
63
|
+
"slide-duration"?: number;
|
|
54
64
|
}
|
|
55
65
|
type VtexAdsStoryCarouselProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryCarouselElement>, VtexAdsStoryCarouselElement> & VtexAdsStoryCarouselAttributes;
|
|
56
66
|
declare module "react" {
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import * as lit from 'lit';
|
|
2
|
+
import { LitElement, PropertyValues, nothing } from 'lit';
|
|
3
|
+
import { ProductFetcher, Offer, ProductPrice, Channel } from '@vtex/ads-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where the element gets its products' details: a fetcher and a matcher, as
|
|
7
|
+
* in `@vtex/ads-core`, and a reader for the price of a fetched product.
|
|
8
|
+
*/
|
|
9
|
+
interface StoryHydration<TProduct extends object = object> {
|
|
10
|
+
fetcher: ProductFetcher<TProduct>;
|
|
11
|
+
matcher(product: TProduct, offer: Offer): boolean;
|
|
12
|
+
price(product: TProduct, offer: Offer): ProductPrice | undefined;
|
|
13
|
+
/** Whether the product can be bought. Without it, it isn't checked. */
|
|
14
|
+
available?(product: TProduct, offer: Offer): boolean | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface StoryProductDetails {
|
|
17
|
+
price?: ProductPrice;
|
|
18
|
+
/** Missing when the strategy doesn't say. */
|
|
19
|
+
available?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare const TAG_NAME = "vtex-ads-story-carousel";
|
|
23
|
+
|
|
24
|
+
declare class VtexAdsStoryCarouselElement extends LitElement {
|
|
25
|
+
static readonly properties: {
|
|
26
|
+
publisherId: {
|
|
27
|
+
attribute: string;
|
|
28
|
+
};
|
|
29
|
+
sessionId: {
|
|
30
|
+
attribute: string;
|
|
31
|
+
};
|
|
32
|
+
placement: {};
|
|
33
|
+
userId: {
|
|
34
|
+
attribute: string;
|
|
35
|
+
};
|
|
36
|
+
accountName: {
|
|
37
|
+
attribute: string;
|
|
38
|
+
};
|
|
39
|
+
channel: {
|
|
40
|
+
converter: {
|
|
41
|
+
fromAttribute: (value: string | null) => Channel | undefined;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
timeout: {
|
|
45
|
+
type: NumberConstructor;
|
|
46
|
+
};
|
|
47
|
+
quantity: {
|
|
48
|
+
type: NumberConstructor;
|
|
49
|
+
};
|
|
50
|
+
currency: {};
|
|
51
|
+
labelAddToCart: {
|
|
52
|
+
attribute: string;
|
|
53
|
+
};
|
|
54
|
+
labelViewProduct: {
|
|
55
|
+
attribute: string;
|
|
56
|
+
};
|
|
57
|
+
labelUnavailable: {
|
|
58
|
+
attribute: string;
|
|
59
|
+
};
|
|
60
|
+
labelSoldOut: {
|
|
61
|
+
attribute: string;
|
|
62
|
+
};
|
|
63
|
+
hydration: {
|
|
64
|
+
converter: {
|
|
65
|
+
fromAttribute: (value: string | null) => "none" | undefined;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
hydrationTimeout: {
|
|
69
|
+
type: NumberConstructor;
|
|
70
|
+
attribute: string;
|
|
71
|
+
};
|
|
72
|
+
slideDuration: {
|
|
73
|
+
type: NumberConstructor;
|
|
74
|
+
attribute: string;
|
|
75
|
+
};
|
|
76
|
+
inactiveAutoplay: {
|
|
77
|
+
type: BooleanConstructor;
|
|
78
|
+
attribute: string;
|
|
79
|
+
converter: {
|
|
80
|
+
fromAttribute: (value: string | null) => boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
stories: {
|
|
84
|
+
state: boolean;
|
|
85
|
+
};
|
|
86
|
+
products: {
|
|
87
|
+
state: boolean;
|
|
88
|
+
};
|
|
89
|
+
requesting: {
|
|
90
|
+
state: boolean;
|
|
91
|
+
};
|
|
92
|
+
mediaLoading: {
|
|
93
|
+
state: boolean;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/** Required. The publisher the ads are requested for. */
|
|
97
|
+
publisherId?: string;
|
|
98
|
+
/** Required. The store's session, also used to deduplicate events. */
|
|
99
|
+
sessionId?: string;
|
|
100
|
+
/** Required. The Story placement configured for the publisher. */
|
|
101
|
+
placement?: string;
|
|
102
|
+
userId?: string;
|
|
103
|
+
accountName?: string;
|
|
104
|
+
/** `site` or `app`. Any other attribute value is ignored. */
|
|
105
|
+
channel?: Channel;
|
|
106
|
+
/**
|
|
107
|
+
* Time limit for the ad request, in milliseconds (default 2000). Without a
|
|
108
|
+
* Story by then, the element renders nothing. A change applies to the next
|
|
109
|
+
* request; it doesn't request again.
|
|
110
|
+
*/
|
|
111
|
+
timeout?: number;
|
|
112
|
+
/**
|
|
113
|
+
* How many Stories to ask for: the carousel positions (default 8). Missing,
|
|
114
|
+
* below 1 or not a number: the default.
|
|
115
|
+
*/
|
|
116
|
+
quantity?: number;
|
|
117
|
+
/**
|
|
118
|
+
* Currency of the prices, as an ISO 4217 code ("BRL", "ARS"). Missing or
|
|
119
|
+
* invalid: BRL.
|
|
120
|
+
*/
|
|
121
|
+
currency?: string;
|
|
122
|
+
/**
|
|
123
|
+
* The add to cart button's text. Missing or blank: the default in the
|
|
124
|
+
* element's language.
|
|
125
|
+
*/
|
|
126
|
+
labelAddToCart?: string;
|
|
127
|
+
/**
|
|
128
|
+
* The view product button's text. Missing or blank: the default in the
|
|
129
|
+
* element's language.
|
|
130
|
+
*/
|
|
131
|
+
labelViewProduct?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The text of the disabled button for a product that can't be bought.
|
|
134
|
+
* Missing or blank: the default in the element's language.
|
|
135
|
+
*/
|
|
136
|
+
labelUnavailable?: string;
|
|
137
|
+
/**
|
|
138
|
+
* The sold out text, shown with the price and read by screen readers.
|
|
139
|
+
* Missing or blank: the default in the element's language.
|
|
140
|
+
*/
|
|
141
|
+
labelSoldOut?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Where the products' details (for now, their prices) come from. A
|
|
144
|
+
* strategy (fetcher, matcher and price reader) is set as a property; the
|
|
145
|
+
* attribute takes only "none", for no product request. Missing:
|
|
146
|
+
* Intelligent Search when `account-name` is set, no product request
|
|
147
|
+
* otherwise.
|
|
148
|
+
*/
|
|
149
|
+
hydration?: StoryHydration | "none";
|
|
150
|
+
/**
|
|
151
|
+
* Time limit for the product request, in milliseconds (default 5000).
|
|
152
|
+
* Without the prices by then, the cards show the ad server's.
|
|
153
|
+
*/
|
|
154
|
+
hydrationTimeout?: number;
|
|
155
|
+
/**
|
|
156
|
+
* With more than one Story, whether the cards without the highlight also
|
|
157
|
+
* play their video, muted. Off by default: they show only their cover, and
|
|
158
|
+
* only the highlighted card plays.
|
|
159
|
+
*/
|
|
160
|
+
inactiveAutoplay: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* With more than one Story, how long each one stays highlighted before the
|
|
163
|
+
* next, in milliseconds (default 5000). Zero: the highlight moves only by
|
|
164
|
+
* hand. A change starts the time over; it doesn't request again.
|
|
165
|
+
*/
|
|
166
|
+
slideDuration?: number;
|
|
167
|
+
/** The Stories shown: none while loading, on error or with none. */
|
|
168
|
+
private stories;
|
|
169
|
+
/**
|
|
170
|
+
* The fetched products, by Story `ad_id`, or `"loading"` while the product
|
|
171
|
+
* request runs. Undefined without a product request.
|
|
172
|
+
*/
|
|
173
|
+
private products?;
|
|
174
|
+
/**
|
|
175
|
+
* The ad request is pending (and has what it needs to go out): a skeleton
|
|
176
|
+
* stands in for the carousel until the Stories arrive.
|
|
177
|
+
*/
|
|
178
|
+
private requesting;
|
|
179
|
+
/**
|
|
180
|
+
* The first Story's media is still loading: a skeleton covers the cards
|
|
181
|
+
* until its cover or its video is ready (or MEDIA_TIMEOUT passes), so the
|
|
182
|
+
* first card doesn't show up piece by piece. Meanwhile, the cards load
|
|
183
|
+
* underneath, their videos without playing, and no event goes out.
|
|
184
|
+
*/
|
|
185
|
+
private mediaLoading;
|
|
186
|
+
/**
|
|
187
|
+
* Cancels the wait for the media in progress: when other Stories replace
|
|
188
|
+
* its Stories, or the element leaves the page.
|
|
189
|
+
*/
|
|
190
|
+
private mediaWait?;
|
|
191
|
+
/**
|
|
192
|
+
* Cancels the request in progress. Kept, already aborted, when leaving the
|
|
193
|
+
* page cancelled it, so connecting again requests once more.
|
|
194
|
+
*/
|
|
195
|
+
private request?;
|
|
196
|
+
static readonly styles: lit.CSSResult[];
|
|
197
|
+
/**
|
|
198
|
+
* How many of each SKU, from each seller (see cartKey), were added since
|
|
199
|
+
* the player opened, for its stepper. It doesn't read the store's cart: it
|
|
200
|
+
* counts the add and remove events sent, and starts over each time the
|
|
201
|
+
* player opens, as the cart may have changed meanwhile.
|
|
202
|
+
*/
|
|
203
|
+
private readonly cartQuantities;
|
|
204
|
+
/**
|
|
205
|
+
* One per rendered card, by its key (see Slide): a Story can show in more
|
|
206
|
+
* than one card, each with its own video.
|
|
207
|
+
*/
|
|
208
|
+
private readonly cardVideos;
|
|
209
|
+
/** The sound was on when the highlight moved: the new card turns it on. */
|
|
210
|
+
private soundPending;
|
|
211
|
+
/**
|
|
212
|
+
* What to do once the next render is on screen, when the new highlighted
|
|
213
|
+
* card's video exists (see leaveHighlight and onLayoutChange). A step
|
|
214
|
+
* taken before then replaces it.
|
|
215
|
+
*/
|
|
216
|
+
private afterRender?;
|
|
217
|
+
private readonly carousel;
|
|
218
|
+
private readonly player;
|
|
219
|
+
private readonly events;
|
|
220
|
+
constructor();
|
|
221
|
+
connectedCallback(): void;
|
|
222
|
+
disconnectedCallback(): void;
|
|
223
|
+
protected willUpdate(changed: PropertyValues<this>): void;
|
|
224
|
+
protected updated(): void;
|
|
225
|
+
private get activeHydration();
|
|
226
|
+
/**
|
|
227
|
+
* Requests the Story and shows it, then hydrates its products. Until the
|
|
228
|
+
* Story arrives, and when there is none (see fetchStories), the element
|
|
229
|
+
* renders nothing.
|
|
230
|
+
*/
|
|
231
|
+
private loadStory;
|
|
232
|
+
private showStories;
|
|
233
|
+
/**
|
|
234
|
+
* Shows the cards once the first Story's cover or video is ready: whichever
|
|
235
|
+
* loads first, or once both failed. Only then are the Stories impressed
|
|
236
|
+
* and do their videos play, from the start.
|
|
237
|
+
*/
|
|
238
|
+
private waitForFirstMedia;
|
|
239
|
+
/**
|
|
240
|
+
* Where each Story is being watched: the cards on screen (not the hidden
|
|
241
|
+
* ones kept for the slide in) and the open player's video, while their
|
|
242
|
+
* video plays. A card showing only its cover doesn't count. Behind the
|
|
243
|
+
* expanded player, a modal over the page, the cards are covered.
|
|
244
|
+
*/
|
|
245
|
+
private viewTargets;
|
|
246
|
+
private videoFor;
|
|
247
|
+
private get activeVideo();
|
|
248
|
+
private leaveHighlight;
|
|
249
|
+
private stepInPlayer;
|
|
250
|
+
private openPlayer;
|
|
251
|
+
private closePlayer;
|
|
252
|
+
private formatter?;
|
|
253
|
+
private get locale();
|
|
254
|
+
private labelSet?;
|
|
255
|
+
private get labels();
|
|
256
|
+
private get formatPrice();
|
|
257
|
+
private productOf;
|
|
258
|
+
private readonly renderSlide;
|
|
259
|
+
protected render(): typeof nothing | lit.TemplateResult<1>;
|
|
260
|
+
private renderPlayer;
|
|
261
|
+
private cartActionsFor;
|
|
262
|
+
/**
|
|
263
|
+
* Adds one of `item` to the stepper's count, or removes one, and tells the
|
|
264
|
+
* store, which changes its cart: the element has none. When add to cart
|
|
265
|
+
* and the stepper swap places, the focus moves to the one now shown.
|
|
266
|
+
*/
|
|
267
|
+
private changeCart;
|
|
268
|
+
}
|
|
269
|
+
declare global {
|
|
270
|
+
interface HTMLElementTagNameMap {
|
|
271
|
+
[TAG_NAME]: VtexAdsStoryCarouselElement;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
declare function defineVtexAdsStoryCarousel(): void;
|
|
275
|
+
|
|
276
|
+
export { type StoryHydration as S, TAG_NAME as T, VtexAdsStoryCarouselElement as V, type StoryProductDetails as a, defineVtexAdsStoryCarousel as d };
|
package/package.json
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commerce events the element hands to the store: it has no cart of its
|
|
3
|
+
* own. They bubble and cross shadow roots, so the store can listen on the
|
|
4
|
+
* element, the document or any ancestor.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add to cart, or the stepper's plus, was clicked in the player. No default
|
|
9
|
+
* action.
|
|
10
|
+
*/
|
|
11
|
+
export const ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The stepper's minus, or its trash with one left, was clicked in the
|
|
15
|
+
* player. No default action.
|
|
16
|
+
*/
|
|
17
|
+
export const REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
|
|
18
|
+
|
|
19
|
+
interface StoryCartEventDetail {
|
|
20
|
+
/** The Story product's SKU, from the ad API (`product.product_sku`). */
|
|
21
|
+
sku: string;
|
|
22
|
+
/**
|
|
23
|
+
* The product's seller, from the ad API (`product.seller_id`). Missing
|
|
24
|
+
* when the ad API doesn't send one.
|
|
25
|
+
*/
|
|
26
|
+
seller?: string;
|
|
27
|
+
/** How many to add (or, removing, to remove). Always 1 for now. */
|
|
28
|
+
quantity: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The detail of the add to cart event: `quantity` is how many to add. */
|
|
32
|
+
export type StoryAddToCartDetail = StoryCartEventDetail;
|
|
33
|
+
|
|
34
|
+
/** The detail of remove from cart: `quantity` is how many to remove. */
|
|
35
|
+
export type StoryRemoveFromCartDetail = StoryCartEventDetail;
|
|
36
|
+
|
|
37
|
+
/** The product an event is about: its SKU and, when known, its seller. */
|
|
38
|
+
export type StoryCartItem = Pick<StoryCartEventDetail, "sku" | "seller">;
|
|
39
|
+
|
|
40
|
+
export type StoryAddToCartEvent = CustomEvent<StoryAddToCartDetail>;
|
|
41
|
+
export type StoryRemoveFromCartEvent = CustomEvent<StoryRemoveFromCartDetail>;
|
|
42
|
+
|
|
43
|
+
function cartEvent(
|
|
44
|
+
type: typeof ADD_TO_CART_EVENT | typeof REMOVE_FROM_CART_EVENT,
|
|
45
|
+
{ sku, seller }: StoryCartItem,
|
|
46
|
+
quantity: number,
|
|
47
|
+
): CustomEvent<StoryCartEventDetail> {
|
|
48
|
+
return new CustomEvent<StoryCartEventDetail>(type, {
|
|
49
|
+
detail: { sku, ...(seller && { seller }), quantity },
|
|
50
|
+
bubbles: true,
|
|
51
|
+
composed: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The add to cart event for `item`, bubbling and composed, to dispatch from
|
|
57
|
+
* the element. `quantity` defaults to 1.
|
|
58
|
+
*/
|
|
59
|
+
export function addToCartEvent(
|
|
60
|
+
item: StoryCartItem,
|
|
61
|
+
quantity = 1,
|
|
62
|
+
): StoryAddToCartEvent {
|
|
63
|
+
return cartEvent(ADD_TO_CART_EVENT, item, quantity);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The remove from cart event for `item`, bubbling and composed, to dispatch
|
|
68
|
+
* from the element. `quantity` (how many to remove) defaults to 1.
|
|
69
|
+
*/
|
|
70
|
+
export function removeFromCartEvent(
|
|
71
|
+
item: StoryCartItem,
|
|
72
|
+
quantity = 1,
|
|
73
|
+
): StoryRemoveFromCartEvent {
|
|
74
|
+
return cartEvent(REMOVE_FROM_CART_EVENT, item, quantity);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Types `addEventListener("vtex-ads-story:add-to-cart", …)` and
|
|
78
|
+
// "vtex-ads-story:remove-from-cart" on any element, the document and the
|
|
79
|
+
// window.
|
|
80
|
+
declare global {
|
|
81
|
+
interface HTMLElementEventMap {
|
|
82
|
+
[ADD_TO_CART_EVENT]: StoryAddToCartEvent;
|
|
83
|
+
[REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
|
|
84
|
+
}
|
|
85
|
+
interface DocumentEventMap {
|
|
86
|
+
[ADD_TO_CART_EVENT]: StoryAddToCartEvent;
|
|
87
|
+
[REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
|
|
88
|
+
}
|
|
89
|
+
interface WindowEventMap {
|
|
90
|
+
[ADD_TO_CART_EVENT]: StoryAddToCartEvent;
|
|
91
|
+
[REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -131,6 +131,11 @@ export interface CardOptions {
|
|
|
131
131
|
* card shows only the cover, with no sound button.
|
|
132
132
|
*/
|
|
133
133
|
withVideo?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Whether the video plays on its own (default true). Without it, the
|
|
136
|
+
* video loads but waits (see renderMedia).
|
|
137
|
+
*/
|
|
138
|
+
autoplay?: boolean;
|
|
134
139
|
/** The texts (the sound button's, shown when the card has a video). */
|
|
135
140
|
labels: StoryLabels;
|
|
136
141
|
/** The Story's product, shown at the bottom of the card. */
|
|
@@ -178,7 +183,8 @@ function renderSoundButton(video: VideoController, options: CardOptions) {
|
|
|
178
183
|
|
|
179
184
|
/**
|
|
180
185
|
* A 9:16 card with the Story cover and, with a media_url, the video looping
|
|
181
|
-
* muted over it (see renderMedia)
|
|
186
|
+
* muted over it (see renderMedia), or a notice that it is unavailable if it
|
|
187
|
+
* can't load. A button with a play icon in the middle (not over the notice)
|
|
182
188
|
* covers the card, and a sound button shows while the video plays. With a
|
|
183
189
|
* product, its pill sits at the bottom (see renderProduct); with a link
|
|
184
190
|
* destination, the call to action does (see renderCta). The sound, product
|
|
@@ -198,7 +204,12 @@ export function renderCard(
|
|
|
198
204
|
${ref(options.ref)}
|
|
199
205
|
@click=${{ handleEvent: () => options.onPress?.(), capture: true }}
|
|
200
206
|
>
|
|
201
|
-
${renderMedia(story, video, {
|
|
207
|
+
${renderMedia(story, video, {
|
|
208
|
+
withVideo,
|
|
209
|
+
autoplay: options.autoplay,
|
|
210
|
+
labels: options.labels,
|
|
211
|
+
announce: false,
|
|
212
|
+
})}
|
|
202
213
|
<button
|
|
203
214
|
type="button"
|
|
204
215
|
class="card-open"
|
|
@@ -206,7 +217,9 @@ export function renderCard(
|
|
|
206
217
|
aria-label=${options.label}
|
|
207
218
|
@click=${options.onSelect}
|
|
208
219
|
>
|
|
209
|
-
|
|
220
|
+
${withVideo && video.failed
|
|
221
|
+
? nothing
|
|
222
|
+
: html`<span class="play" aria-hidden="true">${icon("play")}</span>`}
|
|
210
223
|
</button>
|
|
211
224
|
${withVideo && hasVideo(story, video) && !video.paused
|
|
212
225
|
? renderSoundButton(video, options)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { css, html } from "lit";
|
|
2
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
3
|
+
import { STAGE_HEIGHT, VISIBLE_SIDE } from "./carousel";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* While the covers and product photos load, the carousel is hidden under a
|
|
7
|
+
* skeleton of the same layout, which then fades out. The skeleton's slides
|
|
8
|
+
* have their own class, so they never count as the carousel's.
|
|
9
|
+
*/
|
|
10
|
+
export const carouselSkeletonStyles = css`
|
|
11
|
+
.root {
|
|
12
|
+
position: relative;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.root[data-requesting] {
|
|
16
|
+
height: ${STAGE_HEIGHT};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.root[data-loading] .carousel {
|
|
20
|
+
visibility: hidden;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.skeleton {
|
|
24
|
+
position: absolute;
|
|
25
|
+
inset: 0;
|
|
26
|
+
z-index: 2;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
pointer-events: none;
|
|
30
|
+
transition:
|
|
31
|
+
opacity 0.3s ease,
|
|
32
|
+
visibility 0s;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.skeleton[data-done] {
|
|
36
|
+
opacity: 0;
|
|
37
|
+
visibility: hidden;
|
|
38
|
+
transition:
|
|
39
|
+
opacity 0.3s ease,
|
|
40
|
+
visibility 0s 0.3s;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.skeleton-slide {
|
|
44
|
+
position: absolute;
|
|
45
|
+
top: 0;
|
|
46
|
+
left: 50%;
|
|
47
|
+
width: calc(${STAGE_HEIGHT} * 9 / 16);
|
|
48
|
+
height: 100%;
|
|
49
|
+
margin-left: calc(${STAGE_HEIGHT} * 9 / -32);
|
|
50
|
+
transform: translateX(calc(var(--place) * (100% + 8px))) scale(0.9);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.skeleton-slide[data-active] {
|
|
54
|
+
transform: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.skeleton-card {
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: 100%;
|
|
60
|
+
border-radius: var(--vtex-ads-story-radius, 20px);
|
|
61
|
+
background: #ececec;
|
|
62
|
+
animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.skeleton[data-done] .skeleton-card {
|
|
66
|
+
animation: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@keyframes skeleton-pulse {
|
|
70
|
+
to {
|
|
71
|
+
background-color: #f6f6f6;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@media (prefers-reduced-motion: reduce) {
|
|
76
|
+
.skeleton,
|
|
77
|
+
.skeleton[data-done] {
|
|
78
|
+
transition: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.skeleton-card {
|
|
82
|
+
animation: none;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Placeholder for the carousel while it loads.
|
|
89
|
+
* Decorative, so hidden from assistive technology. With `done`, it fades out
|
|
90
|
+
* and stays out of sight.
|
|
91
|
+
*/
|
|
92
|
+
export function renderCarouselSkeleton({ done }: { done: boolean }) {
|
|
93
|
+
const places = Array.from(
|
|
94
|
+
{ length: VISIBLE_SIDE * 2 + 1 },
|
|
95
|
+
(_, i) => i - VISIBLE_SIDE,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return html`
|
|
99
|
+
<div class="skeleton" aria-hidden="true" ?data-done=${done}>
|
|
100
|
+
${places.map(
|
|
101
|
+
(place) => html`
|
|
102
|
+
<div
|
|
103
|
+
class="skeleton-slide"
|
|
104
|
+
?data-active=${place === 0}
|
|
105
|
+
style=${styleMap({ "--place": String(place) })}
|
|
106
|
+
>
|
|
107
|
+
<div class="skeleton-card"></div>
|
|
108
|
+
</div>
|
|
109
|
+
`,
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
`;
|
|
113
|
+
}
|