UNPKG

@navinc/base-react-components

Version:
99 lines (98 loc) 4.22 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, { useTheme } from 'styled-components'; import PropTypes from 'prop-types'; import isRebrand from './is-rebrand.js'; const TimedBar = styled.div.withConfig({ displayName: "brc-sc-TimedBar", componentId: "brc-sc-2f115b" }) ` @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-n6jl8s" }) ` position: relative; width: 100%; `; const deprecatedExpandedStyles = { error: { primaryColor: 'sebastianRed200', secondaryColor: 'sebastianRed100', defaultIcon: 'actions/circle-warning', defaultActionIcon: 'actions/close', }, neutralAction: { primaryColor: 'bubbleBlue400', secondaryColor: 'bubbleBlue100', defaultIcon: 'actions/circle-info', defaultActionIcon: 'actions/carrot-right', }, success: { primaryColor: 'seaturtleGreen200', secondaryColor: 'seaturtleGreen100', defaultIcon: 'actions/check-circle', defaultActionIcon: 'actions/close', }, }; 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; 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 theme = useTheme(); const styles = isRebrand(theme) ? expandedStyles : deprecatedExpandedStyles; 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, Object.assign({ onMouseOver: handleMouseOver, onMouseOut: handleMouseOut }, { children: [_jsx(Banner, Object.assign({ expandedStyles: styles, onDismiss: shouldNotTimeout && onDismiss, shouldHideBorder: true, type: type, time: time }, props)), shouldShowTimedBar && (_jsx(TimedBar, { isAnimationRunning: isAnimationRunning, onAnimationEnd: onDismiss, time: time, backgroundColor: primaryColor, shouldNotTimeout: shouldNotTimeout, "data-testid": "BannerToast:AnimationBar" }))] }))); }; BannerToast.propTypes = { onDismiss: PropTypes.func, shouldNotTimeout: PropTypes.bool, time: PropTypes.number, }; export default BannerToast; //# sourceMappingURL=banner-toast.js.map