• Stars
    star
    433
  • Rank 100,464 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎨 Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more
Angular color sketch preview

Angular Color


npm codecov


DEMO: https://ngx-color.vercel.app

About

  • 13 Different Pickers - Sketch, Photoshop, Chrome, Twitter and many more

  • Make Your Own - Use the building block components to make your own

  • This is a port of react-color by casesandberg

Getting Started

Dependencies

Latest version available for each version of Angular

ngx-color Angular
4.1.1 8.x
5.1.4 9.x
6.2.0 10.x 11.x
7.3.3 12.x 13.x
8.0.3 14.x 15.x
current >= 16.x

Install

npm install ngx-color --save

Include Component

import
import { ColorSketchModule } from 'ngx-color/sketch';

@NgModule({
  imports: [
    ColorSketchModule, // added to imports
  ],
})
class YourModule {}
use
<color-sketch [color]="state" (onChangeComplete)="changeComplete($event)"></color-sketch>

Others available

import { ColorAlphaModule } from 'ngx-color/alpha'; // <color-alpha-picker></color-alpha-picker>
import { ColorBlockModule } from 'ngx-color/block'; // <color-block></color-block>
import { ColorChromeModule } from 'ngx-color/chrome'; // <color-chrome></color-chrome>
import { ColorCircleModule } from 'ngx-color/circle'; // <color-circle></color-circle>
import { ColorCompactModule } from 'ngx-color/compact'; // <color-compact></color-compact>
import { ColorGithubModule } from 'ngx-color/github'; // <color-github></color-github>
import { ColorHueModule } from 'ngx-color/hue'; // <color-hue-picker></color-hue-picker>
import { ColorMaterialModule } from 'ngx-color/material'; // <color-material></color-material>
import { ColorPhotoshopModule } from 'ngx-color/photoshop'; // <color-photoshop></color-photoshop>
import { ColorSketchModule } from 'ngx-color/sketch'; // <color-sketch></color-sketch>
import { ColorSliderModule } from 'ngx-color/slider'; // <color-slider></color-slider>
import { ColorSwatchesModule } from 'ngx-color/swatches'; // <color-swatches></color-swatches>
import { ColorTwitterModule } from 'ngx-color/twitter'; // <color-twitter></color-twitter>
import { ColorShadeModule } from 'ngx-color/shade'; // <color-shade-picker></color-shade-picker>

Component API

Color

Color controls what color is active on the color picker. You can use this to initialize the color picker with a particular color, or to keep it in sync with the state of a parent component.

Color accepts either a string of a hex color '#333' or a object of rgb or hsl values { r: 51, g: 51, b: 51 } or { h: 0, s: 0, l: .10 }. Both rgb and hsl will also take a a: 1 value for alpha. You can also use transparent.

<color-sketch color="#fff" (onChangeComplete)="handleChangeComplete($event)"></color-sketch>

In this case, the color picker will initialize with the color #fff. When the color is changed, handleChangeComplete will fire and set the new color to state.

onChange

Pass a function to call every time the color is changed. Use this to store the color in the state of a parent component or to make other transformations.

Keep in mind this is called on drag events that can happen quite frequently. If you just need to get the color once use onChangeComplete.

import { Component } from '@angular/core';
import { ColorEvent } from 'ngx-color';

@Component({
  selector: 'selector-name',
  template: ` <color-sketch (onChange)="handleChange($event)"></color-sketch> `,
})
export class NameComponent {
  constructor() {}

  handleChange($event: ColorEvent) {
    console.log($event.color);
    // color = {
    //   hex: '#333',
    //   rgb: {
    //     r: 51,
    //     g: 51,
    //     b: 51,
    //     a: 1,
    //   },
    //   hsl: {
    //     h: 0,
    //     s: 0,
    //     l: .20,
    //     a: 1,
    //   },
    // }
  }
}

onChangeComplete

Pass a function to call once a color change is complete.

