dwyl / elm-criteria / Criteria

This package help you create a hierarchy of "filters" contained in a dropdown

Have a look at a live example and its code

View

view : Config msg filter -> State -> List filter -> Html msg

The view function which take the configuration the state and a list of filters

Config


type Config msg filter

Configuration for displaying the hierarchy of filters

config : { title : String, toMsg : State -> msg, toId : filter -> FilterId, toString : filter -> String, getSubFilters : filter -> List filter } -> Config msg filter

Create the configuation to pass in your view.

State


type State

Define if the hierarchy of filters is open the set of the selected filters the set of filters where the sub-filters are displayed State False Set.empty

init : List FilterId -> State

Initialise the state, ie filters are hidden and filters are selected based on the list of ids passed as first argument to the init function

import Criteria

Criteria.init ["idFilter1", "idFilter5"]

Customise

customConfig : { title : String, toMsg : State -> msg, toId : filter -> FilterId, toString : filter -> String, getSubFilters : filter -> List filter, customisations : Customisations filter msg } -> Config msg filter

Create a customised configuation. This function is similat to config. It takes one more value customisations which defined how to customise the element of the module

defaultCustomisations : Customisations filter msg

the defaultCustomisations function provide the default attribute values for elm-criteria. These values can be resetted with the function customConfig

Helpers

selectedIdFilters : State -> Set FilterId

Return the set of the selected filters' id

unselectFilter : FilterId -> State -> State

Unselect a filter

openFilters : State -> State

Set the open state value to True

closeFilters : State -> State

Set the open state value to False

isOpen : State -> Basics.Bool

Return the open state value