0.1.9 • Published 3 years ago

ngx-color-selector v0.1.9

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

ngx-color-selector

UPDATED TO ANGULAR 10/11

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

npm.io npm.io

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

npm.io

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.

OptionTypeDefaultDescription
paletteIColor[]Flat ColorsAn array of predefined IColor objects to display on the palette. Some pre-made collections using colors from htmlcolorcodes.com are provided.
directionPaletteDirection (enum)Columns (1)Direction to fill the color palette, either rows first or columns first
itemSizeISwatchSize{height: 20, width: 20}Size of each swatch on the palette, and used for the preview color
itemsPernumber10Number of items to display before moving to the next row or column
positionPalettePosition (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.

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago