New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

theme-up

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

theme-up

🎨 Easy and persistent theming using the React Context API & CSS variables

  • 1.0.0-rc.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
npm

theme-up logo

A minimalistic library that allows you to easily add theme support to your React app.

Installing

  1. Add the library to the package.json and install it
npm install theme-up
  1. Make an object of type Config (more details in section "Config object")
import { Config } from 'theme-up'

enum Theme {
  Light = 'light',
  Dark = 'dark'
}

export const themeConfig: Config<Theme> = {
  defaultTheme: Theme.Light,
  defaultThemeDark: Theme.Dark,
  themes: {
    [Theme.Light]: {
      backgroundColor: '#FFF',
      textColor: '#000'
    },
    [Theme.Dark]: {
      backgroundColor: '#273238',
      textColor: '#FFF'
    }
  }
}
  1. Wrap your app in GlobalThemeProvider.
<GlobalThemeProvider config={themeConfig}>
	...
</GlobalThemeProvider>
  1. Profit 💰

Getting the current theme

  1. Import the ThemeContext
import { ThemeContext } from 'theme-up'
  1. Use the Context
  2. ?
  3. Profit

Config object

When you're using typescript you should pass your theme identifier as a type. This type can be a string or number, or an extension of them, ex. an Enum (as shown in the installation example).

keytypeoptionaldescription
defaultTheme: Tgeneric*requiredThe default theme. This value must be an object within themes.
defaultThemeDark: Tgeneric*requiredThe default theme if the browser specifies a user preference (safari macOS). This value must be an object within themes.
themes: { [key in T]?: Styles }requiredObject, with key as defined in genericsAn object containing all themes, every object's key will be used as identifier for that theme. The objects belonging to a theme are key-value pairs defining the variable name and value respectively. The variable names can be written with and without the -- prefix.
initInterceptor?: (theme: T) => TfunctionoptionalGives you the ability to do something when the theme is initiated (on load). This functions expects a return value of a theme (identifier).
onUpdate?: (theme: T) => voidfunctionoptionalA function that gets called on every theme change.
isPersistent?: booleanbooleanoptionalA boolean that decides wether or not the value should be stored and retreived from localStorage

* an extension of string | number

Keywords

FAQs

Package last updated on 04 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc