Static CMS
Star StaticJsCMS/static-cms on GitHub
v4.3.0DocsExamplesDemoCommunity

Theming

Static CMS comes with two default themes (light and dark), and you can add your own custom themes as well.

Static CMS exposes a window.CMS global object that you can use to register custom themes via registerTheme. The same object is also the default export if you import Static CMS as an npm module.

Register Theme

Register a custom theme.

const theme = {
  name: 'Custom Dark',
  text: {
    primary: '#fff',
    secondary: 'rgba(255, 255, 255, 0.7)',
    disabled: 'rgba(255, 255, 255, 0.5)',
  },
  background: {
    main: '#1e293b',
    light: '#2c3b55',
    dark: '#0f172a',
    divider: '#2c3b55',
  },
  scrollbar: {
    main: '#1e293b',
    light: '#2c3b55',
  },
  button: {
    disabled: '#334155',
  },
  primary: {
    main: '#339ef4',
    light: '#6bb9f7',
    dark: '#0c82e0',
    contrastColor: '#ffffff',
  },
  error: {
    main: '#f44336',
    light: '#e57373',
    dark: '#d32f2f',
    contrastColor: '#ffffff',
  },
  warning: {
    main: '#ffa726',
    light: '#ffb74d',
    dark: '#f57c00',
    contrastColor: '#ffffff',
  },
  info: {
    main: '#29b6f6',
    light: '#4fc3f7',
    dark: '#0288d1',
    contrastColor: '#ffffff',
  },
  success: {
    main: '#66bb6a',
    light: '#81c784',
    dark: '#388e3c',
    contrastColor: '#ffffff',
  },
  codemirror: {
    theme: 'dark',
  },
};

// Using global window object
CMS.registerTheme(theme);

// Using npm module import
import CMS from '@staticcms/core';

CMS.registerTheme(theme);

Extend Built-in Themes

Extend either the light or dark themes.

// Using global window object
CMS.registerTheme({
  name: 'Red Orange',
  extends: 'dark',
  primary: {
    main: '#ff4500',
  },
});

// Using npm module import
import CMS from '@staticcms/core';

CMS.registerTheme({
  name: 'Red Orange',
  extends: 'dark',
  primary: {
    main: '#ff4500',
  },
});

Set Default Theme

By default light is the main theme (or dark if the user's system is set to dark mode). default_theme allows you to change that.

theme:
  default_theme: false
  themes:
    # Can also be registered via javascript
    - name: Red Orange
      extends: dark
      primary:
        main: '#ff4500'

Hide Built-in themes

By default both a light and dark them are available. However, if you provide at least one custom theme, include_built_in_themes allows you to disable the built-in themes.

If default_theme is not provided, then the first custom theme is used (when include_built_in_themes is false).

theme:
  include_built_in_themes: false
  themes:
    # Can also be registered via javascript
    - name: Red Orange
      extends: dark
      primary:
        main: '#ff4500'

useTheme Hook

The useTheme hook can be utilized in customize widgets and previews to utilize values from the theme.

Example Preview Card

const PostPreviewCard = ({ entry, widgetFor }) => {
  const theme = useTheme();

  return h(
    'div',
    { style: { width: '100%' } },
    widgetFor('image'),
    h(
      'div',
      { style: { padding: '16px', width: '100%' } },
      h(
        'div',
        {
          style: {
            display: 'flex',
            width: '100%',
            justifyContent: 'space-between',
            alignItems: 'start',
          },
        },
        h(
          'div',
          {
            style: {
              display: 'flex',
              flexDirection: 'column',
              alignItems: 'baseline',
              gap: '8px',
            },
          },
          h('strong', { style: { fontSize: '24px' } }, entry.data.title),
          h('span', { style: { fontSize: '16px' } }, entry.data.date),
        ),
        h(
          'div',
          {
            style: {
              backgroundColor: entry.data.draft === true
                ? theme.info.main
                : theme.success.main,
              color: 'white',
              border: 'none',
              padding: '4px 8px',
              textAlign: 'center',
              textDecoration: 'none',
              display: 'inline-block',
              cursor: 'pointer',
              borderRadius: '4px',
            },
          },
          entry.data.draft === true ? 'Draft' : 'Published',
        ),
      ),
    ),
  );
};

CMS.registerPreviewCard('posts', PostPreviewCard, () => 240);

Theme

The react component that renders the control. It receives the following props:

ParamTypeDescription
namestringThe name of the theme
extendsstringOptional if all other theme options are provided.
The default theme to extend
commonobjectOptional if extends is provided. See Common Colors
textobjectOptional if extends is provided. See Text Colors
backgroundobjectOptional if extends is provided. See Background Colors
scrollbarobjectOptional if extends is provided. See Scrollbar Colors
primaryobjectOptional if extends is provided. See Theme Color
errorobjectOptional if extends is provided. See Theme Color
warningobjectOptional if extends is provided. See Theme Color
infoobjectOptional if extends is provided. See Theme Color
successobjectOptional if extends is provided. See Theme Color
codemirrorobjectOptional if extends is provided. See Codemirror

Common Colors

common allows you to change the common colors.

ParamTypeDescription
graystringOptional if extends is provided.

Text Colors

text allows you to change the text colors.

ParamTypeDescription
primarystringOptional if extends is provided.
secondarystringOptional if extends is provided.
disabledstringOptional if extends is provided.

Background Colors

background allows you to change the background colors.

ParamTypeDescription
mainstringOptional if extends is provided.
lightstringOptional if extends is provided.
Will be calculated from main if not provided.
darkstringOptional if extends is provided.
Will be calculated from main if not provided.
dividerstringOptional if extends is provided.

Scrollbar Colors

scrollbar allows you to change the scrollbar colors.

ParamTypeDescription
mainstringOptional if extends is provided.
lightstringOptional if extends is provided.
Will be calculated from main if not provided.

Theme Color

primary, error, warning, info and success are theme colors and share the same options.

ParamTypeDescription
mainstringOptional if extends is provided.
lightstringOptional if extends is provided.
Will be calculated from main if not provided.
darkstringOptional if extends is provided.
Will be calculated from main if not provided.
contrastColorstringOptional if extends is provided.

Codemirror

codemirror allows you to change the theme settings for Codemirror instances (used by the code and markdown widgets).

ParamTypeDescription
mainstringOptional if extends is provided.
lightstringOptional if extends is provided.
Will be calculated from main if not provided.