Skip to content

Commit

Permalink
feat: add warning toast
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanluongoe committed Jan 10, 2024
1 parent 7375c2a commit 233c580
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,41 @@ const StyledSpinner = styled('i')`
export const Spinner: React.FC = () => {
return <StyledSpinner />;
};

const StyledWarning = styled('i')`
& {
box-sizing: border-box;
position: relative;
display: block;
width: 30px;
height: 30px;
border: 2px solid;
border-radius: 40px;
color: #f6d776;
}
&::after,
&::before {
content: '';
display: block;
box-sizing: border-box;
position: absolute;
border-radius: 3px;
width: 3px;
background: currentColor;
left: 11.5px;
color: #f6d776;
}
&::after {
top: 4px;
height: 14px;
}
&::before {
height: 3px;
bottom: 3px;
width: 3px;
border-radius: 9999px;
}
`;
export const Warning: React.FC = () => {
return <StyledWarning />;
};
5 changes: 4 additions & 1 deletion src/components/toast-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { keyframes, styled } from 'goober';
import React from 'react';
import { Toast } from '../core/types';
import { Check, Close, Spinner } from './icons';
import { Check, Close, Spinner, Warning } from './icons';

interface ToastIconProps {
icon?: Toast['icon'];
Expand Down Expand Up @@ -45,6 +45,9 @@ const ToastIcon: React.FC<ToastIconProps> = (props) => {
if (type === 'loading') {
return <Spinner />;
}
if (type === 'warning') {
return <Warning />;
}
return null;
};

Expand Down
7 changes: 6 additions & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { CSSProperties } from 'react';

export type ToasterType = 'success' | 'error' | 'default' | 'loading';
export type ToasterType =
| 'success'
| 'error'
| 'default'
| 'loading'
| 'warning';

export type Toast = {
id: string;
Expand Down
1 change: 1 addition & 0 deletions src/core/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const toast = (opts: ToastArg) => createHandler('default')(opts);
toast.error = createHandler('error');
toast.success = createHandler('success');
toast.loading = createHandler('loading');
toast.warning = createHandler('warning');

toast.promise = <T>(
promise: Promise<T>,
Expand Down

0 comments on commit 233c580

Please sign in to comment.