chore: icon cleanup (#13770)

Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-04-03 23:23:57 +00:00
1 parent 7421cea0da
commit 3f02de8214
294 files changed
+3161 -1715

No files matched your search

+31 -25
View File
@@ -5,10 +5,8 @@ import Link from "next/link";
import React, { forwardRef } from "react";
import classNames from "@calcom/lib/classNames";
import type { SVGComponent } from "@calcom/types/SVGComponent";
import type { LucideIcon } from "@calcom/ui/components/icon";
import { Plus } from "../icon";
import { Icon, type IconName } from "../..";
import { Tooltip } from "../tooltip";
type InferredVariantProps = VariantProps<typeof buttonClasses>;
@@ -18,9 +16,10 @@ export type ButtonBaseProps = {
/** Action that happens when the button is clicked */
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
/**Left aligned icon*/
StartIcon?: SVGComponent | React.ElementType | LucideIcon;
CustomStartIcon?: React.ReactNode;
StartIcon?: IconName;
/**Right aligned icon */
EndIcon?: SVGComponent | LucideIcon;
EndIcon?: IconName;
shallow?: boolean;
/**Tool tip used when icon size is set to small */
tooltip?: string;
@@ -129,6 +128,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
tooltipSide = "top",
tooltipOffset = 4,
StartIcon,
CustomStartIcon,
EndIcon,
shallow,
// attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps`
@@ -155,23 +155,28 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
: props.onClick,
},
<>
{StartIcon && (
<>
{variant === "fab" ? (
<>
<StartIcon className="hidden h-4 w-4 stroke-[1.5px] ltr:-ml-1 ltr:mr-2 rtl:-mr-1 rtl:ml-2 md:inline-flex" />
<Plus data-testid="plus" className="inline h-6 w-6 md:hidden" />
</>
) : (
<StartIcon
className={classNames(
variant === "icon" && "h-4 w-4",
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:-ml-1 ltr:mr-2 rtl:-mr-1 rtl:ml-2"
)}
/>
)}
</>
)}
{CustomStartIcon ||
(StartIcon && (
<>
{variant === "fab" ? (
<>
<Icon
name={StartIcon}
className="hidden h-4 w-4 stroke-[1.5px] ltr:-ml-1 ltr:mr-2 rtl:-mr-1 rtl:ml-2 md:inline-flex"
/>
<Icon name="plus" data-testid="plus" className="inline h-6 w-6 md:hidden" />
</>
) : (
<Icon
name={StartIcon}
className={classNames(
variant === "icon" && "h-4 w-4",
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:-ml-1 ltr:mr-2 rtl:-mr-1 rtl:ml-2"
)}
/>
)}
</>
))}
{variant === "fab" ? <span className="hidden md:inline">{props.children}</span> : props.children}
{loading && (
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transform">
@@ -196,11 +201,12 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
<>
{variant === "fab" ? (
<>
<EndIcon className="-mr-1 me-2 ms-2 hidden h-5 w-5 md:inline" />
<Plus data-testid="plus" className="inline h-6 w-6 md:hidden" />
<Icon name={EndIcon} className="-mr-1 me-2 ms-2 hidden h-5 w-5 md:inline" />
<Icon name="plus" data-testid="plus" className="inline h-6 w-6 md:hidden" />
</>
) : (
<EndIcon
<Icon
name={EndIcon}
className={classNames(
"inline-flex",
variant === "icon" && "h-4 w-4",
@@ -1,10 +1,9 @@
import React from "react";
import type { SVGComponent } from "@calcom/types/SVGComponent";
import type { LucideIcon } from "@calcom/ui/components/icon";
import { Icon, type IconName } from "@calcom/ui";
interface LinkIconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
Icon: SVGComponent | LucideIcon;
Icon: IconName;
}
export default function LinkIconButton(props: LinkIconButtonProps) {
@@ -14,7 +13,7 @@ export default function LinkIconButton(props: LinkIconButtonProps) {
type="button"
{...props}
className="text-md hover:bg-emphasis hover:text-emphasis text-default flex items-center rounded-md px-2 py-1 text-sm font-medium">
<props.Icon className="text-subtle h-4 w-4 ltr:mr-2 rtl:ml-2" />
<Icon name={props.Icon} className="text-subtle h-4 w-4 ltr:mr-2 rtl:ml-2" />
{props.children}
</button>
</div>
@@ -71,22 +71,22 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button>Button text</Button>
</Example>
<Example title="Icon left">
<Button StartIcon={Plus}>Button text</Button>
<Button StartIcon="plus">Button text</Button>
</Example>
<Example title="Icon right">
<Button EndIcon={Plus}>Button text</Button>
<Button EndIcon="plus">Button text</Button>
</Example>
</Examples>
<Examples title="Icons">
<Example title="Icon Normal">
<Button StartIcon={X} variant="icon" size="base" color="minimal"></Button>
<Button StartIcon="x" variant="icon" size="base" color="minimal"></Button>
</Example>
<Example title="Icon Small">
<Button StartIcon={X} variant="icon" size="sm" color="minimal"></Button>
<Button StartIcon="x" variant="icon" size="sm" color="minimal"></Button>
</Example>
<Example title="Icon Loading">
<Button StartIcon={X} variant="icon" size="sm" color="minimal" loading></Button>
<Button StartIcon="x" variant="icon" size="sm" color="minimal" loading></Button>
</Example>
</Examples>
@@ -113,7 +113,7 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button color="secondary">Button text</Button>
<Button color="minimal">Button text</Button>
<Button color="destructive">Button text</Button>
<Button color="destructive" variant="icon" StartIcon={X}></Button>
<Button color="destructive" variant="icon" StartIcon="x"></Button>
</VariantRow>
<VariantRow variant="Hover">
<Button className="sb-pseudo--hover">Button text</Button>
@@ -126,7 +126,7 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button className="sb-pseudo--hover" color="destructive">
Button text
</Button>
<Button className="sb-pseudo--hover" color="destructive" variant="icon" StartIcon={X}></Button>
<Button className="sb-pseudo--hover" color="destructive" variant="icon" StartIcon="x"></Button>
</VariantRow>
<VariantRow variant="Focus">
<Button className="sb-pseudo--focus">Button text</Button>
@@ -139,7 +139,7 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button className="sb-pseudo--focus" color="destructive">
Button text
</Button>
<Button className="sb-pseudo--focus" color="destructive" variant="icon" StartIcon={X}></Button>
<Button className="sb-pseudo--focus" color="destructive" variant="icon" StartIcon="x"></Button>
</VariantRow>
<VariantRow variant="Loading">
<Button loading>Button text</Button>
@@ -152,7 +152,7 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button loading color="destructive">
Button text
</Button>
<Button loading color="destructive" variant="icon" StartIcon={X}></Button>
<Button loading color="destructive" variant="icon" StartIcon="x"></Button>
</VariantRow>
<VariantRow variant="Disabled">
<Button disabled>Button text</Button>
@@ -165,7 +165,7 @@ Button are clickable elements that initiates user actions. Labels in the button
<Button disabled color="destructive">
Button text
</Button>
<Button disabled color="minimal" variant="icon" StartIcon={X}></Button>
<Button disabled color="minimal" variant="icon" StartIcon="x"></Button>
</VariantRow>
</VariantsTable>
</Story>
+15 -17
View File
@@ -1,10 +1,8 @@
/* eslint-disable playwright/missing-playwright-await */
import { render, screen, fireEvent } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import { useState } from "react";
import { vi } from "vitest";
import { Plus } from "@calcom/ui/components/icon";
import { Button, buttonClasses } from "./Button";
const observeMock = vi.fn();
@@ -138,43 +136,43 @@ describe("Tests for Button component", () => {
expect(button.tagName).toBe("BUTTON");
});
test("Should render StartIcon and Plus icon if is fab variant", () => {
test("Should render StartIcon and Plus icon if is fab variant", async () => {
render(
<Button variant="fab" StartIcon={Plus} data-testid="start-icon">
<Button variant="fab" StartIcon="plus" data-testid="start-icon">
Test Button
</Button>
);
expect(screen.getByTestId("start-icon")).toBeInTheDocument();
expect(screen.getByTestId("plus")).toBeInTheDocument();
expect(await screen.findByTestId("start-icon")).toBeInTheDocument();
expect(await screen.findByTestId("plus")).toBeInTheDocument();
});
test("Should render just StartIcon if is not fab variant", () => {
test("Should render just StartIcon if is not fab variant", async () => {
render(
<Button StartIcon={Plus} data-testid="start-icon">
<Button StartIcon="plus" data-testid="start-icon">
Test Button
</Button>
);
expect(screen.getByTestId("start-icon")).toBeInTheDocument();
expect(await screen.findByTestId("start-icon")).toBeInTheDocument();
expect(screen.queryByTestId("plus")).not.toBeInTheDocument();
});
test("Should render EndIcon and Plus icon if is fab variant", () => {
test("Should render EndIcon and Plus icon if is fab variant", async () => {
render(
<Button variant="fab" EndIcon={Plus} data-testid="end-icon">
<Button variant="fab" EndIcon="plus" data-testid="end-icon">
Test Button
</Button>
);
expect(screen.getByTestId("end-icon")).toBeInTheDocument();
expect(screen.getByTestId("plus")).toBeInTheDocument();
expect(await screen.findByTestId("end-icon")).toBeInTheDocument();
expect(await screen.findByTestId("plus")).toBeInTheDocument();
});
test("Should render just EndIcon if is not fab variant", () => {
test("Should render just EndIcon if is not fab variant", async () => {
render(
<Button EndIcon={Plus} data-testid="end-icon">
<Button EndIcon="plus" data-testid="end-icon">
Test Button
</Button>
);
expect(screen.getByTestId("end-icon")).toBeInTheDocument();
expect(await screen.findByTestId("end-icon")).toBeInTheDocument();
expect(screen.queryByTestId("plus")).not.toBeInTheDocument();
});