@shopify/hydrogen-react
Version:
React components, hooks, and utilities for creating custom Shopify storefronts
45 lines (44 loc) • 1.19 kB
JavaScript
import { shopifyImageLoader } from "./image-size.mjs";
import { createElement } from "react";
import { jsx } from "react/jsx-runtime";
function Video(props) {
var _a, _b;
const {
data,
previewImageOptions,
id = data.id,
playsInline = true,
controls = true,
sourceProps = {},
...passthroughProps
} = props;
const posterUrl = shopifyImageLoader({
src: (_b = (_a = data.previewImage) == null ? void 0 : _a.url) != null ? _b : "",
...previewImageOptions
});
if (!data.sources) {
throw new Error(`<Video/> requires a 'data.sources' array`);
}
return /* @__PURE__ */ jsx("video", {
...passthroughProps,
id,
playsInline,
controls,
poster: posterUrl,
children: data.sources.map((source) => {
if (!((source == null ? void 0 : source.url) && (source == null ? void 0 : source.mimeType))) {
throw new Error(`<Video/> needs 'source.url' and 'source.mimeType'`);
}
return /* @__PURE__ */ createElement("source", {
...sourceProps,
key: source.url,
src: source.url,
type: source.mimeType
});
})
});
}
export {
Video
};
//# sourceMappingURL=Video.mjs.map