ColorPicker
A saturation and brightness area, a hue slider and a hex field. The value is a #rrggbb string.
On this page
Examples
Bound
The area is two native sliders (saturation and brightness), so the keyboard works as on any slider.
Color: #ffd23f
Razor
<div class="flex flex-col items-center gap-3">
<KlyFormField Label="Brand color">
<KlyColorPicker @bind-Value="_color" data-testid="brand" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="brand-state">Color: @(_color ?? "none")</p>
</div>
@code {
private string? _color = "#ffd23f";
}In an EditForm
Razor
<EditForm Model="Model" FormName="theme" OnValidSubmit="Save" class="flex w-full max-w-xs flex-col items-start gap-3">
<KlyFormField Label="Accent color" Description="Posted as #rrggbb." Field="FieldIdentifier.Create(() => Model!.Accent)">
<KlyColorPicker @bind-Value="Model!.Accent" />
</KlyFormField>
<KlyButton Type="ButtonType.Submit" Label="Save theme" />
@if (_saved)
{
<p role="status" class="text-sm text-(--klyroo-success-text)" data-testid="theme-saved">Saved: @Model!.Accent</p>
}
</EditForm>
@code {
[SupplyParameterFromForm(FormName = "theme")]
private Theme? Model { get; set; }
private bool _saved;
protected override void OnInitialized() => Model ??= new() { Accent = "#1f6f7a" };
private void Save() => _saved = true;
private sealed class Theme
{
public string? Accent { get; set; }
}
}API
KlyColorPicker
Color picker with a saturation and brightness area, a hue slider and a hex field. It binds to a hex string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the picker when it is not inside a KlyFormField with a label. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"primary" |
Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral. |
Disabled |
bool |
false |
Disables the control: it cannot be focused or changed and is not submitted. |
Id |
string |
The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one. | |
Name |
string |
Form field name outside an EditForm . Inside one, the name comes from the bound expression. | |
Required |
bool |
false |
Marks the control as required, for the browser and for assistive technology. |
Size |
KlySize? |
Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl. |
|
Ui |
ColorPickerUi |
Per-instance class overrides of the slots of the color picker, see ColorPickerUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Value (@bind-Value) |
string |
The value of the control. Bind it with @bind-Value . | |
ValueExpression |
Expression |
The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field. | |
Variant |
FieldVariant |
FieldVariant. |
Look of the hex field, as a FieldVariant . Values: Outline, Soft, Subtle, Ghost, None. |
Ui slots
Ui takes a ColorPickerUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyColorPicker , after the theme and the app configuration. |
Area |
Classes merged into the area slot of KlyColorPicker , after the theme and the app configuration. |
AreaThumb |
Classes merged into the areaThumb slot of KlyColorPicker , after the theme and the app configuration. |
Hue |
Classes merged into the hue slot of KlyColorPicker , after the theme and the app configuration. |
Preview |
Classes merged into the preview slot of KlyColorPicker , after the theme and the app configuration. |
Swatch |
Classes merged into the swatch slot of KlyColorPicker , after the theme and the app configuration. |
Hex |
Classes merged into the hex slot of KlyColorPicker , after the theme and the app configuration. |