Import Mapper
The mapping step of a spreadsheet import: match each column of the file to a field, check the required ones, then preview the rows with their errors.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
fields | ImportField[] | [] | The fields a column can be imported as. Set as JSON in markup; a field's validate function needs the property. |
columns | string[] | [] | The file's headers, one per column. Leave it empty to read them from rows: the first row when rows are arrays,
the keys of the first record when they are records. Required with a dataSource. |
rows | ImportSourceRow[] | [] | The file's data rows: arrays of cells in column order, or records keyed by header. Ignored while csv or a dataSource is set. |
csv | string | — | Delimited text (comma, semicolon, tab or pipe, detected); its first line is the header. Wins over columns, rows and dataSource. |
mapping | ImportMapping | [] | One field key per source column, or null for a column that is not imported. Filled by matching the headers
whenever the file or the fields change, unless it is set at the same time or manual is set. |
manual | boolean | false | Leave every column unmapped when a file arrives, instead of matching headers to fields. |
view | ImportMapperView | map | map (the default) shows the columns and their pickers, preview the rows as they will be imported. |
sample-count | number | 3 | How many values each column shows as samples. |
page-size | number | 10 | How many rows a preview page shows. |
page | number | 0 | The preview page shown, from 0. |
errors-only | boolean | false | The preview shows only the rows with an error. With a dataSource, only within the loaded page. |
label | string | — | Names the mapper for assistive technology. |
Slots
| Name | Description |
|---|---|
toolbar | Above the mapping or the preview: the app's own actions (Preview, Import, Back). Hidden when empty. |
footer | Below the mapping or the preview. Hidden when empty. |
empty | Replaces the message shown while there is no file to map. |
loading | Replaces the message shown while a dataSource loads rows. |
error | Replaces the message shown when a dataSource fails. |
Events
| Name | Type | Description |
|---|---|---|
mapping-change | CustomEvent | After the user picks a field for a column, and after autoMatch() or clearMapping(); detail is { mapping, column, field, missing }. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
toolbar | Region wrapping the toolbar slot above the mapping or the preview; hidden while the slot is empty. |
footer | Region wrapping the footer slot below the mapping or the preview; hidden while the slot is empty. |
summary | The required fields and the mapping status. |
columns | The list of source columns. |
column | One source column: its header, samples and picker. |
picker | The field picker of a column (a c2-select). |
preview | The preview: summary, table and pager. |
table | The preview table. |
pager | The preview's page range and buttons. |
state | Container for the empty, loading or error slot, which replaces its built-in message. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-import-mapper--width | width | 100% | The mapper lays its columns out from its own width, so it has no width from its content: it fills its container unless given one. |
--c2-import-mapper--background-color | background-color | #ffffff | |
--c2-import-mapper--color | color | #18181b | |
--c2-import-mapper--border | border | 1px solid #e4e4e7 | |
--c2-import-mapper--border-radius | border-radius | 8px | |
--c2-import-mapper--font-family | font-family | inherit | |
--c2-import-mapper--font-size | font-size | 14px | |
--c2-import-mapper--padding | padding | 16px | Space inside the border, around every region. |
--c2-import-mapper--gap | pixel | 16px | Space between the regions. |
--c2-import-mapper__muted--color | color | #52525b | Headings, sample values and hints. |
--c2-import-mapper__summary--background-color | background-color | #fafafa | |
--c2-import-mapper__summary--border-radius | border-radius | 6px | |
--c2-import-mapper__summary--padding | padding | 10px 12px | |
--c2-import-mapper__field--border-radius | border-radius | 999px | A required field in the summary. |
--c2-import-mapper__field__mapped--background-color | background-color | rgba(22, 163, 74, 0.12) | |
--c2-import-mapper__field__mapped--color | color | #166534 | |
--c2-import-mapper__field__missing--background-color | background-color | rgba(220, 38, 38, 0.1) | |
--c2-import-mapper__field__missing--color | color | #b91c1c | |
--c2-import-mapper__column--min-height | pixel | 52px | |
--c2-import-mapper__column--padding | padding | 8px 0 | |
--c2-import-mapper__column--border-bottom | border | 1px solid #e4e4e7 | |
--c2-import-mapper__column__skipped--color | color | #71717a | The header of a column that is not imported. |
--c2-import-mapper__header--font-weight | font-weight | 500 | A column's header. |
--c2-import-mapper__sample--font-size | font-size | 12px | |
--c2-import-mapper__sample--background-color | background-color | #f4f4f5 | |
--c2-import-mapper__sample--border-radius | border-radius | 4px | |
--c2-import-mapper__arrow--color | color | #a1a1aa | |
--c2-import-mapper__picker--width | pixel | 220px | |
--c2-import-mapper__badge--font-size | font-size | 12px | |
--c2-import-mapper__badge--background-color | background-color | #edf1fe | |
--c2-import-mapper__badge--color | color | rgb(2, 101, 220) | |
--c2-import-mapper__table--max-height | pixel | 420px | Past this height the preview table scrolls. |
--c2-import-mapper__table-head--background-color | background-color | #fafafa | |
--c2-import-mapper__table-head--font-weight | font-weight | 600 | |
--c2-import-mapper__cell--padding | padding | 8px 12px | |
--c2-import-mapper__cell--border-bottom | border | 1px solid #e4e4e7 | |
--c2-import-mapper__cell__invalid--background-color | background-color | rgba(220, 38, 38, 0.08) | |
--c2-import-mapper__error--color | color | #b91c1c | A cell's error message, and the error count. |
--c2-import-mapper__valid--color | color | #15803d | The summary when no cell has an error. |
--c2-import-mapper__button--height | pixel | 30px | The pager's buttons. |
--c2-import-mapper__button--border | border | 1px solid #bcbcc6 | |
--c2-import-mapper__button--border-radius | border-radius | 6px | |
--c2-import-mapper__button--background-color | background-color | transparent | |
--c2-import-mapper__button__hover--background-color | background-color | #f4f4f5 | |
--c2-import-mapper__button__disabled--opacity | opacity | 0.38 | |
--c2-import-mapper__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under import-mapper, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
mapper | Import mapping | — |
sourceColumn | Column in your file | — |
samples | Sample values | — |
target | Import as | — |
skip | Don't import | — |
auto | Auto-matched | — |
notImported | Not imported | — |
pickerLabel | Import column “{0}” as | {0} header |
noSamples | No values | — |
untitled | Column {0} | {0} position |
required | Required | — |
requiredFields | Required fields | — |
mapped | mapped | — |
notMapped | not mapped | — |
allRequiredMapped | All required fields are mapped | — |
missingRequired | {0} required fields are not mapped: {1} | {0} missing {1} names |
mappedColumns | {0} of {1} columns mapped | {0} mapped {1} total |
announceMapped | Column “{0}” imports as {1}. | {0} header {1} field |
announceSkipped | Column “{0}” will not be imported. | {0} header |
announceMoved | {0} is no longer imported from “{1}”. | {0} field {1} header |
empty | No file to map yet. Choose a file to see its columns here. | — |
loading | Loading rows… | — |
loadError | The rows could not be loaded. | — |
rowNumber | Row | — |
preview | Preview of the imported rows | — |
noErrors | {0} rows, no errors | {0} rows |
errorSummary | {0} rows, {1} with errors ({2} errors) | {0} rows {1} invalid {2} errors |
loadedOnly | checked on the {0} rows loaded | {0} rows |
pageRange | Rows {0}–{1} of {2} | {0} first {1} last {2} total |
previousPage | Previous rows | — |
nextPage | Next rows | — |
noInvalidRows | No rows with errors | — |
nothingMapped | Map at least one column to preview the import. | — |
errorPrefix | Error: | — |
errRequired | Required | — |
errNumber | Not a number | — |
errInteger | Not a whole number | — |
errDate | Not a date | — |
errEmail | Not an email address | — |
errUrl | Not a web address | — |
errBoolean | Not yes or no | — |
errOptions | Must be one of: {0} | {0} options |
errPattern | Not in the expected format | — |