'use client'; import * as React from 'react'; import { classNames } from '@vkontakte/vkjs'; import { callMultiple } from '../../lib/callMultiple'; import { defineComponentDisplayNames } from '../../lib/react/defineComponentDisplayNames'; import type { HTMLAttributesWithRootRef } from '../../types'; import { RootComponent } from '../RootComponent/RootComponent'; import { DropZoneGrid } from './components/DropZoneGrid'; import styles from './DropZone.module.css'; interface DropZonePropsChildrenProps { /** * Флаг активного состояния компонента. */ active: boolean; } export interface DropZoneProps extends Omit, 'children'> { /** * Содержимое компонента. Можно прокинуть функцию для отрисовки содержимого. */ children?: React.ReactNode | ((renderProps: DropZonePropsChildrenProps) => React.ReactNode); } /** * Компонент позволяет пользователям загружать файлы, перетаскивая файлы в * область на странице. * * @since 6.1.0 * @see https://vkui.io/components/drop-zone */ export const DropZone: React.FC & { Grid: typeof DropZoneGrid; } = ({ onDragOver, onDragLeave, onDrop, children, ...props }: DropZoneProps): React.ReactNode => { const [active, setActive] = React.useState(false); const onActive: React.DragEventHandler = (event) => { if (event.isPropagationStopped()) { return; } setActive(true); }; const offActive: React.DragEventHandler = () => { setActive(false); }; return ( {typeof children === 'function' ? children({ active }) : children} ); }; DropZone.Grid = DropZoneGrid; if (process.env.NODE_ENV !== 'production') { defineComponentDisplayNames(DropZone.Grid, 'DropZone.Grid'); }