Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Banner component #275

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/web-lib/components/Banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import IconAlertWarning from '@yearn-finance/web-lib/icons/IconAlertWarning';
import IconCross from '@yearn-finance/web-lib/icons/IconCross';

import type {ReactElement} from 'react';

type TBannerProps = {
content: string;
type: 'error' | 'warning' | 'success' | 'info';
onClose: () => void
};

export function Banner({content, type, onClose}: TBannerProps): ReactElement {
const {backgroundColor, color} = getColors(type);

return (
// eslint-disable-next-line tailwindcss/classnames-order
<div className={`bg-[${backgroundColor}] flex justify-between p-2 text-${color}`}>
<IconAlertWarning className={'ml-3'} />
<p className={'text-base'}>{content}</p>
<IconCross
className={'cursor-pointer text-white md:right-3 md:top-4'}
onClick={onClose}
/>
</div>
);
}

function getColors(type: TBannerProps['type']): {backgroundColor: string; color: string} {
switch (type) {
case 'error':
return {backgroundColor: '#C73203', color: 'white'};
case 'warning':
return {backgroundColor: '#FFDC53', color: 'black'};
case 'success':
return {backgroundColor: '#00796D', color: 'white'};
default:
return {backgroundColor: '#0657F9', color: 'white'};
}
}