@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
91 lines (86 loc) • 2.55 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React__default from 'react';
import { usePrefix } from '../../internal/usePrefix.js';
const Link = /*#__PURE__*/React__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();
const className = cx(`${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.createElement("a", _extends({
ref: ref
}, linkProps, rest), children, !inline && Icon && /*#__PURE__*/React__default.createElement("div", {
className: `${prefix}--link__icon`
}, /*#__PURE__*/React__default.createElement(Icon, null)));
});
Link.displayName = 'Link';
Link.propTypes = {
/**
* Provide the content for the Link
*/
children: PropTypes.node,
/**
* Provide a custom className to be applied to the containing `<a>` node
*/
className: PropTypes.string,
/**
* Specify if the control should be disabled, or not
*/
disabled: PropTypes.bool,
/**
* Provide the `href` attribute for the `<a>` node
*/
href: PropTypes.string,
/**
* Specify whether you want the inline version of this control
*/
inline: PropTypes.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.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
*/
size: PropTypes.oneOf(['sm', 'md', 'lg']),
/**
* Specify whether you want the link to receive visited styles after the link has been clicked
*/
visited: PropTypes.bool
};
export { Link as default };