content/guides/09.extensions/3.app-extensions/1.interfaces.md
Interfaces are form inputs used primarily inside of the :product-link{product="editor"}.
Interfaces are the primary way users interact with data inside of Directus. Custom interfaces can be used for use cases with unique interaction needs, complex data entry, and any time you need to add elements to the editor.
:partial{content="extensions-app"}
The index.js or index.ts file exports an object that is read by Directus. It contains properties that control how an interface is displayed within menus, it’s what types it supports, what configurable options will be available to users, and the actual Vue component that will be loaded.
import { defineInterface } from '@directus/extensions-sdk'
import InterfaceComponent from './interface.vue';
export default defineInterface({
id: 'custom',
name: 'Custom',
icon: 'box',
description: 'This is my custom interface!',
component: InterfaceComponent,
types: ['string'],
options: [
{
field: 'text',
name: 'Text',
type: 'string',
meta: {
interface: 'input',
width: 'full',
}
},
],
});
| Property | Type | Description |
|---|---|---|
id | string | A unique identifier for this extension. |
name | string | The displayed name for this panel in the Data Studio. |
icon | string | An icon name from the Google Material Icons set. Supports filled and outlined variants. |
description | string | A description of this interface shown in the Data Studio. Maximum 80 characters. |
component | component | A reference to the Vue component rendered in the editor. |
types | array | All types supported by the interface. |
localTypes | array | All local types supported by this interface. Accepts standard, file, files, m2o, o2m, m2m, m2a, presentation, translations, and group. Defaults to standard. |
group | string | The group this interface is shown at when creating a field. Accepts standard, selection, relational, presentation, group, or other. Defaults to other. |
relational | boolean | Indicates if this a relational interface. |
recommendedDisplays | array | A list of display names which are recommended to be used with this interface. |
options | array | component | |
preview | string | Inline SVG to display in interface selection drawer. |
indicatorStyle | string | Controls how comparison indicators are displayed for fields in the comparison modal. Accepts active, muted, or hidden. Defaults to active for standard fields and hidden for group fields. |
:partial{content="extensions-uid"}
:partial{content="extensions-theme"}
The interface component is a Vue component that will be rendered in the Data Studio within the Editor. Data from the entrypoint are passed in as props.
This example assumes there is an item in the entrypoint’s options array with a field value of url.
<template>
<input :value="value" @input="handleChange($event.target.value)" />
<span>{{ text }}</span>
</template>
<script setup>
defineProps(['text', 'value']);
const emit = defineEmits(['input']);
function handleChange(value) {
emit('input', value);
}
</script>
The current value of the field is provided to the component via the value prop. If the value was changed inside your component, it should be emitted to the Directus Editor by using the input emit.
The interface component will be passed all user configuration options from the entrypoint file. It will also receive the following props:
| Prop | Type | Description |
|---|---|---|
value | string | The current value of the field. |
width | string | The layout width of the field. One of half, half-right, full, or fill. |
type | string | The type of the field. |
collection | string | The current collection name. |
field | uuid | The key of the field. |
primaryKey | string | The current item's primary key. |
disabled | boolean | If true, it should appear in subdued colors with disabled interaction. We recommend implementing it. |
nonEditable | boolean | If true, the field will be disabled but retain its normal visual styling, with interaction elements hidden. We recommend implementing it. |
The interface component can emit the following events that will be recognized by Directus.
| Event | Description |
|---|---|
input | Update the value of the field. |
setFieldValue | Used to set the value of other fields. |
:partial{content="extensions-app-internals"}