-
Notifications
You must be signed in to change notification settings - Fork 25
added copy for ai button #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dqnamo
wants to merge
2
commits into
cossistantcom:main
Choose a base branch
from
dqnamo:adding-copy-ai-prompt-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| "use client"; | ||
|
|
||
| import { Check, Copy } from "lucide-react"; | ||
| import { useState } from "react"; | ||
|
|
||
| const MARKDOWN = `You are helping implement Facehash avatars in a React/Next.js project. | ||
|
|
||
| ## What is Facehash? | ||
| A React component that generates unique, deterministic avatar faces from any string (emails, usernames, UUIDs). Zero dependencies, works offline, accessible by default. | ||
|
|
||
| Key behavior: same input = same face, always. No API calls, no storage, no randomness. | ||
|
|
||
| ## Installation | ||
| \`\`\`bash | ||
| npm install facehash | ||
| \`\`\` | ||
|
|
||
| ## Basic Usage | ||
| \`\`\`tsx | ||
| import { Facehash } from "facehash"; | ||
|
|
||
| // Pass any string - emails, usernames, IDs all work | ||
| <Facehash name="user@example.com" size={48} /> | ||
| \`\`\` | ||
|
|
||
| ## Available Props | ||
| - \`name\` (string, required): Input string that determines the face | ||
| - \`size\` (number, default: 40): Avatar size in pixels | ||
| - \`colors\` (string[]): Custom color palette, e.g. \`["#264653", "#2a9d8f", "#e9c46a"]\` | ||
| - \`intensity3d\` ("none" | "subtle" | "medium" | "dramatic"): 3D effect intensity, default "dramatic" | ||
| - \`showInitial\` (boolean, default: true): Show first letter on face | ||
| - \`variant\` ("gradient" | "solid"): Background style, default "gradient" | ||
| - \`enableBlink\` (boolean): Enable blinking animation | ||
| - \`onRenderMouth\` (() => ReactNode): Custom mouth renderer (e.g., for loading spinners) | ||
| - \`className\` (string): CSS classes - controls face color via \`text-*\` and font styles | ||
|
|
||
| ## Next.js Image Route Handler | ||
| For generating avatar URLs (useful for emails, OG images, external services): | ||
|
|
||
| \`\`\`ts | ||
| // app/api/avatar/route.ts | ||
| import { toFacehashHandler } from "facehash/next"; | ||
|
|
||
| export const { GET } = toFacehashHandler(); | ||
| \`\`\` | ||
|
|
||
| Then use as: \`<img src="/api/avatar?name=john" />\` or \`https://yoursite.com/api/avatar?name=john\` | ||
|
|
||
| ## Avatar with Image Fallback | ||
| When you need to show a user photo with Facehash as fallback: | ||
|
|
||
| \`\`\`tsx | ||
| import { Avatar, AvatarImage, AvatarFallback } from "facehash"; | ||
|
|
||
| <Avatar> | ||
| <AvatarImage src={user.photoUrl} /> | ||
| <AvatarFallback name={user.email} /> | ||
| </Avatar> | ||
| \`\`\` | ||
|
|
||
| ## Implementation Guidelines | ||
| 1. Replace existing avatar placeholders or boring initials with Facehash | ||
| 2. Use the user's email, username, or ID as the \`name\` prop for consistency | ||
| 3. Match the \`size\` prop to the existing avatar dimensions | ||
| 4. For dark backgrounds, add \`className="text-white"\` for better contrast | ||
| 5. If the project uses Next.js and needs avatar URLs, add the route handler | ||
| `; | ||
|
|
||
| export function CopyAiPromptButton() { | ||
| const [copied, setCopied] = useState(false); | ||
|
|
||
| const handleCopy = async () => { | ||
| await navigator.clipboard.writeText(MARKDOWN); | ||
| setCopied(true); | ||
| setTimeout(() => setCopied(false), 2000); | ||
| }; | ||
|
Comment on lines
+72
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Timeout set after unmount |
||
|
|
||
| return ( | ||
| <button | ||
| className="inline-flex items-center gap-2 px-2 py-1 text-[var(--muted-foreground)] text-xs transition-colors hover:bg-[var(--border)] hover:text-[var(--foreground)]" | ||
| onClick={handleCopy} | ||
| title="Copy AI prompt" | ||
| type="button" | ||
| > | ||
| {copied ? ( | ||
| <Check className="h-3.5 w-3.5 text-green-500" /> | ||
| ) : ( | ||
| <Copy className="h-3.5 w-3.5" /> | ||
| )} | ||
| <span>copy ai prompt</span> | ||
| </button> | ||
| ); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled clipboard failure
navigator.clipboard.writeTextcan throw (e.g., non-secure context, denied permission, unsupported API). Since the handler doesn’t catch errors, clicking the button can produce an unhandled promise rejection and still schedules state changes. Consider wrapping the copy in a try/catch and only togglingcopiedon success (optionally provide a fallback message).