Import/export settings
Backup and restore application settings
The ImportExportSettings component handles backup and restore of application settings as JSON files.
It manages:
- Export (
onExport): callback to generate and download settings JSON. - Import (
onImport): callback when end user confirms import. - File parsing (
onParseFile): validate and parse uploaded files. - State indicators (
isExporting,isImporting): show loading feedback. - Styling (
className): optional CSS class.
Import
import { ImportExportSettings } from '@mdk/foundation'Props
| Prop | Type | Default | Description |
|---|---|---|---|
onExport | function | none | Required: Callback to trigger settings export |
onImport | function | none | Required: Callback when import is confirmed |
onParseFile | function | none | Required: Parse and validate uploaded file |
isExporting | boolean | false | Export in progress |
isImporting | boolean | false | Import in progress |
className | string | none | Additional CSS class |
Data structure
The SettingsExportData type defines the structure for exported settings:
import type { SettingsExportData } from '@mdk/foundation'
type SettingsExportData = {
headerControls?: HeaderPreferences
featureFlags?: Record<string, boolean>
timestamp?: string
}Callbacks
onExport
Called when end user clicks Export JSON. Generate settings and trigger download:
const handleExport = async () => {
const data = await api.getSettingsExport()
downloadJson(data, 'settings-backup.json')
}onImport
Called after end user confirms import. Receives parsed SettingsExportData:
const handleImport = async (data: SettingsExportData) => {
await api.importSettings(data)
}onParseFile
Validates and parses the uploaded file. Must return a Promise<SettingsExportData>:
const parseFile = async (file: File): Promise<SettingsExportData> => {
const text = await file.text()
return JSON.parse(text)
}Basic usage
import { ImportExportSettings } from '@mdk/foundation'
import type { SettingsExportData } from '@mdk/foundation'
function ImportExportSection() {
const [isExporting, setIsExporting] = useState(false)
const [isImporting, setIsImporting] = useState(false)
const handleExport = async () => {
setIsExporting(true)
const data = await api.getSettingsExport()
downloadJson(data, 'settings-backup.json')
setIsExporting(false)
}
const handleImport = async (data: SettingsExportData) => {
setIsImporting(true)
await api.importSettings(data)
setIsImporting(false)
}
const parseFile = async (file: File): Promise<SettingsExportData> => {
const text = await file.text()
return JSON.parse(text)
}
return (
<ImportExportSettings
onExport={handleExport}
onImport={handleImport}
onParseFile={parseFile}
isExporting={isExporting}
isImporting={isImporting}
/>
)
}Features
Export
Clicking Export JSON triggers the onExport callback. The developer is responsible for:
- Fetching current settings
- Converting to JSON
- Triggering file download
Import flow
- End user clicks Import JSON.
- Modal opens with file upload area.
- End user selects a
.jsonor.csvfile. onParseFilevalidates and parses the file.- Confirmation modal shows what will be imported.
- End user confirms and
onImportis called with parsed data.
Confirmation modal
Before importing, end users see a confirmation dialog listing:
- Header Controls (if present)
- Feature Flags (if present)
- Export timestamp (if available)
Accepted file formats
The file input accepts:
.json: JSON format.csv: CSV format (requires customonParseFilehandling)
Warning message
The component displays a warning:
Importing settings will overwrite your current configuration. Make sure to export your current settings before importing.
Styling
The component uses the .mdk-settings-import-export CSS class. Key selectors:
.mdk-settings-import-export__description: explanatory text.mdk-settings-import-export__actions: button container.mdk-settings-import-export__warning: warning message.mdk-settings-import-export__upload-area: file drop zone in modal

