|
1 | | -import {useRef} from 'react'; |
2 | 1 | import cn from 'bem-cn-lite'; |
3 | 2 |
|
4 | 3 | import type {TTabletStateInfo} from '../../types/api/tablet'; |
5 | | -import type {ShowTooltipFunction} from '../../types/store/tooltip'; |
6 | 4 | import {getTabletLabel} from '../../utils/constants'; |
7 | 5 | import routes, {createHref} from '../../routes'; |
8 | 6 |
|
| 7 | +import {ContentWithPopup} from '../ContentWithPopup/ContentWithPopup'; |
9 | 8 | import {InternalLink} from '../InternalLink'; |
| 9 | +import {TabletTooltipContent} from '../TooltipsContent'; |
10 | 10 |
|
11 | 11 | import './Tablet.scss'; |
12 | 12 |
|
13 | 13 | const b = cn('tablet'); |
14 | 14 |
|
15 | 15 | interface TabletProps { |
16 | 16 | tablet?: TTabletStateInfo; |
17 | | - onMouseEnter?: (...args: Parameters<ShowTooltipFunction>) => void; |
18 | | - onMouseLeave?: VoidFunction; |
19 | 17 | } |
20 | 18 |
|
21 | | -export const Tablet = ({ |
22 | | - tablet = {}, |
23 | | - onMouseEnter = () => {}, |
24 | | - onMouseLeave = () => {}, |
25 | | -}: TabletProps) => { |
26 | | - const ref = useRef(null); |
27 | | - |
28 | | - const _onTabletMouseEnter = () => { |
29 | | - onMouseEnter(ref.current, tablet, 'tablet'); |
30 | | - }; |
31 | | - |
32 | | - const _onTabletClick = () => { |
33 | | - const {TabletId: id} = tablet; |
34 | | - |
35 | | - if (id) { |
36 | | - onMouseLeave(); |
37 | | - } |
38 | | - }; |
39 | | - |
| 19 | +export const Tablet = ({tablet = {}}: TabletProps) => { |
40 | 20 | const {TabletId: id} = tablet; |
41 | 21 | const status = tablet.Overall?.toLowerCase(); |
42 | 22 |
|
43 | 23 | return ( |
44 | | - <InternalLink |
45 | | - onClick={_onTabletClick} |
46 | | - to={id && createHref(routes.tablet, {id})} |
| 24 | + <ContentWithPopup |
47 | 25 | className={b('wrapper')} |
| 26 | + content={<TabletTooltipContent data={tablet} className={b('popup-content')} />} |
48 | 27 | > |
49 | | - <div |
50 | | - ref={ref} |
51 | | - className={b({status})} |
52 | | - onMouseEnter={_onTabletMouseEnter} |
53 | | - onMouseLeave={onMouseLeave} |
54 | | - > |
55 | | - <div className={b('type')}>{[getTabletLabel(tablet.Type)]}</div> |
56 | | - </div> |
57 | | - </InternalLink> |
| 28 | + <InternalLink to={id && createHref(routes.tablet, {id})}> |
| 29 | + <div className={b({status})}> |
| 30 | + <div className={b('type')}>{[getTabletLabel(tablet.Type)]}</div> |
| 31 | + </div> |
| 32 | + </InternalLink> |
| 33 | + </ContentWithPopup> |
58 | 34 | ); |
59 | 35 | }; |
0 commit comments