slide.ng
On this page ▾

Themes and addons

A theme or an addon is a folder, or an npm package, that adds to the built-in look. A theme is the look of the deck. An addon adds to it, for example a set of components. Both have the same contents, see Directory structure.

Use one

---
theme: ./my-theme
addons:
  - ./my-addon
  - slide-ng-addon-charts
---
  • theme: default, none, or no theme: at all is the built-in theme.
  • A path (./my-theme, an absolute path, @/themes/mine relative to the deck's folder) is used as a folder.
  • Any other name is looked up in node_modules, from the deck's folder upwards: @slide-ng/theme-<name>, then slide-ng-theme-<name>, then <name>. A scoped name (@scope/theme-x) is used as written. Addons use @slide-ng/addon-<name>, slide-ng-addon-<name>, then <name>.
  • A path that is not a folder is an error, and so is a package that is not installed. The build stops with The theme "x" was not found. Install it with: npm install -D slide-ng-theme-x. In a terminal, dev and build ask first whether to install it now.
  • --theme <name|path> on the command line, or SLIDE_NG_THEME, overrides the headmatter for one run.

The official themes

seriph, shibainu, bricks and apple-basic are rebuilt from the official Slidev themes, adev is inspired by angular.dev, and all are published from a separate repository, slide-ng/themes, one package each. default is the built-in look. See the Theme gallery.

npm i -D @slide-ng/theme-seriph
---
theme: seriph
---

Slidev themes are written for Vue and are not compatible. Only the folder names are alike. A Slidev theme name such as theme: seriph is looked up as @slide-ng/theme-seriph, so install that package, or the build stops.

The slide.ng repository also has example themes to copy into a deck as folders: examples/theme-minimal, theme-paper (light, editorial: serif headlines and a vermilion accent), theme-moss (dark, forest green and clay) and theme-blueprint (a navy drafting grid with amber marks). Each README lists its layouts, inputs and component.

What a theme can set

A theme can bring layouts, components, layers, CSS, public files, UnoCSS settings, default headmatter and Angular providers. Its default headmatter sits under the deck's own: the deck wins. defaults, fonts, drawings, htmlAttrs and themeConfig are merged key by key.

The one exception is colorSchema. A theme that sets light or dark has colours for that mode only, so every deck that uses it keeps that mode, as in Slidev. The toggle is gone, and when the deck's headmatter asks for another mode the generator says that it is not used. Of the official themes, bricks is light only and shibainu dark only.

Theme settings

themeConfig holds the values a theme offers to change, as in Slidev. Each key with a text or number value becomes the CSS variable --slidev-theme-<key> on <body>, with the key as written: primary is --slidev-theme-primary, accentDark is --slidev-theme-accentDark. It is there in the page, the presenter, the PDF and offline builds.

---
themeConfig:
  primary: '#5d8392'
---

primary recolours the built-in accent: text-primary, bg-primary, border-primary, the progress bar and the controls. Other keys do what the theme makes of them.

  • The theme's theme.json can give defaults. The deck's keys win, key by key, and so do an addon's.
  • A key must be letters, digits, - and _. A value that could leave the CSS declaration (;, {, }, <, >, \, a comment, a line break, quotes or brackets that do not close) is skipped with a warning. So is a url(...) or image-set(...), because the generated CSS would look for the file in the wrong folder. Name pictures in the theme's or the deck's CSS.
  • A number is written without a unit, as in Slidev: radius: 6 is --slidev-theme-radius: 6, which CSS does not take as a length. Write radius: 6px.
  • There is one value for both colour modes, as in Slidev.
  • A slide reads the whole map as themeConfig, for example {{ themeConfig['primary'] }}. The brackets are needed because the map has no fixed keys. Lists and objects are kept there, but they are not CSS variables.
  • A theme's component reads it with inject(THEME_CONFIG) from slide-ng/lib/theme-config. See Writing a theme.

Translating the interface

A theme or an addon can translate slide.ng's own interface (the bar, the menus, the presenter) with a locales/ folder. locales/tr.json, or pt.json and pt-BR.json, holds flat "key": "text" pairs with their {name} placeholders kept:

{ "nav.next": "Sonraki slayta git", "presenter.noNotes": "{no}. slayt için not yok." }

The deck's lang or uiLang picks the file. The built-in translations come first, then the theme, the addons and the deck, key by key, so a deck can change one text of its theme. A theme's own components can show the same texts with the t pipe: import T from slide-ng/i18n/t, then write {{ 'nav.next' | t }}. See Interface language.

Eject a theme

slide-ng theme eject

copies the theme in use into ./theme and sets theme: ./theme, so you can edit it. --theme or SLIDE_NG_THEME picks another theme to copy. For the built-in theme this copies every layout, with their imports rewritten to slide-ng/... (including the helpers background and frame, which stay in the package), and the layouts' CSS as styles/index.css. For a package it copies the whole package folder without node_modules, .git and symbolic links. It refuses a folder that is not empty. --dir picks another folder name.

The built-in styles still load before the ejected styles/index.css. Your copy overrides them rule by rule, so deleting a rule from the copy brings the built-in one back. To undo a built-in rule, override it, for example .slidev-layout.end { background: none }. A later slide.ng version can change the built-in rules under your copy.

Limits

  • There is no versioning or compatibility check between a theme and the app.
  • A layout's inputs are not read from the component, because Angular decorators are not parsed. They come from the built-in layout or from theme.json.
  • Class names in a theme are found by UnoCSS in .ts files of the roots and in the deck's markdown, not in CSS files.
  • A theme package whose files leaves its folders out installs empty. The generator warns, instead of failing later with "is not a known element".

Next: Writing a theme.