import React, { forwardRef, ReactElement, useId } from 'react' import { X } from 'lucide-react' import { AlertV2Props, AlertV2Type, AlertV2SubType, AlertV2Actions, AlertV2ActionPosition, AlertV2Action, } from './alertV2.types' import { useResponsiveTokens } from '../../hooks/useResponsiveTokens' import { AlertV2TokensType } from './alertV2.tokens' import Block from '../Primitives/Block/Block' import Text from '../Text/Text' import PrimitiveButton from '../Primitives/PrimitiveButton/PrimitiveButton' import { addPxToValue } from '../../global-utils/GlobalUtils' import { FOUNDATION_THEME } from '../../tokens' import Seperator from '../common/Seperator' import { filterBlockedProps } from '../../utils/prop-helpers' import { CSSObject } from 'styled-components' import { addAccessibleAriaAttributes } from '../../utils/accessibility/icon-helpers' const SlotContainer = ({ slot, alertV2Tokens, }: { slot?: { slot: ReactElement maxHeight?: CSSObject['maxHeight'] } alertV2Tokens: AlertV2TokensType }) => { if (!slot) return null const slotMaxHeight = slot?.maxHeight || alertV2Tokens.slot.maxHeight return ( {addAccessibleAriaAttributes(slot.slot)} ) } const ActionButton = ({ action, type, alertV2Tokens, variant, }: { action: AlertV2Action type: AlertV2Type alertV2Tokens: AlertV2TokensType variant: 'primaryAction' | 'secondaryAction' }) => { const actionTokens = alertV2Tokens.mainContainer.content.actionContainer[variant] const color = actionTokens.color[type] return ( {action.text} ) } const ActionsContainer = ({ actions, type, alertV2Tokens, }: { actions?: AlertV2Actions type: AlertV2Type alertV2Tokens: AlertV2TokensType }) => { if (!actions) return null return ( {actions.primaryAction && ( )} {actions.secondaryAction && ( )} ) } const TextContainer = ({ heading, description, type, alertV2Tokens, headingId, descriptionId, }: { heading?: string description?: string type: AlertV2Type alertV2Tokens: AlertV2TokensType headingId?: string descriptionId?: string }) => { if (!heading && !description) return null return ( {heading && ( {heading} )} {description && ( {description} )} ) } const CloseButton = ({ closeButton, type, alertV2Tokens, actionPlacementBottom, }: { closeButton?: { show?: boolean onClick?: (event: React.MouseEvent) => void } type: AlertV2Type alertV2Tokens: AlertV2TokensType actionPlacementBottom?: boolean }) => { if (!closeButton?.show) return null const closeButtonColor = alertV2Tokens.mainContainer.closeButton.color[type] return ( ) } const AlertV2 = forwardRef( ( { width, maxWidth, minWidth, type = AlertV2Type.PRIMARY, subType = AlertV2SubType.SUBTLE, slot, heading, description, actions, closeButton = { show: true, onClick: () => {}, }, ...rest }, ref ) => { const alertV2Tokens = useResponsiveTokens('ALERTV2') const filteredProps = filterBlockedProps(rest) const actionsPosition = actions?.position || AlertV2ActionPosition.BOTTOM const actionPlacementBottom = actionsPosition === AlertV2ActionPosition.BOTTOM const showSeparator = actionsPosition === AlertV2ActionPosition.RIGHT && closeButton.show const baseId = useId() const headingId = heading ? `${baseId}-heading` : undefined const descriptionId = description ? `${baseId}-description` : undefined return ( {showSeparator && ( )} ) } ) AlertV2.displayName = 'AlertV2' export default AlertV2