🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

BlazorWheelPicker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

BlazorWheelPicker

BlazorWheelPicker is a tiny NuGet package containing two component for Blazor mimicking the iOS style wheel select input. It is pretty handy for developers using Blazor on MAUI app or for a mobile version of your website.

1.0.1
Source
NuGet
Version published
Maintainers
1
Created
Source

BlazorWheelPicker

BlazorWheelPicker is a tiny NuGet package containing two component for Blazor mimicking the iOS style wheel select input. It is pretty handy for developers using Blazor on MAUI app or for a mobile version of your website.

I used this codepen from Max Kohler for the css part which made me discover css scroll snapping : https://codepen.io/maxakohler/pen/JZgXxe

Get Started

Add the NuGet package via Package Manager:

NuGet\Install-Package BlazorWheelPicker 

via CLI :

dotnet add package BlazorWheelPicker

or simply add the reference in your .csproj file:

<PackageReference Include="BlazorWheelPicker" Version="1.0.0" />

Add the css reference to your index.html file located in /wwwroot

<link href="_content/BlazorWheelPicker/BlazorWheelPicker.css" rel="stylesheet" />

And the javascript:

<script src="_content/BlazorWheelPicker/wheelpicker.js"></script>

And finally add the namespace reference to _Imports.razor for more practicality:

@using BlazorWheelPickerLib;

Usage

This contains 2 components : WheelSelect and DateWheelSelect, the later is just an implementation for a date picker

WheelSelect

NameTypeDescriptionDefault
StylestringAdditional style you want to apply-
TType of the selectable items-
ItemsTSelectable item list-
WheelLevelintLevel of displayed items2
SelectionLinesbooleanWhether or not selection line in the middle are displayedtrue
DensebooleanWhether or not the item rows are densefalse
WheelColorstringHexadecimal value of the background wheel color#ffffff
TextColorstringHexadecimal value of the text color#000000
ValueTSelected value of the picker (or use @bind-Value)-
ValueChangedEventCallback<T>Value changed event (or use @bind-Value)-
ItemTemplateRenderFragment<T>Custom render template for rows-

Example:

<WheelSelect @bind-Value="_selectedCity" Style="width:50%" Dense="true" T="string" Items="Items">
    <ItemTemplate Context="test">
        <div style="display:flex;flex-direction:row;align-items:center;justify-content:center">
            @test
        </div>
    </ItemTemplate>
</WheelSelect>
@code
{
    public List<string> Items = new List<string>() { "Paris", "Rome", "London", "Berlin", "Madrid" };
    private string _selectedCity = "Paris";
}

Example of wheel select

DateWheelSelect

NameTypeDescriptionDefault
StylestringAdditional style you want to apply-
WheelLevelintLevel of displayed items2
DensebooleanWhether or not the item rows are densefalse
SelectionLinesbooleanWhether or not selection line in the middle are displayedtrue
WheelColorstringHexadecimal value of the background wheel color#ffffff
TextColorstringHexadecimal value of the text color#000000
ValueDateTimeSelected DateTime value of the picker (or use @bind-Value)-
ValueChangedEventCallback <DateTime>DateTime Value changed event (or use @bind-Value)-
MinYearDateTime?Minimum year displayed1970
MaxYearDateTime?Maximum year displayed2070

Example:

<DateWheelSelect MaxYear="DateTime.Now.AddYears(40)" MinYear="DateTime.Now.AddYears(-40)" WheelLevel="2" Dense="false" @bind-Value="SelectedDate">
</DateWheelSelect>
<p>Selected Date : @SelectedDate.ToString("dd-MM-yyyy")</p>
@code
{
    DateTime SelectedDate = DateTime.Now;
}

Example of date wheel select

Misc

If used with MAUI, i suggest to add a vibration when a value is changed for a native feel:

HapticFeedback.Default.Perform(HapticFeedbackType.Click);

License

This package is under the MIT license, feel free to fork it and modify it.

Keywords

Blazor

FAQs

Package last updated on 24 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts