Theme

Applies light or dark mode, and a color palette, to the part of the page inside it.

Usage

Code
import { Theme } from '@leverui/components';
Code
<Theme appearance="dark">
  <div />
</Theme>

Examples

Nested

The theme can be nested to apply different appearances to different parts of the tree. This is useful for applying a global appearance and then overriding some parts of it.

Good to know: We use native CSS selectors to achieve this.

Default theme
Dark theme
Light theme

Portalled

Use the asChild prop to force the appearance of portalled elements like the popover and modal content.

Page Specific Color Mode

Wrap the whole page in Theme.

Code
import type { ParentProps } from 'solid-js';
import { Theme } from '@leverui/components';

export function ForcedColorMode(props: ParentProps) {
  return <Theme appearance="dark">{props.children}</Theme>;
}

Guides

Scoped appearance

Finish the stylesheet setup first. Theme applies light or dark mode only to the elements inside it. By default it also gives that section the theme's text and background colors.

Leave out appearance to use the surrounding mode. Set hasBackground={false} to leave the background as it is. Also takes native HTML attributes, class, style, and a named colorPalette.

Portalled content

Mount portal content inside the Theme, or give it the same theme values where it renders. Theme changes colors only, not what its children mean to browsers and screen readers.

Customize with CSS

Add a class to set public --leverui-* variables for that section only. See the CSS theme guide. Changing a palette scale color on the nested element does not recompute a background color it inherited. Set --leverui-colors-bg directly when you need to.

Code
<Theme appearance="dark" class="preview-panel">
  <Text>Dark preview</Text>
</Theme>
Code
.preview-panel {
  padding: var(--leverui-spacing-4);
}