mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-01 13:47:06 +01:00
3c622cd395
If you're thinking about converting a file to TypeScript, you might want to know what files import that file and what files it imports. This commit makes it so that if you click on a box in the visualization, it will draw lines between that box and the other boxes which represent its dependents and dependencies. Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import React, { useEffect, useRef } from 'react';
|
|
import classnames from 'classnames';
|
|
import { Tooltip as ReactTippy } from 'react-tippy';
|
|
import type { ModulePartitionChild } from '../../common/build-module-partitions';
|
|
import type { BoxRect } from './types';
|
|
|
|
export default function Box({
|
|
module,
|
|
register,
|
|
toggleConnectionsFor,
|
|
areConnectionsVisible,
|
|
}: {
|
|
module: ModulePartitionChild;
|
|
register: (id: string, boxRect: BoxRect) => void;
|
|
toggleConnectionsFor: (id: string) => void;
|
|
areConnectionsVisible: boolean;
|
|
}) {
|
|
const isTest = /\.test\.(?:js|tsx?)/u.test(module.id);
|
|
const isStorybookModule = /\.stories\.(?:js|tsx?)/u.test(module.id);
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (ref.current?.offsetParent) {
|
|
const rect = ref.current.getBoundingClientRect();
|
|
const offsetParentRect = ref.current.offsetParent.getBoundingClientRect();
|
|
const top = rect.top - offsetParentRect.top;
|
|
const left = rect.left - offsetParentRect.left;
|
|
const centerX = left + rect.width / 2;
|
|
const centerY = top + rect.height / 2;
|
|
register(module.id, {
|
|
moduleId: module.id,
|
|
top,
|
|
left,
|
|
width: rect.width,
|
|
height: rect.height,
|
|
centerX,
|
|
centerY,
|
|
});
|
|
}
|
|
}, [ref]);
|
|
|
|
const onClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
event.preventDefault();
|
|
toggleConnectionsFor(module.id);
|
|
};
|
|
|
|
return (
|
|
<ReactTippy
|
|
title={module.id}
|
|
arrow={true}
|
|
animation="fade"
|
|
duration={250}
|
|
className="module__tooltipped"
|
|
style={{ display: 'block' }}
|
|
>
|
|
<div
|
|
ref={ref}
|
|
onClick={onClick}
|
|
className={classnames('module', {
|
|
'module--has-been-converted': module.hasBeenConverted,
|
|
'module--to-be-converted': !module.hasBeenConverted,
|
|
'module--test': isTest,
|
|
'module--storybook': isStorybookModule,
|
|
'module--active': areConnectionsVisible,
|
|
})}
|
|
/>
|
|
</ReactTippy>
|
|
);
|
|
}
|