UNPKG

@carbon/react

Version:

React components for the Carbon Design System

93 lines (85 loc) 3.27 kB
/** * 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'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); 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__default["default"].createElement(Loading["default"], { description: iconDescription, small: true, withOverlay: false, className: `${prefix}--file-loading` }); case 'edit': return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, invalid && /*#__PURE__*/React__default["default"].createElement(iconsReact.WarningFilled, { className: `${prefix}--file-invalid` }), /*#__PURE__*/React__default["default"].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__default["default"].createElement(iconsReact.Close, null)))); case 'complete': return /*#__PURE__*/React__default["default"].createElement(iconsReact.CheckmarkFilled, _rollupPluginBabelHelpers["extends"]({ "aria-label": iconDescription, className: `${prefix}--file-complete` }, rest, { tabIndex: -1 }), iconDescription && /*#__PURE__*/React__default["default"].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__default["default"].string, /** * Provide a description of the SVG icon to denote file upload status */ iconDescription: PropTypes__default["default"].string, /** * Specify if the file is invalid */ invalid: PropTypes__default["default"].bool, /** * Name of the uploaded file */ name: PropTypes__default["default"].string, /** * Status of the file upload */ status: PropTypes__default["default"].oneOf(['edit', 'complete', 'uploading']), /** * Provide a custom tabIndex value for the `<Filename>` */ tabIndex: PropTypes__default["default"].number }; exports["default"] = Filename;