|
1 | | -# Advanced-Color-Picker |
2 | | -Translate any CSS Gradient into full controls |
| 1 | +# Advanced Color Picker |
| 2 | +Harnessing the full power of CSS Gradients |
| 3 | + |
| 4 | +[Demo](http://www.codingjack.com/advanced-color-picker/) |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Description |
| 9 | + |
| 10 | +Advanced Color Picker includes full support for modern CSS Gradients, with the ability to translate any valid CSS Gradient into editable controls. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +* **Stacked Gradients** - Bleed semi-transparent gradients into one another |
| 15 | +* **Color Hints** - Change the midpoint transition point between colors |
| 16 | +* **Pixel-based units** - Set positions to percentage or pixel-based values. |
| 17 | +* **Repeating Gradients** - Create interesting patterns with pixel-based units |
| 18 | +* **Conic Gradients** - Experiment with conic gradients supported in Chrome & Safari |
| 19 | +* **Simple Editor Mode** - Can be used for non-gradient editing (text-color, etc.) via "single" mode |
| 20 | +* **Copy/Paste Gradients** - Copy any gradient from the web and paste it into the editor (it's like magic) |
| 21 | + |
| 22 | +## Getting Started |
| 23 | + |
| 24 | +[Download](https://github.com/CodingJack/Advanced-Color-Picker/raw/master/advanced_color_picker.zip) the plugin and copy the files inside the "js" folder to your site. Then add the main script to your web page, setup an input field to be used for the swatch, and "init" the plugin with your custom settings. |
| 25 | + |
| 26 | +## Basic Setup & Options |
| 27 | + |
| 28 | +```html |
| 29 | +<!-- example input field that will be automatically converted to a swatch --> |
| 30 | +<input type="hidden" class="cj-colorpicker" value="linear-gradient(red, blue)" /> |
| 31 | + |
| 32 | +<!-- main script to load --> |
| 33 | +<script type="text/javascript" id="cj-colorpicker" src="js/cj-color.min.js"></script> |
| 34 | +``` |
| 35 | + |
| 36 | +```js |
| 37 | +// initial call with custom settings and their defaults |
| 38 | +window.advColorPicker( { |
| 39 | + // "full" = all controls, "single" = only color controls (no gradients) |
| 40 | + mode: 'full', |
| 41 | + |
| 42 | + // the size of the color picker swatches |
| 43 | + size: 24, |
| 44 | + |
| 45 | + // the color pickjer swatch skin, "classic" or "light" |
| 46 | + skin: 'classic', |
| 47 | + |
| 48 | + // optional color for the modal background |
| 49 | + modalBgColor: 'rgba(0,0,0,0.5)', |
| 50 | + |
| 51 | + // optional id attribute to to apply to the editor's outermost wrapper |
| 52 | + editorId: null, |
| 53 | + |
| 54 | + // allow multi-color stops in output |
| 55 | + // multi-color stops allow for condensed output but are not supported in Edge |
| 56 | + multiStops: true, |
| 57 | + |
| 58 | + // allow conic gradients (only supported in webkit browsers) |
| 59 | + conic: true, |
| 60 | + |
| 61 | + // show a warning note for conic gradients (if conic is enabled) |
| 62 | + conicNote: false, |
| 63 | + |
| 64 | + // show the bar at the bottom of the screen displaying the final output value |
| 65 | + outputBar: false, |
| 66 | + |
| 67 | + // set the value of your input when a color is changed |
| 68 | + onColorChange: ( input, color ) => input.value = color, |
| 69 | + |
| 70 | + // your default and/or custom color presets |
| 71 | + colorPresets: { defaults: [], custom: [] }, |
| 72 | + |
| 73 | + // your default and/or gradient presets |
| 74 | + gradientPresets: { defaults: [], custom: [] }, |
| 75 | + |
| 76 | + // your save/delete preset callback function |
| 77 | + onSaveDeletePreset, |
| 78 | +} ); |
| 79 | +``` |
| 80 | + |
| 81 | +## data-attr options for input fields |
| 82 | +* **type** - "hidden" or "text" required |
| 83 | +* **class** - must match the "inputClass" const inside the index.js source file (currently: "cj-colorpicker") |
| 84 | +* **value** - any valid CSS color (an empty value will translate to "transparent") |
| 85 | +* **data-mode** - "single" (only color controls) or "full" (colors + gradient controls) - default: "full" |
| 86 | +* **data-size** - the width/height of the swatch - default: "24" |
| 87 | +* **data-skin** - "classic" or "light", the swatch skin - default: "classic" |
| 88 | +```html |
| 89 | +<input |
| 90 | + type="hidden" |
| 91 | + class="cj-colorpicker" |
| 92 | + value="linear-gradient(blue, red)" |
| 93 | + data-mode="full" |
| 94 | + data-size="24" |
| 95 | + data-skin="classic" |
| 96 | +/> |
| 97 | +``` |
| 98 | + |
| 99 | +## Example "onColorChange" callback |
| 100 | +```js |
| 101 | +const onColorChange = ( input, color ) => input.value = color; |
| 102 | +``` |
| 103 | + |
| 104 | +## Example "onSaveDeletePreset" callback |
| 105 | +```js |
| 106 | +const onSaveDeletePreset = ( { |
| 107 | + action, // "save" or "delete" |
| 108 | + groupChanged, // "color" or "gradient" |
| 109 | + colorPresets, // the current custom color presets array |
| 110 | + gradientPresets, // the current custom gradient presets array |
| 111 | +} ) => { |
| 112 | + // example saving to local storage |
| 113 | + window.localStorage.setItem( 'presets', JSON.stringify( { |
| 114 | + colorPresets, |
| 115 | + gradientPresets, |
| 116 | + })); |
| 117 | +}; |
| 118 | +``` |
| 119 | + |
| 120 | +## Link to the Demo and open the editor automatically with a custom value |
| 121 | +``` |
| 122 | +// encode the value beforehand via encodeURIComponent() |
| 123 | +http://www.codingjack.com/advanced-color-picker/?open=true&value=linear-gradient(blue%2C%20red) |
| 124 | +``` |
| 125 | + |
| 126 | +## Editing JS/SCSS source files |
| 127 | +``` |
| 128 | +npm install |
| 129 | +npm run watch |
| 130 | +npm run build |
| 131 | +``` |
| 132 | + |
| 133 | +## Built With / Techology Used |
| 134 | + |
| 135 | +* [React](https://www.npmjs.com/package/react) |
| 136 | +* [SASS](https://www.npmjs.com/package/sass) |
| 137 | +* [Babel](https://www.npmjs.com/package/@babel/core) |
| 138 | +* [Webpack](https://www.npmjs.com/package/webpack) |
| 139 | +* [ESLint](https://www.npmjs.com/package/eslint) |
| 140 | +* [core-js](https://www.npmjs.com/package/core-js) |
| 141 | +* [array-move](https://www.npmjs.com/package/array-move) |
| 142 | +* [color-convert](https://github.com/Qix-/color-convert) |
| 143 | +* [React Sortable HOC](https://www.npmjs.com/package/react-sortable-hoc) |
| 144 | +* [Material Icons](https://www.npmjs.com/package/material-icons) |
| 145 | + |
| 146 | +## Authors |
| 147 | + |
| 148 | +* **Jason McElwaine** - *Initial work* - [CodingJack](http://www.codingjack.com) |
| 149 | + |
| 150 | +## License |
| 151 | + |
| 152 | +* The original work in this project is licensed under [MIT](https://opensource.org/licenses/MIT) |
| 153 | +* All dependencies and cited technology above excluding Material Icons is licensed under [MIT](https://opensource.org/licenses/MIT) |
| 154 | +* [Material Icons](https://www.npmjs.com/package/material-icons) is licensed under [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) |
| 155 | + |
| 156 | +## Considerations |
| 157 | + |
| 158 | +If used in cases where all browsers must be accounted for, disable the "multiStops" and "conic" options. |
0 commit comments