UNPKG

@yandex/ui

Version:

Yandex UI components

35 lines (34 loc) 1.55 kB
import { __rest } from "tslib"; import { createElement, } from 'react'; import { cn } from '@bem-react/classname'; import './Link.css'; export var cnLink = cn('Link'); /** * Компонент для создания ссылок. * @param {ILinkProps} props */ export var Link = function (_a) { var AsComponent = _a.as, children = _a.children, controlRef = _a.controlRef, disabled = _a.disabled, innerRef = _a.innerRef, role = _a.role, // Извлекаем свойства, т.к. они не нужны на DOM узле // FIXME: https://github.com/bem/bem-react/issues/381 // @ts-ignore _pseudo = _a.pseudo, // @ts-ignore _view = _a.view, props = __rest(_a, ["as", "children", "controlRef", "disabled", "innerRef", "role", "pseudo", "view"]); var Component = AsComponent || (props.href ? 'a' : 'span'); var rel = props.rel; if (props.target === '_blank' && rel !== undefined && rel.indexOf('noopener') === -1) { // Пользовательский атрибут имеет больший приоритет. rel = rel + " noopener"; } // PERF: Не используем TSX, чтобы избежать лишнего клонирования props. return createElement(Component, Object.assign(props, { 'aria-disabled': disabled, className: cnLink(null, [props.className]), ref: innerRef || controlRef, rel: rel, role: role, tabIndex: disabled ? -1 : props.tabIndex, }), children); }; Link.displayName = cnLink();