Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Drawer custom animation props #262

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/layers/Drawer/Drawer.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment } from 'react';
import React, { Fragment, useState } from 'react';
import { useDrawer } from './useDrawer';
import { Drawer } from './Drawer';
import { Button } from '../../elements';
Expand Down Expand Up @@ -78,3 +78,26 @@ export const CustomHeader = () => {
</Fragment>
);
};

export const CustomAnimation = () => {
const [isOpen, setIsOpen] = useState(false);

return (
<Fragment>
<Drawer
className="max-w-[400px] mr-10 max-h-[90vh] my-auto rounded-xl"
initial={{ x: '120%', opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
exit={{ x: '120%', opacity: 0 }}
transition={{ duration: 0.5, ease: [0.12, 0.78, 0.32, 0.98] }}
open={isOpen}
onClose={() => setIsOpen(false)}
>
<p>Hello There!</p>
</Drawer>
<Button type="button" onClick={() => setIsOpen(!isOpen)}>
Open
</Button>
</Fragment>
);
};
10 changes: 7 additions & 3 deletions src/layers/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import React, { FC, ReactElement } from 'react';
import FocusTrap from 'focus-trap-react';
import { useId, CloneElement } from '@/utils';
import { GlobalOverlay, GlobalOverlayProps } from '@/utils/Overlay';
import { motion } from 'framer-motion';
import { motion, MotionProps } from 'framer-motion';
import { variants } from './variants';
import { DrawerHeader, DrawerHeaderProps } from './DrawerHeader';
import { twMerge } from 'tailwind-merge';
import { DrawerTheme } from './DrawerTheme';
import { useComponentTheme } from '@/utils';

export interface DrawerProps extends Omit<GlobalOverlayProps, 'children'> {
export interface DrawerProps
extends Omit<GlobalOverlayProps, 'children'>,
MotionProps {
/**
* Position of the drawer.
*/
Expand Down Expand Up @@ -82,7 +84,8 @@ export const Drawer: FC<Partial<DrawerProps>> = ({
disablePadding = false,
showCloseButton = true,
onClose,
theme: customTheme
theme: customTheme,
...rest
}) => {
const id = useId();
const variant = variants[position];
Expand Down Expand Up @@ -129,6 +132,7 @@ export const Drawer: FC<Partial<DrawerProps>> = ({
disablePadding && theme.disablePadding,
className
)}
{...rest}
>
{(header || headerElement) && (
<CloneElement<DrawerHeaderProps>
Expand Down
Loading