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,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";
|
||||
Reference in new issue
Block a user