@react-md/form
Version:
This package is for creating all the different form input types.
59 lines • 3.62 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuItemFileInput = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var classnames_1 = __importDefault(require("classnames"));
var icon_1 = require("@react-md/icon");
var menu_1 = require("@react-md/menu");
/**
* A wrapper for the `<input type="file">` element that works within menus.
*
* @remarks \@since 5.0.0
*/
exports.MenuItemFileInput = (0, react_1.forwardRef)(function MenuItemFileInput(_a, ref) {
var id = _a.id, onClick = _a.onClick, onChange = _a.onChange, accept = _a.accept, _b = _a.multiple, multiple = _b === void 0 ? false : _b, children = _a.children, inputProps = _a.inputProps, _c = _a.disableRepeatableFiles, disableRepeatableFiles = _c === void 0 ? false : _c, propLeftAddon = _a.leftAddon, _d = _a.inputLabel, inputLabel = _d === void 0 ? "Upload" : _d, props = __rest(_a, ["id", "onClick", "onChange", "accept", "multiple", "children", "inputProps", "disableRepeatableFiles", "leftAddon", "inputLabel"]);
var inputRef = (0, react_1.useRef)(null);
var leftAddon = (0, icon_1.useIcon)("upload", propLeftAddon);
return ((0, jsx_runtime_1.jsxs)(menu_1.MenuItem, __assign({}, props, { id: "".concat(id, "-menuitem"), ref: ref, onClick: function (event) {
var _a;
onClick === null || onClick === void 0 ? void 0 : onClick(event);
// prevent the menu from closing since you need access to the
// `<input type="file">` to select a file and the menu unmounts when
// hidden.
event.stopPropagation();
/* istanbul-ignore-next */
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
}, leftAddon: leftAddon }, { children: [children, (0, jsx_runtime_1.jsx)("input", __assign({ "aria-label": inputLabel, id: id, ref: inputRef, type: "file", accept: accept, multiple: multiple, value: disableRepeatableFiles ? undefined : "", onChange: onChange }, inputProps, { onClick: function (event) {
var _a;
(_a = inputProps === null || inputProps === void 0 ? void 0 : inputProps.onClick) === null || _a === void 0 ? void 0 : _a.call(inputProps, event);
// prevent double click events since the MenuItem clicks this input
event.stopPropagation();
}, className: (0, classnames_1.default)("rmd-file-input", inputProps === null || inputProps === void 0 ? void 0 : inputProps.className) }))] })));
});
//# sourceMappingURL=MenuItemFileInput.js.map