@sajtempler/react-hooks

1.0.6 • Public • Published

Build and Test

Useful React hooks

  • useColorPair() - generate background color and pick text color with correct contrast, from any string input

Installation

npm i @sajtempler/react-hooks

or

yarn add @sajtempler/react-hooks

Usage

useColorPair

Generate background color and pick text color with correct contrast, from any string input.

import { useColorPair } from "@sajtempler/react-hooks";

const App = () => {
  const [input, setInput] = useState("");

  /**
   * @type {{ color: string, backgroundColor: string }}
   */
  const { color, backgroundColor } = useColorPair(input);

  return (
    <input
      style={{ color, backgroundColor }}
      value={input}
      onChange={(e) => setInput(e.target.value)}
    />
  );
};

image

add two more "!!"

image

Development

Running tests requires node >= 16 due to crypto.webcrypto for SHA-1 digest.

Package Sidebar

Install

npm i @sajtempler/react-hooks

Weekly Downloads

0

Version

1.0.6

License

ISC

Unpacked Size

5.28 kB

Total Files

6

Last publish

Collaborators

  • sajtempler