项目作者: carwow

项目描述 :
Elm package: customisable range sliders
高级语言: Elm
项目地址: git://github.com/carwow/elm-slider.git
创建时间: 2017-08-18T13:31:39Z
项目社区:https://github.com/carwow/elm-slider

开源协议:BSD 3-Clause "New" or "Revised" License

下载


elm-slider

A range slider component, implemented natively in Elm.

Installation

  1. elm install carwow/elm-slider

Live demo

You can check out the single and double sliders on this demo on Ellie.

Usage

For a full example implementation, see examples/Main.elm

There are two types of sliders that can be rendered, a SingleSlider, with one track thumb and a DoubleSlider, with two track thumbs.

Input handling is your responsibility - define a function to decided what to do when the slider’s value changes.

SingleSlider Example

  1. singleSlider =
  2. SingleSlider.init
  3. { min = 0
  4. , max = 1000
  5. , value = 500
  6. , step = 50
  7. , onChange = SingleSliderChange
  8. }
  9. type Msg
  10. = NoOp
  11. | SingleSliderChange Float
  12. view : Model -> Html Msg
  13. view model =
  14. div []
  15. [ div [] [ SingleSlider.view model.singleSlider ] ]

DoubleSliderExample

  1. doubleSlider =
  2. DoubleSlider.init
  3. { min = 0
  4. , max = 1000
  5. , lowValue = 500
  6. , highValue = 750
  7. , step = 50
  8. , onLowChange = DoubleSliderLowChange
  9. , onHighChange = DoubleSliderHighChange
  10. }
  11. type Msg
  12. = NoOp
  13. | DoubleSliderLowChange Float
  14. | DoubleSliderHighChange Float
  15. view : Model -> Html Msg
  16. view model =
  17. div []
  18. [ div [] [ DoubleSlider.view model.doubleSlider ] ]

Using a custom formatter

You can use a custom min label formatter, max label formatter, or value formatter like below:

  1. singleSlider =
  2. SingleSlider.init
  3. { min = 0
  4. , max = 1000
  5. , value = 500
  6. , step = 50
  7. , onChange = handleSingleSliderChange
  8. }
  9. |> SingleSlider.withMinFormatter minFormatter

CSS

Example CSS for the slider components is provided at examples/example.css

It is recommended to start with these styles and override them according to the theme of your website.