ToastDisplay.tsx 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { memo } from "react"
  2. import { Text, Box } from "ink"
  3. import * as theme from "../theme.js"
  4. import type { Toast, ToastType } from "../hooks/useToast.js"
  5. interface ToastDisplayProps {
  6. toast: Toast | null
  7. }
  8. function getToastColor(type: ToastType): string {
  9. switch (type) {
  10. case "success":
  11. return theme.successColor
  12. case "warning":
  13. return theme.warningColor
  14. case "error":
  15. return theme.errorColor
  16. case "info":
  17. default:
  18. return theme.focusColor // cyan for info
  19. }
  20. }
  21. function getToastIcon(type: ToastType): string {
  22. switch (type) {
  23. case "success":
  24. return "✓"
  25. case "warning":
  26. return "⚠"
  27. case "error":
  28. return "✗"
  29. case "info":
  30. default:
  31. return "ℹ"
  32. }
  33. }
  34. function ToastDisplay({ toast }: ToastDisplayProps) {
  35. if (!toast) {
  36. return null
  37. }
  38. const color = getToastColor(toast.type)
  39. const icon = getToastIcon(toast.type)
  40. return (
  41. <Box>
  42. <Text color={color}>
  43. {icon} {toast.message}
  44. </Text>
  45. </Box>
  46. )
  47. }
  48. export default memo(ToastDisplay)