Components
FileImporter
FileImporter presents a button-backed file picker and forwards selected files to your app.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { useState } from 'react';
import { Text } from '@swiftuijs/ui';
import { VStack } from '@swiftuijs/ui';
import { FileImporter } from '@swiftuijs/ui';
function DemoFileImporter() {
const [value, setValue] = useState('No file selected');
return (<VStack spacing={12}>
<FileImporter onSelect={(files) => setValue(files.map((file) => file.name).join(', '))}>
Import file
</FileImporter>
<Text>{value}</Text>
</VStack>);
}
export default function Example() {
return (<DemoFileImporter />);
}Usage and limitations
allowedContentTypesandallowsMultipleSelectionare the preferred SwiftUI-aligned props.- The hidden input is reset after each selection so the same file can be chosen again in a subsequent import flow.
More examples
Multiple Selection
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
accept | string | No | Accepted file types. |
allowedContentTypes | string[] | No | SwiftUI-aligned alias for accepted file types. |
multiple | boolean | No | Whether multiple files can be selected. Default: false |
allowsMultipleSelection | boolean | No | SwiftUI-aligned alias for multiple selection. Default: false |
onSelect | (files: Array<globalThis.File>) => void | Yes | Called with the selected files. |
Inherits additional props from Omit<IBaseElementComponent<'button'>, 'type' | 'onSelect'>.