Export

<smart-export> is a button with a download icon. Bind the data to export and a handler; the button stays disabled until there is a value and calls the handler with it, and the file name, on click.

The handler serialises the data and starts the download, so the format is yours (JSON, CSV, ...). 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 ExportBaseComponent. <smart-import> is the matching upload button, for a download / upload round trip.


Usage

<smart-export [value]="orders" [fileName]="fileName" [handler]="exportOrders" />
@if (exported(); as orders) {
  <p>Exported {{ orders.length }} orders as {{ exportedFileName() }}</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

ExportComponent (<smart-export>)

Renders a <smart-button> with a projected download icon, disabled while value is falsy, and passes class to it. The icon is hidden from assistive technology and a visually hidden "Export" label gives the button its accessible name. It extends ExportBaseComponent, which owns the inputs and the click logic. The icon is projected content, so a button implementation registered through BUTTON_STANDARD_COMPONENT_TOKEN in the same injector (the button preset that provideSmartPresets() registers, or your own) renders it too, in its default <ng-content> slot.

ExportBaseComponent (abstract)

The base directive. onClick() reads value and, when it is set, calls handler(value, fileName); it does nothing while value is falsy. Extend it to change the markup while keeping the behaviour. There is no token to register a subclass under, so a custom export control is rendered by its own selector.

MemberTypeDescription
onClick()() => Promise<void>Calls handler(value, fileName) when value is truthy; does nothing otherwise.
cssClassInputSignal<string>The class input under its property name; bind it on the element your template renders.

API

Inputs

InputTypeDefaultDescription
valueInputSignal<any | undefined>undefinedThe data to export. The button is disabled while it is falsy; an empty array is truthy and enables it, so bind undefined while there is nothing to export.
handlerInputSignal<(value: any, fileName?: string) => void>requiredCalled with value and fileName on click; serialise and download the data here. It is called as a plain function, so pass an arrow function (a class field) when it uses this.
fileNameInputSignal<string | undefined>undefinedName for the downloaded file, passed to handler as its second argument. The fileName argument is optional, so (value) => void handlers keep working.
classInputSignal<string>''Extra CSS classes applied to the rendered button (cssClass input, alias class).

The component emits no outputs: the handler input is where the data leaves it. The CRUD list page does not use it; its export option renders the CSV / XLSX export of @smartsoft001/crud-shell-angular (see the smart-crud skill).

Source

The component lives in packages/shared/angular/src/lib/components/export and is documented for Claude Code by the angular-components-export skill.

SmartExport is a download-icon button. On click it calls handler(value, fileName); the handler serialises the data and triggers the download, so the format is yours (JSON, CSV, ...). The button is disabled while value is empty. It renders through SmartButton, so it follows whatever is registered under the button key.


Usage

import { useState } from 'react';

import { SmartExport } from '@smartsoft001/react';

interface Order {
  id: string;
  customer: string;
  total: number;
}

const orders: Order[] = [
  { id: 'ORD-1001', customer: 'Lindsay Walton', total: 120 },
  { id: 'ORD-1002', customer: 'Courtney Henry', total: 85.5 },
];

export function ExportUsageExample() {
  const [exported, setExported] = useState<{
    orders: Order[];
    fileName?: string;
  } | null>(null);

  // Receives `value` and `fileName` when the button is clicked. Build the
  // file (CSV, XLSX, ...) and start the download under that name.
  const exportOrders = (value: Order[], fileName?: string) =>
    setExported({ orders: value, fileName });

  return (
    <>
      <SmartExport
        value={orders}
        fileName="orders.csv"
        handler={exportOrders}
      />
      {exported && (
        <p>
          Exported {exported.orders.length} orders as {exported.fileName}
        </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.

ExportKindWhat it is
SmartExportcomponentA download-icon SmartButton that calls handler(value, fileName).
useExporthookThe export button's logic: onClick hands value and fileName to handler, and does nothing while there is no value.

Props and Types

SmartExportProps

PropTypeDefaultDescription
value?any—The data to export; the button is disabled while it is empty.
fileName?string—Name for the exported file, passed to handler as its second argument.
handler(value: any, fileName?: string) => voidrequiredCalled with value and fileName on click. Serialise and download the data here. The fileName argument is optional, so (value) => void handlers keep working.
className?string—Classes on the button and on the <span> around it.

Replacing the Implementation

SmartExport has no registry key of its own: it renders a SmartButton, so registering a component under the button key (or SMART_PRESET_COMPONENTS) restyles it too. For a different control, call useExport from a component of your own.

The useExport hook

The export button's logic: onClick hands value and fileName to handler, and does nothing while there is no value.

ReturnsTypeDescription
onClick() => Promise<void>Calls handler(value, fileName); does nothing while there is no value.

Styling

  • The icon is an inline SVG with an Export screen-reader label; the button look comes from the registered button implementation.

Source

The component lives in packages/shared/react/src/lib/components/export and is documented for Claude Code by the react-components-export skill.