1.4.1 • Published 12 months ago

@ldrender/gradient-picker v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

image

Installation

  npm install @ldrender/gradient-picker

Development or Build

  npm run dev
  npm run build

Usage

import GradientPicker from '@ldrender/gradient-picker';
import '@ldrender/gradient-picker/dist/gradient-picker.css';

const gradientPicker = new GradientPicker({
  el: document.querySelector('#gradient-picker'),
  stops: [
    { color: '#ff0000', offset: 0 },
    { color: '#00ff00', offset: 50 },
    { color: '#0000ff', offset: 100 },
  ],
  directionType: "percent",
})

API Documentation

GradientPicker Instance

new GradientPicker(options: GradientPickerOptions): GradientPicker

Create a new instance of GradientPicker. Your element is replaced by the gradient picker. But an input is created with your element id and the value is the gradient string. You can use this input to send the gradient to your server for example.

If your element is input and he have value then value use to generate colorSteps Value = Methods getGradient(): object

GradientPickerOptions

NameTypeDefault ValueDescription
defaultElementIDThe element where the gradient picker will be created
stops?GradientStop[]The initial stops of the gradient (optional)
directionType?string('select' | 'percent')'select'The type of gradient (optional)
returnType?string('string' | 'object' | 'stops-list' )'string'The type of return value (optional)

GradientStop

NameTypeDescription
id?numberThe id of the stop (optional)
colorstringThe color of the stop
offsetnumberThe position of the stop

GradientPicker Methods

getGradient(): object (returnType: 'object')

Exemple :

{
    "type": "linear",
    "direction": "to right",
    "colorStops": [
        {
            "color": "#ff0000",
            "offset": 0
        },
        {
            "color": "#00ff00",
            "offset": 50
        },
        {
            "color": "#0000ff",
            "offset": 100
        }
    ]
}
getGradientString(): string (returnType: 'string')

Exemple :

linear-gradient(to right, #ff0000 0%, #00ff00 50%, #0000ff 100%)
getStopList(): GradientStop[] (returnType: 'stops-list')

Exemple :

[
    {
        "color": "#ff0000",
        "offset": 0
    },
    {
        "color": "#00ff00",
        "offset": 50
    },
    {
        "color": "#0000ff",
        "offset": 100
    }
]
addColorStop(color: string, offset: number): void

Add a color stop to the gradient.

1.4.1

12 months ago

1.4.0

12 months ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago