/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import {
EuiCallOut,
EuiSpacer,
EuiFlexGroup,
EuiFlexItem,
EuiButtonIcon,
EuiLoadingSpinner,
} from '@elastic/eui';
export type TCalloutColor = 'primary' | 'success' | 'warning' | 'danger';
export type TCalloutIcon = 'iInCircle' | 'check' | 'help' | 'alert';
interface ICalloutType {
color: TCalloutColor;
iconType: TCalloutIcon;
}
export interface ICalloutProps {
title: string | JSX.Element;
message?: string | JSX.Element;
type?: ICalloutType | TCalloutColor;
closable?: boolean;
loading?: boolean;
closeHandler?: (callout?: ICalloutProps) => void;
}
export const toastTypes: {
[Key in TCalloutColor]: TCalloutIcon;
} = {
primary: 'iInCircle',
success: 'check',
warning: 'help',
danger: 'alert',
};
export const resolveType = (type?: ICalloutType | TCalloutColor): ICalloutType => {
if (type === undefined) {
return {
color: 'primary',
iconType: 'iInCircle',
};
} else {
if (typeof type === 'string') {
return {
color: type,
iconType: toastTypes[type],
};
} else {
return type;
}
}
};
export const CallOut = ({
title,
message,
type,
closable = true,
loading = false,
closeHandler,
}: ICalloutProps) => {
const closeCallout = () => closeHandler && closeHandler(undefined);
const getTitle = (): JSX.Element => {
return (
{loading && (
)}
{title}
{closable && (
closeCallout()} iconType="cross" aria-label="Close" />
)}
);
};
const { color, iconType } = resolveType(type);
return (
<>
{message}
>
);
};
export default CallOut;