♻️(react) add colorFromType

This utils allows to give the appropriate color palette for each
AlertType | ToastType value.
This commit is contained in:
Nathan Vasse
2024-01-18 14:38:25 +01:00
committed by NathanVss
parent 3d4236c7bd
commit 81e4da1d36

View File

@@ -37,6 +37,21 @@ export const iconFromType = (type?: AlertType | ToastType) => {
}
};
export const colorFromType = (type?: AlertType | ToastType) => {
switch (type) {
case AlertType.INFO:
return "info";
case AlertType.SUCCESS:
return "success";
case AlertType.WARNING:
return "warning";
case AlertType.ERROR:
return "danger";
default:
return "neutral";
}
};
export const AlertIcon = ({ type, ...props }: AlertProps) => {
const icon = useMemo(() => iconFromType(type), [type]);
if (props.icon) {