@snack-uikit/link 0.15.9 → 0.15.10-preview-ed010264.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.
package/README.md CHANGED
@@ -29,17 +29,6 @@ import { Link } from '@snack-uikit/link';
29
29
  ### Props
30
30
  | name | type | default value | description |
31
31
  |------|------|---------------|-------------|
32
- | text | `string` | - | Текст ссылки |
33
- | className | `string` | - | CSS-класс |
34
- | href | `string` | # | Ссылка |
35
- | target | `HTMLAttributeAnchorTarget` | _blank | HTML-атрибут target |
36
- | download | `string` | - | HTML-атрибут download |
37
- | onClick | `MouseEventHandler<HTMLAnchorElement>` | - | Колбек обработки клика |
38
- | size | enum Size: `"s"`, `"m"`, `"l"` | s | Размер |
39
- | appearance | enum Appearance: `"invert-neutral"`, `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | primary | Стилизует ссылку для размещения на цветном фоне |
40
- | textMode | enum TextMode: `"default"`, `"accent"`, `"on-accent"` | default | Тип поверхности, на которой размещена ссылка |
41
- | insideText | `boolean` | - | Находится ли ссылка внутри текста (и можно ли её переносить) |
42
- | truncateVariant | "end" \| "middle" | - | Вариант обрезания строки: <br> - `end` - с конца; <br> - `middle` - по середине |
43
32
 
44
33
 
45
34
  [//]: DOCUMENTATION_SECTION_END
@@ -1,20 +1,10 @@
1
- import { AnchorHTMLAttributes, MouseEventHandler } from 'react';
1
+ import { ComponentPropsWithoutRef } from 'react';
2
2
  import { TruncateStringProps } from '@snack-uikit/truncate-string';
3
3
  import { WithSupportProps } from '@snack-uikit/utils';
4
4
  import { Appearance, Size, TextMode } from './types';
5
- export type LinkProps = WithSupportProps<{
5
+ export type BaseProps = WithSupportProps<{
6
6
  /** Текст ссылки */
7
7
  text?: string;
8
- /** CSS-класс */
9
- className?: string;
10
- /** Ссылка */
11
- href?: string;
12
- /** HTML-атрибут target */
13
- target?: AnchorHTMLAttributes<HTMLAnchorElement>['target'];
14
- /** HTML-атрибут download */
15
- download?: string;
16
- /** Колбек обработки клика */
17
- onClick?: MouseEventHandler<HTMLAnchorElement>;
18
8
  /** Размер
19
9
  * @default 's'
20
10
  */
@@ -36,5 +26,8 @@ export type LinkProps = WithSupportProps<{
36
26
  * */
37
27
  truncateVariant?: TruncateStringProps['variant'];
38
28
  }>;
29
+ export type LinkProps<T extends React.ElementType = 'a'> = BaseProps & {
30
+ as?: T;
31
+ } & Omit<ComponentPropsWithoutRef<T>, keyof BaseProps>;
39
32
  /** Компонент ссылка */
40
- export declare function Link({ text, className, href, target, download, onClick, textMode, size, appearance, insideText, truncateVariant, ...rest }: LinkProps): import("react/jsx-runtime").JSX.Element;
33
+ export declare function Link<T extends React.ElementType = 'a'>({ text, className, onClick, textMode, size, appearance, insideText, truncateVariant, as, ...rest }: LinkProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -28,29 +28,35 @@ function Link(_a) {
28
28
  var {
29
29
  text = '',
30
30
  className,
31
- href = '#',
32
- target = '_blank',
33
- download,
34
31
  onClick,
35
32
  textMode = constants_1.TEXT_MODE.Default,
36
33
  size = constants_1.SIZE.S,
37
34
  appearance = constants_1.APPEARANCE.Primary,
38
35
  insideText = false,
39
- truncateVariant
36
+ truncateVariant,
37
+ as
40
38
  } = _a,
41
- rest = __rest(_a, ["text", "className", "href", "target", "download", "onClick", "textMode", "size", "appearance", "insideText", "truncateVariant"]);
42
- return (0, jsx_runtime_1.jsx)("a", Object.assign({
39
+ rest = __rest(_a, ["text", "className", "onClick", "textMode", "size", "appearance", "insideText", "truncateVariant", "as"]);
40
+ const Component = as || 'a';
41
+ let fallbackProps = rest;
42
+ if (Component === 'a') {
43
+ /**
44
+ * Обратно совместимые изменения с предыдущей версией.
45
+ */
46
+ fallbackProps = Object.assign({
47
+ target: constants_1.TARGET.Blank
48
+ }, fallbackProps, (0, utils_1.extractSupportProps)(rest));
49
+ // @ts-expect-error обратно совместимый
50
+ fallbackProps.rel = fallbackProps.target === constants_1.TARGET.Blank ? 'noopener noreferrer' : undefined;
51
+ }
52
+ return (0, jsx_runtime_1.jsx)(Component, Object.assign({
43
53
  className: (0, classnames_1.default)(styles_module_scss_1.default.link, className),
44
- href: href,
45
- target: target,
46
- download: download,
47
54
  onClick: onClick
48
- }, (0, utils_1.extractSupportProps)(rest), {
55
+ }, fallbackProps, {
49
56
  "data-size": size,
50
57
  "data-text-mode": textMode,
51
58
  "data-appearance": appearance,
52
59
  "data-inside-text": insideText || undefined,
53
- rel: target === '_blank' ? 'noopener noreferrer' : undefined,
54
60
  children: insideText ? text : (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
55
61
  text: text,
56
62
  maxLines: 1,
@@ -1,20 +1,10 @@
1
- import { AnchorHTMLAttributes, MouseEventHandler } from 'react';
1
+ import { ComponentPropsWithoutRef } from 'react';
2
2
  import { TruncateStringProps } from '@snack-uikit/truncate-string';
3
3
  import { WithSupportProps } from '@snack-uikit/utils';
4
4
  import { Appearance, Size, TextMode } from './types';
5
- export type LinkProps = WithSupportProps<{
5
+ export type BaseProps = WithSupportProps<{
6
6
  /** Текст ссылки */
7
7
  text?: string;
8
- /** CSS-класс */
9
- className?: string;
10
- /** Ссылка */
11
- href?: string;
12
- /** HTML-атрибут target */
13
- target?: AnchorHTMLAttributes<HTMLAnchorElement>['target'];
14
- /** HTML-атрибут download */
15
- download?: string;
16
- /** Колбек обработки клика */
17
- onClick?: MouseEventHandler<HTMLAnchorElement>;
18
8
  /** Размер
19
9
  * @default 's'
20
10
  */
@@ -36,5 +26,8 @@ export type LinkProps = WithSupportProps<{
36
26
  * */
37
27
  truncateVariant?: TruncateStringProps['variant'];
38
28
  }>;
29
+ export type LinkProps<T extends React.ElementType = 'a'> = BaseProps & {
30
+ as?: T;
31
+ } & Omit<ComponentPropsWithoutRef<T>, keyof BaseProps>;
39
32
  /** Компонент ссылка */
40
- export declare function Link({ text, className, href, target, download, onClick, textMode, size, appearance, insideText, truncateVariant, ...rest }: LinkProps): import("react/jsx-runtime").JSX.Element;
33
+ export declare function Link<T extends React.ElementType = 'a'>({ text, className, onClick, textMode, size, appearance, insideText, truncateVariant, as, ...rest }: LinkProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -13,10 +13,20 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { TruncateString } from '@snack-uikit/truncate-string';
15
15
  import { extractSupportProps } from '@snack-uikit/utils';
16
- import { APPEARANCE, SIZE, TEXT_MODE } from './constants';
16
+ import { APPEARANCE, SIZE, TARGET, TEXT_MODE } from './constants';
17
17
  import styles from './styles.module.css';
18
18
  /** Компонент ссылка */
19
19
  export function Link(_a) {
20
- var { text = '', className, href = '#', target = '_blank', download, onClick, textMode = TEXT_MODE.Default, size = SIZE.S, appearance = APPEARANCE.Primary, insideText = false, truncateVariant } = _a, rest = __rest(_a, ["text", "className", "href", "target", "download", "onClick", "textMode", "size", "appearance", "insideText", "truncateVariant"]);
21
- return (_jsx("a", Object.assign({ className: cn(styles.link, className), href: href, target: target, download: download, onClick: onClick }, extractSupportProps(rest), { "data-size": size, "data-text-mode": textMode, "data-appearance": appearance, "data-inside-text": insideText || undefined, rel: target === '_blank' ? 'noopener noreferrer' : undefined, children: insideText ? text : _jsx(TruncateString, { text: text, maxLines: 1, variant: truncateVariant }) })));
20
+ var { text = '', className, onClick, textMode = TEXT_MODE.Default, size = SIZE.S, appearance = APPEARANCE.Primary, insideText = false, truncateVariant, as } = _a, rest = __rest(_a, ["text", "className", "onClick", "textMode", "size", "appearance", "insideText", "truncateVariant", "as"]);
21
+ const Component = as || 'a';
22
+ let fallbackProps = rest;
23
+ if (Component === 'a') {
24
+ /**
25
+ * Обратно совместимые изменения с предыдущей версией.
26
+ */
27
+ fallbackProps = Object.assign({ target: TARGET.Blank }, fallbackProps, extractSupportProps(rest));
28
+ // @ts-expect-error обратно совместимый
29
+ fallbackProps.rel = fallbackProps.target === TARGET.Blank ? 'noopener noreferrer' : undefined;
30
+ }
31
+ return (_jsx(Component, Object.assign({ className: cn(styles.link, className), onClick: onClick }, fallbackProps, { "data-size": size, "data-text-mode": textMode, "data-appearance": appearance, "data-inside-text": insideText || undefined, children: insideText ? text : _jsx(TruncateString, { text: text, maxLines: 1, variant: truncateVariant }) })));
22
32
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Link",
7
- "version": "0.15.9",
7
+ "version": "0.15.10-preview-ed010264.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -40,5 +40,5 @@
40
40
  "@snack-uikit/utils": "3.7.0",
41
41
  "classnames": "2.5.1"
42
42
  },
43
- "gitHead": "44591f943a79171320e8db3523ec38953ff101d8"
43
+ "gitHead": "8350a95ba0d09b692dd2c78252fe56187b36adcc"
44
44
  }
@@ -1,26 +1,16 @@
1
1
  import cn from 'classnames';
2
- import { AnchorHTMLAttributes, MouseEventHandler } from 'react';
2
+ import { ComponentPropsWithoutRef } from 'react';
3
3
 
4
4
  import { TruncateString, TruncateStringProps } from '@snack-uikit/truncate-string';
5
5
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
6
6
 
7
- import { APPEARANCE, SIZE, TEXT_MODE } from './constants';
7
+ import { APPEARANCE, SIZE, TARGET, TEXT_MODE } from './constants';
8
8
  import styles from './styles.module.scss';
9
9
  import { Appearance, Size, TextMode } from './types';
10
10
 
11
- export type LinkProps = WithSupportProps<{
11
+ export type BaseProps = WithSupportProps<{
12
12
  /** Текст ссылки */
13
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
14
  /** Размер
25
15
  * @default 's'
26
16
  */
@@ -43,36 +33,47 @@ export type LinkProps = WithSupportProps<{
43
33
  truncateVariant?: TruncateStringProps['variant'];
44
34
  }>;
45
35
 
36
+ export type LinkProps<T extends React.ElementType = 'a'> = BaseProps & {
37
+ as?: T;
38
+ } & Omit<ComponentPropsWithoutRef<T>, keyof BaseProps>;
39
+
46
40
  /** Компонент ссылка */
47
- export function Link({
41
+ export function Link<T extends React.ElementType = 'a'>({
48
42
  text = '',
49
43
  className,
50
- href = '#',
51
- target = '_blank',
52
- download,
53
44
  onClick,
54
45
  textMode = TEXT_MODE.Default,
55
46
  size = SIZE.S,
56
47
  appearance = APPEARANCE.Primary,
57
48
  insideText = false,
58
49
  truncateVariant,
50
+ as,
59
51
  ...rest
60
- }: LinkProps) {
52
+ }: LinkProps<T>) {
53
+ const Component = as || 'a';
54
+
55
+ let fallbackProps = rest;
56
+
57
+ if (Component === 'a') {
58
+ /**
59
+ * Обратно совместимые изменения с предыдущей версией.
60
+ */
61
+ fallbackProps = Object.assign({ target: TARGET.Blank }, fallbackProps, extractSupportProps(rest));
62
+ // @ts-expect-error обратно совместимый
63
+ fallbackProps.rel = fallbackProps.target === TARGET.Blank ? 'noopener noreferrer' : undefined;
64
+ }
65
+
61
66
  return (
62
- <a
67
+ <Component
63
68
  className={cn(styles.link, className)}
64
- href={href}
65
- target={target}
66
- download={download}
67
69
  onClick={onClick}
68
- {...extractSupportProps(rest)}
70
+ {...fallbackProps}
69
71
  data-size={size}
70
72
  data-text-mode={textMode}
71
73
  data-appearance={appearance}
72
74
  data-inside-text={insideText || undefined}
73
- rel={target === '_blank' ? 'noopener noreferrer' : undefined}
74
75
  >
75
76
  {insideText ? text : <TruncateString text={text} maxLines={1} variant={truncateVariant} />}
76
- </a>
77
+ </Component>
77
78
  );
78
79
  }