Skip to main content

Alert

A stylized alert box for displaying important messages to users. Supports icons, dismissibility, and multiple alert types like info, success, error, and warning.

πŸ“¦ Import​

import { Alert } from "@sahilphondekar/react-component-library";

🧱 Props​

NameTypeDefaultDescription
messagestring or ReactNodeβ€” (required)Message to display in the alert.
type"info" | "success" | "error" | "warning""info"Type of alert, which determines the styling and default icon.
onClosefunctionβ€” (required)Function to call when the alert is dismissed.
classNamestring""Additional classes to apply to the container.
dismissiblebooleantrueWhether to show a close (Γ—) button.
iconstring (raw SVG) or React.ElementTypeβ€”Optional custom icon. Falls back to the type's default if not provided.
iconSizestring"20px"Width and height of the icon (e.g. "24px" or "1.5rem").

🎨 Styling​

Each type value maps to specific background, text, and border colors using Tailwind CSS:

TypeBackgroundTextBorder
infobg-blue-50text-blue-800border-blue-200
successbg-green-50text-green-800border-green-200
errorbg-red-50text-red-800border-red-200
warningbg-yellow-50text-yellow-800border-yellow-200

πŸ§ͺ Example​

<Alert
message="Your profile was updated successfully!"
type="success"
onClose={() => console.log("Alert dismissed")}
/>

With custom icon:

import { Info } from "lucide-react";

<Alert
message="This is a custom info alert"
type="info"
icon={Info}
onClose={() => console.log("Dismissed")}
/>

🧠 Notes​

  • Uses a SvgIcon utility component to render inline SVG strings for built-in icons.
  • When icon is a string, it should be valid inline SVG markup.
  • If icon is a React component (like an icon from lucide-react), it will be rendered using React.createElement.

πŸ’‘ Use Cases​

  • Status updates (e.g., β€œSaved successfully”)
  • Form error summaries
  • System notifications
  • Informational callouts