2023-01-25 19:39:49 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
2023-04-05 18:11:10 +02:00
|
|
|
import { BannerBase, Icon, IconName, IconSize } from '..';
|
2023-01-25 19:39:49 +01:00
|
|
|
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
BackgroundColor,
|
|
|
|
IconColor,
|
2023-08-01 23:41:30 +02:00
|
|
|
Severity,
|
2023-01-25 19:39:49 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-02-07 18:32:35 +01:00
|
|
|
import { BANNER_ALERT_SEVERITIES } from './banner-alert.constants';
|
2023-01-25 19:39:49 +01:00
|
|
|
|
2023-02-07 18:32:35 +01:00
|
|
|
export const BannerAlert = ({
|
2023-01-25 19:39:49 +01:00
|
|
|
children,
|
|
|
|
className,
|
2023-08-01 23:41:30 +02:00
|
|
|
severity = Severity.Info,
|
2023-01-25 19:39:49 +01:00
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
const severityIcon = () => {
|
|
|
|
switch (severity) {
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Danger:
|
2023-01-25 19:39:49 +01:00
|
|
|
return {
|
2023-04-05 18:11:10 +02:00
|
|
|
name: IconName.Danger,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.errorDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Warning:
|
2023-01-25 19:39:49 +01:00
|
|
|
return {
|
2023-08-15 17:20:02 +02:00
|
|
|
name: IconName.Danger, // Uses same icon as danger
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.warningDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Success:
|
2023-01-25 19:39:49 +01:00
|
|
|
return {
|
2023-04-05 18:11:10 +02:00
|
|
|
name: IconName.Confirmation,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.successDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
2023-08-01 23:41:30 +02:00
|
|
|
// Defaults to Severity.Info
|
2023-01-25 19:39:49 +01:00
|
|
|
default:
|
|
|
|
return {
|
2023-04-05 18:11:10 +02:00
|
|
|
name: IconName.Info,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.primaryDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const severityBackground = () => {
|
|
|
|
switch (severity) {
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Danger:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.errorMuted;
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Warning:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.warningMuted;
|
2023-08-01 23:41:30 +02:00
|
|
|
case Severity.Success:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.successMuted;
|
2023-08-01 23:41:30 +02:00
|
|
|
// Defaults to Severity.Info
|
2023-01-25 19:39:49 +01:00
|
|
|
default:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.primaryMuted;
|
2023-01-25 19:39:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BannerBase
|
2023-04-05 18:11:10 +02:00
|
|
|
startAccessory={<Icon size={IconSize.Lg} {...severityIcon()} />}
|
2023-01-25 19:39:49 +01:00
|
|
|
backgroundColor={severityBackground()}
|
2023-02-03 09:12:53 +01:00
|
|
|
paddingLeft={2}
|
2023-01-25 19:39:49 +01:00
|
|
|
className={classnames(
|
2023-02-07 18:32:35 +01:00
|
|
|
'mm-banner-alert',
|
2023-01-25 19:39:49 +01:00
|
|
|
{
|
2023-02-07 18:32:35 +01:00
|
|
|
[`mm-banner-alert--severity-${severity}`]: Object.values(
|
|
|
|
BANNER_ALERT_SEVERITIES,
|
|
|
|
).includes(severity),
|
2023-01-25 19:39:49 +01:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</BannerBase>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-02-07 18:32:35 +01:00
|
|
|
BannerAlert.propTypes = {
|
2023-01-25 19:39:49 +01:00
|
|
|
/**
|
|
|
|
* An additional className to apply to the Banner
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
2023-08-01 23:41:30 +02:00
|
|
|
* 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`
|
2023-01-25 19:39:49 +01:00
|
|
|
*/
|
2023-02-07 18:32:35 +01:00
|
|
|
severity: PropTypes.oneOf(Object.values(BANNER_ALERT_SEVERITIES)),
|
2023-01-25 19:39:49 +01:00
|
|
|
/**
|
2023-02-14 18:33:04 +01:00
|
|
|
* BannerAlert accepts all the props from BannerBase
|
2023-01-25 19:39:49 +01:00
|
|
|
*/
|
|
|
|
...BannerBase.propTypes,
|
|
|
|
};
|