UNPKG

@carbon/react

Version:

React components for the Carbon Design System

72 lines (60 loc) 2.58 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'); 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); // First define the component without generics const LinkBase = ({ 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 isSideNavExpanded: _isSideNavExpanded, ...rest }, ref) => { const BaseComponentAsAny = BaseComponent ?? element ?? 'a'; return /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, _rollupPluginBabelHelpers["extends"]({ ref: ref }, rest)); }; // Use forwardRef with the non-generic function const Link = /*#__PURE__*/React__default["default"].forwardRef(LinkBase); /** * 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__default["default"].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["default"](PropTypes__default["default"].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__default["default"].bool }; Link.displayName = 'Link'; Link.propTypes = LinkPropTypes; exports.LinkPropTypes = LinkPropTypes; exports["default"] = Link;