Commit 2dd29102 authored by André Espaze's avatar André Espaze
Browse files

Refactoring selection list to ItemSelector

parent ee09c2221a42
module Common exposing (classes)
import Html.Styled exposing (Attribute)
import Html.Styled.Attributes exposing (class)
classes : List String -> Attribute msg
classes xs =
class (String.join " " xs)
module ItemSelector exposing (view)
import Common exposing (classes)
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (classList)
import Html.Styled.Events exposing (onMouseDown)
import Tachyons.Classes as T
view : (String -> msg) -> List String -> List String -> Html msg
view toMsg items selectedItems =
let
ulClass =
classes [ T.list, T.pl0, T.ml0, T.w_100, T.ba, T.b__light_silver, T.br3 ]
liAttrs item =
let
liClass =
classes [ T.ph3, T.pv2, T.bb, T.b__light_silver, T.dim ]
liSelected =
let
isSelected =
List.member item selectedItems
in
classList <|
List.map
(\x -> ( x, isSelected ))
[ T.white, T.bg_blue ]
in
[ liClass, liSelected, onMouseDown <| toMsg item ]
in
ul [ ulClass ] <|
List.map
(\x -> li (liAttrs x) [ text x ])
items
......@@ -13,11 +13,13 @@
module Main exposing (main)
import Browser
import Common exposing (classes)
import Dict
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (class, classList)
import Html.Styled.Events exposing (onInput, onMouseDown)
import Http
import ItemSelector
import Json.Decode as Decode
import KeywordSelector
import Tachyons.Classes as T
......@@ -44,11 +46,6 @@ type Msg
| MakeSearch
classes : List String -> Attribute msg
classes xs =
class (String.join " " xs)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
let
......@@ -93,25 +90,6 @@ update msg model =
view : Model -> Html Msg
view model =
let
ul_class =
classes [ T.list, T.pl0, T.ml0, T.w_100, T.ba, T.b__light_silver, T.br3 ]
li_class =
classes [ T.ph3, T.pv2, T.bb, T.b__light_silver, T.dim ]
li_selected serie =
let
is_selected =
List.member serie model.selectedSeries
in
classList <| List.map (\x -> ( x, is_selected )) [ T.white, T.bg_blue ]
li_attrs x =
[ li_class, li_selected x, onMouseDown <| ToggleItem x ]
renderSeries xs =
ul [ ul_class ] <| List.map (\x -> li (li_attrs x) [ text x ]) xs
article_class =
classes [ T.center, T.pt4, T.w_90 ]
......@@ -127,7 +105,12 @@ view model =
input [ input_class, onInput SearchSeries ] []
cols =
List.map (\x -> div [ classes [ T.dtc, T.pa1 ] ] [ renderSeries x ])
let
attrs =
[ classes [ T.dtc, T.pa1 ] ]
in
List.map
(\x -> div attrs [ ItemSelector.view ToggleItem x model.selectedSeries ])
[ model.searchedSeries, model.selectedSeries ]
in
[ div [ classes [ T.dt, T.dt__fixed ] ] [ searchInput ]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment