revamp template
This commit is contained in:
34
src/components/modal/Modal.tsx
Normal file
34
src/components/modal/Modal.tsx
Normal file
@ -0,0 +1,34 @@
|
||||
import { forwardRef } from 'react';
|
||||
import { Modal as MuiModal, ModalProps as BaseModalProps } from '@mui/base/Modal';
|
||||
import { ModalBackdrop } from '@/components';
|
||||
import clsx from 'clsx';
|
||||
|
||||
interface IModalProps extends BaseModalProps {
|
||||
zIndex?: number;
|
||||
className?: string; // For content-specific Tailwind stylesx
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const Modal = forwardRef<HTMLDivElement, IModalProps>(
|
||||
({ open, onClose, children, className, zIndex = 100, ...props }, ref) => {
|
||||
return (
|
||||
<MuiModal
|
||||
ref={ref}
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
style={{
|
||||
zIndex: `${zIndex}`,
|
||||
opacity: open ? 1 : 0,
|
||||
display: open ? 'block' : 'none'
|
||||
}}
|
||||
className={clsx('modal', className)}
|
||||
{...props} // Spread any additional props
|
||||
slots={{ backdrop: ModalBackdrop }} // Assign custom backdrop
|
||||
>
|
||||
{children}
|
||||
</MuiModal>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export { Modal };
|
||||
27
src/components/modal/ModalBackdrop.tsx
Normal file
27
src/components/modal/ModalBackdrop.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import clsx from 'clsx';
|
||||
import { forwardRef } from 'react';
|
||||
|
||||
interface IModalBackdropProps {
|
||||
className?: string;
|
||||
open: boolean;
|
||||
ownerState: any;
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const ModalBackdrop = forwardRef<HTMLDivElement, IModalBackdropProps>(
|
||||
({ className, ownerState, ...props }, ref) => {
|
||||
const { ...other } = props;
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={clsx('modal-backdrop transition-all duration-300 -z-1', className && className)}
|
||||
aria-hidden="true"
|
||||
{...other}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export { ModalBackdrop, type IModalBackdropProps };
|
||||
21
src/components/modal/ModalBody.tsx
Normal file
21
src/components/modal/ModalBody.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { forwardRef, ReactNode, CSSProperties } from 'react';
|
||||
|
||||
interface IModalBodyProps {
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
tabIndex?: number;
|
||||
style?: CSSProperties; // Accept inline styles as a prop
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const ModalBody = forwardRef<HTMLDivElement, IModalBodyProps>(
|
||||
({ className, children, style, tabIndex = -1 }, ref) => {
|
||||
return (
|
||||
<div ref={ref} tabIndex={tabIndex} className={`modal-body ${className}`} style={style}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export { ModalBody };
|
||||
20
src/components/modal/ModalContent.tsx
Normal file
20
src/components/modal/ModalContent.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { forwardRef, ReactNode } from 'react';
|
||||
|
||||
interface IModalContentProps {
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
tabIndex?: number;
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const ModalContent = forwardRef<HTMLDivElement, IModalContentProps>(
|
||||
({ className, children, tabIndex = -1 }, ref) => {
|
||||
return (
|
||||
<div ref={ref} tabIndex={tabIndex} className={`modal-content ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export { ModalContent };
|
||||
19
src/components/modal/ModalHeader.tsx
Normal file
19
src/components/modal/ModalHeader.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import { forwardRef, ReactNode } from 'react';
|
||||
|
||||
interface IModalHeaderProps {
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const ModalHeader = forwardRef<HTMLDivElement, IModalHeaderProps>(
|
||||
({ className, children }, ref) => {
|
||||
return (
|
||||
<div ref={ref} className={`modal-header ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export { ModalHeader };
|
||||
17
src/components/modal/ModalTitle.tsx
Normal file
17
src/components/modal/ModalTitle.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import { forwardRef, ReactNode } from 'react';
|
||||
|
||||
interface IModalTitleProps {
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
// Forwarding ref to ensure this component can hold a ref
|
||||
const ModalTitle = forwardRef<HTMLDivElement, IModalTitleProps>(({ className, children }, ref) => {
|
||||
return (
|
||||
<h3 ref={ref} className={`modal-title ${className}`}>
|
||||
{children}
|
||||
</h3>
|
||||
);
|
||||
});
|
||||
|
||||
export { ModalTitle };
|
||||
6
src/components/modal/index.ts
Normal file
6
src/components/modal/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from './Modal';
|
||||
export * from './ModalBackdrop';
|
||||
export * from './ModalContent';
|
||||
export * from './ModalBody';
|
||||
export * from './ModalHeader';
|
||||
export * from './ModalTitle';
|
||||
Reference in New Issue
Block a user