UNPKG

@fluentui/react-northstar

Version:
110 lines (108 loc) 4.72 kB
"use strict"; exports.__esModule = true; exports.videoClassName = exports.Video = void 0; var _reactComponentRef = require("@fluentui/react-component-ref"); var PropTypes = _interopRequireWildcard(require("prop-types")); var React = _interopRequireWildcard(require("react")); var _accessibility = require("@fluentui/accessibility"); var _utils = require("../../utils"); var _reactBindings = require("@fluentui/react-bindings"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var videoClassName = 'ui-video'; exports.videoClassName = videoClassName; /** * A Video provides ability to embed video content. */ var Video = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = (0, _reactBindings.useFluentContext)(); var _useTelemetry = (0, _reactBindings.useTelemetry)(Video.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var controls = props.controls, autoPlay = props.autoPlay, loop = props.loop, poster = props.poster, src = props.src, muted = props.muted, variables = props.variables, className = props.className, design = props.design, styles = props.styles; var videoRef = React.useRef(); var ElementType = (0, _reactBindings.getElementType)(props); var unhandledProps = (0, _reactBindings.useUnhandledProps)(Video.handledProps, props); var getA11yProps = (0, _reactBindings.useAccessibility)(props.accessibility, { debugName: Video.displayName }); React.useEffect(function () { // this is a workaround for a potential memory leak in Chromium which retains a Detached HTMLVideoElement when <video autoplay> is unmounted // https://bugs.chromium.org/p/chromium/issues/detail?id=969049 return function () { if (videoRef.current) { // we want to perform the cleanup on the latest element rendered // eslint-disable-next-line react-hooks/exhaustive-deps videoRef.current.src = ''; } }; }, []); React.useEffect(function () { // React doesn't guaranty that props will be set: // https://github.com/facebook/react/issues/10389 if (videoRef.current) { videoRef.current.muted = !!muted; } }, [muted]); var _useStyles = (0, _reactBindings.useStyles)(Video.displayName, { className: videoClassName, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, variables: variables, design: design, styles: styles }; } }), classes = _useStyles.classes; var element = /*#__PURE__*/React.createElement(_reactComponentRef.Ref, { innerRef: videoRef }, /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({ className: classes.root, autoPlay: autoPlay, controls: controls, ref: ref, loop: loop, poster: poster, src: src }, unhandledProps)))); setEnd(); return element; }); exports.Video = Video; Video.create = (0, _utils.createShorthandFactory)({ Component: Video, mappedProp: 'src' }); Video.displayName = 'Video'; Video.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({ children: false, content: false }), { autoPlay: PropTypes.bool, controls: PropTypes.bool, loop: PropTypes.bool, muted: PropTypes.bool, poster: PropTypes.string, src: PropTypes.string }); Video.defaultProps = { as: 'video', accessibility: _accessibility.videoBehavior, controls: true, autoPlay: false, muted: false }; Video.handledProps = Object.keys(Video.propTypes); //# sourceMappingURL=Video.js.map