Skip to content

Commit

Permalink
Merge pull request #84 from ynput/develop
Browse files Browse the repository at this point in the history
release 1.0.3
  • Loading branch information
Innders authored May 2, 2024
2 parents 9fe706e + 24e01c2 commit 7da740c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/Overlay/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Dialog } from '.'
import { useRef, useState } from 'react'
import { useState } from 'react'
import { Button } from '../../Button'

const meta: Meta<typeof Dialog> = {
Expand Down Expand Up @@ -32,11 +32,6 @@ const closeProps = {
const Template = () => {

const [openModal, setOpenModal] = useState(false)

const handleCloseModal = () => {
setOpenModal(false)
}


return (
<>
Expand All @@ -48,10 +43,11 @@ const Template = () => {
children={<BodyContent />}
footer={<FooterContent />}
isOpen={openModal}
onClose={handleCloseModal}
onClose={() => setOpenModal(false)}
closeProps={closeProps}
hideCancelButton={false}
size='full'
variant='dialog'
/>
</>
)
Expand Down
13 changes: 7 additions & 6 deletions src/Overlay/Dialog/Dialog.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ export const Dialog = styled.dialog<{ $size?: string }>`
/* Backdrop property affects inactive area around modal */
&::backdrop {
background-color: rgba(0, 0, 0, 0.3);
background-color: rgba(0, 0, 0, 0.3);
}
/* Styles for dialogs that carry modal behavior */
&:modal {
display: flex;
}
&:modal[open] {
/* Styles for dialogs that carry non-modal behavior */
&:not(:modal) {
}
&[open] {
display: flex;
animation: ${fadeInAnimation} 150ms ease-in-out forwards, ${fadeInAnimation} 150ms ease-in-out backwards;
animation-fill-mode: both;
}
/* Styles for dialogs that carry non-modal behavior */
&:not(:modal) {
}
`

export const Close = styled(Button)`
Expand Down
6 changes: 5 additions & 1 deletion src/Overlay/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface DialogProps extends Omit<React.HTMLAttributes<HTMLDialogElement
isOpen: boolean
onClose?: () => void
classNames?: ClassNames
variant?: 'dialog' | 'modal'
size?: 'sm' | 'md' | 'lg' | 'full'
}

Expand All @@ -35,6 +36,7 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>((props) => {
className,
classNames,
size,
variant = 'modal'
} = props

const [isModalOpen, setModalOpen] = useState(isOpen)
Expand All @@ -49,7 +51,9 @@ export const Dialog = forwardRef<HTMLDialogElement, DialogProps>((props) => {
useEffect(() => {
const modalElement = modalRef.current
if (!modalElement) return
isModalOpen ? modalElement.showModal() : modalElement.close()
const showDialog = variant === 'dialog' && modalElement.show()
const showModal = variant === 'modal' && modalElement.showModal()
isModalOpen ? (showDialog || showModal) : modalElement.close()
}, [isModalOpen])

const handleCloseModal = () => {
Expand Down

0 comments on commit 7da740c

Please sign in to comment.