Giter Site home page Giter Site logo

dolanmiu / ng-color Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 6.0 542 KB

Simple Angular color picker components which follow Angular best practices. No Frills.

Home Page: https://stackblitz.com/edit/ng-color-demo

TypeScript 98.06% CSS 0.23% JavaScript 0.94% HTML 0.78%
color-picker ng-color angular colour color angular2 component ng2 picker ngx

ng-color's Introduction

ng-color

Simple embeddable color picker components for Angular following best Angular practices, and good coding standards for easy use and easy contribution.

ng-color ng-color

Color picker components for Angular 2+


Chat on Gitter Build Status code style: prettier

Demos

StackBlitz

https://stackblitz.com/edit/ng-color-demo

Run example folder locally (mac/unix only)

  1. npm install
  2. npm run build
  3. npm start
  4. Go to http://localhost:8080/

Installation

To install this library, run:

$ npm install ng-color --save

How to use

To use this library in your AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { NgColorModule } from 'ng-color';

@NgModule({
    declarations: [AppComponent],
    imports: [
        BrowserModule,
        NgColorModule, // Inlude in @NgModule
    ],
    providers: [],
    bootstrap: [AppComponent],
})
export class AppModule {}

Once your library is imported, you can use the component in your Angular application shown below.

Color Pickers

Box

What it looks like is shown in the header

<ng-color-box [(ngModel)]="color"></ng-color-box>
<ng-color-box (ngModelChange)="colorChange($event)"></ng-color-box>

Circle

What it looks like is shown in the header

<ng-color-circle [(ngModel)]="color"></ng-color-circle>
<ng-color-circle (ngModelChange)="colorChange($event)"></ng-color-circle>

NgModel and setting the initial color

The ngModel is of the following format. You can use two-way or one-way binding:

export interface ColorOutput {
    rgb: Rgb;
    hex: number;
    hexString: string;
    hsl: Hsl;
}

Or equivalently:

export interface ColorOutput {
    rgb: {
        red: number; // 0 - 255
        green: number; // 0 - 255
        blue: number; // 0 - 255
    };
    hex: number; // 0 - 16777215
    hexString: string; // #000000 - #ffffff
    hsl: {
        hue: number; // 0 - 360
        saturation: number; // 0 - 100
        lightness: number; // 0 - 100
    };
}

Setting these partially also works, this library will resolve all the other components out on the next change detection cycle.

Therefore, you can set the initial color of the picker by doing:

this.myColor = {
    hexString: '#ff56d3',
};

In the html:

<ng-color-box [(ngModel)]="myColor"></ng-color-box>

Development

To build using ng-packagr:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT ยฉ Dolan Miu

Made with ๐Ÿ’– by Dolan Miu ๐Ÿ† ๐Ÿ’ฆ ๐Ÿ˜

ng-color's People

Contributors

alimahmood avatar dolanmiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ng-color's Issues

Setting color value

Hi.
It seems I can't set the value of the color composant. Can you add this ? :)
I would like to set this value through an input which contains an hex color
Thanks

StartHex - ExpressionChangedAfterItHasBeenCheckedError

In some cases when using startHex - seems like it depend on color - I got that error - ERROR Error when ngColor picker is displayed - ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '#897A7A'. Current value: '#8A7B7B'.

The value I use in startHex is 897A7A but ngColor module recalculates it to 8A7B7B and then trigger that error message.

I noticed that also colorChange event is called twice.

I'm using color property binding with [startHex]="colorVariable". When I add directly some string to startHex property, the error does not appear.

Cannot Use Template

I receive this error on runtime when starting my application:
Unhandled Promise rejection: Template parse errors: 'ng-color' is not a known element:

When compiling my application, I receive this error:
ERROR in NgColorModule is not an NgModule

I'm using Angular 4.0.1, and I've followed your instructions for including this module as an import.

Angular5 -prod -aot not working

Hi,

currently im using your module and trying to build with -prod and -aot flag. Im getting errors connected with this module. Is there any chance this to be fixed soon ?

Errors:

Uncaught TypeError: e is not a constructor

Warning: (a lot of warning of this type)

/node_modules/ng-color/ng-color.ngfactory.js
107:319-324 "export 'ษตj' (imported as 'i1') was not found in 'ng-color'

ng build --prod failed

when I run command: 'ng build --prod'
I get this ERROR:

ERROR in Error encountered resolving symbol values statically. Expression form not supported (position 13:14 in the original .ts file), resolving symbol ษตe in /home/will/src/workbench2/node_modules/ng-color/ng-color.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/will/src/workbench2/src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts

No problem with 'ng server' and 'ng build'

Initializers are not allowed in ambient contexts.

Typescript Error
Initializers are not allowed in ambient contexts.
...m/node_modules/ng-color/saturation-lightness-box/saturation-lightness-image.d.ts

ย  | export declare const IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAACCCAYAAABSD7T3AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AIWDwksPWR6lgAAIABJREFUeNrtnVuT47gRrAHN+P//Or/61Y5wONZ7mZ1u3XAeLMjJZGZVgdKsfc5xR3S0RIIUW+CHzCpc2McYo7XGv3ex7UiZd57rjyzzv+v+33X/R/+3r/f7vR386Y+TvKNcf/wdhTLPcv9qU2wZd74uth0t1821jkIZLPcsI/6nWa4XvutquU0Z85mnx80S/ZzgpnLnOtHNt7/ofx1TKXcSNzN/7qbMQ3ju7rNQmMYYd/4s2j9aa+P+gGa...

Problem with NPM link and Angular 4

I get the following error message when I try to run the module in Angular 4 using NPM link: Unexpected value 'NgColorModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

Steps to reproduce:
Create a new Angular 4 application.
Git clone the ng-color repo
Run gulp watch in the ng-color repo
cd ./dist and npm link
Go to Angular 4 application and run npm link ng-color

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.