1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

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 Savolainen 2023-05-02 10:41:45 +03:00 committed by Iku-turso
parent 11ab79b568
commit 65f04b6e38
5 changed files with 38 additions and 76 deletions

View File

@ -26,21 +26,8 @@ export interface ButtonProps extends ButtonHTMLAttributes<any> {
}
export const Button = withTooltip((props: ButtonProps) => {
const {
waiting,
label,
primary,
accent,
plain,
hidden,
active,
big,
round,
outlined,
light,
children,
...btnProps
} = props;
const { waiting, label, primary, accent, plain, hidden, active, big, round, outlined, light, children, ...btnProps } =
props;
if (hidden) {
return null;
@ -70,11 +57,7 @@ export const Button = withTooltip((props: ButtonProps) => {
// render as button
return (
<button
type="button"
{...btnProps}
data-waiting={typeof waiting === "boolean" ? String(waiting) : undefined}
>
<button type="button" {...btnProps} data-waiting={typeof waiting === "boolean" ? String(waiting) : undefined}>
{label}
{children}
</button>

View File

@ -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 {

View File

@ -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,
});
});
});
});

View File

@ -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" />,
);
});

View File

@ -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 = {