Add icon to fixed dropdown

This commit is contained in:
Eike Kettner 2021-03-27 18:30:32 +01:00
parent 589e136883
commit 9fcab84267
13 changed files with 32 additions and 14 deletions

View File

@ -190,6 +190,7 @@ view2 settings model =
Comp.FixedDropdown.Item
model.categoryListType
(Data.ListType.label model.categoryListType)
Nothing
in
div []
[ Markdown.toHtml [ class "px-2 py-2 opacity-75" ]

View File

@ -101,7 +101,7 @@ view2 data opts model =
[ text opts.label ]
, Html.map LeftMsg
(Comp.FixedDropdown.view2
(Maybe.map (\s -> Comp.FixedDropdown.Item s s) model.leftSelect)
(Maybe.map (\s -> Comp.FixedDropdown.Item s s Nothing) model.leftSelect)
model.leftDropdown
)
, div [ class "field" ]

View File

@ -45,6 +45,7 @@ makeDropdownItem : ContactType -> Comp.FixedDropdown.Item ContactType
makeDropdownItem ct =
{ id = ct
, display = Data.ContactType.toString ct
, icon = Nothing
}

View File

@ -201,7 +201,7 @@ view2 : ViewSettings -> Model -> List (Html Msg)
view2 viewSettings model =
let
mkItem cft =
Comp.FixedDropdown.Item cft (Data.CustomFieldType.label cft)
Comp.FixedDropdown.Item cft (Data.CustomFieldType.label cft) Nothing
dimmerSettings =
Comp.YesNoDimmer.defaultSettings2 "Really delete this custom field?"

View File

@ -147,7 +147,7 @@ type alias UpdateResult =
mkItem : CustomField -> Comp.FixedDropdown.Item CustomField
mkItem f =
Comp.FixedDropdown.Item f (Maybe.withDefault f.name f.label)
Comp.FixedDropdown.Item f (Maybe.withDefault f.name f.label) Nothing
update : Flags -> Msg -> Model -> UpdateResult

View File

@ -161,4 +161,4 @@ view2 model =
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item EquipmentUse)
makeUseItem model =
Just <|
Comp.FixedDropdown.Item model.use (Data.EquipmentUse.label model.use)
Comp.FixedDropdown.Item model.use (Data.EquipmentUse.label model.use) Nothing

View File

@ -23,6 +23,7 @@ import Util.List
type alias Item a =
{ id : a
, display : String
, icon : Maybe String
}
@ -49,19 +50,19 @@ init options =
initString : List String -> Model String
initString strings =
init <| List.map (\s -> Item s s) strings
init <| List.map (\s -> Item s s Nothing) strings
initMap : (a -> String) -> List a -> Model a
initMap elToString els =
init <| List.map (\a -> Item a (elToString a)) els
init <| List.map (\a -> Item a (elToString a) Nothing) els
initTuple : List ( String, a ) -> Model a
initTuple tuples =
let
mkItem ( txt, id ) =
Item id txt
Item id txt Nothing
in
init <| List.map mkItem tuples
@ -170,6 +171,14 @@ update msg model =
viewStyled2 : DS.DropdownStyle -> Bool -> Maybe (Item a) -> Model a -> Html (Msg a)
viewStyled2 style error sel model =
let
iconItem item =
span
[ classList [ ( "hidden", item.icon == Nothing ) ]
, class (Maybe.withDefault "" item.icon)
, class "mr-2"
]
[]
renderItem item =
a
[ href "#"
@ -180,8 +189,13 @@ viewStyled2 style error sel model =
]
, onClick (SelectItem2 item)
]
[ text item.display
[ iconItem item
, text item.display
]
selIcon =
Maybe.map iconItem sel
|> Maybe.withDefault (span [ class "hidden" ] [])
in
div
[ class ("relative " ++ style.root)
@ -200,7 +214,8 @@ viewStyled2 style error sel model =
[ ( "opacity-50", sel == Nothing )
]
]
[ Maybe.map .display sel
[ selIcon
, Maybe.map .display sel
|> Maybe.withDefault "Select"
|> text
]

View File

@ -277,7 +277,7 @@ update flags msg model =
makeItem : IdName -> Comp.FixedDropdown.Item IdName
makeItem idn =
Comp.FixedDropdown.Item idn idn.name
Comp.FixedDropdown.Item idn idn.name Nothing
view2 : Flags -> Model -> Html Msg

View File

@ -150,7 +150,7 @@ update flags msg model =
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item OrgUse)
makeUseItem model =
Just <|
Comp.FixedDropdown.Item model.use (Data.OrgUse.label model.use)
Comp.FixedDropdown.Item model.use (Data.OrgUse.label model.use) Nothing
view2 : Bool -> UiSettings -> Model -> Html Msg

View File

@ -179,7 +179,7 @@ update flags msg model =
makeUseItem : Model -> Maybe (Comp.FixedDropdown.Item PersonUse)
makeUseItem model =
Just <|
Comp.FixedDropdown.Item model.use (Data.PersonUse.label model.use)
Comp.FixedDropdown.Item model.use (Data.PersonUse.label model.use) Nothing

View File

@ -237,7 +237,7 @@ init flags =
mkLanguageItem : Language -> Comp.FixedDropdown.Item Language
mkLanguageItem lang =
Comp.FixedDropdown.Item lang (Data.Language.toName lang)
Comp.FixedDropdown.Item lang (Data.Language.toName lang) Nothing

View File

@ -336,6 +336,7 @@ view2 _ settings model =
Comp.FixedDropdown.Item
model.priority
(Data.Priority.toName model.priority)
Nothing
in
div [ class "flex flex-col" ]
[ div [ class "mb-4" ]

View File

@ -40,7 +40,7 @@ type alias Model =
mkLanguageItem : Language -> Comp.FixedDropdown.Item Language
mkLanguageItem lang =
Comp.FixedDropdown.Item lang (Data.Language.toName lang)
Comp.FixedDropdown.Item lang (Data.Language.toName lang) Nothing
emptyModel : Model