
package.dist.components.file-upload.use-file-upload.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.
The newest version!
'use client';
import * as fileUpload from '@zag-js/file-upload';
import { useMachine, normalizeProps } from '@zag-js/react';
import { useId } from 'react';
import { useEnvironmentContext } from '../../providers/environment/use-environment-context.js';
import { useLocaleContext } from '../../providers/locale/use-locale-context.js';
import { useEvent } from '../../utils/use-event.js';
import { useFieldContext } from '../field/use-field-context.js';
const useFileUpload = (props = {}) => {
const { getRootNode } = useEnvironmentContext();
const { dir } = useLocaleContext();
const field = useFieldContext();
const initialContext = {
id: useId(),
ids: {
label: field?.ids.label,
hiddenInput: field?.ids.control
},
dir,
disabled: field?.disabled,
required: field?.required,
invalid: field?.invalid,
getRootNode,
...props
};
const context = {
...initialContext,
onFileAccept: useEvent(props.onFileAccept),
onFileReject: useEvent(props.onFileReject),
onFileChange: useEvent(props.onFileChange, { sync: true })
};
const [state, send] = useMachine(fileUpload.machine(initialContext), { context });
return fileUpload.connect(state, send, normalizeProps);
};
export { useFileUpload };
© 2015 - 2025 Weber Informatics LLC | Privacy Policy