ConceptPortal-public/rsconcept/frontend/src/components/Modal/ModalView.tsx

84 lines
2.2 KiB
TypeScript
Raw Normal View History

'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-02-19 23:30:35 +03:00
import { useEscapeKey } from '@/hooks/useEscapeKey';
import { useDialogsStore } from '@/stores/dialogs';
2025-02-11 20:56:24 +03:00
import { prepareTooltip } from '@/utils/utils';
2025-02-07 10:54:47 +03:00
import { Button, MiniButton } from '../Control';
import { IconClose } from '../Icons';
2025-02-12 21:36:25 +03:00
import { ModalBackdrop } from './ModalBackdrop';
import { type 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 (
2025-03-10 16:02:53 +03:00
<div className='cc-modal-wrapper'>
<ModalBackdrop onHide={hideDialog} />
2025-03-10 16:02:53 +03:00
<div className='cc-animate-modal grid border rounded-xl bg-prim-100' role='dialog'>
{helpTopic && !hideHelpWhen?.() ? (
2025-03-09 21:59:21 +03:00
<BadgeHelp
topic={helpTopic}
className='absolute z-pop left-0 mt-2 ml-2'
padding='p-0'
contentClass='sm:max-w-160'
/>
) : 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-09 21:59:21 +03:00
className='absolute z-pop right-0 mt-2 mr-2'
2025-03-07 20:38:40 +03:00
onClick={hideDialog}
/>
{header ? <h1 className='px-12 py-2 select-none'>{header}</h1> : null}
<div
className={clsx(
'@container/modal',
'max-h-[calc(100svh-8rem)] max-w-[100svw] xs:max-w-[calc(100svw-2rem)]',
'overscroll-contain outline-hidden',
{
'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}
/>
</div>
</div>
);
}