Element Framework

Color Dialog

  • HTML
  • JS
  • CSS
<ef-color-dialog id="d1" opened></ef-color-dialog>
<div class="dialog-container">
  <button onclick="openDialog()">Open Color Dialog</button>
</div>
function openDialog() {
  var dlg = document.getElementById('d1');
  dlg.opened = true;
}
.dialog-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 450px;
}

ef-color-dialog allows users to select any color. You can set the value as a hex color code (short hex is also supported) or as Red/Green/Blue (0 - 255). Users can choose a color directly from a pallete UI or via input boxes in the dialog.

Basic usage

Color dialog can be opened and closed just like any popup window, by setting the attribute/property opened.

<ef-color-dialog opened id="colorDialog"></ef-color-dialog>

Preset default value

Color Dialog also accepts an initial color value. To set the default value, use the value attribute.

  • HTML
  • JS
  • CSS
<ef-color-dialog id="d1" opened value="#9966ff"></ef-color-dialog>
<div class="dialog-container">
  <button onclick="openDialog()">Open Color Dialog</button>
</div>
function openDialog() {
  var dlg = document.getElementById('d1');
  dlg.opened = true;
}
.dialog-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 450px;
}
<ef-color-dialog value="#9966ff"></ef-color-dialog>

'No Color' option

In some circumstances, it might be necessary for the component to allow a user to select "no color." This option can be activated using the allow-nocolor property/attribute.

When users select "no color" from the UI, the color dialog sets the attribute/property value to null.

  • HTML
  • JS
  • CSS
<ef-color-dialog id="d1" opened allow-nocolor></ef-color-dialog>
<div class="dialog-container">
  <button onclick="openDialog()">Open Color Dialog</button>
</div>
var d1 = document.getElementById('d1');

function openDialog() {
  var dlg = document.getElementById('d1');
  dlg.opened = true;
}
.dialog-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 450px;
}
<ef-color-dialog allow-nocolor></ef-color-dialog>

API Reference

Attributes

boolean
allow-nocolor
Set the palettes to activate no-color option
string
value
Value of selected color from color dialog will be written here as hex value e.g. "#00f" or "#0000ff"
string
hex
Value of hex without # sign, supports both 3-digits shorthand hex and regular 6-digits hex
string
red
Red value from 0 to 255
string
green
Green value from 0 to 255
string
blue
Blue value from 0 to 255
string|null
header
Set Header/Title of the color dialog
boolean
opened
Set dialog to open
string
x
Set a specific x coordinate of dialog
string
y
Set a specific y coordinate of dialog
boolean
no-cancel-on-esc-key
Prevents dialog to close when user presses ESC key
string
position-target
Set position of dialog i.e. `top`, `right`, `left`, `bottom`, `center` or combination of theme e.g. `top right`.

Properties

boolean
allowNocolor
Set the palettes to activate no-color option
false
string
value
Value of selected color from color dialog will be written here as hex value e.g. "#00f" or "#0000ff"
""
string
hex
Value of hex without # sign, supports both 3-digits shorthand hex and regular 6-digits hex
""
string
red
Red value from 0 to 255
""
string
green
Green value from 0 to 255
""
string
blue
Blue value from 0 to 255
""
string|null
header
Set Header/Title of the color dialog
boolean
opened
Set dialog to open
false
boolean
noCancelOnEscKey
Prevents dialog to close when user presses ESC key
false
string
x
Set a specific x coordinate of dialog
string
y
Set a specific y coordinate of dialog
string
positionTarget
Set position of dialog i.e. `top`, `right`, `left`, `bottom`, `center` or combination of theme e.g. `top right`.
boolean
noCancelOnOutsideClick
Prevents dialog to close when user clicks outside the dialog.
true
boolean
withBackdrop
False to hide backdrop.
true
boolean
draggable
False to make the dialog not draggable.
true
boolean
withShadow
False to remove shadow for dialog component.
true

Events

value-changed
Fired when the `value` property changes.
opened-changed
Fired when the `opened` property changes.