@carbon/react
Version:
React components for the Carbon Design System
88 lines (82 loc) • 2.73 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var iconsReact = require('@carbon/icons-react');
var PropTypes = require('prop-types');
var React = require('react');
var Loading = require('../Loading/Loading.js');
var usePrefix = require('../../internal/usePrefix.js');
var _Close;
function Filename({
iconDescription = 'Uploading file',
status = 'uploading',
invalid,
name,
tabIndex = 0,
['aria-describedby']: ariaDescribedBy,
...rest
}) {
const prefix = usePrefix.usePrefix();
switch (status) {
case 'uploading':
return /*#__PURE__*/React.createElement(Loading.default, {
description: iconDescription,
small: true,
withOverlay: false,
className: `${prefix}--file-loading`
});
case 'edit':
return /*#__PURE__*/React.createElement(React.Fragment, null, invalid && /*#__PURE__*/React.createElement(iconsReact.WarningFilled, {
className: `${prefix}--file-invalid`
}), /*#__PURE__*/React.createElement("button", _rollupPluginBabelHelpers.extends({
"aria-label": `${iconDescription} - ${name}`,
className: `${prefix}--file-close`,
type: "button",
tabIndex: tabIndex
}, rest, {
"aria-describedby": invalid ? ariaDescribedBy : undefined
}), _Close || (_Close = /*#__PURE__*/React.createElement(iconsReact.Close, null))));
case 'complete':
return /*#__PURE__*/React.createElement(iconsReact.CheckmarkFilled, _rollupPluginBabelHelpers.extends({
"aria-label": iconDescription,
className: `${prefix}--file-complete`
}, rest, {
tabIndex: -1
}), iconDescription && /*#__PURE__*/React.createElement("title", null, iconDescription));
default:
return null;
}
}
Filename.propTypes = {
/**
* Specify an id that describes the error to be read by screen readers when the filename is invalid
*/
['aria-describedby']: PropTypes.string,
/**
* Provide a description of the SVG icon to denote file upload status
*/
iconDescription: PropTypes.string,
/**
* Specify if the file is invalid
*/
invalid: PropTypes.bool,
/**
* Name of the uploaded file
*/
name: PropTypes.string,
/**
* Status of the file upload
*/
status: PropTypes.oneOf(['edit', 'complete', 'uploading']),
/**
* Provide a custom tabIndex value for the `<Filename>`
*/
tabIndex: PropTypes.number
};
exports.default = Filename;