2023-01-25 19:39:49 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
2023-04-04 18:48:04 +02:00
|
|
|
import { Icon, ICON_NAMES } from '../icon/deprecated';
|
|
|
|
import { BannerBase } from '..';
|
2023-01-25 19:39:49 +01:00
|
|
|
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
BackgroundColor,
|
|
|
|
IconColor,
|
2023-01-25 19:39:49 +01:00
|
|
|
SEVERITIES,
|
2023-02-02 21:15:26 +01:00
|
|
|
Size,
|
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,
|
|
|
|
severity = SEVERITIES.INFO,
|
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
const severityIcon = () => {
|
|
|
|
switch (severity) {
|
|
|
|
case SEVERITIES.DANGER:
|
|
|
|
return {
|
|
|
|
name: ICON_NAMES.DANGER,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.errorDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
|
|
|
case SEVERITIES.WARNING:
|
|
|
|
return {
|
|
|
|
name: ICON_NAMES.WARNING,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.warningDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
|
|
|
case SEVERITIES.SUCCESS:
|
|
|
|
return {
|
|
|
|
name: ICON_NAMES.CONFIRMATION,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.successDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
|
|
|
// Defaults to SEVERITIES.INFO
|
|
|
|
default:
|
|
|
|
return {
|
|
|
|
name: ICON_NAMES.INFO,
|
2023-02-02 21:15:26 +01:00
|
|
|
color: IconColor.primaryDefault,
|
2023-01-25 19:39:49 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const severityBackground = () => {
|
|
|
|
switch (severity) {
|
|
|
|
case SEVERITIES.DANGER:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.errorMuted;
|
2023-01-25 19:39:49 +01:00
|
|
|
case SEVERITIES.WARNING:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.warningMuted;
|
2023-01-25 19:39:49 +01:00
|
|
|
case SEVERITIES.SUCCESS:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.successMuted;
|
2023-01-25 19:39:49 +01:00
|
|
|
// Defaults to SEVERITIES.INFO
|
|
|
|
default:
|
2023-02-02 21:15:26 +01:00
|
|
|
return BackgroundColor.primaryMuted;
|
2023-01-25 19:39:49 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BannerBase
|
2023-02-02 21:15:26 +01:00
|
|
|
startAccessory={<Icon size={Size.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,
|
|
|
|
/**
|
|
|
|
* Use the `severity` prop and the `SEVERITIES` object from `./ui/helpers/constants/design-system.js` to change the context of `Banner`.
|
|
|
|
* Possible options: `SEVERITIES.INFO`(Default), `SEVERITIES.WARNING`, `SEVERITIES.DANGER`, `SEVERITIES.SUCCESS`
|
|
|
|
*/
|
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,
|
|
|
|
};
|