1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/component-library/banner-alert/banner-alert.js
Bhavya gor b0fcb12b99
Update BannerAlert icon to match Figma Issue#20355 (#20407)
* changed warning --> danger

* snapshot updates

* Adding comment

* Updating snapshot

---------

Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
2023-08-15 08:20:02 -07:00

96 lines
2.4 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { BannerBase, Icon, IconName, IconSize } from '..';
import {
BackgroundColor,
IconColor,
Severity,
} from '../../../helpers/constants/design-system';
import { BANNER_ALERT_SEVERITIES } from './banner-alert.constants';
export const BannerAlert = ({
children,
className,
severity = Severity.Info,
...props
}) => {
const severityIcon = () => {
switch (severity) {
case Severity.Danger:
return {
name: IconName.Danger,
color: IconColor.errorDefault,
};
case Severity.Warning:
return {
name: IconName.Danger, // Uses same icon as danger
color: IconColor.warningDefault,
};
case Severity.Success:
return {
name: IconName.Confirmation,
color: IconColor.successDefault,
};
// Defaults to Severity.Info
default:
return {
name: IconName.Info,
color: IconColor.primaryDefault,
};
}
};
const severityBackground = () => {
switch (severity) {
case Severity.Danger:
return BackgroundColor.errorMuted;
case Severity.Warning:
return BackgroundColor.warningMuted;
case Severity.Success:
return BackgroundColor.successMuted;
// Defaults to Severity.Info
default:
return BackgroundColor.primaryMuted;
}
};
return (
<BannerBase
startAccessory={<Icon size={IconSize.Lg} {...severityIcon()} />}
backgroundColor={severityBackground()}
paddingLeft={2}
className={classnames(
'mm-banner-alert',
{
[`mm-banner-alert--severity-${severity}`]: Object.values(
BANNER_ALERT_SEVERITIES,
).includes(severity),
},
className,
)}
{...props}
>
{children}
</BannerBase>
);
};
BannerAlert.propTypes = {
/**
* An additional className to apply to the Banner
*/
className: PropTypes.string,
/**
* Use the `severity` prop and the `Severity` enum from `./ui/helpers/constants/design-system.js` to change the context of `Banner`.
* Possible options: `Severity.Info`(Default), `Severity.Warning`, `Severity.Danger`, `Severity.Success`
*/
severity: PropTypes.oneOf(Object.values(BANNER_ALERT_SEVERITIES)),
/**
* BannerAlert accepts all the props from BannerBase
*/
...BannerBase.propTypes,
};