@braineet/ui
Version:
Braineet design system
60 lines (58 loc) • 2.33 kB
JavaScript
var _excluded = ["icon", "title", "helper", "children", "disabled", "isDragActive", "isFocused"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
/* eslint-disable react/no-array-index-key */
import React from 'react';
import Heading from '../../heading';
import Icon from '../../icon';
import Pane from '../../pane';
import { UploadContainer } from './styles';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var UploadDropzone = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
var icon = _ref.icon,
title = _ref.title,
helper = _ref.helper,
children = _ref.children,
disabled = _ref.disabled,
isDragActive = _ref.isDragActive,
isFocused = _ref.isFocused,
restProps = _objectWithoutPropertiesLoose(_ref, _excluded);
/** constants */
var renderChildren = React.useMemo(function () {
if (children && /*#__PURE__*/React.isValidElement(children)) {
return /*#__PURE__*/React.cloneElement(children, {
className: 'upload-dropzone'
});
}
return /*#__PURE__*/_jsxs(Pane, {
className: "upload-dropzone",
children: [/*#__PURE__*/_jsx(Icon, {
name: icon,
size: 32
}), /*#__PURE__*/_jsxs(Pane, {
className: "upload-dropzone-texts",
children: [/*#__PURE__*/_jsx(Heading, {
sm: "sm",
margin: "0.5rem 0 0.25rem 0",
children: title
}), helper ? /*#__PURE__*/_jsx(Heading, {
size: "xs",
fontWeight: "500",
children: helper
}) : null]
})]
});
}, [children, icon, title, helper]);
return /*#__PURE__*/_jsx(UploadContainer, _extends({
isDragActive: isDragActive || isFocused,
disabled: disabled,
p: "0.5rem",
ref: ref
}, restProps, {
children: renderChildren
}));
});
UploadDropzone.defaultProps = {
icon: 'publish',
title: 'Drag and Drop or click to upload'
};