FordLabs/elm-star-rating/1.2.0

NOTE: the latest version is 2.0.1

Rating

A simple five star rating component. Uses unicode star characters ★ & ☆ (U+2605 & U+2606) by default. Allows for custom Html elements to be used.

Init

Initial rating state. Sets rating to zero. Uses "★" and "☆".

initialCustomState : Html Msg -> Html Msg -> State

Initial rating state. Sets rating to zero. Uses html passed in by user.

View

classView : List String -> State -> Html Msg

Render the component. Accepts a list of css class names and a Rating.State. Note that the component uses text characters to display the stars, so use css accordingly.

Rating.classView [ "cssClass1", "cssClass2" ] ratingState
styleView : List ( String, String ) -> State -> Html Msg

Render the component. Accepts a list of style tuples and a Rating.State. Note that the component uses text characters to display the stars, so use css accordingly.

Rating.styleView [ ( "color", "red" ) ] ratingState

Update

Update the state of the rating component.

RatingMsg msg ->
    ( { model | ratingState = (Rating.update msg model.ratingState) }, Cmd.none )

Helpers

get : State -> Int

Get the current rating.

Rating.get ratingState
set : Int -> State -> State

Set the rating. Keeps values between 0 and 5.

Rating.set 4 ratingState

Types

type State

Opaque type obscuring rating model.

type Msg

Opaque type obscuring rating messages.