GithubHelp home page GithubHelp logo

mathisloge / flatpickrblazor Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 6.0 261 KB

Blazor version of FlatPicker.js

Home Page: https://mathisloge.github.io/FlatpickrBlazorExample/

License: MIT License

HTML 2.04% C# 2.84% JavaScript 94.36% CSS 0.76%
flatpickr blazor blazor-server blazor-component blazor-extensions blazor-interop

flatpickrblazor's Introduction

FlatPickr Blazor

uses https://github.com/flatpickr/flatpickr under the hood.

Nuget Version is availible under https://www.nuget.org/packages/FlatPickrBlazor

Install-Package FlatPickrBlazor

Usage

MyFlatpickr.razor

<div>
	<Flatpickr hidden class="my-custom-class" @ref="_datepicker" Options="@calendarOpts" OnChange="@OnChangeDate" />
	<Flatpickr Options="@monthPickerOpts" PluginOptions="@monthPluginOptions" />
</div>

@code{
    private Flatpickr _datepicker;

    private FlatpickrOptions calendarOpts = new FlatpickrOptions
    {
        Inline = true,
        WeekNumbers = true,
        MaxDate = DateTimeOffset.UtcNow,
        Locale = "de",
        Mode = FlatpickrOptionsMode.Range
    };

    private FlatpickrOptions monthPickerOpts = new FlatpickrOptions
    {
        Inline = true
    };

    // these are already default values, so new FlatpickrPluginOptions() would fullfill everything, if you want default values
    private FlatpickrPluginOptions monthPluginOptions = new FlatpickrPluginOptions
    {
        UseMonthSelectPlugin = new FlatpickrPluginOptions.MonthSelectOptions
        {
            ShortHand = false,
            DateFormat = "F Y",
            AltFormat = "F Y",
            Theme = "light"
        }
    };

    private void OnChangeDate(List<DateTimeOffset> dateTimes)
    {
        foreach (var dateTime in dateTimes)
        {
            Console.WriteLine(dateTime.ToString());
        }
    }
}

_Host.cshtml

you have to include at a minimum these to your _Host.cshtml

<link href="_content/FlatpickrBlazor/flatpickr.min.css" rel="stylesheet" />
<script src="_content/FlatpickrBlazor/flatpickr.min.js"></script>
<script src="_content/FlatpickrBlazor/flatpickr.blazor.js"></script>

to add a locale (specify in your FlatpickrOptions variable) add the following script:

<script src="_content/FlatpickrBlazor/l10n/de.js"></script>

and change the "de.js" with your choosed language

to add the plugins, you have to include the script and style files. e.g. for the month select plugin:

<link href="_content/FlatpickrBlazor/plugins/monthSelect/style.css" rel="stylesheet" />
<script src="_content/FlatpickrBlazor/plugins/monthSelect/index.js"></script>

flatpickrblazor's People

Contributors

dependabot[bot] avatar mathisloge avatar zimm-lostpolygon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.