Example of API in ASP.NET MVC Chips Control
This sample demonstrates the default functionalities of Chips with different types and predefined styles. Click and interact the chip, to select single or multiple options from chips collection.
Janet Leverling
@Html.UiChipList(new UiChipListOptions { Id = "chip", Chips = { new UiChip { Text = "Janet Leverling" } } })
@Html.UiDropDownList("chip-color", new UiDropDownListOptions { Placeholder = "Select a color", DataSource = (IEnumerable<object>)ViewData["ddlData"], Fields = new UiDropDownFields { Text = "text", Value = "text" }, OnChange = "colorChange" })
@Html.UiCheckBox("chip-leadingicon", false, new UiCheckBoxOptions { Id = "chip-leadingicon", OnChange = "iconHandler" })
@Html.UiDropDownList("chip-avatar", new UiDropDownListOptions { Placeholder = "Select an avatar", DataSource = (IEnumerable<object>)ViewData["avatarData"], Fields = new UiDropDownFields { Text = "text", Value = "text" }, OnChange = "avatarHandler" })
@Html.UiCheckBox("chip-trailingicon", false, new UiCheckBoxOptions { Id = "chip-trailingicon", OnChange = "deleteIconHandler" })
@Html.UiCheckBox("chip-outline", false, new UiCheckBoxOptions { Id = "chip-outline", OnChange = "variantHandler" })
<style>
#chip-api-wrapper { display: flex; justify-content: center; padding: 40px 0; }
</style>
<div class="control-section">
<div id="chip-api-wrapper">
@Html.UiChipList(new UiChipListOptions { Id = "chip", Chips = { new UiChip { Text = "Janet Leverling" } } })
</div>
</div>
<div class="demo-property-panel" title="Properties">
<div class="demo-property-row">
<label>Color</label>
@Html.UiDropDownList("chip-color", new UiDropDownListOptions { Placeholder = "Select a color", DataSource = (IEnumerable<object>)ViewData["ddlData"], Fields = new UiDropDownFields { Text = "text", Value = "text" }, OnChange = "colorChange" })
</div>
<div class="demo-property-row">
<label>Leading icon</label>
@Html.UiCheckBox("chip-leadingicon", false, new UiCheckBoxOptions { Id = "chip-leadingicon", OnChange = "iconHandler" })
</div>
<div class="demo-property-row">
<label>Avatar</label>
@Html.UiDropDownList("chip-avatar", new UiDropDownListOptions { Placeholder = "Select an avatar", DataSource = (IEnumerable<object>)ViewData["avatarData"], Fields = new UiDropDownFields { Text = "text", Value = "text" }, OnChange = "avatarHandler" })
</div>
<div class="demo-property-row">
<label>Trailing icon</label>
@Html.UiCheckBox("chip-trailingicon", false, new UiCheckBoxOptions { Id = "chip-trailingicon", OnChange = "deleteIconHandler" })
</div>
<div class="demo-property-row">
<label>Outline</label>
@Html.UiCheckBox("chip-outline", false, new UiCheckBoxOptions { Id = "chip-outline", OnChange = "variantHandler" })
</div>
</div>
<script>
var janet = '@Url.Content("~/Content/images/chips/janet.png")';
var state = { color: 'default', outline: false, leadingIcon: false, avatar: 'none', trailingIcon: false };
// The chip shows what the properties above say: its colour, outline, leading icon or avatar, and trailing icon.
function apply() {
var props = { color: state.color, outline: state.outline, deletable: state.trailingIcon, imageUrl: '', iconCss: '', avatarText: '' };
if (state.avatar === 'image' || (state.avatar === 'none' && state.leadingIcon)) { props.imageUrl = janet; }
else if (state.avatar === 'icon') { props.iconCss = 'ui-icon-profile'; }
else if (state.avatar === 'letter') { props.avatarText = 'JL'; }
window.Lumen.get('chip').update(0, props);
}
// checkbox change handler for chip leading icon
function iconHandler(checked) { state.leadingIcon = checked; apply(); }
// drop-down list change handler for chip color
function colorChange(value) { state.color = String(value || 'default').toLowerCase(); apply(); }
// checkbox change handler for chip outline
function variantHandler(checked) { state.outline = checked; apply(); }
// drop-down list change handler for chip avatar
function avatarHandler(value) { state.avatar = String(value || 'none').toLowerCase(); apply(); }
// checkbox change handler for chip trailing icon
function deleteIconHandler(checked) { state.trailingIcon = checked; apply(); }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ChipsController : Controller
{
// The page is Views/Chips/Api.cshtml; it draws what ViewData holds.
public ActionResult Api()
{
List<object> ddlData = new List<object>();
ddlData.Add(new { text = "Default", id = "1" });
ddlData.Add(new { text = "Primary", id = "2" });
ddlData.Add(new { text = "Success", id = "3" });
ddlData.Add(new { text = "Danger", id = "4" });
ddlData.Add(new { text = "Warning", id = "5" });
ddlData.Add(new { text = "Info", id = "6" });
ViewData["ddlData"] = ddlData;
List<object> avatarData = new List<object>();
avatarData.Add(new { text = "None", id = "1" });
avatarData.Add(new { text = "Icon", id = "2" });
avatarData.Add(new { text = "Image", id = "3" });
avatarData.Add(new { text = "Letter", id = "4" });
ViewData["avatarData"] = avatarData;
return View();
}
}
}
@* 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>
Chip is a small block of essential information that triggers an event on click action. It contains the text, an image, or both, mostly used in contacts, mails or filter tags.
In this sample, default, input, filter and choice chips are demonstrated with their default functionalities.
- Input chip– Basic chip with delete icon, enables to remove chips from the chip list collection.
- Choice chip – Used to choose a choice from available options.
- Filter chip – Used to select multiple choices from available options.