Themes
Vanilla Tweakpane provides a robust theming system based on CSS variables.
Svelte Tweakpane UI provides abstractions over the underlying CSS variables with some additional conveniences, most notably:
- Easy access to a collection of bundled preset themes.
- Abstractions around scoping to simplify using different themes on the same page.
- Type safety / autocompletion when defining custom themes or overriding existing ones.
Theme-related helpers are exposed on the ThemeUtils
object, and a Theme
type is also available to provide auto-completion and type safety when defining or overriding themes.
ThemeUtils.presets
provides default dark and light themes, plus all of the themes defined in the Panepaint theme building tool on the Tweakpane site.
Every Svelte Tweakpane UI component includes an optional theme
prop, into which you can pass a Theme
object. The Theme
object can be a bundled preset, a completely new theme of of your own creation, an extension of a bundled preset, or a partial override of the global default theme (standard
) by default.
Pass a ThemeUtils.presets
value to the theme
prop of your Tweakpane component:
This applies the theme to a single component or pane on the page:
A quick example of using a <List>
to browse and select from all the available preset themes:
Svelte Tweakpane UI manages setting CSS variables at the right points in the DOM to ensure that themes are rationally scoped, and to allow for multiple themes to be used on the same page.
Themes are scoped either to a pane via its theme
prop, to a standalone component via its theme
prop, or to the entire window via the setGlobalDefaultTheme()
utility function.
In the case of standalone Svelte Tweakpane UI components, the theme is still technically scoped to a <Pane>
, because it is applied to the implicit pane that’s created to contain the standalone element.
Each pane on the page can have its own theme:
Standalone components can also have their own themes:
You can set a global default theme for all Tweakpane components on the page using the setGlobalDefaultTheme()
utility function.
Individual panes or standalone components can still override the global default theme via their theme
prop.
Themes are plain old JavaScript objects with a key for each CSS variable that Tweakpane uses. Define all theme keys to ensure complete control over the output.
If you only want to override a few values, you can extend a preset theme. This approach ensures that none of the global default theme’s values can reach your custom theme.
If you don’t mind inheriting from the global default theme, then passing partial theme objects to the theme
prop is a quick way to override a few keys of the global default theme.
For example, to restore the rounded look to specific inline components, you can pass a specific baseBorderRadius
value:
By default, all components will use the ThemeUtils.presets.standard
theme, which is a dark theme.
Svelte Tweakpane UI introduces one exception for inline panes and standalone components. “Inline” components include those created inside a <Pane position="inline">
component, and “standalone” components that are not the child of a <Pane>
.
To better integrate with other inline elements on the page, and especially to avoid a strange scalloped aesthetic when stacking multiple standalone components, rounding is removed by default from inline and standalone the component backgrounds.
If you want to restore the rounded look to specific inline components, you can pass a specific baseBorderRadius
value to the theme
prop of the component — or explicitly set the ThemeUtils.presets.standard
theme.