Spaces:
Running
Running
Download src/film/CopyPanel.tsx from Ethscriptions/tz: direct link, hf CLI and curl.
- Browser
- Download file 3.66 kB
-
https://huggingface.co/spaces/Ethscriptions/tz/resolve/main/src/film/CopyPanel.tsx
- Command line
-
hf download hf://spaces/Ethscriptions/tz/src/film/CopyPanel.tsx
-
curl -L -o CopyPanel.tsx https://huggingface.co/spaces/Ethscriptions/tz/resolve/main/src/film/CopyPanel.tsx
3.66 kB
| import { useState } from 'react' | |
| import { Check, Copy } from 'lucide-react' | |
| import { PLATFORMS, charLen, platformCopy, type PlatformKey } from '@/film/core/copy' | |
| import { quoteById } from '@/film/core/film' | |
| async function copyText(s: string) { | |
| try { | |
| await navigator.clipboard.writeText(s) | |
| return true | |
| } catch { | |
| const ta = document.createElement('textarea') | |
| ta.value = s | |
| ta.style.position = 'fixed' | |
| ta.style.opacity = '0' | |
| document.body.appendChild(ta) | |
| ta.select() | |
| const ok = document.execCommand('copy') | |
| ta.remove() | |
| return ok | |
| } | |
| } | |
| function CopyBtn({ text, label }: { text: string; label: string }) { | |
| const [ok, setOk] = useState(false) | |
| return ( | |
| <button | |
| onClick={async () => { if (await copyText(text)) { setOk(true); setTimeout(() => setOk(false), 1400) } }} | |
| className={`flex items-center gap-1 rounded px-2 py-1 text-[11px] ring-1 transition ${ok ? 'bg-emerald-500/20 text-emerald-300 ring-emerald-500/40' : 'text-white/70 ring-white/15 hover:bg-white/5'}`} | |
| > | |
| {ok ? <Check className="h-3 w-3" /> : <Copy className="h-3 w-3" />}{ok ? '已复制' : label} | |
| </button> | |
| ) | |
| } | |
| export default function CopyPanel({ id }: { id: number }) { | |
| const q = quoteById(id) | |
| const [tab, setTab] = useState<PlatformKey>('xhs') | |
| const p = PLATFORMS.find((x) => x.key === tab)! | |
| const c = platformCopy(id, q.text, tab) | |
| const tags = c.tags.map((t) => `#${t}`).join(' ') | |
| const tl = charLen(c.title) | |
| const all = `${c.title}\n\n${c.desc}\n\n${tags}` | |
| return ( | |
| <div className="space-y-3"> | |
| <div className="grid grid-cols-4 gap-1"> | |
| {PLATFORMS.map((x) => ( | |
| <button key={x.key} onClick={() => setTab(x.key)} className={`rounded-md px-1 py-2 text-[12px] ring-1 transition ${tab === x.key ? 'bg-white/10 text-white ring-white/30' : 'text-white/55 ring-white/10 hover:text-white/80'}`}> | |
| <span className="mr-1 inline-block h-1.5 w-1.5 rounded-full align-middle" style={{ background: x.color }} />{x.name} | |
| </button> | |
| ))} | |
| </div> | |
| <div className="rounded-lg bg-white/[0.03] p-3 ring-1 ring-white/10"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-[11px] text-white/45">标题 <span className={tl > p.titleMax ? 'text-red-400' : 'text-emerald-400'}>{tl}/{p.titleMax} 字</span></span> | |
| <CopyBtn text={c.title} label="复制标题" /> | |
| </div> | |
| <p className="mt-1.5 font-[OdbSerif] text-[15px] font-semibold leading-snug text-white">{c.title}</p> | |
| </div> | |
| <div className="rounded-lg bg-white/[0.03] p-3 ring-1 ring-white/10"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-[11px] text-white/45">描述</span> | |
| <CopyBtn text={c.desc} label="复制描述" /> | |
| </div> | |
| <p className="mt-1.5 whitespace-pre-wrap text-[13px] leading-relaxed text-white/80">{c.desc}</p> | |
| </div> | |
| <div className="rounded-lg bg-white/[0.03] p-3 ring-1 ring-white/10"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-[11px] text-white/45">话题 <span className="text-emerald-400">{c.tags.length}{p.tagMax ? `/${p.tagMax}` : ' 个(不限)'}</span></span> | |
| <CopyBtn text={tags} label="复制话题" /> | |
| </div> | |
| <div className="mt-2 flex flex-wrap gap-1.5"> | |
| {c.tags.map((t) => <span key={t} className="rounded-full bg-white/[0.06] px-2 py-0.5 text-[12px] text-[#F5C518]/90">#{t}</span>)} | |
| </div> | |
| </div> | |
| <div className="flex justify-end"><CopyBtn text={all} label="一键复制全部" /></div> | |
| </div> | |
| ) | |
| } | |