|
| 1 | +using Microsoft.AspNetCore.Components; |
| 2 | +using MudBlazor; |
| 3 | +using MudBlazor.Utilities; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Runtime.InteropServices; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | + |
| 11 | +namespace MudExtensions |
| 12 | +{ |
| 13 | + public partial class MudPopup : MudComponentBase |
| 14 | + { |
| 15 | + Guid _animationGuid = Guid.NewGuid(); |
| 16 | + |
| 17 | + protected string Classname => new CssBuilder("mud-popup") |
| 18 | + .AddClass($"fixed mud-width-full gap-4 pa-4 popup-{_animationGuid}") |
| 19 | + .AddClass("mud-popup-center", PopupPosition == PopupPosition.Center) |
| 20 | + .AddClass("d-flex", (_breakpoint != Breakpoint.Xs && PopupPosition != PopupPosition.Center)) |
| 21 | + .AddClass("align-center", PopupPosition == PopupPosition.Bottom || PopupPosition == PopupPosition.Top) |
| 22 | + .AddClass($"mud-elevation-{Elevation.ToString()}") |
| 23 | + .AddClass(Class) |
| 24 | + .Build(); |
| 25 | + |
| 26 | + protected string Stylename => new StyleBuilder() |
| 27 | + .AddStyle("bottom", $"{Padding}px", PopupPosition == PopupPosition.Bottom) |
| 28 | + .AddStyle("top", $"{Padding}px", PopupPosition == PopupPosition.Top) |
| 29 | + .AddStyle("left", $"{Padding}px", PopupPosition == PopupPosition.Bottom || PopupPosition == PopupPosition.Top) |
| 30 | + .AddStyle("width", $"calc(100% - {Padding * 2}px)", PopupPosition == PopupPosition.Bottom || PopupPosition == PopupPosition.Top) |
| 31 | + .AddStyle(Style) |
| 32 | + .Build(); |
| 33 | + |
| 34 | + [Parameter] |
| 35 | + public PopupPosition PopupPosition { get; set; } = PopupPosition.Bottom; |
| 36 | + |
| 37 | + bool _open = false; |
| 38 | + /// <summary> |
| 39 | + /// The popup's visible state. |
| 40 | + /// </summary> |
| 41 | + [Parameter] |
| 42 | + public bool Open |
| 43 | + { |
| 44 | + get => _open; |
| 45 | + set |
| 46 | + { |
| 47 | + if (_open == value) |
| 48 | + { |
| 49 | + return; |
| 50 | + } |
| 51 | + _open = value; |
| 52 | + OpenChanged.InvokeAsync(_open).AndForget(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Popup's space between the borders. Has no effect on centered popups. |
| 58 | + /// </summary> |
| 59 | + [Parameter] |
| 60 | + public int Padding { get; set; } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// If true, popup appears with a fade animation. |
| 64 | + /// </summary> |
| 65 | + [Parameter] |
| 66 | + public bool EnableAnimation { get; set; } = true; |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// The higher the number, the heavier the drop-shadow. |
| 70 | + /// </summary> |
| 71 | + [Parameter] |
| 72 | + [Category(CategoryTypes.Paper.Appearance)] |
| 73 | + public int Elevation { set; get; } = 4; |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// The icon at the start of the popup. Can be overridden with ChildContent. |
| 77 | + /// </summary> |
| 78 | + [Parameter] |
| 79 | + public string Icon { get; set; } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// The text coming after the icon of the popup. Can be overridden with ChildContent. |
| 83 | + /// </summary> |
| 84 | + [Parameter] |
| 85 | + public string Text { get; set; } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Icon and text color. |
| 89 | + /// </summary> |
| 90 | + [Parameter] |
| 91 | + public Color Color { get; set; } |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Custom content for override everything. |
| 95 | + /// </summary> |
| 96 | + [Parameter] |
| 97 | + public RenderFragment ChildContent { get; set; } |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// The action button section. If this renderfragment null, a close icon button will be appear. |
| 101 | + /// </summary> |
| 102 | + [Parameter] |
| 103 | + public RenderFragment ActionContent { get; set; } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// The MudLink content continues after the text. |
| 107 | + /// </summary> |
| 108 | + [Parameter] |
| 109 | + public RenderFragment LinkContent { get; set; } |
| 110 | + |
| 111 | + [Parameter] |
| 112 | + public EventCallback<bool> OpenChanged { get; set; } |
| 113 | + |
| 114 | + Breakpoint _breakpoint; |
| 115 | + protected void GetBreakpoint(Breakpoint breakpoint) |
| 116 | + { |
| 117 | + _breakpoint = breakpoint; |
| 118 | + } |
| 119 | + |
| 120 | + } |
| 121 | +} |
0 commit comments