1.1.0 • Published 4 years ago

mui-theme-switcher v1.1.0

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

mui-theme-switcher

A dark mode theme switcher for Material UI

NPM JavaScript Style Guide npm

Install

npm install --save mui-theme-switcher

Usage

In App root (example: index.js)

import { ThemeSwitcherProvider } from "mui-theme-switcher";
import { createMuiTheme } from "@material-ui/core";

const lightTheme = createMuiTheme();
const darkTheme = createMuiTheme({
  palette: {
    type: "dark"
  }
});

ReactDOM.render(
  <ThemeSwitcherProvider
    lightTheme={lightTheme}
    darkTheme={darkTheme}
    defaultTheme="dark"
  >
    <App />
  </ThemeSwitcherProvider>,
  document.getElementById("root")
);

In your component (example: App.js)

import { useThemeSwitcher } from "mui-theme-switcher";

const App = () => {
  const { dark, toggleDark } = useThemeSwitcher();
  return (
    <Paper>
      <Typography variant="h5">
        Let there be {dark ? "darkness" : "light"}
      </Typography>
      <Button onClick={toggleDark}>Toggle Theme</Button>
    </Paper>
  );
};

Props

PropTypeDescription
childrennodeThe app which will be themed
darkThemeThemeDark variant of the theme. Theme object created using @material-ui's createMuiTheme
lightThemeThemeLight variant of the theme. Theme object created using @material-ui's createMuiTheme
followSystemboolean (default false)Whether the App should follow system/browser theme.
persistboolean (default false)Whether the App should save the theme locally
appIdstring (Required if using persist)Unique ID of the App.
defaultThemeenum "dark" | "light"Default theme of the App
smoothTransitionboolean (default true)Whether to smooth out the transition between themes. This only affects the background color

License

MIT ©


This hook is created using create-react-hook.