UNPKG

@procore/core-react

Version:
79 lines 4.65 kB
var _excluded = ["maxFileNumber", "children", "onSubmit", "sources", "isOpen", "currentSource", "onCurrentSourceChange", "onCancel", "unsubmittedValueCount", "qa"]; 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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } 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; } import React from 'react'; import { Button } from '../../Button/Button'; import { Modal } from '../../Modal/Modal'; import { Tooltip } from '../../Tooltip/Tooltip'; import { Typography } from '../../Typography/Typography'; import { useI18nContext } from '../../_hooks/I18n'; import { FileExplorerSidebar } from '../FileExplorer/FileExplorerSidebar'; import { StyledAttachButton, StyledModalBody, StyledModalContent, StyledModalHeader, StyledModalInnerBody, StyledSource } from './FileExplorer.styles'; import { FileExplorerModal } from './FileExplorerModal'; export var FileExplorer = /*#__PURE__*/React.forwardRef(function FileExplorer(_ref, ref) { var _ref$maxFileNumber = _ref.maxFileNumber, maxFileNumber = _ref$maxFileNumber === void 0 ? Infinity : _ref$maxFileNumber, children = _ref.children, onSubmit = _ref.onSubmit, sources = _ref.sources, isOpen = _ref.isOpen, currentSource = _ref.currentSource, onCurrentSourceChange = _ref.onCurrentSourceChange, onCancel = _ref.onCancel, unsubmittedValueCount = _ref.unsubmittedValueCount, qa = _ref.qa, props = _objectWithoutProperties(_ref, _excluded); var I18n = useI18nContext(); var hasPendingUploadSources = sources.some(function (_ref2) { var isUploading = _ref2.isUploading; return isUploading; }); var isAttachButtonDisabled = hasPendingUploadSources || unsubmittedValueCount === 0; return /*#__PURE__*/React.createElement(FileExplorerModal, _extends({}, props, { ref: ref, open: isOpen, onKeyDown: function onKeyDown(e) { if (e.key === 'Esc' || e.key === 'Escape') { onCancel(); } } }), /*#__PURE__*/React.createElement(StyledModalHeader, { onClose: function onClose() { onCancel(); } }, I18n.t('core.fileExplorer.modalTitle')), /*#__PURE__*/React.createElement(StyledModalBody, null, /*#__PURE__*/React.createElement(StyledModalInnerBody, null, /*#__PURE__*/React.createElement(FileExplorerSidebar, { value: currentSource, onChange: onCurrentSourceChange, sources: sources, isOpen: isOpen }), /*#__PURE__*/React.createElement(StyledModalContent, { tabIndex: -1 }, /*#__PURE__*/React.createElement(StyledSource, null, children)))), /*#__PURE__*/React.createElement(Modal.Footer, null, /*#__PURE__*/React.createElement(Modal.FooterNotation, null, /*#__PURE__*/React.createElement(Typography, { color: "gray45", italic: true }, maxFileNumber === Infinity ? I18n.t('core.fileExplorer.filesSelected', { count: unsubmittedValueCount }) : I18n.t('core.fileExplorer.filesSelectedWithLimit', { count: unsubmittedValueCount, maxFileNumber: maxFileNumber }))), /*#__PURE__*/React.createElement(Modal.FooterButtons, null, /*#__PURE__*/React.createElement(Button, { "data-qa": qa === null || qa === void 0 ? void 0 : qa.cancelButton, variant: "tertiary", onClick: function onClick() { onCancel(); } }, I18n.t('core.fileExplorer.cancelAction')), /*#__PURE__*/React.createElement(Tooltip, { showKeys: [], trigger: isAttachButtonDisabled ? 'hover' : 'none', overlay: hasPendingUploadSources ? I18n.t('core.fileExplorer.filesPendingUpload') : I18n.t('core.fileExplorer.noSelectedItems') }, /*#__PURE__*/React.createElement(StyledAttachButton, null, /*#__PURE__*/React.createElement(Button, { "data-qa": qa === null || qa === void 0 ? void 0 : qa.attachButton, variant: "primary", disabled: isAttachButtonDisabled, onClick: function onClick() { onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(); } }, I18n.t('core.fileExplorer.attachAction'))))))); }); //# sourceMappingURL=FileExplorer.js.map