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 Jul 17, 2022
1 parent ff7c91b commit 10da76b
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 10da76b

Please sign in to comment.