UNPKG

@navinc/base-react-components

Version:
76 lines (75 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'; import PropTypes from 'prop-types'; const TimedBar = styled.div ` @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 ` position: relative; width: 100%; `; const expandedStyles = { error: { primaryColor: 'copperRed200', secondaryColor: 'copperRed100', defaultIcon: 'actions/circle-warning', defultActionIcon: 'actions/close', }, neutralAction: { primaryColor: 'lightBlue400', secondaryColor: 'lightBlue100', defaultIcon: 'actions/circle-info', defultActionIcon: 'actions/carrot-right', }, success: { primaryColor: 'oceanGreen200', secondaryColor: 'oceanGreen100', defaultIcon: 'actions/check-circle', defultActionIcon: 'actions/close', }, }; const FIVE_SECONDS = 5000; 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 [isAnimationRunning, setIsAnimationRunning] = useState(true); const handleMouseOver = () => setIsAnimationRunning(false); const handleMouseOut = () => setIsAnimationRunning(true); const { primaryColor } = (_b = expandedStyles[type]) !== null && _b !== void 0 ? _b : expandedStyles.neutralAction; return (_jsxs(Container, Object.assign({ onMouseOver: handleMouseOver, onMouseOut: handleMouseOut }, { children: [_jsx(Banner, Object.assign({ expandedStyles: expandedStyles, onDismiss: shouldNotTimeout && onDismiss, shouldHideBorder: true, type: type, time: time }, props), void 0), shouldShowTimedBar && (_jsx(TimedBar, { isAnimationRunning: isAnimationRunning, onAnimationEnd: onDismiss, time: time, backgroundColor: primaryColor, shouldNotTimeout: shouldNotTimeout, "data-testid": "BannerToast:AnimationBar" }, void 0))] }), void 0)); }; BannerToast.propTypes = { onDismiss: PropTypes.func, shouldNotTimeout: PropTypes.bool, time: PropTypes.number, }; export default BannerToast; //# sourceMappingURL=banner-toast.js.map