1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/components/component-library/banner/banner.js
Garrett Bear ed75dabe57
Feat/15086/add banner severities component (#17307)
* add banner component

* update banner styles and tests

* fix padding and update snapshot

* banner stories id removal

* update readme

* Update ui/components/component-library/banner/banner.js

Co-authored-by: George Marshall <george.marshall@consensys.net>

* Update ui/components/component-library/banner/README.mdx

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/component-library/banner/README.mdx

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* banner updates

Co-authored-by: George Marshall <george.marshall@consensys.net>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
2023-01-25 10:39:49 -08:00

94 lines
2.3 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { BannerBase, Icon, ICON_NAMES } from '..';
import {
COLORS,
SEVERITIES,
SIZES,
} from '../../../helpers/constants/design-system';
import { BANNER_SEVERITIES } from './banner.constants';
export const Banner = ({
children,
className,
severity = SEVERITIES.INFO,
...props
}) => {
const severityIcon = () => {
switch (severity) {
case SEVERITIES.DANGER:
return {
name: ICON_NAMES.DANGER,
color: COLORS.ERROR_DEFAULT,
};
case SEVERITIES.WARNING:
return {
name: ICON_NAMES.WARNING,
color: COLORS.WARNING_DEFAULT,
};
case SEVERITIES.SUCCESS:
return {
name: ICON_NAMES.CONFIRMATION,
color: COLORS.SUCCESS_DEFAULT,
};
// Defaults to SEVERITIES.INFO
default:
return {
name: ICON_NAMES.INFO,
color: COLORS.PRIMARY_DEFAULT,
};
}
};
const severityBackground = () => {
switch (severity) {
case SEVERITIES.DANGER:
return COLORS.ERROR_MUTED;
case SEVERITIES.WARNING:
return COLORS.WARNING_MUTED;
case SEVERITIES.SUCCESS:
return COLORS.SUCCESS_MUTED;
// Defaults to SEVERITIES.INFO
default:
return COLORS.PRIMARY_MUTED;
}
};
return (
<BannerBase
startAccessory={<Icon size={SIZES.LG} {...severityIcon()} />}
backgroundColor={severityBackground()}
className={classnames(
'mm-banner',
{
[`mm-banner--severity-${severity}`]:
Object.values(BANNER_SEVERITIES).includes(severity),
},
className,
)}
{...props}
>
{children}
</BannerBase>
);
};
Banner.propTypes = {
/**
* 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`
*/
severity: PropTypes.oneOf(Object.values(BANNER_SEVERITIES)),
/**
* Banner accepts all the props from BannerBase
*/
...BannerBase.propTypes,
};