Skip to content

Commit 0281988

Browse files
Buttongroup initial (#83)
* chore(buttonGroup): initial skeleton * docs(buttonGroup): first version of overview article * docs(buttonGroup): icons and selection articles * docs(buttonGroup): events * update wording on selected vs primary Co-authored-by: Joana Ivanova <Joana.Ivanova@telerik.com> * typo Co-authored-by: Joana Ivanova <Joana.Ivanova@telerik.com> Co-authored-by: Joana Ivanova <Joana.Ivanova@telerik.com>
1 parent 2c7fbc6 commit 0281988

12 files changed

+445
-0
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ intro_columns:
280280
items:
281281
"Button": "components/button/overview"
282282
"Toggle Button": "togglebutton-overview"
283+
"Button Group" : "buttongroup-overview"
283284
"Menu": "components/menu/overview"
284285
"Tab Strip": "components/tabstrip/overview"
285286
"TreeView": "components/treeview/overview"

components/buttongroup/events.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: Events
3+
page_title: ButtonGroup for Blazor | Events
4+
description: Events of the ButtonGroup for Blazor
5+
slug: buttongroup-events
6+
tags: telerik,blazor,Toggle,button,group
7+
published: True
8+
position: 20
9+
---
10+
11+
# ButtonGroup Events
12+
13+
This article explains the events available in the Telerik buttons in a ButtonGroup for Blazor:
14+
15+
* [SelectedChanged](#selectedchanged)
16+
* [OnClick](#onclick)
17+
18+
19+
## SelectedChanged
20+
21+
The `SelectedChanged` fires when the user changes the state of the button by clicking it (or by using `Space` or `Enter`). You can use it to call local view-model logic. To fetch data or perform async operations, use the [OnClick](#onclick) event.
22+
23+
This event is available only for `ButtonGroupToggleButton` instances, as they are the only selecteble buttons.
24+
25+
>caption Handle the SelectedChanged event
26+
27+
````CSHTML
28+
@* If you do not update the view-model in the handler, you can effectively cancel the event *@
29+
30+
<TelerikButtonGroup SelectionMode="@ButtonGroupSelectionMode.Single">
31+
<ButtonGroupToggleButton Selected="@FirstSelected" SelectedChanged="@FirstSelectedChangedHandler">First</ButtonGroupToggleButton>
32+
<ButtonGroupToggleButton Selected="@SecondSelected" SelectedChanged="@SecondSelectedChangedHandler">Second</ButtonGroupToggleButton>
33+
</TelerikButtonGroup>
34+
35+
@code{
36+
bool FirstSelected { get; set; }
37+
bool SecondSelected { get; set; } = true; // you can pre-select buttons
38+
39+
void FirstSelectedChangedHandler(bool currState)
40+
{
41+
FirstSelected = currState;
42+
// you have to update the model manually because handling the SelectedChanged event does not let you use @bind-Selected
43+
// if you don't update the View-Model, you will effectively cancel the event
44+
45+
Console.WriteLine($"The first button is selected: {FirstSelected}");
46+
}
47+
48+
void SecondSelectedChangedHandler(bool currState)
49+
{
50+
SecondSelected = currState;
51+
// you have to update the model manually because handling the SelectedChanged event does not let you use @bind-Selected
52+
// if you don't update the View-Model, you will effectively cancel the event
53+
54+
Console.WriteLine($"The Second button is now selected: {FirstSelected}");
55+
}
56+
}
57+
````
58+
59+
60+
## OnClick
61+
62+
The `OnClick` event fires when the user clicks or taps the button. You can use it to invoke async logic such as fetching data or calling a service.
63+
64+
>caption Handle the Button OnClick event in a ButtonGroup
65+
66+
````CSHTML
67+
@* This example shows how to handle each click individually, and also a way to use the same async handler from several instances, and pass arguments to it *@
68+
69+
@result
70+
71+
<br />
72+
73+
<TelerikButtonGroup SelectionMode="@ButtonGroupSelectionMode.Single">
74+
<ButtonGroupButton OnClick="@FirstClickHandler">First</ButtonGroupButton>
75+
<ButtonGroupButton OnClick="@( async() => await SharedClickHandler("Second button, shared handler") )">Second</ButtonGroupButton>
76+
<ButtonGroupToggleButton OnClick="@( async() => await SharedClickHandler("Shared Toggle Button") )">Toggle Button</ButtonGroupToggleButton>
77+
<ButtonGroupToggleButton OnClick="@ToggleButtonClickHandler">Toggle Button Two</ButtonGroupToggleButton>
78+
</TelerikButtonGroup>
79+
80+
@code{
81+
string result { get; set; }
82+
83+
async Task FirstClickHandler()
84+
{
85+
await Task.Delay(500);//simulate network delay from real data retrieval. Remove from a real app
86+
87+
result = "First button: " + DateTime.Now.Millisecond;
88+
}
89+
90+
async Task ToggleButtonClickHandler()
91+
{
92+
await Task.Delay(500);//simulate network delay from real data retrieval. Remove from a real app
93+
94+
result = "Standalone Toggle Button: " + DateTime.Now.Millisecond;
95+
}
96+
97+
async Task SharedClickHandler(string sender)
98+
{
99+
await Task.Delay(500);//simulate network delay from real data retrieval. Remove from a real app
100+
101+
result = sender + DateTime.Now.Millisecond;
102+
}
103+
}
104+
````
105+
106+
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
107+
108+
109+
## See Also
110+
111+
* [ButtonGroup Overview]({%slug buttongroup-overview%})

components/buttongroup/icons.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Icons
3+
page_title: ButtonGroup for Blazor | Icon
4+
description: Icons and images in the ButtonGroup for Blazor
5+
slug: buttongroup-icons
6+
tags: telerik,blazor,Toggle,button,group,icon,sprite,image
7+
published: True
8+
position: 5
9+
---
10+
11+
12+
# ButtonGroup Icons
13+
14+
You can put an image, sprite or a font icon in the buttons within a ButtonGroup to illustrate its purpose for your end users. To apply them, use the following properties:
15+
16+
* for a [Telerik font icon]({%slug general-information/font-icons%}), use the `Icon` attribute to set the font icon class.
17+
18+
* for a raster image, use the `ImageUrl` attribute to provide the URL to the icon (relative or absolute).
19+
20+
* for a custom font icon class, set the `IconClass` parameter of the component to the desired CSS class list which provides the required rules (like font name and glyph symbol). Make sure to also reference the desired font in your app and to use its own recommendations.
21+
22+
* for a sprite, set the `SpriteClass` attribute to `k-icon MySpriteClass` where `MySpriteClass` defines the CSS rules for the sprite.
23+
24+
25+
The following example shows how to use an image from a URL, a sprite image, and the built-in font icons.
26+
27+
>caption How to use icons in the Telerik ButtonGroup Button
28+
29+
````CSHTML
30+
@* This sample shows how you can use conditional logic to show different icons in the different states.
31+
It also shows how to use telerik icons, raster icons and sprite images*@
32+
33+
<TelerikButtonGroup SelectionMode="@ButtonGroupSelectionMode.Multiple">
34+
<ButtonGroupToggleButton SpriteClass="@( FlagSelected ? "flag netherlands" : "flag brazil")" @bind-Selected="@FlagSelected">Sprite</ButtonGroupToggleButton>
35+
36+
<ButtonGroupToggleButton Icon="@( FontSelected ? IconName.VolumeOff : IconName.VolumeUp )" @bind-Selected="@FontSelected">Font Icon</ButtonGroupToggleButton>
37+
38+
<ButtonGroupToggleButton ImageUrl="@RasterIconUrl" @bind-Selected="@RasterSelected">Image URL</ButtonGroupToggleButton>
39+
</TelerikButtonGroup>
40+
41+
<style>
42+
/* the sprite for the first button is defined through a CSS rule matchin its Class */
43+
.flag {
44+
background-image: url("https://docs.telerik.com/blazor-ui/images/flags.png");
45+
}
46+
47+
.flag.netherlands {
48+
background-position: 0 -64px;
49+
background-color: white;
50+
}
51+
52+
.flag.brazil {
53+
background-position: 0 0;
54+
}
55+
</style>
56+
57+
@code{
58+
bool FlagSelected { get; set; }
59+
bool FontSelected { get; set; }
60+
bool RasterSelected { get; set; }
61+
string RasterIconUrl => RasterSelected ? "https://docs.telerik.com/blazor-ui/images/snowboarding.png" : "https://docs.telerik.com/blazor-ui/images/swimming.png";
62+
}
63+
````
64+
65+
>caption The result from the code snippet above
66+
67+
![Icons in ButtonGroup Buttons](images/buttongroup-icons.png)
68+
69+
>tip You can use relative paths to your images in the `wwwroot` folder. The example above uses absolute paths to make it easy for you to see the results without preparing images.
70+
71+
>tip If you don't add text to the button, the button will center the icon on all sides.
72+
73+
>note Images used as icons should generally be small enough to fit in a line of text - the button is an inline element and is not designed for large images. If you want to use big icon buttons, consider one of the following options:
74+
>
75+
> * defining a `Class` on the button that provides `height` and `width`. The width and height can be set in `px` sufficient to accommodate the icon or to `auto`,
76+
> * or attaching an `@onclick` handler to an icon/`span`/`img` element instead of using a button,
77+
> * or adding your own HTML inside the button, something like: `<TelerikButton><img style="width: 400px; height: 400px;" src="my-icon.svg" />some text</TelerikButton>`
78+
79+
80+
## See Also
81+
82+
* [ButtonGroup Overview]({%slug buttongroup-overview%})
5.1 KB
Loading
1.46 KB
Loading
10.4 KB
Loading
65.4 KB
Loading
3.51 KB
Loading
65.2 KB
Loading
7.63 KB
Loading

0 commit comments

Comments
 (0)