1.0.0 • Published 1 year ago

@weave-design/theme-context v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

ThemeContext component

Themable Weave components within a ThemeContext.Provider will have access to the provided theme.

Getting started

yarn add @weave-design/theme-context @weave-design/theme-data

Provide a theme to components

import WeaveDarkBlueTheme from '@weave-design/theme-data/build/esm/darkBlueMediumDensityTheme';
import ThemeContext from '@weave-design/theme-context';

function MyApp() {
  <ThemeContext.Provider value={WeaveDarkBlueTheme}>
    <TheRestOfMyApp />
  </ThemeContext.Provider>
}

For information on customizing a theme or importing theme data in different formats, see the theme-data README.

Consume theme values in a component

import ThemeContext from '@weave-design/theme-context';

function MyThemedComponent() {
  <ThemeContext.Consumer>{({ resolvedRoles, metadata }) => (
    <div style={{
      backgroundColor: resolvedRoles["colorScheme.surface.level200"],
      borderRadius: resolvedRoles["basics.borderRadii.small"],
      color: resolvedRoles["colorScheme.text.default"],
      padding: resolvedRoles["density.spacings.medium"],
    }}>
      The current theme is "${metadata.name}".
    </div>
  )}</ThemeContext.Consumer>
}