@braineet/ui
Version:
Braineet design system
94 lines • 3.77 kB
JavaScript
var _excluded = ["file", "status", "children", "display"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
/* eslint-disable no-nested-ternary */
import React from 'react';
import Icon from '../icon';
import Link from '../link';
import Pane from '../pane';
import Text from '../text';
import { Tooltip } from '../tooltip';
import { getFileIcon } from '../upload/useUploadState/utils';
import { FileContainer, FileIconWrapper, FileThumb } from './styles';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export var File = function File(_ref) {
var file = _ref.file,
status = _ref.status,
children = _ref.children,
display = _ref.display,
restProps = _objectWithoutPropertiesLoose(_ref, _excluded);
var name = file.name,
thumbUrl = file.thumbUrl,
icon = file.icon,
tooltipText = file.tooltipText;
var iconPropsByStatus = React.useMemo(function () {
if (icon === null) return;
switch (status) {
case 'error':
return {
color: null
};
default:
{
var _getFileIcon, _getFileIcon2;
return {
name: (icon == null ? void 0 : icon.name) || ((_getFileIcon = getFileIcon(file)) == null ? void 0 : _getFileIcon.name),
color: (icon == null ? void 0 : icon.color) || ((_getFileIcon2 = getFileIcon(file)) == null ? void 0 : _getFileIcon2.color)
};
}
}
}, [status]);
return /*#__PURE__*/_jsxs(FileContainer, _extends({
status: status,
$display: display
}, restProps, {
children: [/*#__PURE__*/_jsx(Tooltip, {
placement: "bottom-start",
content: /*#__PURE__*/_jsx(Text, {
display: "block",
textAlign: "left",
"aria-hidden": "true",
maxWidth: "240px",
minWidth: "auto",
size: "xs",
children: tooltipText || name
}),
children: /*#__PURE__*/_jsxs(Pane, {
display: "flex",
maxWidth: "100%",
minWidth: "0",
children: [thumbUrl || iconPropsByStatus ? thumbUrl ? /*#__PURE__*/_jsx(FileThumb, {
thumbUrl: thumbUrl
}) : iconPropsByStatus != null && iconPropsByStatus.name ? /*#__PURE__*/_jsx(FileIconWrapper, {
children: /*#__PURE__*/_jsx(Icon, _extends({}, iconPropsByStatus))
}) : null : null, display === 'row' ? /*#__PURE__*/_jsx(Pane, {
display: "flex",
alignY: "center",
minWidth: "0",
flexGrow: 1,
marginLeft: "8px",
children: (file == null ? void 0 : file.type) === 'link' ? /*#__PURE__*/_jsx(Link, _extends({
size: "small",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
display: "block",
overflow: "hidden"
}, file, {
children: name
})) : /*#__PURE__*/_jsx(Text, {
size: "xs",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
display: "block",
overflow: "hidden",
children: name
})
}) : null]
})
}), children]
}));
};
File.defaultProps = {
display: 'row'
};