FormFooterChangeBadge.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { AnimatePresence, motion } from 'framer-motion'
  2. interface FormFooterChangeBadgeProps {
  3. formState: {
  4. dirtyFields: Record<string, boolean>
  5. }
  6. }
  7. export const FormFooterChangeBadge = ({ formState }: FormFooterChangeBadgeProps) => {
  8. return (
  9. <AnimatePresence mode="wait">
  10. {Object.keys(formState.dirtyFields).length > 0 && (
  11. <motion.div
  12. initial={{ opacity: 0, scale: 0.9 }}
  13. animate={{ opacity: 1, scale: 1 }}
  14. exit={{ opacity: 0, scale: 0.9 }}
  15. transition={{ duration: 0.2 }}
  16. >
  17. <motion.div
  18. animate={{
  19. scale: [1, 1.05, 1],
  20. transition: { duration: 0.3 },
  21. }}
  22. >
  23. <p className="text-sm text-foreground-lighter">
  24. <motion.span
  25. key={Object.keys(formState.dirtyFields).length}
  26. initial={{ opacity: 0, scale: 0.9 }}
  27. animate={{ opacity: 1, scale: 1 }}
  28. exit={{ opacity: 0, scale: 0.9 }}
  29. transition={{ duration: 0.1 }}
  30. >
  31. {Object.keys(formState.dirtyFields).length === 1
  32. ? '1 change to review'
  33. : `${Object.keys(formState.dirtyFields).length} changes to review`}
  34. </motion.span>
  35. </p>
  36. </motion.div>
  37. </motion.div>
  38. )}
  39. </AnimatePresence>
  40. )
  41. }