import React, { Fragment } from 'react'; import { Dialog as HeadlessDialog, Transition } from '@headlessui/react'; import { Button } from '@/components/elements/button/index'; import styles from './style.module.css'; import { XIcon } from '@heroicons/react/solid'; import { CheckIcon, ExclamationIcon, InformationCircleIcon, ShieldExclamationIcon } from '@heroicons/react/outline'; import classNames from 'classnames'; interface Props { visible: boolean; onDismissed: () => void; title?: string; children?: React.ReactNode; } interface DialogIconProps { type: 'danger' | 'info' | 'success' | 'warning'; className?: string; } const DialogIcon = ({ type, className }: DialogIconProps) => { const [ Component, styles ] = (function (): [(props: React.ComponentProps<'svg'>) => JSX.Element, string] { switch (type) { case 'danger': return [ ShieldExclamationIcon, 'bg-red-500 text-red-50' ]; case 'warning': return [ ExclamationIcon, 'bg-yellow-600 text-yellow-50' ]; case 'success': return [ CheckIcon, 'bg-green-600 text-green-50' ]; case 'info': return [ InformationCircleIcon, 'bg-primary-500 text-primary-50' ]; } })(); return (
); }; const DialogButtons = ({ children }: { children: React.ReactNode }) => ( <>{children} ); const Dialog = ({ visible, title, onDismissed, children }: Props) => { const items = React.Children.toArray(children || []); const [ buttons, icon, content ] = [ // @ts-expect-error items.find(child => child.type === DialogButtons), // @ts-expect-error items.find(child => child.type === DialogIcon), // @ts-expect-error items.filter(child => ![ DialogIcon, DialogButtons ].includes(child.type)), ]; return ( onDismissed()} className={styles.wrapper}>
{icon &&
{icon}
}
{title && {title} } {content}
{buttons &&
{buttons}
} {/* Keep this below the other buttons so that it isn't the default focus if they're present. */}
onDismissed()} className={'hover:rotate-90'}>
); }; const _Dialog = Object.assign(Dialog, { Buttons: DialogButtons, Icon: DialogIcon }); export default _Dialog;