From bacc60d4fa6aaa52f57f5e29e0612d54d65f8dd3 Mon Sep 17 00:00:00 2001 From: Anastasios Date: Fri, 15 Nov 2024 13:25:40 +0400 Subject: [PATCH] feat: add sheet animation --- .../components/sheet/sheet.web.stories.tsx | 43 +++--- .../ui/src/components/sheet/sheet.web.tsx | 135 +++++++++++------- 2 files changed, 107 insertions(+), 71 deletions(-) diff --git a/packages/ui/src/components/sheet/sheet.web.stories.tsx b/packages/ui/src/components/sheet/sheet.web.stories.tsx index acc7f74cb..ec9f27caa 100644 --- a/packages/ui/src/components/sheet/sheet.web.stories.tsx +++ b/packages/ui/src/components/sheet/sheet.web.stories.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useRef } from 'react'; import type { Meta } from '@storybook/react'; import { Box, Flex } from 'leather-styles/jsx'; @@ -23,14 +23,17 @@ const meta: Meta = { export default meta; export function Sheet() { - const [isShowing, setIsShowing] = useState(false); + const triggerRef = useRef(null); + const closeRef = useRef(null); + return ( <> - + } - isShowing={isShowing} - onClose={() => setIsShowing(false)} + onClose={() => closeRef.current?.click()} + header={ closeRef.current?.click()} />} + triggerRef={triggerRef} + closeRef={closeRef} > Let's start talk sheet. @@ -41,16 +44,19 @@ export function Sheet() { } export function SheetWithFooter() { - const [isShowing, setIsShowing] = useState(false); + const triggerRef = useRef(null); + const closeRef = useRef(null); + return ( <> - + } - isShowing={isShowing} - onClose={() => setIsShowing(false)} + onClose={() => closeRef.current?.click()} + triggerRef={triggerRef} + closeRef={closeRef} footer={ - } @@ -64,20 +70,23 @@ export function SheetWithFooter() { } export function SheetWithButtonsFooter() { - const [isShowing, setIsShowing] = useState(false); + const triggerRef = useRef(null); + const closeRef = useRef(null); + return ( <> - + } - isShowing={isShowing} - onClose={() => setIsShowing(false)} + onClose={() => closeRef.current?.click()} + triggerRef={triggerRef} + closeRef={closeRef} footer={ - - diff --git a/packages/ui/src/components/sheet/sheet.web.tsx b/packages/ui/src/components/sheet/sheet.web.tsx index 95631d54d..01506e9de 100644 --- a/packages/ui/src/components/sheet/sheet.web.tsx +++ b/packages/ui/src/components/sheet/sheet.web.tsx @@ -1,4 +1,4 @@ -import { JSXElementConstructor, ReactElement, ReactNode, cloneElement } from 'react'; +import { JSXElementConstructor, ReactElement, ReactNode, RefObject, cloneElement } from 'react'; import * as RadixDialog from '@radix-ui/react-dialog'; import { css } from 'leather-styles/css'; @@ -10,8 +10,10 @@ import { pxStringToNumber } from '@leather.io/utils'; import { SheetFooter } from './components/sheet-footer.web'; export interface SheetProps { - isShowing: boolean; onClose?(): void; + triggerRef?: RefObject; + closeRef?: RefObject; + isDefaultOpen?: boolean; } interface RadixDialogProps extends SheetProps { children: ReactNode; @@ -38,65 +40,90 @@ export function Sheet({ footer, header, onClose, - isShowing, wrapChildren = true, + triggerRef, + closeRef, + isDefaultOpen = false, }: RadixDialogProps) { const maxHeightOffset = getHeightOffset(header, footer); const contentMaxHeight = getContentMaxHeight(maxHeightOffset); return ( - - - - - {header && cloneElement(header, { onClose })} + + + + + + {header && cloneElement(header, { onClose })} - {wrapChildren ? ( - - {children} - - ) : ( - children - )} - {footer && {footer}} - - - + {wrapChildren ? ( + + {children} + + ) : ( + children + )} + {footer && {footer}} + ); }