remove close button from TopBanner (#10705)
Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com>
This commit is contained in:
2 files changed
+50
-16
No files matched your search
@@ -1,17 +1,14 @@
|
||||
import classNames from "classnames";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { noop } from "lodash";
|
||||
import type { ComponentType, ReactNode } from "react";
|
||||
|
||||
import type { LucideIcon, LucideProps } from "@calcom/ui/components/icon";
|
||||
import { X, AlertTriangle, Info } from "@calcom/ui/components/icon";
|
||||
import { AlertTriangle, Info } from "@calcom/ui/components/icon";
|
||||
|
||||
export type TopBannerProps = {
|
||||
Icon?: ComponentType<LucideProps> & LucideIcon;
|
||||
text: string;
|
||||
variant?: keyof typeof variantClassName;
|
||||
actions?: ReactNode;
|
||||
onClose?: () => void;
|
||||
};
|
||||
|
||||
const variantClassName = {
|
||||
@@ -26,14 +23,14 @@ const defaultIconProps = {
|
||||
} as LucideProps;
|
||||
|
||||
export function TopBanner(props: TopBannerProps) {
|
||||
const { Icon, variant = "default", text, actions, onClose } = props;
|
||||
const { Icon, variant = "default", text, actions } = props;
|
||||
|
||||
const renderDefaultIconByVariant = () => {
|
||||
switch (variant) {
|
||||
case "error":
|
||||
return <AlertTriangle {...defaultIconProps} />;
|
||||
return <AlertTriangle {...defaultIconProps} data-testid="variant-error" />;
|
||||
case "warning":
|
||||
return <Info {...defaultIconProps} />;
|
||||
return <Info {...defaultIconProps} data-testid="variant-warning" />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -49,19 +46,11 @@ export function TopBanner(props: TopBannerProps) {
|
||||
)}>
|
||||
<div className="flex flex-1 flex-col items-start justify-center gap-2 p-1 lg:flex-row lg:items-center">
|
||||
<p className="text-emphasis flex flex-col items-start justify-center gap-2 text-left font-sans text-sm font-medium leading-4 lg:flex-row lg:items-center">
|
||||
{Icon ? <Icon {...defaultIconProps} /> : defaultIcon}
|
||||
{Icon ? <Icon data-testid="variant-default" {...defaultIconProps} /> : defaultIcon}
|
||||
{text}
|
||||
</p>
|
||||
{actions && <div className="text-sm font-medium">{actions}</div>}
|
||||
</div>
|
||||
{typeof onClose === "function" && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={noop}
|
||||
className="hover:bg-gray-20 text-muted flex items-center rounded-lg p-1.5 text-sm">
|
||||
<X className="text-emphasis h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
|
||||
import { ArrowDown } from "@calcom/ui/components/icon";
|
||||
|
||||
import { TopBanner } from "./TopBanner";
|
||||
|
||||
describe("Tests for TopBanner component", () => {
|
||||
test("Should render the component properly", () => {
|
||||
render(<TopBanner text="the banner test" />);
|
||||
|
||||
const bannerElt = screen.getByTestId("banner");
|
||||
expect(bannerElt).toBeInTheDocument();
|
||||
|
||||
const btnElt = screen.queryByRole("button");
|
||||
expect(btnElt).toBeNull();
|
||||
});
|
||||
|
||||
test("Should render actions", () => {
|
||||
render(<TopBanner text="the banner test" actions={<div>cta</div>} />);
|
||||
|
||||
const ctaElt = screen.getByText("cta");
|
||||
expect(ctaElt).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render the default variant", () => {
|
||||
render(<TopBanner text="the banner test" Icon={ArrowDown} />);
|
||||
|
||||
const variant = screen.getByTestId("variant-default");
|
||||
expect(variant).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render the alert variant", () => {
|
||||
render(<TopBanner text="the banner test" variant="error" />);
|
||||
|
||||
const variant = screen.getByTestId("variant-error");
|
||||
expect(variant).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render the warning variant", () => {
|
||||
render(<TopBanner text="the banner test" variant="warning" />);
|
||||
|
||||
const variant = screen.getByTestId("variant-warning");
|
||||
expect(variant).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user