Certainly! Below is a complete and self-contained example of the MobileContact component in React. This example assumes you have a basic React setup and creates a functional mobile contact popup. The Plus icon component and the Contact component are included for demonstration purposes, along with some basic CSS styles to manage the popup appearance.
File Structure
/src
├── components
│ ├── Icons
│ │ └── Plus.js
│ ├── Contact.js
│ └── MobileContact.js
└── App.js
1. Plus Icon Component (Plus.js)
This is a simple representation of a plus icon. You can use SVG or any other method to create this icon.
// Plus.js
import React from 'react';
const Plus = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="icon-plus"
>
<line x1="12" y1="5" x2="12" y2="19"></line>
<line x1="5" y1="12" x2="19" y2="12"></line>
</svg>
);
export default Plus;
2. Contact Component (Contact.js)
This is a simple placeholder for the Contact component.
// Contact.js
import React from 'react';
const Contact = ({ resources }) => {
return (
<div className="contact-list">
{resources.map((resource, index) => (
<div key={index} className="contact-item">
<h3>{resource.name}</h3>
<p>{resource.info}</p>
</div>
))}
</div>
);
};
export default Contact;
3. Mobile Contact Component (MobileContact.js)
This is your original MobileContact component with added functionality for closing the popup.
// MobileContact.js
import React from "react";
import Plus from "../Icons/Plus";
import Contact from './Contact';
const MobileContact = ({ resources, onClose }) => {
return (
<aside
id="mobilepopup"
className="popup_container"
aria-label="Mobile contact popup"
>
<Contact resources={resources}></Contact>
<button className="mobile__close contact-mobile-close" onClick={onClose}>
<span className="close__dummy">close button</span>
<Plus />
</button>
</aside>
);
};
export default MobileContact;
4. Example App Using the Mobile Contact (App.js)
Here’s how you can integrate the MobileContact in your App.js.
// App.js
import React, { useState } from 'react';
import MobileContact from './components/MobileContact';
const App = () => {
const [isPopupVisible, setPopupVisible] = useState(false);
const resources = [
{ name: 'Contact 1', info: 'Contact 1 info' },
{ name: 'Contact 2', info: 'Contact 2 info' },
];
const togglePopup = () => {
setPopupVisible(!isPopupVisible);
};
return (
<div>
<button onClick={togglePopup} className="open-popup-button">
Open Contact
</button>
{isPopupVisible && (
<MobileContact resources={resources} onClose={togglePopup} />
)}
</div>
);
};
export default App;
5. Basic Styles (CSS)
Optionally, you may want to add some CSS to style the popup.
/* styles.css */
.popup_container {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 1000;
}
.contact-list {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.contact-item {
margin-bottom: 10px;
}
.mobile__close {
background: transparent;
border: none;
cursor: pointer;
}
How It Works
- The
App component manages the state for showing or hiding the MobileContact popup.
- When the "Open Contact" button is clicked, the popup will appear.
- The
MobileContact component receives a list of resources and an onClose function to handle closing the popup.
- The
Contact component displays the list of contact information.
You can further customize the styles and functionality to fit the needs of your application!