@wecodesolutions/shared-react-components-ts 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
interface PopupProps {
|
|
3
|
+
/** Controls whether the modal is visible or not */
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
/** Called when the user clicks outside the modal or on a close button */
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
/** The content to show inside the modal */
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const Popup: FC<PopupProps>;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.modal_overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
/* Semi-transparent black background to block the page */
|
|
8
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
9
|
+
/* Place on top of other elements */
|
|
10
|
+
z-index: 9999;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
align-items: center;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.modal_container {
|
|
17
|
+
background: #fff;
|
|
18
|
+
border-radius: 4px;
|
|
19
|
+
padding: 15px;
|
|
20
|
+
max-width: 90%;
|
|
21
|
+
/* If on desktop, you can also add a max width or any design you like */
|
|
22
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Simple close button (optional) */
|
|
26
|
+
.close_button {
|
|
27
|
+
display: block;
|
|
28
|
+
margin-top: 16px;
|
|
29
|
+
padding: 8px 16px;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { FC, ReactNode } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import styles from './Popup.module.css'; // We'll define some basic styles in a separate file
|
|
4
|
+
|
|
5
|
+
interface PopupProps {
|
|
6
|
+
/** Controls whether the modal is visible or not */
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
/** Called when the user clicks outside the modal or on a close button */
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
/** The content to show inside the modal */
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Popup: FC<PopupProps> = ({ isOpen, onClose, children }) => {
|
|
15
|
+
// If the modal is not open, don't render anything
|
|
16
|
+
if (!isOpen) return null;
|
|
17
|
+
|
|
18
|
+
return ReactDOM.createPortal(
|
|
19
|
+
<div className={styles.modal_overlay} onClick={onClose}>
|
|
20
|
+
{/*
|
|
21
|
+
Stop the click from bubbling up to the overlay,
|
|
22
|
+
so a click inside the modal doesn't close it.
|
|
23
|
+
*/}
|
|
24
|
+
<div
|
|
25
|
+
className={styles.modal_container}
|
|
26
|
+
onClick={e => e.stopPropagation()}
|
|
27
|
+
>
|
|
28
|
+
{/* Render the consumer’s content */}
|
|
29
|
+
{children}
|
|
30
|
+
|
|
31
|
+
{/* Example close button (optional) */}
|
|
32
|
+
<button className={styles.close_button} onClick={onClose}>
|
|
33
|
+
Close
|
|
34
|
+
</button>
|
|
35
|
+
</div>
|
|
36
|
+
</div>,
|
|
37
|
+
document.body
|
|
38
|
+
);
|
|
39
|
+
};
|