Skip to content

Commit

Permalink
[Docs] Add icon preview in API documentation (#2284)
Browse files Browse the repository at this point in the history
* Add icon preview
  • Loading branch information
franklupo authored Jun 28, 2024
1 parent 7af7584 commit 53f826d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 20 additions & 2 deletions examples/Demo/Shared/Components/ApiDocumentation.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
@* Display list of Enumerations (if available) *@
@if (context.EnumValues.Length > 0)
{

var id = Identifier.NewId();
<span id="@id">
<FluentIcon Value="@(new Icons.Regular.Size20.Info())" Style="margin-left: 10px; vertical-align: top;" Color="@Color.Accent" />
Expand All @@ -46,10 +45,29 @@
@item <br />
}
</FluentTooltip>
}
</TemplateColumn>

<TemplateColumn Title="Default">
@if (context.Icon != null)
{
var id = Identifier.NewId();
<FluentStack Orientation="Orientation.Horizontal" HorizontalGap="0">
<div>Preview:</div>
<FluentIcon Id="@id" Value="@context.Icon" Width="20px" />
<FluentTooltip Anchor="@id" Position="TooltipPosition.Right">
@context.Default
</FluentTooltip>
</FluentStack>
}
else
{
<div>
@context.Default
</div>
}
</TemplateColumn>
<PropertyColumn Property="@(c => c.Default)" />

<TemplateColumn Title="Description">
<div style="white-space: break-spaces">
@(new MarkupString(context.Description))
Expand Down
8 changes: 6 additions & 2 deletions examples/Demo/Shared/Components/ApiDocumentation.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberDescription>? _allMembers = null;
Expand Down Expand Up @@ -110,16 +111,18 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
// Parameters/properties
if (!isEvent)
{
Icon? icon = null;
var defaultVaue = "";
if (propertyInfo.PropertyType.IsValueType || propertyInfo.PropertyType == typeof(string))
{
defaultVaue = obj?.GetType().GetProperty(propertyInfo.Name)?.GetValue(obj)?.ToString();
}
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}";
}
}

Expand All @@ -132,6 +135,7 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
Default = defaultVaue,
Description = CodeComments.GetSummary(Component.Name + "." + propertyInfo.Name) ?? CodeComments.GetSummary(Component.BaseType?.Name + "." + propertyInfo.Name),
IsParameter = isParameter,
Icon = icon
});
}

Expand Down

0 comments on commit 53f826d

Please sign in to comment.