kamotive_ui 1.2.25 → 1.2.26
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.
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import styles from './Link.module.css';
|
|
4
4
|
import { Typography } from '../Typography/Typography';
|
|
5
5
|
import { ETypographyVariants } from '../Typography/enums';
|
|
6
6
|
import { Tooltip } from '../Tooltip/Tooltip';
|
|
7
|
-
export const Link = ({ href, children, title, className, style, underline = 'hover', variant = ETypographyVariants.Body1, color = 'var(--text-dark)', maxWidth, }) => {
|
|
8
|
-
const stylesUnderline = underline === 'hover'
|
|
7
|
+
export const Link = ({ href, onClick, children, title, className, style, underline = 'hover', variant = ETypographyVariants.Body1, color = 'var(--text-dark)', maxWidth, size, widthInPixels, }) => {
|
|
8
|
+
const stylesUnderline = underline === 'hover' ? styles.linkHover : underline === 'none' ? styles.linkNone : '';
|
|
9
9
|
const stylesTooltipWidth = maxWidth ? { maxWidth: maxWidth } : {};
|
|
10
|
+
const textRef = useRef(null);
|
|
11
|
+
const [measuredSize, setMeasuredSize] = useState(0);
|
|
10
12
|
const linkStyle = Object.assign(Object.assign({}, style), { color: color, textDecorationColor: color });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
useLayoutEffect(() => {
|
|
14
|
+
if (!size && textRef.current) {
|
|
15
|
+
const textWidth = textRef.current.scrollWidth;
|
|
16
|
+
setMeasuredSize(textWidth);
|
|
17
|
+
}
|
|
18
|
+
}, [children, size, variant]);
|
|
19
|
+
const actualSize = size || measuredSize;
|
|
20
|
+
const isTooltipVisible = useMemo(() => {
|
|
21
|
+
if (!actualSize || !widthInPixels) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const shouldShow = actualSize > widthInPixels;
|
|
25
|
+
return shouldShow;
|
|
26
|
+
}, [actualSize, widthInPixels, size]);
|
|
27
|
+
const linkContent = (React.createElement(Typography, { variant: variant, color: color }, children));
|
|
28
|
+
const link = onClick ? (React.createElement("div", { onClick: onClick, className: classNames(styles.link, stylesUnderline, isTooltipVisible && styles.tooltipStyle, className), style: Object.assign(Object.assign({}, linkStyle), stylesTooltipWidth) },
|
|
29
|
+
!size && (React.createElement("div", { ref: textRef, style: {
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
visibility: 'hidden',
|
|
32
|
+
height: 0,
|
|
33
|
+
overflow: 'hidden',
|
|
34
|
+
whiteSpace: 'nowrap',
|
|
35
|
+
pointerEvents: 'none',
|
|
36
|
+
} }, linkContent)),
|
|
37
|
+
linkContent)) : (React.createElement("a", { href: href, title: title, className: classNames(styles.link, stylesUnderline, isTooltipVisible && styles.tooltipStyle, className), style: Object.assign(Object.assign({}, linkStyle), stylesTooltipWidth) },
|
|
38
|
+
!size && (React.createElement("div", { ref: textRef, style: {
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
visibility: 'hidden',
|
|
41
|
+
height: 0,
|
|
42
|
+
overflow: 'hidden',
|
|
43
|
+
whiteSpace: 'nowrap',
|
|
44
|
+
pointerEvents: 'none',
|
|
45
|
+
} }, linkContent)),
|
|
46
|
+
linkContent));
|
|
47
|
+
return isTooltipVisible ? (React.createElement(Tooltip, { key: `${size}-${widthInPixels}`, label: children, opacity: 0.4, displayDelay: 0, style: { maxWidth: '500px' } }, link)) : (link);
|
|
14
48
|
};
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
.link {
|
|
2
|
+
cursor: pointer;
|
|
3
|
+
}
|
|
1
4
|
.linkHover {
|
|
2
|
-
|
|
5
|
+
text-decoration: none;
|
|
3
6
|
}
|
|
4
7
|
|
|
5
8
|
.linkHover:hover {
|
|
6
|
-
|
|
9
|
+
text-decoration: underline;
|
|
10
|
+
}
|
|
11
|
+
.linkNone {
|
|
12
|
+
text-decoration: none;
|
|
13
|
+
}
|
|
14
|
+
.linkNone:hover {
|
|
15
|
+
text-decoration: none;
|
|
7
16
|
}
|
|
8
17
|
|
|
9
18
|
.tooltipStyle {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
text-overflow: ellipsis;
|
|
22
|
+
cursor: context-menu;
|
|
23
|
+
display: inline-block;
|
|
15
24
|
}
|
|
16
|
-
|
package/dist/types/index.d.ts
CHANGED
|
@@ -619,7 +619,9 @@ export interface CommentProps {
|
|
|
619
619
|
}
|
|
620
620
|
export interface LinkProps {
|
|
621
621
|
/**Гипертекстовая ссылка */
|
|
622
|
-
href
|
|
622
|
+
href?: string;
|
|
623
|
+
/** Обработчик клика */
|
|
624
|
+
onClick?: () => void;
|
|
623
625
|
/** Дочерние элементы */
|
|
624
626
|
children: ReactNode;
|
|
625
627
|
/**Заголовок, содержащий дополнительную информацию о ссылке */
|
|
@@ -629,11 +631,14 @@ export interface LinkProps {
|
|
|
629
631
|
/** Стили передаваемые напрямую */
|
|
630
632
|
style?: CSSProperties;
|
|
631
633
|
/**Подчеркивание */
|
|
632
|
-
underline?: 'hover' | 'underline';
|
|
634
|
+
underline?: 'hover' | 'underline' | 'none';
|
|
633
635
|
/** Вариант шрифта */
|
|
634
636
|
variant?: `${ETypographyVariants}`;
|
|
635
637
|
/** Цвет текста */
|
|
636
638
|
color?: CSSProperties['color'];
|
|
637
639
|
/**Максимальная ширина - нужна для отображения тултипа */
|
|
638
640
|
maxWidth?: string;
|
|
641
|
+
/** Размер - для отображения тултипа */
|
|
642
|
+
size?: number;
|
|
643
|
+
widthInPixels?: number;
|
|
639
644
|
}
|