UNPKG

@yandex/ui

Version:

Yandex UI components

39 lines (38 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Link = exports.cnLink = void 0; var tslib_1 = require("tslib"); var react_1 = require("react"); var classname_1 = require("@bem-react/classname"); require("./Link.css"); exports.cnLink = classname_1.cn('Link'); /** * Компонент для создания ссылок. * @param {ILinkProps} props */ 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 = tslib_1.__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 react_1.createElement(Component, Object.assign(props, { 'aria-disabled': disabled, className: exports.cnLink(null, [props.className]), ref: innerRef || controlRef, rel: rel, role: role, tabIndex: disabled ? -1 : props.tabIndex, }), children); }; exports.Link = Link; exports.Link.displayName = exports.cnLink();