1.0.6 • Published 2 years ago

@sajtempler/react-hooks v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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.

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago