New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tokens-studio/color-picker

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tokens-studio/color-picker

Colorjs.io-based color picker as a reusable webcomponent

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

Colorjs.io Picker

NPM version badge License badge

Colorjs.io color picker as a reusable Web Component.

This is a Web Component port of the VueJS picker from Colorjs.io so that it can be used in an encapsulated and reusable manner.

Click here for the demo

Installation

With NPM:

npm install @tokens-studio/color-picker

Usage

// import the Web Component class and define it yourself
import { TSColorPicker } from '@tokens-studio/color-picker';
// or optionally pre-register it and use <ts-color-picker>
import '@tokens-studio/color-picker/define';
<ts-color-picker space="hsl"></ts-color-picker>

The space attribute can be passed optionally to set the initial color space.

Reactive props

The following properties can be manually set as well which will cause re-renders:

nametypedefaultdescription
spaceIdstring'hsl'The id of the color space, same type as "space" attribute for setting the initial ColorSpace
coordsArray<number> (3)[50, 50 ,50]Coordinates/channels e.g. for hsl: hue, saturation, lightness
alphanumber1Alpha channel value of the color
precisionnumber3Precision for outputting the colors

The easiest way to set the color programmatically, if you're not sure about coords and you've only got the color as CSS string:

import Color from 'colorjs.io';

const cssString = "rgb(255, 0, 0)";
const colorPickerEl = document.querySelector('ts-color-picker');
const color = new Color(cssString);
const converted = color.to(colorPickerEl.spaceId);
colorPickerEl.coords = converted.coords;
colorPickerEl.alpha = converted.alpha * 100;

Bare import specifiers

This Web Component is published to NPM as an ES Module. It's usable in any modern JavaScript context out of the box with the exception that it uses bare import specifiers, for example:

import { render } from 'lit';

By default, browsers won't know how to resolve the specifier 'lit', only absolute and relative paths are allowed.

This means you either need:

  • a bundler like Rollup (needs @rollup/plugin-node-resolve)
  • a smart dev server like Vite
  • inject an import map that tells the browser how to resolve the specifier

The easiest solution if you're not familiar with bundlers and dev servers is to create an import map e.g. using JSPM.

If you've installed this module from NPM into your local project:

npx jspm install -p nodemodules @tokens-studio/color-picker

Which creates an importmap.json file, the contents of which you can put inside an importmap script in your HTML:

<script type="importmap">
... import map contents here ...
</script>

Alternatively, if you don't want to install from NPM locally and would rather just consume from a CDN:

npx jspm install @tokens-studio/color-picker

Keywords

FAQs

Package last updated on 11 Jul 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc