UNPKG

@trail-ui/react

Version:
78 lines (75 loc) 2.62 kB
import { _IconButton } from "./chunk-CTOQKVKR.mjs"; // src/flag/flag.tsx import { useMemo } from "react"; import { filterVariantProps, flag } from "@trail-ui/theme"; import { CheckCircleIcon, CloseIcon, ErrorIcon, InfoIcon, SettingsIcon, WarningIcon } from "@trail-ui/icons"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; function Flag(props) { let flagIcon; let closeBtn; const { title, desc, variant, isClosable, onClose } = props; const variantProps = filterVariantProps(props, flag.variantKeys); const styles = useMemo( () => flag({ ...variantProps, variant }), [variantProps, variant] ); switch (variant) { case "default": flagIcon = /* @__PURE__ */ jsx(SettingsIcon, { height: 24, width: 24 }); closeBtn = /* @__PURE__ */ jsx(CloseIcon, { height: 24, width: 24, className: "text-neutral-900" }); break; case "success": flagIcon = /* @__PURE__ */ jsx(CheckCircleIcon, { height: 24, width: 24 }); closeBtn = /* @__PURE__ */ jsx(CloseIcon, { height: 24, width: 24, className: "text-green-950" }); break; case "error": flagIcon = /* @__PURE__ */ jsx(ErrorIcon, { height: 24, width: 24 }); closeBtn = /* @__PURE__ */ jsx(CloseIcon, { height: 24, width: 24, className: "text-red-950" }); break; case "warning": flagIcon = /* @__PURE__ */ jsx(WarningIcon, { height: 24, width: 24 }); closeBtn = /* @__PURE__ */ jsx(CloseIcon, { height: 24, width: 24, className: "text-yellow-950" }); break; case "info": flagIcon = /* @__PURE__ */ jsx(InfoIcon, { height: 24, width: 24 }); closeBtn = /* @__PURE__ */ jsx(CloseIcon, { height: 24, width: 24, className: "text-blue-950" }); break; default: break; } return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", { className: styles, children: [ /* @__PURE__ */ jsx("div", { children: flagIcon }), /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-1.5", children: [ /* @__PURE__ */ jsxs("div", { className: "flex w-full font-semibold", children: [ /* @__PURE__ */ jsx("p", { children: title }), isClosable && /* @__PURE__ */ jsx( _IconButton, { spacing: "compact", appearance: "transparent", onPress: onClose, "aria-label": "Close", className: "ml-auto", children: closeBtn } ) ] }), desc && /* @__PURE__ */ jsx("p", { className: "font-normal", children: desc }) ] }) ] }) }); } export { Flag };