From 9fa7d43bb723a853004298effdc770d7242a6780 Mon Sep 17 00:00:00 2001 From: nils stolpe Date: Fri, 5 Jan 2024 11:49:00 -0500 Subject: [PATCH] fix/modal (#273) * fix: made modal footer button lg * fix: updated form modal styles to match design, used asChild prop to get rid of nested buttons * refactor: moved Modal.example to ModalForm.example * refactor: updated styling for modals and added info and custom modal examples * fix: right aligned buttons on custom modal to show layout options --- src/components/Modal/index.tsx | 80 ++++++++++++++----- stories/Modal/Docs.mdx | 13 ++- stories/Modal/Modal.example.tsx | 54 ------------- .../{Modal.stories.ts => Modal.stories.tsx} | 23 ++++-- stories/Modal/ModalCustom.example.tsx | 39 +++++++++ stories/Modal/ModalForm.example.tsx | 46 +++++++++++ stories/Modal/ModalInfo.example.tsx | 37 +++++++++ 7 files changed, 209 insertions(+), 83 deletions(-) delete mode 100644 stories/Modal/Modal.example.tsx rename stories/Modal/{Modal.stories.ts => Modal.stories.tsx} (65%) create mode 100644 stories/Modal/ModalCustom.example.tsx create mode 100644 stories/Modal/ModalForm.example.tsx create mode 100644 stories/Modal/ModalInfo.example.tsx diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index d92b0d69..611a124a 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -2,8 +2,9 @@ import * as React from 'react' import * as DialogPrimitive from '@radix-ui/react-dialog' -import { CloseIcon } from '@/assets' +import { cva, type VariantProps } from 'class-variance-authority' +import { CloseIcon } from '@/assets' import { cn } from '@/lib/utils' const Modal = DialogPrimitive.Root @@ -35,7 +36,7 @@ const ModalContent = React.forwardRef< ) => ( -
+}: React.HTMLAttributes & + VariantProps) => ( +
) + ModalHeader.displayName = 'ModalHeader' const ModalFooter = ({ className, ...props }: React.HTMLAttributes) => ( -
+
) ModalFooter.displayName = 'ModalFooter' @@ -108,17 +125,38 @@ const ModalClose = React.forwardRef< )) +const descriptionVariants = cva( + [ + 'text-sm', + 'text-foreground-muted', + 'border-border-subtle', + 'dark:border-border-subtle-dark' + ], + { + variants: { + variant: { + default: ['border-b'], + form: ['border-b-0'] + } + }, + defaultVariants: { + variant: 'default' + } + } +) + const ModalDescription = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( + React.ComponentPropsWithoutRef & + VariantProps +>(({ className, variant, ...props }, ref) => ( )) -ModalDescription.displayName = DialogPrimitive.Description.displayName +ModalDescription.displayName = 'ModalDescription' export { Modal, diff --git a/stories/Modal/Docs.mdx b/stories/Modal/Docs.mdx index 7ef06286..cc9be9a2 100644 --- a/stories/Modal/Docs.mdx +++ b/stories/Modal/Docs.mdx @@ -1,6 +1,7 @@ import { Canvas, Meta } from '@storybook/blocks' import * as ModalStories from './Modal.stories' +import { ModalInfoDemo } from './ModalInfo.example' @@ -8,9 +9,17 @@ import * as ModalStories from './Modal.stories' A modal is a window that can be overlaid on the main window, which when opened, the main window is left partially visible and doesn't allow any user interaction. -## Default +## Info - + + +## Custom + + + +## Form + + ## Attributes diff --git a/stories/Modal/Modal.example.tsx b/stories/Modal/Modal.example.tsx deleted file mode 100644 index 62d2db9a..00000000 --- a/stories/Modal/Modal.example.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { - Modal, - ModalContent, - ModalClose, - ModalCloseFooter, - ModalFooter, - ModalDescription, - ModalHeader, - ModalTitle, - ModalTrigger -} from '@/components/Modal' -import { Button } from '@/components' - -export const ModalDemo = () => { - return ( - - - - - - - Title - - - -
- Replace this component with your content -
-
- - - -
-
- Additional text line -
-
- Additional text line -
-
-
-
-
-
- ) -} diff --git a/stories/Modal/Modal.stories.ts b/stories/Modal/Modal.stories.tsx similarity index 65% rename from stories/Modal/Modal.stories.ts rename to stories/Modal/Modal.stories.tsx index 9edcf9e3..18e97afe 100644 --- a/stories/Modal/Modal.stories.ts +++ b/stories/Modal/Modal.stories.tsx @@ -1,11 +1,13 @@ import type { Meta, StoryObj } from '@storybook/react' -import { ModalDemo } from './Modal.example' +import { ModalInfoDemo } from './ModalInfo.example' +import { ModalCustomDemo } from './ModalCustom.example' +import { ModalFormDemo } from './ModalForm.example' // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export const meta = { title: 'Components/Modal', - component: ModalDemo, + component: ModalFormDemo, parameters: { // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout layout: 'centered' @@ -13,17 +15,26 @@ const meta = { // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs argTypes: { className: { - controle: 'text', + control: 'text', description: 'Alter the className to change the style' } } // More on argTypes: https://storybook.js.org/docs/react/api/argtypes -} satisfies Meta +} satisfies Meta export default meta type Story = StoryObj // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args -export const Default: Story = { - args: {} + +export const Info: Story = { + render: () => +} + +export const Custom: Story = { + render: () => +} + +export const Form: Story = { + render: () => } diff --git a/stories/Modal/ModalCustom.example.tsx b/stories/Modal/ModalCustom.example.tsx new file mode 100644 index 00000000..bb56a5d5 --- /dev/null +++ b/stories/Modal/ModalCustom.example.tsx @@ -0,0 +1,39 @@ +import { + Modal, + ModalContent, + ModalClose, + ModalFooter, + ModalDescription, + ModalHeader, + ModalTitle, + ModalTrigger +} from '@/components/Modal' +import { Button } from '@/components' + +export const ModalCustomDemo = () => ( + + + + + Title + + + +
+
+ Replace this component with your content +
+
+
+ +
+ + + +
+
+
+
+) diff --git a/stories/Modal/ModalForm.example.tsx b/stories/Modal/ModalForm.example.tsx new file mode 100644 index 00000000..398a7cda --- /dev/null +++ b/stories/Modal/ModalForm.example.tsx @@ -0,0 +1,46 @@ +import { + Modal, + ModalContent, + ModalClose, + ModalCloseFooter, + ModalFooter, + ModalDescription, + ModalHeader, + ModalTitle, + ModalTrigger +} from '@/components/Modal' +import { Button } from '@/components' + +export const ModalFormDemo = () => ( + + + + + Title + + + +
+
+ Replace this component with your form +
+
+
+ + +
+
Additional text line
+
+ Additional text line +
+
+
+
+
+) diff --git a/stories/Modal/ModalInfo.example.tsx b/stories/Modal/ModalInfo.example.tsx new file mode 100644 index 00000000..d9a25d13 --- /dev/null +++ b/stories/Modal/ModalInfo.example.tsx @@ -0,0 +1,37 @@ +import { + Modal, + ModalContent, + ModalClose, + ModalFooter, + ModalDescription, + ModalHeader, + ModalTitle, + ModalTrigger +} from '@/components/Modal' +import { Button } from '@/components' + +export const ModalInfoDemo = () => ( + + + + + Title + + + +
+

Test

+
+
+ +
+ + + +
+
+
+
+)