Individual APIs

Some pickers have specific APIs that are unique to themselves:

Alpha

  • width - String | Number, Pixel value for picker width. Default 316px
  • height - String | Number, Pixel value for picker height. Default 16px
  • direction - String, horizontal or vertical. Default horizontal

Block

  • width - string | number, Pixel value for picker width. Default 170px
  • colors - Array of Strings, Color squares to display. Default ['#D9E3F0', '#F47373', '#697689', '#37D67A', '#2CCCE4', '#555555', '#dce775', '#ff8a65', '#ba68c8']
  • triangle - String, Either hide or top. Default top
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Chrome

  • disableAlpha - Bool, Remove alpha slider and options from picker. Default false

Circle

  • width - String | number, Pixel value for picker width. Default 252px
  • colors - Array of Strings, Color squares to display. Default ["#f44336", "#e91e63", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4caf50", "#8bc34a", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#795548", "#607d8b"]
  • circleSize - Number, Value for circle size. Default 28
  • circleSpacing - Number, Value for spacing between circles. Default 14
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Compact

  • colors - Array of Strings, Color squares to display. Default ['#4D4D4D', '#999999', '#FFFFFF', '#F44E3B', '#FE9200', '#FCDC00', '#DBDF00', '#A4DD00', '#68CCCA', '#73D8FF', '#AEA1FF', '#FDA1FF', '#333333', '#808080', '#cccccc', '#D33115', '#E27300', '#FCC400', '#B0BC00', '#68BC00', '#16A5A5', '#009CE0', '#7B64FF', '#FA28FF', '#000000', '#666666', '#B3B3B3', '#9F0500', '#C45100', '#FB9E00', '#808900', '#194D33', '#0C797D', '#0062B1', '#653294', '#AB149E']
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Github

  • width - string | number, Pixel value for picker width. Default 212px
  • colors - Array of Strings, Color squares to display. Default ['#B80000', '#DB3E00', '#FCCB00', '#008B02', '#006B76', '#1273DE', '#004DCF', '#5300EB', '#EB9694', '#FAD0C3', '#FEF3BD', '#C1E1C5', '#BEDADC', '#C4DEF6', '#BED3F3', '#D4C4FB']
  • triangle - String, Either hide, top-left or top-right. Default top-left
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Hue

  • width - string | number, Pixel value for picker width. Default 316px
  • height - string | number, Pixel value for picker height. Default 16px
  • direction - String Enum, horizontal or vertical. Default horizontal

Material

None

Photoshop

  • header - String, Title text. Default Color Picker
  • onAccept - (Output), Callback for when accept is clicked.
  • onCancel - (Output), Callback for when cancel is clicked.

Sketch

  • disableAlpha - Bool, Remove alpha slider and options from picker. Default false
  • presetColors - Array of Strings or Objects, Hex strings for default colors at bottom of picker. Default ['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']

    presetColors may also be described as an array of objects with color and title properties: [{ color: '#f00', title: 'red' }] or a combination of both

  • width - Number, Width of picker. Default 200
  • onSwatchHover - An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Slider

  • pointer - React Component, Custom pointer component

Swatches

  • width - string | number, Pixel value for picker width. Default 320
  • height - string | number, Pixel value for picker height. Default 240
  • colors - Array of Arrays of Strings, An array of color groups, each with an array of colors
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Twitter

  • width - string | number, Pixel value for picker width. Default 276px
  • colors - Array of Strings, Color squares to display. Default ['#FF6900', '#FCB900', '#7BDCB5', '#00D084', '#8ED1FC', '#0693E3', '#ABB8C3', '#EB144C', '#F78DA7', '#9900EF']
  • triangle - String, Either hide, top-left or top-right. Default top-left
  • onSwatchHover - (Output) An event handler for onMouseOver on the <Swatch>s within this component. Gives the args (color, event)

Shade

  • width - String | Number, Pixel value for picker width. Default 316px
  • height - String | Number, Pixel value for picker height. Default 16px

GitHub @scttcper  ·  Twitter @scttcper

More Repositories

1

ngx-toastr

🍞 Angular Toastr
TypeScript
2,503
star
2

tinycolor

🎨 Color manipulation and conversion
TypeScript
543
star
3

gatsby-casper

A Casper blog starter for Gatsby
TypeScript
478
star
4

ngx-emoji-mart

Customizable Slack-like emoji picker for Angular
TypeScript
448
star
5

ngx-codemirror

Codemirror Wrapper for Angular
TypeScript
281
star
6

ng2-adsense

Angular Adsense Component
TypeScript
137
star
7

ngx-trend

📈 Simple, elegant spark lines for Angular
TypeScript
117
star
8

react-adsense

Adsense component for react
TypeScript
95
star
9

ngx-rightclick

Context Menu Service for Angular
TypeScript
81
star
10

ts-trueskill

TypeScript port of the python TrueSkill package
TypeScript
73
star
11

video-filename-parser

Scene release name parser
TypeScript
57
star
12

ngx-chartjs

Functional Chart.js wrapper for Angular
TypeScript
56
star
13

qbittorrent

qBittorrent api wrapper
TypeScript
42
star
14

ngx-csv

Angular directive to generate a CSV download in the browser
TypeScript
38
star
15

ngx-droppable

Give file dropping super-powers to any element or component
TypeScript
34
star
16

deluge

Deluge API wrapper
TypeScript
27
star
17

transmission

Transmission torrent client API wrapper
TypeScript
21
star
18

plex

Plex API client for node written in typescript
TypeScript
18
star
19

golang-template

basic golang template parsing in js
TypeScript
18
star
20

gatsby-theme-casper

TypeScript
17
star
21

koa-simple-ratelimit

Simple rate limiter for Koa.js v2 web framework
TypeScript
17
star
22

magnet-link

Parse a magnet URI into an object
TypeScript
15
star
23

ts-base32

Base32 encoder/decoder with support for multiple variants
TypeScript
13
star
24

ngx-github-buttons

GitHub Buttons in Angular
TypeScript
11
star
25

torrent-file

TypeScript torrent file parser
TypeScript
11
star
26

honbot-api

HoN 4 compatible API
TypeScript
8
star
27

react-orgchart

JavaScript
8
star
28

irc

Irc client library for node
TypeScript
7
star
29

utorrent

utorrent api wrapper
TypeScript
6
star
30

shared-torrent

shared types and interfaces between torrent clients
TypeScript
5
star
31

typescript-quickstart-lib

TypeScript
5
star
32

xm-channel-scrape

5
star
33

ts-gaussian

TypeScript model of the normal distribution
TypeScript
5
star
34

honbot-frontend

Angular frontend for HoN stats website
TypeScript
4
star
35

mac-address

Parse and manipulate MAC addresses
TypeScript
4
star
36

ngx-numbered-codeblock

Prism.js wrapper with built-in line numbers
TypeScript
3
star
37

hangry-py

python port of https://github.com/iancanderson/hangry
Python
2
star
38

url-join

TypeScript
2
star
39

eslint-config

JavaScript
1
star
40

shared-nzb

TypeScript
1
star
41

ts-wcwidth

Determine number of columns needed for a fixed-size wide-character string
TypeScript
1
star
42

gatsby-theme-casper-example

JavaScript
1
star
43

rtorrent

rtorrent api wrapper
TypeScript
1
star
44

csv-fns

TypeScript
1
star
45

version-adoption

NPM package download count by version over the last 7 days - grouped by major and minor version
TypeScript
1
star
46

eslint-config-react

JavaScript
1
star
47

eslint-config-biome

JavaScript
1
star
48

ng2-bs-dropdown

DEPRECATED: use ng-bootstrap
TypeScript
1
star
49

eslint-config-react-biome

JavaScript
1
star