UNPKG

@carbon/react

Version:

React components for the Carbon Design System

110 lines (101 loc) 3.55 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 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); // First create the component with basic types const LinkBase = /*#__PURE__*/React__default["default"].forwardRef(({ as: BaseComponent, 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; } const BaseComponentAsAny = BaseComponent ?? 'a'; return /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, _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))); }); const Link = LinkBase; Link.displayName = 'Link'; Link.propTypes = { /** * Provide a custom element or component to render the top-level node for the * component. */ as: PropTypes__default["default"].elementType, /** * 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, /** * A component used to render an icon. */ 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;