-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/BlazorUI/Bit.BlazorUI.Extras/Components/ProLayout/BitCascadingValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Bit.BlazorUI; | ||
|
||
public class BitCascadingValue | ||
{ | ||
public string? Name { get; set; } | ||
public object? Value { get; set; } | ||
|
||
public BitCascadingValue() { } | ||
|
||
public BitCascadingValue(object? value, string? name = null) | ||
{ | ||
Name = name; | ||
Value = value; | ||
} | ||
|
||
public static implicit operator BitCascadingValue(int value) => new(value); | ||
public static implicit operator BitCascadingValue(int? value) => new(value); | ||
public static implicit operator BitCascadingValue(bool value) => new(value); | ||
public static implicit operator BitCascadingValue(bool? value) => new(value); | ||
public static implicit operator BitCascadingValue(string value) => new(value); | ||
public static implicit operator BitCascadingValue(BitDir? value) => new(value); | ||
public static implicit operator BitCascadingValue(RouteData value) => new(value); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/BlazorUI/Bit.BlazorUI.Extras/Components/ProLayout/BitCascadingValueProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Bit.BlazorUI; | ||
|
||
public class BitCascadingValueProvider : ComponentBase | ||
{ | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] | ||
private Type _cascadingValueType = typeof(CascadingValue<>); | ||
|
||
[Parameter] public RenderFragment? ChildContent { get; set; } | ||
[Parameter] public IEnumerable<BitCascadingValue> Values { get; set; } = []; | ||
|
||
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(BitCascadingValue))] | ||
protected override void BuildRenderTree(RenderTreeBuilder builder) | ||
{ | ||
var seq = 0; | ||
RenderFragment? rf = ChildContent; | ||
|
||
foreach (var value in Values) | ||
{ | ||
if (value.Value is null) continue; | ||
|
||
var r = rf; | ||
var s = seq; | ||
var v = value; | ||
|
||
rf = b => { CreateCascadingValue(b, s, v.Name, v.Value, r); }; | ||
|
||
seq += string.IsNullOrEmpty(v.Name) ? 3 : 4; | ||
} | ||
|
||
builder.AddContent(seq, rf); | ||
} | ||
|
||
|
||
private void CreateCascadingValue(RenderTreeBuilder builder, | ||
int seq, | ||
string? name, | ||
object value, | ||
RenderFragment? childContent) | ||
{ | ||
#pragma warning disable IL2055 // Either the type on which the MakeGenericType is called can't be statically determined, or the type parameters to be used for generic arguments can't be statically determined. | ||
builder.OpenComponent(seq, _cascadingValueType.MakeGenericType(value.GetType())); | ||
#pragma warning restore IL2055 // Either the type on which the MakeGenericType is called can't be statically determined, or the type parameters to be used for generic arguments can't be statically determined. | ||
if (string.IsNullOrEmpty(name) is false) | ||
{ | ||
builder.AddComponentParameter(++seq, "Name", name); | ||
} | ||
builder.AddComponentParameter(++seq, "Value", value); | ||
builder.AddComponentParameter(++seq, "ChildContent", childContent); | ||
builder.CloseComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/BlazorUI/Bit.BlazorUI.Extras/Styles/extra-variables.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
$bit-env-inset-top: var(--bit-env-inset-top); | ||
$bit-env-inset-left: var(--bit-env-inset-left); | ||
$bit-env-inset-right: var(--bit-env-inset-right); | ||
$bit-env-inset-bottom: var(--bit-env-inset-bottom); | ||
//-- | ||
$bit-env-width-vw: var(--bit-env-width-vw); | ||
$bit-env-height-vh: var(--bit-env-height-vh); | ||
$bit-env-width-percent: var(--bit-env-width-per); | ||
$bit-env-height-percent: var(--bit-env-height-per); | ||
$bit-env-width-available: var(--bit-env-width-avl); | ||
$bit-env-height-available: var(--bit-env-height-avl); | ||
//-- | ||
$bit-env-inset-inline-start: var(--bit-env-inset-inline-start); | ||
$bit-env-inset-inline-end: var(--bit-env-inset-inline-end); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters