Socket
Socket
Sign inDemoInstall

@colorsystem/react-hooks

Package Overview
Dependencies
3
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @colorsystem/react-hooks

React hooks for ColorSystem.io


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Hook for ColorSystem.io

Usage


npm i @colorsystem/react-hooks

Example Usage

import useColorSystem from "@colorsystem/react-hooks";

const Component = () => {
  const { colorSystem, toggleMode, setMode } = useColorSystem("HE9IHE11");

  return (
    <main
      style={{
        color: colorSystem?.text.primary.hex,
        backgroundColor: colorSystem?.bg.canvas.hex,
      }}
    >
      {/* Toggle Dark / Light Mode */}
      <button onClick={toggleMode}>Toggle Mode</button>

      {/* Set Specific Color Theme */}
      <button onClick={() => setMode("dark")}>Switch to Dark Mode</button>
      <button onClick={() => setMode("light")}>Switch to Light Mode</button>

      <h1>ColorSystem.io</h1>
      <p style={{ color: colorSystem?.text.secondary.hex }}>
        Secondary text example
      </p>
    </main>
  );
};

Multiple Themes

import useColorSystem from "@colorsystem/react-hooks";
import { useState } from "react";

const Component = () => {
  const [colorSystemId, setColorSystemId] = useState("HE9IHE11");
  const { colorSystem, toggleMode } = useColorSystem(colorSystemId);

  return (
    <main
      style={{
        color: colorSystem?.text.primary.hex,
        backgroundColor: colorSystem?.bg.canvas.hex,
      }}
    >
      {/* Toggle Dark / Light Mode */}
      <button onClick={toggleMode}>Toggle Mode</button>

      {/* Change Theme of site by setting different ColorSystem IDs  */}
      <select
        value={colorSystemId}
        onChange={(e) => setColorSystemId(e.target.value)}
      >
        <option value="HE9IHE11">Default</option>
        <option value="D16KG3H7">Blue</option>
        <option value="0IDA2IML">Green</option>
      </select>

      <h1>ColorSystem.io</h1>
      <p style={{ color: colorSystem?.text.secondary.hex }}>
        Secondary text example
      </p>
    </main>
  );
};

Dynamic Toggle Button Text

import useColorSystem from "@colorsystem/react-hooks";

const Component = () => {
  const { colorSystem, toggleMode, isDarkMode } = useColorSystem("HE9IHE11");

  return (
    <main
      style={{
        color: colorSystem?.text.primary.hex,
        backgroundColor: colorSystem?.bg.canvas.hex,
      }}
    >
      {/* Toggle Dark / Light Mode with dynamic text */}
      <button onClick={toggleMode}>
        Switch to {isDarkMode ? "Light" : "Dark"} Mode
      </button>

      <h1>ColorSystem.io</h1>
      <p style={{ color: colorSystem?.text.secondary.hex }}>
        Secondary text example
      </p>
    </main>
  );
};

Keywords

FAQs

Last updated on 03 Nov 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc