Detalhes do pacote

vanilla-picker

Sphinxxxx1.5mISC2.12.3

A simple, easy to use vanilla JS color picker with alpha selection.

ux, ui, color, colour

readme (leia-me)

vanilla-picker

License Version Size Downloads

A simple, easy to use vanilla JS (no dependencies) color picker with alpha selection.

Demo

https://codepen.io/Sphinxxxx/pen/zRmKBX

Getting Started

Installing

  • For the pros:

    • npm install vanilla-picker --save
    • import Picker from 'vanilla-picker';
  • For the rest of us:

<script src="https://unpkg.com/vanilla-picker@2"></script>

Note:

The script adds a <style> element to the page, with all the needed CSS. If your site's Content Security Policy doesn't allow that, use the CSP build with a separate CSS file instead:

import Picker from 'vanilla-picker/csp';
import 'vanilla-picker/dist/vanilla-picker.csp.css';

..or

<script src="vanilla-picker.csp.min.js"></script>
<link  href="vanilla-picker.csp.css" rel="stylesheet">

Usage

<div id="parent">Click me</div>

<script>

    /*
        Create a new Picker instance and set the parent element.
        By default, the color picker is a popup which appears when you click the parent.
    */
    var parent = document.querySelector('#parent');
    var picker = new Picker(parent);

    /*
        You can do what you want with the chosen color using two callbacks: onChange and onDone.
    */
    picker.onChange = function(color) {
        parent.style.background = color.rgbaString;
    };

    /* onDone is similar to onChange, but only called when you click 'Ok' */

</script>

API and advanced options

https://vanilla-picker.js.org/gen/Picker.html

Accessibility

The color picker is built to support basic keyboard navigation and use with screen readers. I would be very interested in feedback on improvements that could be done here!

Credits

License

The ISC license - see the LICENSE.md file for details.

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

2.12.2 - 2023-08-20

Fixed

  • export TypeScript types.

2.12.1 - 2021-10-28

Fixed

  • More exports from package.json.

2.12.0 - 2021-10-27

Added

  • vanilla-picker.csp.js for sites with strict CSP settings (#45).

2.11.2 - 2021-01-23

Fixed

  • Updated TypeScript definitions (#38, #42).

2.11.0 - 2020-11-12

Added

  • TypeScript declaration (#37).

2.10.1 - 2019-12-29

Added

  • options.defaultColor (#29).

Changed

  • Clarified documentation.

2.10.0 - 2019-09-03

Added

  • destroy() (#14).

2.9.2 - 2019-07-23

Fixed

  • More relevant CSS prefixes.
  • Transpiled ES module (#22).

2.9.1 - 2019-07-17

Fixed

  • Normalized CSS for input and button (#21).

2.9.0 - 2019-06-28

Added

  • options.cancelButton (#18).

2.8.2 - 2019-06-28

Fixed

  • Simpler mouse/touch interaction. Fixes #19.

2.8.1 - 2019-06-09

Fixed

  • Text field interaction.

2.8.0 - 2019-04-19

Added

  • Shadow DOM support (#15).

Fixed

  • Better event handling when closing the popup (#17).

2.7.2 - 2019-01-24

Fixed

  • Removed double onChange event (#11).

2.7.1 - 2019-01-11

Added

  • CSS vendor prefixes with Autoprefixer.

Changed

  • Updated dependencies.

2.7.0 - 2018-11-12

Added

  • options.editorFormat (#7).

2.6.0 - 2018-10-05

Fixed

  • Make an ES6 module that actually works.

2.5.3 - 2018-10-03

Changed

  • Minor documentation changes.

2.5.2 - 2018-09-14

Fixed

  • Focusing and mouse interaction.

2.5.1 - 2018-09-13

Fixed

  • Bug in setColor().

2.5.0 - 2018-09-13

Added

  • Keyboard navigation and basic accessibility.

2.4.3 - 2018-09-09

Added

  • README changes.

2.4.2 - 2018-09-06

Added

  • js.org domain.

2.4.1 - 2018-09-03

Changed

  • Minor documentation changes.

2.4.0 - 2018-09-02

Added

  • movePopup(): Share a picker among multiple parents.
  • silent flag in setColor() (#4).
  • JSDoc documentation.

2.3.0 - 2018-08-16

Added

  • onOpen/onClose callbacks when the popup opens and closes.

2.2.1 - 2018-05-21

Removed

2.2.0 - 2018-05-20

Added

  • Supports CSS color names as input.

2.1.0 - 2018-04-10

Added

  • Text field for color input.
  • This CHANGELOG file.

Changed

  • Separate layout CSS for easier customization.

2.0.2 - 2018-04-05

Added

  • Build scripts for development.

2.0.1 - 2018-03-24

Fixed

  • CSS fix for Firefox (#1).

2.0.0 - 2018-03-24

Major changes from https://github.com/dissimulate/Picker

  • Multiple instances
  • Touch support
  • Enable/disable alpha
  • .setColor()
  • Inline styles replaced with CSS for easier customization