mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
5b5ca4599e
* Replaces SEVERITIES const with Severity enum in BannerAlert * Replaced SEVERITIES with Severity in banner-alert.constants.js * Used BANNER_ALERT_SEVERITIES instead of SEVERITIES in banner-alert.stories.js * Updated README for usage of Severity instead of SEVERITIES * Updates to stories and docs link --------- Co-authored-by: Brad Decker <bhdecker84@gmail.com> Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
96 lines
2.4 KiB
JavaScript
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.Warning,
|
|
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,
|
|
};
|