UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

101 lines (92 loc) 3.25 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var cx = require('classnames'); var PropTypes = require('prop-types'); var React = require('react'); var usePrefix = require('../../internal/usePrefix.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); const Link = /*#__PURE__*/React__default["default"].forwardRef(function Link(_ref, ref) { let { children, className: customClassName, href, disabled = false, inline = false, visited = false, renderIcon: Icon, size, target, ...rest } = _ref; const prefix = usePrefix.usePrefix(); const className = cx__default["default"](`${prefix}--link`, customClassName, { [`${prefix}--link--disabled`]: disabled, [`${prefix}--link--inline`]: inline, [`${prefix}--link--visited`]: visited, [`${prefix}--link--${size}`]: size }); const rel = target === '_blank' ? 'noopener' : undefined; const linkProps = { className, rel, target }; // Reference for disabled links: // https://www.scottohara.me/blog/2021/05/28/disabled-links.html if (!disabled) { linkProps.href = href; } else { linkProps.role = 'link'; linkProps['aria-disabled'] = true; } return /*#__PURE__*/React__default["default"].createElement("a", _rollupPluginBabelHelpers["extends"]({ ref: ref }, linkProps, rest), children, !inline && Icon && /*#__PURE__*/React__default["default"].createElement("div", { className: `${prefix}--link__icon` }, /*#__PURE__*/React__default["default"].createElement(Icon, null))); }); Link.displayName = 'Link'; Link.propTypes = { /** * Provide the content for the Link */ children: PropTypes__default["default"].node, /** * Provide a custom className to be applied to the containing `<a>` node */ className: PropTypes__default["default"].string, /** * Specify if the control should be disabled, or not */ disabled: PropTypes__default["default"].bool, /** * Provide the `href` attribute for the `<a>` node */ href: PropTypes__default["default"].string, /** * Specify whether you want the inline version of this control */ inline: PropTypes__default["default"].bool, /** * Optional prop to render an icon next to the link. * Can be a React component class */ // @ts-expect-error - PropTypes are unable to cover this case. renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]), /** * Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option. */ size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg']), /** * Specify whether you want the link to receive visited styles after the link has been clicked */ visited: PropTypes__default["default"].bool }; exports["default"] = Link;