App Extensions

Editor Interfaces

Interfaces are form inputs used primarily inside of the Directus Editor.

Interfaces are form inputs used primarily inside of the 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.

An "input" in the content module

This extension type is loaded into the Directus Data Studio. They are are built with Vue 3, and can use the provided composables exported by the @directus/extensions-sdk package. Extensions can be written in JavaScript or TypeScript.

Interface Entrypoint

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.

Entrypoint Example

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',
            }
        },
    ],
});

Properties

PropertyTypeDescription
idstringA unique identifier for this extension.
namestringThe displayed name for this panel in the Data Studio.
iconstringAn icon name from the Google Material Icons set. Supports filled and outlined variants.
descriptionstringA description of this interface shown in the Data Studio. Maximum 80 characters.
componentcomponentA reference to the Vue component rendered in the editor.
typesarrayAll types supported by the interface.
localTypesarrayAll local types supported by this interface. Accepts standard, file, files, m2o, o2m, m2m, m2a, presentation, translations, and group. Defaults to standard.
groupstringThe group this interface is shown at when creating a field. Accepts standard, selection, relational, presentation, group, or other. Defaults to other.
relationalbooleanIndicates if this a relational interface.
recommendedDisplaysarrayA list of display names which are recommended to be used with this interface.
optionsarray | component
previewstringInline SVG to display in interface selection drawer.
Unique Identifiers
The extension id must not conflict with other extensions, so consider prefixing with author name.
Theme-Aware Previews
In your SVG, use available theme CSS variables such as --theme--primary and --theme--primary-subdued to match your panel preview with the project theme.

Interface Component

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.

Component Example

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.

Props

The interface component will be passed all user configuration options from the entrypoint file. It will also receive the following props:

PropTypeDescription
valuestringThe current value of the field.
widthstringThe layout width of the field. One of half, half-right, full, or fill.
typestringThe type of the field.
collectionstringThe current collection name.
fielduuidThe key of the field.
primaryKeystringThe current item's primary key.

Emits

The interface component can emit the following events that will be recognized by Directus.

EventDescription
inputUpdate the value of the field.
setFieldValueUsed to set the value of other fields.

Using Directus Internals

To access internal systems like the API or the stores in app extensions, you can use the useApi() and useStores() composables exported by the @directus/extensions-sdk package.

Learn more about using Directus composables.

Directus UI components are globally registered, making them accessible throughout your extension without the need to import them.

Learn more about using the Directus UI library.

Using External APIs

To avoid Cross Site Request Forgery (CSRF), app extensions cannot make requests to external servers by default. A common approach to achieve this is to create a bundle containing an endpoint that makes the external request, and an app extension that uses the now-internal endpoint to retrieve data.

Learn more about building extensions through our tutorials.