Skip to content

Commit

Permalink
refactor: convert tooltip.js to tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
IzStriker committed Dec 12, 2023
1 parent 9badcd3 commit b4cae6b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions packages/desktop-client/src/components/tooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
createRef,
useState,
RefObject,
ReactNode,
} from 'react';
import ReactDOM from 'react-dom';

Check warning on line 9 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import { css } from 'glamor';

Check warning on line 10 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import { styles, theme } from '../style';
import { CSSProperties, styles, theme } from '../style';

Check warning on line 11 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

Import "CSSProperties" is only used as types

// TODO: workout type
export const IntersectionBoundary = createContext({});
export const IntersectionBoundary = createContext<any>(null);

Check warning on line 13 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

export function useTooltip() {
const [isOpen, setIsOpen] = useState<boolean>(false);
Expand Down Expand Up @@ -47,18 +47,27 @@ type TooltipProps = {
position: TooltipPosition;
onClose: () => void;
forceLayout: boolean;
forceTop: number;
ignoreBoundary: boolean;
targetRect: any;

Check warning on line 52 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
offset: number;
style: CSSProperties;
width: number;
children: ReactNode;
};

export class Tooltip extends Component<TooltipProps> {
static contextType = IntersectionBoundary;
declare context: React.ContextType<typeof IntersectionBoundary>;

Check warning on line 61 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

Using default React import is discouraged, please use named exports directly instead
position: TooltipPosition;
contentRef: RefObject<HTMLElement>;
contentRef: RefObject<HTMLDivElement>;
cleanup: () => void;
target: HTMLDivElement;

constructor(props: TooltipProps) {
constructor(props) {
super(props);
this.position = props.position || 'bottom-right';
this.contentRef = createRef<HTMLElement>();
this.contentRef = createRef<HTMLDivElement>();
}

setup() {
Expand Down Expand Up @@ -165,7 +174,7 @@ export class Tooltip extends Component<TooltipProps> {
}

const box = contentEl.getBoundingClientRect();
const anchorEl = this.target.parentNode;
const anchorEl = this.target.parentNode as any;

Check warning on line 177 in packages/desktop-client/src/components/tooltips.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

let anchorRect = targetRect || anchorEl.getBoundingClientRect();

Expand Down Expand Up @@ -260,7 +269,13 @@ export class Tooltip extends Component<TooltipProps> {
}

getStyleForPosition(position, boxRect, anchorRect, containerRect, offset) {
const style = {
const style: {
top?: string;
bottom?: string;
left?: string;
right?: string;
width?: string;
} = {
top: 'inherit',
bottom: 'inherit',
left: 'inherit',
Expand Down

0 comments on commit b4cae6b

Please sign in to comment.