Skip to content

Commit

Permalink
feat: render warn icon when type is "warn"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostein Kringlen committed Apr 12, 2022
1 parent fa39669 commit 7853629
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/components/toast-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Toast } from '../core/types';
import { ErrorIcon, ErrorTheme } from './error';
import { LoaderIcon, LoaderTheme } from './loader';
import { CheckmarkIcon, CheckmarkTheme } from './checkmark';
import { WarnIcon, WarnTheme } from './warn';

const StatusWrapper = styled('div')`
position: absolute;
Expand Down Expand Up @@ -42,6 +43,7 @@ export type IconThemes = Partial<{
success: CheckmarkTheme;
error: ErrorTheme;
loading: LoaderTheme;
warn: WarnTheme;
}>;

export const ToastIcon: React.FC<{
Expand All @@ -60,18 +62,21 @@ export const ToastIcon: React.FC<{
return null;
}

const renderIcon = (type: Toast['type']) => {
switch (type) {
case 'error':
return <ErrorIcon {...iconTheme} />;
case 'warn':
return <WarnIcon {...iconTheme} />;
default:
return <CheckmarkIcon {...iconTheme} />;
}
};

return (
<IndicatorWrapper>
<LoaderIcon {...iconTheme} />
{type !== 'loading' && (
<StatusWrapper>
{type === 'error' ? (
<ErrorIcon {...iconTheme} />
) : (
<CheckmarkIcon {...iconTheme} />
)}
</StatusWrapper>
)}
{type !== 'loading' && <StatusWrapper>{renderIcon(type)}</StatusWrapper>}
</IndicatorWrapper>
);
};

0 comments on commit 7853629

Please sign in to comment.