card.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use client";
  2. import { type ComponentRenderProps } from "@json-render/react";
  3. export function Card({ element, children }: ComponentRenderProps) {
  4. const { title, description, padding } = element.props as {
  5. title?: string | null;
  6. description?: string | null;
  7. padding?: string | null;
  8. };
  9. const paddings: Record<string, string> = {
  10. none: "0",
  11. sm: "12px",
  12. lg: "24px",
  13. };
  14. return (
  15. <div
  16. style={{
  17. background: "var(--card)",
  18. border: "1px solid var(--border)",
  19. borderRadius: "var(--radius)",
  20. }}
  21. >
  22. {(title || description) && (
  23. <div
  24. style={{
  25. padding: "16px 20px",
  26. borderBottom: "1px solid var(--border)",
  27. }}
  28. >
  29. {title && (
  30. <h3 style={{ margin: 0, fontSize: 16, fontWeight: 600 }}>
  31. {title}
  32. </h3>
  33. )}
  34. {description && (
  35. <p
  36. style={{ margin: "4px 0 0", fontSize: 14, color: "var(--muted)" }}
  37. >
  38. {description}
  39. </p>
  40. )}
  41. </div>
  42. )}
  43. <div style={{ padding: paddings[padding || ""] || "16px" }}>
  44. {children}
  45. </div>
  46. </div>
  47. );
  48. }