import React, { useId } from 'react' import { X } from 'lucide-react' import Block from '../Primitives/Block/Block' import { FOUNDATION_THEME } from '../../tokens' import { AlertActionPlacement, type AlertProps, AlertStyle, AlertVariant, } from './types' import type { CSSObject } from 'styled-components' import type { AlertTokenType } from './alert.tokens' import Text from '../Text/Text' import { forwardRef } from 'react' import PrimitiveButton from '../Primitives/PrimitiveButton/PrimitiveButton' import { useResponsiveTokens } from '../../hooks/useResponsiveTokens' const Alert = forwardRef( ( { heading, description, variant = AlertVariant.PRIMARY, style = AlertStyle.SUBTLE, primaryAction, secondaryAction, onClose, icon, maxWidth, minWidth, width, actionPlacement = AlertActionPlacement.RIGHT, }, ref ) => { const alertTokens = useResponsiveTokens('ALERT') const shouldShowCloseAtBottom = onClose && primaryAction === undefined && secondaryAction === undefined const finalActionPlacement = shouldShowCloseAtBottom ? AlertActionPlacement.BOTTOM : actionPlacement const baseId = useId() const headingId = `${baseId}-heading` const descriptionId = `${baseId}-description` const isErrorOrWarning = variant === AlertVariant.ERROR || variant === AlertVariant.WARNING const alertRole = isErrorOrWarning ? 'alert' : 'status' return ( {icon && ( )} {heading && ( {heading} )} {description && ( {description} {(primaryAction || secondaryAction || onClose) && ( {(primaryAction || secondaryAction) && ( {primaryAction && ( { primaryAction.label } )} {secondaryAction && ( { secondaryAction.label } )} )} {onClose && finalActionPlacement === AlertActionPlacement.RIGHT && ( <> )} )} {onClose && finalActionPlacement === AlertActionPlacement.BOTTOM && ( )} ) } ) const AlertCloseButton = ({ $color, children, onClick, 'aria-label': ariaLabel, }: { $color: CSSObject['color'] children: React.ReactNode onClick: () => void 'aria-label'?: string }) => { return ( {children} ) } Alert.displayName = 'Alert' export default Alert