@ducor/react
Version:
admin template ui interface
34 lines (33 loc) • 1.84 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, forwardRef } from "react";
import { twMerge } from "tailwind-merge";
import { getColor } from "../helpers/colors";
import Button from "./button";
import Flex from "./flex";
import { FiX } from "react-icons/fi";
const Alert = forwardRef((_a, ref) => {
var { dismissible = false, children, color = "info", className, onDismiss } = _a, props = __rest(_a, ["dismissible", "children", "color", "className", "onDismiss"]);
const [isDismissed, setIsDismissed] = useState(false);
if (isDismissed)
return null;
const handleDismiss = () => {
setIsDismissed(true);
if (onDismiss) {
onDismiss();
}
};
return (_jsx("div", Object.assign({ ref: ref, className: twMerge(`p-4 border-l-4 rounded-lg transition-all duration-300 ease-in-out border-r border-t border-b hover:shadow-md mb-2`, getColor({ variant: "filled", color, active: true }), className), role: 'alert' }, props, { children: _jsxs(Flex, { align: 'center', justify: 'between', children: [_jsx("div", { children: children }), dismissible && (_jsx(Button, { onClick: handleDismiss, variant: 'text', active: true, color: color, "aria-label": 'Dismiss alert', children: _jsx(FiX, {}) }))] }) })));
});
Alert.displayName = "Alert";
export default Alert;