NapCatQQ/packages/napcat-webui-frontend/src/components/input/image_input.tsx
手瓜一十雪 84f0e0f9a0 Refactor UI for network cards and improve theming
Redesigned network display cards and related components for a more modern, consistent look, including improved button styles, card layouts, and responsive design. Added support for background images and dynamic theming across cards, tables, and log views. Enhanced input and select components with unified styling. Improved file table responsiveness and log display usability. Refactored OneBot API debug and navigation UI for better usability and mobile support.
2025-12-22 12:27:56 +08:00

62 lines
1.7 KiB
TypeScript

import { Button } from '@heroui/button';
import { Image } from '@heroui/image';
import { Input } from '@heroui/input';
import { useRef } from 'react';
export interface ImageInputProps {
onChange: (base64: string) => void;
value: string;
label?: string;
}
const ImageInput: React.FC<ImageInputProps> = ({ onChange, value, label }) => {
const inputRef = useRef<HTMLInputElement>(null);
return (
<div className='flex items-end gap-2'>
<div className='w-5 h-5 flex-shrink-0'>
<Image
src={value}
alt={label}
className='w-5 h-5 flex-shrink-0 rounded-none'
/>
</div>
<Input
ref={inputRef}
label={label}
type='file'
placeholder='选择图片'
accept='image/*'
classNames={{
inputWrapper:
'bg-default-100/50 dark:bg-white/5 backdrop-blur-md border border-transparent hover:bg-default-200/50 dark:hover:bg-white/10 transition-all shadow-sm data-[hover=true]:border-default-300',
input: 'bg-transparent text-default-700 placeholder:text-default-400',
}}
onChange={async (e) => {
const file = e.target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = async () => {
const base64 = reader.result as string;
onChange(base64);
};
reader.readAsDataURL(file);
}
}}
/>
<Button
onPress={() => {
onChange('');
if (inputRef.current) inputRef.current.value = '';
}}
color='primary'
variant='flat'
size='sm'
>
</Button>
</div>
);
};
export default ImageInput;