UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

45 lines (44 loc) 1.74 kB
"use client"; const require_runtime = require("../../_virtual/_rolldown/runtime.cjs"); const require_use_props = require("../../core/MantineProvider/use-props/use-props.cjs"); const require_factory = require("../../core/factory/factory.cjs"); let react = require("react"); react = require_runtime.__toESM(react); let _mantine_hooks = require("@mantine/hooks"); let react_jsx_runtime = require("react/jsx-runtime"); //#region packages/@mantine/core/src/components/FileButton/FileButton.tsx const FileButton = require_factory.genericFactory((props) => { const { onChange, children, multiple, accept, name, form, resetRef, disabled, capture, inputProps, ref, ...others } = require_use_props.useProps("FileButton", null, props); const inputRef = (0, react.useRef)(null); const onClick = () => { !disabled && inputRef.current?.click(); }; const handleChange = (event) => { if (event.currentTarget.files === null) return onChange(multiple ? [] : null); if (multiple) onChange(Array.from(event.currentTarget.files)); else onChange(event.currentTarget.files[0] || null); }; const reset = () => { if (inputRef.current) inputRef.current.value = ""; }; (0, _mantine_hooks.assignRef)(resetRef, reset); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { style: { display: "none" }, type: "file", accept, multiple, onChange: handleChange, ref: (0, _mantine_hooks.useMergedRef)(ref, inputRef), name, form, capture, ...inputProps }), children({ onClick, ...others })] }); }); FileButton.displayName = "@mantine/core/FileButton"; //#endregion exports.FileButton = FileButton; //# sourceMappingURL=FileButton.cjs.map