UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

30 lines (29 loc) 919 B
import * as React from 'react'; import cx from 'classnames'; import { Box } from '../../utils/index.js'; import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden.js'; import { TextContext } from './Text.js'; export const Anchor = React.forwardRef((props, forwardedRef) => { let isInsideText = React.useContext(TextContext); let { isExternal, underline = isInsideText, children, ...rest } = props; return React.createElement( Box, { as: 'a', 'data-iui-underline': underline ? 'true' : void 0, ...rest, ref: forwardedRef, className: cx( 'iui-anchor', { 'iui-anchor-external': isExternal, }, props.className, ), }, children, '_blank' === props.target && React.createElement(VisuallyHidden, null, ' (opens in new tab)'), ); }); if ('development' === process.env.NODE_ENV) Anchor.displayName = 'Anchor';