// // Copyright 2023 DXOS.org // import * as ToastPrimitive from '@radix-ui/react-toast'; import React, { type ComponentPropsWithRef, forwardRef } from 'react'; import { useTranslation } from 'react-i18next'; import { translationKey } from '#translations'; import { useThemeContext } from '../../hooks'; import { DensityProvider, ElevationProvider } from '../../primitives'; import { type ThemedClassName } from '../../util'; import { IconButton } from '../Button'; import { Column } from '../Column'; import { Icon } from '../Icon'; // // Provider // type ToastProviderProps = ToastPrimitive.ToastProviderProps; const ToastProvider = ToastPrimitive.Provider; // // Viewport // type ToastViewportProps = ThemedClassName; const ToastViewport = forwardRef(({ classNames, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ; }); ToastViewport.displayName = 'Toast.Viewport'; // // Root // type ToastRootProps = ThemedClassName; const ToastRoot = forwardRef(({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }); ToastRoot.displayName = 'Toast.Root'; // // Title // type ToastTitleProps = ThemedClassName & { icon?: string; onClose?: () => void; }; const ToastTitle = forwardRef( ({ classNames, children, icon, onClose, ...props }, forwardedRef) => { const { t } = useTranslation(translationKey); const { tx } = useThemeContext(); return ( {icon && ( )} {children} {onClose && ( )} ); }, ); ToastTitle.displayName = 'Toast.Title'; // // Description // type ToastDescriptionProps = ThemedClassName; const ToastDescription = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); ToastDescription.displayName = 'Toast.Description'; // // Actions // type ToastActionsProps = ThemedClassName>; const ToastActions = forwardRef( ({ classNames, children, ...props }, forwardedRef) => { const { tx } = useThemeContext(); return ( {children} ); }, ); ToastActions.displayName = 'Toast.Actions'; // // Action / Close // type ToastActionProps = ToastPrimitive.ToastActionProps; const ToastAction = ToastPrimitive.Action; type ToastCloseProps = ToastPrimitive.ToastCloseProps; const ToastClose = ToastPrimitive.Close; // // Toast // export const Toast = { Provider: ToastProvider, Viewport: ToastViewport, Root: ToastRoot, Title: ToastTitle, Description: ToastDescription, Actions: ToastActions, Action: ToastAction, Close: ToastClose, }; export type { ToastActionProps, ToastActionsProps, ToastCloseProps, ToastDescriptionProps, ToastProviderProps, ToastRootProps, ToastTitleProps, ToastViewportProps, };