@navinc/base-react-components
Version:
Nav's Pattern Library
77 lines (76 loc) • 3.72 kB
JavaScript
;
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 });
exports.BannerToast = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const banner_js_1 = require("./banner.js");
const styled_components_1 = __importDefault(require("styled-components"));
const TimedBar = styled_components_1.default.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_components_1.default.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;
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] = (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, { onMouseOver: handleMouseOver, onMouseOut: handleMouseOut, children: [(0, jsx_runtime_1.jsx)(banner_js_1.Banner, Object.assign({ expandedStyles: styles, onDismiss: shouldNotTimeout ? onDismiss : undefined, 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" }))] }));
};
exports.BannerToast = BannerToast;
//# sourceMappingURL=banner-toast.js.map