Skip to content

Commit 36cb691

Browse files
committed
feat: add iconsColors object to customize icon colors in Toast component
1 parent e7fbf9e commit 36cb691

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

library/src/components/toast.tsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const icons: Record<Variant, FC<React.SVGProps<SVGSVGElement>>> = {
1717
info: Info,
1818
};
1919

20+
const iconsColors: Record<Variant, string> = {
21+
success: '#22c55e',
22+
error: '#ef4444',
23+
warning: '#eab308',
24+
info: '#3b82f6',
25+
};
26+
2027
interface ToastComponentProps extends ToastPropsWithVariant {
2128
toastPosition: Position;
2229
onClose: () => void;
@@ -85,16 +92,16 @@ const Toast = (props: ToastComponentProps) => {
8592
onMouseLeave={handleMouseLeave}
8693
>
8794
<div className="t_container">
88-
{props.variant &&
89-
(props.icon ? (
90-
<div className="t_icon">{props.icon}</div>
91-
) : (
92-
<IconComponent
93-
width={props.iconSize || 18}
94-
height={props.iconSize || 18}
95-
className="t_icon"
96-
/>
97-
))}
95+
{props.variant && !props.icon ? (
96+
<IconComponent
97+
width={props.iconSize || 18}
98+
height={props.iconSize || 18}
99+
style={{ fill: iconsColors[props.variant] }}
100+
className="t_icon"
101+
/>
102+
) : (
103+
props.icon && <div className="t_icon">{props.icon}</div>
104+
)}
98105
<div className="t_content">
99106
<p>{props.text}</p>
100107
{props.description && <p>{props.description}</p>}

library/src/icons/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import type { ComponentProps, FC } from "react";
1+
import type { ComponentProps, FC } from 'react';
22

3-
const Success: FC<ComponentProps<"svg">> = (props) => (
3+
const Success: FC<ComponentProps<'svg'>> = (props) => (
44
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" {...props}>
55
<path d="M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z"></path>
66
</svg>
77
);
88

9-
const Warning: FC<ComponentProps<"svg">> = (props) => (
9+
const Warning: FC<ComponentProps<'svg'>> = (props) => (
1010
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" {...props}>
1111
<path d="M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z"></path>
1212
</svg>
1313
);
1414

15-
const Error: FC<ComponentProps<"svg">> = (props) => (
15+
const Error: FC<ComponentProps<'svg'>> = (props) => (
1616
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" {...props}>
1717
<path d="M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z"></path>
1818
</svg>
1919
);
2020

21-
const Info: FC<ComponentProps<"svg">> = (props) => (
21+
const Info: FC<ComponentProps<'svg'>> = (props) => (
2222
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" {...props}>
2323
<path d="M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z"></path>
2424
</svg>

library/src/main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { ToastProvider } from './providers/toast-provider';
22
export { useToast } from './hooks/toast-context';
3-
export * from './types/toast.types';
3+
export type { ToastProps, ToastProviderProperties } from './types/toast.types';

library/src/styles/toast-component.css

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080
.t_icon {
8181
fill: var(--text-color);
82+
margin-top: 0.1rem;
8283
}
8384

8485
.t_content {

0 commit comments

Comments
 (0)