Color Picker - 图1

Color Picker

Framework7 comes with ultimate modular Color Picker component that allows to create color picker with limitless combinations of “color modules”.

Color Picker App Methods

Let’s look at related App methods to work with Color Picker:

app.colorPicker.create(parameters)- create Color Picker instance

  • parameters - object. Object with Color Picker parameters

Method returns created Color Picker instance

app.colorPicker.destroy(el)- destroy Color Picker instance

  • el - HTMLElement or string (with CSS Selector) or object. Color Picker element or Color Picker instance to destroy.

app.colorPicker.get(el)- get Color Picker instance by HTML element

  • el - HTMLElement or string (with CSS Selector). Color Picker element.

Method returns Color Picker’s instance

app.colorPicker.close(el)- close Color Picker

  • el - HTMLElement or string (with CSS Selector). Color Picker element to close.

Method returns Color Picker’s instance

For example:

  1. var colorPicker = app.colorPicker.create({
  2. inputEl: '#color-input',
  3. value: {
  4. hex: '#ff000',
  5. },
  6. });

Color Picker Parameters

Let’s look on list of all available Color Picker parameters:

ParameterTypeDefaultDescription
valueobjectObject with Color Picker value
modulesarray[‘wheel’]Array with Color Picker modules in order of their appearance
palettearray

Array with palette module colors where each palette color must be specified as a HEX string.

