import type { AlertDescriptionProps } from '@chakra-ui/react'; import { Alert as ChakraAlert, Icon } from '@chakra-ui/react'; import * as React from 'react'; import IndicatorIcon from 'icons/info_filled.svg'; import { CloseButton } from './close-button'; import { Skeleton } from './skeleton'; export interface AlertProps extends Omit { startElement?: React.ReactNode; endElement?: React.ReactNode; descriptionProps?: AlertDescriptionProps; title?: React.ReactNode; icon?: React.ReactElement; closable?: boolean; onClose?: () => void; loading?: boolean; showIcon?: boolean; } export const Alert = React.forwardRef( function Alert(props, ref) { const { title, children, icon, closable, onClose, startElement, endElement, loading, size, showIcon = false, descriptionProps, ...rest } = props; const [ isOpen, setIsOpen ] = React.useState(true); const defaultIcon = ; const iconElement = (() => { if (startElement !== undefined) { return startElement; } if (!showIcon && icon === undefined) { return null; } return { icon || defaultIcon }; })(); const handleClose = React.useCallback(() => { setIsOpen(false); onClose?.(); }, [ onClose ]); if (closable && !isOpen) { return null; } return ( { iconElement } { children ? ( { title && { title } } { children } ) : ( { title } ) } { endElement } { closable && ( ) } ); }, );