Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import './DynamicAlert.css'; // Import the CSS file
const DynamicAlert = ({ message, type, showAlert, closeAlert }) => {
const alertTypeClass = type ? `alert-${type}` : '';
return (
<div className={`alert-popup ${showAlert ? 'show' : ''}`}>
<div className={`alert-content ${alertTypeClass}`}>
<span>{message}</span>
<button className="close-btn" onClick={closeAlert}>
Close
</button>
</div>
</div>
);
};
export default DynamicAlert;
-------------------------------------------------
.alert-popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
z-index: 1000;
}
.alert-popup.show {
display: flex;
}
.alert-content {
background-color: white;
padding: 20px;
border-radius: 5px;
text-align: center;
width: 300px;
}
.alert-success {
background-color: #28a745;
color: white;
}
.alert-error {
background-color: #dc3545;
color: white;
}
.alert-warning {
background-color: #ffc107;
color: black;
}
.close-btn {
background-color: #007bff;
color: white;
border: none;
padding: 10px;
cursor: pointer;
margin-top: 10px;
border-radius: 5px;
}
.close-btn:hover {
background-color: #0056b3;
}
------------------------------------
component call
import React, { useState } from 'react';
import DynamicAlert from './DynamicAlert'; // Import the dynamic alert component
const App = () => {
const [showAlert, setShowAlert] = useState(false);
const [alertType, setAlertType] = useState('success');
const [alertMessage, setAlertMessage] = useState('This is a success message!');
// Function to display the alert with dynamic type and message
const handleShowAlert = (type, message) => {
setAlertType(type);
setAlertMessage(message);
setShowAlert(true);
};
// Function to close the alert
const handleCloseAlert = () => {
setShowAlert(false);
};
return (
<div>
<h1>Dynamic React Alert Popup Example</h1>
{/* Buttons to trigger different types of alerts */}
<button onClick={() => handleShowAlert('success', 'This is a success message!')}>
Show Success Alert
</button>
<button onClick={() => handleShowAlert('error', 'This is an error message!')}>
Show Error Alert
</button>
<button onClick={() => handleShowAlert('warning', 'This is a warning message!')}>
Show Warning Alert
</button>
{/* DynamicAlert component */}
<DynamicAlert
message={alertMessage}
type={alertType}
showAlert={showAlert}
closeAlert={handleCloseAlert}
/>
</div>
);
};
export default App;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team