It can be a plain array with palette values like:

  1. palette: [‘#ff0000’, ‘#00ff00’, …]

Or it can be an array of palette “rows” where each item specified as array with colors:

  1. palette: [
  2. // first row
  3. [‘#ff0000’, ‘#00ff00’, …]
  4. // second row
  5. [‘#0000ff’, ‘#f0000f’, …]
  6. ]

By default it is:

  1. [
  2. [‘#FFEBEE’, ‘#FFCDD2’, ‘#EF9A9A’, ‘#E57373’, ‘#EF5350’, ‘#F44336’, ‘#E53935’, ‘#D32F2F’, ‘#C62828’, ‘#B71C1C’],
  3. [‘#F3E5F5’, ‘#E1BEE7’, ‘#CE93D8’, ‘#BA68C8’, ‘#AB47BC’, ‘#9C27B0’, ‘#8E24AA’, ‘#7B1FA2’, ‘#6A1B9A’, ‘#4A148C’],
  4. [‘#E8EAF6’, ‘#C5CAE9’, ‘#9FA8DA’, ‘#7986CB’, ‘#5C6BC0’, ‘#3F51B5’, ‘#3949AB’, ‘#303F9F’, ‘#283593’, ‘#1A237E’],
  5. [‘#E1F5FE’, ‘#B3E5FC’, ‘#81D4FA’, ‘#4FC3F7’, ‘#29B6F6’, ‘#03A9F4’, ‘#039BE5’, ‘#0288D1’, ‘#0277BD’, ‘#01579B’],
  6. [‘#E0F2F1’, ‘#B2DFDB’, ‘#80CBC4’, ‘#4DB6AC’, ‘#26A69A’, ‘#009688’, ‘#00897B’, ‘#00796B’, ‘#00695C’, ‘#004D40’],
  7. [‘#F1F8E9’, ‘#DCEDC8’, ‘#C5E1A5’, ‘#AED581’, ‘#9CCC65’, ‘#8BC34A’, ‘#7CB342’, ‘#689F38’, ‘#558B2F’, ‘#33691E’],
  8. [‘#FFFDE7’, ‘#FFF9C4’, ‘#FFF59D’, ‘#FFF176’, ‘#FFEE58’, ‘#FFEB3B’, ‘#FDD835’, ‘#FBC02D’, ‘#F9A825’, ‘#F57F17’],
  9. [‘#FFF3E0’, ‘#FFE0B2’, ‘#FFCC80’, ‘#FFB74D’, ‘#FFA726’, ‘#FF9800’, ‘#FB8C00’, ‘#F57C00’, ‘#EF6C00’, ‘#E65100’],
  10. ]
groupedModulesbooleanfalseWhen enabled it will add more exposure to sliders modules to make them look more separated
centerModulesbooleantrueWhen enabled it will try to center vertically modules if there is enough space
sliderLabelbooleanfalseWhen enabled, it will display sliders labels with text
sliderValuebooleanfalseWhen enabled, it will display sliders values
sliderValueEdiablebooleanfalseWhen enabled, it will display sliders values as <input> elements to edit directly
barLabelbooleanfalseWhen enabled, it will display bars labels with text
barValuebooleanfalseWhen enabled, it will display bars values
barValueEdiablebooleanfalseWhen enabled, it will display bars values as <input> elements to edit directly
hexLabelbooleanfalseWhen enabled, it will display HEX module label text, e.g. HEX
hexValueEditablebooleanfalseWhen enabled, it will display HEX module value as <input> element to edit directly
Labels Texts
redLabelTextstring‘R’Red slider/bar label text
greenLabelTextstring‘G’Green slider/bar label text
blueLabelTextstring‘B’Blue slider/bar label text
hueLabelTextstring‘H’Hue slider label text
saturationLabelTextstring‘S’Saturation slider label text
brightnessLabelTextstring‘B’Brightness slider label text
hexLabelTextstring‘HEX’
alphaLabelTextstring‘A’Alpha (opacity) slider label text
formatValuefunction (value)Function to format input value, should return new/formatted string value. value is the Color Picker value object. By default it returns HEX value.
Container/opener-specific parameters
containerElstring
HTMLElement
String with CSS selector or HTMLElement where to place generated Color Picker HTML. Use only for inline color picker
openInstringpopoverCan be auto, popover (to open color picker in popover), sheet (to open in sheet modal), popup (to open in Popup) or page (to open in Page). In case of auto it will as specified openInPhone parameter on small screens and in popover on large screens.
openInPhonestringpopupDefines how to open Color Picker on small screens when openIn: “auto”
inputElstring or HTMLElementString with CSS selector or HTMLElement with related input element
targetElstring or HTMLElementString with CSS selector or HTMLElement with related target element. In addition to input element, you will probably want to place additional element that displays currently selected color. Such element can be specified as target element. If Color Picker opened in Popover, it will be positioned around this target element. Click on specified target element will also open Color Picker.
targetElSetBackgroundColorbooleanfalseWhen enabled and you have passed targetEl then it will set background-color with currently selected value to target element.
scrollToInputbooleantrueScroll viewport (page-content) to input when color picker opened
inputReadOnlybooleantrueSets “readonly” attribute on specified input
cssClassstringAdditional CSS class name to be set on color picker container
closeByOutsideClickbooleantrueIf enabled, picker will be closed by clicking outside of picker or related input element
toolbarSheetbooleantrueDisplays Toolbar when opened in Sheet modal
toolbarPopoverbooleanfalseDisplays Toolbar when opened in Popover modal
toolbarCloseTextstringDoneText for Done/Close toolbar button
navbarPopupbooleantrueDisplays Navbar when opened in Popup modal
navbarCloseTextstringDoneText for Done/Close navbar button
navbarTitleTextstringColorNavbar title’s text
navbarBackLinkTextstringBackNavbar back link’s text, available when Color Picker opened in Page
routableModalsbooleantrueWill add opened color picker to router history which gives ability to close it by going back in router history and set current route to the color picker modal
urlstringcolor/Color Picker modal URL that will be set as a current route
viewobjectView where to set routing when routableModals enabled. Defaults to parent view of inputEl or main view if not found parent view
backdropbooleanEnables Color Picker backdrop (dark semi transparent layer behind). By default it is enabled when Color Picker opened in Popover or Popup.
closeByBackdropClickbooleantrueWhen enabled, Color Picker will be closed on backdrop click
Render Functions
renderToolbarfunctionFunction to render toolbar. Must return toolbar HTML string
renderNavbarfunction(date)Function to render navbar. Must return navbar HTML string
renderfunctionFunction to render color picker. Must return full color picker HTML string
Events
onobjectObject with events handlers. For example:
  1. var colorPicker = app.colorPicker.create({
  2. on: {
  3. opened: function () {
  4. console.log(‘Color Picker opened’)
  5. }
  6. }
  7. })

Note that all following parameters can be used in global app parameters under colorPicker property to set defaults for all color pickers. For example:

  1. var app = new Framework7({
  2. colorPicker: {
  3. modules: ['hb-spectrum', 'hue-slider'],
  4. url: 'select-color/',
  5. }
  6. });

Color Picker Modules

You can create your own Color Picker layout by specifing modules you want to use in modules array parameter on Color Picker creation. There are following modules available:

wheel

Hue weel with Saturation-Brightness spectrum inside

Color Picker - 图2

sb-spectrum

Saturation-Brightness spectrum. It is recommended to use it with hue-slider

Color Picker - 图3

hue-slider

Single hue slider

Color Picker - 图4

hs-spectrum

Hue-Saturation spectrum. It is recommended to use it with brightness-slider

Color Picker - 图5

brightness-slider

Single brightness slider

Color Picker - 图6

rgb-sliders

Red, green and blue sliders

Color Picker - 图7

hsb-sliders

Hue, saturation and brightness sliders

Color Picker - 图8

alpha-slider

Alpha (opacity) single slider

Color Picker - 图9

rgb-bars

Vertical red, green and blue sliders

Color Picker - 图10

palette

Module displays palette colors specified in palette parameter

Color Picker - 图11

hex

Module with current HEX value

Color Picker - 图12

current-color

Modules displays currently selected color

Color Picker - 图13

initial-current-colors

Modules displays currently selected color, and initial color (color that was selected before Color Picker was opened). Clicking on initial color will set Color Picker value to initial color.

Color Picker - 图14

Custom Modules

It is also possible to use and create custom color picker modules. Such custom modules can be used to create custom pickers or just to add some custom content between modules.

To add custom color picker module, we need to pass an object instead of string to modules array parameter. Custom module object can contain following methods. Each method receives color picker instance as an argument.

render(colorPicker)Module render function. It must return module HTML content
init(colorPicker)Module init function. It is executed when module rendered and added to DOM. You should define here any custom event listeners
update(colorPicker)This method executed when color picker value updated
destroy(colorPicker)This method executed on module destroy. You should detach all event listeners here

For, example if we need to add some custom text between modules, we can use such simple module:

  1. var colorPicker = app.colorPicker.create({
  2. // ...
  3. modules: [
  4. 'sb-spectrum',
  5. // custom module with only render function
  6. {
  7. render: function() {
  8. return '<p class="text-align-center">Enter HUE value:</p>'
  9. },
  10. },
  11. 'hue-slider',
  12. ]
  13. })

For inspiration and how things work in modules, check the built-in modules source code.

Color Picker Value

Color Picker instance value represented as Object with the following properties.

hexstringHEX color value, e.g. #ff0000
rgbarrayArray with RGB ([Red, Green, Blue]) color, e.g. [255, 100, 20]
hslarrayArray with HSL ([Hue, Saturation, Lightness]) color, e.g. [320, 0.1, 0.9]
hsbarrayArray with HSB/V ([Hue, Saturation, Brightness]) color, e.g. [180, 0.5, 0.3]
alphanumberAlpha (opacity) value (from 0 to 1), e.g. 0.6
huenumberHue value (from 0 to 360), e.g. 320
rgbaarrayArray with RGBA ([Red, Green, Blue, Alpha]) color, e.g. [255, 100, 20, 0.5]
hslaarrayArray with HSLA ([Hue, Saturation, Lightness, Alpha]) color, e.g. [320, 0.1, 0.9, 0.2]

For example:

  1. var colorPicker = app.colorPicker.create({
  2. ...
  3. on: {
  4. change: function (value) {
  5. console.log(`HEX value is ${value.hex}. Opacity is ${value.alpha}`);
  6. $('.some-element').css('background-color', `rgba(${value.rgba.join(', ')})`);
  7. }
  8. }
  9. })

Color Picker Methods & Properties

After we initialize Color Picker we have its initialized instance in variable (like colorPicker variable in examples above) with helpful methods and properties:

Properties
colorPicker.appLink to global app instance
colorPicker.containerElColor Picker wrapping container HTML element (when inline color picker is in use)
colorPicker.$containerElDom7 instance with color picker wrapping container HTML element (when inline color picker is in use)
colorPicker.elColor Picker HTML element
colorPicker.$elDom7 instance with color picker HTML element
colorPicker.inputElColor Picker input HTML element (passed in inputEl parameter)
colorPicker.$inputElDom7 instance with color picker input HTML element (passed in inputEl parameter)
colorPicker.targetElColor Picker target HTML element (passed in targetEl parameter)
colorPicker.$targetElDom7 instance with color picker target HTML element (passed in targetEl parameter)
colorPicker.valueObject with color picker value
colorPicker.openedtrue if color picker is currently opened
colorPicker.inlinetrue when inline color picker is in use
colorPicker.urlColor Picker URL (that was passed in url parameter)
colorPicker.viewColor Picker View (that was passed in view parameter) or found parent view
colorPicker.paramsObject with initialization parameters
Methods
colorPicker.setValue(value)Set new color picker value. value is the color picker value object which can be specified partially:
  1. var colorPicker = app.colorPicker.create({
  2. value: ‘#ff0000’,
  3. });
  4. // update only hue
  5. colorPicker.setValue({ hue: 200 });
  6. // update only alpha
  7. colorPicker.setValue({ alpha: 0.2 });
  8. // set value by hex
  9. colorPicker.setValue({ hex: ‘#ff00ff });
colorPicker.getValue()Returns current color picker value
colorPicker.update()Updates color picker modules layout (when opened or inline)
colorPicker.open()Open Color Picker
colorPicker.close()Close Color Picker
colorPicker.destroy()Destroy Color Picker instance and remove all events
colorPicker.on(event, handler)Add event handler
colorPicker.once(event, handler)Add event handler that will be removed after it was fired
colorPicker.off(event, handler)Remove event handler
colorPicker.off(event)Remove all handlers for specified event
colorPicker.emit(event, …args)Fire event on instance

Color Picker Events

Color Picker will fire the following DOM events on color picker element and events on app andcolor picker instance:

DOM Events

EventDescription
colorpicker:openEvent will be triggered when Color Picker starts its opening animation
colorpicker:openedEvent will be triggered after Color Picker completes its opening animation
colorpicker:closeEvent will be triggered when Color Picker starts its closing animation
colorpicker:closedEvent will be triggered after Color Picker completes its closing animation

App and Color Picker Instance Events

Color Picker instance emits events on both self instance and app instance. App instance events has same names prefixed with colorPicker.

EventTargetArgumentsDescription
changecolorPicker(colorPicker, value)Event will be triggered when color picker value changes
colorPickerChangeapp
initcolorPicker(colorPicker)Event will be triggered when color picker initialized
colorPickerInitapp
opencolorPicker(colorPicker)Event will be triggered when Color Picker starts its opening animation. As an argument event handler receives color picker instance
colorPickerOpenapp
openedcolorPicker(colorPicker)Event will be triggered after Color Picker completes its opening animation. As an argument event handler receives color picker instance
colorPickerOpenedapp
closecolorPicker(colorPicker)Event will be triggered when Color Picker starts its closing animation. As an argument event handler receives color picker instance
colorPickerCloseapp
closedcolorPicker(colorPicker)Event will be triggered after Color Picker completes its closing animation. As an argument event handler receives color picker instance
colorPickerClosedapp
beforeDestroycolorPicker(colorPicker)Event will be triggered right before Color Picker instance will be destroyed. As an argument event handler receives color picker instance
colorPickerBeforeDestroyapp

CSS Variables

Below is the list of related CSS variables (CSS custom properties).

  1. :root {
  2. --f7-color-picker-sheet-bg-color: #fff;
  3. --f7-color-picker-popup-bg-color: #fff;
  4. --f7-color-picker-popover-width: 350px;
  5. --f7-color-picker-slider-size: 6px;
  6. --f7-color-picker-slider-knob-size: 16px;
  7. --f7-color-picker-bar-size: 50px;
  8. --f7-color-picker-bar-min-height: 260px;
  9. --f7-color-picker-value-bg-color: rgba(0, 0, 0, 0.05);
  10. --f7-color-picker-value-width: 64px;
  11. --f7-color-picker-value-height: 32px;
  12. --f7-color-picker-value-font-size: 16px;
  13. --f7-color-picker-value-border-radius: 4px;
  14. --f7-color-picker-hex-value-width: 84px;
  15. --f7-color-picker-label-font-size: 14px;
  16. --f7-color-picker-label-width: 10px;
  17. --f7-color-picker-label-height: 14px;
  18. --f7-color-picker-sb-spectrum-height: 260px;
  19. --f7-color-picker-sb-spectrum-handle-size: 16px;
  20. --f7-color-picker-wheel-width: 330px;
  21. --f7-color-picker-group-bg-color: rgba(0, 0, 0, 0.05);
  22. --f7-color-picker-group-value-bg-color: #fff;
  23. --f7-color-picker-palette-value-width: 36px;
  24. --f7-color-picker-palette-value-height: 36px;
  25. --f7-color-picker-initial-current-color-height: 40px;
  26. --f7-color-picker-initial-current-color-border-radius: 4px;
  27. }
  28. :root .theme-dark,
  29. :root.theme-dark {
  30. --f7-color-picker-sheet-bg-color: #171717;
  31. --f7-color-picker-popup-bg-color: #171717;
  32. --f7-color-picker-value-bg-color: rgba(255, 255, 255, 0.1);
  33. --f7-color-picker-group-bg-color: #000;
  34. --f7-color-picker-group-value-bg-color: rgba(255, 255, 255, 0.12);
  35. }

Examples

Color Wheel

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-wheel-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-wheel"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerWheel = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-wheel',
  3. targetEl: '#demo-color-picker-wheel-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['wheel'],
  6. openIn: 'popover',
  7. value: {
  8. hex: '#00ff00',
  9. },
  10. });

Saturation-Brightness Spectrum

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-spectrum-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-spectrum"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerSpectrum = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-spectrum',
  3. targetEl: '#demo-color-picker-spectrum-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['sb-spectrum', 'hue-slider'],
  6. openIn: 'popover',
  7. value: {
  8. hex: '#ff0000',
  9. },
  10. });

Hue-Saturation Spectrum

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-hs-spectrum-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-hs-spectrum"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerHsSpectrum = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-hs-spectrum',
  3. targetEl: '#demo-color-picker-hs-spectrum-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['hs-spectrum', 'brightness-slider'],
  6. openIn: 'popover',
  7. value: {
  8. hex: '#ff0000',
  9. },
  10. });

RGB Sliders

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-rgb-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-rgb"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerRgb = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-rgb',
  3. targetEl: '#demo-color-picker-rgb-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['rgb-sliders'],
  6. openIn: 'popover',
  7. sliderValue: true,
  8. sliderLabel: true,
  9. value: {
  10. hex: '#0000ff',
  11. },
  12. });

RGBA Sliders

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-rgba-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-rgba"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerRgba = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-rgba',
  3. targetEl: '#demo-color-picker-rgba-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['rgb-sliders', 'alpha-slider'],
  6. openIn: 'popover',
  7. sliderValue: true,
  8. sliderLabel: true,
  9. value: {
  10. hex: '#ff00ff',
  11. },
  12. formatValue: function (value) {
  13. return 'rgba(' + value.rgba.join(', ') + ')';
  14. },
  15. });

HSB Sliders

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-hsb-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-hsb"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerHsb = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-hsb',
  3. targetEl: '#demo-color-picker-hsb-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['hsb-sliders'],
  6. openIn: 'popover',
  7. sliderValue: true,
  8. sliderLabel: true,
  9. formatValue: function (value) {
  10. return 'hsb(' + value.hsb[0] + (', ' + value.hsb[1] * 1000 / 10 + '%') + (', ' + value.hsb[2] * 1000 / 10 + '%') + ')';
  11. },
  12. value: {
  13. hex: '#00ff00',
  14. },
  15. });

RGB Bars

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-rgb-bars-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-rgb-bars"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerRgbBars = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-rgb-bars',
  3. targetEl: '#demo-color-picker-rgb-bars-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['rgb-bars'],
  6. openIn: 'auto',
  7. barValue: true,
  8. barLabel: true,
  9. formatValue: function (value) {
  10. return 'rgb(' + value.rgb.join(', ') + ')';
  11. },
  12. value: {
  13. hex: '#0000ff',
  14. },
  15. });

