docspell/modules/webapp/src/main/elm/Comp/StringListInput.elm
Eike Kettner dd935454c9 First version of new ui based on tailwind
This drops fomantic-ui as css toolkit and introduces tailwindcss. With
tailwind there are no predefined components, but it's very easy to
create those. So customizing the look&feel is much simpler, most of
the time no additional css is needed.

This requires a complete rewrite of the markup + styles. Luckily all
logic can be kept as is. The now old ui is not removed, it is still
available by using a request header `Docspell-Ui` with a value of `1`
for the old ui and `2` for the new ui.

Another addition is "dev mode", where docspell serves assets with a
no-cache header, to disable browser caching. This makes developing a
lot easier.
2021-02-14 01:46:13 +01:00

148 lines
3.2 KiB
Elm

module Comp.StringListInput exposing
( ItemAction(..)
, Model
, Msg
, init
, update
, view
, view2
)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
import Styles as S
import Util.Maybe
type alias Model =
{ currentInput : String
}
type Msg
= AddString
| RemoveString String
| SetString String
init : Model
init =
{ currentInput = ""
}
--- Update
type ItemAction
= AddAction String
| RemoveAction String
| NoAction
update : Msg -> Model -> ( Model, ItemAction )
update msg model =
case msg of
SetString str ->
( { model | currentInput = str }
, NoAction
)
AddString ->
( { model | currentInput = "" }
, Util.Maybe.fromString model.currentInput
|> Maybe.map AddAction
|> Maybe.withDefault NoAction
)
RemoveString s ->
( model, RemoveAction s )
--- View
view : List String -> Model -> Html Msg
view values model =
let
valueItem s =
div [ class "item" ]
[ a
[ class "ui icon link"
, onClick (RemoveString s)
, href "#"
]
[ i [ class "delete icon" ] []
]
, text s
]
in
div [ class "string-list-input" ]
[ div [ class "ui list" ]
(List.map valueItem values)
, div [ class "ui icon input" ]
[ input
[ placeholder ""
, type_ "text"
, onInput SetString
, value model.currentInput
]
[]
, i
[ class "circular add link icon"
, onClick AddString
]
[]
]
]
--- View2
view2 : List String -> Model -> Html Msg
view2 values model =
let
valueItem s =
div [ class "flex flex-row items-center" ]
[ a
[ class S.deleteLabel
, onClick (RemoveString s)
, href "#"
]
[ i [ class "fa fa-trash" ] []
]
, span [ class "ml-2" ]
[ text s
]
]
in
div [ class "flex flex-col" ]
[ div [ class "relative" ]
[ input
[ placeholder ""
, type_ "text"
, onInput SetString
, value model.currentInput
, class ("pr-10 py-2 rounded" ++ S.textInput)
]
[]
, a
[ href "#"
, onClick AddString
, class S.inputLeftIconLink
]
[ i [ class "fa fa-plus" ] []
]
]
, div
[ class "flex flex-col space-y-4 md:space-y-2 mt-2"
, class "px-2 border-0 border-l dark:border-bluegray-600"
]
(List.map valueItem values)
]