npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tiagotrindade/solid-colorful

v1.0.2

Published

🎨 A tiny (2,8 KB) color picker component for SolidJS apps. Fast, well-tested, dependency-free, mobile-friendly and accessible

Downloads

27

Readme

Features

  • 🗜 Small: Just 3.9 KB gzipped (10x lighter than react-color).
  • 🌳 Tree-shakeable: Only the parts you use will be imported into your app's bundle.
  • 🚀 Fast: Built with hooks and functional components only.
  • 🛡 Bulletproof: Written in strict TypeScript.
  • 🗂 Typed: Ships with types included
  • 😍 Simple: The interface is straightforward and easy to use.
  • 👫 Cross-browser: Works out-of-the-box for most browsers, regardless of version.
  • 📲 Mobile-friendly: Supports mobile devices and touch screens.
  • 💬 Accessible: Follows the WAI-ARIA guidelines to support users of assistive technologies.
  • 💨 No dependencies

Live demos

Table of Contents

Getting Started

npm install solid-colorful
import { HexColorPicker } from "@tiagotrindade/solid-colorful"

const YourComponent = () => {
  const [color, setColor] = createSignal("#aabbcc")
  return <HexColorPicker color={color()} onChange={setColor} />
}

Supported Color Models

We provide 12 additional color picker components for different color models, unless your app needs a HEX string as an input/output format.

Available pickers

| Import | Value example | | --------------------------- | ---------------------------------- | | { HexColorPicker } | "#ffffff" | | { RgbColorPicker } | { r: 255, g: 255, b: 255 } | | { RgbaColorPicker } | { r: 255, g: 255, b: 255, a: 1 } | | { RgbStringColorPicker } | "rgb(255, 255, 255)" | | { RgbaStringColorPicker } | "rgba(255, 255, 255, 1)" | | { HslColorPicker } | { h: 0, s: 0, l: 100 } | | { HslaColorPicker } | { h: 0, s: 0, l: 100, a: 1 } | | { HslStringColorPicker } | "hsl(0, 0%, 100%)" | | { HslaStringColorPicker } | "hsla(0, 0%, 100%, 1)" | | { HsvColorPicker } | { h: 0, s: 0, v: 100 } | | { HsvaColorPicker } | { h: 0, s: 0, v: 100, a: 1 } | | { HsvStringColorPicker } | "hsv(0, 0%, 100%)" | | { HsvaStringColorPicker } | "hsva(0, 0%, 100%, 1)" |

Code example

import { RgbColorPicker } from "@tiagotrindade/solid-colorful"

const YourComponent = () => {
  const [color, setColor] = createSignal({ r: 50, g: 100, b: 150 })
  return <RgbColorPicker color={color} onChange={setColor} />
}

Live demo →

Customization

The easiest way to tweak solid-colorful is to create another stylesheet to override the default styles.

.your-component .solid-colorful {
  height: 240px;
}
.your-component .solid-colorful__saturation {
  border-radius: 4px 4px 0 0;
}
.your-component .solid-colorful__hue {
  height: 40px;
  border-radius: 0 0 4px 4px;
}
.your-component .solid-colorful__hue-pointer {
  width: 12px;
  height: inherit;
  border-radius: 0;
}

See examples →

How to paste or type a color?

As you probably noticed the color picker itself does not include an input field, but do not worry if you need one. solid-colorful is a modular library that allows you to build any picker you need. Since v2.1 we provide an additional component that works perfectly in pair with our color picker.

import { HexColorPicker, HexColorInput } from "@tiagotrindade/solid-colorful"

const YourComponent = () => {
  const [color, setColor] = createSignal("#aabbcc")
  return (
    <div>
      <HexColorPicker color={color()} onChange={setColor} />
      <HexColorInput color={color()} onChange={setColor} />
    </div>
  )
}

Live demo →

| Property | Default | Description | | ---------- | ------- | -------------------------------------------- | | alpha | false | Allows #rgba and #rrggbbaa color formats | | prefixed | false | Enables # prefix displaying |

HexColorInput does not have any default styles, but it also accepts all properties that a regular input tag does (such as class, placeholder and autoFocus). That means you can place and modify this component as you like. Also, that allows you to combine the color picker and input in different ways:

<HexColorInput color={color} onChange={setColor} placeholder="Type a color" prefixed alpha />

Code Recipes

TypeScript Support

solid-colorful supports TypeScript and ships with types in the library itself; no need for any other install.

While not only typing its own functions and variables, it can also help you type yours. Depending on the component you are using, you can also import the type that is associated with the component. For example, if you are using our HSL color picker component, you can also import the HSL type.

import { HslColorPicker, HslColor } from "@tiagotrindade/solid-colorful";

const myHslValue: HslColor = { h: 0, s: 0, l: 0 };

Take a look at Supported Color Models for more information about the types and color formats you may want to use.

Browser Support

It would be an easier task to list all of the browsers and versions that solid-colorful does not support! We regularly test against browser versions going all the way back to 2013 and this includes IE11.

solid-colorful works out-of-the-box for most browsers, regardless of version, and only requires an Object.assign polyfill be provided for full IE11 support.

Why solid-colorful?

Today each dependency drags more dependencies and increases your project’s bundle size uncontrollably. But size is very important for everything that intends to work in a browser.

solid-colorful is a simple color picker for those who care about their bundle size and client-side performance. It is fast and lightweight because:

  • has no dependencies (no risks in terms of vulnerabilities, no unexpected bundle size changes);
  • built with hooks and functional components only (no classes and polyfills for them);
  • ships only a minimal amount of manually optimized color conversion algorithms (while most of the popular pickers import entire color manipulation libraries that increase the bundle size by more than 10 KB and make your app slower).

To show you the problem that solid-colorful is trying to solve, we have performed a simple benchmark (using bundlephobia.com) against popular React color picker libraries:

| Name | Bundle size | Bundle size (gzip) | Dependencies | | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | solid-colorful | | | | | react-color | | | | | react-input-color | | | | | rc-color-picker | | | |