use-luminance
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

use-luminance

introduction

use-luminance is a simple, fast, and efficient luminance calculation hook.

it use the useDeferredValue hook to calculate the luminance of a color.

it can also provide a useTheme hook to calculate current theme based on the luminance of background-color.

Tips

this package is only support for React18.To use it,you must upgrade your react version to 18.

install

with npm

npm install --save use-luminance

with yarn

yarn add use-luminance

usage

import { useLuminance } from "use-luminance";

function App() {
  const luminance = useLuminance(color);
  return <div>{luminance}</div>;
}
import { useTheme } from "use-luminance";

function App() {
  const theme = useTheme(color);
  return <div>{theme}</div>;
}

API

  • useLuminance(color: string):number
  • useTheme(color: string):'light'|'dark'

color is a string, it can be a rbg string or a hex color.Be careful,color name is not supported.

demo

click me to view

licence

MIT

Package Sidebar

Install

npm i use-luminance

Weekly Downloads

3

Version

0.1.3

License

MIT

Unpacked Size

16.3 kB

Total Files

27

Last publish

Collaborators

  • tohsaka888