fix: menu title padding and layout demo (#186)

This commit is contained in:
James Yeung 2020-06-04 14:48:13 +08:00 committed by GitHub
parent e448d5cf0f
commit 757dd369f2
12 changed files with 28 additions and 16 deletions

View File

@ -14,7 +14,7 @@
@ChildContent @ChildContent
</div> </div>
</CascadingValue> </CascadingValue>
@if (Collapsible && Breakpoint != null) @if (Collapsible && !NoTrigger)
{ {
<div class="ant-layout-sider-trigger" style="width: @($"{width}px")" @onclick="ToggleCollapsed"> <div class="ant-layout-sider-trigger" style="width: @($"{width}px")" @onclick="ToggleCollapsed">
@Trigger @Trigger

View File

@ -22,6 +22,8 @@ namespace AntDesign
[Parameter] public RenderFragment Trigger { get; set; } [Parameter] public RenderFragment Trigger { get; set; }
[Parameter] public bool NoTrigger { get; set; }
[CascadingParameter] public Layout Parent { get; set; } [CascadingParameter] public Layout Parent { get; set; }
[Parameter] public BreakpointType Breakpoint { get; set; } [Parameter] public BreakpointType Breakpoint { get; set; }
@ -82,11 +84,10 @@ namespace AntDesign
{ {
base.OnInitialized(); base.OnInitialized();
Parent?.HasSider(); Parent?.HasSider();
if (Trigger == null) if (Trigger == null && !NoTrigger)
{ {
Trigger = defaultTrigger; Trigger = defaultTrigger;
} }
isCollapsed = Collapsed; isCollapsed = Collapsed;
SetClass(); SetClass();
} }

View File

@ -2,7 +2,7 @@
@inherits AntDomComponentBase @inherits AntDomComponentBase
<CascadingValue Value="this"> <CascadingValue Value="this">
<li class="@ClassMapper.Class" role="menuitem" style="@Style" @onclick="HandleOnClick" @key="Key"> <li class="@ClassMapper.Class" role="menuitem" style=" @(PaddingLeft>0? $"padding-left:{PaddingLeft}px;":"") @Style" @onclick="HandleOnClick" @key="Key">
@ChildContent @ChildContent
</li> </li>
</CascadingValue> </CascadingValue>

View File

@ -33,6 +33,8 @@ namespace AntDesign
public bool IsSelected { get; private set; } public bool IsSelected { get; private set; }
private string _key; private string _key;
private int PaddingLeft => RootMenu.InternalMode == MenuMode.Inline ? ((ParentMenu?.Level ?? 0) + 1) * 24 : 0;
private void SetClass() private void SetClass()
{ {
string prefixCls = $"{RootMenu.PrefixCls}-item"; string prefixCls = $"{RootMenu.PrefixCls}-item";

View File

@ -9,7 +9,7 @@
@if (RootMenu.InternalMode == MenuMode.Inline) @if (RootMenu.InternalMode == MenuMode.Inline)
{ {
<li class="@ClassMapper.Class" role="menuitem" @key="Key" style="position:relative;@Style"> <li class="@ClassMapper.Class" role="menuitem" @key="Key" style="position:relative;@Style">
<div class="@(prefixCls)-title" role="button" @onclick="HandleOnTitleClick" aria-haspopup="true"> <div class="@(prefixCls)-title" style="padding-left: @(PaddingLeft)px; " role="button" @onclick="HandleOnTitleClick" aria-haspopup="true">
@if (Title.IsT0) @if (Title.IsT0)
{ {

View File

@ -38,6 +38,10 @@ namespace AntDesign
[Parameter] [Parameter]
public EventCallback<MouseEventArgs> OnTitleClicked { get; set; } public EventCallback<MouseEventArgs> OnTitleClicked { get; set; }
internal int Level => RootMenu.InternalMode == MenuMode.Inline ? (Parent?.Level ?? 0) + 1 : 0;
private int PaddingLeft => Level * 24;
private ClassMapper SubMenuMapper { get; } = new ClassMapper(); private ClassMapper SubMenuMapper { get; } = new ClassMapper();
private bool _isSelected; private bool _isSelected;

View File

@ -9,7 +9,7 @@
} }
<Layout> <Layout>
<Sider Collapsible Collapsed=@collapsed> <Sider Collapsible Collapsed=@collapsed NoTrigger>
<div class="logo" /> <div class="logo" />
<Menu Theme="MenuTheme.Dark" Mode="MenuMode.Inline" DefaultSelectedKeys=@(new[]{"1"})> <Menu Theme="MenuTheme.Dark" Mode="MenuMode.Inline" DefaultSelectedKeys=@(new[]{"1"})>
<MenuItem Key="1"> <MenuItem Key="1">

View File

@ -28,7 +28,7 @@
{ {
RenderFragment sub1Title = RenderFragment sub1Title =
@<Template> @<Template>
<AntIcon Type="appstore" Theme="outline"></AntIcon> <AntIcon Type="setting" Theme="outline"></AntIcon>
Navigation Three - Submenu Navigation Three - Submenu
</Template>; </Template>;
} }

View File

@ -1,4 +1,4 @@
<Menu Style="width: 256;" <Menu Style="width: 256px;"
DefaultSelectedKeys=@(new[]{"1"}) DefaultSelectedKeys=@(new[]{"1"})
DefaultOpenKeys=@(new[]{"sub1"}) DefaultOpenKeys=@(new[]{"sub1"})
Mode=@MenuMode.Inline> Mode=@MenuMode.Inline>

View File

@ -1,4 +1,4 @@
<div style="width: 256;"> <div style="width: 256px;">
<Button Type="primary" OnClick="ToggleCollapsed" Style="margin-bottom: 16px"> <Button Type="primary" OnClick="ToggleCollapsed" Style="margin-bottom: 16px">
@if (collapsed) @if (collapsed)
{ {
@ -25,7 +25,7 @@
<span>Option 2</span> <span>Option 2</span>
</MenuItem> </MenuItem>
<MenuItem Key="3"> <MenuItem Key="3">
<AntIcon Type="contaainer" Theme="outline"></AntIcon> <AntIcon Type="container" Theme="outline"></AntIcon>
<span>Option 3</span> <span>Option 3</span>
</MenuItem> </MenuItem>
<SubMenu Key="sub1" Title=sub1Title > <SubMenu Key="sub1" Title=sub1Title >

View File

@ -1,12 +1,18 @@
@page "/mock" @page "/mock"
@using System.Reflection @using System.Reflection
@using System.Net
@layout BlankLayout; @layout BlankLayout;
<div id="@DemoId">
@ShowCaseContent
</div>
@ShowCaseContent
@code @code
{ {
[Parameter]
public string DemoId { get; set; }
[Parameter] [Parameter]
public string Type { get; set; } public string Type { get; set; }

View File

@ -1,12 +1,13 @@
@using System.Reflection @using System.Reflection
@using AntDesign.JsInterop @using AntDesign.JsInterop
@using System.Net
@inherits ComponentBase @inherits ComponentBase
<div class="code-box" id="@DemoId"> <div class="code-box" id="@DemoId">
<section class="code-box-demo"> <section class="code-box-demo">
@if (Demo.Iframe > 0) @if (Demo.Iframe > 0)
{ {
<MockBrowser Height="@Demo.Iframe.Value" WithUrl="@($"/mock?type={Demo.Type}")" /> <MockBrowser Height="@Demo.Iframe.Value" WithUrl="@($"/mock?demoId={@DemoId}&type={Demo.Type}")" />
} }
else else
{ {
@ -45,17 +46,15 @@
<HighlightedCode Code="@Demo.Code" CanLoad="codeExpand" Language="html"></HighlightedCode> <HighlightedCode Code="@Demo.Code" CanLoad="codeExpand" Language="html"></HighlightedCode>
</div> </div>
</section> </section>
<Style> <style>
@Demo.Style @Demo.Style
</Style> </style>
</div> </div>
@inject InteropService InteropService @inject InteropService InteropService
@code { @code {
[Parameter] [Parameter]
public string ComponentName { get; set; } public string ComponentName { get; set; }