npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-gradient-control

v2.0.0

Published

Angular package that provide one reusable component for change gradient colors value by using mouse dragging.

Downloads

314

Readme

GradientControl

This library was generated with Angular CLI version 16.1.2.

Description

This Package is fully supported with angular's various version and written in angular. This provide simple drag and drop UI for change gradient colors and it's all properties. Package is configurable with multiple directives and support two way binding.

Preview of control

Preview of control

Preview of Delete Area (Red backgrounded) of control :

Preview of control

Live Demo Here

How to Use Package

Import GradientControlModule into your app.module.ts like Below :

import { GradientControlModule } from 'gradient-control';
.
.
@NgModule({
    imports: [
        ...
        GradientControlModule
    ]
});

In Your HTML Template file of angular, Just Use gradient-control selecter like below :

<gradient-control [(colorArray)]="colors"></gradient-control>

Configuration Options

Events

| Event | Return Type | Purpose | | ---------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | colorArrayChange | colorArray [{ color: string, stop: number, stopInPercent: number, id: number }] | fire when any changes in colorArray using control or assignment (=) in binding variable. | | onColorAdd | colorArray (same as above) | This event will Fire when any new color is added via double click on color Ramp. | | onColorRemove | colorArray (same as above) | This event will Fire when any any color is removed via pull color pin into remove area above the color Ramp. | | onColorControlActivate | object { color: string, stop: number, stopInPercent: number, id: number } | fire when select any color pin via click on color pin. | | onColorSlideStart | colorArray (same as above) | Dispatch event when user start sliding color pin. It will fire only once in cycle of dragStart-dragging-dragEnd | | onColorSliding | colorArray (same as above) | Dispatch event while user sliding color pin. It will fire multiple time when any pin move through mouse. second stage of cycle dragStart-dragging-dragEnd | | onColorSlideEnd | colorArray (same as above) | Dispatch event once when user ends sliding color pin. It will fire only once. third stage of cycle dragStart-dragging-dragEnd |

Service

You can Use GradientControlService for convert color array into gradient css.

import service in your component's constructor and Use it's function like below :

import { GradientControlService } from 'gradient-control';
.
.
.
constructor(public gradientService: GradientControlService) {
    .
    .
    .
}

Convert color Array into css :

    GradientControlService.getGradientCss = function(colorArray, Options: gradientCSSOptions<optional> )

    // Where
    Options: gradientCSSOptions = { 
        type: 'Linear' | 'Radial',      @Optional (default: 'Linear')
        angle: number,                  @Optional (default: 0)
        min: number<minColorStop>,      @Optional (default: 0)
        max: number<maxColorStop>       @Optional (default: 1)
        }

Note : If you used minColorStop and maxColorStop property with your custom boundry value in html with control. then you must have to pass that values into this getGradientCss function like this: service.getGradientCss(colorArray, {minColorStop: number, maxColorStop: number, gradientType: 'Linear' | 'Radial', angle: number<0-360> }).then(...)

Note : Don't use function from service that is start with underscore(_). it's for internal use of library. GradientControlService only provice one function that converts color array into css.

/* 
    below function is fire when colorArrayChnage event will fire from conmponent. check live demo and interect with control. you can check console.log in inspect > console.
*/
colorArrayChange(colorArray) {
    console.log("ColorArrayChange Event", colorArray); <== []
    this.gradientService.getGradientCss(colorArray).then(result => {
      this.backgroundCss = result;
    })
  }

In HTML, Background variable used like this :

    <div [ngStyle]="{'background': backgroundCss}">...</div>

Examples

Fully Functional Control look like this :

<gradient-control 
    [minColors]="3"
    [maxColors]="5"
    [minColorStop]="minColorStop"
    [maxColorStop]="maxColorStop"
    (onColorAdd)="onColorAdd($event)" 
    (onColorRemove)="onColorRemove($event)" 
    (onColorControlActivate)="selectPin($event)" 
    (onColorSlideStart)="onColorSlideStart($event)" 
    (onColorSliding)="onColorSliding($event)" 
    (onColorSlideEnd)="onColorSlideEnd($event)"
    [(colorArray)]="colorArray" 
    (colorArrayChange)="colorArrayChange($event)"
></gradient-control>

Js for above control looks like below:


minColorStop: number = 1
minColorStop: number = 100
colorArray: Array<any> = [
    {color: '#fff', stop: 10 },
    {color: '#f0a', stop: 45 },
    {color: '#00c', stop: 70 }
    {color: '#000', stop: 100 }
]
function onColorAdd(colorArray) {...}
function onColorRemove(colorArray) {...}
function selectPin(singleColorObject) {...}
function onColorSlideStart(colorArray) {...}
function onColorSliding(colorArray) {...}
function onColorSlideEnd(colorArray) {...}
function colorArrayChange(colorArray) {...}

You can checkout repo to see full example code with rotation angle and gradient type changes.

In above merged directive, colorArray variable will be automatic update on value changes.

Help

Each and every things that on a internet is written and develop by someone with lot's of efforts and time. You can empower them to do more and best work for others who can freely use that by Buying them a coffee.

Buy me a Coffee

Further help

To get more help on the this Control. Contact me on this email [email protected]