mirror of
https://git.zhongyuan.online/ytke/tap.git
synced 2026-11-24 22:15:18 -08:00
18 lines
1.7 KiB
TypeScript
18 lines
1.7 KiB
TypeScript
'use client';
|
|||
|
|
import { useRef, useState } from 'react';
|
||
|
|
import { BookOpen, Download, ExternalLink } from 'lucide-react';
|
||
|
|
import { FEISHU_TEMPLATE_DIRECTORY, findDocument, templateDownloadUrl, type DocumentId } from '@/lib/documents';
|
||
|
|
import TemplatePreview from './template-preview';
|
||
|
|
|
||
|
|
export type OpenTemplatePreview = (id: DocumentId, trigger: HTMLButtonElement) => void;
|
||
|
|
|
||
|
|
export function TemplateActions({ documentId, disabled = false, showDirectory = true, onPreview }: { documentId: DocumentId; disabled?: boolean; showDirectory?: boolean; onPreview?: OpenTemplatePreview }) {
|
||
|
|
const [open, setOpen] = useState(false);
|
||
|
|
const trigger = useRef<HTMLButtonElement>(null);
|
||
|
|
const document = findDocument(documentId)!;
|
||
|
|
return <><span className="template-actions">
|
||
|
|
<button ref={trigger} className="text-button" type="button" disabled={disabled} onClick={event => { if (onPreview) onPreview(documentId, event.currentTarget); else setOpen(true); }} aria-label={'查看' + document.title}><BookOpen size={14}/>{documentId==='sop'?'查看规范':'查看模板'}</button>
|
||
|
|
<a className="text-button" href={disabled ? undefined : templateDownloadUrl(documentId)} aria-disabled={disabled || undefined} tabIndex={disabled ? -1 : undefined} download aria-label={'下载' + document.title + ' Word 版'}><Download size={14}/>{documentId==='sop'?'下载规范':'下载模板'}</a>
|
||
|
|
{showDirectory && <a className="text-button" href={disabled ? undefined : FEISHU_TEMPLATE_DIRECTORY} aria-disabled={disabled || undefined} tabIndex={disabled ? -1 : undefined} target="_blank" rel="noopener noreferrer"><ExternalLink size={14}/>飞书总目录</a>}
|
||
|
|
</span>{open && <TemplatePreview documentId={documentId} onClose={() => setOpen(false)} returnFocus={trigger}/>}</>;
|
||
|
|
}
|