1.0.0 • Published 4 years ago

use-solarized v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

use-solarized

React Hook for using the Solarized color scheme.

Install

yarn add use-solarized
# or
npm install use-solarized

Basic Usage

import React from "react";
import useSolarized from "use-solarized";

const App = () => {
  const { colors, toggleColorMode } = useSolarized();

  return (
    <div
      style={{
        color: colors.text,
        backgroundColor: colors.background,
      }}
    >
      <button onClick={toggleColorMode}>Click Me</button>
    </div>
  );
};

API

Initialization

useSolarized() has a boolean argument defining if it should start in light mode or not. Using no argument will default to light mode.

const App = () => {
  const { colors } = useSolarized(false); // dark mode
};

toggleColorMode

Calling toggleColorMode() will toggle between light mode and dark mode.

Accent Colors

Solarized has 8 accent colors, which can either be accessed by name or by index:

IndexKeyCodeColor
0yellow#b58900yellow
1orange#cb4b16orange
2red#dc322fred
3magenta#d33682magenta
4violet#6c71c4violet
5blue#268bd2blue
6cyan#2aa198cyan
7green#859900green
const { colors } = useSolarized();
colors.yellow; // "#b58900"
colors[4]; // "#6c71c4"

Content Colors

Solarized has 8 content colors, using 5 for light mode and 5 for dark mode:

Light Mode

NameKeyCodeColorDescription
base01emphasized#586e75base01Optional emphasized content
base00primary#657b83base00Body text / primary content
base1secondary#93a1a1base1Secondary content
base2highlight#eee8d5base2Background highlights
base3background#fdf6e3base3Bachground

Dark Mode

NameKeyCodeColorDescription
base1emphasized#93a1a1base1Optional emphasized content
base0primary#839496base0Body text / primary content
base01secondary#586e75base01Secondary content
base02highlight#073642base02Background highlights
base03background#002b36base03Bachground
const { colors, toggleColorMode } = useSolarized();
colors.primary; // "#657683"
colors["background"]; // "#fdf6e3"
toggleColorMode();
colors.primary; // "#839496"
colors["background"]; // "#002b36"

License

MIT