commit.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use client";
  2. import {
  3. Commit,
  4. CommitActions,
  5. CommitAuthor,
  6. CommitAuthorAvatar,
  7. CommitContent,
  8. CommitCopyButton,
  9. CommitFile,
  10. CommitFileAdditions,
  11. CommitFileChanges,
  12. CommitFileDeletions,
  13. CommitFileIcon,
  14. CommitFileInfo,
  15. CommitFilePath,
  16. CommitFileStatus,
  17. CommitFiles,
  18. CommitHash,
  19. CommitHeader,
  20. CommitInfo,
  21. CommitMessage,
  22. CommitMetadata,
  23. CommitSeparator,
  24. CommitTimestamp,
  25. } from "@/components/ai-elements/commit";
  26. const handleCopy = () => {
  27. console.log("Copied hash!");
  28. };
  29. const hash = "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0";
  30. const timestamp = new Date(Date.now() - 1000 * 60 * 60 * 2);
  31. const files = [
  32. {
  33. additions: 150,
  34. deletions: 0,
  35. path: "src/auth/login.tsx",
  36. status: "added" as const,
  37. },
  38. {
  39. additions: 45,
  40. deletions: 0,
  41. path: "src/auth/logout.tsx",
  42. status: "added" as const,
  43. },
  44. {
  45. additions: 23,
  46. deletions: 8,
  47. path: "src/lib/session.ts",
  48. status: "modified" as const,
  49. },
  50. ];
  51. const Example = () => (
  52. <Commit>
  53. <CommitHeader>
  54. <CommitAuthor>
  55. <CommitAuthorAvatar initials="HB" />
  56. </CommitAuthor>
  57. <CommitInfo>
  58. <CommitMessage>feat: Add user authentication flow</CommitMessage>
  59. <CommitMetadata>
  60. <CommitHash>{hash.slice(0, 7)}</CommitHash>
  61. <CommitSeparator />
  62. <CommitTimestamp date={timestamp} />
  63. </CommitMetadata>
  64. </CommitInfo>
  65. <CommitActions>
  66. <CommitCopyButton hash={hash} onCopy={handleCopy} />
  67. </CommitActions>
  68. </CommitHeader>
  69. <CommitContent>
  70. <CommitFiles>
  71. {files.map((file) => (
  72. <CommitFile key={file.path}>
  73. <CommitFileInfo>
  74. <CommitFileStatus status={file.status} />
  75. <CommitFileIcon />
  76. <CommitFilePath>{file.path}</CommitFilePath>
  77. </CommitFileInfo>
  78. <CommitFileChanges>
  79. <CommitFileAdditions count={file.additions} />
  80. <CommitFileDeletions count={file.deletions} />
  81. </CommitFileChanges>
  82. </CommitFile>
  83. ))}
  84. </CommitFiles>
  85. </CommitContent>
  86. </Commit>
  87. );
  88. export default Example;