UNPKG

@carbon/react

Version:

React components for the Carbon Design System

69 lines (59 loc) 2.44 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 PropTypes = require('prop-types'); var React = require('react'); var deprecate = require('../../prop-types/deprecate.js'); // First define the component without generics const frFn = React.forwardRef; const Link = frFn((props, ref) => { const { element, as: BaseComponent, // Captured here to prevent it from being passed into the created element. // See https://github.com/carbon-design-system/carbon/issues/3970 // eslint-disable-next-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452 isSideNavExpanded: _isSideNavExpanded, ...rest } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452 const BaseComponentAsAny = BaseComponent ?? element ?? 'a'; return /*#__PURE__*/React.createElement(BaseComponentAsAny, _rollupPluginBabelHelpers.extends({ ref: ref }, rest)); }); /** * Link is a custom component that allows us to supporting rendering elements * other than `a` in our markup. The goal is to allow users to support passing * in their own components to support use-cases like `react-router` or * `@reach/router` */ const LinkPropTypes = { /** * Provide a custom element or component to render the top-level node for the * component. */ as: PropTypes.elementType, /** * The base element to use to build the link. Defaults to `a`, can also accept * alternative tag names or custom components like `Link` from `react-router`. * @deprecated Use `as` instead * */ element: deprecate.deprecate(PropTypes.elementType, 'The `element` prop for `Link` has been deprecated. Please use `as` ' + 'instead. This will be removed in the next major release.'), /** * Property to indicate if the side nav container is open (or not). Use to * keep local state and styling in step with the SideNav expansion state. */ isSideNavExpanded: PropTypes.bool }; Link.displayName = 'Link'; Link.propTypes = LinkPropTypes; exports.LinkPropTypes = LinkPropTypes; exports.default = Link;