UNPKG

@wordpress/components

Version:
49 lines (48 loc) • 1.48 kB
import { useRef } from "@wordpress/element"; import Button from "../button/index.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/components/src/form-file-upload/index.tsx /** * FormFileUpload allows users to select files from their local device. * * ```jsx * import { FormFileUpload } from '@wordpress/components'; * * const MyFormFileUpload = () => ( * <FormFileUpload * accept="image/*" * onChange={ ( event ) => console.log( event.currentTarget.files ) } * > * Upload * </FormFileUpload> * ); * ``` */ function FormFileUpload({ accept, children, multiple = false, onChange, onClick, render, __next40pxDefaultSize: _next40pxDefaultSize, ...props }) { const ref = useRef(null); const openFileDialog = () => { ref.current?.click(); }; const ui = render ? render({ openFileDialog }) : /* @__PURE__ */ jsx(Button, { onClick: openFileDialog, __next40pxDefaultSize: true, ...props, children }); const compatAccept = accept?.includes("audio/*") ? `${accept}, audio/mp3, audio/x-m4a, audio/x-m4b, audio/x-m4p, audio/x-wav, audio/webm` : accept; return /* @__PURE__ */ jsxs("div", { className: "components-form-file-upload", children: [ui, /* @__PURE__ */ jsx("input", { type: "file", ref, multiple, style: { display: "none" }, accept: compatAccept, onChange, onClick, "data-testid": "form-file-upload-input" })] }); } export { FormFileUpload, FormFileUpload as default }; //# sourceMappingURL=index.mjs.map