Замена wordpdf-cli на Spring Boot REST API: wordpdf-app, SPA wordpdf-web, docker-compose
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import type { DragEvent } from 'react'
|
||||
|
||||
interface Props {
|
||||
file: File | null
|
||||
disabled: boolean
|
||||
onSelect: (file: File) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Зона drag&drop + клик для выбора .docx. Скрытый input[type=file] —
|
||||
* единственный источник выбора; drop берёт первый файл.
|
||||
*/
|
||||
export default function DropZone({ file, disabled, onSelect }: Props) {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [dragging, setDragging] = useState(false)
|
||||
|
||||
const onDrop = (e: DragEvent<HTMLLabelElement>) => {
|
||||
e.preventDefault()
|
||||
setDragging(false)
|
||||
if (disabled) return
|
||||
const dropped = e.dataTransfer.files[0]
|
||||
if (dropped) onSelect(dropped)
|
||||
}
|
||||
|
||||
return (
|
||||
<label
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault()
|
||||
if (!disabled) setDragging(true)
|
||||
}}
|
||||
onDragLeave={(e) => {
|
||||
e.preventDefault()
|
||||
setDragging(false)
|
||||
}}
|
||||
onDrop={onDrop}
|
||||
className={`flex cursor-pointer flex-col items-center gap-3 rounded-xl border-2 border-dashed p-9 text-center transition-colors ${
|
||||
dragging
|
||||
? 'border-accent bg-accent/6'
|
||||
: 'border-border hover:border-accent hover:bg-accent/6'
|
||||
}`}
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className="h-9 w-9 text-accent"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M12 16V4m0 0-4 4m4-4 4 4" />
|
||||
<path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" />
|
||||
</svg>
|
||||
<span>Перетащите .docx сюда или нажмите для выбора</span>
|
||||
{file && (
|
||||
<span className="text-sm text-muted">
|
||||
{file.name} · {(file.size / 1024).toFixed(0)} КБ
|
||||
</span>
|
||||
)}
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept=".docx"
|
||||
className="sr-only"
|
||||
disabled={disabled}
|
||||
onChange={(e) => {
|
||||
const picked = e.target.files?.[0]
|
||||
if (picked) onSelect(picked)
|
||||
// сбрасываем value — иначе повторный выбор того же файла не событие
|
||||
e.target.value = ''
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user