Import
<smart-import> is a button with an upload icon and a hidden file input. Clicking it opens the native file dialog; the chosen file is emitted through the set output.
The input is cleared after every pick, so choosing the same file again emits it again. accept filters the dialog (application/json by default). Reading and parsing the file is up to you. The component renders a <smart-button>, so it follows whatever button implementation is registered through BUTTON_STANDARD_COMPONENT_TOKEN. It has no injection token of its own: for a different control, extend ImportBaseComponent. <smart-export> is the matching download button, for a download / upload round trip.
Usage
<smart-import [accept]="accept" (set)="onImport($event)" />
@if (importedFile(); as fileName) {
<p>Imported: {{ fileName }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
ImportComponent (<smart-import>)
Renders a <smart-button> with a projected upload icon next to a hidden <input type="file">, both inside a <span> that takes class. The button click forwards to the input through triggerFileInput, and the input's change event goes through ImportBaseComponent.onFileSelected. As with <smart-export>, a button implementation registered through BUTTON_STANDARD_COMPONENT_TOKEN receives the projected icon in its default <ng-content> slot. Unlike <smart-export>, the icon has no text alternative, so the button has no accessible name; for a labelled control, extend ImportBaseComponent.
ImportBaseComponent (abstract)
The base directive. onFileSelected(event) reads the first selected file, clears the input so the same file can be chosen again, and emits it through set; it throws ImportBaseComponent: File not found when the change event carries no file. triggerFileInput(inputEl) opens the dialog. Extend it to change the markup while keeping the behaviour. There is no token to register a subclass under, so a custom import control is rendered by its own selector.
| Member | Type | Description |
|---|---|---|
onFileSelected(event) | (event: Event) => void | The change handler of the file input: emits its first file through set and clears it. |
triggerFileInput(inputEl) | (inputEl: HTMLInputElement) => void | Opens the native file dialog of inputEl (calls its click()). |
cssClass | InputSignal<string> | The class input under its property name; bind it on the element your template renders. |
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
accept | InputSignal<string | undefined> | 'application/json' | Value of the accept attribute on the hidden file input; filters the native dialog. Binding undefined keeps application/json. |
class | InputSignal<string> | '' | Classes on a <span> around the button and the hidden file input (cssClass input, alias class). |
Outputs
| Output | Type | Description |
|---|---|---|
set | OutputEmitterRef<File> | Emits the selected File once per dialog confirmation |
Source
The component lives in packages/shared/angular/src/lib/components/import and is documented for Claude Code by the angular-components-import skill.
SmartImport is an upload-icon button that opens a hidden <input type="file">; the picked File is passed to onSet, and the input is cleared so the same file can be picked again. accept limits the file types (application/json by default). Reading and parsing the file is up to you. It renders through SmartButton, so it follows the button registry key.
Usage
import { useState } from 'react';
import { SmartImport } from '@smartsoft001/react';
export function ImportUsageExample() {
const [importedFile, setImportedFile] = useState<string | null>(null);
// Receives the picked File: read and parse it here.
const onImport = (file: File) => setImportedFile(file.name);
return (
<>
<SmartImport accept="text/csv" onSet={onImport} />
{importedFile && <p>Imported: {importedFile}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartImport | component | An upload-icon SmartButton that opens a hidden file input and passes the picked file to onSet. |
useImport | hook | The import button's logic: onFileSelected hands the picked file to onSet and clears the input, so picking the same file again fires change again; triggerFileInput opens the picker of inputEl. |
Props and Types
SmartImportProps
| Prop | Type | Default | Description |
|---|---|---|---|
accept? | string | 'application/json' | The file types the picker offers (application/json by default). |
className? | string | — | Extra CSS classes applied to the <span> around the button. |
onSet? | (file: File) => void | — | Called with the picked file. |
Replacing the Implementation
SmartImport has no registry key of its own: it renders a SmartButton, so registering a component under the button key restyles it too. For a different control, build one on useImport.
The useImport hook
The import button's logic: onFileSelected hands the picked file to onSet and clears the input, so picking the same file again fires change again; triggerFileInput opens the picker of inputEl.
| Returns | Type | Description |
|---|---|---|
inputRef | RefObject<HTMLInputElement | null> | Attach to the hidden file input. |
onFileSelected | (event: { target: HTMLInputElement; }) => void | The input's change handler: passes the first file to onSet and clears the input. |
triggerFileInput | (inputEl: HTMLInputElement) => void | Opens the file picker of an input element. |
Styling
classNamegoes on the<span>around the button and the input.
Source
The component lives in packages/shared/react/src/lib/components/import and is documented for Claude Code by the react-components-import skill.