UNPKG

organism-react-video

Version:
72 lines (69 loc) 2.19 kB
import _objectSpread from "reshow-runtime/es/helpers/objectSpread2"; import _toConsumableArray from "reshow-runtime/es/helpers/toConsumableArray"; import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties"; var _excluded = ["src", "otherSources", "videoParams", "sourceComponent", "videoComponent", "sourceType"]; // @ts-check import * as React from "react"; import { KEYS } from "reshow-constant"; import build from "reshow-build"; /** * @typedef {import('reshow-build').Component} Component */ /** * @typedef {object} VideoFileProps * @property {string} src * @property {string} [sourceType] * @property {{[key: string]: string}} [otherSources] * @property {Component} [sourceComponent] * @property {Component} [videoComponent] * @property {{[key:string]:any}} [videoParams] * @property {string} [className] * @property {React.CSSProperties} [style] */ /** * @param {VideoFileProps} props * https://www.w3schools.com/tags/tag_video.asp */ var VideoFile = function VideoFile(_ref) { var { src, otherSources, videoParams, sourceComponent = "source", videoComponent = "video", sourceType = "video/mp4" } = _ref, restProps = _objectWithoutProperties(_ref, _excluded); var sourceEl = build(sourceComponent); var videoEl = build(videoComponent); var thisSources = [sourceEl({ src, type: sourceType, key: "default" })]; if (otherSources) { thisSources.push.apply(thisSources, _toConsumableArray(KEYS(otherSources).map(function (key) { var sSrc = otherSources[key]; return sourceEl({ src: sSrc, type: key, key }); }))); } videoParams = videoParams || { controls: true }; if (videoParams["autoPlay"]) { videoParams["muted"] = true; if (null == videoParams["playsInline"]) { /** * https://stackoverflow.com/questions/43570460/html5-video-autoplay-on-iphone * https://webkit.org/blog/6784/new-video-policies-for-ios/ */ videoParams["playsInline"] = true; } } return videoEl(_objectSpread(_objectSpread({}, videoParams), restProps), thisSources); }; export default VideoFile;