rating.tsx 890 B

12345678910111213141516171819202122232425262728293031
  1. "use client";
  2. import type { ComponentRenderProps } from "./types";
  3. import { baseClass, getCustomClass } from "./utils";
  4. export function Rating({ element }: ComponentRenderProps) {
  5. const { props } = element;
  6. const customClass = getCustomClass(props);
  7. const ratingValue = (props.value as number) || 0;
  8. const maxRating = (props.max as number) || 5;
  9. return (
  10. <div className={`${baseClass} ${customClass}`}>
  11. {props.label ? (
  12. <div className="text-[10px] text-muted-foreground mb-1 text-left">
  13. {props.label as string}
  14. </div>
  15. ) : null}
  16. <div className="flex gap-0.5">
  17. {Array.from({ length: maxRating }).map((_, i) => (
  18. <span
  19. key={i}
  20. className={`text-sm ${i < ratingValue ? "text-yellow-400" : "text-muted"}`}
  21. >
  22. *
  23. </span>
  24. ))}
  25. </div>
  26. </div>
  27. );
  28. }