UNPKG

@wordpress/block-library

Version:
147 lines (146 loc) • 5.25 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_components = require("@wordpress/components"); let _wordpress_element = require("@wordpress/element"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/video/edit-common-settings.jsx const options = [ { value: "auto", label: (0, _wordpress_i18n.__)("Auto") }, { value: "metadata", label: (0, _wordpress_i18n.__)("Metadata") }, { value: "none", label: (0, _wordpress_i18n._x)("None", "Preload value") } ]; const VideoSettings = ({ setAttributes, attributes }) => { const { autoplay, controls, loop, muted, playsInline, preload } = attributes; const autoPlayHelpText = (0, _wordpress_i18n.__)("Autoplay may cause usability issues for some users."); const getAutoplayHelp = (0, _wordpress_element.useCallback)((checked) => { return checked ? autoPlayHelpText : null; }, []); const toggleFactory = (0, _wordpress_element.useMemo)(() => { const toggleAttribute = (attribute) => { return (newValue) => { setAttributes({ [attribute]: newValue, ...attribute === "autoplay" && { muted: newValue, playsInline: newValue } }); }; }; return { autoplay: toggleAttribute("autoplay"), loop: toggleAttribute("loop"), muted: toggleAttribute("muted"), controls: toggleAttribute("controls"), playsInline: toggleAttribute("playsInline") }; }, []); const onChangePreload = (0, _wordpress_element.useCallback)((value) => { setAttributes({ preload: value }); }, []); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Autoplay"), isShownByDefault: true, hasValue: () => !!autoplay, onDeselect: () => { setAttributes({ autoplay: false, muted: false }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Autoplay"), onChange: toggleFactory.autoplay, checked: !!autoplay, help: getAutoplayHelp }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Loop"), isShownByDefault: true, hasValue: () => !!loop, onDeselect: () => { setAttributes({ loop: false }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Loop"), onChange: toggleFactory.loop, checked: !!loop }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Muted"), isShownByDefault: true, hasValue: () => !!muted, onDeselect: () => { setAttributes({ muted: false }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Muted"), onChange: toggleFactory.muted, checked: !!muted, disabled: autoplay, help: autoplay ? (0, _wordpress_i18n.__)("Muted because of Autoplay.") : null }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Playback controls"), isShownByDefault: true, hasValue: () => !controls, onDeselect: () => { setAttributes({ controls: true }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Playback controls"), onChange: toggleFactory.controls, checked: !!controls }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Play inline"), isShownByDefault: true, hasValue: () => !!playsInline, onDeselect: () => { setAttributes({ playsInline: false }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, { label: (0, _wordpress_i18n.__)("Play inline"), onChange: toggleFactory.playsInline, checked: !!playsInline, disabled: autoplay, help: autoplay ? (0, _wordpress_i18n.__)("Play inline enabled because of Autoplay.") : (0, _wordpress_i18n.__)("When enabled, videos will play directly within the webpage on mobile browsers, instead of opening in a fullscreen player.") }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, { label: (0, _wordpress_i18n.__)("Preload"), isShownByDefault: true, hasValue: () => preload !== "metadata", onDeselect: () => { setAttributes({ preload: "metadata" }); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.SelectControl, { label: (0, _wordpress_i18n.__)("Preload"), value: preload, onChange: onChangePreload, options, hideCancelButton: true }) }) ] }); }; exports.default = VideoSettings; //# sourceMappingURL=edit-common-settings.cjs.map