@wordpress/block-library
Version:
Block library for the WordPress editor.
52 lines (51 loc) • 1.71 kB
JavaScript
import { useState } from "@wordpress/element";
import { Notice, TextControl, __experimentalConfirmDialog } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { Stack } from "@wordpress/ui";
import { isValidVideoEmbedUrl } from "../embed-video-utils.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/cover/edit/embed-video-url-input.jsx
function EmbedVideoUrlInput({ onSubmit, onClose, initialUrl = "", allowedVideoProviders }) {
const [url, setUrl] = useState(initialUrl);
const [error, setError] = useState("");
const handleConfirm = () => {
if (!url) {
setError(__("Please enter a URL."));
return;
}
if (!isValidVideoEmbedUrl(url, allowedVideoProviders)) {
setError(__("This URL is not supported. Please enter a valid video link from a supported provider."));
return;
}
onSubmit(url);
onClose();
};
return /* @__PURE__ */ jsx(__experimentalConfirmDialog, {
isOpen: true,
onConfirm: handleConfirm,
onCancel: onClose,
confirmButtonText: __("Add video"),
size: "medium",
children: /* @__PURE__ */ jsxs(Stack, {
direction: "column",
gap: "lg",
children: [error && /* @__PURE__ */ jsx(Notice, {
status: "error",
isDismissible: false,
children: error
}), /* @__PURE__ */ jsx(TextControl, {
type: "url",
label: __("Video URL"),
value: url,
onChange: (value) => {
setUrl(value);
setError("");
},
placeholder: __("Enter YouTube, Vimeo, or other video URL"),
help: __("Add a background video to the cover block that will autoplay in a loop.")
})]
})
});
}
export { EmbedVideoUrlInput as default };
//# sourceMappingURL=embed-video-url-input.mjs.map