RGB Sliders + Colors

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-rgb-initial-current-colors-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-rgb-initial-current-colors"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerRgbInitialCurrentColors = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-rgb-initial-current-colors',
  3. targetEl: '#demo-color-picker-rgb-initial-current-colors-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['initial-current-colors', 'rgb-sliders'],
  6. openIn: 'popover',
  7. sliderValue: true,
  8. sliderLabel: true,
  9. formatValue: function (value) {
  10. return 'rgb(' + value.rgb.join(', ') + ')';
  11. },
  12. value: {
  13. hex: '#ffff00',
  14. },
  15. });

Palette

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-palette-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-palette"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerPalette = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-palette',
  3. targetEl: '#demo-color-picker-palette-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['palette'],
  6. openIn: 'auto',
  7. openInPhone: 'sheet',
  8. palette: [
  9. ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C'],
  10. ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24AA', '#7B1FA2', '#6A1B9A', '#4A148C'],
  11. ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949AB', '#303F9F', '#283593', '#1A237E'],
  12. ['#E1F5FE', '#B3E5FC', '#81D4FA', '#4FC3F7', '#29B6F6', '#03A9F4', '#039BE5', '#0288D1', '#0277BD', '#01579B'],
  13. ['#E0F2F1', '#B2DFDB', '#80CBC4', '#4DB6AC', '#26A69A', '#009688', '#00897B', '#00796B', '#00695C', '#004D40'],
  14. ['#F1F8E9', '#DCEDC8', '#C5E1A5', '#AED581', '#9CCC65', '#8BC34A', '#7CB342', '#689F38', '#558B2F', '#33691E'],
  15. ['#FFFDE7', '#FFF9C4', '#FFF59D', '#FFF176', '#FFEE58', '#FFEB3B', '#FDD835', '#FBC02D', '#F9A825', '#F57F17'],
  16. ['#FFF3E0', '#FFE0B2', '#FFCC80', '#FFB74D', '#FFA726', '#FF9800', '#FB8C00', '#F57C00', '#EF6C00', '#E65100'],
  17. ],
  18. value: {
  19. hex: '#FFEBEE',
  20. },
  21. formatValue: function (value) {
  22. return value.hex;
  23. },
  24. });

