JSFiddle - React, Tailwind, and code Playground
by bgrins
HTML
<link rel="stylesheet" href="http://bgrins.github.com/spectrum/spectrum.css">
<a href='http://bgrins.github.com/spectrum'><--Spectrum Homepage</a>
<h2>Local storage</h2>
<input type='text' />
<br/><br/>
1:<br/>
Choose 3 custom colors.<br/>
Notice that the new custom colors appear in the third row of the palette.<br/>
<br/>
2:<br/>
Then choose one of the 6 predefined colors.<br/>
Notice that the last local stored custom color dissappear from the list.<br/>
Choose 3 predefined colors, and all local stored colors dissappear!<br/>
CSS
.full-spectrum .sp-palette {
max-width: 200px;
}
JavaScript
// Spectrum Colorpicker v1.3.1
// https://github.com/bgrins/spectrum
// Author: Brian Grinstead
// License: MIT
(function (window, $, undefined) {
var defaultOpts = {
// Callbacks
beforeShow: noop,
move: noop,
change: noop,
show: noop,
hide: noop,
// Options
color: false,
flat: false,
showInput: false,
allowEmpty: false,
showButtons: true,
clickoutFiresChange: false,
showInitial: false,
showPalette: false,
showPaletteOnly: false,
showSelectionPalette: true,
localStorageKey: false,
appendTo: "body",
maxSelectionSize: 7,
cancelText: "cancel",
chooseText: "choose",
clearText: "Clear Color Selection",
preferredFormat: false,
className: "",
showAlpha: false,
theme: "sp-light",
palette: [["#ffffff", "#000000", "#ff0000", "#ff8000", "#ffff00", "#008000", "#0000ff", "#4b0082", "#9400d3"]],
selectionPalette: [],
disabled: false
},
spectrums = [],
IE = !!/msie/i.exec( window.navigator.userAgent ),
rgbaSupport = (function() {
function contains( str, substr ) {
return !!~('' + str).indexOf(substr);
}
var elem = document.createElement('div');
var style = elem.style;
style.cssText = 'background-color:rgba(0,0,0,.5)';
return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla');
})(),
inputTypeColorSupport = (function() {
var colorInput = $("<input type='color' value='!' />")[0];
return colorInput.type === "color" && colorInput.value !== "!";
})(),
replaceInput = [
"<div class='sp-replacer'>",
"<div class='sp-preview'><div class='sp-preview-inner'></div></div>",
"<div class='sp-dd'>▼</div>",
"</div>"
].join(''),
markup = (function () {
//...