Custom Themes
Themes are comprised of a definition and a set of components.
Defining a Theme
Use the defineTheme
helper to define a theme.
At minimum you must provide componentsPath
, an absolute path to the directory containing the theme's components,
and we'd recommend providing a config type.
Components Folder
The folder at componentsPath
must contain a Layout
file and optionally an mdx-components
file.
All other files in this directory will be ignored,
feel free to organize your components however you'd like.
The Layout
file is the runtime entrypoint for the theme and will be rendered by SolidBaseRoot
.
It must have a component as its default export.
Any named exports from mdx-components
will be given to MDXProvider
from solid-mdx,
making them available in MDX files without needing to be imported.
Components with lowercase names will override HTML elements of the same name.
Some exports have special uses:
DirectiveContainer
: Rendered whenever a Markdown directive is encountered.
Vite Plugin
Themes can provide their own Vite plugin by defining a vite
function.
This function receives the SolidBase config and should return a Vite plugin.
You can use it to conditionally import code based on the provided config, load virtual modules generated by the theme, or anything else you'd want a Vite plugin for.
SolidBase's default theme uses its own Vite plugin to conditionally import fonts!
Building a Layout
The most basic Layout
receives the current route as children
and renders it:
You can use the SolidBase config and each page's metadata to customize the layout
via useSolidBaseContext
and useCurrentPageData
respectively.
Distributing a Custom Theme
SolidBase themes are most easily distributed as npm packages. If using TypeScript, your theme definition must be compiled to JavaScript before publishing. It's up to you whether you distribute your theme's components as TS or JS.
Consuming a Theme
To consume a theme, import its definition in your app.config
and use it to create a custom withSolidBase
function:
You can add to the theme by extending it with your own theme.
Last updated: 11/14/24, 7:58 PM