-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added card and modal component
- Loading branch information
Showing
7 changed files
with
402 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
built | ||
healthcheck.js | ||
tailwind.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Button } from '../Button'; | ||
import { Modal, ModalContent, ModalContentProps, ModalTrigger } from './Modal'; | ||
|
||
const meta: Meta<typeof Modal> = { | ||
title: 'Components/Modal', | ||
component: Modal, | ||
tags: ['v2'], | ||
argTypes: {} | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof ModalContent>; | ||
|
||
const Template = (args: ModalContentProps) => ( | ||
<Modal> | ||
<ModalTrigger asChild> | ||
<Button>Open</Button> | ||
</ModalTrigger> | ||
<ModalContent {...args}>Hello world</ModalContent> | ||
</Modal> | ||
); | ||
|
||
export const Basic: Story = { | ||
render: (args) => <Template {...args} />, | ||
args: { | ||
title: 'Title', | ||
subTitle: 'Something as subtitle', | ||
footerContent: 'footer content' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { forwardRef, ReactNode } from 'react'; | ||
import { faTimes } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import * as DialogPrimitive from '@radix-ui/react-dialog'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import { Card, CardBody, CardFooter, CardTitle } from '../Card'; | ||
import { IconButton } from '../IconButton'; | ||
|
||
export type ModalContentProps = Omit<DialogPrimitive.DialogContentProps, 'open'> & { | ||
title?: ReactNode; | ||
subTitle?: string; | ||
footerContent?: ReactNode; | ||
}; | ||
|
||
export const ModalContent = forwardRef<HTMLDivElement, ModalContentProps>( | ||
({ children, title, subTitle, className, footerContent, ...props }, forwardedRef) => ( | ||
<DialogPrimitive.Portal> | ||
<DialogPrimitive.Overlay | ||
className="fixed inset-0 w-full h-full animate-fadeIn" | ||
style={{ backgroundColor: 'rgba(0, 0, 0, 0.5)' }} | ||
/> | ||
<DialogPrimitive.Content {...props} ref={forwardedRef}> | ||
<Card | ||
isRounded | ||
className={twMerge( | ||
'fixed max-w-md animate-popIn top-1/2 left-1/2 -translate-y-2/4 -translate-x-2/4', | ||
className | ||
)} | ||
> | ||
{title && <CardTitle subTitle={subTitle}>{title}</CardTitle>} | ||
<CardBody>{children}</CardBody> | ||
{footerContent && <CardFooter>{footerContent}</CardFooter>} | ||
<DialogPrimitive.Close aria-label="Close" asChild> | ||
<IconButton | ||
variant="plain" | ||
ariaLabel="close" | ||
className="absolute top-2.5 right-2.5 text-white hover:bg-gray-600 rounded" | ||
> | ||
<FontAwesomeIcon icon={faTimes} size="sm" className="cursor-pointer" /> | ||
</IconButton> | ||
</DialogPrimitive.Close> | ||
</Card> | ||
</DialogPrimitive.Content> | ||
</DialogPrimitive.Portal> | ||
) | ||
); | ||
|
||
ModalContent.displayName = 'ModalContent'; | ||
|
||
export const Modal = DialogPrimitive.Root; | ||
export type ModalProps = DialogPrimitive.DialogProps; | ||
|
||
export const ModalTrigger = DialogPrimitive.Trigger; | ||
export type ModalTriggerProps = DialogPrimitive.DialogTriggerProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { ModalContentProps, ModalProps, ModalTriggerProps } from './Modal'; | ||
export { Modal, ModalContent, ModalTrigger } from './Modal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.