UNPKG

@wordpress/block-library

Version:
142 lines (141 loc) • 4.11 kB
import { __, _x } from "@wordpress/i18n"; import { SelectControl, ToggleControl, __experimentalToolsPanelItem } from "@wordpress/components"; import { useCallback, useMemo } from "@wordpress/element"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; // packages/block-library/src/video/edit-common-settings.jsx const options = [ { value: "auto", label: __("Auto") }, { value: "metadata", label: __("Metadata") }, { value: "none", label: _x("None", "Preload value") } ]; const VideoSettings = ({ setAttributes, attributes }) => { const { autoplay, controls, loop, muted, playsInline, preload } = attributes; const autoPlayHelpText = __("Autoplay may cause usability issues for some users."); const getAutoplayHelp = useCallback((checked) => { return checked ? autoPlayHelpText : null; }, []); const toggleFactory = 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 = useCallback((value) => { setAttributes({ preload: value }); }, []); return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Autoplay"), isShownByDefault: true, hasValue: () => !!autoplay, onDeselect: () => { setAttributes({ autoplay: false, muted: false }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Autoplay"), onChange: toggleFactory.autoplay, checked: !!autoplay, help: getAutoplayHelp }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Loop"), isShownByDefault: true, hasValue: () => !!loop, onDeselect: () => { setAttributes({ loop: false }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Loop"), onChange: toggleFactory.loop, checked: !!loop }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Muted"), isShownByDefault: true, hasValue: () => !!muted, onDeselect: () => { setAttributes({ muted: false }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Muted"), onChange: toggleFactory.muted, checked: !!muted, disabled: autoplay, help: autoplay ? __("Muted because of Autoplay.") : null }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Playback controls"), isShownByDefault: true, hasValue: () => !controls, onDeselect: () => { setAttributes({ controls: true }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Playback controls"), onChange: toggleFactory.controls, checked: !!controls }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Play inline"), isShownByDefault: true, hasValue: () => !!playsInline, onDeselect: () => { setAttributes({ playsInline: false }); }, children: /* @__PURE__ */ jsx(ToggleControl, { label: __("Play inline"), onChange: toggleFactory.playsInline, checked: !!playsInline, disabled: autoplay, help: autoplay ? __("Play inline enabled because of Autoplay.") : __("When enabled, videos will play directly within the webpage on mobile browsers, instead of opening in a fullscreen player.") }) }), /* @__PURE__ */ jsx(__experimentalToolsPanelItem, { label: __("Preload"), isShownByDefault: true, hasValue: () => preload !== "metadata", onDeselect: () => { setAttributes({ preload: "metadata" }); }, children: /* @__PURE__ */ jsx(SelectControl, { label: __("Preload"), value: preload, onChange: onChangePreload, options, hideCancelButton: true }) }) ] }); }; export { VideoSettings as default }; //# sourceMappingURL=edit-common-settings.mjs.map