|
| 1 | +using Microsoft.AspNetCore.Components; |
| 2 | +using Microsoft.AspNetCore.Components.Web; |
| 3 | +using MudBlazor; |
| 4 | +using MudBlazor.Components.Highlighter; |
| 5 | +using MudBlazor.Extensions; |
| 6 | +using MudBlazor.Utilities; |
| 7 | +using System; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.Linq; |
| 10 | +using System.Text; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using static MudBlazor.CategoryTypes; |
| 13 | + |
| 14 | +namespace MudExtensions |
| 15 | +{ |
| 16 | + public partial class MudSplitter : MudComponentBase |
| 17 | + { |
| 18 | + |
| 19 | + Guid _styleGuid = Guid.NewGuid(); |
| 20 | + MudSlider<double> _slider; |
| 21 | + |
| 22 | + protected string Classname => new CssBuilder("mud-splitter") |
| 23 | + .AddClass($"border-solid border-8 mud-border-{Color.ToDescriptionString()}", Bordered == true) |
| 24 | + .AddClass($"mud-splitter-generate mud-splitter-generate-{_styleGuid}") |
| 25 | + .AddClass(Class) |
| 26 | + .Build(); |
| 27 | + |
| 28 | + protected string ContentClassname => new CssBuilder($"mud-splitter-content mud-splitter-content-{_styleGuid} d-flex ma-2") |
| 29 | + .AddClass(ClassContent) |
| 30 | + .Build(); |
| 31 | + |
| 32 | + protected string SliderClassname => new CssBuilder($"mud-splitter-thumb mud-splitter-thumb-{_styleGuid} mud-splitter-track") |
| 33 | + .Build(); |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// The two contents' (sections) classes, seperated by space. |
| 37 | + /// </summary> |
| 38 | + [Parameter] |
| 39 | + public string ClassContent { get; set; } |
| 40 | + |
| 41 | + string _height; |
| 42 | + /// <summary> |
| 43 | + /// The height of splitter. |
| 44 | + /// </summary> |
| 45 | + [Parameter] |
| 46 | + public string Height |
| 47 | + { |
| 48 | + get => _height; |
| 49 | + set |
| 50 | + { |
| 51 | + if (value == _height) |
| 52 | + { |
| 53 | + return; |
| 54 | + } |
| 55 | + _height = value; |
| 56 | + UpdateDimensions().AndForget(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// The height of splitter. |
| 62 | + /// </summary> |
| 63 | + [Parameter] |
| 64 | + public Color Color { get; set; } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// If true, splitter has borders. |
| 68 | + /// </summary> |
| 69 | + [Parameter] |
| 70 | + public bool Bordered { get; set; } |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// The two contents' (sections) styles, seperated by space. |
| 74 | + /// </summary> |
| 75 | + [Parameter] |
| 76 | + public string StyleContent { get; set; } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// The splitter bar's styles, seperated by space. All styles have to include !important and end with ';' |
| 80 | + /// </summary> |
| 81 | + [Parameter] |
| 82 | + public string StyleBar { get; set; } |
| 83 | + |
| 84 | + ///// <summary> |
| 85 | + ///// If true, splitter bar goes vertical. |
| 86 | + ///// </summary> |
| 87 | + //[Parameter] |
| 88 | + //public bool Horizontal { get; set; } |
| 89 | + |
| 90 | + [Parameter] |
| 91 | + public RenderFragment StartContent { get; set; } |
| 92 | + |
| 93 | + [Parameter] |
| 94 | + public RenderFragment EndContent { get; set; } |
| 95 | + |
| 96 | + [Parameter] |
| 97 | + public EventCallback DimensionChanged { get; set; } |
| 98 | + |
| 99 | + protected override async Task OnInitializedAsync() |
| 100 | + { |
| 101 | + await base.OnInitializedAsync(); |
| 102 | + await UpdateDimensions(); |
| 103 | + } |
| 104 | + |
| 105 | + double _firstContentDimension = 50; |
| 106 | + double _secondContentDimension = 50; |
| 107 | + protected async Task UpdateDimensions() |
| 108 | + { |
| 109 | + if (_slider == null) |
| 110 | + { |
| 111 | + return; |
| 112 | + } |
| 113 | + _firstContentDimension = _slider.Value; |
| 114 | + _secondContentDimension = 100d - _firstContentDimension; |
| 115 | + await DimensionChanged.InvokeAsync(); |
| 116 | + } |
| 117 | + |
| 118 | + public double GetStartContentPercentage() => _firstContentDimension; |
| 119 | + |
| 120 | + /// <summary> |
| 121 | + /// Updates the dimension with given the start content's percentage |
| 122 | + /// </summary> |
| 123 | + /// <param name="percentage"></param> |
| 124 | + public async Task SetDimensions(double percentage) |
| 125 | + { |
| 126 | + _slider.Value = percentage; |
| 127 | + await UpdateDimensions(); |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | +} |
0 commit comments