Skip to content

Commit

Permalink
🆕 feat(Slider): support for other numeric types including double (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Mar 3, 2023
1 parent 169e6cd commit 1c32948
Show file tree
Hide file tree
Showing 26 changed files with 75 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
@onblur="OnBlur"
@onkeydown="OnKeyDown"
@onkeydown:preventDefault>
@RenderPart(typeof(BSliderThumb<,>))
@RenderPart(typeof(BSliderThumb<,,>))
@if (ShowThumbLabel)
{
@RenderPart(typeof(BSliderThumbLabel<,>))
@RenderPart(typeof(BSliderThumbLabel<,,>))
}
</div>

Expand All @@ -23,10 +23,10 @@
@onblur="OnSecondBlur"
@onkeydown="OnKeyDown"
@onkeydown:preventDefault>
@RenderPart(typeof(BSliderThumb<,>))
@RenderPart(typeof(BSliderThumb<,,>))
@if (ShowThumbLabel)
{
@RenderPart(typeof(BSliderThumbLabel<,>),1,arg0Name:"Index")
@RenderPart(typeof(BSliderThumbLabel<,,>),1,arg0Name:"Index")
}
</div>

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TRangeSlider
@inherits BSliderTrackContainer<IList<TValue>,TRangeSlider>
@inherits BSliderTrackContainer<IList<TValue>, TValue, TRangeSlider>

<div class="@CssProvider.GetClass("track-container")" @ref="TrackElement">
@for (var i = 0; i < 3; i++)
{
var index = i;
<div class="@CssProvider.GetClass("range-track-background",index)" style="@CssProvider.GetStyle("range-track-background",index)"></div>
<div class="@CssProvider.GetClass("range-track-background", index)" style="@CssProvider.GetStyle("range-track-background", index)"></div>
}
</div>

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

namespace BlazorComponent
namespace BlazorComponent
{
public interface IRangeSlider<TValue> : ISlider<IList<TValue>>
public interface IRangeSlider<TValue> : ISlider<IList<TValue>, TValue>
{
ElementReference SecondThumbElement { set; }

Expand All @@ -12,4 +9,3 @@ public interface IRangeSlider<TValue> : ISlider<IList<TValue>>
Task HandleOnSecondBlurAsync(FocusEventArgs args);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BlazorComponent
{
public static class RangeSliderAbstractProviderExtensions
{
public static ComponentAbstractProvider ApplyRangeSliderDefault<TValue>(this ComponentAbstractProvider abstractProvider)
{
return abstractProvider
.Merge(typeof(BSliderThumbContainer<,,>), typeof(BRangeSliderThumbContainer<TValue, IRangeSlider<TValue>>))
.Merge(typeof(BSliderInput<,,>), typeof(BRangeSliderInput<TValue, IRangeSlider<TValue>>))
.Merge(typeof(BSliderTrackContainer<,,>), typeof(BRangeSliderTrackContainer<TValue, IRangeSlider<TValue>>));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits BInputDefaultSlot<TValue,TInput>
@inherits BInputDefaultSlot<TValue, TInput>

@if (!InverseLabel)
{
@RenderPart(typeof(BInputLabel<,>))
}
@RenderPart(typeof(BSliderSlider<,>))
@RenderPart(typeof(BSliderSlider<,,>))
@if (InverseLabel)
{
@RenderPart(typeof(BInputLabel<,>))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BlazorComponent
{
public partial class BSliderDefaultSlot<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderDefaultSlot<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public bool InverseLabel => Component.InverseLabel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand All @@ -12,5 +13,5 @@
@onmouseup:preventDefault
@onmouseup:stopPropagation
@onexmousedown:preventDefault>
@RenderPart(typeof(BSliderChildren<,>))
@RenderPart(typeof(BSliderChildren<,,>))
</div>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

namespace BlazorComponent
namespace BlazorComponent
{
public partial class BSliderSlider<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderSlider<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public EventCallback<MouseEventArgs> HandleOnSliderClickAsync => EventCallback.Factory.Create<MouseEventArgs>(Component, Component.HandleOnSliderClickAsync);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

@RenderPart(typeof(BSliderInput<,>))
@RenderPart(typeof(BSliderTrackContainer<,>))
@RenderPart(typeof(BSliderSteps<,>))
@RenderPart(typeof(BSliderThumbContainer<,>))
@RenderPart(typeof(BSliderInput<,,>))
@RenderPart(typeof(BSliderTrackContainer<,,>))
@RenderPart(typeof(BSliderSteps<,,>))
@RenderPart(typeof(BSliderThumbContainer<,,>))

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace BlazorComponent
{
public partial class BSliderChildren<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderChildren<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{

}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace BlazorComponent
{
public partial class BSliderInput<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderInput<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public TValue InternalValue => Component.InternalValue;

public Dictionary<string, object> InputAttrs => Component.InputAttrs;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace BlazorComponent
{
public partial class BSliderSteps<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderSteps<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public double Step => Component.Step;
public double Step => (double)(dynamic)Component.Step;

public bool ShowTicks => Component.ShowTicks;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand All @@ -9,9 +10,9 @@
@onblur="OnBlur"
@onkeydown="OnKeyDown"
@onkeydown:preventDefault>
@RenderPart(typeof(BSliderThumb<,>))
@RenderPart(typeof(BSliderThumb<,,>))
@if (ShowThumbLabel)
{
@RenderPart(typeof(BSliderThumbLabel<,>))
@RenderPart(typeof(BSliderThumbLabel<,,>))
}
</div>
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

namespace BlazorComponent
namespace BlazorComponent
{
public partial class BSliderThumbContainer<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderThumbContainer<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public ElementReference ThumbElement
{
set
{
Component.ThumbElement = value;
}
set { Component.ThumbElement = value; }
}

public Dictionary<string, object> ThumbAttrs => Component.ThumbAttrs;
Expand All @@ -19,7 +13,8 @@ public ElementReference ThumbElement

public EventCallback<FocusEventArgs> OnBlur => EventCallback.Factory.Create<FocusEventArgs>(Component, Component.HandleOnBlurAsync);

public EventCallback<KeyboardEventArgs> OnKeyDown => EventCallback.Factory.Create<KeyboardEventArgs>(Component, Component.HandleOnKeyDownAsync);
public EventCallback<KeyboardEventArgs> OnKeyDown =>
EventCallback.Factory.Create<KeyboardEventArgs>(Component, Component.HandleOnKeyDownAsync);

public bool ShowThumbLabel => Component.ShowThumbLabel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BlazorComponent
{
public partial class BSliderThumb<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderThumb<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

<ScaleTransition Origin="bottom center">
<ShowTransitionElement Value="ShowThumbLabelContainer" class="@CssProvider.GetClass("thumb-label-container")" style="@CssProvider.GetStyle("thumb-label-container")">
<div class="@CssProvider.GetClass("thumb-label")">
<div>@ThumbLabelContent(Index)</div>
<div>@ComputedThumbLabelContent</div>
</div>
</ShowTransitionElement>
</ScaleTransition>


Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Microsoft.AspNetCore.Components;

namespace BlazorComponent
namespace BlazorComponent
{
public partial class BSliderThumbLabel<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderThumbLabel<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
[Parameter]
public int Index { get; set; }

public RenderFragment<int> ThumbLabelContent => Component.ThumbLabelContent;
public RenderFragment ComputedThumbLabelContent => Component.ComputedThumbLabelContent(Index);

public bool ShowThumbLabelContainer => Component.ShowThumbLabelContainer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorComponent
@typeparam TValue
@typeparam TNumeric
@typeparam TInput
@inherits ComponentPartBase<TInput>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using Microsoft.AspNetCore.Components;

namespace BlazorComponent
namespace BlazorComponent
{
public partial class BSliderTrackContainer<TValue, TInput> where TInput : ISlider<TValue>
public partial class BSliderTrackContainer<TValue, TNumeric, TInput> where TInput : ISlider<TValue, TNumeric>
{
public ElementReference TrackElement
{
set
{
Component.TrackElement = value;
}
set { Component.TrackElement = value; }
}
}
}

11 changes: 4 additions & 7 deletions src/Component/BlazorComponent/Components/Slider/ISlider.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

namespace BlazorComponent
namespace BlazorComponent
{
public interface ISlider<TValue> : IInput<TValue>, ILoadable
public interface ISlider<TValue, out TNumeric> : IInput<TValue>, ILoadable
{
bool InverseLabel => default;

Dictionary<string, object> InputAttrs { get; }

ElementReference TrackElement { set; }

double Step { get; }
TNumeric Step { get; }

bool ShowTicks { get; }

Expand All @@ -35,7 +32,7 @@ public interface ISlider<TValue> : IInput<TValue>, ILoadable

bool ShowThumbLabelContainer { get; }

RenderFragment<int> ThumbLabelContent { get; }
RenderFragment<int> ComputedThumbLabelContent { get; }

Task HandleOnSliderClickAsync(MouseEventArgs args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
{
public static class SliderAbstractProviderExtensions
{
public static ComponentAbstractProvider ApplySliderDefault<TValue>(this ComponentAbstractProvider abstractProvider)
public static ComponentAbstractProvider ApplySliderDefault<TValue, TNumeric>(this ComponentAbstractProvider abstractProvider)
{
return abstractProvider
.ApplyInputDefault<double>()
.Merge(typeof(BInputDefaultSlot<,>), typeof(BSliderDefaultSlot<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderSlider<,>), typeof(BSliderSlider<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderChildren<,>), typeof(BSliderChildren<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderInput<,>), typeof(BSliderInput<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderSteps<,>), typeof(BSliderSteps<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderThumbContainer<,>), typeof(BSliderThumbContainer<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderThumb<,>), typeof(BSliderThumb<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderThumbLabel<,>), typeof(BSliderThumbLabel<TValue, ISlider<TValue>>))
.Apply(typeof(BSliderTrackContainer<,>), typeof(BSliderTrackContainer<TValue, ISlider<TValue>>));
.Merge(typeof(BInputDefaultSlot<,>), typeof(BSliderDefaultSlot<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderSlider<,,>), typeof(BSliderSlider<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderChildren<,,>), typeof(BSliderChildren<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderInput<,,>), typeof(BSliderInput<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderSteps<,,>), typeof(BSliderSteps<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderThumbContainer<,,>), typeof(BSliderThumbContainer<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderThumb<,,>), typeof(BSliderThumb<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderThumbLabel<,,>), typeof(BSliderThumbLabel<TValue, TNumeric, ISlider<TValue, TNumeric>>))
.Apply(typeof(BSliderTrackContainer<,,>), typeof(BSliderTrackContainer<TValue, TNumeric, ISlider<TValue, TNumeric>>));
}
}
}
Loading

0 comments on commit 1c32948

Please sign in to comment.