|
| 1 | +using Microsoft.AspNetCore.Components.CompilerServices; |
| 2 | + |
| 3 | +namespace Bit.BlazorUI; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// A component to easily use predefined bit BlazorUI media queries in Blazor components. |
| 7 | +/// </summary> |
| 8 | +public partial class BitMediaQuery : BitComponentBase |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// The content of the element. |
| 12 | + /// </summary> |
| 13 | + [Parameter] public RenderFragment? ChildContent { get; set; } |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Specifies the media query to match for the child content. |
| 17 | + /// </summary> |
| 18 | + [Parameter] public BitScreenQuery? Query { get; set; } |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + protected override string RootElementClass => "bit-mdq"; |
| 23 | + |
| 24 | + protected override void RegisterCssClasses() |
| 25 | + { |
| 26 | + ClassBuilder.Register(() => Query switch |
| 27 | + { |
| 28 | + BitScreenQuery.Xs => "bit-mdq-xs", |
| 29 | + BitScreenQuery.Sm => "bit-mdq-sm", |
| 30 | + BitScreenQuery.Md => "bit-mdq-md", |
| 31 | + BitScreenQuery.Lg => "bit-mdq-lg", |
| 32 | + BitScreenQuery.Xl => "bit-mdq-xl", |
| 33 | + BitScreenQuery.Xxl => "bit-mdq-xxl", |
| 34 | + BitScreenQuery.LtSm => "bit-mdq-ltsm", |
| 35 | + BitScreenQuery.LtMd => "bit-mdq-ltmd", |
| 36 | + BitScreenQuery.LtLg => "bit-mdq-ltlg", |
| 37 | + BitScreenQuery.LtXl => "bit-mdq-ltxl", |
| 38 | + BitScreenQuery.LtXxl => "bit-mdq-ltxxl", |
| 39 | + BitScreenQuery.GtXs => "bit-mdq-gtxs", |
| 40 | + BitScreenQuery.GtSm => "bit-mdq-gtsm", |
| 41 | + BitScreenQuery.GtMd => "bit-mdq-gtmd", |
| 42 | + BitScreenQuery.GtLg => "bit-mdq-gtlg", |
| 43 | + BitScreenQuery.GtXl => "bit-mdq-gtxl", |
| 44 | + _ => string.Empty |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + protected override void BuildRenderTree(RenderTreeBuilder builder) |
| 49 | + { |
| 50 | + builder.OpenElement(0, "div"); |
| 51 | + builder.AddMultipleAttributes(1, RuntimeHelpers.TypeCheck(HtmlAttributes)); |
| 52 | + builder.AddAttribute(2, "id", _Id); |
| 53 | + builder.AddAttribute(3, "style", StyleBuilder.Value); |
| 54 | + builder.AddAttribute(4, "class", ClassBuilder.Value); |
| 55 | + builder.AddAttribute(5, "dir", Dir?.ToString().ToLower()); |
| 56 | + builder.AddAttribute(6, "aria-label", AriaLabel); |
| 57 | + builder.AddElementReferenceCapture(7, v => RootElement = v); |
| 58 | + builder.AddContent(8, ChildContent); |
| 59 | + builder.CloseElement(); |
| 60 | + |
| 61 | + base.BuildRenderTree(builder); |
| 62 | + } |
| 63 | +} |
0 commit comments