2025-02-06 20:28:23 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-26 00:16:41 +03:00
|
|
|
import { BadgeHelp } from '@/features/help/components';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-03-12 11:55:43 +03:00
|
|
|
import { useEscapeKey } from '@/hooks/use-escape-key';
|
2025-02-06 20:28:23 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2025-02-11 20:56:24 +03:00
|
|
|
import { prepareTooltip } from '@/utils/utils';
|
2025-02-06 20:28:23 +03:00
|
|
|
|
2025-03-12 12:04:50 +03:00
|
|
|
import { Button, MiniButton } from '../control';
|
|
|
|
import { IconClose } from '../icons';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-03-12 11:55:43 +03:00
|
|
|
import { ModalBackdrop } from './modal-backdrop';
|
|
|
|
import { type ModalProps } from './modal-form';
|
2025-02-06 20:28:23 +03:00
|
|
|
|
|
|
|
interface ModalViewProps extends ModalProps {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a customizable modal window with submit form.
|
|
|
|
*/
|
|
|
|
export function ModalView({
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
header,
|
|
|
|
overflowVisible,
|
|
|
|
helpTopic,
|
|
|
|
hideHelpWhen,
|
|
|
|
...restProps
|
|
|
|
}: React.PropsWithChildren<ModalViewProps>) {
|
|
|
|
const hideDialog = useDialogsStore(state => state.hideDialog);
|
|
|
|
useEscapeKey(hideDialog);
|
|
|
|
|
|
|
|
return (
|
2025-03-10 16:02:53 +03:00
|
|
|
<div className='cc-modal-wrapper'>
|
2025-02-06 20:28:23 +03:00
|
|
|
<ModalBackdrop onHide={hideDialog} />
|
2025-03-11 12:56:58 +03:00
|
|
|
<div className='cc-animate-modal relative grid border rounded-xl bg-prim-100' role='dialog'>
|
2025-02-06 20:28:23 +03:00
|
|
|
{helpTopic && !hideHelpWhen?.() ? (
|
2025-03-09 21:59:21 +03:00
|
|
|
<BadgeHelp
|
|
|
|
topic={helpTopic}
|
2025-03-11 12:56:58 +03:00
|
|
|
className='absolute z-pop top-2 left-2'
|
2025-03-09 21:59:21 +03:00
|
|
|
padding='p-0'
|
|
|
|
contentClass='sm:max-w-160'
|
|
|
|
/>
|
2025-02-06 20:28:23 +03:00
|
|
|
) : null}
|
|
|
|
|
2025-03-07 20:38:40 +03:00
|
|
|
<MiniButton
|
|
|
|
noPadding
|
2025-03-09 21:59:21 +03:00
|
|
|
aria-label='Закрыть'
|
2025-03-07 20:38:40 +03:00
|
|
|
titleHtml={prepareTooltip('Закрыть диалоговое окно', 'ESC')}
|
|
|
|
icon={<IconClose size='1.25rem' />}
|
2025-03-11 12:56:58 +03:00
|
|
|
className='absolute z-pop top-2 right-2'
|
2025-03-07 20:38:40 +03:00
|
|
|
onClick={hideDialog}
|
|
|
|
/>
|
2025-02-06 20:28:23 +03:00
|
|
|
|
|
|
|
{header ? <h1 className='px-12 py-2 select-none'>{header}</h1> : null}
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={clsx(
|
2025-03-04 12:24:16 +03:00
|
|
|
'@container/modal',
|
|
|
|
'max-h-[calc(100svh-8rem)] max-w-[100svw] xs:max-w-[calc(100svw-2rem)]',
|
|
|
|
'overscroll-contain outline-hidden',
|
2025-02-06 20:28:23 +03:00
|
|
|
{
|
|
|
|
'overflow-auto': !overflowVisible,
|
|
|
|
'overflow-visible': overflowVisible
|
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
|
2025-03-09 21:59:21 +03:00
|
|
|
<Button
|
|
|
|
text='Закрыть'
|
|
|
|
aria-label='Закрыть'
|
|
|
|
className='z-pop my-2 mx-auto text-sm min-w-28'
|
|
|
|
onClick={hideDialog}
|
|
|
|
/>
|
2025-02-06 20:28:23 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|