chore: Fix code style

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala authored and Iku-turso committed 2023-05-03 09:31:24 +03:00
1 parent 11ab79b568
commit 65f04b6e38
5 files changed
+38 -76

No files matched your search

@@ -115,8 +115,7 @@ export const computeNextPosition = ({
tooltipBounds,
targetBounds,
});
const fitsToWindow =
left >= 0 && top >= 0 && right <= viewportWidth && bottom <= viewportHeight;
const fitsToWindow = left >= 0 && top >= 0 && right <= viewportWidth && bottom <= viewportHeight;
if (fitsToWindow) {
return {
@@ -11,9 +11,7 @@ import React from "react";
import { computeNextPosition, RectangleDimensions } from "./helpers";
import { Tooltip, TooltipPosition } from "./tooltip";
const getRectangle = (
parts: Omit<RectangleDimensions, "width" | "height">,
): RectangleDimensions => {
const getRectangle = (parts: Omit<RectangleDimensions, "width" | "height">): RectangleDimensions => {
assert(parts.right >= parts.left);
assert(parts.bottom >= parts.top);
@@ -382,33 +380,30 @@ describe("computeNextPosition technical tests", () => {
TooltipPosition.TOP_LEFT,
TooltipPosition.BOTTOM_RIGHT,
TooltipPosition.BOTTOM_LEFT,
])(
"computes to the %p if there is space and it is specified as a preferred position",
(position) => {
expect(
computeNextPosition({
preferredPositions: position,
offset: 10,
target: {
getBoundingClientRect: () =>
getRectangle({
top: 50,
left: 50,
bottom: 100,
right: 100,
}),
},
tooltip: {
getBoundingClientRect: () => ({
height: 20,
width: 20,
])("computes to the %p if there is space and it is specified as a preferred position", (position) => {
expect(
computeNextPosition({
preferredPositions: position,
offset: 10,
target: {
getBoundingClientRect: () =>
getRectangle({
top: 50,
left: 50,
bottom: 100,
right: 100,
}),
},
}),
).toMatchObject({
position,
});
},
);
},
tooltip: {
getBoundingClientRect: () => ({
height: 20,
width: 20,
}),
},
}),
).toMatchObject({
position,
});
});
});
});
@@ -16,14 +16,12 @@ type MyComponentProps = {
"data-testid"?: string;
};
const MyComponent = withTooltip(
({ text, "data-testid": testId, id, children }: MyComponentProps) => (
<div id={id} data-testid={testId}>
{text}
{children}
</div>
),
);
const MyComponent = withTooltip(({ text, "data-testid": testId, id, children }: MyComponentProps) => (
<div id={id} data-testid={testId}>
{text}
{children}
</div>
));
describe("withTooltip tests", () => {
it("does not render a tooltip when not specified", () => {
@@ -42,9 +40,7 @@ describe("withTooltip tests", () => {
let result: RenderResult;
beforeEach(() => {
result = render(
<MyComponent text="foobar" data-testid="my-test-id" tooltip="my-tooltip" id="bat" />,
);
result = render(<MyComponent text="foobar" data-testid="my-test-id" tooltip="my-tooltip" id="bat" />);
});
it("renders", () => {
@@ -71,12 +67,7 @@ describe("withTooltip tests", () => {
beforeEach(() => {
result = render(
<MyComponent
text="foobar"
data-testid="my-test-id"
tooltip={{ children: "my-tooltip" }}
id="bat"
/>,
<MyComponent text="foobar" data-testid="my-test-id" tooltip={{ children: "my-tooltip" }} id="bat" />,
);
});
@@ -32,13 +32,7 @@ export function withTooltip<TargetProps>(
const [defaultTooltipId] = useState(uniqueId("tooltip_target_"));
let { id: targetId, children: targetChildren } = props;
const {
tooltip,
tooltipOverrideDisabled,
id: _unusedId,
children: _unusedTargetChildren,
...targetProps
} = props;
const { tooltip, tooltipOverrideDisabled, id: _unusedId, children: _unusedTargetChildren, ...targetProps } = props;
if (tooltip) {
const tooltipProps: TooltipProps = {