UNPKG

@navinc/base-react-components

Version:
127 lines (126 loc) 5.75 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const banner_js_1 = __importDefault(require("./banner.js")); const styled_components_1 = __importStar(require("styled-components")); const prop_types_1 = __importDefault(require("prop-types")); const is_rebrand_js_1 = __importDefault(require("./is-rebrand.js")); const TimedBar = styled_components_1.default.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_components_1.default.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 = (0, styled_components_1.useTheme)(); const styles = (0, is_rebrand_js_1.default)(theme) ? expandedStyles : deprecatedExpandedStyles; const [isAnimationRunning, setIsAnimationRunning] = (0, react_1.useState)(true); const handleMouseOver = () => setIsAnimationRunning(false); const handleMouseOut = () => setIsAnimationRunning(true); const { primaryColor } = (_b = styles[type]) !== null && _b !== void 0 ? _b : styles.neutralAction; return ((0, jsx_runtime_1.jsxs)(Container, Object.assign({ onMouseOver: handleMouseOver, onMouseOut: handleMouseOut }, { children: [(0, jsx_runtime_1.jsx)(banner_js_1.default, Object.assign({ expandedStyles: styles, onDismiss: shouldNotTimeout && onDismiss, shouldHideBorder: true, type: type, time: time }, props)), shouldShowTimedBar && ((0, jsx_runtime_1.jsx)(TimedBar, { isAnimationRunning: isAnimationRunning, onAnimationEnd: onDismiss, time: time, backgroundColor: primaryColor, shouldNotTimeout: shouldNotTimeout, "data-testid": "BannerToast:AnimationBar" }))] }))); }; BannerToast.propTypes = { onDismiss: prop_types_1.default.func, shouldNotTimeout: prop_types_1.default.bool, time: prop_types_1.default.number, }; exports.default = BannerToast; //# sourceMappingURL=banner-toast.js.map