Example of API in ASP.NET MVC ColorPicker Control
This sample demonstrates customization of the ColorPicker component by using its properties from the property pane. Select any combination of properties from the property pane to customize the ColorPicker component.
Choose a color
Value
Mode
Disable
Show Buttons
Show Switcher
@Html.UiColorPicker("color-picker", new UiColorPickerOptions { Value = "#0db1e7", OnChange = "onChange" })
@Html.UiDropDownList("ddl", new UiDropDownListOptions { Width = "110px", Value = "Picker", OnChange = "valueChanged", Items = ((IEnumerable<InputsDemoController.ColorModeList>)ViewData["data"]).Select(g => new UiListItem(g.Id, g.Mode)).ToList() })
@Html.UiCheckBox("disabled", false, new UiCheckBoxOptions { Id = "disabled", OnChange = "disabled_onChange" })
@Html.UiCheckBox("button", true, new UiCheckBoxOptions { Id = "button", OnChange = "button_onChange" })
@Html.UiCheckBox("mode-switch", true, new UiCheckBoxOptions { Id = "mode-switch", OnChange = "mode_onChange" })
<style>
#default-control, #inline-control, #custom-control, #colorpicker-control { text-align: center; padding: 20px 0; }
#default-control h4, #colorpicker-control h4, #inline-control h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.color-preview { width: 120px; height: 80px; margin: 0 auto 16px; border: 1px solid var(--ui-border); border-radius: 8px; background: #008000; }
.color-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 110px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div id="colorpicker-control">
<h4>Choose a color</h4>
@Html.UiColorPicker("color-picker", new UiColorPickerOptions { Value = "#0db1e7", OnChange = "onChange" })
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Value</span> <input id="hex-value" value="#0db1e7" maxlength="9" spellcheck="false" type="text" class="prop-input" /></div>
<div class="property-row"><span>Mode</span> @Html.UiDropDownList("ddl", new UiDropDownListOptions { Width = "110px", Value = "Picker", OnChange = "valueChanged", Items = ((IEnumerable<InputsDemoController.ColorModeList>)ViewData["data"]).Select(g => new UiListItem(g.Id, g.Mode)).ToList() })</div>
<div class="property-row"><span>Disable</span> @Html.UiCheckBox("disabled", false, new UiCheckBoxOptions { Id = "disabled", OnChange = "disabled_onChange" })</div>
<div class="property-row"><span>Show Buttons</span> @Html.UiCheckBox("button", true, new UiCheckBoxOptions { Id = "button", OnChange = "button_onChange" })</div>
<div class="property-row"><span>Show Switcher</span> @Html.UiCheckBox("mode-switch", true, new UiCheckBoxOptions { Id = "mode-switch", OnChange = "mode_onChange" })</div>
</div>
<script>
// Syncfusion: the panel sets the value, the mode, the disabled state and the buttons of the colour picker
function picker() { return window.Lumen.get('color-picker'); }
function onChange(args) { document.getElementById('hex-value').value = args.value; }
function inputChange() { picker().setValue(document.getElementById('hex-value').value); }
document.getElementById('hex-value').addEventListener('input', inputChange);
function valueChanged(value) { if (value) { picker().setMode(value); } }
function disabled_onChange(checked) { picker()[checked ? 'disable' : 'enable'](); }
function button_onChange(checked) { picker().setShowButtons(checked); }
function mode_onChange(checked) { picker().setModeSwitcher(checked); }
</script>
<script>
(function (window, document) {
'use strict';
document.querySelector('.input-actions').addEventListener('click', function (event) {
var action = event.target.getAttribute('data-input-action');
var control = window.Lumen.get('inputApi');
if (!action || !control) { return; }
if (action === 'set') { control.setValue('#09af74'); }
else if (action === 'state') { window.InputSampleLog('Color present: ' + !!control.getValue()); return; }
else if (action === 'enabled') { control[control.isEnabled() ? 'disable' : 'enable'](); }
else if (action === 'show') { control.show(); }
else if (action === 'hide') { control.hide(); }
else if (action === 'toggle') { control.toggle(); }
else if (action === 'focus') { control.focus(); }
window.InputSampleLog('API action: ' + action);
});
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ColorPickerController : Controller
{
// The page is Views/ColorPicker/Api.cshtml; it draws what ViewData holds.
public ActionResult Api()
{
ViewData["data"] = new ColorModeList().ColorPickerModeModel();
return View();
}
public class ColorModeList
{
public string Id { get; set; }
public string Mode { get; set; }
public List<ColorModeList> ColorPickerModeModel()
{
List<ColorModeList> game = new List<ColorModeList>();
game.Add(new ColorModeList { Id = "Picker", Mode = "Picker" });
game.Add(new ColorModeList { Id = "Palette", Mode = "Palette" });
return game;
}
}
private ActionResult Show(string method)
{
InputSample sample = (InputSample)ViewBag.InputSample;
// A sample keeps its data in a Prepare<Page> method (InputsDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod(method + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Inputss with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The ColorPicker is a user interface to select and adjust color values. This supports various color specifications like RGB (Red Green Blue), HSV (Hue Saturation Value), and Hex codes.
In this sample, ColorPicker is rendered with default configuration.
This sample can be customized further with the combination of ColorPicker properties from the property pane. For example,
- Control (apply/cancel) buttons can be enabled or disabled using Show Buttons checkbox from the property pane.
- You can select the color by entering the color value in the property pane Value textbox.
- You can switch to 'Picker' and 'Palette' modes by clicking and selecting the mode from Select Mode dropdownlist.
- you can enable or disable the ColorPicker using Disabled checkbox from property pane.
- you can enable or disable the mode switcher using Mode Switcher checkbox from property pane.