2025-02-06 20:27:56 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-12 13:41:58 +03:00
|
|
|
import { BadgeHelp } from '@/features/help';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
2025-02-19 23:29:45 +03:00
|
|
|
import { useEscapeKey } from '@/hooks/useEscapeKey';
|
2025-02-06 20:27:56 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
|
|
|
import { PARAMETER } from '@/utils/constants';
|
2025-02-11 20:56:11 +03:00
|
|
|
import { prepareTooltip } from '@/utils/utils';
|
2025-02-06 20:27:56 +03:00
|
|
|
|
2025-02-07 10:53:49 +03:00
|
|
|
import { Button, MiniButton } from '../Control';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { IconClose } from '../Icons';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
2025-02-06 20:27:56 +03:00
|
|
|
import { ModalBackdrop } from './ModalBackdrop';
|
|
|
|
import { ModalProps } from './ModalForm';
|
|
|
|
|
|
|
|
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 (
|
|
|
|
<div className='fixed top-0 left-0 w-full h-full z-modal cursor-default'>
|
|
|
|
<ModalBackdrop onHide={hideDialog} />
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'cc-animate-modal',
|
|
|
|
'z-modal absolute bottom-1/2 left-1/2 -translate-x-1/2 translate-y-1/2',
|
|
|
|
'border rounded-xl bg-prim-100'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{helpTopic && !hideHelpWhen?.() ? (
|
|
|
|
<div className='float-left mt-2 ml-2'>
|
|
|
|
<BadgeHelp topic={helpTopic} className={clsx(PARAMETER.TOOLTIP_WIDTH, 'sm:max-w-[40rem]')} padding='p-0' />
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
<MiniButton
|
|
|
|
noPadding
|
|
|
|
titleHtml={prepareTooltip('Закрыть диалоговое окно', 'ESC')}
|
|
|
|
icon={<IconClose size='1.25rem' />}
|
|
|
|
className='float-right mt-2 mr-2'
|
|
|
|
onClick={hideDialog}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{header ? <h1 className='px-12 py-2 select-none'>{header}</h1> : null}
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'overscroll-contain max-h-[calc(100svh-8rem)] max-w-[100svw] xs:max-w-[calc(100svw-2rem)] outline-none',
|
|
|
|
{
|
|
|
|
'overflow-auto': !overflowVisible,
|
|
|
|
'overflow-visible': overflowVisible
|
|
|
|
},
|
|
|
|
className
|
|
|
|
)}
|
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='z-modalControls my-2 flex gap-12 justify-center text-sm'>
|
|
|
|
<Button text='Закрыть' className='min-w-[7rem]' onClick={hideDialog} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|