Skip to content

adrianhideki/theme-token-manager

Repository files navigation

🎨 theme-token-manager

npm latest package codecov

A theme token manager for React that uses tokens to style and theme applications.
Try the demo.


Installation

npm install theme-token-manager

or

yarn add theme-token-manager

Usage

1. Provide a Theme

Wrap your app with ThemeProvider:

import { ThemeProvider, defaultTheme } from "theme-token-manager";

<ThemeProvider theme={defaultTheme}>
  <App />
</ThemeProvider>;

You can also provide your own theme object (see Theme).

2. Access Theme in Components

Use the useTheme hook to access the current theme:

import { useTheme } from "theme-token-manager";

const MyComponent = () => {
  const { theme } = useTheme();
  return (
    <div
      style={{
        backgroundColor: theme.palette.light.surface["primary-default"],
      }}
    >
      {/* ... */}
    </div>
  );
};

CSS Variables and Baseline

To inject CSS variables and baseline styles, use CssBaseline:

import 'theme-token-manager/css-baseline/styles.css'
import { CssBaseline } from "theme-token-manager";

<CssBaseline mode="light">
  <App />
</CssBaseline>;

This will inject CSS variables based on your theme. Import the src/css-baseline/styles.css to work as tailwind-css classes.


Multiple Themes

To manage multiple themes, use the ThemeCollectionProvider:

import { ThemeCollectionProvider } from "theme-token-manager";

<ThemeCollectionProvider themes={[theme1, theme2]}>
  <App />
</ThemeCollectionProvider>;

API Reference


Contributing

Contributions are welcome! Please open issues or pull requests on GitHub.


About

A theme token manager for react

Resources

Stars

Watchers

Forks

Packages

No packages published