feat: routing v3 design (#20607)
Co-authored-by: Sean Brydon <[email protected]> Co-authored-by: Eunjae Lee <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
35 files changed
+3018
-1886
No files matched your search
@@ -7,21 +7,81 @@ import classNames from "@calcom/ui/classNames";
|
||||
|
||||
import type { BadgeProps } from "../badge";
|
||||
import { Badge } from "../badge";
|
||||
import { Divider } from "../divider";
|
||||
import { Button } from "../button";
|
||||
import { Dropdown, DropdownMenuTrigger, DropdownMenuContent, DropdownItem } from "../dropdown";
|
||||
import { Input } from "../form/inputs/TextField";
|
||||
import { Icon } from "../icon";
|
||||
import type { IconName } from "../icon";
|
||||
|
||||
type Action = { check: () => boolean; fn: () => void };
|
||||
|
||||
type FormCardActionsProps = {
|
||||
deleteField?: Action | null;
|
||||
duplicateField?: Action | null;
|
||||
};
|
||||
|
||||
const FormCardActions = ({ deleteField, duplicateField }: FormCardActionsProps) => {
|
||||
type ActionItem = {
|
||||
label: string;
|
||||
icon: IconName;
|
||||
onClick: () => void;
|
||||
color?: "destructive" | "minimal";
|
||||
};
|
||||
|
||||
const actions: ActionItem[] = [
|
||||
duplicateField?.fn && {
|
||||
label: "Duplicate",
|
||||
icon: "copy",
|
||||
onClick: () => duplicateField.fn(),
|
||||
},
|
||||
deleteField?.fn && {
|
||||
label: "Delete",
|
||||
icon: "trash",
|
||||
color: "minimal",
|
||||
onClick: () => deleteField.fn(),
|
||||
},
|
||||
].filter((action): action is ActionItem => !!action);
|
||||
|
||||
if (actions.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Dropdown>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button type="button" variant="icon" color="minimal" className="ml-2">
|
||||
<Icon name="ellipsis" className="text-default h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{actions.map((action) => (
|
||||
<DropdownItem
|
||||
key={action.label}
|
||||
StartIcon={action.icon}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
action.onClick();
|
||||
}}
|
||||
color={action.color}>
|
||||
{action.label}
|
||||
</DropdownItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default function FormCard({
|
||||
children,
|
||||
label,
|
||||
isLabelEditable,
|
||||
onLabelChange,
|
||||
deleteField,
|
||||
duplicateField,
|
||||
moveUp,
|
||||
moveDown,
|
||||
className,
|
||||
badge,
|
||||
collapsible = true,
|
||||
leftIcon,
|
||||
...restProps
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
@@ -29,14 +89,17 @@ export default function FormCard({
|
||||
isLabelEditable?: boolean;
|
||||
onLabelChange?: (label: string) => void;
|
||||
deleteField?: Action | null;
|
||||
duplicateField?: Action | null;
|
||||
moveUp?: Action | null;
|
||||
moveDown?: Action | null;
|
||||
className?: string;
|
||||
badge?: { text: string; href?: string; variant: BadgeProps["variant"] } | null;
|
||||
leftIcon?: IconName;
|
||||
collapsible?: boolean;
|
||||
} & JSX.IntrinsicElements["div"]) {
|
||||
className = classNames(
|
||||
className,
|
||||
"flex items-center group relative w-full rounded-md p-4 border border-subtle"
|
||||
"flex items-center group relative w-full rounded-2xl p-1 border border-subtle bg-muted mb-2",
|
||||
className
|
||||
);
|
||||
|
||||
const [isCollapsed, setIsCollapsed] = useState(false);
|
||||
@@ -47,11 +110,11 @@ export default function FormCard({
|
||||
|
||||
return (
|
||||
<div className={className} {...restProps}>
|
||||
<div>
|
||||
<div className="absolute left-0 top-1/2 -translate-y-1/2">
|
||||
{moveUp?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="bg-default text-muted hover:text-emphasis invisible absolute left-0 -ml-[13px] -mt-10 flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100 "
|
||||
className="bg-default text-muted hover:text-emphasis invisible -ml-[13px] mb-1 flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100"
|
||||
onClick={() => moveUp?.fn()}>
|
||||
<Icon name="arrow-up" />
|
||||
</button>
|
||||
@@ -59,15 +122,40 @@ export default function FormCard({
|
||||
{moveDown?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="bg-default text-muted hover:text-emphasis invisible absolute left-0 -ml-[13px] -mt-2 flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100"
|
||||
className="bg-default text-muted hover:text-emphasis invisible -ml-[13px] flex h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:border-transparent hover:shadow group-hover:visible group-hover:scale-100"
|
||||
onClick={() => moveDown?.fn()}>
|
||||
<Icon name="arrow-down" />
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div className="flex items-center justify-between p-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{leftIcon && (
|
||||
<div className="text-subtle border-subtle rounded-lg border p-1.5">
|
||||
<Icon name={leftIcon} className="text-default h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
{collapsible && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="icon"
|
||||
color="minimal"
|
||||
CustomStartIcon={
|
||||
<Icon
|
||||
name="chevron-up"
|
||||
className={classNames(
|
||||
"text-default h-4 w-4 transition-transform",
|
||||
isCollapsed && "rotate-180"
|
||||
)}
|
||||
/>
|
||||
}
|
||||
onClick={() => {
|
||||
toggleFormCard();
|
||||
}}
|
||||
className="text-muted"
|
||||
/>
|
||||
)}
|
||||
{isLabelEditable ? (
|
||||
<Input type="text" value={label} onChange={(e) => onLabelChange?.(e.target.value)} />
|
||||
) : (
|
||||
@@ -80,31 +168,10 @@ export default function FormCard({
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
toggleFormCard();
|
||||
}}
|
||||
color="secondary">
|
||||
<Icon name="chevrons-down-up" className="text-default h-4 w-4" />
|
||||
</button>
|
||||
{deleteField?.check() ? (
|
||||
<button
|
||||
type="button"
|
||||
className="ml-2"
|
||||
onClick={() => {
|
||||
deleteField?.fn();
|
||||
}}
|
||||
color="secondary">
|
||||
<Icon name="trash-2" className="text-default h-4 w-4" />
|
||||
</button>
|
||||
) : null}
|
||||
<FormCardActions deleteField={deleteField} duplicateField={duplicateField} />
|
||||
</div>
|
||||
</div>
|
||||
<div className={isCollapsed ? "hidden" : ""}>
|
||||
<Divider className="mb-6 mt-3" />
|
||||
{children}
|
||||
</div>
|
||||
<div className={isCollapsed ? "hidden" : ""}>{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -47,6 +47,7 @@ interface MultiOptionInputProps<TFieldValues extends FieldValues> {
|
||||
*/
|
||||
keyPattern?: string;
|
||||
addOptionLabel?: string;
|
||||
addOptionButtonColor?: "primary" | "secondary" | "minimal";
|
||||
optionPlaceholders?: string[];
|
||||
/**
|
||||
* Placeholders for value fields in key-value mode
|
||||
@@ -93,6 +94,7 @@ export const MultiOptionInput = <TFieldValues extends FieldValues>({
|
||||
showRemoveButton: _showRemoveButton,
|
||||
minOptions = 1,
|
||||
disabled = false,
|
||||
addOptionButtonColor = "primary",
|
||||
}: MultiOptionInputProps<TFieldValues>) => {
|
||||
const [animationRef] = useAutoAnimate<HTMLUListElement>();
|
||||
const { control } = useFormContext<TFieldValues>();
|
||||
@@ -255,6 +257,7 @@ export const MultiOptionInput = <TFieldValues extends FieldValues>({
|
||||
required
|
||||
addOnClassname="bg-transparent border-0"
|
||||
{...control.register(`${fieldArrayName}.${index}.label` as Path<TFieldValues>)}
|
||||
data-testid={`${fieldArrayName}.${index}-input`}
|
||||
addOnSuffix={
|
||||
showRemoveButton ? (
|
||||
<button
|
||||
@@ -299,7 +302,7 @@ export const MultiOptionInput = <TFieldValues extends FieldValues>({
|
||||
<div className={classNames("flex")}>
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
color={addOptionButtonColor}
|
||||
StartIcon="plus"
|
||||
onClick={addOption}
|
||||
className="mt-4 border-none"
|
||||
|
||||
@@ -81,7 +81,7 @@ export const Select = <
|
||||
? "h-7 px-2"
|
||||
: "h-9 px-3",
|
||||
props.isDisabled && "bg-subtle",
|
||||
size === "sm" ? "rounded-md" : "rounded-[10px]",
|
||||
"rounded-[10px]",
|
||||
"[&:focus-within]:border-emphasis [&:focus-within]:shadow-outline-gray-focused [&:focus-within]:ring-0 !flex",
|
||||
innerClassNames?.control
|
||||
),
|
||||
|
||||
@@ -54,21 +54,29 @@ export const BooleanToggleGroup = function BooleanToggleGroup({
|
||||
onValueChange(defaultValue);
|
||||
return null;
|
||||
}
|
||||
|
||||
const commonClass = classNames(
|
||||
getVariantStyles(variant).commonClass,
|
||||
"inline-flex items-center justify-center rounded text-sm font-medium leading-4 transition",
|
||||
"inline-flex items-center justify-center rounded-lg text-sm leading-none transition",
|
||||
disabled && "cursor-not-allowed"
|
||||
);
|
||||
|
||||
const selectedClass = classNames(commonClass, "bg-emphasis text-emphasis");
|
||||
const unselectedClass = classNames(commonClass, "text-default hover:bg-subtle hover:text-emphasis");
|
||||
const selectedClass = classNames(
|
||||
commonClass,
|
||||
"bg-default border-subtle text-emphasis shadow-[0px_2px_3px_0px_rgba(0,0,0,0.03),0px_2px_2px_-1px_rgba(0,0,0,0.03)]"
|
||||
);
|
||||
const unselectedClass = classNames(
|
||||
commonClass,
|
||||
"text-default border-transparent [&[aria-checked='false']]:hover:text-emphasis"
|
||||
);
|
||||
|
||||
return (
|
||||
<ToggleGroupPrimitive
|
||||
value={yesNoValue}
|
||||
type="single"
|
||||
disabled={disabled}
|
||||
className={classNames(
|
||||
"border-subtle flex h-9 space-x-2 rounded-md border p-1 rtl:space-x-reverse",
|
||||
"bg-subtle border-subtle inline-flex gap-0.5 rounded-[10px] border p-0.5 rtl:flex-row-reverse",
|
||||
getVariantStyles(variant).toggleGroupPrimitiveClass
|
||||
)}
|
||||
onValueChange={(yesNoValue: "yes" | "no") => {
|
||||
|
||||
@@ -12,6 +12,7 @@ interface ToggleGroupProps extends Omit<RadixToggleGroup.ToggleGroupSingleProps,
|
||||
disabled?: boolean;
|
||||
tooltip?: string;
|
||||
iconLeft?: ReactNode;
|
||||
dataTestId?: string;
|
||||
}[];
|
||||
isFullWidth?: boolean;
|
||||
orientation?: "horizontal" | "vertical";
|
||||
@@ -67,7 +68,7 @@ export const ToggleGroup = ({
|
||||
<RadixToggleGroup.Item
|
||||
disabled={option.disabled}
|
||||
value={option.value}
|
||||
data-testid={`toggle-group-item-${option.value}`}
|
||||
data-testid={option.dataTestId ?? `toggle-group-item-${option.value}`}
|
||||
className={classNames(
|
||||
"aria-checked:bg-default aria-checked:border-subtle rounded-lg border border-transparent p-1.5 text-sm leading-none transition aria-checked:shadow-[0px_2px_3px_0px_rgba(0,0,0,0.03),0px_2px_2px_-1px_rgba(0,0,0,0.03)]",
|
||||
option.disabled
|
||||
|
||||
@@ -68,7 +68,8 @@ const SheetContent = React.forwardRef<
|
||||
ref={forwardedRef}
|
||||
className={classNames(
|
||||
// base
|
||||
"fixed inset-y-2 mx-auto flex w-[95vw] flex-1 flex-col overflow-y-auto rounded-xl border p-4 shadow-lg focus:outline-none max-sm:inset-x-2 sm:inset-y-2 sm:right-2 sm:max-w-lg sm:p-6",
|
||||
"fixed inset-y-4 mx-auto flex w-[95vw] flex-1 flex-col overflow-y-auto rounded-xl border p-4 shadow-lg focus:outline-none sm:right-2 sm:max-w-lg sm:p-6",
|
||||
// "inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm sm:p-6 p-4 shadow-lg rounded-xl border ",
|
||||
// border color
|
||||
"border-subtle",
|
||||
// background color
|
||||
|
||||
Reference in new issue
Block a user