* 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 <hey@eunjae.dev> Co-authored-by: Morgan Vernay <morgan@cal.com> * 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 <hey@eunjae.dev> Co-authored-by: Morgan Vernay <morgan@cal.com> Co-authored-by: Hariom <hariombalhara@gmail.com> Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
379 lines
11 KiB
TypeScript
379 lines
11 KiB
TypeScript
import type { VariantProps } from "class-variance-authority";
|
|
import { cva } from "class-variance-authority";
|
|
import type { LinkProps } from "next/link";
|
|
import Link from "next/link";
|
|
import React, { forwardRef } from "react";
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
import { Icon } from "../icon";
|
|
import type { IconName } from "../icon";
|
|
import { Tooltip } from "../tooltip";
|
|
|
|
type InferredVariantProps = VariantProps<typeof buttonClasses>;
|
|
|
|
export type ButtonColor = NonNullable<InferredVariantProps["color"]>;
|
|
export type ButtonBaseProps = {
|
|
/** Action that happens when the button is clicked */
|
|
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
/**Left aligned icon*/
|
|
CustomStartIcon?: React.ReactNode;
|
|
StartIcon?: IconName;
|
|
/**Right aligned icon */
|
|
EndIcon?: IconName;
|
|
shallow?: boolean;
|
|
/**Tool tip used when icon size is set to small */
|
|
tooltip?: string | React.ReactNode;
|
|
tooltipSide?: "top" | "right" | "bottom" | "left";
|
|
tooltipOffset?: number;
|
|
tooltipClassName?: string;
|
|
disabled?: boolean;
|
|
flex?: boolean;
|
|
} & Omit<InferredVariantProps, "color"> & {
|
|
color?: ButtonColor;
|
|
};
|
|
|
|
export type ButtonProps = ButtonBaseProps &
|
|
(
|
|
| (Omit<JSX.IntrinsicElements["a"], "href" | "onClick" | "ref"> & LinkProps)
|
|
| (Omit<JSX.IntrinsicElements["button"], "onClick" | "ref"> & { href?: never })
|
|
);
|
|
|
|
export const buttonClasses = cva(
|
|
"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-[10px] radix-state-open:rotate-45 md:radix-state-open:rotate-0 radix-state-open:shadown-none radix-state-open:ring-0",
|
|
},
|
|
color: {
|
|
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: {
|
|
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",
|
|
},
|
|
},
|
|
compoundVariants: [
|
|
// Primary variants
|
|
{
|
|
loading: true,
|
|
color: "primary",
|
|
className: "opacity-30",
|
|
},
|
|
// Secondary variants
|
|
{
|
|
loading: true,
|
|
color: "secondary",
|
|
className: "bg-subtle text-emphasis/80",
|
|
},
|
|
// Minimal variants
|
|
{
|
|
loading: true,
|
|
color: "minimal",
|
|
className: "bg-subtle text-emphasis/30",
|
|
},
|
|
// Destructive variants
|
|
{
|
|
loading: true,
|
|
color: "destructive",
|
|
className:
|
|
"text-red-700/30 dark:text-red-700/30 hover:text-red-700/30 border border-default text-emphasis",
|
|
},
|
|
{
|
|
variant: "icon",
|
|
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 rounded-md",
|
|
},
|
|
{
|
|
variant: "icon",
|
|
size: "lg",
|
|
className: "h-10 w-10 !p-1",
|
|
},
|
|
{
|
|
variant: "fab",
|
|
size: "base",
|
|
className: "min-h-14 md:min-h-9 md:min-w-auto md:px-4 md:py-2.5",
|
|
},
|
|
],
|
|
defaultVariants: {
|
|
variant: "button",
|
|
color: "primary",
|
|
size: "base",
|
|
},
|
|
}
|
|
);
|
|
|
|
export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonProps>(function Button(
|
|
props: ButtonProps,
|
|
forwardedRef
|
|
) {
|
|
const {
|
|
loading = false,
|
|
color = "primary",
|
|
size,
|
|
variant = "button",
|
|
type = "button",
|
|
tooltipSide = "top",
|
|
tooltipOffset = 4,
|
|
tooltipClassName,
|
|
StartIcon,
|
|
CustomStartIcon,
|
|
EndIcon,
|
|
shallow,
|
|
// attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps`
|
|
...passThroughProps
|
|
} = props;
|
|
// Buttons are **always** disabled if we're in a `loading` state
|
|
const disabled = props.disabled || loading;
|
|
// If pass an `href`-attr is passed it's `<a>`, otherwise it's a `<button />`
|
|
const isLink = typeof props.href !== "undefined";
|
|
const elementType = isLink ? "a" : "button";
|
|
const element = React.createElement(
|
|
elementType,
|
|
{
|
|
...passThroughProps,
|
|
disabled,
|
|
type: !isLink ? type : undefined,
|
|
ref: forwardedRef,
|
|
className: classNames(buttonClasses({ color, size, loading, variant }), props.className),
|
|
// if we click a disabled button, we prevent going through the click handler
|
|
onClick: disabled
|
|
? (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
|
e.preventDefault();
|
|
}
|
|
: props.onClick,
|
|
},
|
|
<>
|
|
{CustomStartIcon ||
|
|
(StartIcon && (
|
|
<>
|
|
{variant === "fab" ? (
|
|
<>
|
|
<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] "
|
|
)}
|
|
/>
|
|
)}
|
|
</>
|
|
))}
|
|
{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
|
|
className={classNames(
|
|
"mx-4 h-5 w-5 animate-spin",
|
|
color === "primary" ? "text-inverted" : "text-emphasis"
|
|
)}
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
fill="none"
|
|
viewBox="0 0 24 24">
|
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
<path
|
|
className="opacity-75"
|
|
fill="currentColor"
|
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
/>
|
|
</svg>
|
|
</div>
|
|
)}
|
|
{EndIcon && (
|
|
<>
|
|
{variant === "fab" ? (
|
|
<>
|
|
<Icon name={EndIcon} className="-mr-1 me-2 ms-2 hidden h-5 w-5 md:inline" />
|
|
<Icon name="plus" data-testid="plus" className="inline h-6 w-6 md:hidden" />
|
|
</>
|
|
) : (
|
|
<Icon
|
|
name={EndIcon}
|
|
className={classNames(
|
|
loading ? "invisible" : "visible",
|
|
"group-active:translate-y-[0.5px]",
|
|
variant === "icon" && "h-4 w-4",
|
|
variant === "button" && "h-4 w-4 stroke-[1.5px] "
|
|
)}
|
|
/>
|
|
)}
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return props.href ? (
|
|
<Link data-testid="link-component" passHref href={props.href} shallow={shallow && shallow} legacyBehavior>
|
|
{element}
|
|
</Link>
|
|
) : (
|
|
<Wrapper
|
|
data-testid="wrapper"
|
|
tooltip={props.tooltip}
|
|
tooltipSide={tooltipSide}
|
|
tooltipOffset={tooltipOffset}
|
|
tooltipClassName={tooltipClassName}>
|
|
{element}
|
|
</Wrapper>
|
|
);
|
|
});
|
|
|
|
const Wrapper = ({
|
|
children,
|
|
tooltip,
|
|
tooltipSide,
|
|
tooltipOffset,
|
|
tooltipClassName,
|
|
}: {
|
|
tooltip?: string | React.ReactNode;
|
|
children: React.ReactNode;
|
|
tooltipSide?: "top" | "right" | "bottom" | "left";
|
|
tooltipOffset?: number;
|
|
tooltipClassName?: string;
|
|
}) => {
|
|
if (!tooltip) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
return (
|
|
<Tooltip
|
|
data-testid="tooltip"
|
|
className={tooltipClassName}
|
|
content={tooltip}
|
|
side={tooltipSide}
|
|
sideOffset={tooltipOffset}>
|
|
{children}
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
Button.displayName = "Button";
|