@yandex/ui
Version:
Yandex UI components
112 lines (80 loc) • 38.4 kB
Markdown
# Link
<a href='https://github.yandex-team.ru/search-interfaces/frontend/tree/master/packages/lego-components/src/Link' target='_blank'><img src='https://badger.yandex-team.ru/custom/[Исходники]/[Github
][green]/badge.svg' /></a> <a href='https://search.yandex-team.ru/stsearch?text=Link.ts&facet.queue=ISL&facet.type=bug&facet.status=128' target='_blank'><img src='https://badger.yandex-team.ru/custom/[Известные проблемы]/[Startrek][blue]/badge.svg' /></a>
<!-- description:start -->
Компонент для создания ссылок.
<!-- description:end -->
## Пример использования
Конфигурация темы на уровне проекта:
```ts
// src/lib/theme.ts
import { configureRootTheme } from '@yandex-lego/components/Theme'
import { theme } from '@yandex-lego/components/Theme/presets/default'
configureRootTheme({ theme })
```
Использование с нужным набором модификаторов:
```ts
// src/App.ts
import React from 'react'
import { compose } from '@bem-react/core'
import {
Link as LinkDesktop,
withViewDefault,
} from '-lego/components/Link/desktop'
// Композиция из различных модификаторов
const Link = compose(withViewDefault)(LinkDesktop)
const App = () => (
<Link view="default" href="http://yandex.ru">
Yandex
</Link>
)
```
Использование с полным набором модификаторов:
```ts
// src/App.ts
import React from 'react'
import { Link } from '@yandex-lego/components/Link/desktop/bundle'
const App = () => (
<Link view="default" href="http://yandex.ru">
Yandex
</Link>
)
```
## Примеры
### Вид ссылки
Чтобы изменить вид ссылки, установите свойство `view` в значение `dеfault`.
{{%story::desktop:navigation-link-desktop--view%}}
### Стилевое оформление
Чтобы изменить стилевое оформление ссылки, установите свойство `theme` в одно из следующих значений: `"black"`, `"ghost"`, `"normal"`, `"outer"`, `"pseudo"`, `"strong"`.
{{%story::desktop:navigation-link-desktop--theme%}}
### Псевдоссылка
Чтобы сделать псевдоссылку, установите свойство `pseudo`.
Клик по такой ссылке не вызывает перехода на страницу, указанную в свойстве `href`, а вызывает событие, которое указано в свойстве `onClick`.
Псевдоссылки используются для того, чтобы открыть/скрыть какую-то информацию на странице, например показать всплывающую подсказку.
Для оформления псевдоссылок можно использовать тему `pseudo`.
| Свойство | Тип | Описание |
| ---------- | -------------------------------------------------- | ------------------------------ |
| pseudo? | `false \| true` | Псевдоссылка |
| onKeyDown? | `(event: KeyboardEvent<ContainerElement>) => void` | Обработчик события `onKeyDown` |
{{%story::desktop:navigation-link-desktop--pseudo%}}
### Недоступная ссылка
Чтобы сделать ссылку недоступной, установите свойство `disabled`.
{{%story::desktop:navigation-link-desktop--disabled%}}
## Свойства
<!-- props:start -->
| Свойство | Тип | Описание |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| href? | `string` | Адрес ссылки. Если указано, то компонент будет оформлен тегом `a`, в противном случае — `span`.<br>Значение игнорируется при использовании модификатора `pseudo` |
| disabled? | `false \| true` | Выключение интерактивности ссылки. Состояние, при котором ссылка отображается, но недоступна для действий пользователя |
| innerRef? | `RefObject<ContainerElement>` | Ссылка на корневой DOM-элемент компонента |
| controlRef? | `RefObject<ContainerElement>` | Ссылка на DOM-элемент нативного контрола |
| as? | `"symbol" \| "object" \| "a" \| "abbr" \| "address" \| "area" \| "article" \| "aside" \| "audio" \| "b" \| "base" \| "bdi" \| "bdo" \| "big" \| "blockquote" \| "body" \| "br" \| "button" \| "canvas" \| "caption" \| "cite" \| "code" \| "col" \| "colgroup" \| "data" \| "datalist" \| "dd" \| "del" \| "details" \| "dfn" \| "dialog" \| "div" \| "dl" \| "dt" \| "em" \| "embed" \| "fieldset" \| "figcaption" \| "figure" \| "footer" \| "form" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "head" \| "header" \| "hgroup" \| "hr" \| "html" \| "i" \| "iframe" \| "img" \| "input" \| "ins" \| "kbd" \| "keygen" \| "label" \| "legend" \| "li" \| "link" \| "main" \| "map" \| "mark" \| "menu" \| "menuitem" \| "meta" \| "meter" \| "nav" \| "noindex" \| "noscript" \| "ol" \| "optgroup" \| "option" \| "output" \| "p" \| "param" \| "picture" \| "pre" \| "progress" \| "q" \| "rp" \| "rt" \| "ruby" \| "s" \| "samp" \| "script" \| "section" \| "select" \| "small" \| "source" \| "span" \| "strong" \| "style" \| "sub" \| "summary" \| "sup" \| "table" \| "tbody" \| "td" \| "textarea" \| "tfoot" \| "th" \| "thead" \| "time" \| "title" \| "tr" \| "track" \| "u" \| "ul" \| "var" \| "video" \| "wbr" \| "webview" \| "svg" \| "animate" \| "animateMotion" \| "animateTransform" \| "circle" \| "clipPath" \| "defs" \| "desc" \| "ellipse" \| "feBlend" \| "feColorMatrix" \| "feComponentTransfer" \| "feComposite" \| "feConvolveMatrix" \| "feDiffuseLighting" \| "feDisplacementMap" \| "feDistantLight" \| "feDropShadow" \| "feFlood" \| "feFuncA" \| "feFuncB" \| "feFuncG" \| "feFuncR" \| "feGaussianBlur" \| "feImage" \| "feMerge" \| "feMergeNode" \| "feMorphology" \| "feOffset" \| "fePointLight" \| "feSpecularLighting" \| "feSpotLight" \| "feTile" \| "feTurbulence" \| "filter" \| "foreignObject" \| "g" \| "image" \| "line" \| "linearGradient" \| "marker" \| "mask" \| "metadata" \| "mpath" \| "path" \| "pattern" \| "polygon" \| "polyline" \| "radialGradient" \| "rect" \| "stop" \| "switch" \| "text" \| "textPath" \| "tspan" \| "use" \| "view" \| ComponentClass<any, any> \| FunctionComponent<any>` | Указание для отрисовки компонента |
| className? | `string` | Дополнительный класс |
| children? | `string \| number \| false \| true \| {} \| ReactElement<any, string \| ((props: any) => ReactElement<any, string \| ... \| (new (props: any) => Component<any, any, any>)>) \| (new (props: any) => Component<any, any, any>)> \| ReactNodeArray \| ReactPortal` | Содержимое ссылки |
| title? | `string` | HTML-атрибут `title` |
| target? | `string` | HTML-атрибут `target` |
| rel? | `string` | HTML-атрибут `rel` |
| tabIndex? | `number` | HTML-атрибут `tabIndex`. Определяет последовательность перехода между ссылками при нажатии на кнопку Tab |
| onClick? | `(event: MouseEvent<ContainerElement, MouseEvent>) => void` | Обработчик события клика. |
| role? | `string` | HTML-атрибут `role` |
<!-- props:end -->