-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module: radio): support enum type for
RadioGroup
(#1840)
- Loading branch information
1 parent
bcd5e6b
commit b2494a6
Showing
4 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AntDesign | ||
{ | ||
public class EnumRadioGroup<TEnum> : RadioGroup<TEnum> | ||
{ | ||
public EnumRadioGroup() | ||
{ | ||
Options = EnumHelper<TEnum>.GetValueLabelList() | ||
.Select(x => new RadioOption<TEnum> { Value = x.Value, Label = x.Label }) | ||
.ToArray(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
site/AntDesign.Docs/Demos/Components/Radio/demo/EnumGroup.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@using System.ComponentModel.DataAnnotations | ||
|
||
<EnumRadioGroup TEnum="Fruits" @bind-Value="_radioValue"></EnumRadioGroup> | ||
<br /> | ||
Value: @_radioValue | ||
|
||
@code { | ||
Fruits _radioValue = Fruits.Apple; | ||
|
||
enum Fruits | ||
{ | ||
[Display(Name = "🍎 Apple")] | ||
Apple, | ||
|
||
Pear, | ||
|
||
Orange | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
site/AntDesign.Docs/Demos/Components/Radio/demo/enum-group.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
order: 8.5 | ||
title: | ||
zh-CN: RadioGroup 组合 - 枚举方式 | ||
en-US: Radio group - enum type | ||
--- | ||
|
||
## zh-CN | ||
|
||
通过指定枚举类型,来渲染单选框。 | ||
|
||
|
||
## en-US | ||
|
||
Render radios by specific enum type. |