Giter Club home page Giter Club logo

ngx-color-selector's Introduction

ngx-color-selector

UPDATED TO ANGULAR 10/11

FORKED FROM https://github.com/bytelabsco/ngx-color-selector

ngx-color-selector provides a simple interface for selecting from a predefined set of colors.

Demo

Clone the repository and run

npm install    
npm run playground

then navigate in a browser to

http://localhost:3000

Installation

npm install --save ngx-color-selector

Getting Started

Import the BytelabsColorSelectorModule in your application module:

import { NgModule } from '@angular/core';

// ... Other imports

import { BytelabsColorSelectorModule } from 'sngx-color-selector';

@NgModule({
	imports: [
	// ...
	BytelabsColorSelectorModule
	],
	/...
})
export class AppModule {}

In your component, set up a variable to store your color:

import { Component } from '@angular/core';

import { IColor } from 'ngx-color-selector';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css']
})
export class AppComponent {

	public currentColor: IColor = {
		hex: "#000"
	}
}

In your template, use the component:

<bytelabs-color-selector [(color)]="currentColor"></bytelabs-color-selector>

Options

The following options are defined in IColorSelectorConfig and a basic implementation is provided in ColorSelectorConfig using reasonable defaults from the constant COLOR_SELECTOR_CONFIG_DEFAULTS. Those can all be found in the color-selector-config.ts file.

Option Type Default Description
palette IColor[] Flat Colors An array of predefined IColor objects to display on the palette. Some pre-made collections using colors from htmlcolorcodes.com are provided.
direction PaletteDirection (enum) Columns (1) Direction to fill the color palette, either rows first or columns first
itemSize ISwatchSize {height: 20, width: 20} Size of each swatch on the palette, and used for the preview color
itemsPer number 10 Number of items to display before moving to the next row or column
position PalettePosition (enum) BottomRight (3) Position to place the palette, relative to the preview color, when displayed

PaletteDirection Enum

Rows,					// 0
Columns					// 1

PalettePosition Enum

TopLeft,				// 0
TopRight,				// 1
BottomLeft;				// 2
BottomRight				// 3

Overriding Defaults

In your component you can create a variable to hold your custom options, or you can provide them directly to the component in your template:

import { Component } from '@angular/core';

import { IColorSelectorConfig, IColor, PalettePosition } from 'ngx-color-selector';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',s
	styleUrls: ['./app.component.css']
})
export class AppComponent {

	// You can just provide an object containing the options you want to override
	public colorSelectorOptions : IColorSelectorConfig = {
		position: PalettePosition.BottomLeft
	};

	public currentColor: IColor = {
		hex: "#000"
	}
}

In your template, pass your option overrides with the component:

<bytelabs-color-selector [(color)]="currentColor" [options]="colorSelectorOptions" ></bytelabs-color-selector>

Or just provide your overrides in the template:

<bytelabs-color-selector [(color)]="currentColor" [options]="{itemsPer: 5}" ></bytelabs-color-selector>

Credits

jvandemo/generator-angular2-library for their excellent Angular2 Library Yeoman Generator

HTMLColorCodes.com for the pre-made color charts.

Shout-out to scoutzfiction

LICENSE

This project is licensed under the MIT license. Se the LICENSE for more info.

ngx-color-selector's People

Contributors

bytelabsco avatar alisalama avatar

Watchers

James Cloos avatar  avatar

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.