@true-engineering/true-react-common-ui-kit 3.40.0 → 3.41.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 +9 -1
- package/dist/components/SmartInput/SmartInput.d.ts +8 -6
- package/dist/components/SmartInput/constants.d.ts +4 -6
- package/dist/components/SmartInput/helpers.d.ts +2 -4
- package/dist/components/SmartInput/types.d.ts +5 -0
- package/dist/true-react-common-ui-kit.js +1081 -940
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1081 -940
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +98 -98
- package/src/components/MoreMenu/MoreMenu.tsx +93 -93
- package/src/components/SmartInput/SmartInput.stories.tsx +52 -51
- package/src/components/SmartInput/SmartInput.tsx +116 -134
- package/src/components/SmartInput/constants.ts +91 -84
- package/src/components/SmartInput/helpers.ts +26 -13
- package/src/components/SmartInput/types.ts +18 -11
- package/src/components/TextWithTooltip/TextWithTooltip.tsx +156 -156
- package/src/components/WithPopup/WithPopup.styles.ts +45 -45
- package/src/components/WithPopup/WithPopup.tsx +184 -184
- package/src/components/WithTooltip/WithTooltip.stories.tsx +56 -56
- package/src/components/WithTooltip/WithTooltip.styles.ts +7 -7
- package/src/components/WithTooltip/WithTooltip.tsx +67 -67
- package/src/components/WithTooltip/index.ts +2 -2
- package/src/components/index.ts +46 -46
- package/src/theme/types.ts +158 -158
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
import { CSSProperties, FC, ReactNode, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { Portal } from 'react-overlays';
|
|
3
|
-
import usePopper, { Modifier, Placement } from 'react-overlays/usePopper';
|
|
4
|
-
import clsx from 'clsx';
|
|
5
|
-
import { addDataTestId } from '@true-engineering/true-react-platform-helpers';
|
|
6
|
-
import { addDataAttributes } from '../../helpers';
|
|
7
|
-
import { useOnClickOutsideWithRef, useTweakStyles } from '../../hooks';
|
|
8
|
-
import { ICommonProps } from '../../types';
|
|
9
|
-
import { ITooltipProps, Tooltip } from '../Tooltip';
|
|
10
|
-
import { useStyles, ITextWithTooltipStyles } from './TextWithTooltip.styles';
|
|
11
|
-
|
|
12
|
-
export interface ITextWithTooltipProps extends ICommonProps<ITextWithTooltipStyles> {
|
|
13
|
-
children: ReactNode;
|
|
14
|
-
tooltipText: ITooltipProps['text'];
|
|
15
|
-
/** @default 'tooltip' */
|
|
16
|
-
tooltipView?: ITooltipProps['view'];
|
|
17
|
-
/** @default 'info' */
|
|
18
|
-
tooltipType?: ITooltipProps['type'];
|
|
19
|
-
/** @default 'top' */
|
|
20
|
-
tooltipPosition?: Placement;
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
/** @default [] */
|
|
23
|
-
tooltipModifiers?: Array<Partial<Modifier<any, any>>>;
|
|
24
|
-
tooltipOffsetOptions?: Record<string, unknown>;
|
|
25
|
-
/** @default 'hover' */
|
|
26
|
-
mouseEventType?: 'hover' | 'click';
|
|
27
|
-
hoverDelay?: number;
|
|
28
|
-
/** @default false */
|
|
29
|
-
isDisabled?: boolean;
|
|
30
|
-
/** @default true */
|
|
31
|
-
shouldRenderInBody?: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** @deprecated Используйте {@link import('../WithTooltip').WithTooltip WithTooltip} */
|
|
35
|
-
export const TextWithTooltip: FC<ITextWithTooltipProps> = ({
|
|
36
|
-
children,
|
|
37
|
-
tooltipText,
|
|
38
|
-
tooltipPosition = 'top',
|
|
39
|
-
tooltipView = 'tooltip',
|
|
40
|
-
tooltipType = 'info',
|
|
41
|
-
tooltipModifiers = [],
|
|
42
|
-
tooltipOffsetOptions,
|
|
43
|
-
isDisabled = false,
|
|
44
|
-
shouldRenderInBody = true,
|
|
45
|
-
mouseEventType = 'hover',
|
|
46
|
-
hoverDelay,
|
|
47
|
-
testId,
|
|
48
|
-
data,
|
|
49
|
-
tweakStyles,
|
|
50
|
-
}) => {
|
|
51
|
-
const classes = useStyles({ theme: tweakStyles });
|
|
52
|
-
|
|
53
|
-
const tweakTooltipStyles = useTweakStyles({
|
|
54
|
-
tweakStyles,
|
|
55
|
-
className: 'tweakTooltip',
|
|
56
|
-
currentComponentName: 'TextWithTooltip',
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
60
|
-
const [tooltipTimeout, setTooltipTimeout] = useState<ReturnType<typeof setTimeout>>();
|
|
61
|
-
|
|
62
|
-
const root = useRef<HTMLDivElement>(null);
|
|
63
|
-
const tooltip = useRef<HTMLDivElement>(null);
|
|
64
|
-
|
|
65
|
-
const hasDelay = hoverDelay !== undefined;
|
|
66
|
-
|
|
67
|
-
const handleMouseEnter = () => {
|
|
68
|
-
if (hasDelay) {
|
|
69
|
-
const timeout = setTimeout(() => {
|
|
70
|
-
setIsTooltipVisible(true);
|
|
71
|
-
}, hoverDelay);
|
|
72
|
-
|
|
73
|
-
setTooltipTimeout(timeout);
|
|
74
|
-
} else {
|
|
75
|
-
setIsTooltipVisible(true);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const handleMouseLeave = () => {
|
|
80
|
-
if (hasDelay) {
|
|
81
|
-
clearTimeout(tooltipTimeout);
|
|
82
|
-
}
|
|
83
|
-
setIsTooltipVisible(false);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
useEffect(() => () => clearTimeout(tooltipTimeout), []);
|
|
87
|
-
|
|
88
|
-
const { styles: popperStyles, attributes } = usePopper(root.current, tooltip.current, {
|
|
89
|
-
enabled: isTooltipVisible,
|
|
90
|
-
placement: tooltipPosition,
|
|
91
|
-
modifiers: [
|
|
92
|
-
{
|
|
93
|
-
name: 'offset',
|
|
94
|
-
options: {
|
|
95
|
-
offset: [0, 6],
|
|
96
|
-
...tooltipOffsetOptions,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
...tooltipModifiers,
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
useOnClickOutsideWithRef(
|
|
104
|
-
tooltip,
|
|
105
|
-
() => {
|
|
106
|
-
if (mouseEventType === 'click') {
|
|
107
|
-
setIsTooltipVisible(false);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
root,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const props =
|
|
114
|
-
mouseEventType === 'click'
|
|
115
|
-
? {
|
|
116
|
-
onClick: () => setIsTooltipVisible(true),
|
|
117
|
-
}
|
|
118
|
-
: {
|
|
119
|
-
onMouseEnter: handleMouseEnter,
|
|
120
|
-
onMouseLeave: handleMouseLeave,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const shouldShowTooltip = tooltipText !== undefined && tooltipText !== null && !isDisabled;
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
<div
|
|
127
|
-
className={clsx(
|
|
128
|
-
classes.root,
|
|
129
|
-
mouseEventType === 'click' && shouldShowTooltip && classes.clickable,
|
|
130
|
-
)}
|
|
131
|
-
{...(shouldShowTooltip ? props : undefined)}
|
|
132
|
-
{...addDataTestId(testId)}
|
|
133
|
-
{...addDataAttributes(data)}
|
|
134
|
-
ref={root}
|
|
135
|
-
>
|
|
136
|
-
{shouldShowTooltip && (
|
|
137
|
-
<Portal container={shouldRenderInBody ? document.body : root.current}>
|
|
138
|
-
<div
|
|
139
|
-
className={classes.tooltip}
|
|
140
|
-
style={popperStyles.popper as CSSProperties}
|
|
141
|
-
{...attributes.popper}
|
|
142
|
-
ref={tooltip}
|
|
143
|
-
>
|
|
144
|
-
<Tooltip
|
|
145
|
-
view={tooltipView}
|
|
146
|
-
type={tooltipType}
|
|
147
|
-
text={tooltipText}
|
|
148
|
-
tweakStyles={tweakTooltipStyles}
|
|
149
|
-
/>
|
|
150
|
-
</div>
|
|
151
|
-
</Portal>
|
|
152
|
-
)}
|
|
153
|
-
{children}
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
1
|
+
import { CSSProperties, FC, ReactNode, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Portal } from 'react-overlays';
|
|
3
|
+
import usePopper, { Modifier, Placement } from 'react-overlays/usePopper';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { addDataTestId } from '@true-engineering/true-react-platform-helpers';
|
|
6
|
+
import { addDataAttributes } from '../../helpers';
|
|
7
|
+
import { useOnClickOutsideWithRef, useTweakStyles } from '../../hooks';
|
|
8
|
+
import { ICommonProps } from '../../types';
|
|
9
|
+
import { ITooltipProps, Tooltip } from '../Tooltip';
|
|
10
|
+
import { useStyles, ITextWithTooltipStyles } from './TextWithTooltip.styles';
|
|
11
|
+
|
|
12
|
+
export interface ITextWithTooltipProps extends ICommonProps<ITextWithTooltipStyles> {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
tooltipText: ITooltipProps['text'];
|
|
15
|
+
/** @default 'tooltip' */
|
|
16
|
+
tooltipView?: ITooltipProps['view'];
|
|
17
|
+
/** @default 'info' */
|
|
18
|
+
tooltipType?: ITooltipProps['type'];
|
|
19
|
+
/** @default 'top' */
|
|
20
|
+
tooltipPosition?: Placement;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
/** @default [] */
|
|
23
|
+
tooltipModifiers?: Array<Partial<Modifier<any, any>>>;
|
|
24
|
+
tooltipOffsetOptions?: Record<string, unknown>;
|
|
25
|
+
/** @default 'hover' */
|
|
26
|
+
mouseEventType?: 'hover' | 'click';
|
|
27
|
+
hoverDelay?: number;
|
|
28
|
+
/** @default false */
|
|
29
|
+
isDisabled?: boolean;
|
|
30
|
+
/** @default true */
|
|
31
|
+
shouldRenderInBody?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @deprecated Используйте {@link import('../WithTooltip').WithTooltip WithTooltip} */
|
|
35
|
+
export const TextWithTooltip: FC<ITextWithTooltipProps> = ({
|
|
36
|
+
children,
|
|
37
|
+
tooltipText,
|
|
38
|
+
tooltipPosition = 'top',
|
|
39
|
+
tooltipView = 'tooltip',
|
|
40
|
+
tooltipType = 'info',
|
|
41
|
+
tooltipModifiers = [],
|
|
42
|
+
tooltipOffsetOptions,
|
|
43
|
+
isDisabled = false,
|
|
44
|
+
shouldRenderInBody = true,
|
|
45
|
+
mouseEventType = 'hover',
|
|
46
|
+
hoverDelay,
|
|
47
|
+
testId,
|
|
48
|
+
data,
|
|
49
|
+
tweakStyles,
|
|
50
|
+
}) => {
|
|
51
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
52
|
+
|
|
53
|
+
const tweakTooltipStyles = useTweakStyles({
|
|
54
|
+
tweakStyles,
|
|
55
|
+
className: 'tweakTooltip',
|
|
56
|
+
currentComponentName: 'TextWithTooltip',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
60
|
+
const [tooltipTimeout, setTooltipTimeout] = useState<ReturnType<typeof setTimeout>>();
|
|
61
|
+
|
|
62
|
+
const root = useRef<HTMLDivElement>(null);
|
|
63
|
+
const tooltip = useRef<HTMLDivElement>(null);
|
|
64
|
+
|
|
65
|
+
const hasDelay = hoverDelay !== undefined;
|
|
66
|
+
|
|
67
|
+
const handleMouseEnter = () => {
|
|
68
|
+
if (hasDelay) {
|
|
69
|
+
const timeout = setTimeout(() => {
|
|
70
|
+
setIsTooltipVisible(true);
|
|
71
|
+
}, hoverDelay);
|
|
72
|
+
|
|
73
|
+
setTooltipTimeout(timeout);
|
|
74
|
+
} else {
|
|
75
|
+
setIsTooltipVisible(true);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const handleMouseLeave = () => {
|
|
80
|
+
if (hasDelay) {
|
|
81
|
+
clearTimeout(tooltipTimeout);
|
|
82
|
+
}
|
|
83
|
+
setIsTooltipVisible(false);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
useEffect(() => () => clearTimeout(tooltipTimeout), []);
|
|
87
|
+
|
|
88
|
+
const { styles: popperStyles, attributes } = usePopper(root.current, tooltip.current, {
|
|
89
|
+
enabled: isTooltipVisible,
|
|
90
|
+
placement: tooltipPosition,
|
|
91
|
+
modifiers: [
|
|
92
|
+
{
|
|
93
|
+
name: 'offset',
|
|
94
|
+
options: {
|
|
95
|
+
offset: [0, 6],
|
|
96
|
+
...tooltipOffsetOptions,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
...tooltipModifiers,
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
useOnClickOutsideWithRef(
|
|
104
|
+
tooltip,
|
|
105
|
+
() => {
|
|
106
|
+
if (mouseEventType === 'click') {
|
|
107
|
+
setIsTooltipVisible(false);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
root,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const props =
|
|
114
|
+
mouseEventType === 'click'
|
|
115
|
+
? {
|
|
116
|
+
onClick: () => setIsTooltipVisible(true),
|
|
117
|
+
}
|
|
118
|
+
: {
|
|
119
|
+
onMouseEnter: handleMouseEnter,
|
|
120
|
+
onMouseLeave: handleMouseLeave,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const shouldShowTooltip = tooltipText !== undefined && tooltipText !== null && !isDisabled;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
className={clsx(
|
|
128
|
+
classes.root,
|
|
129
|
+
mouseEventType === 'click' && shouldShowTooltip && classes.clickable,
|
|
130
|
+
)}
|
|
131
|
+
{...(shouldShowTooltip ? props : undefined)}
|
|
132
|
+
{...addDataTestId(testId)}
|
|
133
|
+
{...addDataAttributes(data)}
|
|
134
|
+
ref={root}
|
|
135
|
+
>
|
|
136
|
+
{shouldShowTooltip && (
|
|
137
|
+
<Portal container={shouldRenderInBody ? document.body : root.current}>
|
|
138
|
+
<div
|
|
139
|
+
className={classes.tooltip}
|
|
140
|
+
style={popperStyles.popper as CSSProperties}
|
|
141
|
+
{...attributes.popper}
|
|
142
|
+
ref={tooltip}
|
|
143
|
+
>
|
|
144
|
+
<Tooltip
|
|
145
|
+
view={tooltipView}
|
|
146
|
+
type={tooltipType}
|
|
147
|
+
text={tooltipText}
|
|
148
|
+
tweakStyles={tweakTooltipStyles}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
</Portal>
|
|
152
|
+
)}
|
|
153
|
+
{children}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { createThemedStyles, ITweakStyles } from '../../theme';
|
|
2
|
-
|
|
3
|
-
export const useStyles = createThemedStyles('WithPopup', {
|
|
4
|
-
trigger: {
|
|
5
|
-
width: 'fit-content',
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
clickable: {
|
|
9
|
-
cursor: 'pointer',
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
active: {},
|
|
13
|
-
|
|
14
|
-
disabled: {
|
|
15
|
-
cursor: 'auto',
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
popup: {
|
|
19
|
-
zIndex: 5,
|
|
20
|
-
outline: 'none',
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
animationEnd: {},
|
|
24
|
-
|
|
25
|
-
animationStart: {},
|
|
26
|
-
|
|
27
|
-
'dropdown-initial': {
|
|
28
|
-
extend: 'animationEnd',
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
'dropdown-open': {
|
|
32
|
-
extend: 'animationStart',
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
'dropdown-close': {
|
|
36
|
-
visibility: 'hidden',
|
|
37
|
-
extend: 'animationEnd',
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
'dropdown-unmounted': {
|
|
41
|
-
extend: 'animationEnd',
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
export type IWithPopupStyles = ITweakStyles<typeof useStyles>;
|
|
1
|
+
import { createThemedStyles, ITweakStyles } from '../../theme';
|
|
2
|
+
|
|
3
|
+
export const useStyles = createThemedStyles('WithPopup', {
|
|
4
|
+
trigger: {
|
|
5
|
+
width: 'fit-content',
|
|
6
|
+
},
|
|
7
|
+
|
|
8
|
+
clickable: {
|
|
9
|
+
cursor: 'pointer',
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
active: {},
|
|
13
|
+
|
|
14
|
+
disabled: {
|
|
15
|
+
cursor: 'auto',
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
popup: {
|
|
19
|
+
zIndex: 5,
|
|
20
|
+
outline: 'none',
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
animationEnd: {},
|
|
24
|
+
|
|
25
|
+
animationStart: {},
|
|
26
|
+
|
|
27
|
+
'dropdown-initial': {
|
|
28
|
+
extend: 'animationEnd',
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
'dropdown-open': {
|
|
32
|
+
extend: 'animationStart',
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
'dropdown-close': {
|
|
36
|
+
visibility: 'hidden',
|
|
37
|
+
extend: 'animationEnd',
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
'dropdown-unmounted': {
|
|
41
|
+
extend: 'animationEnd',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export type IWithPopupStyles = ITweakStyles<typeof useStyles>;
|