Skip to content

Commit

Permalink
Docs: Add tooltips for enum types showing enum constants (#1020, #3172)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwis committed Nov 3, 2021
1 parent 9081c3b commit 33db3d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/MudBlazor.Docs/Components/DocsApi.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
<MudChip Variant="Variant.Outlined" Color="Color.Secondary" Size="Size.Small">overridden</MudChip>
}
</MudTd>
<MudTd Class="docs-content-api-cell" DataLabel="Type"><div style="display: flex; flex-direction: row; align-items: center; white-space: nowrap;">@context.Type<DocsBinding IsTwoWay="@context.IsTwoWay" /></div></MudTd>
<MudTd Class="docs-content-api-cell" DataLabel="Type">
<div style="display: flex; flex-direction: row; align-items: center; white-space: nowrap;">
<DocsTypeInfo Type="@context.Type" />
<DocsBinding IsTwoWay="@context.IsTwoWay" />
</div>
</MudTd>
<MudTd Class="docs-content-api-cell" DataLabel="Default">
@if (PresentDefaultValue(context.Default).Contains("<path"))
{
Expand Down Expand Up @@ -75,7 +80,7 @@
</HeaderContent>
<RowTemplate>
<MudTd Class="docs-content-api-cell" DataLabel="Name"><CodeInline>@context.Name</CodeInline></MudTd>
<MudTd Class="docs-content-api-cell" DataLabel="Type"><div style="display: flex; flex-direction: row; align-items: center; white-space: nowrap;">@context.Type</div></MudTd>
<MudTd Class="docs-content-api-cell" DataLabel="Type"><div style="display: flex; flex-direction: row; align-items: center; white-space: nowrap;">@context.Type.ConvertToCSharpSource()</div></MudTd>
<MudTd Class="docs-content-api-cell docs-content-api-description" DataLabel="Description">@(HttpUtility.HtmlDecode(context.Description))</MudTd>
</RowTemplate>
</MudTable>
Expand Down Expand Up @@ -152,7 +157,7 @@
Default = string.Empty,
Description = GetDescription(Type, info),
IsTwoWay = CheckIsTwoWayEventCallback(info),
Type = info.PropertyType.ConvertToCSharpSource(),
Type = info.PropertyType,
};
}
}
Expand Down Expand Up @@ -207,7 +212,7 @@
Default = GetDefaultValue(info),
IsTwoWay = CheckIsTwoWayProperty(info),
Description = GetDescription(Type, info),
Type = info.PropertyType.ConvertToCSharpSource()
Type = info.PropertyType
};
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/MudBlazor.Docs/Components/DocsTypeInfo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@if (NonnullableType.IsEnum)
{
<MudTooltip>
<ChildContent>@Type.ConvertToCSharpSource()</ChildContent>
<TooltipContent>
enumeration type
<MudText Align="Align.Left" Typo="Typo.body2">
@foreach (var name in Enum.GetNames(NonnullableType))
{
@(NonnullableType.Name + "." + name)<br />
}
</MudText>
</TooltipContent>
</MudTooltip>
}
else
{
@Type.ConvertToCSharpSource()
}

@code {
[Parameter] public Type Type { get; set; }

private Type NonnullableType => Nullable.GetUnderlyingType(Type) ?? Type;
}
5 changes: 3 additions & 2 deletions src/MudBlazor.Docs/Models/ApiProperty.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Reflection;
using System;
using System.Reflection;

namespace MudBlazor.Docs.Models
{
public class ApiProperty
{
public string Name { get; set; }
public string Type { get; set; }
public Type Type { get; set; }
public PropertyInfo PropertyInfo { get; set; }
public string Description { get; set; }
public object Default { get; set; }
Expand Down

0 comments on commit 33db3d5

Please sign in to comment.