UNPKG

@brizy/ui

Version:
40 lines (39 loc) 2.19 kB
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 React, { useRef, useCallback, useEffect } from "react"; import { Icon } from "../Icon"; import { CheckCircleOn, Close, Error, Info } from "../icons"; import { CSSTransition } from "react-transition-group"; import { BRZ_PREFIX } from "../constants"; export const Notice = (_a) => { var { id, text, type, closable, duration, onClose } = _a, cssTransitionProps = __rest(_a, ["id", "text", "type", "closable", "duration", "onClose"]); const timer = useRef(); const node = useRef(null); const handleClose = useCallback(() => onClose(id), [id, onClose]); const onEntering = useCallback(() => { if (duration && duration > 0) { timer.current = setTimeout(handleClose, duration); } }, [duration, handleClose]); useEffect(() => () => { if (timer.current) clearTimeout(timer.current); }, []); return (React.createElement(CSSTransition, Object.assign({}, cssTransitionProps, { nodeRef: node, onEntering: onEntering }), React.createElement("div", { ref: node, className: `${BRZ_PREFIX}-notification` }, type === "success" && React.createElement(Icon, { source: CheckCircleOn, color: "green" }), type === "info" && React.createElement(Icon, { source: Info, color: "blue" }), type === "error" && React.createElement(Icon, { source: Error, color: "red" }), React.createElement("span", { className: `${BRZ_PREFIX}-notification__message` }, text), closable && (React.createElement("div", { className: `${BRZ_PREFIX}-notification__close`, onClick: handleClose }, React.createElement(Icon, { source: Close, color: "gray-light" })))))); };