♻️(react) extract typeToColor from AlertIcon

We will need to use the logic of this function in the Toast component.
This commit is contained in:
Nathan Vasse
2024-01-05 11:53:11 +01:00
committed by NathanVss
parent 6e4dd55f49
commit 83a533d245

View File

@@ -3,6 +3,7 @@ import classNames from "classnames";
import { Button } from ":/components/Button"; import { Button } from ":/components/Button";
import { AlertProps, AlertType } from ":/components/Alert/index"; import { AlertProps, AlertType } from ":/components/Alert/index";
import { useCunningham } from ":/components/Provider"; import { useCunningham } from ":/components/Provider";
import { ToastType } from ":/components/Toast/ToastProvider";
export const AlertWrapper = (props: AlertProps) => { export const AlertWrapper = (props: AlertProps) => {
return ( return (
@@ -21,8 +22,7 @@ export const AlertWrapper = (props: AlertProps) => {
); );
}; };
export const AlertIcon = ({ type, ...props }: AlertProps) => { export const iconFromType = (type?: AlertType | ToastType) => {
const icon = useMemo(() => {
switch (type) { switch (type) {
case AlertType.INFO: case AlertType.INFO:
return "info"; return "info";
@@ -35,7 +35,10 @@ export const AlertIcon = ({ type, ...props }: AlertProps) => {
default: default:
return ""; return "";
} }
}, [type]); };
export const AlertIcon = ({ type, ...props }: AlertProps) => {
const icon = useMemo(() => iconFromType(type), [type]);
if (props.icon) { if (props.icon) {
return props.icon; return props.icon;
} }
@@ -54,7 +57,6 @@ export const AlertClose = (props: AlertProps) => {
return ( return (
props.canClose && ( props.canClose && (
<Button <Button
className="ml-st"
color="tertiary" color="tertiary"
size="small" size="small"
icon={<span className="material-icons">close</span>} icon={<span className="material-icons">close</span>}