ant-design-blazor/components/dropdown/Dropdown.razor
Andrzej Bakun 1d3a13e57e feat(module: dropdown): each button customization (#1659)
* feat(module:dropdownbutton): each button customization

* fix: Tag tests
2021-06-22 23:55:14 +08:00

89 lines
2.7 KiB
C#

@namespace AntDesign
@inherits OverlayTrigger
@using AntDesign.Internal
@if (ChildContent != null)
{
@if (IsButton)
{
<div class="@ClassMapper.Class"
style="display: inline-block; width: @(Block ? "100%" : "fit-content" ); @Style"
id="@Id"
>
@buttons((this, ChildContent))
</div>
}
else
{
<div class="@ClassMapper.Class"
style="display: inline-block; width: fit-content; @Style"
id="@Id"
@ref="@Ref"
@onclick="OnClickDiv"
@onmouseenter="OnTriggerMouseEnter"
@onmouseleave="OnTriggerMouseLeave"
@oncontextmenu="OnTriggerContextmenu"
@oncontextmenu:preventDefault
>
@ChildContent
</div>
}
}
@if (Unbound != null)
{
@if (IsButton)
{
@buttons((this, Unbound(default)))
}
else
{
@Unbound(RefBack)
}
}
<CascadingValue Value="this" Name="Trigger" IsFixed="@true">
<Overlay @ref="_overlay"
OverlayChildPrefixCls="@($"{PrefixCls}-menu")"
OnOverlayMouseEnter="OnOverlayMouseEnter"
OnOverlayMouseLeave="OnOverlayMouseLeave"
OnOverlayMouseUp="OnOverlayMouseUp" />
</CascadingValue>
@code {
RenderFragment<(Dropdown dropdown, RenderFragment childContent)> buttons = data => @<CascadingValue Value="@data.dropdown" IsFixed>
<DropdownGroupButton>
<LeftButton>
<Button @key="1"
Size="@data.dropdown.ButtonSize"
Class="@data.dropdown.ButtonClassLeft"
Type="@data.dropdown.ButtonTypeLeft"
Disabled="@data.dropdown.Disabled"
Danger="@data.dropdown.ButtonDanger"
Ghost="@data.dropdown.ButtonGhost"
Style="@(data.dropdown.Block ? "flex: 1 0 auto;" + data.dropdown.ButtonStyleLeft : data.dropdown.ButtonStyleLeft)"
@attributes="@(new Dictionary<string, object>() { ["OnClick"] = _callbackFactory.Create<MouseEventArgs>(data.dropdown, data.dropdown.OnClick) })"
>
@data.childContent
</Button>
</LeftButton>
<RightButton>
<span @ref="@data.dropdown.Ref">
<Button @key="2"
Size="@data.dropdown.ButtonSize"
Type="@data.dropdown.ButtonTypeRight"
Disabled="@data.dropdown.Disabled"
Class="@("ant-dropdown-trigger " + @data.dropdown.ButtonClassRight)"
Icon="@data.dropdown.RightButtonIcon"
Danger="@data.dropdown.ButtonDanger"
Loading="@data.dropdown.IsLoading"
Ghost="@data.dropdown.ButtonGhost"
Style="@(data.dropdown.Block ? "flex: 0 0 auto;" + data.dropdown.ButtonStyleRight : data.dropdown.ButtonStyleRight)"
@attributes="@(new Dictionary<string, object>() { ["OnClick"] = _callbackFactory.Create<MouseEventArgs>(data.dropdown, data.dropdown.OnTriggerClick) })"
/>
</span>
</RightButton>
</DropdownGroupButton>
</CascadingValue>;
}