|
| 1 | +--- |
| 2 | +title: Overview |
| 3 | +page_title: Overview | ColorPicker for Blazor |
| 4 | +description: Overview of the ColorPicker for Blazor. |
| 5 | +slug: colorpicker-overview |
| 6 | +tags: telerik,blazor,colorpicker,overview |
| 7 | +published: True |
| 8 | +position: 0 |
| 9 | +--- |
| 10 | + |
| 11 | +# ColorPicker Overview |
| 12 | + |
| 13 | +The <a href = "https://www.telerik.com/blazor-ui/colorpicker" target="_blank">ColorPicker for Blazor</a> is an interactive component that allows color selection from a popup palette or a [HSVA](https://en.wikipedia.org/wiki/HSL_and_HSV) canvas. Users can also type a specific RGB/HEX color value manually. |
| 14 | + |
| 15 | +#### In this article: |
| 16 | + * [Basics](#basics) |
| 17 | + * [Example](#example) |
| 18 | + * [Interface](#interface) |
| 19 | + * [Features](#features) |
| 20 | + * [Supported Value Formats](#supported-value-formats) |
| 21 | + |
| 22 | +## Basics |
| 23 | + |
| 24 | +To use a Telerik ColorPicker for Blazor: |
| 25 | + |
| 26 | +1. Add the `TelerikColorPicker` tag. |
| 27 | +1. Set its `Value` attribute to any of the [supported HEX/RGB formats](#supported-value-formats). Use a `string` property with [one-way]({%slug colorpicker-events%}#valuechanged) or [two-way](#example) binding. |
| 28 | +1. (optional) Set the `ValueFormat` to `ColorFormat.Hex` or `ColorFormat.Rgb` if the app expects a specific color format. |
| 29 | + |
| 30 | +## Example |
| 31 | + |
| 32 | +Here is a simple ColorPicker declaration and the resulting UI. |
| 33 | + |
| 34 | +````CSHTML |
| 35 | +@* Blazor ColorPicker *@ |
| 36 | +
|
| 37 | +<TelerikColorPicker @bind-Value="@Color" /> |
| 38 | +
|
| 39 | +@code { |
| 40 | + string Color { get; set; } = "rgb(40, 47, 137)"; |
| 41 | +} |
| 42 | +```` |
| 43 | + |
| 44 | +## Interface |
| 45 | + |
| 46 | +The image below reveals all ColorPicker interface elements: |
| 47 | + |
| 48 | +* Main component button with the current value and a dropdown arrow (outside the popup) |
| 49 | +* View selectors (top left) |
| 50 | +* Color preview box (top right) |
| 51 | +* Current color box (below the color preview) |
| 52 | +* Clear button (top) |
| 53 | +* Palette tiles or HSV canvas with hue and opacity sliders (middle) |
| 54 | +* RGBA or HEX value textboxes (bottom) |
| 55 | +* Apply and Cancel buttons (bottom) |
| 56 | + |
| 57 | +Clicking outside the ColorPicker popup acts as an **Apply** action. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +## Features |
| 62 | + |
| 63 | +The ColorPicker tag exposes the following features via its attributes: |
| 64 | + |
| 65 | +* `Value` - `string` - sets the ColorPicker value in a few [different color formats](#supported-value-formats). Supports two-way binding. |
| 66 | +* `ValueFormat` - `ColorFormat` - sets the color format, which the component will return in the application code. By default, the property is not set and the value format will change depending on the used view: `Rgb` when selecting a color from the GradientView, and `Hex` when selecting a color from the PaletteView. |
| 67 | +* `ColorPickerViews` - `RenderFragment` - a nested container to list the [ColorPicker views]({%slug colorpicker-views%}). All views are enabled by default and the user can switch between them with buttons. Each view tag has its own configuration attributes. |
| 68 | +* `View` - `ColorPickerView` - sets the default selected [view]({%slug colorpicker-views%}) (`ColorPickerView.Gradient` by default). Supports two-way binding. |
| 69 | +* `ShowPreview` - `bool` - toggles the [current color box and the color preview box](#interface) in the popup (`true` by default). |
| 70 | + |
| 71 | +* `Class` - `string` - renders a custom CSS class to the `span.k-colorpicker` element. |
| 72 | +* `Enabled` - `bool` - determines if the user can open the popup and change the value (`true` by default). |
| 73 | + |
| 74 | +### Buttons |
| 75 | + |
| 76 | +* `ShowButtons` - `bool` - sets the visibility of the Apply and Cancel buttons (`true` by default). |
| 77 | +* `ClearButton` - `bool` - sets the visibility of the Clear button. |
| 78 | + |
| 79 | +### Custom Icon |
| 80 | + |
| 81 | +The ColorPicker provides attributes to render an icon or image inside the [main component button](#interface). This icon can be used to visually distinguish different ColorPickers on the page. In such cases, the selected color is displayed below the icon. |
| 82 | + |
| 83 | +Use one attribute at a time: |
| 84 | + |
| 85 | +* `Icon` - `string` - specifies a [built-in font icon class]({%slug general-information/font-icons%}). |
| 86 | +* `ImageUrl` - `string` - specifies an URL for an image. |
| 87 | +* `IconClass` - `string` - sets a custom icon class. |
| 88 | + |
| 89 | + |
| 90 | +## Supported Value Formats |
| 91 | + |
| 92 | +The ColorPicker accepts values by the application code in the following formats: |
| 93 | + |
| 94 | +@[template](/_contentTemplates/common/coloreditors.md#value-formats) |
| 95 | + |
| 96 | +Color keywords are not supported. |
| 97 | + |
| 98 | +## See Also |
| 99 | + |
| 100 | +* [ColorPicker Views]({%slug colorpicker-views%}) |
| 101 | +* [ColorPicker Events]({%slug colorpicker-events%}) |
| 102 | +* [ColorPicker Live Demo](https://demos.telerik.com/blazor-ui/colorpicker/overview) |
0 commit comments