Giter Club home page Giter Club logo

colorpicker's Introduction

Colorpicker ๐ŸŽจ

A multi format Colorpicker built with Svelte. The Colorpicker accepts and sets hex(a), rgb(a) and hsl(a) colors.

Image

Features

  • Choose your color by clicking or dragging on a palette.
  • Set the hue and opacity of your chosen color using Slider controls.
  • Convert your selected color to your preferred color format (hexa, rgba, hsla).
  • Set your color by typing into an input.
  • A swatch panel for keeping track of recent colours or for passing favourite colors so they can be easily set again.
  • Handy keyboard events to tab through control panel, set colors and close the Colorpicker.
  • Colorpicker anchors to its preview element which displays the selected color and acts as a button to display the Colorpicker.
  • Viewport positional awareness - the colorpicker centers by default but will adapt and position itself appropriately based on available space.
  • Colorpicker renders outside the dom structure which prevents problems with overflow clipping in scrolling containers.

Installation

  1. Navigate to your project in the terminal.
  2. Run yarn add @budibase/colorpicker.
  3. Or use npm npm i @budibase/colorpicker.

Usage

import Colorpicker from "@budibase/colorpicker"

<Colorpicker
  //must be a valid color supported by Colorpicker (hsl(a), hex(a) or rgb(a))
  value="#abc" 
  //An array of 12 or less swatches for use in the Colorpicker panel.
  swatches=["#abc2", "rgba(255,2,100,0.5)", "hsl(360,50,50)"] 
  //disable swatches for the Colorpicker. Defaults to false
  disableSwatches={true | false} 
  //Open or close the Colorpicker. Defaults to false
  open={true | false} 
  //width of the Colorpreview. Defaults to 25px
  width="25px" 
  //height of the Colorpreview. Defaults to 25px
  height="25px"
  //change event - invoked when color has been selected
  on:change={selectedColor => {}}
  //remove swatch - invoked when swatch has been removed
  on:removeswatch={removedSwatch => {})}
  //add swatch event - invoked when a swatch has been added
  on:addswatch={addedSwatch => {}}
  />

Events

The Colorpicker exposes the following events. In each case, the color will be provided as the first parameter to the bound function.

Change Event on:change={selectedColor: string => {}} The on change event will be invoked whenever a color has been set in the Colorpicker via the palette, the hue slider, the alpha slider or by typing into the input.

Add Swatch on:addswatch={addedSwatch: string => {}} The add swatch event will be invoked when a user adds a swatch by clicking the add button.

Remove Swatch on:removeswatch={removedSwatch: string => {}} The remove swatch will be invoked when a user clicks the delete button that appears when hovering over a swatch.

Swatches

  • By default, added swatches are saved to local storage so that they can be displayed across all Colorpickers in your application.
  • Only 12 or less swatches can be displayed in the Coloricker at any any one time.
  • If more than 12 have been passed the Colorpicker will display the first 12 and warn in the console.
  • An array of swatches can be passed to the Colorpicker to set up a dedicated panel of swatches. This will use provided swatches instead of locally stored swatches. Swatches added will still be saved to local storage.
  • You can disable swatch functionality by passing the disableSwatches={true} property to the Colorpicker.

colorpicker's People

Contributors

conor-mack 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.