From 53c37a9ddff5aa198075336ab4bd92276f2ce936 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:41:23 +0100 Subject: [PATCH] feat: refactor drawer component (#15892) * Add sheet component * refactor user edit sheet * refactor availbility sheet edit * Remove tremor raw sheet text * remove accidently file commit * fix overflow issue --- packages/config/tailwind-preset.js | 10 + .../components/AvailabilityEditSheet.tsx | 39 ++- .../UserTable/EditSheet/EditUserForm.tsx | 146 ++++---- .../UserTable/EditSheet/EditUserSheet.tsx | 48 ++- packages/ui/components/sheet/sheet.tsx | 330 ++++++++---------- packages/ui/index.tsx | 1 + 6 files changed, 287 insertions(+), 287 deletions(-) diff --git a/packages/config/tailwind-preset.js b/packages/config/tailwind-preset.js index b5ca2bbbf6..c93ef3b485 100644 --- a/packages/config/tailwind-preset.js +++ b/packages/config/tailwind-preset.js @@ -105,11 +105,21 @@ module.exports = { spinning: { "100%": { transform: "rotate(360deg)" }, }, + drawerSlideLeftAndFade: { + from: { opacity: "0", transform: "translateX(100%)" }, + to: { opacity: "1", transform: "translateX(0)" }, + }, + drawerSlideRightAndFade: { + from: { opacity: "1", transform: "translateX(0)" }, + to: { opacity: "0", transform: "translateX(100%)" }, + }, }, animation: { "fade-in-up": "fade-in-up 600ms var(--animation-delay, 0ms) cubic-bezier(.21,1.02,.73,1) forwards", "fade-in-bottom": "fade-in-bottom cubic-bezier(.21,1.02,.73,1) forwards", spinning: "spinning 0.75s linear infinite", + drawerSlideLeftAndFade: "drawerSlideLeftAndFade 150ms cubic-bezier(0.16, 1, 0.3, 1)", + drawerSlideRightAndFade: "drawerSlideRightAndFade 150ms ease-in", }, boxShadow: { dropdown: "0px 2px 6px -1px rgba(0, 0, 0, 0.08)", diff --git a/packages/features/timezone-buddy/components/AvailabilityEditSheet.tsx b/packages/features/timezone-buddy/components/AvailabilityEditSheet.tsx index b2d8bba01f..5e721bea51 100644 --- a/packages/features/timezone-buddy/components/AvailabilityEditSheet.tsx +++ b/packages/features/timezone-buddy/components/AvailabilityEditSheet.tsx @@ -15,7 +15,10 @@ import { Form, Label, Sheet, + SheetBody, + SheetClose, SheetContent, + SheetFooter, SheetHeader, SheetTitle, showToast, @@ -151,22 +154,7 @@ export function AvailabilityEditSheetForm(props: Props & { data: Data; isPending ...values, }); }}> - - - - - }> + {t("edit_users_availability", { @@ -185,7 +173,7 @@ export function AvailabilityEditSheetForm(props: Props & { data: Data; isPending )} -
+
-
+ + + + + + +
diff --git a/packages/features/users/components/UserTable/EditSheet/EditUserForm.tsx b/packages/features/users/components/UserTable/EditSheet/EditUserForm.tsx index c2bb0d0c28..44f7c2c6be 100644 --- a/packages/features/users/components/UserTable/EditSheet/EditUserForm.tsx +++ b/packages/features/users/components/UserTable/EditSheet/EditUserForm.tsx @@ -19,9 +19,13 @@ import { showToast, Avatar, ImageUploader, + SheetHeader, + SheetBody, + SheetFooter, } from "@calcom/ui"; import type { Action } from "../UserListTable"; +import { SheetFooterControls } from "./SheetFooterControls"; import { useEditMode } from "./store"; type MembershipOption = { @@ -117,73 +121,83 @@ export function EditForm({ const watchTimezone = form.watch("timeZone"); return ( -
{ - setMutationLoading(true); - mutation.mutate({ - userId: selectedUser?.id ?? "", - role: values.role, - username: values.username, - name: values.name, - email: values.email, - avatar: values.avatar, - bio: values.bio, - timeZone: values.timeZone, - }); - }}> -
- ( -
- -
- { - form.setValue("avatar", newAvatar, { shouldDirty: true }); - }} - imageSrc={value || undefined} - /> -
+ <> + { + setMutationLoading(true); + mutation.mutate({ + userId: selectedUser?.id ?? "", + role: values.role, + username: values.username, + name: values.name, + email: values.email, + avatar: values.avatar, + bio: values.bio, + timeZone: values.timeZone, + }); + }}> + +
+ ( +
+ +
+ { + form.setValue("avatar", newAvatar, { shouldDirty: true }); + }} + imageSrc={value || undefined} + /> +
+
+ )} + /> +
+ + {selectedUser?.name ?? "Nameless User"} + +

+ {domainUrl}/{selectedUser?.username} +

- )} - /> -
- {selectedUser?.name ?? "Nameless User"} -

- {domainUrl}/{selectedUser?.username} -

-
-
-
- - - +
+
+ + + + - -
- - { - form.setValue("role", value); - }} - /> -
-
- - -
-
- + +
+ + { + form.setValue("role", value); + }} + /> +
+
+ + +
+ + + + + + ); } diff --git a/packages/features/users/components/UserTable/EditSheet/EditUserSheet.tsx b/packages/features/users/components/UserTable/EditSheet/EditUserSheet.tsx index b2c0c3e386..34d64272b6 100644 --- a/packages/features/users/components/UserTable/EditSheet/EditUserSheet.tsx +++ b/packages/features/users/components/UserTable/EditSheet/EditUserSheet.tsx @@ -5,7 +5,19 @@ import { useOrgBranding } from "@calcom/ee/organizations/context/provider"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; -import { Avatar, Label, Loader, Sheet, SheetContent, SheetFooter, Skeleton } from "@calcom/ui"; +import { + Avatar, + Label, + Loader, + Sheet, + SheetContent, + SheetBody, + Skeleton, + SheetHeader, + SheetDescription, + SheetTitle, + SheetFooter, +} from "@calcom/ui"; import type { Action, State } from "../UserListTable"; import { DisplayInfo } from "./DisplayInfo"; @@ -35,32 +47,34 @@ export function EditUserSheet({ state, dispatch }: { state: State; dispatch: Dis setEditMode(false); dispatch({ type: "CLOSE_MODAL" }); }}> - + {!isPending && loadedUser ? ( -
+ <> {!editMode ? ( -
-
+ <> + -
+ {loadedUser?.name ?? "Nameless User"} + +

{orgBranding?.fullDomain ?? WEBAPP_URL}/{loadedUser?.username}

-
-
-
+ + + 0} /> -
-
+ + + + + ) : ( -
+ <> -
+ )} - - - -
+ ) : ( )} diff --git a/packages/ui/components/sheet/sheet.tsx b/packages/ui/components/sheet/sheet.tsx index ff6f0f953e..e5cdcfd11a 100644 --- a/packages/ui/components/sheet/sheet.tsx +++ b/packages/ui/components/sheet/sheet.tsx @@ -1,215 +1,173 @@ -import * as SheetPrimitive from "@radix-ui/react-dialog"; -import { cva, type VariantProps } from "class-variance-authority"; +import * as SheetPrimitives from "@radix-ui/react-dialog"; import * as React from "react"; import classNames from "@calcom/lib/classNames"; -import { Icon } from "@calcom/ui"; -const Sheet = SheetPrimitive.Root; +import { Button } from "../button"; -const SheetTrigger = SheetPrimitive.Trigger; +const Sheet = (props: React.ComponentPropsWithoutRef) => { + return ; +}; +Sheet.displayName = "Sheet"; -const SheetClose = SheetPrimitive.Close; - -const portalVariants = cva("fixed inset-0 z-50 flex", { - variants: { - position: { - top: "items-start", - bottom: "items-end", - left: "justify-start", - right: "justify-end", - }, - }, - defaultVariants: { position: "right" }, +const SheetTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ; }); +SheetTrigger.displayName = "Sheet.Trigger"; -interface SheetPortalProps extends SheetPrimitive.DialogPortalProps, VariantProps {} +const SheetClose = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ; +}); +SheetClose.displayName = "Sheet.Close"; -const SheetPortal = ({ position, className, children, ...props }: SheetPortalProps) => ( - -
{children}
-
-); -SheetPortal.displayName = SheetPrimitive.Portal.displayName; +const SheetPortal = SheetPrimitives.Portal; + +SheetPortal.displayName = "SheetPortal"; const SheetOverlay = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef - // eslint-disable-next-line @typescript-eslint/no-unused-vars ->(({ className, children, ...props }, ref) => ( - -)); -SheetOverlay.displayName = SheetPrimitive.Overlay.displayName; + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, forwardedRef) => { + return ( + + ); +}); -const sheetVariants = cva( - "fixed z-50 scale-100 gap-4 bg-default m-4 rounded-xl p-6 opacity-100 shadow-lg border border-default flex flex-col ", - { - variants: { - position: { - top: "animate-in slide-in-from-top w-full duration-200", - bottom: "animate-in slide-in-from-bottom w-full duration-200", - left: "animate-in slide-in-from-left h-full duration-200", - right: "animate-in slide-in-from-right h-full duration-200", - }, - size: { - content: "", - default: "", - sm: "", - lg: "", - xl: "", - full: "", - }, - }, - compoundVariants: [ - { - position: ["top", "bottom"], - size: "content", - class: "max-h-screen", - }, - { - position: ["top", "bottom"], - size: "default", - class: "h-1/3", - }, - { - position: ["top", "bottom"], - size: "sm", - class: "h-1/4", - }, - { - position: ["top", "bottom"], - size: "lg", - class: "h-1/2", - }, - { - position: ["top", "bottom"], - size: "xl", - class: "h-5/6", - }, - { - position: ["top", "bottom"], - size: "full", - class: "h-screen", - }, - { - position: ["right", "left"], - size: "content", - class: "max-w-screen", - }, - { - position: ["right", "left"], - size: "default", - class: "w-[calc(100%-2rem)] lg:w-1/3 max-h-[calc(100vh-2rem)]", - }, - { - position: ["right", "left"], - size: "sm", - class: "w-1/4 max-h-[calc(100vh-2rem)]", - }, - { - position: ["right", "left"], - size: "lg", - class: "w-1/2 h-[calc(100vh-2rem)]", - }, - { - position: ["right", "left"], - size: "xl", - class: "w-5/6 h-[calc(100vh-2rem)]", - }, - { - position: ["right", "left"], - size: "full", - class: "w-screen h-[calc(100vh-2rem)]", - }, - ], - defaultVariants: { - position: "right", - size: "default", - }, +SheetOverlay.displayName = "SheetOverlay"; + +const SheetContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, forwardedRef) => { + return ( + + + + + + ); +}); + +SheetContent.displayName = "SheetContent"; + +const SheetHeader = React.forwardRef>( + ({ children, className, ...props }, ref) => { + return ( +
+
{children}
+ +
+ ); } ); -export interface DialogContentProps - extends React.ComponentPropsWithoutRef, - VariantProps { - bottomActions?: React.ReactNode; -} - -const SheetContent = React.forwardRef, DialogContentProps>( - ({ position, size, className, children, bottomActions, ...props }, ref) => ( - - - -
{children}
- {bottomActions && ( -
-
{bottomActions}
-
- )} - - - Close - -
-
- ) -); -SheetContent.displayName = SheetPrimitive.Content.displayName; - -const SheetHeader = ({ className, ...props }: React.HTMLAttributes) => ( -
-); -SheetHeader.displayName = "SheetHeader"; - -const SheetFooter = ({ className, ...props }: React.HTMLAttributes) => ( -
-); -SheetFooter.displayName = "SheetFooter"; +SheetHeader.displayName = "Sheet.Header"; const SheetTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - , + React.ComponentPropsWithoutRef +>(({ className, ...props }, forwardedRef) => ( + )); -SheetTitle.displayName = SheetPrimitive.Title.displayName; + +SheetTitle.displayName = "SheetTitle"; + +const SheetBody = React.forwardRef>( + ({ className, ...props }, ref) => { + return
; + } +); + +SheetBody.displayName = "Sheet.Body"; const SheetDescription = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -SheetDescription.displayName = SheetPrimitive.Description.displayName; + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, forwardedRef) => { + return ( + + ); +}); + +SheetDescription.displayName = "SheetDescription"; + +const SheetFooter = ({ className, ...props }: React.HTMLAttributes) => { + return ( +
+ ); +}; + +SheetFooter.displayName = "SheetFooter"; export { Sheet, - SheetTrigger, + SheetBody, SheetClose, SheetContent, - SheetHeader, - SheetFooter, - SheetTitle, SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, + SheetTrigger, }; diff --git a/packages/ui/index.tsx b/packages/ui/index.tsx index a63f5d1065..a39b2f7417 100644 --- a/packages/ui/index.tsx +++ b/packages/ui/index.tsx @@ -172,6 +172,7 @@ export { WizardLayoutAppDir } from "./layouts/WizardLayoutAppDir"; export { DataTable } from "./components/data-table"; export { Sheet, + SheetBody, SheetClose, SheetContent, SheetDescription,