Skip to content

Commit

Permalink
feat(Harmony): create alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrin-kudryash authored and awinogradov committed Feb 13, 2024
1 parent 885cf34 commit c6119a3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/harmony/Alert/Alert.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.Alert {
display: flex;
align-items: center;
border-radius: var(--radius-m);
padding: var(--gap-sm);
gap: var(--gap-s);
}

.Alert_default {
background: var(--gray-900);
color: var(--text-primary);
}

.Alert_danger {
color: var(--danger-300);
background: var(--danger-900);
}

.Alert_warning {
color: var(--warn-300);
background: var(--warn-900);
}
17 changes: 17 additions & 0 deletions src/harmony/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Meta, StoryObj } from '@storybook/react';

import { Alert } from './Alert';

const meta: Meta = {
title: '@harmony/Alert',
component: Alert,
};

export default meta;

export const Default: StoryObj<typeof Alert> = {
args: {
view: 'default',
text: 'The selected date has already passed',
},
};
34 changes: 34 additions & 0 deletions src/harmony/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { ReactNode } from 'react';
import cn from 'classnames';
import { IconExclamationCircleOutline, IconInfoCircleOutline } from '@taskany/icons';

import { nullable } from '../../utils/nullable';
import { Text } from '../../harmony/Text/Text';

import s from './Alert.module.css';

interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
view: 'default' | 'danger' | 'warning';
text: string;
icon?: ReactNode;
}
const viewMap = {
default: s.Alert_default,
danger: s.Alert_danger,
warning: s.Alert_warning,
};

const iconMap = {
default: <IconInfoCircleOutline size="s" />,
danger: <IconExclamationCircleOutline size="s" />,
warning: <IconExclamationCircleOutline size="s" />,
};

export const Alert: React.FC<AlertProps> = ({ text, icon, className, view, ...props }) => {
return (
<div className={cn(s.Alert, viewMap[view], className)} {...props}>
{nullable(icon, (i) => i, iconMap[view])}
<Text color="inherit">{text}</Text>
</div>
);
};
1 change: 1 addition & 0 deletions src/harmony/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Alert/Alert';
export * from './AutoComplete/AutoComplete';
export * from './Badge/Badge';
export * from './Button/Button';
Expand Down

0 comments on commit c6119a3

Please sign in to comment.