4.3.0 • Published 2 years ago

@hig/theme-context v4.3.0

Weekly downloads
18
License
Apache-2.0
Repository
github
Last release
2 years ago

ThemeContext component

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

Getting started

yarn add @hig/theme-context @hig/theme-data

Provide a theme to components

import HIGDarkBlueTheme from '@hig/theme-data/build/esm/darkBlueMediumDensityTheme';
import ThemeContext from '@hig/theme-context';

function MyApp() {
  <ThemeContext.Provider value={HIGDarkBlueTheme}>
    <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 '@hig/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>
}
4.3.0

2 years ago

4.2.0

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha

6 years ago