UNPKG

@navinc/base-react-components

Version:
70 lines (69 loc) 3.29 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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import { Banner } from './banner.js'; import styled from 'styled-components'; const TimedBar = styled.div.withConfig({ displayName: "brc-sc-TimedBar", componentId: "brc-sc-cdr9it" }) ` @keyframes animate { from { width: 100%; } to { width: 0%; } } animation-name: 'animate'; animation-play-state: ${({ $isAnimationRunning, $shouldNotTimeout }) => !$shouldNotTimeout && $isAnimationRunning ? 'running' : 'paused'}; animation-duration: ${({ $time }) => `${$time}ms`}; background-color: ${({ $backgroundColor, theme }) => theme[$backgroundColor]}; height: 5px; position: absolute; bottom: 0; border-radius: ${({ $shouldNotTimeout }) => ($shouldNotTimeout ? '0 0 4px 4px' : '0 0 0 4px')}; `; const Container = styled.div.withConfig({ displayName: "brc-sc-Container", componentId: "brc-sc-vri1ms" }) ` position: relative; width: 100%; `; const expandedStyles = { error: { primaryColor: 'navStatusNegative', secondaryColor: 'navStatusNegative200', defaultIcon: 'actions/circle-warning', defaultActionIcon: 'actions/close', }, neutralAction: { primaryColor: 'navNeutral400', secondaryColor: 'navNeutral100', defaultIcon: 'actions/circle-info', defaultActionIcon: 'actions/carrot-right', }, success: { primaryColor: 'navStatusPositive', secondaryColor: 'navStatusPositive200', defaultIcon: 'actions/check-circle', defaultActionIcon: 'actions/close', }, }; const FIVE_SECONDS = 5000; export const BannerToast = (_a) => { var _b; var { onDismiss, shouldNotTimeout, type = 'neutralAction', time = FIVE_SECONDS, shouldShowTimedBar = true } = _a, props = __rest(_a, ["onDismiss", "shouldNotTimeout", "type", "time", "shouldShowTimedBar"]); const styles = expandedStyles; const [isAnimationRunning, setIsAnimationRunning] = useState(true); const handleMouseOver = () => setIsAnimationRunning(false); const handleMouseOut = () => setIsAnimationRunning(true); const { primaryColor } = (_b = styles[type]) !== null && _b !== void 0 ? _b : styles.neutralAction; return (_jsxs(Container, { onMouseOver: handleMouseOver, onMouseOut: handleMouseOut, children: [_jsx(Banner, Object.assign({ expandedStyles: styles, onDismiss: shouldNotTimeout ? onDismiss : undefined, shouldHideBorder: true, type: type, time: time }, props)), shouldShowTimedBar && (_jsx(TimedBar, { "$isAnimationRunning": isAnimationRunning, onAnimationEnd: onDismiss, "$time": time, "$backgroundColor": primaryColor, "$shouldNotTimeout": shouldNotTimeout, "data-testid": "BannerToast:AnimationBar" }))] })); }; //# sourceMappingURL=banner-toast.js.map