GithubHelp home page GithubHelp logo

maxfarseer / elm-daterange-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from n1k0/elm-daterange-picker

0.0 1.0 0.0 175 KB

A date range picker written in Elm.

Home Page: https://package.elm-lang.org/packages/allo-media/elm-daterange-picker/latest/

License: MIT License

Elm 88.69% CSS 11.31%

elm-daterange-picker's Introduction

elm-daterange-picker

A date range picker written in Elm (Demo).

How is this useful?

Selecting a date range is a common operation for many Web applications. While there are offerings in the Elm ecosystem, we couldn't find any ergonomic equivalent of daterangepicker, which this package takes a lot of inspiration from.

Demo

You can look at how this package can be used by browsing this demo code here.

Usage

import Browser
import DateRangePicker as Picker
import Html exposing (Html, text)

type alias Model =
    { picker : Picker.State }

type Msg
    = PickerChanged Picker.State

init : () -> ( Model, Cmd Msg )
init _ =
    let
        picker =
            Picker.init Picker.defaultConfig Nothing
    in
    ( { picker = picker }
    , Picker.now PickerChanged picker
    )

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        PickerChanged state ->
            ( { model | picker = state }, Cmd.none )

view : Model -> Html Msg
view model =
    Picker.view PickerChanged model.picker

main =
    Browser.element
        { init = init
        , update = update
        , view = view
        , subscriptions = .picker >> Picker.subscriptions PickerChanged
        }

Customize styles

By default, we have not defined any default font-family, so that the style fits any app/site.

You can use the style.css file or its SCSS source as a starting point for fine-tuning the default styles of the datepicker, which also uses CSS variables to help you tweaking most colors used by the component; just add your own root colors after calling our CSS, and it's done:

:root {
  --edrp-background-color: #fff;
  --edrp-font-color: rgba(0, 0, 0, 0.8);
  --edrp-primary-color: rgb(82, 143, 255);
  --edrp-primary-color-alpha: rgba(82, 143, 255, 0.25);
  --edrp-border-color: lightgrey;
}

So if you have questionable tastes, you can eventually obtain this:

Install

elm install allo-media/elm-daterange-picker

Local install

npm install

Run the demo

The demo is powered by elm-live, meaning any code changes will trigger a page reload. Neat!

npm start

Then head to localhost:3000 from your browser.

Hacking on the demo with Atom & Elmjutsu

If you've configured Atom & Elmjutsu to use ./node_modules/.bin/elm as the default path to the Elm executable, you'll need a trick for having the compiler working when editing demo/Main.elm:

mkdir -P demo/node_modules/.bin
ln -sf ../../../node_modules/.bin/elm demo/node_modules/.bin/elm

License

MIT

elm-daterange-picker's People

Contributors

beardedbear avatar n1k0 avatar

Watchers

 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.