From 53f826d2980fcfa3e1aba69355b48c9a069b539f Mon Sep 17 00:00:00 2001 From: Daniele Corsini Date: Fri, 28 Jun 2024 12:44:37 +0200 Subject: [PATCH] [Docs] Add icon preview in API documentation (#2284) * Add icon preview --- .../Shared/Components/ApiDocumentation.razor | 22 +++++++++++++++++-- .../Components/ApiDocumentation.razor.cs | 8 +++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/examples/Demo/Shared/Components/ApiDocumentation.razor b/examples/Demo/Shared/Components/ApiDocumentation.razor index cc165dd530..cffacb48ed 100644 --- a/examples/Demo/Shared/Components/ApiDocumentation.razor +++ b/examples/Demo/Shared/Components/ApiDocumentation.razor @@ -35,7 +35,6 @@ @* Display list of Enumerations (if available) *@ @if (context.EnumValues.Length > 0) { - var id = Identifier.NewId(); @@ -46,10 +45,29 @@ @item
} + } + + + @if (context.Icon != null) + { + var id = Identifier.NewId(); + +
Preview:
+ + + @context.Default + +
+ } + else + { +
+ @context.Default +
}
- +
@(new MarkupString(context.Description)) diff --git a/examples/Demo/Shared/Components/ApiDocumentation.razor.cs b/examples/Demo/Shared/Components/ApiDocumentation.razor.cs index f357b3c676..194dacbafb 100644 --- a/examples/Demo/Shared/Components/ApiDocumentation.razor.cs +++ b/examples/Demo/Shared/Components/ApiDocumentation.razor.cs @@ -18,6 +18,7 @@ private class MemberDescription public string? Default { get; set; } = null; public string Description { get; set; } = ""; public bool IsParameter { get; set; } + public Icon? Icon { get; set; } } private IEnumerable? _allMembers = null; @@ -110,6 +111,7 @@ private IEnumerable GetMembers(MemberTypes type) // Parameters/properties if (!isEvent) { + Icon? icon = null; var defaultVaue = ""; if (propertyInfo.PropertyType.IsValueType || propertyInfo.PropertyType == typeof(string)) { @@ -117,9 +119,10 @@ private IEnumerable GetMembers(MemberTypes type) } else if (propertyInfo.PropertyType == typeof(Icon)) { - if (obj?.GetType().GetProperty(propertyInfo.Name)?.GetValue(obj) is Icon icon) + if (obj?.GetType().GetProperty(propertyInfo.Name)?.GetValue(obj) is Icon value) { - defaultVaue = $"{icon.Variant}.{icon.Size}.{icon.Name}"; + icon = value; + defaultVaue = $"{value.Variant}.{value.Size}.{value.Name}"; } } @@ -132,6 +135,7 @@ private IEnumerable GetMembers(MemberTypes type) Default = defaultVaue, Description = CodeComments.GetSummary(Component.Name + "." + propertyInfo.Name) ?? CodeComments.GetSummary(Component.BaseType?.Name + "." + propertyInfo.Name), IsParameter = isParameter, + Icon = icon }); }