@adminjs/themes

中文文档
1.0.1发布于 2023/09/18SEE LICENSE IN LICENSETypeScriptESM + CJS近 30 天下载 2.2万

Themes let you change the style and default components of your admin panel. There are three elements added to the app by each theme:

原始使用文档
文档目录7 节
  1. Importing Themes in AdminJS
  2. Setup
  3. Per-user themes
  4. CLI
  5. Usage
  6. License
  7. About rst.software

Themes for AdminJS

Themes let you change the style and default components of your admin panel. There are three elements added to the app by each theme:

component overrides - React components that replace a subset of overridable components

theme overrides for @adminjs/design-system - this is merged into the default config, and then user's branding is applied on top

custom CSS styles - a single global CSS file with additional theme styles

Importing Themes in AdminJS

Setup

You can add availableThemes configuration option with an array of theme objects (for example imported from @adminjs/themes package) or themes bundled locally with @adminjs/themes CLI adminjs-themes bundle. The first theme on the list will be active by default. This can be changed with defaultTheme option - specify the ID of a theme - these are usually the same as the named exports.

import AdminJS from 'adminjs'
import { light, dark } from '@adminjs/themes'

new AdminJS({
  defaultTheme: 'dark', // same as `dark` from id in the theme index file,
  availableThemes: [light, dark],
})

Bundle and style paths are taken from @adminjs/themes if the theme is officially supported by library or can be imported from a local path like:

import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

new AdminJS({
  defaultTheme: 'my-custom-theme',
  availableThemes: {
    id: 'my-custom-theme',
    name: 'my custom theme',
    overrides: {
      colors: {
        primary100: '#f00',
      },
    },
    bundlePath: `${path.join(__dirname, `../themes/my-custom-theme`)}/theme.bundle.js`,
    stylePath: `${path.join(__dirname, `../themes/my-custom-theme`)}/style.css`,
  },
});

Full example available in @adminjs/themes example app.

Per-user themes

Additionally, the theme can be configured per-user by returning theme ID in the theme property of the CurrentAdmin object - this should be implemented via the framework plugin, i.e. authenticate function in @adminjs/express. Since you have full control of that object, returned the theme can be selected based on things like user's role or property in the database.

There's no UI control for changing themes, but you can implement this yourself. The general idea is to keep theme ID in the user resource, and add a button that will update the current user record with the selected theme. Alternatively, you can let the user edit their own record and offer a custom select property. Note that for the currentAdmin object to update the user most likely needs to sign in again.

CLI

You can create a new theme using @adminjs/themes cli. After checkout the repository you can register cli on your machine with yarn register:cli. After that, you can use adminjs-themes in your command line.

AdminJS Themes CLI provides commands for:

  • adminjs-themes generate <theme name> - Generating a new theme with the recommended file structure.
  • adminjs-themes bundle - Bundling all themes component overrides. You can pass theme ID as an argument to bundle ssingle theme.

For more information please use the command adminjs-themes bundle --help

Usage

Please see the documentation.

License

AdminJS is copyrighted © 2023 rst.software. It is a free software, and may be redistributed under the terms specified in the LICENSE file.

About rst.software

We’re an open, friendly team that helps clients from all over the world to transform their businesses and create astonishing products.

  • We are available for hire.
  • If you want to work for us - check out the career page.

版本与发布记录

@adminjs/themes 共发布 8 个版本,首次发布于 2023/04/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2023/09/183 年前
1.0.02023/04/183 年前
1.0.0-beta.6beta2023/04/053 年前
1.0.0-beta.52023/04/053 年前
1.0.0-beta.42023/04/053 年前
1.0.0-beta.32023/04/043 年前

关于 @adminjs/themes 的常见问题

@adminjs/themes 是什么?

Themes let you change the style and default components of your admin panel. There are three elements added to the app by each theme:

如何安装 @adminjs/themes?

在项目目录运行 npm install @adminjs/themes,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:adminjs(^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 adminjs-themes,可以用 npx adminjs-themes 直接运行。

@adminjs/themes 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adminjs/themes 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adminjs/themes 可以商用吗?

@adminjs/themes 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@adminjs/themes 的下载量有多少?

根据 npm 官方下载统计,@adminjs/themes 在 2026/10/05 – 2026/11/03 这 30 天内被下载 21,728 次,日均约 724 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adminjs/themes 还在维护吗?

最新版本 1.0.1 发布于 2023/09/18(3 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/04/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。