feat: v3 of UI components (#19136)
* ui playground * add types to ui * push avatar ignore ts and eslint errors * feat: V3 UI avatar (#18997) * avatar playground * add overflow-hidden back for loading indicator * update lock * feat: v3/badge (#18999) * badge intro * fix text on small badge * add dark mode warning * feat: v3/button (#19014) * TOC * wip buttons * shadows * secondary * semantic colours * minimal buttons * update disabled states * checkbox * dropdown v3 * load icons * fix design sections * fix icon gap * fix * remove client component from rsc * use peer as avatar * gif * fix button gap - dropdown iocn * support start icon in dropdowns * add alert demo + v3 component + darken semantic text * base inputs and text field * wip input * input field addon/suffix * toast page * wip select * match designs for input and select rounded * fix * fix select isloading transform * fix multi icons transition rotation * fix group heading * range slider demo + range slider * range slider popover design * v3 dialog * fix slider thumb size * wrap in suspense for useSearchParam difference in next14+ * base of tabs + horizontal tabs * fix select sizing to match input 36px * fix dark mode hover on button * target domState class for light/dark so we work on portal elements * fix default bg on popover * lightmode toasts + eleveation token * empty screen * intro to split button concept * mass colour updates * intro to themes * remove i18n from label with name * bouncy buttons * feat: small select * nav item dumb component * full demo * settings demo * fix tabs * fix mt * fix dropdown feedback from loom * alert fixes mentioned in loom * push font-cal * move to fumadocs * fix avatar * colors table * add typeography * icon + spacing guide * add border radius and shadow tables * fix colours and border radius * remove prose undline via fumas fork * fix icon buttons sizes * button group component * fix horizontal tabs * tab fixes * switches * pagination component * show toasts components raw * sync with airtable * add use client * 10px on input again * 10px in select also * fix input height * fix files merge * fix loading state for icon buttons * fix button fab * Enable addon to now overflow to next line in DS * use cal font for dialog text * add avatar square variant * fix select padding and menu size * fix type errors * fix type errors * add switch small size and fix type errors * fix ref types on input * update web styles * remove addonFilled to fix type errors * push dialog fixes * fix checkbox display * remove prose from alert examples * remove prose from all our component examples * badge rounded-lg on lg size * update colors * force w/h on icon buttons instead of inheriting * remove border-focus * remove border-focus from tailwind config * update tokens to match new colours * add new border subtle tokens and add to toasts * fix lg button padding * fix and drastically improve rtl rests * multi select use badges * use badge design for select pills * fix avatar alignment * fix tests and remove redudant ones * fix tests and remove redudant ones * update atoms globals css * extract tokens.css * extract app.css * force flex for atoms * add @calcom/ui/css * revert ui playground styles abstraction * fix input focus states * fix focus states for buttons * feat: v3/app work (#19233) * globals.css for app + event types listing search * few app wide NITS * fix select foucs within styling * fix formbuilder switch styles * fix disabled state of nested inputs * workflow fixes * webhook form fixes * i18n on tabs info * booking filters + tab * fix filters spacing * make first item so we get correct border radius if not default * round radio group in create event types + make button small * profile page * update editor br * button nits in existing places in the app * fix timezone select and multilist in guest form * fix text area on public booking page * size small event types create * margin on routing filter * filters improvments * routing insights fixes * fix date filter range * ooo fixes * fix teams/members bulk actions * create team UI * i18n in useTabs instead of in tab component now * Add event type setup border to availability * fix bulk actions on org members table * onboarding fixes * fix input types with ref stripe comparision * i18n fixes for platform * update globals of atoms * fix form builder firstname/lastname switch + correct footer useage * fix select * Revert "add @calcom/ui/css" This reverts commit 0dd8f9012907a278cfede4a98f289cb0744c9244. * revert tokens css * Revert "extract app.css" This reverts commit 10b998604816ad3310c24b36a02a638dabc5be24. * linear nits * workflow dropdown * fix page theme heading sizes to match cards * fix stepper for team creation * adjust margin to FilterSearchField * fix ooo icon * fix booker and dark mode due to darkgray 50 * more dark mode fixes * add size prop --------- Co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> * remove ui-playground * fix grow missing from merge * add search icon data-test-id back to search * fix FormAction style * fix datatestid for apps and tabs * change selector for team invitation e2e * fix use data-testid from item instaed of using names * rename upper case O * fix unit tests data-testid * fix unit tests data-testid * more data-testid changes * add data-testid to apps tab * data-testid to installed appPage * fix embed tests * fix filter-popover-trigger * use text-error and use dataId for locator * more e2e improvment * pass in single testId as button is now duplicate * show field-error instead * add test to eventtype tabs * Add css vars to embed too\ * add scrollbar and change dialog overlay colour * fix type * use attribute instead of class for tab detection * await promise * use new tokens for sprite generation * add correct testing Ids to e2e instead of button:text * use testIds for creation of orgs * Webhook receiver wait for 10 seconds --------- Co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: Hariom <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
145 files changed
+17438
-10708
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
import classNames from "classnames";
|
||||
import type { ReactNode } from "react";
|
||||
import { forwardRef } from "react";
|
||||
@@ -5,36 +6,36 @@ import { forwardRef } from "react";
|
||||
import { Icon } from "../icon";
|
||||
import type { IconName } from "../icon";
|
||||
|
||||
export const alertStyles = cva("rounded-[10px] p-3", {
|
||||
variants: {
|
||||
severity: {
|
||||
neutral: "bg-default border-subtle border-[1px] text-default",
|
||||
info: "bg-semantic-info-subtle text-semantic-info",
|
||||
warning: "bg-semantic-attention-subtle text-semantic-attention",
|
||||
error: "bg-semantic-error-subtle text-semantic-error",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
severity: "neutral",
|
||||
},
|
||||
});
|
||||
|
||||
export interface AlertProps {
|
||||
title?: ReactNode;
|
||||
// @TODO: Message should be children, more flexible?
|
||||
message?: ReactNode;
|
||||
// @TODO: Provide action buttons so style is always the same.
|
||||
actions?: ReactNode;
|
||||
className?: string;
|
||||
iconClassName?: string;
|
||||
// @TODO: Success and info shouldn't exist as per design?
|
||||
severity: "success" | "warning" | "error" | "info" | "neutral" | "green";
|
||||
severity: "warning" | "error" | "info" | "neutral";
|
||||
CustomIcon?: IconName;
|
||||
customIconColor?: string;
|
||||
}
|
||||
|
||||
export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
||||
const { severity, iconClassName, CustomIcon, customIconColor } = props;
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="alert"
|
||||
ref={ref}
|
||||
className={classNames(
|
||||
"rounded-md p-3",
|
||||
props.className,
|
||||
severity === "error" && "bg-red-100 text-red-900 dark:bg-red-900 dark:text-red-200",
|
||||
severity === "warning" && "text-attention bg-attention dark:bg-orange-900 dark:text-orange-200",
|
||||
severity === "info" && "bg-blue-100 text-blue-900 dark:bg-blue-900 dark:text-blue-200",
|
||||
severity === "green" && "bg-success text-success",
|
||||
severity === "success" && "bg-inverted text-inverted",
|
||||
severity === "neutral" && "bg-subtle text-default"
|
||||
)}>
|
||||
<div data-testid="alert" ref={ref} className={alertStyles({ severity, className: props.className })}>
|
||||
<div className="relative flex md:flex-row">
|
||||
{CustomIcon ? (
|
||||
<div className="flex-shrink-0">
|
||||
@@ -42,16 +43,16 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
||||
name={CustomIcon}
|
||||
data-testid="custom-icon"
|
||||
aria-hidden="true"
|
||||
className={classNames(`h-5 w-5`, iconClassName, customIconColor ?? "text-default")}
|
||||
className={classNames(`h4 mr-2 w-4`, iconClassName, customIconColor ?? "text-default")}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex-shrink-0">
|
||||
<div className={classNames("mr-2 flex-shrink-0", props.title ? "" : "mt-0.5")}>
|
||||
{severity === "error" && (
|
||||
<Icon
|
||||
name="circle-x"
|
||||
data-testid="circle-x"
|
||||
className={classNames("h-5 w-5 text-red-900 dark:text-red-200", iconClassName)}
|
||||
className={classNames("h4 w-4", iconClassName)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
@@ -59,7 +60,7 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
||||
<Icon
|
||||
name="triangle-alert"
|
||||
data-testid="alert-triangle"
|
||||
className={classNames("text-attention h-5 w-5 dark:text-orange-200", iconClassName)}
|
||||
className={classNames("h4 w-4", iconClassName)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
@@ -67,7 +68,7 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
||||
<Icon
|
||||
name="info"
|
||||
data-testid="info"
|
||||
className={classNames("h-5 w-5 text-blue-900 dark:text-blue-200", iconClassName)}
|
||||
className={classNames("h4 w-4", iconClassName)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
@@ -75,26 +76,20 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props, ref) => {
|
||||
<Icon
|
||||
name="info"
|
||||
data-testid="neutral"
|
||||
className={classNames("text-default h-5 w-5 fill-transparent", iconClassName)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
{severity === "success" && (
|
||||
<Icon
|
||||
name="circle-check"
|
||||
data-testid="circle-check"
|
||||
className={classNames("fill-muted text-default h-5 w-5", iconClassName)}
|
||||
className={classNames("text-default h4 w-4 fill-transparent", iconClassName)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-grow flex-col sm:flex-row">
|
||||
<div className="ltr:ml-3 rtl:mr-3">
|
||||
<h3 className="text-sm font-medium">{props.title}</h3>
|
||||
<div className="text-sm">{props.message}</div>
|
||||
<div className="space-y-1 ltr:ml-3 rtl:mr-3">
|
||||
{props.title && <h3 className="text-sm font-medium leading-none">{props.title}</h3>}
|
||||
{props.message && <div className="text-sm leading-5">{props.message}</div>}
|
||||
</div>
|
||||
{props.actions && <div className="ml-auto mt-2 text-sm sm:mt-0 md:relative">{props.actions}</div>}
|
||||
{props.actions && (
|
||||
<div className="ml-auto mt-auto text-sm sm:mt-0 md:relative">{props.actions}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -33,9 +33,4 @@ describe("Tests for Alert component", () => {
|
||||
render(<Alert severity="neutral" />);
|
||||
expect(await screen.findByTestId("neutral")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render corresponding icon: success", async () => {
|
||||
render(<Alert severity="success" />);
|
||||
expect(await screen.findByTestId("circle-check")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
||||
import { Provider as TooltipPrimitiveProvider } from "@radix-ui/react-tooltip";
|
||||
import { cva } from "class-variance-authority";
|
||||
import Link from "next/link";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
@@ -11,7 +12,8 @@ type Maybe<T> = T | null | undefined;
|
||||
|
||||
export type AvatarProps = {
|
||||
className?: string;
|
||||
size?: "xxs" | "xs" | "xsm" | "sm" | "md" | "mdLg" | "lg" | "xl";
|
||||
size?: "xs" | "xsm" | "sm" | "md" | "mdLg" | "lg" | "xl";
|
||||
shape?: "circle" | "square";
|
||||
imageSrc?: Maybe<string>;
|
||||
title?: string;
|
||||
alt: string;
|
||||
@@ -23,34 +25,65 @@ export type AvatarProps = {
|
||||
"data-testid"?: string;
|
||||
};
|
||||
|
||||
const sizesPropsBySize = {
|
||||
xxs: "w-3.5 h-3.5 min-w-3.5 min-h-3.5", // 14px
|
||||
xs: "w-4 h-4 min-w-4 min-h-4 max-h-4", // 16px
|
||||
xsm: "w-5 h-5 min-w-5 min-h-5", // 20px
|
||||
sm: "w-6 h-6 min-w-6 min-h-6", // 24px
|
||||
md: "w-8 h-8 min-w-8 min-h-8", // 32px
|
||||
mdLg: "w-10 h-10 min-w-10 min-h-10", //40px
|
||||
lg: "w-16 h-16 min-w-16 min-h-16", // 64px
|
||||
xl: "w-24 h-24 min-w-24 min-h-24", // 96px
|
||||
} as const;
|
||||
const avatarClasses = cva(
|
||||
"bg-emphasis border-default relative inline-flex aspect-square items-center justify-center border align-top",
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
xs: "w-4 h-4 min-w-4 min-h-4 max-h-4", // 16px
|
||||
xsm: "w-5 h-5 min-w-5 min-h-5", // 20px
|
||||
sm: "w-6 h-6 min-w-6 min-h-6", // 24px
|
||||
md: "w-8 h-8 min-w-8 min-h-8", // 32px
|
||||
mdLg: "w-10 h-10 min-w-10 min-h-10", // 40px
|
||||
lg: "w-16 h-16 min-w-16 min-h-16", // 64px
|
||||
xl: "w-24 h-24 min-w-24 min-h-24", // 96px
|
||||
},
|
||||
shape: {
|
||||
circle: "rounded-full",
|
||||
square: "",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "md",
|
||||
shape: "circle",
|
||||
},
|
||||
compoundVariants: [
|
||||
{
|
||||
size: ["xs", "xsm", "sm"],
|
||||
shape: "square",
|
||||
className: "rounded",
|
||||
},
|
||||
{
|
||||
size: ["md"],
|
||||
shape: "square",
|
||||
className: "rounded-md",
|
||||
},
|
||||
{
|
||||
size: ["mdLg", "lg", "xl"],
|
||||
shape: "square",
|
||||
className: "rounded-[10px]",
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
export function Avatar(props: AvatarProps) {
|
||||
const { imageSrc, size = "md", alt, title, href, indicator } = props;
|
||||
const rootClass = classNames("aspect-square rounded-full", sizesPropsBySize[size]);
|
||||
const avatarClass = avatarClasses({ size, shape: props.shape });
|
||||
const rootClass = classNames("aspect-square rounded-full", avatarClass);
|
||||
let avatar = (
|
||||
<AvatarPrimitive.Root
|
||||
data-testid={props?.["data-testid"]}
|
||||
className={classNames(
|
||||
"bg-emphasis item-center relative inline-flex aspect-square justify-center rounded-full align-top",
|
||||
avatarClass,
|
||||
indicator ? "overflow-visible" : "overflow-hidden",
|
||||
props.className,
|
||||
sizesPropsBySize[size]
|
||||
props.className
|
||||
)}>
|
||||
<>
|
||||
<AvatarPrimitive.Image
|
||||
src={imageSrc ?? undefined}
|
||||
alt={alt}
|
||||
className={classNames("aspect-square rounded-full", sizesPropsBySize[size])}
|
||||
className={classNames("aspect-square", avatarClass)}
|
||||
/>
|
||||
<AvatarPrimitive.Fallback
|
||||
delayMs={600}
|
||||
|
||||
@@ -20,11 +20,12 @@ export const badgeStyles = cva("font-medium inline-flex items-center justify-cen
|
||||
red: "bg-error text-error",
|
||||
error: "bg-error text-error",
|
||||
grayWithoutHover: "bg-gray-100 text-gray-800 dark:bg-darkgray-200 dark:text-darkgray-800",
|
||||
purple: "bg-purple-50 text-purple-800",
|
||||
},
|
||||
size: {
|
||||
sm: "px-1 py-0.5 text-xs leading-3",
|
||||
md: "py-1 px-1.5 text-xs leading-3",
|
||||
lg: "py-1 px-2 text-sm leading-4",
|
||||
sm: "px-1 py-1 text-[10px] leading-none",
|
||||
md: "py-1 px-1.5 text-xs leading-none",
|
||||
lg: "py-1 px-1.5 text-sm leading-none rounded-lg",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
/* eslint-disable playwright/missing-playwright-await */
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import { Icon } from "../icon";
|
||||
import { Badge, badgeStyles } from "./Badge";
|
||||
|
||||
describe("Tests for Badge component", () => {
|
||||
describe("Badge", () => {
|
||||
const variants = [
|
||||
"default",
|
||||
"warning",
|
||||
@@ -18,74 +16,71 @@ describe("Tests for Badge component", () => {
|
||||
"red",
|
||||
"error",
|
||||
"grayWithoutHover",
|
||||
];
|
||||
"purple",
|
||||
] as const;
|
||||
|
||||
const sizes = ["sm", "md", "lg"];
|
||||
const children = "Test Badge";
|
||||
|
||||
test.each(variants)("Should apply variant class", (variant) => {
|
||||
render(<Badge variant={variant as any}>{children}</Badge>);
|
||||
const badgeClass = screen.getByText(children).className;
|
||||
const badgeComponentClass = badgeStyles({ variant: variant as any });
|
||||
expect(badgeClass).toEqual(badgeComponentClass);
|
||||
});
|
||||
|
||||
test.each(sizes)("Should apply size class", (size) => {
|
||||
render(<Badge size={size as any}>{children}</Badge>);
|
||||
const badgeClass = screen.getByText(children).className;
|
||||
const badgeComponentClass = badgeStyles({ size: size as any });
|
||||
expect(badgeClass).toEqual(badgeComponentClass);
|
||||
});
|
||||
|
||||
test("Should render without errors", () => {
|
||||
render(<Badge>{children}</Badge>);
|
||||
expect(screen.getByText(children)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render WithDot if the prop is true and shouldn't render if is false", async () => {
|
||||
const { rerender } = render(<Badge withDot>{children}</Badge>);
|
||||
expect(await screen.findByTestId("go-primitive-dot")).toBeInTheDocument();
|
||||
|
||||
rerender(<Badge>{children}</Badge>);
|
||||
expect(screen.queryByTestId("go-primitive-dot")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render with a startIcon when startIcon prop is provided shouldn't render if is false", () => {
|
||||
const { rerender } = render(<Badge customStartIcon={<svg data-testid="start-icon" />}>{children}</Badge>);
|
||||
expect(screen.getByTestId("start-icon")).toBeInTheDocument();
|
||||
|
||||
rerender(<Badge>{children}</Badge>);
|
||||
expect(screen.queryByTestId("start-icon")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render as a button when onClick prop is provided and shouldn't if is not", () => {
|
||||
const handleClick = vi.fn();
|
||||
const { rerender } = render(<Badge onClick={handleClick}>{children}</Badge>);
|
||||
test.each(variants)("renders %s variant correctly", (variant) => {
|
||||
render(<Badge variant={variant}>{children}</Badge>);
|
||||
const badge = screen.getByText(children);
|
||||
expect(badge.tagName).toBe("BUTTON");
|
||||
fireEvent.click(badge);
|
||||
expect(handleClick).toHaveBeenCalledTimes(1);
|
||||
|
||||
rerender(<Badge>{children}</Badge>);
|
||||
const updateBadge = screen.getByText(children);
|
||||
expect(updateBadge.tagName).not.toBe("BUTTON");
|
||||
expect(badge.className).toContain(badgeStyles({ variant }));
|
||||
});
|
||||
|
||||
test("Should render as a div when onClick prop is not provided", () => {
|
||||
test("renders with default props", () => {
|
||||
render(<Badge>{children}</Badge>);
|
||||
const badge = screen.getByText(children);
|
||||
expect(badge).toBeInTheDocument();
|
||||
expect(badge.tagName).toBe("DIV");
|
||||
});
|
||||
|
||||
test("Should render children when provided", () => {
|
||||
const { getByText } = render(
|
||||
test("renders with dot when withDot prop is true", () => {
|
||||
render(<Badge withDot>{children}</Badge>);
|
||||
expect(screen.getByTestId("go-primitive-dot")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders with startIcon when provided", () => {
|
||||
render(<Badge startIcon="info">{children}</Badge>);
|
||||
expect(screen.getByTestId("start-icon")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders with customStartIcon when provided", () => {
|
||||
render(<Badge customStartIcon={<Icon name="info" data-testid="custom-icon" />}>{children}</Badge>);
|
||||
expect(screen.getByTestId("custom-icon")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders as button with onClick handler", () => {
|
||||
const handleClick = vi.fn();
|
||||
render(<Badge onClick={handleClick}>{children}</Badge>);
|
||||
const badge = screen.getByText(children);
|
||||
|
||||
expect(badge.tagName).toBe("BUTTON");
|
||||
fireEvent.click(badge);
|
||||
expect(handleClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("renders with rounded style when rounded prop is true", () => {
|
||||
render(<Badge rounded>{children}</Badge>);
|
||||
const badge = screen.getByText(children);
|
||||
expect(badge.className).toContain("h-5 w-5 rounded-full p-0");
|
||||
});
|
||||
|
||||
test("renders with additional className when provided", () => {
|
||||
const customClass = "custom-class";
|
||||
render(<Badge className={customClass}>{children}</Badge>);
|
||||
const badge = screen.getByText(children);
|
||||
expect(badge.className).toContain(customClass);
|
||||
});
|
||||
|
||||
test("renders nested children correctly", () => {
|
||||
render(
|
||||
<Badge>
|
||||
<span>Child element 1</span>
|
||||
<span>Child element 2</span>
|
||||
<span data-testid="child-1">Child 1</span>
|
||||
<span data-testid="child-2">Child 2</span>
|
||||
</Badge>
|
||||
);
|
||||
|
||||
expect(getByText("Child element 1")).toBeInTheDocument();
|
||||
expect(getByText("Child element 2")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("child-1")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("child-2")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -40,28 +40,118 @@ export type ButtonProps = ButtonBaseProps &
|
||||
);
|
||||
|
||||
export const buttonClasses = cva(
|
||||
"whitespace-nowrap inline-flex items-center text-sm font-medium relative rounded-md transition disabled:cursor-not-allowed",
|
||||
"group whitespace-nowrap inline-flex items-center text-sm font-medium relative rounded-[10px] transition disabled:cursor-not-allowed gap-1",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
button: "",
|
||||
icon: "flex justify-center",
|
||||
fab: "rounded-full justify-center md:rounded-md radix-state-open:rotate-45 md:radix-state-open:rotate-0 radix-state-open:shadown-none radix-state-open:ring-0 !shadow-none",
|
||||
fab: "rounded-full justify-center md:rounded-[10px] radix-state-open:rotate-45 md:radix-state-open:rotate-0 radix-state-open:shadown-none radix-state-open:ring-0",
|
||||
},
|
||||
color: {
|
||||
primary:
|
||||
"bg-brand-default hover:bg-brand-emphasis focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset focus-visible:ring-brand-default text-brand disabled:bg-brand-subtle disabled:text-brand-subtle disabled:opacity-40 disabled:hover:bg-brand-subtle disabled:hover:text-brand-default disabled:hover:opacity-40",
|
||||
secondary:
|
||||
"text-emphasis border border-default bg-default hover:bg-muted hover:border-emphasis focus-visible:bg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset focus-visible:ring-empthasis disabled:border-subtle disabled:bg-opacity-30 disabled:text-muted disabled:hover:bg-opacity-30 disabled:hover:text-muted disabled:hover:border-subtle disabled:hover:bg-default",
|
||||
minimal:
|
||||
"text-emphasis hover:bg-subtle focus-visible:bg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset focus-visible:ring-empthasis disabled:border-subtle disabled:bg-opacity-30 disabled:text-muted disabled:hover:bg-transparent disabled:hover:text-muted disabled:hover:border-subtle",
|
||||
destructive:
|
||||
"border border-default text-emphasis hover:text-red-700 dark:hover:text-red-100 focus-visible:text-red-700 hover:border-red-100 focus-visible:border-red-100 hover:bg-error focus-visible:bg-error focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset focus-visible:ring-red-700 disabled:bg-red-100 disabled:border-red-200 disabled:text-red-700 disabled:hover:border-red-200 disabled:opacity-40",
|
||||
primary: [
|
||||
// Base colors
|
||||
"bg-brand-default",
|
||||
"text-brand",
|
||||
// Focus state
|
||||
"focus-visible:outline-none",
|
||||
"focus-visible:ring-0",
|
||||
"focus-visible:shadow-button-solid-brand-focused",
|
||||
// Border
|
||||
"border border-brand-default",
|
||||
// Disabled
|
||||
"disabled:opacity-30",
|
||||
// Shadows and effects
|
||||
"shadow-button-solid-brand-default",
|
||||
"enabled:active:shadow-button-solid-brand-active",
|
||||
"enabled:hover:shadow-button-solid-brand-hover",
|
||||
"transition-shadow",
|
||||
"transition-transform",
|
||||
"duration-100",
|
||||
],
|
||||
|
||||
secondary: [
|
||||
// Base colors and border
|
||||
"bg-default",
|
||||
"text-default",
|
||||
"border",
|
||||
"border-default",
|
||||
// Hover state
|
||||
"enabled:hover:bg-muted",
|
||||
"enabled:hover:border-emphasis",
|
||||
"enabled:hover:text-emphasis",
|
||||
// Disabled
|
||||
"disabled:opacity-30",
|
||||
// Focus state
|
||||
"focus-visible:bg-subtle",
|
||||
"focus-visible:outline-none",
|
||||
"focus-visible:ring-0",
|
||||
"focus-visible:shadow-outline-gray-focused",
|
||||
// Shadows and effects
|
||||
"shadow-outline-gray-rested",
|
||||
"enabled:hover:shadow-outline-gray-hover",
|
||||
"enabled:active:shadow-outline-gray-active",
|
||||
"transition-shadow",
|
||||
"duration-200",
|
||||
],
|
||||
|
||||
minimal: [
|
||||
// Base color
|
||||
"text-subtle",
|
||||
"border border-transparent",
|
||||
// Hover
|
||||
"enabled:hover:bg-subtle",
|
||||
"enabled:hover:text-emphasis",
|
||||
"enabled:hover:border-subtle hover:border",
|
||||
// Disabled
|
||||
"disabled:opacity-30",
|
||||
// Focus
|
||||
"focus-visible:bg-subtle",
|
||||
"focus-visible:outline-none",
|
||||
"focus-visible:ring-0",
|
||||
"focus-visible:border-subtle",
|
||||
"focus-visible:shadow-button-outline-gray-focused",
|
||||
|
||||
// Shadows and effects
|
||||
"enabled:active:shadow-outline-gray-active",
|
||||
"transition-shadow",
|
||||
"duration-200",
|
||||
],
|
||||
|
||||
destructive: [
|
||||
// Base colors and border
|
||||
"border",
|
||||
"border-default",
|
||||
"text-error",
|
||||
// Hover state
|
||||
"dark:hover:text-red-100",
|
||||
"hover:border-semantic-danager-subtle",
|
||||
"hover:bg-error",
|
||||
// Focus state
|
||||
"focus-visible:text-red-700",
|
||||
"focus-visible:bg-error",
|
||||
"focus-visible:outline-none",
|
||||
"focus-visible:ring-0",
|
||||
"focus-visible:shadow-button-outline-red-focused",
|
||||
// Disabled state
|
||||
"disabled:bg-red-100",
|
||||
"disabled:border-red-200",
|
||||
"disabled:text-red-700",
|
||||
"disabled:hover:border-red-200",
|
||||
"disabled:opacity-30",
|
||||
// Shadows and effects
|
||||
"shadow-outline-red-rested",
|
||||
"enabled:hover:shadow-outline-red-hover",
|
||||
"enabled:active:shadow-outline-red-active",
|
||||
"transition-shadow",
|
||||
"duration-200",
|
||||
],
|
||||
},
|
||||
size: {
|
||||
sm: "px-3 py-2 leading-4 rounded-md" /** For backwards compatibility */,
|
||||
base: "h-9 px-4 py-2.5 ",
|
||||
lg: "h-[36px] px-4 py-2.5 ",
|
||||
xs: "h-6 p-2 leading-none text-xs rounded-md",
|
||||
sm: "h-7 px-2 py-1.5 leading-none text-sm" /** For backwards compatibility */,
|
||||
base: "px-2.5 py-2 text-sm leading-none",
|
||||
lg: "px-3 py-2.5 ",
|
||||
},
|
||||
loading: {
|
||||
true: "cursor-wait",
|
||||
@@ -72,7 +162,7 @@ export const buttonClasses = cva(
|
||||
{
|
||||
loading: true,
|
||||
color: "primary",
|
||||
className: "bg-brand-subtle text-brand-subtle",
|
||||
className: "opacity-30",
|
||||
},
|
||||
// Secondary variants
|
||||
{
|
||||
@@ -98,15 +188,25 @@ export const buttonClasses = cva(
|
||||
size: "base",
|
||||
className: "min-h-[36px] min-w-[36px] !p-2 hover:border-default",
|
||||
},
|
||||
{
|
||||
variant: "icon",
|
||||
size: "xs",
|
||||
className: "h-5 w-5 !p-1 rounded-md",
|
||||
},
|
||||
{
|
||||
variant: "icon",
|
||||
size: "sm",
|
||||
className: "h-6 w-6 !p-1",
|
||||
className: "h-6 w-6 !p-1 rounded-md",
|
||||
},
|
||||
{
|
||||
variant: "icon",
|
||||
size: "lg",
|
||||
className: "h-10 w-10 !p-1",
|
||||
},
|
||||
{
|
||||
variant: "fab",
|
||||
size: "base",
|
||||
className: "h-14 md:h-9 md:w-auto md:px-4 md:py-2.5",
|
||||
className: "min-h-14 md:min-h-9 md:min-w-auto md:px-4 md:py-2.5",
|
||||
},
|
||||
],
|
||||
defaultVariants: {
|
||||
@@ -163,24 +263,31 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
<>
|
||||
{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={StartIcon} className="hidden h-4 w-4 stroke-[1.5px] md:inline-flex" />
|
||||
<Icon name="plus" data-testid="plus" className="inline h-6 w-6 md:hidden" />
|
||||
</>
|
||||
) : (
|
||||
<Icon
|
||||
data-name="start-icon"
|
||||
name={StartIcon}
|
||||
className={classNames(
|
||||
loading ? "invisible" : "visible",
|
||||
"button-icon group-active:translate-y-[0.5px]",
|
||||
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 === "button" && "h-4 w-4 stroke-[1.5px] "
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
{variant === "fab" ? <span className="hidden md:inline">{props.children}</span> : props.children}
|
||||
{props.children &&
|
||||
(variant === "fab" ? (
|
||||
<span className={`hidden md:inline ${loading ? "invisible" : "visible "}`}>{props.children}</span>
|
||||
) : (
|
||||
<span className={loading ? "invisible" : "visible group-active:translate-y-[0.5px]"}>
|
||||
{props.children}
|
||||
</span>
|
||||
))}
|
||||
{loading && (
|
||||
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transform">
|
||||
<svg
|
||||
@@ -211,9 +318,10 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
|
||||
<Icon
|
||||
name={EndIcon}
|
||||
className={classNames(
|
||||
"inline-flex",
|
||||
loading ? "invisible" : "visible",
|
||||
"group-active:translate-y-[0.5px]",
|
||||
variant === "icon" && "h-4 w-4",
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] ltr:-mr-1 ltr:ml-2 rtl:-ml-1 rtl:mr-2"
|
||||
variant === "button" && "h-4 w-4 stroke-[1.5px] "
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
@@ -266,3 +374,5 @@ const Wrapper = ({
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
Button.displayName = "Button";
|
||||
@@ -0,0 +1,76 @@
|
||||
"use client";
|
||||
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||
import type { ReactNode } from "react";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { Icon } from "../icon";
|
||||
import type { ButtonBaseProps, ButtonProps } from "./Button";
|
||||
import { Button, buttonClasses } from "./Button";
|
||||
|
||||
export interface SplitButtonProps extends ButtonBaseProps {
|
||||
children?: ReactNode;
|
||||
dropdown?: {
|
||||
items: {
|
||||
label: string;
|
||||
action: () => void;
|
||||
icon?: ButtonProps["StartIcon"];
|
||||
color?: ButtonProps["color"];
|
||||
}[];
|
||||
};
|
||||
}
|
||||
|
||||
export const SplitButton = forwardRef<HTMLButtonElement, SplitButtonProps>(function SplitButton(
|
||||
{ children, dropdown, StartIcon, color = "primary", ...mainButtonProps },
|
||||
forwardedRef
|
||||
) {
|
||||
if (!dropdown) {
|
||||
return (
|
||||
<Button ref={forwardedRef} StartIcon={StartIcon} color={color} {...mainButtonProps}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="inline-flex">
|
||||
<Button
|
||||
{...mainButtonProps}
|
||||
className="rounded-r-none border-r-0"
|
||||
StartIcon={StartIcon}
|
||||
color={color}
|
||||
ref={forwardedRef}>
|
||||
{children}
|
||||
</Button>
|
||||
<DropdownMenuPrimitive.Root>
|
||||
<DropdownMenuPrimitive.Trigger asChild>
|
||||
<button
|
||||
className={buttonClasses({
|
||||
variant: "button",
|
||||
color,
|
||||
size: mainButtonProps.size,
|
||||
className: "rounded-l-none px-2",
|
||||
})}>
|
||||
<Icon name="chevron-down" className="h-4 w-4" />
|
||||
</button>
|
||||
</DropdownMenuPrimitive.Trigger>
|
||||
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
align="end"
|
||||
className="bg-default border-subtle z-50 mt-1 min-w-[180px] overflow-hidden rounded-md border p-1 shadow-md">
|
||||
{dropdown.items.map((item, index) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
key={index}
|
||||
className="text-default hover:bg-subtle focus:bg-subtle flex w-full cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm outline-none"
|
||||
onClick={item.action}>
|
||||
{item.icon && <Icon name={item.icon} className="h-4 w-4" />}
|
||||
{item.label}
|
||||
</DropdownMenuPrimitive.Item>
|
||||
))}
|
||||
</DropdownMenuPrimitive.Content>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
</DropdownMenuPrimitive.Root>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
export { Button, buttonClasses } from "./Button";
|
||||
export { SplitButton } from "./SplitButton";
|
||||
export type { ButtonBaseProps, ButtonProps, ButtonColor } from "./Button";
|
||||
export { default as LinkIconButton } from "./LinkIconButton";
|
||||
@@ -4,24 +4,30 @@ import classNames from "@calcom/lib/classNames";
|
||||
|
||||
type Props = { children: React.ReactNode; combined?: boolean; containerProps?: JSX.IntrinsicElements["div"] };
|
||||
|
||||
/**
|
||||
* Breakdown of Tailwind Magic below
|
||||
* [&_button]:border-l-0 [&_a]:border-l-0 -> Selects all buttons/a tags and applies a border left of 0
|
||||
* [&>*:first-child]:rounded-l-md [&>*:first-child]:border-l -> Selects the first child of the content
|
||||
* ounds the left side
|
||||
* [&>*:last-child]:rounded-r-md -> Selects the last child of the content and rounds the right side
|
||||
* We dont need to add border to the right as we never remove it
|
||||
*/
|
||||
const sizeToRadius = {
|
||||
lg: "12px",
|
||||
base: "8px",
|
||||
sm: "10px",
|
||||
xs: "8px",
|
||||
} as const;
|
||||
|
||||
export function ButtonGroup({ children, combined = false, containerProps }: Props) {
|
||||
// Get the size from the first button child if it exists
|
||||
const firstButton = React.Children.toArray(children)[0] as React.ReactElement;
|
||||
const size = firstButton?.props?.size || "base";
|
||||
const radius = sizeToRadius[size as keyof typeof sizeToRadius];
|
||||
|
||||
const style = combined ? ({ "--btn-group-radius": radius } as React.CSSProperties) : undefined;
|
||||
|
||||
return (
|
||||
<div
|
||||
{...containerProps}
|
||||
style={style}
|
||||
className={classNames(
|
||||
"flex",
|
||||
!combined
|
||||
? "space-x-2 rtl:space-x-reverse"
|
||||
: "ltr:[&>*:first-child]:ml-0 ltr:[&>*:first-child]:rounded-l-md ltr:[&>*:first-child]:border-l rtl:[&>*:first-child]:rounded-r-md rtl:[&>*:first-child]:border-r ltr:[&>*:last-child]:rounded-r-md rtl:[&>*:last-child]:rounded-l-md [&>a]:-ml-[1px] hover:[&>a]:z-[1] [&>button]:-ml-[1px] hover:[&>button]:z-[1] [&_a]:rounded-none [&_button]:rounded-none",
|
||||
: "[&>*:first-child]:rounded-l-[var(--btn-group-radius)] rtl:[&>*:first-child]:rounded-l-none rtl:[&>*:first-child]:rounded-r-[var(--btn-group-radius)] [&>*:last-child]:rounded-r-[var(--btn-group-radius)] rtl:[&>*:last-child]:rounded-l-[var(--btn-group-radius)] rtl:[&>*:last-child]:rounded-r-none [&>*:not(:first-child)]:-ml-[1px] [&>*]:rounded-none [&>*]:border hover:[&>*]:z-[1]",
|
||||
containerProps?.className
|
||||
)}>
|
||||
{children}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const StepCard: React.FC<{ children: React.ReactNode }> = (props) => {
|
||||
return (
|
||||
<div className="sm:border-subtle bg-default mt-10 border p-4 dark:bg-black sm:rounded-md sm:p-8">
|
||||
{props.children}
|
||||
</div>
|
||||
<div className="sm:border-subtle bg-muted mt-10 border p-4 sm:rounded-md sm:p-8">{props.children}</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
@@ -77,6 +79,7 @@ export function CreateButton(props: CreateBtnProps) {
|
||||
<>
|
||||
{!hasTeams && !platform ? (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
!!CreateDialog
|
||||
? openModal(options[0])
|
||||
@@ -97,6 +100,7 @@ export function CreateButton(props: CreateBtnProps) {
|
||||
<Button
|
||||
variant={disableMobileButton ? "button" : "fab"}
|
||||
StartIcon="plus"
|
||||
size="sm"
|
||||
data-testid="create-button-dropdown"
|
||||
loading={isPending}
|
||||
{...restProps}>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import type { ForwardRefExoticComponent, ReactElement, ReactNode } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
|
||||
import { Dialog as PlatformDialogPrimitives, useIsPlatform } from "@calcom/atoms/monorepo";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
@@ -15,6 +16,23 @@ import { Button } from "../button";
|
||||
import type { IconName } from "../icon";
|
||||
import { Icon } from "../icon";
|
||||
|
||||
const dialogClasses = cva(
|
||||
"fadeIn bg-default scroll-bar fixed left-1/2 top-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 rounded-2xl text-left shadow-xl focus-visible:outline-none sm:align-middle",
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
xl: "px-8 pt-8 sm:max-w-[90rem]",
|
||||
lg: "px-8 pt-8 sm:max-w-[70rem]",
|
||||
md: "px-8 pt-8 sm:max-w-[48rem]",
|
||||
default: "px-8 pt-8 sm:max-w-[35rem]",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export type DialogProps = React.ComponentProps<(typeof DialogPrimitive)["Root"]> & {
|
||||
name?: string;
|
||||
clearQueryParamsOnClose?: string[];
|
||||
@@ -81,7 +99,6 @@ function WebDialog(props: DialogProps) {
|
||||
}
|
||||
|
||||
type DialogContentProps = React.ComponentProps<(typeof DialogPrimitive)["Content"]> & {
|
||||
size?: "xl" | "lg" | "md";
|
||||
type?: "creation" | "confirmation";
|
||||
title?: string;
|
||||
description?: string | JSX.Element | null;
|
||||
@@ -94,7 +111,7 @@ type DialogContentProps = React.ComponentProps<(typeof DialogPrimitive)["Content
|
||||
* Disables the ability to close the dialog by clicking outside of it. Could be useful when the dialog is doing something critical which might be in progress.
|
||||
*/
|
||||
preventCloseOnOutsideClick?: boolean;
|
||||
};
|
||||
} & VariantProps<typeof dialogClasses>;
|
||||
|
||||
// enableOverflow:- use this prop whenever content inside DialogContent could overflow and require scrollbar
|
||||
export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps>(
|
||||
@@ -126,9 +143,9 @@ export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps
|
||||
return (
|
||||
<Portal>
|
||||
{forceOverlayWhenNoModal ? (
|
||||
<div className="fadeIn fixed inset-0 z-50 bg-neutral-800 bg-opacity-70 transition-opacity dark:bg-opacity-70 " />
|
||||
<div className="fadeIn fixed inset-0 z-50 bg-neutral-800 bg-opacity-70 transition-opacity" />
|
||||
) : (
|
||||
<Overlay className="fadeIn fixed inset-0 z-50 bg-neutral-800 bg-opacity-70 transition-opacity dark:bg-opacity-70 " />
|
||||
<Overlay className="fadeIn fixed inset-0 z-50 bg-neutral-800 bg-opacity-70 transition-opacity dark:bg-opacity-80" />
|
||||
)}
|
||||
<Content
|
||||
{...props}
|
||||
@@ -138,16 +155,9 @@ export const DialogContent = React.forwardRef<HTMLDivElement, DialogContentProps
|
||||
}
|
||||
}}
|
||||
className={classNames(
|
||||
"fadeIn bg-default scroll-bar fixed left-1/2 top-1/2 z-50 w-full max-w-[22rem] -translate-x-1/2 -translate-y-1/2 rounded-md text-left shadow-xl focus-visible:outline-none sm:align-middle",
|
||||
props.size == "xl"
|
||||
? "px-8 pt-8 sm:max-w-[90rem]"
|
||||
: props.size == "lg"
|
||||
? "px-8 pt-8 sm:max-w-[70rem]"
|
||||
: props.size == "md"
|
||||
? "px-8 pt-8 sm:max-w-[48rem]"
|
||||
: "px-8 pt-8 sm:max-w-[35rem]",
|
||||
dialogClasses({ size: props.size }),
|
||||
"max-h-[95vh]",
|
||||
enableOverflow ? "overflow-auto" : "overflow-visible",
|
||||
enableOverflow ? "overflow-y-auto" : "overflow-visible",
|
||||
`${props.className || ""}`
|
||||
)}
|
||||
ref={forwardedRef}>
|
||||
@@ -191,11 +201,15 @@ export function DialogHeader(props: DialogHeaderProps) {
|
||||
<div className="mb-4">
|
||||
<h3
|
||||
data-testid="dialog-title"
|
||||
className="leading-20 text-semibold font-cal text-emphasis pb-1 text-xl"
|
||||
className="leading-20 text-semibold text-emphasis font-cal mb-1 text-xl"
|
||||
id="modal-title">
|
||||
{props.title}
|
||||
</h3>
|
||||
{props.subtitle && <p className="text-subtle text-sm">{props.subtitle}</p>}
|
||||
{props.subtitle && (
|
||||
<p className="text-subtle text-sm leading-none" data-testid="dialog-subtitle">
|
||||
{props.subtitle}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -208,16 +222,14 @@ type DialogFooterProps = {
|
||||
|
||||
export function DialogFooter(props: DialogFooterProps) {
|
||||
return (
|
||||
<div className={classNames("bg-default bottom-0", props?.noSticky ? "" : "sticky", props.className)}>
|
||||
{props.showDivider && (
|
||||
// TODO: the -mx-8 is causing overflow in the dialog buttons
|
||||
<hr data-testid="divider" className="border-subtle -mx-8" />
|
||||
)}
|
||||
<div
|
||||
className={classNames(
|
||||
"flex justify-end space-x-2 pb-4 pt-4 rtl:space-x-reverse",
|
||||
!props.showDivider && "pb-8"
|
||||
)}>
|
||||
<div
|
||||
className={classNames(
|
||||
"bg-muted border-subtle bottom-0 -mx-8 mt-10 rounded-b-2xl",
|
||||
props?.noSticky ? "" : "sticky",
|
||||
props.className
|
||||
)}>
|
||||
{props.showDivider && <div data-testid="divider" className="border-subtle border-t" />}
|
||||
<div className={classNames("flex justify-end space-x-2 px-8 py-4 font-sans rtl:space-x-reverse")}>
|
||||
{props.children}
|
||||
</div>
|
||||
</div>
|
||||
@@ -265,13 +277,15 @@ export function DialogClose(
|
||||
[isPlatform]
|
||||
);
|
||||
|
||||
const { className, ...buttonProps } = props;
|
||||
|
||||
return (
|
||||
<Close asChild {...props.dialogCloseProps}>
|
||||
{/* This will require the i18n string passed in */}
|
||||
<Button
|
||||
data-testid={props["data-testid"] || "dialog-rejection"}
|
||||
color={props.color || "minimal"}
|
||||
{...props}>
|
||||
className={classNames(props.color === "destructive" && "destructive", className)}
|
||||
{...buttonProps}>
|
||||
{props.children ? props.children : t("close")}
|
||||
</Button>
|
||||
</Close>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "./Dialog";
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTrigger } from "./Dialog";
|
||||
|
||||
vi.mock("@calcom/lib/hooks/useCompatSearchParams", () => ({
|
||||
useCompatSearchParams() {
|
||||
@@ -25,116 +25,106 @@ vi.mock("next/navigation", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const title = "Dialog Header";
|
||||
const subtitle = "Dialog Subtitle";
|
||||
describe("Dialog", () => {
|
||||
const title = "Dialog Title";
|
||||
const subtitle = "Dialog Subtitle";
|
||||
const content = "Dialog Content";
|
||||
const footerContent = "Dialog Footer";
|
||||
|
||||
const DialogComponent = (props: {
|
||||
open: boolean;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
type?: "creation" | "confirmation";
|
||||
showDivider?: boolean;
|
||||
color?: "primary" | "secondary" | "minimal" | "destructive";
|
||||
}) => {
|
||||
return (
|
||||
<Dialog open={props.open}>
|
||||
<DialogContent type={props.type}>
|
||||
<div className="flex flex-row justify-center align-middle ">
|
||||
const TestDialog = (props: {
|
||||
open?: boolean;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
type?: "creation" | "confirmation";
|
||||
showDivider?: boolean;
|
||||
color?: "primary" | "secondary" | "minimal" | "destructive";
|
||||
preventCloseOnOutsideClick?: boolean;
|
||||
enableOverflow?: boolean;
|
||||
}) => (
|
||||
<Dialog open={props.open} name="test-dialog">
|
||||
<DialogContent
|
||||
type={props.type}
|
||||
title={props.title}
|
||||
preventCloseOnOutsideClick={props.preventCloseOnOutsideClick}
|
||||
enableOverflow={props.enableOverflow}>
|
||||
<div className="flex flex-row space-x-4">
|
||||
<DialogHeader title={props.title} subtitle={props.subtitle} />
|
||||
<p>Dialog Content</p>
|
||||
<p>{content}</p>
|
||||
<DialogFooter showDivider={props.showDivider}>
|
||||
<DialogClose color={props.color} />
|
||||
<p>Dialog Footer</p>
|
||||
<DialogClose color={props.color}>{props.color ? "Custom Close" : undefined}</DialogClose>
|
||||
<p>{footerContent}</p>
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
describe("Tests for Dialog component", () => {
|
||||
test("Should render Dialog with header", () => {
|
||||
render(<DialogComponent open title={title} />);
|
||||
describe("Rendering", () => {
|
||||
it("renders without header when no title provided", () => {
|
||||
render(<TestDialog open />);
|
||||
|
||||
expect(screen.queryByText("Dialog Header")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
expect(screen.queryByTestId("dialog-title")).not.toBeInTheDocument();
|
||||
expect(screen.getByText(content)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders creation type dialog", () => {
|
||||
render(<TestDialog open type="creation" />);
|
||||
|
||||
expect(screen.getByTestId("dialog-creation")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders confirmation type dialog", () => {
|
||||
render(<TestDialog open type="confirmation" />);
|
||||
|
||||
expect(screen.getByTestId("dialog-confirmation")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test("Should render Dialog without header", () => {
|
||||
render(<DialogComponent open />);
|
||||
describe("Visibility", () => {
|
||||
it("shows content when open", () => {
|
||||
render(<TestDialog open />);
|
||||
|
||||
expect(screen.queryByTestId("dialog-title")).toBeNull();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
expect(screen.getByText(content)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides content when closed", () => {
|
||||
render(<TestDialog open={false} />);
|
||||
|
||||
expect(screen.queryByText(content)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("toggles visibility with DialogTrigger", () => {
|
||||
render(
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<button>Open Dialog</button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<p>{content}</p>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
expect(screen.queryByText(content)).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByText("Open Dialog"));
|
||||
expect(screen.getByText(content)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test("Should render Dialog with header and subtitle", () => {
|
||||
render(<DialogComponent open title={title} subtitle={subtitle} />);
|
||||
describe("Footer", () => {
|
||||
it("shows divider when showDivider is true", () => {
|
||||
render(<TestDialog open showDivider />);
|
||||
|
||||
expect(screen.queryByText("Dialog Header")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Dialog Subtitle")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("divider")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test("Should render Dialog with default type creation", () => {
|
||||
render(<DialogComponent open />);
|
||||
describe("Behavior", () => {
|
||||
it("enables overflow when enableOverflow is true", () => {
|
||||
render(<TestDialog open enableOverflow />);
|
||||
|
||||
expect(screen.getByTestId("dialog-creation")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render Dialog with type creation", () => {
|
||||
render(<DialogComponent open type="creation" />);
|
||||
|
||||
expect(screen.getByTestId("dialog-creation")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should render Dialog with type confirmation", () => {
|
||||
render(<DialogComponent open type="confirmation" />);
|
||||
|
||||
expect(screen.getByTestId("dialog-confirmation")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should open Dialog", async () => {
|
||||
const { rerender } = render(<DialogComponent open={false} />);
|
||||
|
||||
expect(screen.queryByText("Dialog Content")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Dialog Footer")).not.toBeInTheDocument();
|
||||
|
||||
rerender(<DialogComponent open />);
|
||||
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should close Dialog", async () => {
|
||||
const { rerender } = render(<DialogComponent open />);
|
||||
|
||||
expect(screen.getByText("Dialog Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Dialog Footer")).toBeInTheDocument();
|
||||
|
||||
rerender(<DialogComponent open={false} />);
|
||||
|
||||
expect(screen.queryByText("Dialog Content")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Dialog Footer")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("Should use color from props in CloseDialog", async () => {
|
||||
render(<DialogComponent open color="destructive" />);
|
||||
const closeBtn = screen.getByText("close");
|
||||
expect(closeBtn.classList.toString()).toContain("hover:text-red-700");
|
||||
});
|
||||
|
||||
test("Should show divider with showDivider", async () => {
|
||||
render(<DialogComponent open showDivider />);
|
||||
|
||||
expect(screen.getByTestId("divider")).toBeInTheDocument();
|
||||
const dialogContent = screen.getByRole("dialog");
|
||||
expect(dialogContent.className).toContain("overflow-y-auto");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -39,8 +39,8 @@ export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuConten
|
||||
{...props}
|
||||
sideOffset={sideOffset}
|
||||
className={classNames(
|
||||
"shadow-dropdown bg-default border-subtle relative z-10 ml-1.5 origin-top-right rounded-md border text-sm",
|
||||
"[&>*:first-child]:mt-1 [&>*:last-child]:mb-1",
|
||||
"shadow-dropdown bg-default border-subtle relative z-10 origin-top-right space-y-[1px] rounded-xl border p-1 text-sm",
|
||||
"w-[220px] [&>*:first-child]:mt-1 [&>*:last-child]:mb-1",
|
||||
props.className
|
||||
)}
|
||||
ref={forwardedRef}>
|
||||
@@ -53,14 +53,17 @@ DropdownMenuContent.displayName = "DropdownMenuContent";
|
||||
|
||||
type DropdownMenuLabelProps = ComponentProps<(typeof DropdownMenuPrimitive)["Label"]>;
|
||||
export const DropdownMenuLabel = (props: DropdownMenuLabelProps) => (
|
||||
<DropdownMenuPrimitive.Label {...props} className={classNames("text-subtle px-3 py-2", props.className)} />
|
||||
<DropdownMenuPrimitive.Label
|
||||
{...props}
|
||||
className={classNames("text-subtle px-2 pb-1 pt-1.5 text-xs font-semibold leading-none", props.className)}
|
||||
/>
|
||||
);
|
||||
|
||||
type DropdownMenuItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["CheckboxItem"]>;
|
||||
export const DropdownMenuItem = forwardRef<HTMLDivElement, DropdownMenuItemProps>(
|
||||
({ className = "", ...props }, forwardedRef) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
className={`focus:ring-brand-800 hover:bg-subtle hover:text-emphasis text-default text-sm ring-inset first-of-type:rounded-t-[inherit] last-of-type:rounded-b-[inherit] focus:outline-none focus:ring-1 ${className}`}
|
||||
className={`focus:ring-brand-default hover:bg-subtle hover:text-emphasis text-default text-sm ring-inset first-of-type:rounded-t-[inherit] last-of-type:rounded-b-[inherit] hover:ring-0 focus:outline-none focus:ring-1 ${className}`}
|
||||
{...props}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
@@ -129,6 +132,7 @@ type DropdownItemProps = {
|
||||
color?: ButtonColor;
|
||||
StartIcon?: IconName;
|
||||
CustomStartIcon?: React.ReactNode;
|
||||
kbd?: string;
|
||||
EndIcon?: IconName;
|
||||
href?: string;
|
||||
disabled?: boolean;
|
||||
@@ -161,15 +165,15 @@ export const DropdownItem = (props: DropdownItemProps) => {
|
||||
<ButtonOrLink
|
||||
{...rest}
|
||||
className={classNames(
|
||||
"hover:text-emphasis text-default inline-flex w-full items-center space-x-2 px-3 py-2 disabled:cursor-not-allowed",
|
||||
color === "destructive"
|
||||
? "hover:bg-error hover:text-red-700 dark:hover:text-red-100"
|
||||
: "hover:bg-subtle",
|
||||
"hover:text-emphasis text-default inline-flex w-full items-center space-x-1 rounded-lg p-2 disabled:cursor-not-allowed",
|
||||
color === "destructive" ? "hover:bg-error hover:text-error text-error" : "hover:bg-subtle",
|
||||
props.className
|
||||
)}>
|
||||
<>
|
||||
{CustomStartIcon || (StartIcon && <Icon name={StartIcon} className="h-4 w-4" />)}
|
||||
<div className={classNames("text-sm font-medium leading-5", childrenClassName)}>{children}</div>
|
||||
{CustomStartIcon || (StartIcon && <Icon name={StartIcon} className="mr-1 h-4 w-4" />)}
|
||||
<div className={classNames("w-fit text-sm font-medium leading-none", childrenClassName)}>
|
||||
{children}
|
||||
</div>
|
||||
{EndIcon && <Icon name={EndIcon} className="h-4 w-4" />}
|
||||
</>
|
||||
</ButtonOrLink>
|
||||
@@ -181,7 +185,7 @@ export const DropdownMenuSeparator = forwardRef<HTMLDivElement, DropdownMenuSepa
|
||||
({ className = "", ...props }, forwardedRef) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
className={classNames("bg-emphasis my-1 h-px", className)}
|
||||
className={classNames("bg-emphasis -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
|
||||
@@ -77,7 +77,7 @@ export const Editor = (props: TextEditorProps) => {
|
||||
return (
|
||||
<div className="editor rounded-md">
|
||||
<LexicalComposer initialConfig={{ ...editorConfig }}>
|
||||
<div className="editor-container hover:border-emphasis focus-within:ring-brand-default rounded-md p-0 transition focus-within:ring-2">
|
||||
<div className="editor-container hover:border-emphasis focus-within:ring-brand-default rounded-[10px] p-0 transition focus-within:ring-2">
|
||||
<ToolbarPlugin
|
||||
getText={props.getText}
|
||||
setText={props.setText}
|
||||
|
||||
@@ -55,13 +55,11 @@ export const AddVariablesDropdown = (props: IAddVariablesDropdown) => {
|
||||
type="button"
|
||||
className="w-full px-4 py-2"
|
||||
onClick={() => props.addVariable(t(`${variable}_variable`))}>
|
||||
<div className="sm:grid sm:grid-cols-2">
|
||||
<div className="mr-3 text-left md:col-span-1">
|
||||
<div className="flex flex-col">
|
||||
<div className="mr-text-left">
|
||||
{`{${t(`${variable}_variable`).toUpperCase().replace(/ /g, "_")}}`}
|
||||
</div>
|
||||
<div className="text-default hidden text-left sm:col-span-1 sm:flex">
|
||||
{t(`${variable}_info`)}
|
||||
</div>
|
||||
<div className="text-default hidden text-left sm:flex">{t(`${variable}_info`)}</div>
|
||||
</div>
|
||||
</button>
|
||||
</DropdownMenuItem>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
.editor-container {
|
||||
border-radius: 6px;
|
||||
border-radius: 10px;
|
||||
position: relative;
|
||||
line-height: 20px;
|
||||
font-weight: 400;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
import type { IconName } from "@calcom/ui";
|
||||
import {
|
||||
Button,
|
||||
Popover,
|
||||
@@ -26,7 +27,7 @@ interface FilterSelectProps {
|
||||
options: FilterOption[];
|
||||
selectedValue?: string | number | null;
|
||||
onChange: (value: string | number | null) => void;
|
||||
buttonIcon?: React.ReactNode;
|
||||
buttonIcon?: IconName;
|
||||
placeholder?: string;
|
||||
emptyText?: string;
|
||||
testId?: string;
|
||||
@@ -47,8 +48,7 @@ export function FilterSelect({
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button color="secondary" className="border-subtle rounded-md" data-testid={`${testId}-button`}>
|
||||
{buttonIcon}
|
||||
<Button color="secondary" data-testid={`${testId}-button`} StartIcon={buttonIcon}>
|
||||
{title}
|
||||
{selectedValue && (
|
||||
<div className="ml-2 hidden space-x-1 md:flex">
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Icon } from "../../icon";
|
||||
|
||||
type Props = InputHTMLAttributes<HTMLInputElement> & {
|
||||
label?: React.ReactNode;
|
||||
description: string;
|
||||
description?: string;
|
||||
descriptionAsLabel?: boolean;
|
||||
informationIconText?: string;
|
||||
error?: boolean;
|
||||
@@ -63,7 +63,7 @@ const CheckboxField = forwardRef<HTMLInputElement, Props>(
|
||||
</div>
|
||||
)}
|
||||
<div className="w-full">
|
||||
<div className="relative flex items-center">
|
||||
<div className="hover:bg-subtle relative flex w-fit items-center rounded-md p-1">
|
||||
{React.createElement(
|
||||
descriptionAsLabel ? "label" : "div",
|
||||
{
|
||||
@@ -94,14 +94,25 @@ const CheckboxField = forwardRef<HTMLInputElement, Props>(
|
||||
</div>
|
||||
{descriptionAsSafeHtml ? (
|
||||
<span
|
||||
className={classNames("text-sm", rest.descriptionClassName)}
|
||||
className={classNames(
|
||||
"text-default ml-2 text-sm",
|
||||
!label && "font-medium",
|
||||
rest.descriptionClassName
|
||||
)}
|
||||
// eslint-disable-next-line react/no-danger
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: markdownToSafeHTML(descriptionAsSafeHtml),
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<span className={classNames("text-sm", rest.descriptionClassName)}>{description}</span>
|
||||
<span
|
||||
className={classNames(
|
||||
"text-default ml-2 text-sm",
|
||||
!label && "font-medium",
|
||||
rest.descriptionClassName
|
||||
)}>
|
||||
{description}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -52,7 +52,7 @@ export function HintsOrErrors<T extends FieldValues = FieldValues>({
|
||||
<li
|
||||
key={key}
|
||||
data-testid="hint-error"
|
||||
className={error !== undefined ? (submitted ? "text-red-500" : "") : "text-green-600"}>
|
||||
className={error !== undefined ? (submitted ? "text-error" : "") : "text-green-600"}>
|
||||
{error !== undefined ? (
|
||||
submitted ? (
|
||||
<Icon
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Alert } from "../../alert";
|
||||
import { Icon } from "../../icon";
|
||||
import { Tooltip } from "../../tooltip";
|
||||
import { Input, InputField } from "../inputs/TextField";
|
||||
import { Input, InputField, inputStyles } from "../inputs/TextField";
|
||||
import { Label } from "./Label";
|
||||
import type { InputFieldProps } from "./types";
|
||||
|
||||
@@ -44,7 +44,6 @@ export const PasswordField = forwardRef<HTMLInputElement, InputFieldProps>(funct
|
||||
"addon-wrapper mb-0 ltr:border-r-0 ltr:pr-10 rtl:border-l-0 rtl:pl-10",
|
||||
props.className
|
||||
)}
|
||||
addOnFilled={false}
|
||||
addOnSuffix={
|
||||
<Tooltip content={textLabel}>
|
||||
<button
|
||||
@@ -98,12 +97,9 @@ type TextAreaProps = JSX.IntrinsicElements["textarea"];
|
||||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(function TextAreaInput(props, ref) {
|
||||
return (
|
||||
<textarea
|
||||
ref={ref}
|
||||
{...props}
|
||||
className={classNames(
|
||||
"hover:border-emphasis border-default bg-default placeholder:text-muted text-emphasis disabled:hover:border-default disabled:bg-subtle focus:ring-brand-default focus:border-subtle mb-2 block w-full rounded-md border px-3 py-2 text-sm transition focus:outline-none focus:ring-2 focus:ring-offset-1 disabled:cursor-not-allowed",
|
||||
props.className
|
||||
)}
|
||||
ref={ref}
|
||||
className={classNames(inputStyles(), "min-h-[80px] w-full", props.className)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -184,22 +180,17 @@ export const NumberInput = forwardRef<HTMLInputElement, InputFieldProps>(functio
|
||||
);
|
||||
});
|
||||
|
||||
export const FilterSearchField = forwardRef<HTMLInputElement, InputFieldProps>(function TextField(
|
||||
export const FilterSearchField = forwardRef<HTMLInputElement, InputFieldProps>(function PasswordField(
|
||||
props,
|
||||
ref
|
||||
) {
|
||||
return (
|
||||
<div
|
||||
dir="ltr"
|
||||
className="focus-within:ring-brand-default group relative mx-3 mb-1 mt-2.5 flex items-center rounded-md transition focus-within:outline-none focus-within:ring-2">
|
||||
<div className="addon-wrapper border-default [input:hover_+_&]:border-emphasis [input:hover_+_&]:border-l-default [&:has(+_input:hover)]:border-emphasis [&:has(+_input:hover)]:border-r-default flex h-7 items-center justify-center rounded-l-md border border-r-0 transition">
|
||||
<Icon name="search" className="ms-3 h-4 w-4" data-testid="search-icon" />
|
||||
</div>
|
||||
<Input
|
||||
ref={ref}
|
||||
className="disabled:bg-subtle disabled:hover:border-subtle !my-0 h-7 rounded-l-none border-l-0 !ring-0 disabled:cursor-not-allowed"
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
<InputField
|
||||
ref={ref}
|
||||
addOnLeading={<Icon name="search" className="h-4 w-4 stroke-[2.5px]" data-testid="search-icon" />}
|
||||
placeholder="Search"
|
||||
containerClassName="mx-3 mt-2"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -5,7 +5,7 @@ type InputErrorProp = {
|
||||
};
|
||||
|
||||
export const InputError = ({ message }: InputErrorProp) => (
|
||||
<div data-testid="field-error" className="text-gray mt-2 flex items-center gap-x-2 text-sm text-red-700">
|
||||
<div data-testid="field-error" className="text-error mt-2 flex items-center gap-x-2 text-sm">
|
||||
<div>
|
||||
<Icon name="info" className="h-3 w-3" />
|
||||
</div>
|
||||
|
||||
@@ -1,66 +1,94 @@
|
||||
"use client";
|
||||
|
||||
import { cva } from "class-variance-authority";
|
||||
import React, { forwardRef, useId, useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Icon } from "../../icon";
|
||||
import { Skeleton } from "../../skeleton";
|
||||
import { HintsOrErrors } from "./HintOrErrors";
|
||||
import { Label } from "./Label";
|
||||
import type { InputFieldProps, InputProps } from "./types";
|
||||
|
||||
export const inputStyles = cva(
|
||||
[
|
||||
// Base styles
|
||||
"block rounded-[10px] border",
|
||||
"leading-none font-normal",
|
||||
|
||||
// Colors
|
||||
"bg-default",
|
||||
"border-default",
|
||||
"text-default",
|
||||
"placeholder:text-muted",
|
||||
|
||||
// States
|
||||
"hover:border-emphasis",
|
||||
"focus:ring-0",
|
||||
"focus:shadow-outline-gray-focused",
|
||||
|
||||
// Disabled state
|
||||
"disabled:bg-subtle",
|
||||
"disabled:hover:border-default",
|
||||
"disabled:cursor-not-allowed",
|
||||
|
||||
// Shadow
|
||||
"shadow-outline-gray-rested",
|
||||
|
||||
// Transitions
|
||||
"transition",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
sm: "h-7 px-2 py-1 text-xs",
|
||||
md: "h-8 px-3 py-2 text-sm",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "md",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
|
||||
{ isFullWidth = true, ...props },
|
||||
{ isFullWidth = true, size = "md", className, ...props },
|
||||
ref
|
||||
) {
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
ref={ref}
|
||||
className={classNames(
|
||||
"hover:border-emphasis dark:focus:border-emphasis border-default bg-default placeholder:text-muted text-emphasis disabled:hover:border-default disabled:bg-subtle focus:ring-brand-default focus:border-subtle mb-2 block h-9 rounded-md border px-3 py-2 text-sm leading-4 transition focus:outline-none focus:ring-2 disabled:cursor-not-allowed",
|
||||
isFullWidth && "w-full",
|
||||
props.className
|
||||
)}
|
||||
className={classNames(inputStyles({ size }), isFullWidth && "w-full", className)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
type AddonProps = {
|
||||
children: React.ReactNode;
|
||||
isFilled?: boolean;
|
||||
className?: string;
|
||||
error?: boolean;
|
||||
onClickAddon?: () => void;
|
||||
size?: "sm" | "md";
|
||||
position?: "start" | "end";
|
||||
};
|
||||
|
||||
const Addon = ({ isFilled, children, className, error, onClickAddon }: AddonProps) => (
|
||||
const Addon = ({ children, className, error, onClickAddon, size = "md", position = "start" }: AddonProps) => (
|
||||
<div
|
||||
onClick={onClickAddon && onClickAddon}
|
||||
className={classNames(
|
||||
"addon-wrapper border-default [input:hover_+_&]:border-emphasis [input:hover_+_&]:border-l-default [&:has(+_input:hover)]:border-emphasis [&:has(+_input:hover)]:border-r-default h-9 border px-3 transition",
|
||||
isFilled && "bg-subtle",
|
||||
onClickAddon && "cursor-pointer disabled:hover:cursor-not-allowed",
|
||||
"flex flex-shrink-0 items-center justify-center whitespace-nowrap",
|
||||
onClickAddon && "pointer-events-auto cursor-pointer disabled:hover:cursor-not-allowed",
|
||||
className
|
||||
)}>
|
||||
<div
|
||||
<span
|
||||
className={classNames(
|
||||
"min-h-9 flex flex-col justify-center text-sm leading-7",
|
||||
error ? "text-error" : "text-default"
|
||||
"text-sm font-medium leading-none",
|
||||
error ? "text-error" : "text-muted peer-disabled:opacity-50"
|
||||
)}>
|
||||
<span
|
||||
className="flex max-w-2xl overflow-y-auto whitespace-nowrap"
|
||||
style={{
|
||||
WebkitOverflowScrolling: "touch",
|
||||
scrollbarWidth: "none",
|
||||
overflow: "-ms-scroll-chaining",
|
||||
msOverflowStyle: "-ms-autohiding-scrollbar",
|
||||
}}>
|
||||
{children}
|
||||
</span>
|
||||
</div>
|
||||
{children}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -79,7 +107,6 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
className,
|
||||
addOnLeading,
|
||||
addOnSuffix,
|
||||
addOnFilled = true,
|
||||
addOnClassname,
|
||||
inputIsFullWidth,
|
||||
hint,
|
||||
@@ -94,6 +121,7 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
t: __t,
|
||||
dataTestid,
|
||||
size,
|
||||
...passThrough
|
||||
} = props;
|
||||
|
||||
@@ -102,10 +130,8 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
{!!name && !noLabel && (
|
||||
<Skeleton
|
||||
as={Label}
|
||||
<Label
|
||||
htmlFor={id}
|
||||
loadingClassName="w-16"
|
||||
{...labelProps}
|
||||
className={classNames(labelClassName, labelSrOnly && "sr-only", props.error && "text-error")}>
|
||||
{label}
|
||||
@@ -113,32 +139,35 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
<span className="text-default ml-1 font-medium">*</span>
|
||||
) : null}
|
||||
{LockedIcon}
|
||||
</Skeleton>
|
||||
</Label>
|
||||
)}
|
||||
{addOnLeading || addOnSuffix ? (
|
||||
<div
|
||||
dir="ltr"
|
||||
className="focus-within:ring-brand-default group relative mb-1 flex items-center rounded-md transition focus-within:outline-none focus-within:ring-2">
|
||||
className={classNames(
|
||||
inputStyles({ size }),
|
||||
"group relative mb-1 flex min-w-0 items-center gap-1",
|
||||
"[&:focus-within]:border-subtle [&:focus-within]:ring-brand-default [&:focus-within]:ring-2",
|
||||
"[&:has(:disabled)]:bg-subtle [&:has(:disabled)]:hover:border-default [&:has(:disabled)]:cursor-not-allowed",
|
||||
inputIsFullWidth && "w-full"
|
||||
)}>
|
||||
{addOnLeading && (
|
||||
<Addon
|
||||
isFilled={addOnFilled}
|
||||
className={classNames("ltr:rounded-l-md rtl:rounded-r-md", addOnClassname)}>
|
||||
<Addon size={size ?? "md"} position="start" className={classNames(addOnClassname)}>
|
||||
{addOnLeading}
|
||||
</Addon>
|
||||
)}
|
||||
<Input
|
||||
data-testid={`${dataTestid}-input` ?? "input-field"}
|
||||
<input
|
||||
data-testid={dataTestid ? `${dataTestid}-input` : "input-field"}
|
||||
id={id}
|
||||
type={type}
|
||||
placeholder={placeholder}
|
||||
isFullWidth={inputIsFullWidth}
|
||||
className={classNames(
|
||||
className,
|
||||
"disabled:bg-subtle disabled:hover:border-subtle disabled:cursor-not-allowed",
|
||||
addOnLeading && "rounded-l-none border-l-0",
|
||||
addOnSuffix && "rounded-r-none border-r-0",
|
||||
type === "search" && "pr-8",
|
||||
"!my-0 !ring-0"
|
||||
"w-full min-w-0 truncate border-0 bg-transparent focus:outline-none focus:ring-0",
|
||||
"text-default rounded-lg text-sm font-medium leading-none",
|
||||
"placeholder:text-muted disabled:cursor-not-allowed disabled:bg-transparent",
|
||||
addOnLeading && "pl-0.5 pr-0",
|
||||
addOnSuffix && "pl-0",
|
||||
className
|
||||
)}
|
||||
{...passThrough}
|
||||
{...(type == "search" && {
|
||||
@@ -153,9 +182,10 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
/>
|
||||
{addOnSuffix && (
|
||||
<Addon
|
||||
size={size ?? "md"}
|
||||
position="end"
|
||||
onClickAddon={onClickAddon}
|
||||
isFilled={addOnFilled}
|
||||
className={classNames("ltr:rounded-r-md rtl:rounded-l-md", addOnClassname)}>
|
||||
className={classNames(addOnClassname)}>
|
||||
{addOnSuffix}
|
||||
</Addon>
|
||||
)}
|
||||
@@ -175,6 +205,7 @@ export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function
|
||||
id={id}
|
||||
type={type}
|
||||
placeholder={placeholder}
|
||||
size={size}
|
||||
className={classNames(
|
||||
className,
|
||||
"disabled:bg-subtle disabled:hover:border-subtle disabled:cursor-not-allowed"
|
||||
|
||||
+13
-9
@@ -1,28 +1,32 @@
|
||||
import type { ReactNode } from "react";
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
|
||||
import type { Input } from "./TextField";
|
||||
import type { inputStyles } from "./TextField";
|
||||
|
||||
export type InputFieldProps = {
|
||||
label?: ReactNode;
|
||||
label?: React.ReactNode;
|
||||
LockedIcon?: React.ReactNode;
|
||||
hint?: ReactNode;
|
||||
hint?: string;
|
||||
hintErrors?: string[];
|
||||
addOnLeading?: ReactNode;
|
||||
addOnSuffix?: ReactNode;
|
||||
addOnLeading?: React.ReactNode;
|
||||
addOnSuffix?: React.ReactNode;
|
||||
inputIsFullWidth?: boolean;
|
||||
addOnFilled?: boolean;
|
||||
addOnClassname?: string;
|
||||
error?: string;
|
||||
labelSrOnly?: boolean;
|
||||
containerClassName?: string;
|
||||
showAsteriskIndicator?: boolean;
|
||||
t?: (key: string) => string;
|
||||
className?: string;
|
||||
placeholder?: string;
|
||||
dataTestid?: string;
|
||||
noLabel?: boolean;
|
||||
onClickAddon?: () => void;
|
||||
} & React.ComponentProps<typeof Input> & {
|
||||
} & InputProps & {
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
labelClassName?: string;
|
||||
};
|
||||
|
||||
export type InputProps = JSX.IntrinsicElements["input"] & { isFullWidth?: boolean };
|
||||
export type InputProps = Omit<JSX.IntrinsicElements["input"], "size" | "ref"> &
|
||||
VariantProps<typeof inputStyles> & {
|
||||
isFullWidth?: boolean;
|
||||
};
|
||||
@@ -7,13 +7,19 @@ import cx from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Label } from "../inputs/Label";
|
||||
import { inputStyles } from "../inputs/TextField";
|
||||
import { getReactSelectProps } from "./selectTheme";
|
||||
|
||||
export type SelectProps<
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
> = Props<Option, IsMulti, Group> & { variant?: "default" | "checkbox"; "data-testid"?: string };
|
||||
> = Props<Option, IsMulti, Group> & {
|
||||
variant?: "default" | "checkbox";
|
||||
"data-testid"?: string;
|
||||
size?: "sm" | "md";
|
||||
grow?: boolean;
|
||||
};
|
||||
|
||||
export const Select = <
|
||||
Option,
|
||||
@@ -22,6 +28,8 @@ export const Select = <
|
||||
>({
|
||||
components,
|
||||
variant = "default",
|
||||
size = "md",
|
||||
grow,
|
||||
...props
|
||||
}: SelectProps<Option, IsMulti, Group> & {
|
||||
innerClassNames?: {
|
||||
@@ -43,17 +51,26 @@ export const Select = <
|
||||
});
|
||||
}, [components, menuPlacement]);
|
||||
|
||||
const hasMultiLastIcons = props.isMulti || props.isLoading || props.isClearable;
|
||||
|
||||
// Annoyingly if we update styles here we have to update timezone select too
|
||||
// We cant create a generate function for this as we can't force state changes - onSelect styles dont change for example
|
||||
return (
|
||||
<ReactSelect
|
||||
{...reactSelectProps}
|
||||
menuPlacement={menuPlacement}
|
||||
styles={{
|
||||
control: (base) => ({
|
||||
...base,
|
||||
minHeight: size === "sm" ? "28px" : "36px",
|
||||
height: grow ? "h-auto " : size === "sm" ? "28px" : "36px",
|
||||
}),
|
||||
}}
|
||||
classNames={{
|
||||
input: () => cx("text-emphasis", innerClassNames?.input),
|
||||
option: (state) =>
|
||||
cx(
|
||||
"bg-default flex cursor-pointer justify-between py-2.5 px-3 rounded-none text-default ",
|
||||
"bg-default flex cursor-pointer justify-between py-1.5 px-2 rounded-md text-default items-center",
|
||||
state.isFocused && "bg-subtle",
|
||||
state.isDisabled && "bg-muted",
|
||||
state.isSelected && "bg-emphasis text-default",
|
||||
@@ -63,41 +80,49 @@ export const Select = <
|
||||
dropdownIndicator: () => "text-default",
|
||||
control: (state) =>
|
||||
cx(
|
||||
"bg-default border-default !min-h-9 h-9 text-sm leading-4 placeholder:text-sm placeholder:font-normal dark:focus:border-emphasis focus-within:outline-none focus-within:ring-2 focus-within:ring-brand-default hover:border-emphasis rounded-md transition border",
|
||||
inputStyles({ size }),
|
||||
state.isMulti
|
||||
? variant === "checkbox"
|
||||
? "px-3 py-2 h-fit"
|
||||
? "px-3 h-fit"
|
||||
: state.hasValue
|
||||
? "p-1 h-fit"
|
||||
: "px-3 py-2 h-fit"
|
||||
: "py-2 px-3",
|
||||
: "px-3 h-fit"
|
||||
: size === "sm"
|
||||
? "h-7 px-2"
|
||||
: "h-9 px-3",
|
||||
props.isDisabled && "bg-subtle",
|
||||
size === "sm" ? "rounded-md" : "rounded-[10px]",
|
||||
"[&:focus-within]:border-emphasis [&:focus-within]:shadow-outline-gray-focused [&:focus-within]:ring-0 !flex",
|
||||
innerClassNames?.control
|
||||
),
|
||||
singleValue: () => cx("text-emphasis placeholder:text-muted", innerClassNames?.singleValue),
|
||||
singleValue: () => cx("text-default placeholder:text-muted", innerClassNames?.singleValue),
|
||||
valueContainer: () =>
|
||||
cx("text-emphasis placeholder:text-muted flex gap-1", innerClassNames?.valueContainer),
|
||||
cx("text-default placeholder:text-muted flex gap-1", innerClassNames?.valueContainer),
|
||||
multiValue: () =>
|
||||
cx(
|
||||
"bg-subtle text-default rounded-md py-1.5 px-2 flex items-center text-sm leading-tight",
|
||||
innerClassNames?.multiValue
|
||||
"font-medium inline-flex items-center justify-center rounded bg-emphasis text-emphasis leading-none text-xs",
|
||||
size == "sm" ? "px-1.5 py-[1px] rounded-md" : "py-1 px-1.5 leading-none rounded-lg"
|
||||
),
|
||||
menu: () =>
|
||||
cx(
|
||||
" rounded-md bg-default text-sm leading-4 text-default mt-1 border border-subtle",
|
||||
"rounded-lg bg-default text-sm leading-4 text-default mt-1 border border-subtle shadow-dropdown p-1",
|
||||
innerClassNames?.menu
|
||||
),
|
||||
groupHeading: () => "leading-none text-xs uppercase text-default pl-2.5 pt-4 pb-2",
|
||||
menuList: () => cx("scroll-bar scrollbar-track-w-20 rounded-md", innerClassNames?.menuList),
|
||||
groupHeading: () => "leading-none text-xs text-muted p-2 font-medium ml-1",
|
||||
menuList: () =>
|
||||
cx(
|
||||
"scroll-bar scrollbar-track-w-20 rounded-md flex flex-col space-y-[1px]",
|
||||
innerClassNames?.menuList
|
||||
),
|
||||
indicatorsContainer: (state) =>
|
||||
cx(
|
||||
state.selectProps.menuIsOpen
|
||||
? state.isMulti
|
||||
? hasMultiLastIcons
|
||||
? "[&>*:last-child]:rotate-180 [&>*:last-child]:transition-transform"
|
||||
: "rotate-180 transition-transform"
|
||||
: "text-default" // Woo it adds another SVG here on multi for some reason
|
||||
),
|
||||
multiValueRemove: () => "text-default py-auto ml-2",
|
||||
multiValueRemove: () => "text-default py-auto",
|
||||
...classNames,
|
||||
}}
|
||||
{...restProps}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
"use client";
|
||||
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import { useState } from "react";
|
||||
|
||||
import { Badge, Button } from "@calcom/ui";
|
||||
|
||||
import { inputStyles, TextField } from "../inputs/TextField";
|
||||
import { Slider } from "./index";
|
||||
|
||||
interface RangeSliderPopoverProps {
|
||||
triggerText: string;
|
||||
value: number[];
|
||||
onChange: (value: number[]) => void;
|
||||
min: number;
|
||||
max: number;
|
||||
step?: number;
|
||||
badgeVariant?: "default" | "success" | "gray" | "warning" | "orange" | "red";
|
||||
badgeSuffix?: string;
|
||||
inputSuffix?: string;
|
||||
inputLeading?: string;
|
||||
}
|
||||
|
||||
export const RangeSliderPopover = ({
|
||||
triggerText,
|
||||
value,
|
||||
onChange,
|
||||
min,
|
||||
max,
|
||||
step = 1,
|
||||
badgeVariant = "default",
|
||||
badgeSuffix,
|
||||
inputSuffix,
|
||||
inputLeading,
|
||||
}: RangeSliderPopoverProps) => {
|
||||
const [internalValue, setInternalValue] = useState<number[]>(value);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const handleReset = () => {
|
||||
setInternalValue([min, max]);
|
||||
};
|
||||
|
||||
const handleApply = () => {
|
||||
onChange(internalValue);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover.Root open={open} onOpenChange={setOpen}>
|
||||
<Popover.Trigger asChild>
|
||||
<button className={inputStyles()}>
|
||||
<span className="text-subtle text-sm font-medium leading-none">{triggerText}:</span>
|
||||
{value && (
|
||||
<Badge variant={badgeVariant} className="ml-2">
|
||||
{value[0]} - {value[1]} {badgeSuffix}
|
||||
</Badge>
|
||||
)}
|
||||
</button>
|
||||
</Popover.Trigger>
|
||||
<Popover.Portal>
|
||||
<Popover.Content
|
||||
align="start"
|
||||
className="border-subtle shadow-dropdown bg-default z-50 mt-2 w-72 rounded-lg border-[1px] px-4 pb-3 pt-4 font-[family-name:var(--font-inter)]">
|
||||
<div className="mb-4">
|
||||
<Slider min={min} max={max} step={step} value={internalValue} onValueChange={setInternalValue} />
|
||||
</div>
|
||||
<div className="mb-4 flex items-center justify-between gap-2">
|
||||
<TextField
|
||||
labelSrOnly
|
||||
name="start"
|
||||
type="number"
|
||||
min={min}
|
||||
max={internalValue[1]}
|
||||
value={internalValue[0]}
|
||||
onChange={(e) => {
|
||||
const newValue = parseInt(e.target.value);
|
||||
if (!isNaN(newValue) && newValue >= min && newValue <= internalValue[1]) {
|
||||
setInternalValue([newValue, internalValue[1]]);
|
||||
}
|
||||
}}
|
||||
addOnLeading={inputLeading ? inputLeading : undefined}
|
||||
addOnSuffix={inputSuffix ? inputSuffix : undefined}
|
||||
containerClassName="w-full"
|
||||
/>
|
||||
<TextField
|
||||
labelSrOnly
|
||||
name="end"
|
||||
type="number"
|
||||
min={internalValue[0]}
|
||||
max={max}
|
||||
value={internalValue[1]}
|
||||
onChange={(e) => {
|
||||
const newValue = parseInt(e.target.value);
|
||||
if (!isNaN(newValue) && newValue >= internalValue[0] && newValue <= max) {
|
||||
setInternalValue([internalValue[0], newValue]);
|
||||
}
|
||||
}}
|
||||
addOnLeading={inputLeading ? inputLeading : undefined}
|
||||
addOnSuffix={inputSuffix ? inputSuffix : undefined}
|
||||
containerClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="-mx-4">
|
||||
<hr className="border-subtle" />
|
||||
<div className="mt-3 flex items-center justify-end gap-2 px-4">
|
||||
<Button color="minimal" size="sm" onClick={handleReset}>
|
||||
Reset
|
||||
</Button>
|
||||
<Button color="secondary" size="sm" onClick={handleApply}>
|
||||
Apply
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Popover.Content>
|
||||
</Popover.Portal>
|
||||
</Popover.Root>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import * as SliderPrimitive from "@radix-ui/react-slider";
|
||||
import * as React from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
const Slider = React.forwardRef<
|
||||
React.ElementRef<typeof SliderPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SliderPrimitive.Root
|
||||
ref={ref}
|
||||
className={classNames("relative flex w-full touch-none select-none items-center", className)}
|
||||
{...props}>
|
||||
<SliderPrimitive.Track className="bg-subtle border-subtle relative h-2 w-full grow overflow-hidden rounded-full border-[1px]">
|
||||
<SliderPrimitive.Range className="bg-brand-default absolute h-full" />
|
||||
</SliderPrimitive.Track>
|
||||
<SliderPrimitive.Thumb className="border-subtle bg-brand-default ring-offset-background focus-visible:ring-ring block h-4 w-4 rounded-full border-2 border-[1px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
|
||||
<SliderPrimitive.Thumb className="border-subtle bg-brand-default ring-offset-background focus-visible:ring-ring block h-4 w-4 rounded-full border-2 border-[1px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
|
||||
</SliderPrimitive.Root>
|
||||
));
|
||||
Slider.displayName = SliderPrimitive.Root.displayName;
|
||||
|
||||
export { Slider };
|
||||
@@ -20,45 +20,53 @@ const Switch = (
|
||||
fitToHeight?: boolean;
|
||||
disabled?: boolean;
|
||||
tooltip?: string;
|
||||
small?: boolean;
|
||||
labelOnLeading?: boolean;
|
||||
size?: "base" | "sm";
|
||||
classNames?: {
|
||||
container?: string;
|
||||
thumb?: string;
|
||||
};
|
||||
LockedIcon?: React.ReactNode;
|
||||
padding?: boolean;
|
||||
}
|
||||
) => {
|
||||
const { label, fitToHeight, classNames, small, labelOnLeading, LockedIcon, ...primitiveProps } = props;
|
||||
const {
|
||||
label,
|
||||
fitToHeight,
|
||||
classNames,
|
||||
labelOnLeading,
|
||||
LockedIcon,
|
||||
padding,
|
||||
size = "base",
|
||||
...primitiveProps
|
||||
} = props;
|
||||
const id = useId();
|
||||
const isChecked = props.checked || props.defaultChecked;
|
||||
return (
|
||||
<Wrapper tooltip={props.tooltip}>
|
||||
<div
|
||||
className={cx(
|
||||
"flex h-auto w-auto flex-row items-center",
|
||||
"flex h-auto w-fit flex-row items-center",
|
||||
fitToHeight && "h-fit",
|
||||
labelOnLeading && "flex-row-reverse",
|
||||
padding && "hover:bg-subtle rounded-md p-1.5",
|
||||
classNames?.container
|
||||
)}>
|
||||
{LockedIcon && <div className="mr-2">{LockedIcon}</div>}
|
||||
<PrimitiveSwitch.Root
|
||||
{...primitiveProps}
|
||||
id={id}
|
||||
className={cx(
|
||||
isChecked ? "bg-brand-default dark:bg-brand-emphasis" : "bg-emphasis",
|
||||
primitiveProps.disabled && "cursor-not-allowed",
|
||||
small ? "h-4 w-[27px]" : "h-5 w-[34px]",
|
||||
"focus:ring-brand-default rounded-full shadow-none transition focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1",
|
||||
props.className
|
||||
)}
|
||||
{...primitiveProps}>
|
||||
size === "sm" ? "h-3 w-[20px]" : "h-4 w-[28px]",
|
||||
"focus:ring-brand-default data-[state=checked]:bg-brand-default dark:data-[state=checked]:bg-brand-emphasis data-[state=unchecked]:bg-emphasis peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-inner transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
size === "sm" ? "h-4 w-7" : "h-6 w-11",
|
||||
classNames?.container
|
||||
)}>
|
||||
<PrimitiveSwitch.Thumb
|
||||
id={id}
|
||||
className={cx(
|
||||
small
|
||||
? "h-[10px] w-[10px] ltr:translate-x-[2px] rtl:-translate-x-[2px] ltr:[&[data-state='checked']]:translate-x-[13px] rtl:[&[data-state='checked']]:-translate-x-[13px]"
|
||||
: "h-[14px] w-[14px] ltr:translate-x-[4px] rtl:-translate-x-[4px] ltr:[&[data-state='checked']]:translate-x-[17px] rtl:[&[data-state='checked']]:-translate-x-[17px]",
|
||||
"block rounded-full transition will-change-transform",
|
||||
isChecked ? "bg-brand-accent shadow-inner" : "bg-default",
|
||||
"bg-default data-[state=checked]:bg-brand-accent shadow-switch-thumb pointer-events-none block rounded-full shadow-lg ring-0 transition-transform",
|
||||
size === "sm"
|
||||
? "h-3 w-3 data-[state=checked]:translate-x-3 data-[state=unchecked]:translate-x-0"
|
||||
: "h-5 w-5 data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0",
|
||||
classNames?.thumb
|
||||
)}
|
||||
/>
|
||||
@@ -67,7 +75,8 @@ const Switch = (
|
||||
<Label.Root
|
||||
htmlFor={id}
|
||||
className={cx(
|
||||
"text-emphasis ms-2 align-text-top text-sm font-medium",
|
||||
"text-emphasis align-text-top font-medium",
|
||||
size === "sm" ? "m-1 text-xs" : "m-2 text-sm",
|
||||
primitiveProps.disabled ? "cursor-not-allowed opacity-25" : "cursor-pointer",
|
||||
labelOnLeading && "flex-1"
|
||||
)}>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { filterBySearchText, addTimezonesToDropdown, handleOptionLabel } from "@
|
||||
import type { Timezones } from "@calcom/lib/timezone";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { inputStyles } from "../inputs/TextField";
|
||||
import { getReactSelectProps } from "../select";
|
||||
|
||||
const SELECT_SEARCH_DATA: Timezones = [
|
||||
@@ -37,6 +38,8 @@ const SELECT_SEARCH_DATA: Timezones = [
|
||||
export type TimezoneSelectProps = SelectProps & {
|
||||
variant?: "default" | "minimal";
|
||||
timezoneSelectCustomClassname?: string;
|
||||
size?: "sm" | "md";
|
||||
grow?: boolean;
|
||||
};
|
||||
export function TimezoneSelect(props: TimezoneSelectProps) {
|
||||
const { data = [], isPending } = trpc.viewer.timezones.cityTimezones.useQuery(
|
||||
@@ -61,7 +64,10 @@ export type TimezoneSelectComponentProps = SelectProps & {
|
||||
isPending: boolean;
|
||||
data?: Timezones;
|
||||
timezoneSelectCustomClassname?: string;
|
||||
size?: "sm" | "md";
|
||||
grow?: boolean;
|
||||
};
|
||||
|
||||
export function TimezoneSelectComponent({
|
||||
className,
|
||||
classNames: timezoneClassNames,
|
||||
@@ -70,6 +76,8 @@ export function TimezoneSelectComponent({
|
||||
variant = "default",
|
||||
isPending,
|
||||
value,
|
||||
size = "md",
|
||||
grow = false,
|
||||
...props
|
||||
}: TimezoneSelectComponentProps) {
|
||||
const data = [...(props.data || []), ...SELECT_SEARCH_DATA];
|
||||
@@ -103,6 +111,13 @@ export function TimezoneSelectComponent({
|
||||
...(props.data ? addTimezonesToDropdown(data) : {}),
|
||||
...addTimezonesToDropdown(additionalTimezones),
|
||||
}}
|
||||
styles={{
|
||||
control: (base) => ({
|
||||
...base,
|
||||
minHeight: size === "sm" ? "28px" : "36px",
|
||||
height: grow ? "h-auto " : size === "sm" ? "28px" : "36px",
|
||||
}),
|
||||
}}
|
||||
onInputChange={handleInputChange}
|
||||
{...props}
|
||||
formatOptionLabel={(option) => (
|
||||
@@ -118,19 +133,26 @@ export function TimezoneSelectComponent({
|
||||
),
|
||||
option: (state) =>
|
||||
classNames(
|
||||
"bg-default flex !cursor-pointer justify-between py-2.5 px-3 rounded-none text-default ",
|
||||
"bg-default flex cursor-pointer justify-between py-2.5 px-3 rounded-md text-default ",
|
||||
state.isFocused && "bg-subtle",
|
||||
state.isSelected && "bg-emphasis",
|
||||
state.isDisabled && "bg-muted",
|
||||
state.isSelected && "bg-emphasis text-default",
|
||||
timezoneClassNames?.option && timezoneClassNames.option(state)
|
||||
),
|
||||
placeholder: (state) => classNames("text-muted", state.isFocused && "hidden"),
|
||||
dropdownIndicator: () => "text-default",
|
||||
control: (state) =>
|
||||
classNames(
|
||||
"!cursor-pointer",
|
||||
variant === "default"
|
||||
? "px-3 py-2 bg-default border-default !min-h-9 text-sm leading-4 placeholder:text-sm placeholder:font-normal focus-within:ring-2 focus-within:ring-emphasis hover:border-emphasis rounded-md border gap-1"
|
||||
: "text-sm gap-1",
|
||||
inputStyles({ size }),
|
||||
state.isMulti
|
||||
? state.hasValue
|
||||
? "p-1 h-fit"
|
||||
: "px-3 h-fit"
|
||||
: size === "sm"
|
||||
? "h-7 px-2"
|
||||
: "h-9 px-3",
|
||||
props.isDisabled && "bg-subtle",
|
||||
"rounded-[10px]",
|
||||
timezoneClassNames?.control && timezoneClassNames.control(state)
|
||||
),
|
||||
singleValue: (state) =>
|
||||
|
||||
@@ -13,6 +13,7 @@ interface ToggleGroupProps extends Omit<RadixToggleGroup.ToggleGroupSingleProps,
|
||||
iconLeft?: ReactNode;
|
||||
}[];
|
||||
isFullWidth?: boolean;
|
||||
orientation?: "horizontal" | "vertical";
|
||||
}
|
||||
|
||||
const OptionalTooltipWrapper = ({
|
||||
@@ -36,6 +37,7 @@ export const ToggleGroup = ({
|
||||
options,
|
||||
onValueChange,
|
||||
isFullWidth,
|
||||
orientation = "horizontal",
|
||||
customClassNames,
|
||||
...props
|
||||
}: ToggleGroupProps & { customClassNames?: string }) => {
|
||||
@@ -44,9 +46,12 @@ export const ToggleGroup = ({
|
||||
<RadixToggleGroup.Root
|
||||
type="single"
|
||||
{...props}
|
||||
orientation={orientation}
|
||||
onValueChange={onValueChange}
|
||||
className={classNames(
|
||||
`min-h-9 border-default bg-default relative inline-flex gap-0.5 rounded-md border p-1 rtl:flex-row-reverse`,
|
||||
`border-default bg-default relative rounded-md border p-1`,
|
||||
orientation === "horizontal" && "min-h-9 inline-flex gap-0.5 rtl:flex-row-reverse",
|
||||
orientation === "vertical" && "flex w-fit flex-col gap-0.5",
|
||||
props.className,
|
||||
isFullWidth && "w-full",
|
||||
customClassNames
|
||||
@@ -64,8 +69,13 @@ export const ToggleGroup = ({
|
||||
: "text-default [&[aria-checked='false']]:hover:text-emphasis",
|
||||
isFullWidth && "w-full"
|
||||
)}>
|
||||
<div className="item-center flex justify-center ">
|
||||
{option.iconLeft && <span className="mr-2 flex h-4 w-4 items-center">{option.iconLeft}</span>}
|
||||
<div
|
||||
className={classNames(
|
||||
"flex items-center gap-2",
|
||||
orientation === "horizontal" && "justify-center",
|
||||
orientation === "vertical" && "justify-start"
|
||||
)}>
|
||||
{option.iconLeft && <span className="flex h-4 w-4 items-center">{option.iconLeft}</span>}
|
||||
{option.label}
|
||||
</div>
|
||||
</RadixToggleGroup.Item>
|
||||
|
||||
@@ -118,9 +118,10 @@ describe("Tests for WizardForm component", () => {
|
||||
test("Should disable 'Next step' button if current step navigation is not enabled", async () => {
|
||||
currentStepNavigation = 1;
|
||||
const { nextLabel } = props;
|
||||
const { getByText } = renderComponent();
|
||||
const { getByRole } = renderComponent();
|
||||
|
||||
expect(getByText(nextLabel)).toBeDisabled();
|
||||
const nextButton = getByRole("button", { name: nextLabel });
|
||||
expect(nextButton).toBeDisabled();
|
||||
});
|
||||
|
||||
test("Should handle when navigation is disabled", async () => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import type { NextSeoProps } from "next-seo";
|
||||
import { NextSeo } from "next-seo";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
@@ -1,2 +1,101 @@
|
||||
/* TODO: Implement NavigationItem */
|
||||
export {};
|
||||
import { cva } from "class-variance-authority";
|
||||
import { Fragment } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import { ButtonOrLink } from "../dropdown";
|
||||
import { Icon } from "../icon";
|
||||
import type { IconName } from "../icon";
|
||||
|
||||
export type NavigationItemType = {
|
||||
isLastChild?: boolean;
|
||||
isExpanded?: boolean;
|
||||
onToggle?: () => void;
|
||||
name: string;
|
||||
href?: string;
|
||||
isLoading?: boolean;
|
||||
badge?: React.ReactNode;
|
||||
icon?: IconName;
|
||||
child?: NavigationItemType[];
|
||||
onlyMobile?: boolean;
|
||||
onlyDesktop?: boolean;
|
||||
moreOnMobile?: boolean;
|
||||
isCurrent?: boolean;
|
||||
};
|
||||
|
||||
const navigationItemStyles = cva(
|
||||
"text-default group flex items-center rounded-[10px] p-2 text-sm font-medium transition hover:bg-subtle hover:text-emphasis",
|
||||
{
|
||||
variants: {
|
||||
isChild: {
|
||||
true: "[&[aria-current='page']]:text-emphasis [&[aria-current='page']]:bg-emphasis hidden h-8 ml-16 lg:flex lg:ml-10 relative before:absolute before:left-[-24px] before:top-[-0.5rem] before:h-[calc(100%+0.5rem)] before:w-0.5 before:bg-subtle before:content-[''] [&:first-child]:before:rounded-t-full [&:last-child]:before:rounded-b-full",
|
||||
false: "[&[aria-current='page']]:text-emphasis mt-0.5 text-sm",
|
||||
},
|
||||
hasChild: {
|
||||
true: "[&[aria-current='page']]:!bg-transparent relative after:absolute after:left-[-24px] after:top-[1.5rem] after:h-[calc(100%-1.5rem)] after:w-0.5 after:bg-subtle after:content-[''] [&:first-child]:after:rounded-t-full [&:last-child]:after:rounded-b-full",
|
||||
false: "[&[aria-current='page']]:bg-subtle",
|
||||
},
|
||||
isFirstChild: {
|
||||
true: "mt-0",
|
||||
false: "mt-px",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
isChild: false,
|
||||
hasChild: false,
|
||||
isFirstChild: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const Label = ({ children }: { children: React.ReactNode }) => {
|
||||
return <span className="text-default ml-3">{children}</span>;
|
||||
};
|
||||
|
||||
const NavigationItemComponent = ({
|
||||
item,
|
||||
isChild,
|
||||
index,
|
||||
}: {
|
||||
item: NavigationItemType;
|
||||
isChild?: boolean;
|
||||
index?: number;
|
||||
}) => {
|
||||
return (
|
||||
<Fragment>
|
||||
<ButtonOrLink
|
||||
data-test-id={item.name}
|
||||
href={item.href}
|
||||
className={navigationItemStyles({
|
||||
isChild,
|
||||
hasChild: !!item.child,
|
||||
isFirstChild: isChild && index === 0,
|
||||
})}
|
||||
aria-current={item.isCurrent ? "page" : undefined}
|
||||
onClick={item.onToggle}>
|
||||
{item.icon && (
|
||||
<Icon
|
||||
name={item.isLoading ? "rotate-cw" : item.icon}
|
||||
className={classNames(
|
||||
"text-subtle mr-2 h-4 w-4 flex-shrink-0 rtl:ml-2 md:ltr:mx-auto lg:ltr:mr-2",
|
||||
item.isLoading && "animate-spin"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
aria-current={item.isCurrent ? "page" : undefined}
|
||||
/>
|
||||
)}
|
||||
<span className="text-emphasis hidden w-full justify-between truncate text-ellipsis lg:flex">
|
||||
{item.name}
|
||||
{item.badge && item.badge}
|
||||
</span>
|
||||
</ButtonOrLink>
|
||||
{item.child &&
|
||||
item.isExpanded &&
|
||||
item.child.map((childItem, childIndex) => (
|
||||
<NavigationItem key={childItem.name} item={childItem} isChild index={childIndex} />
|
||||
))}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export const NavigationItem = Object.assign(NavigationItemComponent, { Label });
|
||||
@@ -1,13 +1,11 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useUrlMatchesCurrentUrl } from "@calcom/lib/hooks/useUrlMatchesCurrentUrl";
|
||||
|
||||
import { Avatar } from "../../avatar";
|
||||
import { Icon } from "../../icon";
|
||||
import type { IconName } from "../../icon";
|
||||
import { SkeletonText } from "../../skeleton";
|
||||
|
||||
export type HorizontalTabItemProps = {
|
||||
name: string;
|
||||
@@ -21,6 +19,7 @@ export type HorizontalTabItemProps = {
|
||||
avatar?: string;
|
||||
onClick?: (name: string) => void;
|
||||
isActive?: boolean;
|
||||
"data-testid"?: string;
|
||||
};
|
||||
|
||||
const HorizontalTabItem = function ({
|
||||
@@ -31,8 +30,6 @@ const HorizontalTabItem = function ({
|
||||
avatar,
|
||||
...props
|
||||
}: HorizontalTabItemProps) {
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
|
||||
const isCurrent = useUrlMatchesCurrentUrl(href) || props?.isActive;
|
||||
|
||||
return (
|
||||
@@ -47,32 +44,24 @@ const HorizontalTabItem = function ({
|
||||
href={href}
|
||||
shallow={linkShallow}
|
||||
scroll={linkScroll}
|
||||
aria-disabled={props.disabled ? "true" : undefined}
|
||||
className={classNames(
|
||||
isCurrent ? "bg-emphasis text-emphasis" : "hover:bg-subtle hover:text-emphasis text-default",
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-[6px] p-2 text-sm font-medium leading-4 transition md:mb-0",
|
||||
isCurrent ? "bg-subtle text-emphasis" : "hover:bg-muted hover:text-default text-subtle",
|
||||
"inline-flex h-fit items-center justify-center whitespace-nowrap rounded-md p-2 text-sm font-medium leading-none transition md:mb-0",
|
||||
props.disabled && "pointer-events-none !opacity-30",
|
||||
props.className
|
||||
)}
|
||||
target={props.target ? props.target : undefined}
|
||||
data-testid={`horizontal-tab-${name}`}
|
||||
data-testid={`horizontal-tab-${props["data-testid"]}`}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{props.icon && (
|
||||
<Icon
|
||||
name={props.icon}
|
||||
className={classNames(
|
||||
isCurrent ? "text-emphasis" : "group-hover:text-subtle text-muted",
|
||||
"-ml-0.5 hidden h-4 w-4 ltr:mr-2 rtl:ml-2 sm:inline-block"
|
||||
)}
|
||||
className={classNames("-ml-0.5 me-2 hidden h-4 w-4 text-inherit sm:inline-block")}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
{isLocaleReady ? (
|
||||
<div className="flex items-center gap-x-2">
|
||||
{avatar && <Avatar size="sm" imageSrc={avatar} alt="avatar" />} {t(name)}
|
||||
</div>
|
||||
) : (
|
||||
<SkeletonText className="h-4 w-24" />
|
||||
)}
|
||||
{avatar && <Avatar size="xs" imageSrc={avatar} alt="avatar" className="-ml-0.5 me-1" />} {name}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,19 +10,13 @@ export interface NavTabProps {
|
||||
|
||||
const HorizontalTabs = function ({ tabs, linkShallow, linkScroll, actions, ...props }: NavTabProps) {
|
||||
return (
|
||||
<div className="mb-4 h-9 max-w-full lg:mb-5">
|
||||
<div className="mb-4 max-w-full lg:mb-5">
|
||||
<nav
|
||||
className="no-scrollbar flex max-h-9 space-x-1 overflow-x-scroll rounded-md"
|
||||
className="no-scrollbar flex space-x-0.5 overflow-x-scroll rounded-md"
|
||||
aria-label="Tabs"
|
||||
{...props}>
|
||||
{tabs.map((tab, idx) => (
|
||||
<HorizontalTabItem
|
||||
className="px-4 py-2.5"
|
||||
{...tab}
|
||||
key={idx}
|
||||
linkShallow={linkShallow}
|
||||
linkScroll={linkScroll}
|
||||
/>
|
||||
<HorizontalTabItem {...tab} key={idx} linkShallow={linkShallow} linkScroll={linkScroll} />
|
||||
))}
|
||||
</nav>
|
||||
{actions && actions}
|
||||
|
||||
@@ -2,12 +2,10 @@ import Link from "next/link";
|
||||
import { Fragment } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useUrlMatchesCurrentUrl } from "@calcom/lib/hooks/useUrlMatchesCurrentUrl";
|
||||
|
||||
import { Icon } from "../../icon";
|
||||
import type { IconName } from "../../icon";
|
||||
import { Skeleton } from "../../skeleton";
|
||||
|
||||
export type VerticalTabItemProps = {
|
||||
name: string;
|
||||
@@ -28,6 +26,7 @@ export type VerticalTabItemProps = {
|
||||
iconClassName?: string;
|
||||
onClick?: (name: string) => void;
|
||||
isActive?: boolean;
|
||||
"data-testid"?: string;
|
||||
};
|
||||
|
||||
const VerticalTabItem = ({
|
||||
@@ -40,7 +39,6 @@ const VerticalTabItem = ({
|
||||
linkScroll,
|
||||
...props
|
||||
}: VerticalTabItemProps) => {
|
||||
const { t } = useLocale();
|
||||
const isCurrent = useUrlMatchesCurrentUrl(href) || props?.isActive;
|
||||
|
||||
return (
|
||||
@@ -58,42 +56,34 @@ const VerticalTabItem = ({
|
||||
href={href}
|
||||
shallow={linkShallow}
|
||||
scroll={linkScroll}
|
||||
aria-disabled={props.disabled ? "true" : undefined}
|
||||
target={props.isExternalLink ? "_blank" : "_self"}
|
||||
className={classNames(
|
||||
props.textClassNames || "text-default text-sm font-medium leading-none",
|
||||
"min-h-7 hover:bg-subtle [&[aria-current='page']]:bg-emphasis [&[aria-current='page']]:text-emphasis group-hover:text-default group flex w-64 flex-row items-center rounded-md px-3 py-2 transition",
|
||||
"hover:bg-subtle [&[aria-current='page']]:bg-subtle [&[aria-current='page']]:text-emphasis group-hover:text-default group flex w-full flex-row items-center rounded-md p-2 transition",
|
||||
props.disabled && "pointer-events-none !opacity-30",
|
||||
(isChild || !props.icon) && "ml-7 w-auto ltr:mr-5 rtl:ml-5",
|
||||
!info ? "h-6" : "h-auto",
|
||||
(isChild || !props.icon) && "ml-7",
|
||||
props.className
|
||||
)}
|
||||
data-testid={`vertical-tab-${name}`}
|
||||
data-testid={`vertical-tab-${props["data-testid"]}`}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{props.icon && (
|
||||
<Icon
|
||||
name={props.icon}
|
||||
className={classNames(
|
||||
"mr-2 h-[16px] w-[16px] stroke-[2px] ltr:mr-2 rtl:ml-2 md:mt-0",
|
||||
props.iconClassName
|
||||
)}
|
||||
className={classNames("me-2 h-4 w-4", props.iconClassName)}
|
||||
data-testid="icon-component"
|
||||
/>
|
||||
)}
|
||||
<div className="h-fit">
|
||||
<span className="flex items-center space-x-2 rtl:space-x-reverse">
|
||||
<Skeleton title={t(name)} as="p" className="max-w-36 min-h-4 truncate">
|
||||
{t(name)}
|
||||
</Skeleton>
|
||||
<div className="h-fit min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2 truncate">
|
||||
{name}
|
||||
{props.isExternalLink ? <Icon name="external-link" data-testid="external-link" /> : null}
|
||||
</span>
|
||||
{info && (
|
||||
<Skeleton
|
||||
data-testid="apps-info"
|
||||
as="p"
|
||||
title={t(info)}
|
||||
className="max-w-44 mt-1 truncate text-xs font-normal">
|
||||
{t(info)}
|
||||
</Skeleton>
|
||||
// TODO: I don't think having apps-info as a data-test-id is right here as this is meant to be dumb component.
|
||||
<p data-testid="apps-info" className="mt-1 truncate text-xs font-normal">
|
||||
{info}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{!disableChevron && isCurrent && (
|
||||
|
||||
@@ -32,6 +32,9 @@ const NavTabs = function ({
|
||||
`no-scrollbar flex flex-col space-y-0.5 overflow-scroll ${className}`,
|
||||
sticky && "sticky top-0 -mt-7"
|
||||
)}
|
||||
style={{
|
||||
maxWidth: "256px",
|
||||
}}
|
||||
aria-label="Tabs"
|
||||
{...props}>
|
||||
{/* padding top for sticky */}
|
||||
|
||||
@@ -1,145 +1,215 @@
|
||||
/* eslint-disable playwright/missing-playwright-await */
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import type { IconName } from "../../icon";
|
||||
import HorizontalTabs from "./HorizontalTabs";
|
||||
import VerticalTabs from "./VerticalTabs";
|
||||
|
||||
// Mock the hooks
|
||||
vi.mock("@calcom/lib/hooks/useUrlMatchesCurrentUrl", () => ({
|
||||
useUrlMatchesCurrentUrl() {
|
||||
return {
|
||||
route: "/",
|
||||
pathname: "",
|
||||
query: "",
|
||||
asPath: "",
|
||||
push: vi.fn(),
|
||||
events: {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
},
|
||||
beforePopState: vi.fn(() => null),
|
||||
prefetch: vi.fn(() => null),
|
||||
};
|
||||
},
|
||||
useUrlMatchesCurrentUrl: () => false,
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
||||
useLocale: () => {
|
||||
return {
|
||||
t: (str: string) => str,
|
||||
isLocaleReady: true,
|
||||
i18n: {
|
||||
language: "en",
|
||||
defaultLocale: "en",
|
||||
locales: ["en"],
|
||||
exists: () => false,
|
||||
},
|
||||
};
|
||||
},
|
||||
useLocale: () => ({
|
||||
t: (str: string) => str,
|
||||
isLocaleReady: true,
|
||||
i18n: {
|
||||
language: "en",
|
||||
defaultLocale: "en",
|
||||
locales: ["en"],
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("Tests for navigation folder", () => {
|
||||
describe("Test HorizontalTabs Component", () => {
|
||||
describe("Navigation Components", () => {
|
||||
describe("HorizontalTabs", () => {
|
||||
const mockTabs = [
|
||||
{ name: "Tab 1", href: "/tab1" },
|
||||
{ name: "Tab 2", href: "/tab2", avatar: "Avatar" },
|
||||
{ name: "Tab 3", href: "/tab3" },
|
||||
];
|
||||
{ name: "Dashboard", href: "/dashboard", "data-testid": "dashboard" },
|
||||
{ name: "Settings", href: "/settings", icon: "atom", "data-testid": "settings" },
|
||||
{ name: "Profile", href: "/profile", avatar: "user-avatar", "data-testid": "profile" },
|
||||
{ name: "Disabled", href: "/disabled", disabled: true, "data-testid": "disabled" },
|
||||
] as {
|
||||
name: string;
|
||||
href: string;
|
||||
icon?: IconName;
|
||||
avatar?: string;
|
||||
disabled?: boolean;
|
||||
"data-testid"?: string;
|
||||
}[];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test("Should render tabs with correct name and href", () => {
|
||||
test("renders all tabs with correct name and href", async () => {
|
||||
render(<HorizontalTabs tabs={mockTabs} />);
|
||||
mockTabs.forEach((tab) => {
|
||||
const tabLabelElement = screen.getByTestId(`horizontal-tab-${tab.name}`);
|
||||
expect(tabLabelElement).toBeInTheDocument();
|
||||
|
||||
const name = screen.getByText(tab.name);
|
||||
expect(name).toBeInTheDocument();
|
||||
expect(tabLabelElement).toHaveAttribute("href", tab.href);
|
||||
});
|
||||
for (const tab of mockTabs) {
|
||||
const tabElement = screen.getByTestId(`horizontal-tab-${tab["data-testid"]}`);
|
||||
expect(tabElement).toBeInTheDocument();
|
||||
await expect(tabElement).toHaveAttribute("href", tab.href);
|
||||
}
|
||||
});
|
||||
|
||||
test("Should render actions correctly", () => {
|
||||
const handleClick = vi.fn();
|
||||
const mockActions = <button onClick={handleClick}>Actions</button>;
|
||||
render(<HorizontalTabs tabs={mockTabs} actions={mockActions} />);
|
||||
const actionsElement = screen.getByText("Actions");
|
||||
expect(actionsElement).toBeInTheDocument();
|
||||
fireEvent.click(actionsElement);
|
||||
test("renders disabled tabs with correct aria-disabled attribute", async () => {
|
||||
render(<HorizontalTabs tabs={mockTabs} />);
|
||||
|
||||
expect(handleClick).toHaveBeenCalled();
|
||||
const disabledTab = mockTabs.find((tab) => tab.disabled);
|
||||
// Just to keep TS happy
|
||||
// eslint-disable-next-line playwright/no-conditional-in-test
|
||||
if (!disabledTab) throw new Error("Test requires a disabled tab in mockTabs");
|
||||
|
||||
const tabElement = screen.getByTestId(`horizontal-tab-${disabledTab["data-testid"]}`);
|
||||
|
||||
await expect(tabElement).toHaveAttribute("aria-disabled", "true");
|
||||
});
|
||||
|
||||
test("renders actions when provided", async () => {
|
||||
const mockAction = <button>Add New</button>;
|
||||
render(<HorizontalTabs tabs={mockTabs} actions={mockAction} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "Add New" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("handles tab click events", () => {
|
||||
const handleClick = vi.fn();
|
||||
const tabsWithClick = [{ name: "Tab", href: "/tab", onClick: handleClick, "data-testid": "tab" }];
|
||||
|
||||
render(<HorizontalTabs tabs={tabsWithClick} />);
|
||||
fireEvent.click(screen.getByTestId("horizontal-tab-tab"));
|
||||
|
||||
expect(handleClick).toHaveBeenCalledWith("Tab");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Test VerticalTabs Component", () => {
|
||||
describe("VerticalTabs", () => {
|
||||
const mockTabs = [
|
||||
{
|
||||
name: "Tab 1",
|
||||
href: "/tab1",
|
||||
disableChevron: true,
|
||||
disabled: true,
|
||||
icon: "plus" as const,
|
||||
name: "Overview",
|
||||
href: "/overview",
|
||||
icon: "home",
|
||||
info: "Main dashboard view",
|
||||
"data-testid": "Overview",
|
||||
},
|
||||
{ name: "Tab 2", href: "/tab2", isExternalLink: true },
|
||||
{ name: "Tab 3", href: "/tab3", info: "info" },
|
||||
];
|
||||
{
|
||||
name: "External",
|
||||
href: "https://external.com",
|
||||
isExternalLink: true,
|
||||
icon: "external",
|
||||
"data-testid": "Exteral",
|
||||
},
|
||||
{
|
||||
name: "Disabled",
|
||||
href: "/disabled",
|
||||
disabled: true,
|
||||
icon: "lock",
|
||||
"data-testid": "Disabled",
|
||||
},
|
||||
{
|
||||
name: "Child Tab",
|
||||
href: "/child",
|
||||
isChild: true,
|
||||
disableChevron: true,
|
||||
"data-testid": "Child Tab",
|
||||
},
|
||||
] as {
|
||||
name: string;
|
||||
href: string;
|
||||
icon?: IconName;
|
||||
avatar?: string;
|
||||
disabled?: boolean;
|
||||
isExternalLink?: boolean;
|
||||
isChild?: boolean;
|
||||
disableChevron?: boolean;
|
||||
info?: string;
|
||||
"data-testid"?: string;
|
||||
}[];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test("Should render tabs with correct name and href", () => {
|
||||
render(<VerticalTabs tabs={mockTabs} />);
|
||||
mockTabs.forEach((tab) => {
|
||||
const tabLabelElement = screen.getByTestId(`vertical-tab-${tab.name}`);
|
||||
expect(tabLabelElement).toBeInTheDocument();
|
||||
test("renders all tabs with correct structure and attributes", async () => {
|
||||
const { container } = render(<VerticalTabs tabs={mockTabs} sticky className="custom-class" />);
|
||||
|
||||
const name = screen.getByText(tab.name);
|
||||
expect(name).toBeInTheDocument();
|
||||
expect(tabLabelElement).toHaveAttribute("href", tab.href);
|
||||
});
|
||||
});
|
||||
mockTabs.forEach(async (tab) => {
|
||||
const tabElement = screen.getByTestId(`vertical-tab-${tab["data-testid"]}`);
|
||||
expect(tabElement).toBeInTheDocument();
|
||||
await expect(tabElement).toHaveAttribute("href", tab.href);
|
||||
|
||||
test("Should render correctly if props are passed", async () => {
|
||||
render(<VerticalTabs tabs={mockTabs} />);
|
||||
|
||||
const iconElement = await screen.findAllByTestId("icon-component");
|
||||
const externalLink = await screen.findAllByTestId("external-link");
|
||||
const chevronRight = await screen.findAllByTestId("chevron-right");
|
||||
|
||||
mockTabs.forEach((tab) => {
|
||||
const tabName = screen.getByText(tab.name);
|
||||
expect(tabName).toBeInTheDocument();
|
||||
|
||||
const aTag = screen.getByTestId(`vertical-tab-${tab.name}`);
|
||||
const tabContainer = tabName.closest("a");
|
||||
const infoElement = tabContainer?.querySelector("p[title='info']");
|
||||
|
||||
expect(chevronRight.length).toEqual(mockTabs.length - 1);
|
||||
if (tab.disabled) {
|
||||
expect(aTag).tabToBeDisabled();
|
||||
} else {
|
||||
expect(aTag).not.tabToBeDisabled();
|
||||
}
|
||||
|
||||
if (tab.info) {
|
||||
expect(infoElement).toBeInTheDocument();
|
||||
} else {
|
||||
expect(infoElement).toBeNull();
|
||||
await expect(tabElement).toHaveAttribute("aria-disabled", "true");
|
||||
}
|
||||
|
||||
if (tab.isExternalLink) {
|
||||
expect(aTag).toHaveAttribute("target", "_blank");
|
||||
} else {
|
||||
expect(aTag).toHaveAttribute("target", "_self");
|
||||
await expect(tabElement).toHaveAttribute("target", "_blank");
|
||||
expect(screen.getByTestId("external-link")).toBeInTheDocument();
|
||||
}
|
||||
|
||||
if (tab.info) {
|
||||
const infoElement = screen.getByTestId("apps-info");
|
||||
expect(infoElement).toBeInTheDocument();
|
||||
expect(infoElement).toHaveTextContent(tab.info);
|
||||
}
|
||||
|
||||
if (tab.icon) {
|
||||
expect(screen.getAllByTestId("icon-component")).toHaveLength(3);
|
||||
}
|
||||
});
|
||||
|
||||
expect(externalLink.length).toEqual(1);
|
||||
expect(iconElement.length).toEqual(1);
|
||||
// Check sticky behavior
|
||||
await expect(container.firstChild).toHaveClass("sticky");
|
||||
});
|
||||
|
||||
test("applies custom icon correctly", async () => {
|
||||
render(
|
||||
<VerticalTabs
|
||||
tabs={[
|
||||
{
|
||||
name: "Overview",
|
||||
href: "/overview",
|
||||
icon: "atom",
|
||||
info: "Main dashboard view",
|
||||
},
|
||||
]}
|
||||
className="custom-nav"
|
||||
itemClassname="custom-item"
|
||||
iconClassName="custom-icon"
|
||||
/>
|
||||
);
|
||||
|
||||
const iconElement = screen.getByTestId("icon-component");
|
||||
expect(iconElement).toBeInTheDocument();
|
||||
await expect(iconElement).toHaveClass("custom-icon");
|
||||
});
|
||||
|
||||
test("applies custom classNames correctly", async () => {
|
||||
render(
|
||||
<VerticalTabs
|
||||
tabs={[
|
||||
{
|
||||
name: "Overview",
|
||||
href: "/overview",
|
||||
icon: "atom",
|
||||
info: "Main dashboard view",
|
||||
"data-testid": "overview",
|
||||
},
|
||||
]}
|
||||
className="custom-nav"
|
||||
itemClassname="custom-item"
|
||||
iconClassName="custom-icon"
|
||||
/>
|
||||
);
|
||||
|
||||
const nav = screen.getByTestId("vertical-tab-overview").closest("nav");
|
||||
await expect(nav).toHaveClass("custom-nav");
|
||||
|
||||
const tabElement = screen.getByTestId("vertical-tab-overview");
|
||||
await expect(tabElement).toHaveClass("custom-item");
|
||||
|
||||
const iconElement = screen.getByTestId("icon-component");
|
||||
await expect(iconElement).toHaveClass("custom-icon");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { Button } from "../button";
|
||||
import { ButtonGroup } from "../buttonGroup";
|
||||
import { Select } from "../form/select";
|
||||
|
||||
export interface PaginationProps {
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
totalItems: number;
|
||||
onPageChange: (page: number) => void;
|
||||
onPageSizeChange: (pageSize: number) => void;
|
||||
onNext?: () => void;
|
||||
onPrevious?: () => void;
|
||||
pageSizeOptions?: number[];
|
||||
}
|
||||
|
||||
const DEFAULT_PAGE_SIZE_OPTIONS = [10, 25, 50, 100];
|
||||
|
||||
export const Pagination = ({
|
||||
currentPage,
|
||||
pageSize,
|
||||
totalItems,
|
||||
onPageChange,
|
||||
onPageSizeChange,
|
||||
pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
|
||||
onNext,
|
||||
onPrevious,
|
||||
}: PaginationProps) => {
|
||||
const [internalPageSize, setInternalPageSize] = useState(pageSize);
|
||||
const totalPages = Math.ceil(totalItems / pageSize);
|
||||
|
||||
const handlePageSizeChange = (option: { value: number; label: string } | null) => {
|
||||
if (option) {
|
||||
const newPageSize = option.value;
|
||||
setInternalPageSize(newPageSize);
|
||||
onPageSizeChange(newPageSize);
|
||||
// Reset to first page when changing page size
|
||||
onPageChange(1);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePrevious = () => {
|
||||
if (currentPage > 1) {
|
||||
onPageChange(currentPage - 1);
|
||||
onPrevious?.();
|
||||
}
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (currentPage < totalPages) {
|
||||
onPageChange(currentPage + 1);
|
||||
onNext?.();
|
||||
}
|
||||
};
|
||||
|
||||
const pageSizeSelectOptions = pageSizeOptions.map((size) => ({
|
||||
value: size,
|
||||
label: `${size}`,
|
||||
}));
|
||||
|
||||
const startItem = (currentPage - 1) * pageSize + 1;
|
||||
const endItem = Math.min(currentPage * pageSize, totalItems);
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between space-x-2 py-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Select
|
||||
options={pageSizeSelectOptions}
|
||||
value={pageSizeSelectOptions.find((option) => option.value === internalPageSize)}
|
||||
onChange={handlePageSizeChange}
|
||||
size="sm"
|
||||
/>
|
||||
<span className="text-default text-sm">rows per page</span>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-default text-sm">
|
||||
{startItem}-{endItem} of {totalItems}
|
||||
</span>
|
||||
<ButtonGroup containerProps={{ className: "space-x-1.5" }}>
|
||||
<Button
|
||||
variant="icon"
|
||||
StartIcon="arrow-left"
|
||||
onClick={handlePrevious}
|
||||
disabled={currentPage <= 1}
|
||||
color="secondary"
|
||||
size="sm"
|
||||
/>
|
||||
<Button
|
||||
variant="icon"
|
||||
StartIcon="arrow-right"
|
||||
onClick={handleNext}
|
||||
disabled={currentPage >= totalPages}
|
||||
color="secondary"
|
||||
size="sm"
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { Pagination } from "./Pagination";
|
||||
export type { PaginationProps } from "./Pagination";
|
||||
@@ -3,6 +3,7 @@ import React from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import { buttonClasses } from "../button";
|
||||
import { Icon } from "../icon";
|
||||
import { Tooltip } from "../tooltip";
|
||||
|
||||
@@ -29,7 +30,8 @@ export const AnimatedPopover = ({
|
||||
const ref = React.useRef<HTMLButtonElement>(null);
|
||||
// calculate which aligment to open the popover with based on which half of the screen it is on (left or right)
|
||||
const [align, setAlign] = React.useState<"start" | "end">("start");
|
||||
React.useEffect(() => {
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
const handleResize = () => {
|
||||
const halfWidth = window.innerWidth / 2;
|
||||
const { x } = ref?.current?.getBoundingClientRect() || {
|
||||
@@ -55,7 +57,9 @@ export const AnimatedPopover = ({
|
||||
<button
|
||||
ref={ref}
|
||||
className={classNames(
|
||||
"hover:border-emphasis border-default text-default hover:text-emphasis radix-state-open:border-emphasis radix-state-open:outline-none radix-state-open:ring-2 radix-state-open:ring-emphasis mb-4 flex h-9 max-h-72 items-center justify-between whitespace-nowrap rounded-md border px-3 py-2 text-sm hover:cursor-pointer",
|
||||
buttonClasses({
|
||||
color: "secondary",
|
||||
}),
|
||||
popoverTriggerClassNames
|
||||
)}>
|
||||
{Trigger ? (
|
||||
@@ -63,7 +67,7 @@ export const AnimatedPopover = ({
|
||||
) : (
|
||||
<div className="max-w-36 flex items-center">
|
||||
<Tooltip content={prefix ? `${prefix}${text}` : text}>
|
||||
<div className="flex select-none truncate font-medium">
|
||||
<div className="flex select-none items-center truncate font-medium leading-none">
|
||||
{PrefixComponent ? PrefixComponent : null}
|
||||
{prefix && <span className="text-subtle">{prefix} </span>}
|
||||
{text}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { DefaultToast, ErrorToast, SuccessToast, WarningToast, showToast } from "./showToast";
|
||||
export { ErrorToast, SuccessToast, WarningToast, showToast } from "./showToast";
|
||||
@@ -14,64 +14,57 @@ type IToast = {
|
||||
export const SuccessToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
|
||||
<button
|
||||
className={classNames(
|
||||
"data-testid-toast-success bg-brand-default text-brand mb-2 flex h-auto space-x-2 rounded-md p-3 text-sm font-semibold shadow-md rtl:space-x-reverse md:max-w-sm",
|
||||
"data-testid-toast-success bg-default dark:bg-inverted text-emphasis dark:text-inverted shadow-elevation-low border-subtle mb-2 flex h-auto space-x-2 rounded-lg border px-3 py-2.5 text-sm font-semibold rtl:space-x-reverse md:max-w-sm",
|
||||
toastVisible && "animate-fade-in-up cursor-pointer"
|
||||
)}
|
||||
onClick={() => onClose(toastId)}>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="check" className="h-4 w-4" />
|
||||
</span>
|
||||
<p data-testid="toast-success" className="text-left">
|
||||
<p data-testid="toast-success" className="m-0 w-full text-left">
|
||||
{message}
|
||||
</p>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="x" className="h-4 w-4 hover:cursor-pointer" />
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
||||
export const ErrorToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
|
||||
<button
|
||||
className={classNames(
|
||||
"animate-fade-in-up bg-error text-error text-brand mb-2 flex h-auto space-x-2 rounded-md p-3 text-sm font-semibold shadow-md rtl:space-x-reverse md:max-w-sm",
|
||||
"animate-fade-in-up bg-semantic-error-subtle text-semantic-error shadow-elevation-low border-semantic-error-subtle mb-2 flex h-auto space-x-2 rounded-md border px-3 py-2.5 text-sm font-semibold rtl:space-x-reverse md:max-w-sm",
|
||||
toastVisible && "animate-fade-in-up cursor-pointer"
|
||||
)}
|
||||
onClick={() => onClose(toastId)}>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="info" className="h-4 w-4" />
|
||||
<Icon name="info" className="text-semantic-error h-4 w-4" />
|
||||
</span>
|
||||
<p data-testid="toast-error" className="text-left">
|
||||
<p data-testid="toast-error" className="m-0 w-full text-left">
|
||||
{message}
|
||||
</p>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="x" className="text-semantic-error h-4 w-4 hover:cursor-pointer" />
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
||||
export const WarningToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
|
||||
<button
|
||||
className={classNames(
|
||||
"animate-fade-in-up bg-brand-default text-brand mb-2 flex h-auto space-x-2 rounded-md p-3 text-sm font-semibold shadow-md rtl:space-x-reverse md:max-w-sm",
|
||||
"animate-fade-in-up bg-semantic-attention-subtle text-semantic-attention shadow-elevation-low border-semantic-attention-subtle mb-2 flex h-auto space-x-2 rounded-md border px-3 py-2.5 text-sm font-semibold rtl:space-x-reverse md:max-w-sm",
|
||||
toastVisible && "animate-fade-in-up cursor-pointer"
|
||||
)}
|
||||
onClick={() => onClose(toastId)}>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="info" className="h-4 w-4" />
|
||||
<Icon name="info" className="text-semantic-attention h-4 w-4" />
|
||||
</span>
|
||||
<p data-testid="toast-warning" className="text-left">
|
||||
<p data-testid="toast-warning" className="m-0 w-full text-left">
|
||||
{message}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
|
||||
export const DefaultToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
|
||||
<button
|
||||
className={classNames(
|
||||
"animate-fade-in-up bg-brand-default text-brand mb-2 flex h-auto space-x-2 rounded-md p-3 text-sm font-semibold shadow-md rtl:space-x-reverse md:max-w-sm",
|
||||
toastVisible && "animate-fade-in-up cursor-pointer"
|
||||
)}
|
||||
onClick={() => onClose(toastId)}>
|
||||
<span className="mt-0.5">
|
||||
<Icon name="check" className="h-4 w-4" />
|
||||
<Icon name="x" className="text-semantic-attention h-4 w-4 hover:cursor-pointer" />
|
||||
</span>
|
||||
<p data-testid="toast-default" className="text-left">
|
||||
{message}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -104,7 +97,7 @@ export function showToast(
|
||||
};
|
||||
return toast.custom(
|
||||
toastElements[variant] ||
|
||||
((t) => <DefaultToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />),
|
||||
((t) => <SuccessToast message={message} toastVisible={t.visible} onClose={onClose} toastId={t.id} />),
|
||||
_options
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import { SuccessToast, ErrorToast, WarningToast, DefaultToast } from "./showToast";
|
||||
import { SuccessToast, ErrorToast, WarningToast } from "./showToast";
|
||||
|
||||
describe("Tests for Toast Components", () => {
|
||||
const testToastComponent = (Component: typeof DefaultToast, toastTestId: string) => {
|
||||
const testToastComponent = (Component: typeof SuccessToast, toastTestId: string) => {
|
||||
const message = "This is a test message";
|
||||
const toastId = "some-id";
|
||||
|
||||
@@ -20,11 +20,10 @@ describe("Tests for Toast Components", () => {
|
||||
expect(onCloseMock).toHaveBeenCalledWith(toastId);
|
||||
};
|
||||
|
||||
const toastComponents: [string, typeof DefaultToast, string][] = [
|
||||
const toastComponents: [string, typeof SuccessToast, string][] = [
|
||||
["SuccessToast", SuccessToast, "toast-success"],
|
||||
["ErrorToast", ErrorToast, "toast-error"],
|
||||
["WarningToast", WarningToast, "toast-warning"],
|
||||
["DefaultToast", DefaultToast, "toast-default"],
|
||||
];
|
||||
|
||||
test.each(toastComponents)("Should render and close %s component", (_, ToastComponent, expectedClass) => {
|
||||
|
||||
Reference in new issue
Block a user