Skip to content

Commit

Permalink
New Component: Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris0011 committed Oct 1, 2023
1 parent 543a46e commit 360c29c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';

export interface IModalProps {
isOpen: boolean;
onClose: () => void;
title?: string;
children: React.ReactNode;
}

export const Modal: React.FunctionComponent<IModalProps> = (props) => {
const { isOpen, onClose, title, children } = props;

const modalStyles: React.CSSProperties = {
display: isOpen ? 'block' : 'none',
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
zIndex: 1000,
backgroundColor: '#fff',
padding: '20px',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
color: 'black'
};

const overlayStyles: React.CSSProperties = {
display: isOpen ? 'block' : 'none',
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
zIndex: 999
};

return (
<div>
{/* Overlay */}
<div style={overlayStyles} onClick={onClose}></div>

{/* Modal */}
<div style={modalStyles}>
<div>{title && <h2>{title}</h2>}</div>
<div>{children}</div>
<button onClick={onClose}>close</button>
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Button';
export * from './Modal' ;

0 comments on commit 360c29c

Please sign in to comment.