LogoLogo
Join our community
  • AdminJS
  • Contribute
  • Demo
  • Addons Marketplace
  • Installation
    • Getting started
    • Plugins
      • Adonis
      • Express
      • Nest
      • Fastify
      • Hapi
      • Koa
      • Community Plugins
        • FeathersJS
        • AdonisJS
      • Matrix
    • Adapters
      • TypeORM
      • Sequelize
      • Prisma
      • MikroORM
      • Objection
      • SQL
      • Mongoose
      • Community Adapters
        • AdonisJS
    • What's new in v7?
    • Migration Guide v7
  • Basics
    • Resource
    • Action
    • Property
    • Features
      • Relations
      • Upload
      • Logger
      • Import & Export
      • Password
      • Leaflet Maps
      • Writing your own features
    • API
      • List
      • New
      • Search
      • Show
      • Edit
      • Delete
      • Bulk Delete
    • Themes
    • Authentication
      • FirebaseAuthProvider
      • MatrixAuthProvider
  • How to write an addon?
  • UI Customization
    • Writing your own Components
    • Overwriting CSS styles
    • Dasard customization
    • Changing the form view
    • Storybook
  • Tutorials
    • Role-Based Access Control
    • Internationalization (i18n)
    • Content Management System
    • Custom components library
    • Custom component internationalization
  • FAQ
    • PDF Generator
    • Charts
    • Forgot Password
  • ⚠️Legacy documentation
Powered by GitBook
On this page
  • Adding custom components
  • Custom Component Structure
  • Dependencies
  • Props passed to components
  • Overriding internal AdminJS components
  • Other customizations
  • Theming
  • Reusing UI Components of AdminJS
  • Creating Custom Pages
  • Using other AdminJS frontend classes and objects
  1. UI Customization

Writing your own Components

Adding custom components

AdminJS handles all properties and actions using its own, built-in components. These are the familiar text inputs, checkboxes, paginated lists, edit forms etc. However, you can define a custom component for any single property or action instead. This gives you great control over how the data is being displayed and modified.

In general, you need to create an instance of ComponentLoader, add your custom components there, pass it in the AdminJS options object and specify which properties/actions are using your custom components and where.

./components.ts:

import { ComponentLoader } from 'adminjs'

const componentLoader = new ComponentLoader()

const Components = {
    MyInput: componentLoader.add('MyInput', './my-input'),
    // other custom components
}

export { componentLoader, Components }

./my-input.tsx

import React from 'react'

// just some regular React component
const MyInputComponent = () => <input />

export default MyInputComponent

./some-resource.ts

import { Components } from './components.js'

export const SomeResource = {
  resource: Something, // database model
  options: {
    properties: {
      someText: {
        type: 'string',
        components: {
          edit: Components.MyInput, // this is our custom component
        },
      },
    },
  },
}

./index.ts

import { AdminJS } from 'adminjs'
import { componentLoader } from './components.js'
import { SomeResource } from './some-resource.js'

const admin = new AdminJS({
    resources: [SomeResource],
    componentLoader, // the loader needs to be added here
    // other options
})

admin.watch() // this builds your frontend code in development environment

// rest of the adapter and plugin code

Custom Component Structure

Files added to ComponentLoader need to expose the component function as a default export. Both .jsx and .tsx formats are supported.

Advanced usage: The path passed in the second argument to the ComponentLoader.add() and ComponentLoader.override() functions needs to be relative to the file where it was called. If you want to wrap these calls in another function you might find that AdminJS cannot find the correct files. To fix that, pass a third argument with the name of the caller function, like this:

import { ComponentLoader } from 'adminjs'

const loader = new ComponentLoader()

export const bundleFile = (key: string, path: string) => {
    loader.add(key, path, 'bundleFile') // `bundleFile` is the name of this function
}

Dependencies

AdminJS uses these dependencies internally, so they are exposed for your code without the need to require them in the package.json file:

State management

Routing

Styling

Other

Props passed to components

In your property and action components, you can use props passed by their controlling components.

Currently we have 2 controlling components:

Check out their documentation to see available props

Other, internal components (like Dasard) have either no or different props, see the source code in each case.

Overriding internal AdminJS components

ComponentLoader also has an .override() method that lets you replace components used by AdminJS internally by your own custom components. This is useful in cases where you want to change or add behavior to the entire AdminJS app, for example:

  • Adding a custom dasard

  • Changing the app layout

  • Overriding entire controls (like replacing boolean checkboxes with toggles)

  • Customizing component look and feel when theming is insufficient

The methods are split into .add() and .override() as a safety layer, so you don't accidentally override an internal component with a custom component of the same name - the functions will throw an error when used for conflicting components. In short, .add() won't let you use internal component names and .override() requires an internal component name.

Other customizations

Theming

In order to override default colors, fonts, sizes etc., you can put your values in AdminJSOptions.branding.

Using style props

AdminJS components are supercharged with multiple props controlling styles. For instance in order to change color of a module:@adminjs/design-system.Button you can pass backgroundColor (bg) from the module:@adminjs/design-system.Theme like that:

<Button bg="primary60"></Button>

Adding custom css to components

If using style props is not enough - you can always pass your custom CSS. So for instance let's assume that you would like to overwrite CSS in a Button component. You can do this like that:

import { Button } from '@adminjs/design-system'

const MyButton = styled(Button)`
  background-color: #ccc;
  color: ${({theme}) => theme.colors.grey100};
  ...
`

Reusing UI Components of AdminJS

AdminJS gives you the ability to reuse its component library:

import { Label } from '@adminjs/design-system'

const YourComponent (props) => {(
  <Label>Some styled text<Label>
)}

We divide components internally to 2 groups:

  • application components - which requires AdminJS, you can think about them as "smart components"

  • and design system components - they don't require AdminJS and you can use them outside of the AdminJS setup.

That is why sometimes you have to import components from 'adminjs' package and sometimes from '@adminjs/design-system'.

Each of the components is described with the playground option, so make sure to check out all the documentation of all the components.

Creating Custom Pages

You can also use custom components as full pages by specifying their name in the pages object in AdminJS options:

import AdminJS from 'adminjs'
import { Components } from './components.js'

new AdminJS({
    pages: {
        myPage: { // name, will be used to build an URL
            handler: // handler code,
            component: Components.MyPage,
            icon: // page icon name
        }
    }
})

Using other AdminJS frontend classes and objects

AdminJS also exposes following classes:

You can use them like this:

import { ApiClient, ViewHelpers } from 'adminjs'
PreviousHow to write an addon?NextOverwriting CSS styles

Last updated 1 year ago

Components for actions are added in the exact same way, only in the action section of a resource instead of properties. Refer toandpages for more information.

one for an action:with

and one for custom property field:with

Overriding component works exactly the same way as adding custom components, but you need to specify the matching name of the component ().

We supportcompatible with https://system-ui.com/theme standard.

For all possible options visit thedescription.

We useunder the hood so make sure to check out their docs.

One of the most versatile component is a. It allows you to render any property. Combined withis a powerful tool for building forms.

react
react-dom
prop-types
redux
react-redux
react-router
react-router-dom
styled-components
styled-system
axios
flat
react-feather
BaseActionComponent
ActionProps
BasePropertyComponent
BasePropertyProps
here's the list
Theme
Theme
styled-components
BasePropertyComponent
useRecord
ApiClient
ViewHelpers
Creating custom properties
Action with custom component