Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ravamp KB article for Checkbox icon change #2336

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 45 additions & 51 deletions knowledge-base/checkbox-custom-icon.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Change Checkbox Icon
description: How to change the CheckBox icon to a custom one.
title: How to Change Checkbox Icons
description: Learn how to change the Checkbox icon, modify the default check mark and indeterminate icons, and integrate third-party icons.
type: how-to
page_title: Custom Checkbox Icon
page_title: How to Change Checkbox Icons
slug: checkbox-kb-custom-icon
position:
tags:
Expand All @@ -22,69 +22,63 @@ res_type: kb

## Description

How do I change the checkbox icon? I want to use another icon, not the default checkmark.
This knowledge base article answers the following questions:

## Solution

Add a `Class` to the CheckBox component. [Override the theme styles]({%slug themes-override%}) and change the default font icon glyphs.

You can replace the icons with different glyphs, even from a different font. You can also change the icon size and color.
* How do I change the Checkbox icon?
* How to change the default check mark icon?
* How to change the icon of the indeterminate state?
* How to integrate custom icons from a third-party library into a Telerik Checkbox component?

The `k-icon` CSS class applies the custom font, which contains all [built-in Telerik font icons]({%slug common-features-icons%}). If you will use a different font, remove `k-icon`.
## Solution
1. Set a custom CSS class to the Tooltip through the `Class` parameter. This configuration will allow you to target specific Checkbox instances.
2. Use the defiend class to [Override the theme styles]({%slug themes-override%}) with the following CSS approach.
Tsvetomir-Hr marked this conversation as resolved.
Show resolved Hide resolved

>caption How to change the checkbox icon
>caption How to change the Checkbox icons

````CSHTML
<TelerikCheckBox Value="true" Class="k-icon heart-icon" />
<TelerikCheckBox Value="false" Class="k-icon heart-icon" />
<TelerikCheckBox Value="false" Indeterminate="true" Class="k-icon heart-icon" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<TelerikButton ThemeColor="primary" OnClick="@( _ => IndeterminateValue = null )">Make indeterminate</TelerikButton>
<br />
<br />
<TelerikCheckBox @bind-Value="@IndeterminateValue" Size="lg" Indeterminate="@( !IndeterminateValue.HasValue )" Class="custom-icons" />
<label>Checkbox</label>

<style>
/* remove some built-in styles */
.heart-icon.k-checkbox,
.heart-icon.k-checkbox:focus,
.heart-icon.k-checkbox:checked,
.heart-icon.k-checkbox:checked:focus {
border: none;
background: none;
box-shadow: none;
/* Set the Font Awesome family and weight for custom checkbox icons */
.custom-icons.k-checkbox:before {
font-family: "Font Awesome 6 Free";
font-weight: 900;
}

.heart-icon.k-checkbox::before,
.heart-icon.k-checkbox:checked::before,
.heart-icon.k-checkbox:indeterminate::before {
transform: none;
top: 0;
left: 0;
width: auto;
height: auto;
font-size: 30px; /* used for dimensions, see the next section */
}

/* set desired dimensions */
.heart-icon.k-checkbox {
width: 30px;
height: 30px;
/* Remove the default background image for checked state */
.custom-icons.k-checkbox:checked {
background-image: none;
}

/* change the font icon glyph to a different one - in this case - a heart icon from the Telerik font
we also change the colors here to denote states, you can alter this further - like using your own fonts or colors
*/
.heart-icon.k-checkbox:checked::before {
content: "\e301";
color: #ff6358;
/* Set the Font Awesome check mark icon for the checked state */
.custom-icons.k-checkbox:checked:before {
content: "\f00c"; /* Checkmark icon */
margin-left: 1px;
}

.heart-icon.k-checkbox:indeterminate::before {
content: "\e300";
color: #ff6358;
background: none;
}
/* Remove the default background image for indeterminate state */
.custom-icons.k-checkbox:indeterminate {
background-image: none;
}

.heart-icon.k-checkbox::before {
content: "\e300";
color: #656565;
/* Set the Font Awesome minus icon for the indeterminate state */
.custom-icons.k-checkbox:indeterminate:before {
content: "\f068"; /* Minus icon */
margin-left: 1px;
}
</style>

@code {
private bool? IndeterminateValue { get; set; }
}
````

## See Also
* [Built-in Font and SVG Icons]({%slug common-features-icons%})
* [Checkbox Indeterminate State]({%slug checkbox-indeterminate-state%})

Loading