Pro Mode

  1. <div class="list no-hairlines-md">
  2. <ul>
  3. <li>
  4. <div class="item-content item-input">
  5. <div class="item-media">
  6. <i class="icon demo-list-icon" id="demo-color-picker-pro-value"></i>
  7. </div>
  8. <div class="item-inner">
  9. <div class="item-input-wrap">
  10. <input type="text" placeholder="Color" readonly="readonly" id="demo-color-picker-pro"/>
  11. </div>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  1. var colorPickerRgbPro = app.colorPicker.create({
  2. inputEl: '#demo-color-picker-pro',
  3. targetEl: '#demo-color-picker-pro-value',
  4. targetElSetBackgroundColor: true,
  5. modules: ['initial-current-colors', 'sb-spectrum', 'hsb-sliders', 'rgb-sliders', 'alpha-slider', 'hex', 'palette'],
  6. openIn: 'auto',
  7. sliderValue: true,
  8. sliderValueEditable: true,
  9. sliderLabel: true,
  10. hexLabel: true,
  11. hexValueEditable: true,
  12. groupedModules: true,
  13. palette: [
  14. ['#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C'],
  15. ['#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24AA', '#7B1FA2', '#6A1B9A', '#4A148C'],
  16. ['#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949AB', '#303F9F', '#283593', '#1A237E'],
  17. ['#E1F5FE', '#B3E5FC', '#81D4FA', '#4FC3F7', '#29B6F6', '#03A9F4', '#039BE5', '#0288D1', '#0277BD', '#01579B'],
  18. ['#E0F2F1', '#B2DFDB', '#80CBC4', '#4DB6AC', '#26A69A', '#009688', '#00897B', '#00796B', '#00695C', '#004D40'],
  19. ['#F1F8E9', '#DCEDC8', '#C5E1A5', '#AED581', '#9CCC65', '#8BC34A', '#7CB342', '#689F38', '#558B2F', '#33691E'],
  20. ['#FFFDE7', '#FFF9C4', '#FFF59D', '#FFF176', '#FFEE58', '#FFEB3B', '#FDD835', '#FBC02D', '#F9A825', '#F57F17'],
  21. ['#FFF3E0', '#FFE0B2', '#FFCC80', '#FFB74D', '#FFA726', '#FF9800', '#FB8C00', '#F57C00', '#EF6C00', '#E65100'],
  22. ],
  23. formatValue: function (value) {
  24. return 'rgba(' + value.rgba.join(', ') + ')';
  25. },
  26. value: {
  27. hex: '#00ffff',
  28. },
  29. });

Inline Color Picker

  1. <div class="block block-strong no-padding">
  2. <div id="demo-color-picker-inline"></div>
  3. </div>
  1. var colorPickerInline = app.colorPicker.create({
  2. containerEl: '#demo-color-picker-inline',
  3. modules: ['sb-spectrum', 'hsb-sliders', 'alpha-slider'],
  4. value: {
  5. hex: '#77ff66',
  6. },
  7. });