|
| 1 | +export default function CopyPage({ file }: { file: string | undefined }) { |
| 2 | + if (!file || file.includes("[")) return null; |
| 3 | + |
| 4 | + const markdownUrl = `https://docs.deno.com${file}`; |
| 5 | + const claudeUrl = `https://claude.ai/new?q=${ |
| 6 | + encodeURIComponent( |
| 7 | + `Read this page from the Deno docs: ${markdownUrl} and answer questions about the content.`, |
| 8 | + ) |
| 9 | + }`; |
| 10 | + |
| 11 | + return ( |
| 12 | + <div class="copy-page-split inline-flex shrink-0 rounded-full border-2 border-foreground-primary dark:border-background-tertiary"> |
| 13 | + {/* Primary: directly copies the URL */} |
| 14 | + <button |
| 15 | + type="button" |
| 16 | + class="copy-page-main-btn flex items-center gap-2 px-4 py-2 text-sm font-semibold text-foreground-primary bg-transparent hover:bg-header-highlight dark:hover:text-background-primary rounded-l-full transition-colors cursor-pointer select-none" |
| 17 | + > |
| 18 | + <svg |
| 19 | + xmlns="http://www.w3.org/2000/svg" |
| 20 | + aria-hidden="true" |
| 21 | + fill="currentColor" |
| 22 | + width="12" |
| 23 | + height="12" |
| 24 | + viewBox="0 0 16 16" |
| 25 | + > |
| 26 | + <path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z" /> |
| 27 | + <path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z" /> |
| 28 | + </svg> |
| 29 | + <span class="copy-page-main-label">Copy page</span> |
| 30 | + </button> |
| 31 | + |
| 32 | + {/* Visual divider between the two halves */} |
| 33 | + <span |
| 34 | + class="self-stretch w-0.5 bg-foreground-primary dark:bg-background-tertiary shrink-0" |
| 35 | + aria-hidden="true" |
| 36 | + > |
| 37 | + </span> |
| 38 | + |
| 39 | + {/* Chevron: opens the popover panel */} |
| 40 | + <button |
| 41 | + type="button" |
| 42 | + class="copy-page-toggle-btn flex items-center px-3 py-2 text-foreground-primary bg-transparent hover:bg-header-highlight dark:hover:text-background-primary rounded-r-full transition-colors cursor-pointer select-none" |
| 43 | + popovertarget="copy-page-menu" |
| 44 | + aria-label="More copy options" |
| 45 | + aria-haspopup="menu" |
| 46 | + > |
| 47 | + <svg |
| 48 | + class="copy-page-chevron transition-transform duration-200" |
| 49 | + xmlns="http://www.w3.org/2000/svg" |
| 50 | + aria-hidden="true" |
| 51 | + fill="currentColor" |
| 52 | + width="12" |
| 53 | + height="12" |
| 54 | + viewBox="0 0 16 16" |
| 55 | + > |
| 56 | + <path d="M12.78 5.22a.749.749 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.06 0L3.22 6.28a.749.749 0 1 1 1.06-1.06L8 8.939l3.72-3.719a.749.749 0 0 1 1.06 0Z" /> |
| 57 | + </svg> |
| 58 | + </button> |
| 59 | + |
| 60 | + {/* Popover panel — lives in top layer, positioned via JS */} |
| 61 | + <div id="copy-page-menu" popover="auto" class="copy-page-panel"> |
| 62 | + <a |
| 63 | + href={file} |
| 64 | + target="_blank" |
| 65 | + class="no-underline flex items-start gap-3 px-4 py-3 hover:bg-background-secondary dark:hover:bg-gray-800 transition-colors" |
| 66 | + > |
| 67 | + <svg |
| 68 | + xmlns="http://www.w3.org/2000/svg" |
| 69 | + aria-hidden="true" |
| 70 | + fill="currentColor" |
| 71 | + width="16" |
| 72 | + height="16" |
| 73 | + viewBox="0 0 16 16" |
| 74 | + class="mt-0.5 shrink-0" |
| 75 | + > |
| 76 | + <path d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z" /> |
| 77 | + </svg> |
| 78 | + <span> |
| 79 | + <span class="block text-sm font-medium">View Page as Markdown</span> |
| 80 | + <span class="block text-xs text-foreground-secondary mt-0.5"> |
| 81 | + Open the Markdown file in a new tab |
| 82 | + </span> |
| 83 | + </span> |
| 84 | + </a> |
| 85 | + <a |
| 86 | + href={claudeUrl} |
| 87 | + target="_blank" |
| 88 | + class="no-underline flex items-start gap-3 px-4 py-3 border-t border-foreground-tertiary hover:bg-background-secondary dark:hover:bg-gray-800 transition-colors" |
| 89 | + > |
| 90 | + <svg |
| 91 | + xmlns="http://www.w3.org/2000/svg" |
| 92 | + aria-hidden="true" |
| 93 | + fill="currentColor" |
| 94 | + width="16" |
| 95 | + height="16" |
| 96 | + viewBox="0 0 24 24" |
| 97 | + class="mt-0.5 shrink-0" |
| 98 | + > |
| 99 | + <path d="M12 0C12 0 10.5 10.5 0 12C10.5 12 12 24 12 24C12 24 13.5 13.5 24 12C13.5 12 12 0 12 0Z" /> |
| 100 | + </svg> |
| 101 | + <span> |
| 102 | + <span class="block text-sm font-medium">Open in Claude</span> |
| 103 | + <span class="block text-xs text-foreground-secondary mt-0.5"> |
| 104 | + Ask Claude about this page |
| 105 | + </span> |
| 106 | + </span> |
| 107 | + </a> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + ); |
| 111 | +} |
0 commit comments