@snack-uikit/link 0.7.1-preview-85c5f47b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export * from './components';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components';
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@snack-uikit/link",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "title": "Link",
7
+ "version": "0.7.1-preview-85c5f47b.0",
8
+ "sideEffects": [
9
+ "*.css",
10
+ "*.woff",
11
+ "*.woff2"
12
+ ],
13
+ "description": "Ссылка, используемая внутри текста",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.js",
16
+ "homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/link",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/cloud-ru-tech/snack-uikit.git",
20
+ "directory": "packages/link"
21
+ },
22
+ "author": "Anna Kozlova <apkozlova@cloud.ru>",
23
+ "contributors": [
24
+ "Anna Kozlova <apkozlova@cloud.ru>"
25
+ ],
26
+ "files": [
27
+ "dist",
28
+ "src",
29
+ "./CHANGELOG.md",
30
+ "./LICENSE"
31
+ ],
32
+ "license": "Apache-2.0",
33
+ "scripts": {},
34
+ "dependencies": {
35
+ "@snack-uikit/icons": "0.18.2-preview-85c5f47b.0",
36
+ "@snack-uikit/truncate-string": "0.2.17-preview-85c5f47b.0",
37
+ "@snack-uikit/utils": "2.0.2-preview-85c5f47b.0",
38
+ "classnames": "2.3.2"
39
+ },
40
+ "gitHead": "6a7eef41d780d945f64f791448eaa72b9e0ae72d"
41
+ }
@@ -0,0 +1,70 @@
1
+ import cn from 'classnames';
2
+ import { AnchorHTMLAttributes, MouseEventHandler } from 'react';
3
+
4
+ import { ArrowLinksSVG } from '@snack-uikit/icons';
5
+ import { TruncateString } from '@snack-uikit/truncate-string';
6
+ import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
7
+
8
+ import { OnColor, OnSurface, Size, Target } from './constants';
9
+ import styles from './styles.module.scss';
10
+
11
+ export type LinkProps = WithSupportProps<{
12
+ /** Текст ссылки */
13
+ text?: string;
14
+ /** CSS-класс */
15
+ className?: string;
16
+ /** Ссылка */
17
+ href?: string;
18
+ /** HTML-атрибут target */
19
+ target?: AnchorHTMLAttributes<HTMLAnchorElement>['target'];
20
+ /** HTML-атрибут download */
21
+ download?: string;
22
+ /** Колбек обработки клика */
23
+ onClick?: MouseEventHandler<HTMLAnchorElement>;
24
+ /** Размер */
25
+ size?: Size;
26
+ /** Ведет ли ссылка на внешний ресурс (добавляет иконку если true) */
27
+ external?: boolean;
28
+ /** Стилизует ссылку для размещения на цветном фоне */
29
+ onColor?: OnColor;
30
+ /** Тип поверхности, на которой размещена ссылка */
31
+ onSurface?: OnSurface;
32
+ }>;
33
+
34
+ /** Компонент ссылка */
35
+ export function Link({
36
+ text = '',
37
+ className,
38
+ href = '#',
39
+ target = Target.Blank,
40
+ download,
41
+ onClick,
42
+ onSurface = OnSurface.Background,
43
+ size = Size.S,
44
+ external,
45
+ onColor = OnColor.Primary,
46
+ ...rest
47
+ }: LinkProps) {
48
+ return (
49
+ <a
50
+ className={cn(styles.link, className)}
51
+ href={href}
52
+ target={target}
53
+ download={download}
54
+ onClick={onClick}
55
+ {...extractSupportProps(rest)}
56
+ data-size={size}
57
+ data-on-surface={onSurface}
58
+ data-color={onColor}
59
+ rel={target === Target.Blank ? 'noopener noreferrer' : undefined}
60
+ >
61
+ <TruncateString text={text} maxLines={1} />
62
+ {external && <ArrowLinksSVG data-test-id='link__external-icon' className={styles.icon} />}
63
+ </a>
64
+ );
65
+ }
66
+
67
+ Link.sizes = Size;
68
+ Link.targets = Target;
69
+ Link.onColors = OnColor;
70
+ Link.onSurfaces = OnSurface;
@@ -0,0 +1,31 @@
1
+ export enum OnColor {
2
+ InvertNeutral = 'invert-neutral',
3
+ Neutral = 'neutral',
4
+ Primary = 'primary',
5
+ Red = 'red',
6
+ Orange = 'orange',
7
+ Yellow = 'yellow',
8
+ Green = 'green',
9
+ Blue = 'blue',
10
+ Violet = 'violet',
11
+ Pink = 'pink',
12
+ }
13
+
14
+ export enum Size {
15
+ S = 's',
16
+ M = 'm',
17
+ L = 'l',
18
+ }
19
+
20
+ export enum Target {
21
+ Self = '_self',
22
+ Blank = '_blank',
23
+ Parent = '_parent',
24
+ Top = '_top',
25
+ }
26
+
27
+ export enum OnSurface {
28
+ Background = 'background',
29
+ Decor = 'decor',
30
+ Accent = 'accent',
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Link';
2
+ export { OnColor } from './constants';
@@ -0,0 +1,91 @@
1
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-link';
2
+ @import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
3
+
4
+ $sizes: 's', 'm', 'l';
5
+ $colors: 'invert-neutral','neutral', 'primary', 'red', 'orange', 'blue', 'violet', 'pink', 'yellow', 'green';
6
+ $on-surfaces: 'background', 'decor', 'accent';
7
+ $icon-sizes: (
8
+ 's': $icon-xs,
9
+ 'm': $icon-s,
10
+ 'l': $icon-s,
11
+ );
12
+
13
+ .link {
14
+ cursor: pointer;
15
+
16
+ display: inline-flex;
17
+ align-items: center;
18
+
19
+ width: fit-content;
20
+ max-width: 100%;
21
+
22
+ text-decoration: none;
23
+ text-decoration-skip-ink: none;
24
+
25
+ @each $on-surface in $on-surfaces {
26
+ &[data-on-surface='#{$on-surface}'] {
27
+ @each $color in $colors {
28
+ &[data-color='#{$color}'] {
29
+ @if $on-surface == 'accent' {
30
+ color: simple-var($theme-variables, 'sys', $color, 'on-accent');
31
+
32
+ &:hover {
33
+ color: simple-var($theme-variables, 'sys', $color, 'on-accent');
34
+ opacity: $opacity-a080;
35
+ }
36
+ &:focus-visible {
37
+ @include outline-var($container-focused-s);
38
+
39
+ opacity: $opacity-a080;
40
+ outline-color: $sys-available-on-complementary;
41
+ }
42
+ }
43
+
44
+ @else {
45
+ color: simple-var($theme-variables, 'sys', $color, 'accent-default');
46
+
47
+ &:hover {
48
+ color: simple-var($theme-variables, 'sys', $color, 'text-main');
49
+ }
50
+ &:focus-visible {
51
+ @include outline-var($container-focused-s);
52
+
53
+ color: simple-var($theme-variables, 'sys', $color, 'text-main');
54
+
55
+ @if $color == 'invert-neutral' {
56
+ outline-color: $sys-available-on-complementary;
57
+ }
58
+
59
+ @else {
60
+ outline-color: $sys-available-complementary;
61
+ }
62
+ }
63
+ }
64
+
65
+ @each $size in $sizes {
66
+ &[data-size='#{$size}'] {
67
+ @if $on-surface == 'decor' {
68
+ @include composite-var($theme-variables, 'sans', 'body', $size);
69
+ }
70
+
71
+ @else {
72
+ @include composite-var($theme-variables, 'link', 'body', $size);
73
+ }
74
+
75
+ @include composite-var($link, 'container', $size);
76
+
77
+ svg {
78
+ width: simple-var($icon-sizes, $size) !important; /* stylelint-disable-line declaration-no-important */
79
+ height: simple-var($icon-sizes, $size) !important; /* stylelint-disable-line declaration-no-important */
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ .icon {
90
+ flex-shrink: 0;
91
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './components';