my-alert-dialog
v1.0.0
Published
A reusable React alert dialog component with custom CSS styling
Maintainers
Readme
Theam Alert Dialog
A reusable React alert dialog component with custom CSS styling, designed for easy integration into any React application.
Features
- Customizable alert dialog with overlay
- Trigger button integration
- Cancel and confirm actions
- Responsive design
- Built with React and raw CSS
- No external dependencies (except React)
Installation
npm install my-alert-dialogUsage
import React, { useState } from "react";
import { AlertDialog } from "react-alert-dialog-component";
function App() {
const [isOpen, setIsOpen] = useState(false);
const handleOpen = () => setIsOpen(true);
const handleClose = () => setIsOpen(false);
const handleConfirm = () => {
console.log("Confirmed!");
setIsOpen(false);
};
return (
<div>
<button onClick={handleOpen}>Show Dialog</button>
<AlertDialog
isOpen={isOpen}
onClose={handleClose}
onConfirm={handleConfirm}
title="Are you absolutely sure?"
description="This action cannot be undone. This will permanently delete your account and remove your data from our servers."
cancelText="Cancel"
confirmText="Continue"
/>
</div>
);
}
export default App;Props
| Prop | Type | Default | Description |
| ------------- | -------- | ---------- | --------------------------------------- |
| isOpen | boolean | - | Controls whether the dialog is visible |
| onClose | function | - | Callback when dialog should close |
| onConfirm | function | - | Callback when confirm button is clicked |
| title | string | - | Dialog title |
| description | string | - | Dialog description |
| cancelText | string | "Cancel" | Text for cancel button |
| confirmText | string | "Continue" | Text for confirm button |
Styling
The component includes its own CSS styles. You can override them by adding your own CSS with higher specificity or by modifying the component's CSS file.
Development
To build the library:
npm run buildTo run the demo:
npm run devLicense
MIT
Clone the repository:
git clone <repository-url> cd packageInstall dependencies:
npm installStart the development server:
npm run devOpen your browser and navigate to
http://localhost:5173
Usage
Click the "Show Dialog" button to open the alert dialog. You can cancel or confirm the action.
Project Structure
src/
├── components/
│ └── AlertDialog.jsx # Reusable alert dialog component
├── App.jsx # Main component
├── App.css # Styles for the alert dialog
├── main.jsx # Entry point
└── assets/ # Static assetsTechnologies Used
- React 19
- Vite
- CSS
Scripts
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLint
License
This project is open source and available under the MIT License.
