This pattern demonstrates how to automate the process of filling design elements with data. The workflow involves three main steps:
- Identify tagged fields: Use
getDesignMetadata to read which elements in the current design have been tagged with specific field labels. - Match data fields: Use
requestDataFieldMatching to allow the user to map their data source columns (e.g., "Name", "Role") to the labels tagged in the Canva design. - Apply data: Use
autofillDesign to populate the tagged design elements with the values from a DataTable.
Note that the DataTable shape used here is defined by the DataTable type from @canva/intents/data, which is the same format returned by a Data Connector's getDataTable method.
import {
requestDataFieldMatching,
autofillDesign,
getDesignMetadata
} from '@canva/design';
import { DataTable } from '@canva/intents/data';
// Example workflow logic:
// 1. const metadata = await getDesignMetadata();
// 2. await requestDataFieldMatching(sampleTable);
// 3. await autofillDesign(sampleTable);