Cleaning up storybook files (#5290)
* storybook v2 init * Merge config into storybook vite build * Remove path * Storybook config tweaks * Added styles and settings for storybook v2, and started working on button documentation and examples. * Badges + flex wrap on mobile * Breadcrumbs+button+avatar * Checkbox * Input + moving files around * WIP table * WIP table grid * Replaced imports for new components. * Added first steps for varianttable. * Small alignment fix. * Custom Args Table - With scrollbar * Adding table to components that need it + darkmode * Add intro * Fix types * Remove V1 storybook and replace with V2 * Fix badge type error * Fixed storybook dependencies * Added cover image to storybook * Remove vita from ts config, we dont use vite. * Fixed button import. * Explained postcss pseudo plugin. * Fixed badge import. * Add Avatar Stories * ButtonGroup Stories * Fixed imports * Add checkbox stories * Add exports for differnt types of inputs * Fix form and text area input * Fix mass import errors Co-authored-by: Jeroen Reumkens <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
234 files changed
+2709
-2692
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
||||
import * as Tooltip from "@radix-ui/react-tooltip";
|
||||
import { Check } from "react-feather";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { defaultAvatarSrc } from "@calcom/lib/defaultAvatarImage";
|
||||
|
||||
import { Maybe } from "@trpc/server";
|
||||
|
||||
export type AvatarProps = {
|
||||
className?: string;
|
||||
size: "sm" | "md" | "mdLg" | "lg";
|
||||
imageSrc?: Maybe<string>;
|
||||
title?: string;
|
||||
alt: string;
|
||||
gravatarFallbackMd5?: string;
|
||||
accepted?: boolean;
|
||||
};
|
||||
|
||||
const sizesPropsBySize = {
|
||||
sm: "w-6", // 24px
|
||||
md: "w-8", // 32px
|
||||
mdLg: "w-10", //40px
|
||||
lg: "w-16", // 64px
|
||||
} as const;
|
||||
|
||||
export function Avatar(props: AvatarProps) {
|
||||
const { imageSrc, gravatarFallbackMd5, size, alt, title } = props;
|
||||
const sizeClassname = sizesPropsBySize[size];
|
||||
const rootClass = classNames("rounded-full aspect-square", sizeClassname, "h-auto");
|
||||
const avatar = (
|
||||
<AvatarPrimitive.Root
|
||||
className={classNames(
|
||||
sizeClassname,
|
||||
"dark:bg-darkgray-300 relative inline-block aspect-square overflow-hidden rounded-full"
|
||||
)}>
|
||||
<AvatarPrimitive.Image src={imageSrc ?? undefined} alt={alt} className={rootClass} />
|
||||
<AvatarPrimitive.Fallback delayMs={600}>
|
||||
{gravatarFallbackMd5 && (
|
||||
<img src={defaultAvatarSrc({ md5: gravatarFallbackMd5 })} alt={alt} className={rootClass} />
|
||||
)}
|
||||
</AvatarPrimitive.Fallback>
|
||||
{props.accepted && (
|
||||
<div
|
||||
className={classNames(
|
||||
"absolute bottom-0 right-0 block rounded-full bg-green-400 text-white ring-2 ring-white",
|
||||
size === "lg" ? "h-5 w-5" : "h-2 w-2"
|
||||
)}>
|
||||
<div className="flex h-full items-center justify-center p-[2px]">
|
||||
{size === "lg" && <Check className="" />}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</AvatarPrimitive.Root>
|
||||
);
|
||||
|
||||
return title ? (
|
||||
<Tooltip.Provider>
|
||||
<Tooltip.Tooltip delayDuration={300}>
|
||||
<Tooltip.TooltipTrigger className="cursor-default">{avatar}</Tooltip.TooltipTrigger>
|
||||
<Tooltip.Content className="rounded-sm bg-black p-2 text-sm text-white shadow-sm">
|
||||
<Tooltip.Arrow />
|
||||
{title}
|
||||
</Tooltip.Content>
|
||||
</Tooltip.Tooltip>
|
||||
</Tooltip.Provider>
|
||||
) : (
|
||||
<>{avatar}</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
import { Avatar } from "./Avatar";
|
||||
|
||||
export type AvatarGroupProps = {
|
||||
size: "sm" | "lg";
|
||||
items: {
|
||||
image: string;
|
||||
title?: string;
|
||||
alt?: string;
|
||||
}[];
|
||||
className?: string;
|
||||
accepted?: boolean;
|
||||
};
|
||||
|
||||
export const AvatarGroup = function AvatarGroup(props: AvatarGroupProps) {
|
||||
const avatars = props.items.slice(0, 4);
|
||||
const LENGTH = props.items.length;
|
||||
|
||||
return (
|
||||
<ul className={classNames(props.className, "flex items-center")}>
|
||||
{avatars.map((item, enumerator) => {
|
||||
if (item.image != null) {
|
||||
if (LENGTH > 4 && enumerator === 3) {
|
||||
return (
|
||||
<li key={enumerator} className="relative -mr-4 inline-block ">
|
||||
<div className="relative">
|
||||
<div className="h-90 relative min-w-full scale-105 transform border-gray-200 ">
|
||||
<Avatar className="" imageSrc={item.image} alt={item.alt || ""} size={props.size} />
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={classNames(
|
||||
"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-white",
|
||||
props.size === "sm" ? "text-base" : "text-2xl"
|
||||
)}>
|
||||
<span>+{LENGTH - 3}</span>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
// Always display the first Four items items
|
||||
return (
|
||||
<li key={enumerator} className="-mr-4 inline-block">
|
||||
<Avatar
|
||||
className="border-gray-200"
|
||||
imageSrc={item.image}
|
||||
title={item.title}
|
||||
alt={item.alt || ""}
|
||||
accepted={props.accepted}
|
||||
size={props.size}
|
||||
/>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,139 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable,VariantsTable,VariantRow } from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import {Avatar} from './Avatar';
|
||||
import {AvatarGroup} from './AvatarGroup';
|
||||
|
||||
<Meta title="UI/Avatar" component={Avatar} />
|
||||
|
||||
<Title title="Avatar" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
|
||||
|
||||
## Definition
|
||||
An avatar group signals that there is more than 1 person associated with an item
|
||||
|
||||
## Structure
|
||||
Avatar group can be composed differently based on the number of user profile.
|
||||
|
||||
<CustomArgsTable of={Avatar} />
|
||||
|
||||
<Examples title="Avatar style">
|
||||
<Example title="Small">
|
||||
<Avatar size="sm" alt="Avatar Story" gravatarFallbackMd5="[email protected]" />
|
||||
</Example>
|
||||
<Example title="Large">
|
||||
<Avatar size="lg" alt="Avatar Story" gravatarFallbackMd5="[email protected]" />
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<ArgsTable of={Avatar} />
|
||||
|
||||
### Avatar Group
|
||||
<ArgsTable of={AvatarGroup} />
|
||||
<Examples title="Avatar Group ">
|
||||
<Example title="Small">
|
||||
<AvatarGroup size="sm" items={[
|
||||
{
|
||||
image: "https://cal.com/stakeholder/peer.jpg",
|
||||
alt: "Peer",
|
||||
title: "Peer Richelsen",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/bailey.jpg",
|
||||
alt: "Bailey",
|
||||
title: "Bailey Pumfleet",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/alex-van-andel.jpg",
|
||||
alt: "Alex",
|
||||
title: "Alex Van Andel",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/ciaran.jpg",
|
||||
alt: "Ciarán",
|
||||
title: "Ciarán Hanrahan",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/peer.jpg",
|
||||
alt: "Peer",
|
||||
title: "Peer Richelsen",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/bailey.jpg",
|
||||
alt: "Bailey",
|
||||
title: "Bailey Pumfleet",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/alex-van-andel.jpg",
|
||||
alt: "Alex",
|
||||
title: "Alex Van Andel",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/ciaran.jpg",
|
||||
alt: "Ciarán",
|
||||
title: "Ciarán Hanrahan",
|
||||
},
|
||||
]}/>
|
||||
</Example>
|
||||
<Example title="large">
|
||||
<AvatarGroup size="lg" items={[
|
||||
{
|
||||
image: "https://cal.com/stakeholder/peer.jpg",
|
||||
alt: "Peer",
|
||||
title: "Peer Richelsen",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/bailey.jpg",
|
||||
alt: "Bailey",
|
||||
title: "Bailey Pumfleet",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/alex-van-andel.jpg",
|
||||
alt: "Alex",
|
||||
title: "Alex Van Andel",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/ciaran.jpg",
|
||||
alt: "Ciarán",
|
||||
title: "Ciarán Hanrahan",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/peer.jpg",
|
||||
alt: "Peer",
|
||||
title: "Peer Richelsen",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/bailey.jpg",
|
||||
alt: "Bailey",
|
||||
title: "Bailey Pumfleet",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/alex-van-andel.jpg",
|
||||
alt: "Alex",
|
||||
title: "Alex Van Andel",
|
||||
},
|
||||
{
|
||||
image: "https://cal.com/stakeholder/ciaran.jpg",
|
||||
alt: "Ciarán",
|
||||
title: "Ciarán Hanrahan",
|
||||
},
|
||||
]}/>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Title offset title="Avatar" suffix="Variants" />
|
||||
|
||||
<Canvas>
|
||||
<Story
|
||||
name="Avatar">
|
||||
<VariantsTable titles={['Default']} columnMinWidth={150}>
|
||||
<VariantRow variant="Sm">
|
||||
<Avatar size="sm" alt="Avatar Story" gravatarFallbackMd5="[email protected]" />
|
||||
</VariantRow>
|
||||
<VariantRow variant="Lg">
|
||||
<Avatar size="lg" alt="Avatar Story" gravatarFallbackMd5="[email protected]" />
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./Avatar";
|
||||
export * from "./AvatarGroup";
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Icon } from "react-feather";
|
||||
import { GoPrimitiveDot } from "react-icons/go";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
export const badgeClassNameByVariant = {
|
||||
default: "bg-orange-100 text-orange-800",
|
||||
warning: "bg-orange-100 text-orange-800",
|
||||
orange: "bg-orange-100 text-orange-800",
|
||||
success: "bg-green-100 text-green-800",
|
||||
green: "bg-green-100 text-green-800",
|
||||
gray: "bg-gray-100 text-gray-800 dark:bg-transparent dark:text-darkgray-800",
|
||||
blue: "bg-blue-100 text-blue-800",
|
||||
red: "bg-red-100 text-red-800",
|
||||
error: "bg-red-100 text-red-800",
|
||||
};
|
||||
|
||||
const classNameBySize = {
|
||||
default: "h-5",
|
||||
lg: "h-6",
|
||||
};
|
||||
|
||||
export type BadgeProps = {
|
||||
variant: keyof typeof badgeClassNameByVariant;
|
||||
size?: keyof typeof classNameBySize;
|
||||
StartIcon?: Icon;
|
||||
bold?: boolean;
|
||||
withDot?: boolean;
|
||||
rounded?: boolean;
|
||||
} & JSX.IntrinsicElements["div"];
|
||||
|
||||
export const Badge = function Badge(props: BadgeProps) {
|
||||
const {
|
||||
variant = "default",
|
||||
className,
|
||||
size = "default",
|
||||
rounded,
|
||||
StartIcon,
|
||||
withDot,
|
||||
bold,
|
||||
...passThroughProps
|
||||
} = props;
|
||||
const hasIconOrDot = StartIcon || withDot;
|
||||
return (
|
||||
<div
|
||||
{...passThroughProps}
|
||||
className={classNames(
|
||||
"inline-flex items-center justify-center py-0.5 px-[6px] text-xs",
|
||||
bold ? "font-semibold" : "font-normal",
|
||||
rounded ? "min-w-5 min-h-5 rounded-full pt-1" : "rounded-md",
|
||||
!hasIconOrDot ? classNameBySize[size] : "",
|
||||
badgeClassNameByVariant[variant],
|
||||
className
|
||||
)}>
|
||||
<>
|
||||
{StartIcon && <StartIcon className="mr-1 h-3 w-3 stroke-[3px]" />}
|
||||
{withDot && <GoPrimitiveDot className="mr-1 h-3 w-3 stroke-[3px]" />}
|
||||
{props.children}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable,VariantsTable, VariantRow } from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
import { Badge } from './Badge';
|
||||
|
||||
<Meta title="UI/Badge" component={Badge} />
|
||||
|
||||
<Title title="Bages" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
|
||||
## Definition
|
||||
Badges are small status descriptors for UI elements. A badge consists of a small circle, typically containing a number or other short set of characters, that appears in proximity to another object. We provide three different type of badge such as status, alert, and brand badge.
|
||||
|
||||
Status badge communicate status information. It is generally used within a container such as accordion and tables to label status for easy scanning.
|
||||
## Structure
|
||||
|
||||
<CustomArgsTable of={Badge} />
|
||||
|
||||
|
||||
<Examples title="Badge style">
|
||||
<Example title="Gray">
|
||||
<Badge variant="gray" >Badge text</Badge>
|
||||
</Example>
|
||||
<Example title="Green/Success">
|
||||
<Badge variant="success">Badge text</Badge>
|
||||
</Example>
|
||||
<Example title="Orange/Default">
|
||||
<Badge variant="default">Badge text</Badge>
|
||||
</Example>
|
||||
<Example title="Red/Error">
|
||||
<Badge variant="red">Badge text</Badge>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Variants">
|
||||
<Example title="Default">
|
||||
<Badge>Button text</Badge>
|
||||
</Example>
|
||||
<Example title="With Dot">
|
||||
<Badge withDot>Button Text</Badge>
|
||||
</Example>
|
||||
<Example title="With Icon">
|
||||
<Badge StartIcon={Icon.FiPlus}>Button Text</Badge>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
|
||||
## Alert Badges
|
||||
|
||||
|
||||
## Usage
|
||||
Alet badge is used in conjunction with an item, profile or label to indicate numeric value and messages assocciated with them.
|
||||
|
||||
|
||||
|
||||
<Title offset title="Badge" suffix="Variants" />
|
||||
|
||||
<Canvas>
|
||||
<Story name="All Variants">
|
||||
<VariantsTable titles={['Default','With Dot', 'With Icon']} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<Badge variant="default" >Badge text</Badge>
|
||||
<Badge variant="default" withDot>Badge text</Badge>
|
||||
<Badge variant="default" StartIcon={Icon.FiPlus}>Badge text</Badge>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Success">
|
||||
<Badge variant="success" >Badge text</Badge>
|
||||
<Badge variant="success" withDot>Badge text</Badge>
|
||||
<Badge variant="success" StartIcon={Icon.FiPlus}>Badge text</Badge>
|
||||
</VariantRow>
|
||||
<VariantRow variant="gray">
|
||||
<Badge variant="gray" >Badge text</Badge>
|
||||
<Badge variant="gray" withDot>Badge text</Badge>
|
||||
<Badge variant="gray" StartIcon={Icon.FiPlus}>Badge text</Badge>
|
||||
</VariantRow>
|
||||
<VariantRow variant="error">
|
||||
<Badge variant="error" >Badge text</Badge>
|
||||
<Badge variant="error" withDot>Badge text</Badge>
|
||||
<Badge variant="error" StartIcon={Icon.FiPlus}>Badge text</Badge>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./Badge";
|
||||
@@ -0,0 +1,71 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { Children, Fragment, useEffect, useState } from "react";
|
||||
|
||||
type BreadcrumbProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
export const Breadcrumb = ({ children }: BreadcrumbProps) => {
|
||||
const childrenArray = Children.toArray(children);
|
||||
|
||||
const childrenSeperated = childrenArray.map((child, index) => {
|
||||
// If not the last item in the array insert a /
|
||||
if (index !== childrenArray.length - 1) {
|
||||
return (
|
||||
<Fragment key={index}>
|
||||
{child}
|
||||
<span>/</span>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
// Else return just the child
|
||||
return child;
|
||||
});
|
||||
|
||||
return (
|
||||
<nav className="text-sm font-normal leading-5 text-gray-600">
|
||||
<ol className="flex items-center space-x-2">{childrenSeperated}</ol>
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
type BreadcrumbItemProps = {
|
||||
children: React.ReactNode;
|
||||
href: string;
|
||||
listProps?: JSX.IntrinsicElements["li"];
|
||||
};
|
||||
|
||||
export const BreadcrumbItem = ({ children, href, listProps }: BreadcrumbItemProps) => {
|
||||
return (
|
||||
<li {...listProps}>
|
||||
<Link href={href}>
|
||||
<a>{children}</a>
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
export const BreadcrumbContainer = () => {
|
||||
const router = useRouter();
|
||||
const [breadcrumbs, setBreadcrumbs] = useState<{ href: string; label: string }[]>();
|
||||
|
||||
useEffect(() => {
|
||||
const rawPath = router.asPath.split("?")[0]; // this will ignore any query params for now?
|
||||
|
||||
let pathArray = rawPath.split("/");
|
||||
pathArray.shift();
|
||||
|
||||
pathArray = pathArray.filter((path) => path !== "");
|
||||
|
||||
const allBreadcrumbs = pathArray.map((path, idx) => {
|
||||
const href = `/${pathArray.slice(0, idx + 1).join("/")}`;
|
||||
return {
|
||||
href,
|
||||
label: path.charAt(0).toUpperCase() + path.slice(1),
|
||||
};
|
||||
});
|
||||
setBreadcrumbs(allBreadcrumbs);
|
||||
}, [router.asPath]);
|
||||
};
|
||||
|
||||
export default Breadcrumb;
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable } from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { Breadcrumb } from './Breadcrumb';
|
||||
|
||||
<Meta title="UI/Breadcrumbs" component={Breadcrumb} />
|
||||
|
||||
<Title title="Breadcrumbs" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
|
||||
## Structure
|
||||
|
||||
<CustomArgsTable of={Breadcrumb} />
|
||||
|
||||
|
||||
<Examples title="Breadcrumb style"
|
||||
>
|
||||
<Example title="Primary">
|
||||
<Breadcrumb>
|
||||
<BreadcrumbItem href="/">Home</BreadcrumbItem>
|
||||
<BreadcrumbItem href="/">Test</BreadcrumbItem>
|
||||
</Breadcrumb>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
## Usage
|
||||
When hovering over the button, there should be a tooltip to explain the context of the button, so the user can understand the result of action.
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./Breadcrumb";
|
||||
@@ -0,0 +1,154 @@
|
||||
import Link, { LinkProps } from "next/link";
|
||||
import React, { forwardRef } from "react";
|
||||
import { Icon } from "react-feather";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
import Tooltip from "../../v2/core/Tooltip";
|
||||
|
||||
export type ButtonBaseProps = {
|
||||
/* Primary: Signals most important actions at any given point in the application.
|
||||
Secondary: Gives visual weight to actions that are important
|
||||
Minimal: Used for actions that we want to give very little significane to */
|
||||
color?: keyof typeof variantClassName;
|
||||
/**Default: H = 36px (default)
|
||||
Large: H = 38px (Onboarding, modals)
|
||||
Icon: Makes the button be an icon button */
|
||||
size?: "base" | "lg" | "icon";
|
||||
/**Signals the button is loading */
|
||||
loading?: boolean;
|
||||
/** Disables the button from being clicked */
|
||||
disabled?: boolean;
|
||||
/** Action that happens when the button is clicked */
|
||||
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
||||
/**Left aligned icon*/
|
||||
StartIcon?: Icon | React.ElementType;
|
||||
/**Right aligned icon */
|
||||
EndIcon?: Icon;
|
||||
shallow?: boolean;
|
||||
/**Tool tip used when icon size is set to small */
|
||||
tooltip?: string;
|
||||
/** @deprecated This has now been replaced by button group. */
|
||||
combined?: boolean;
|
||||
flex?: boolean;
|
||||
};
|
||||
export type ButtonProps = ButtonBaseProps &
|
||||
(
|
||||
| (Omit<JSX.IntrinsicElements["a"], "href" | "onClick" | "ref"> & LinkProps)
|
||||
| (Omit<JSX.IntrinsicElements["button"], "onClick" | "ref"> & { href?: never })
|
||||
);
|
||||
|
||||
const variantClassName = {
|
||||
primary:
|
||||
"border border-transparent text-white bg-brand-500 hover:bg-brand-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-500",
|
||||
secondary: "border border-gray-200 text-brand-900 bg-white hover:bg-gray-100",
|
||||
minimal:
|
||||
"text-gray-700 bg-transparent hover:bg-gray-100 focus:outline-none focus:ring-offset-1 focus:bg-gray-100 focus:ring-brand-900 dark:text-darkgray-900 hover:dark:text-gray-50",
|
||||
minimalSecondary:
|
||||
"text-gray-700 bg-transparent hover:bg-gray-100 dark:hover:bg-darkgray-200 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-gray-100 focus:ring-brand-900 dark:text-darkgray-900 hover:dark:text-gray-50 border border-transparent hover:border-gray-300 dark:hover:border-darkgray-300",
|
||||
destructive:
|
||||
"text-gray-900 focus:text-red-700 bg-transparent hover:bg-red-100 hover:text-red-700 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-red-100 focus:ring-red-700",
|
||||
};
|
||||
const variantDisabledClassName = {
|
||||
primary: "border border-transparent bg-brand-500 bg-opacity-20 text-white",
|
||||
secondary: "border border-gray-200 text-brand-900 bg-white opacity-30",
|
||||
minimal: "text-gray-400 bg-transparent",
|
||||
minimalSecondary: "text-gray-400 bg-transparent",
|
||||
destructive: "text-red-700 bg-transparent opacity-30",
|
||||
};
|
||||
|
||||
export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonProps>(function Button(
|
||||
props: ButtonProps,
|
||||
forwardedRef
|
||||
) {
|
||||
const {
|
||||
loading = false,
|
||||
color = "primary",
|
||||
size = "base",
|
||||
type = "button",
|
||||
StartIcon,
|
||||
EndIcon,
|
||||
shallow,
|
||||
combined = false,
|
||||
// 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(
|
||||
// base styles independent what type of button it is
|
||||
"inline-flex items-center text-sm font-medium relative",
|
||||
// different styles depending on size
|
||||
size === "base" && "h-9 px-4 py-2.5 ",
|
||||
size === "lg" && "h-[36px] px-4 py-2.5 ",
|
||||
size === "icon" && "flex justify-center min-h-[36px] min-w-[36px] ",
|
||||
combined ? "" : "rounded-md",
|
||||
// different styles depending on color
|
||||
// set not-allowed cursor if disabled
|
||||
disabled ? variantDisabledClassName[color] : variantClassName[color],
|
||||
loading ? "cursor-wait" : disabled ? "cursor-not-allowed" : "",
|
||||
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,
|
||||
},
|
||||
<>
|
||||
{StartIcon && (
|
||||
<StartIcon
|
||||
className={classNames("inline-flex", size === "icon" ? "h-4 w-4 " : "mr-2 h-4 w-4 stroke-[1.5px]")}
|
||||
/>
|
||||
)}
|
||||
{props.children}
|
||||
{loading && (
|
||||
<div className="absolute top-1/2 left-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-white dark:text-black" : "text-black"
|
||||
)}
|
||||
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 && <EndIcon className="-mr-1 inline h-5 w-5 ltr:ml-2 rtl:mr-2" />}
|
||||
</>
|
||||
);
|
||||
|
||||
return props.href ? (
|
||||
<Link passHref href={props.href} shallow={shallow && shallow}>
|
||||
{element}
|
||||
</Link>
|
||||
) : (
|
||||
<Wrapper tooltip={props.tooltip}>{element}</Wrapper>
|
||||
);
|
||||
});
|
||||
|
||||
const Wrapper = ({ children, tooltip }: { tooltip?: string; children: React.ReactNode }) => {
|
||||
if (!tooltip) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return <Tooltip content={tooltip}>{children}</Tooltip>;
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title, VariantsTable, VariantColumn, RowTitles, CustomArgsTable} from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { Button } from './Button';
|
||||
|
||||
<Meta title="UI/Button" component={Button} />
|
||||
|
||||
<Title title="Buttons" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
|
||||
## Definition
|
||||
Button are clickable elements that initiates user actions. Labels in the button guide users to what action will occur when the user interacts with it.
|
||||
|
||||
## Structure
|
||||
|
||||
<CustomArgsTable of={Button} />
|
||||
|
||||
|
||||
<Examples title="Button style" footnote={
|
||||
<ul>
|
||||
<li>Primary: Signals most important actions at any given point in the application.</li>
|
||||
<li>Secondary: Gives visual weight to actions that are important</li>
|
||||
<li>Minimal: Used for actions that we want to give very little significane to</li>
|
||||
</ul>
|
||||
}>
|
||||
<Example title="Primary">
|
||||
<Button className="sb-fake-pseudo--focus">Button text</Button>
|
||||
</Example>
|
||||
<Example title="Secondary">
|
||||
<Button color="secondary">Button text</Button>
|
||||
</Example>
|
||||
<Example title="Minimal">
|
||||
<Button color="minimal">Button text</Button>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="State">
|
||||
<Example title="Default">
|
||||
<Button>Button text</Button>
|
||||
</Example>
|
||||
<Example title="Hover">
|
||||
<Button className="sb-pseudo--hover">Button text</Button>
|
||||
</Example>
|
||||
<Example title="Focus">
|
||||
<Button className="sb-pseudo--focus">Button text</Button>
|
||||
</Example>
|
||||
<Example title="Disabled">
|
||||
<Button disabled>Button text</Button>
|
||||
</Example>
|
||||
<Example title="Loading">
|
||||
<Button loading>Button text</Button>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Icons">
|
||||
<Example title="Default">
|
||||
<Button>Button text</Button>
|
||||
</Example>
|
||||
<Example title="Icon left">
|
||||
<Button StartIcon={Icon.FiPlus}>Button text</Button>
|
||||
</Example>
|
||||
<Example title="Icon right">
|
||||
<Button EndIcon={Icon.FiPlus}>Button text</Button>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
|
||||
## Anatomy
|
||||
Button are clickable elements that initiates user actions. Labels in the button guide users to what action will occur when the user interacts with it.
|
||||
|
||||
## Usage
|
||||
|
||||
<Note>In general, there should be only one Primary button in any application context</Note>
|
||||
<Note>Aim to use maximum 2 words for the button label. Button size can be flexible based on the visual hierarchy and devices. </Note>
|
||||
<Note>Hover state variant for Mobile button is an option for assistive device.</Note>
|
||||
|
||||
<Title offset title="Buttons" suffix="Variants" />
|
||||
|
||||
|
||||
<Canvas>
|
||||
<Story name="All variants">
|
||||
<VariantsTable titles={['Primary', 'Secondary', 'Minimal']} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<Button>Button text</Button>
|
||||
<Button color="secondary">Button text</Button>
|
||||
<Button color="minimal">Button text</Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Hover">
|
||||
<Button className="sb-pseudo--hover">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="secondary">Button text</Button>
|
||||
<Button className="sb-pseudo--hover" color="minimal">Button text</Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Focus">
|
||||
<Button className="sb-pseudo--focus">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="secondary">Button text</Button>
|
||||
<Button className="sb-pseudo--focus" color="minimal">Button text</Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Loading">
|
||||
<Button loading>Button text</Button>
|
||||
<Button loading color="secondary">Button text</Button>
|
||||
<Button loading color="minimal">Button text</Button>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Disabled">
|
||||
<Button disabled>Button text</Button>
|
||||
<Button disabled color="secondary">Button text</Button>
|
||||
<Button disabled color="minimal">Button text</Button>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./Button";
|
||||
@@ -0,0 +1,30 @@
|
||||
import React from "react";
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
export function ButtonGroup({ children, combined = false, containerProps }: Props) {
|
||||
return (
|
||||
<div
|
||||
{...containerProps}
|
||||
className={classNames(
|
||||
"flex",
|
||||
!combined
|
||||
? "space-x-2"
|
||||
: "[&_button]:rounded-none [&_button]:border-l-0 [&>*:first-child]:rounded-l-md [&>*:first-child]:border-l [&_a]:rounded-none [&_a]:border-l-0 [&>*:last-child]:rounded-r-md",
|
||||
containerProps?.className
|
||||
)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable,VariantsTable,VariantsRow } from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { ButtonGroup} from './ButtonGroup';
|
||||
import { Button} from '../button/Button';
|
||||
|
||||
<Meta title="UI/Button Group" component={ButtonGroup} />
|
||||
|
||||
<Title title="Button Group" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
## Definition
|
||||
Button group enables multiple buttons to be combined into a single unit. It offers users access to frequently performed, related actions.
|
||||
|
||||
## Structure
|
||||
|
||||
<CustomArgsTable of={ButtonGroup} />
|
||||
|
||||
|
||||
<Examples title="Breadcrumb style"
|
||||
footNote ={
|
||||
<ul>
|
||||
<li>
|
||||
Seperated: In general, seperated button group style can be included in container such as card, modal, and page.
|
||||
</li>
|
||||
<li>
|
||||
Combined: Combined button group can be used standalone e.g. mini toggles for calendars
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
>
|
||||
<Example title="Default" >
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</Example>
|
||||
<Example title="Combined">
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
|
||||
<Canvas>
|
||||
<Story
|
||||
name="All Variatns">
|
||||
<VariantsTable titles={["Default",'Secondary',"Minimal"]} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon"/>
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="minimal" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="minimal" />
|
||||
</ButtonGroup>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Combined">
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" />
|
||||
</ButtonGroup>
|
||||
<ButtonGroup combined>
|
||||
<Button StartIcon={Icon.FiTrash} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiNavigation} size="icon" color="secondary" />
|
||||
<Button StartIcon={Icon.FiClipboard} size="icon" color="secondary" />
|
||||
</ButtonGroup>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./ButtonGroup";
|
||||
@@ -0,0 +1,73 @@
|
||||
import React, { forwardRef, InputHTMLAttributes } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
|
||||
type Props = InputHTMLAttributes<HTMLInputElement> & {
|
||||
label?: React.ReactNode;
|
||||
description: string;
|
||||
descriptionAsLabel?: boolean;
|
||||
informationIconText?: string;
|
||||
error?: boolean;
|
||||
};
|
||||
|
||||
const CheckboxField = forwardRef<HTMLInputElement, Props>(
|
||||
({ label, description, error, informationIconText, disabled, ...rest }, ref) => {
|
||||
const descriptionAsLabel = !label || rest.descriptionAsLabel;
|
||||
return (
|
||||
<div className="block items-center sm:flex">
|
||||
{label && (
|
||||
<div className="min-w-48 mb-4 sm:mb-0">
|
||||
{React.createElement(
|
||||
descriptionAsLabel ? "div" : "label",
|
||||
{
|
||||
className: classNames("flex text-sm font-medium text-gray-900"),
|
||||
...(!descriptionAsLabel
|
||||
? {
|
||||
htmlFor: rest.id,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
label
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="w-full">
|
||||
<div className="relative flex items-start">
|
||||
{React.createElement(
|
||||
descriptionAsLabel ? "label" : "div",
|
||||
{
|
||||
className: classNames(
|
||||
"relative flex items-start",
|
||||
!error && descriptionAsLabel ? "text-gray-900" : "text-neutral-900",
|
||||
error && "text-red-800"
|
||||
),
|
||||
},
|
||||
<>
|
||||
<div className="flex h-5 items-center">
|
||||
<input
|
||||
{...rest}
|
||||
ref={ref}
|
||||
type="checkbox"
|
||||
className={classNames(
|
||||
"text-primary-600 focus:ring-primary-500 mr-2 h-4 w-4 rounded border-gray-300 ",
|
||||
!error && disabled
|
||||
? "bg-gray-300 checked:bg-gray-300"
|
||||
: "checked:bg-gray-800 hover:bg-gray-100",
|
||||
error && "border-red-800 checked:bg-red-800 hover:bg-red-400"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-sm ltr:ml-3 rtl:mr-3">{description}</span>
|
||||
</>
|
||||
)}
|
||||
{/* {informationIconText && <InfoBadge content={informationIconText}></InfoBadge>} */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
CheckboxField.displayName = "CheckboxField";
|
||||
|
||||
export default CheckboxField;
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable,VariantsTable,VariantsRow } from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import Checkbox from './Checkbox';
|
||||
|
||||
|
||||
<Meta title="UI/Form/Checkbox" component={Checkbox} />
|
||||
|
||||
<Title title="Checkbox " suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
## Definition
|
||||
Checkboxes are used in forms and databases to indicate an answer to a question, apply a batch of settings or allow the user to make a multi-selection from a list. Alternatively, a single checkbox may be used for making single selections
|
||||
## Structure
|
||||
|
||||
<CustomArgsTable of={Checkbox} />
|
||||
|
||||
|
||||
<Examples title="Checkbox style">
|
||||
<Example title="Default" >
|
||||
<Checkbox label="Default" />
|
||||
</Example>
|
||||
<Example title="Error" >
|
||||
<Checkbox label="Error" error/>
|
||||
</Example>
|
||||
<Example title="Disabled" >
|
||||
<Checkbox label="Disabled" disabled/>
|
||||
</Example>
|
||||
<Example title="Disabled" >
|
||||
<Checkbox label="Disabled Checked" checked disabled />
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Description As Label">
|
||||
<Example title="Default" >
|
||||
<Checkbox descriptionAsLabel description="Default Description" />
|
||||
</Example>
|
||||
<Example title="Error" >
|
||||
<Checkbox descriptionAsLabel description="Default Description" error/>
|
||||
</Example>
|
||||
<Example title="Disabled" >
|
||||
<Checkbox descriptionAsLabel description="Default Description" disabled/>
|
||||
</Example>
|
||||
<Example title="Disabled" >
|
||||
<Checkbox descriptionAsLabel description="Default Description" disabled checked/>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Canvas>
|
||||
<Story name="Checkbox">
|
||||
<VariantsTable titles={[""]} columnMinWidth={150}>
|
||||
<VariantsRow variant="Default">
|
||||
<Checkbox label="Default" />
|
||||
<Checkbox label="Error" error/>
|
||||
<Checkbox label="Disabled" disabled/>
|
||||
<Checkbox label="Disabled Checked" checked disabled />
|
||||
</VariantsRow>
|
||||
<VariantsRow variant="Description As Label">
|
||||
<Checkbox description="Default" descriptionAsLabel />
|
||||
<Checkbox description="Error" error descriptionAsLabel/>
|
||||
<Checkbox description="Disabled" disabled descriptionAsLabel/>
|
||||
<Checkbox description="Disabled Checked" checked disabled descriptionAsLabel/>
|
||||
</VariantsRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as Checkbox } from "./Checkbox";
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./checkbox";
|
||||
export * from "./inputs/HintOrErrors";
|
||||
export * from "./inputs/Input";
|
||||
export * from "./inputs/Label";
|
||||
@@ -0,0 +1,102 @@
|
||||
import { X, Circle, Check } from "react-feather";
|
||||
import { FieldValues, useFormContext } from "react-hook-form";
|
||||
|
||||
// TODO: Refactor import once V1 migration has happened
|
||||
import { Icon } from "../../../Icon";
|
||||
|
||||
export function HintsOrErrors<T extends FieldValues = FieldValues>(props: {
|
||||
hintErrors?: string[];
|
||||
fieldName: string;
|
||||
t: (key: string) => string;
|
||||
}) {
|
||||
const methods = useFormContext() as ReturnType<typeof useFormContext> | null;
|
||||
/* If there's no methods it means we're using these components outside a React Hook Form context */
|
||||
if (!methods) return null;
|
||||
const { formState } = methods;
|
||||
const { hintErrors, fieldName, t } = props;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const fieldErrors: FieldErrors<T> | undefined = formState.errors[fieldName];
|
||||
|
||||
if (!hintErrors && fieldErrors && !fieldErrors.message) {
|
||||
// no hints passed, field errors exist and they are custom ones
|
||||
return (
|
||||
<div className="text-gray mt-2 flex items-center text-sm text-gray-700">
|
||||
<ul className="ml-2">
|
||||
{Object.keys(fieldErrors).map((key: string) => {
|
||||
return (
|
||||
<li key={key} className="text-blue-700">
|
||||
{t(`${fieldName}_hint_${key}`)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (hintErrors && fieldErrors) {
|
||||
// hints passed, field errors exist
|
||||
return (
|
||||
<div className="text-gray mt-2 flex items-center text-sm text-gray-700">
|
||||
<ul className="ml-2">
|
||||
{hintErrors.map((key: string) => {
|
||||
const submitted = formState.isSubmitted;
|
||||
const error = fieldErrors[key] || fieldErrors.message;
|
||||
return (
|
||||
<li
|
||||
key={key}
|
||||
className={error !== undefined ? (submitted ? "text-red-700" : "") : "text-green-600"}>
|
||||
{error !== undefined ? (
|
||||
submitted ? (
|
||||
<X size="12" strokeWidth="3" className="mr-2 -ml-1 inline-block" />
|
||||
) : (
|
||||
<Circle fill="currentColor" size="5" className="mr-2 inline-block" />
|
||||
)
|
||||
) : (
|
||||
<Check size="12" strokeWidth="3" className="mr-2 -ml-1 inline-block" />
|
||||
)}
|
||||
{t(`${fieldName}_hint_${key}`)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// errors exist, not custom ones, just show them as is
|
||||
if (fieldErrors) {
|
||||
return (
|
||||
<div className="text-gray mt-2 flex items-center text-sm text-red-700">
|
||||
<Icon.FiInfo className="mr-1 h-3 w-3" />
|
||||
<>{fieldErrors.message}</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!hintErrors) return null;
|
||||
|
||||
// hints passed, no errors exist, proceed to just show hints
|
||||
return (
|
||||
<div className="text-gray mt-2 flex items-center text-sm text-gray-700">
|
||||
<ul className="ml-2">
|
||||
{hintErrors.map((key: string) => {
|
||||
// if field was changed, as no error exist, show checked status and color
|
||||
const dirty = formState.dirtyFields[fieldName];
|
||||
return (
|
||||
<li key={key} className={!!dirty ? "text-green-600" : ""}>
|
||||
{!!dirty ? (
|
||||
<Icon.FiCheck size="12" strokeWidth="3" className="mr-2 -ml-1 inline-block" />
|
||||
) : (
|
||||
<Icon.FiCircle fill="currentColor" size="5" className="mr-2 inline-block" />
|
||||
)}
|
||||
{t(`${fieldName}_hint_${key}`)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
import { forwardRef, ReactElement, ReactNode, Ref, useCallback, useId, useState } from "react";
|
||||
import React from "react";
|
||||
import { Eye, EyeOff } from "react-feather";
|
||||
import { FieldValues, FormProvider, SubmitHandler, useFormContext, UseFormReturn } from "react-hook-form";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Skeleton, Tooltip, Alert, showToast } from "@calcom/ui/v2";
|
||||
|
||||
import { HintsOrErrors } from "./HintOrErrors";
|
||||
import { Label } from "./Label";
|
||||
|
||||
type InputProps = JSX.IntrinsicElements["input"];
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(props, ref) {
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
ref={ref}
|
||||
className={classNames(
|
||||
"mb-2 block h-9 w-full rounded-md border border-gray-300 py-2 px-3 text-sm placeholder:text-gray-400 hover:border-gray-400 focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1",
|
||||
props.className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export function InputLeading(props: JSX.IntrinsicElements["div"]) {
|
||||
return (
|
||||
<span className="inline-flex flex-shrink-0 items-center rounded-l-sm border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm">
|
||||
{props.children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
type InputFieldProps = {
|
||||
label?: ReactNode;
|
||||
hint?: ReactNode;
|
||||
hintErrors?: string[];
|
||||
addOnLeading?: ReactNode;
|
||||
addOnSuffix?: ReactNode;
|
||||
addOnFilled?: boolean;
|
||||
error?: string;
|
||||
labelSrOnly?: boolean;
|
||||
containerClassName?: string;
|
||||
t?: (key: string) => string;
|
||||
} & React.ComponentProps<typeof Input> & {
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
labelClassName?: string;
|
||||
};
|
||||
|
||||
type AddonProps = {
|
||||
children: React.ReactNode;
|
||||
isFilled?: boolean;
|
||||
className?: string;
|
||||
error?: boolean;
|
||||
};
|
||||
|
||||
const Addon = ({ isFilled, children, className, error }: AddonProps) => (
|
||||
<div
|
||||
className={classNames(
|
||||
"addon-wrapper h-9 border border-gray-300 px-3",
|
||||
isFilled && "bg-gray-100",
|
||||
className
|
||||
)}>
|
||||
<div className={classNames("flex h-full flex-col justify-center px-1 text-sm", error && "text-red-900")}>
|
||||
<span className="whitespace-nowrap py-2.5">{children}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputField(props, ref) {
|
||||
const id = useId();
|
||||
const { t: _t, isLocaleReady, i18n } = useLocale();
|
||||
const t = props.t || _t;
|
||||
const name = props.name || "";
|
||||
const {
|
||||
label = t(name),
|
||||
labelProps,
|
||||
labelClassName,
|
||||
placeholder = isLocaleReady && i18n.exists(name + "_placeholder") ? t(name + "_placeholder") : "",
|
||||
className,
|
||||
addOnLeading,
|
||||
addOnSuffix,
|
||||
addOnFilled = true,
|
||||
hint,
|
||||
hintErrors,
|
||||
labelSrOnly,
|
||||
containerClassName,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
t: __t,
|
||||
...passThrough
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
{!!name && (
|
||||
<Skeleton
|
||||
as={Label}
|
||||
htmlFor={id}
|
||||
loadingClassName="w-16"
|
||||
{...labelProps}
|
||||
className={classNames(labelClassName, labelSrOnly && "sr-only", props.error && "text-red-900")}>
|
||||
{label}
|
||||
</Skeleton>
|
||||
)}
|
||||
{addOnLeading || addOnSuffix ? (
|
||||
<div className="relative mb-1 flex items-center rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-neutral-800 focus-within:ring-offset-1">
|
||||
{addOnLeading && (
|
||||
<Addon isFilled={addOnFilled} className="rounded-l-md border-r-0">
|
||||
{addOnLeading}
|
||||
</Addon>
|
||||
)}
|
||||
<Input
|
||||
id={id}
|
||||
placeholder={placeholder}
|
||||
className={classNames(
|
||||
className,
|
||||
addOnLeading && "rounded-l-none",
|
||||
addOnSuffix && "rounded-r-none",
|
||||
"!my-0 !ring-0"
|
||||
)}
|
||||
{...passThrough}
|
||||
ref={ref}
|
||||
/>
|
||||
{addOnSuffix && (
|
||||
<Addon isFilled={addOnFilled} className="rounded-r-md border-l-0">
|
||||
{addOnSuffix}
|
||||
</Addon>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Input id={id} placeholder={placeholder} className={className} {...passThrough} ref={ref} />
|
||||
)}
|
||||
<HintsOrErrors hintErrors={hintErrors} fieldName={name} t={t} />
|
||||
{hint && <div className="text-gray mt-2 flex items-center text-sm text-gray-700">{hint}</div>}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export const TextField = forwardRef<HTMLInputElement, InputFieldProps>(function TextField(props, ref) {
|
||||
return <InputField ref={ref} {...props} />;
|
||||
});
|
||||
|
||||
export const PasswordField = forwardRef<HTMLInputElement, InputFieldProps>(function PasswordField(
|
||||
props,
|
||||
ref
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
|
||||
const toggleIsPasswordVisible = useCallback(
|
||||
() => setIsPasswordVisible(!isPasswordVisible),
|
||||
[isPasswordVisible, setIsPasswordVisible]
|
||||
);
|
||||
const textLabel = isPasswordVisible ? t("hide_password") : t("show_password");
|
||||
|
||||
return (
|
||||
<div className="relative [&_.group:hover_.addon-wrapper]:border-gray-400 [&_.group:focus-within_.addon-wrapper]:border-neutral-300">
|
||||
<InputField
|
||||
type={isPasswordVisible ? "text" : "password"}
|
||||
placeholder={props.placeholder || "•••••••••••••"}
|
||||
ref={ref}
|
||||
{...props}
|
||||
className={classNames("mb-0 border-r-0 pr-10", props.className)}
|
||||
addOnFilled={false}
|
||||
addOnSuffix={
|
||||
<Tooltip content={textLabel}>
|
||||
<button
|
||||
className="absolute right-3 bottom-0 h-9 text-gray-900"
|
||||
type="button"
|
||||
onClick={() => toggleIsPasswordVisible()}>
|
||||
{isPasswordVisible ? (
|
||||
<EyeOff className="h-4 stroke-[2.5px]" />
|
||||
) : (
|
||||
<Eye className="h-4 stroke-[2.5px]" />
|
||||
)}
|
||||
<span className="sr-only">{textLabel}</span>
|
||||
</button>
|
||||
</Tooltip>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export const EmailInput = forwardRef<HTMLInputElement, InputFieldProps>(function EmailInput(props, ref) {
|
||||
return (
|
||||
<Input
|
||||
ref={ref}
|
||||
type="email"
|
||||
autoCapitalize="none"
|
||||
autoComplete="email"
|
||||
autoCorrect="off"
|
||||
inputMode="email"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export const EmailField = forwardRef<HTMLInputElement, InputFieldProps>(function EmailField(props, ref) {
|
||||
return (
|
||||
<InputField
|
||||
ref={ref}
|
||||
type="email"
|
||||
autoCapitalize="none"
|
||||
autoComplete="email"
|
||||
autoCorrect="off"
|
||||
inputMode="email"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
type TextAreaProps = JSX.IntrinsicElements["textarea"];
|
||||
|
||||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(function TextAreaInput(props, ref) {
|
||||
return (
|
||||
<textarea
|
||||
ref={ref}
|
||||
{...props}
|
||||
className={classNames(
|
||||
"block w-full rounded-md border border-gray-300 py-2 px-3 hover:border-gray-400 focus:border-neutral-300 focus:outline-none focus:ring-2 focus:ring-neutral-800 focus:ring-offset-1 sm:text-sm",
|
||||
props.className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
type TextAreaFieldProps = {
|
||||
label?: ReactNode;
|
||||
t?: (key: string) => string;
|
||||
} & React.ComponentProps<typeof TextArea> & {
|
||||
name: string;
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
};
|
||||
|
||||
export const TextAreaField = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>(function TextField(
|
||||
props,
|
||||
ref
|
||||
) {
|
||||
const id = useId();
|
||||
const { t: _t } = useLocale();
|
||||
const t = props.t || _t;
|
||||
const methods = useFormContext();
|
||||
const {
|
||||
label = t(props.name as string),
|
||||
labelProps,
|
||||
/** Prevents displaying untranslated placeholder keys */
|
||||
placeholder = t(props.name + "_placeholder") !== props.name + "_placeholder"
|
||||
? t(props.name + "_placeholder")
|
||||
: "",
|
||||
...passThrough
|
||||
} = props;
|
||||
return (
|
||||
<div>
|
||||
{!!props.name && (
|
||||
<Label htmlFor={id} {...labelProps}>
|
||||
{label}
|
||||
</Label>
|
||||
)}
|
||||
<TextArea ref={ref} placeholder={placeholder} {...passThrough} />
|
||||
{methods?.formState?.errors[props.name]?.message && (
|
||||
<Alert
|
||||
className="mt-1"
|
||||
severity="error"
|
||||
message={<>{methods.formState.errors[props.name]?.message}</>}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
type FormProps<T extends object> = { form: UseFormReturn<T>; handleSubmit: SubmitHandler<T> } & Omit<
|
||||
JSX.IntrinsicElements["form"],
|
||||
"onSubmit"
|
||||
>;
|
||||
|
||||
const PlainForm = <T extends FieldValues>(props: FormProps<T>, ref: Ref<HTMLFormElement>) => {
|
||||
const { form, handleSubmit, ...passThrough } = props;
|
||||
|
||||
return (
|
||||
<FormProvider {...form}>
|
||||
<form
|
||||
ref={ref}
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
form
|
||||
.handleSubmit(handleSubmit)(event)
|
||||
.catch((err) => {
|
||||
showToast(`${getErrorFromUnknown(err).message}`, "error");
|
||||
});
|
||||
}}
|
||||
{...passThrough}>
|
||||
{
|
||||
/* @see https://react-hook-form.com/advanced-usage/#SmartFormComponent */
|
||||
React.Children.map(props.children, (child) => {
|
||||
return typeof child !== "string" &&
|
||||
typeof child !== "number" &&
|
||||
typeof child !== "boolean" &&
|
||||
child &&
|
||||
"props" in child &&
|
||||
child.props.name
|
||||
? React.createElement(child.type, {
|
||||
...{
|
||||
...child.props,
|
||||
register: form.register,
|
||||
key: child.props.name,
|
||||
},
|
||||
})
|
||||
: child;
|
||||
})
|
||||
}
|
||||
</form>
|
||||
</FormProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export const Form = forwardRef(PlainForm) as <T extends FieldValues>(
|
||||
p: FormProps<T> & { ref?: Ref<HTMLFormElement> }
|
||||
) => ReactElement;
|
||||
|
||||
export function FieldsetLegend(props: JSX.IntrinsicElements["legend"]) {
|
||||
return (
|
||||
<legend {...props} className={classNames("text-sm font-medium text-gray-700", props.className)}>
|
||||
{props.children}
|
||||
</legend>
|
||||
);
|
||||
}
|
||||
|
||||
export function InputGroupBox(props: JSX.IntrinsicElements["div"]) {
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
className={classNames("space-y-2 rounded-sm border border-gray-300 bg-white p-2", props.className)}>
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const MinutesField = forwardRef<HTMLInputElement, InputFieldProps>(function MinutesField(props, ref) {
|
||||
return <InputField ref={ref} type="number" min={0} {...props} addOnSuffix="mins" />;
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export function Label(props: JSX.IntrinsicElements["label"]) {
|
||||
return (
|
||||
<label
|
||||
{...props}
|
||||
className={classNames("mb-2 block text-sm font-medium leading-none text-gray-700", props.className)}>
|
||||
{props.children}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
||||
import { Examples, Example, Note, Title,CustomArgsTable, VariantRow,VariantsTable} from '@calcom/storybook/components'
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import {InputField} from "./Input"
|
||||
|
||||
<Meta title="UI/Form/Input Field" component={InputField} />
|
||||
|
||||
<Title title="Inputs" suffix="Brief" subtitle="Version 2.0 — Last Update: 22 Aug 2022"/>
|
||||
|
||||
## Definition
|
||||
Text fields allow users to input and edit text into the product. Usually appear in forms and modals. Various options can be shown with the field to communicate the input requirements.## Structure
|
||||
|
||||
## Structure
|
||||
<CustomArgsTable of={InputField} />
|
||||
|
||||
|
||||
<Examples title="Inputs" footnote={
|
||||
<ul>
|
||||
<li>The width is flexible but the height is fixed for both desktop and mobile. </li>
|
||||
</ul>
|
||||
}>
|
||||
<Example title="Default">
|
||||
<InputField placeholder="Default"/>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Input Types">
|
||||
<Example title="Default">
|
||||
<InputField placeholder="Default"/>
|
||||
</Example>
|
||||
<Example title="Prefix">
|
||||
<InputField placeholder="Prefix" addOnLeading={<>Prefix</>}/>
|
||||
</Example>
|
||||
<Example title="Suffix">
|
||||
<InputField placeholder="Suffic" addOnSuffix={<>Suffix</>}/>
|
||||
</Example>
|
||||
<Example title="Focused">
|
||||
<InputField placeholder="Focused" className="sb-pseudo--focus"/>
|
||||
</Example>
|
||||
<Example title="Hovered">
|
||||
<InputField placeholder="Hovered" className="sb-pseudo--hover"/>
|
||||
</Example>
|
||||
<Example title="Error">
|
||||
<InputField placeholder="Error" error="Error"/>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Examples title="Input Text">
|
||||
<Example title="Default">
|
||||
<InputField />
|
||||
</Example>
|
||||
<Example title="Placeholder">
|
||||
<InputField placeholder="Placeholder"/>
|
||||
</Example>
|
||||
<Example title="Filled">
|
||||
<InputField value="Filled"/>
|
||||
</Example>
|
||||
</Examples>
|
||||
|
||||
<Title offset title="Input" suffix="Variants" />
|
||||
|
||||
<Canvas>
|
||||
<Story name="All Variants">
|
||||
<VariantsTable titles={['Default','Focused', 'Hovered']} columnMinWidth={150}>
|
||||
<VariantRow variant="Default">
|
||||
<InputField placeholder="Default"/>
|
||||
<InputField placeholder="Focused" className="sb-pseudo--focus"/>
|
||||
<InputField placeholder="Hovered" className="sb-pseudo--hover"/>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Prefixed">
|
||||
<InputField placeholder="Default" addOnLeading={<>Prefix</>}/>
|
||||
<InputField placeholder="Focused" className="sb-pseudo--focus" addOnLeading={<>Prefix</>}/>
|
||||
<InputField placeholder="Hovered" className="sb-pseudo--hover" addOnLeading={<>Prefix</>}/>
|
||||
</VariantRow>
|
||||
<VariantRow variant="Suffix">
|
||||
<InputField placeholder="Default" addOnSuffix={<>Prefix</>}/>
|
||||
<InputField placeholder="Focused" className="sb-pseudo--focus" addOnSuffix={<>Prefix</>}/>
|
||||
<InputField placeholder="Hovered" className="sb-pseudo--hover" addOnSuffix={<>Prefix</>}/>
|
||||
</VariantRow>
|
||||
</VariantsTable>
|
||||
</Story>
|
||||
</Canvas>
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from "./avatar";
|
||||
export * from "./button";
|
||||
export * from "./buttonGroup";
|
||||
export * from "./badge";
|
||||
export * from "./breadcrumb";
|
||||
export * from "./form";
|
||||
Reference in new issue
Block a user