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

114 lines
2.8 KiB
Elm

module Comp.Tabs exposing
( State(..)
, Style
, Tab
, akkordion
, akkordionTab
, defaultStyle
, searchMenuStyle
)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
type alias Tab msg =
{ title : String
, info : Maybe String
, body : List (Html msg)
}
type alias Style =
{ rootClasses : String
, tabClasses : String
, titleClasses : String
, bodyClasses : String
}
type State
= Open
| Closed
| Hidden
defaultStyle : Style
defaultStyle =
{ rootClasses = "border-0 border-t dark:border-bluegray-600"
, tabClasses = "border-0 border-b dark:border-bluegray-600"
, titleClasses = "py-4 md:py-2 px-2 bg-gray-50 hover:bg-gray-100 dark:bg-bluegray-700 dark:bg-opacity-50 dark:hover:bg-opacity-100"
, bodyClasses = "mt-2 py-2"
}
searchMenuStyle : Style
searchMenuStyle =
{ rootClasses = "border-0 "
, tabClasses = "border-0 "
, titleClasses = "py-4 md:py-2 pl-2 bg-blue-50 hover:bg-blue-100 dark:bg-bluegray-700 dark:hover:bg-opacity-100 dark:hover:bg-bluegray-600 rounded"
, bodyClasses = "mt-1 py-1 pl-2"
}
akkordion : Style -> (Tab msg -> ( State, msg )) -> List (Tab msg) -> Html msg
akkordion style state tabs =
let
viewTab t =
let
( open, m ) =
state t
in
akkordionTab style open m t
in
div
[ class style.rootClasses
, class "flex flex-col"
]
(List.map viewTab tabs)
akkordionTab : Style -> State -> msg -> Tab msg -> Html msg
akkordionTab style state toggle tab =
let
tabTitle =
a
[ class "flex flex-row items-center"
, class style.titleClasses
, href "#"
, onClick toggle
]
[ div [ class "inline-flex mr-2 w-2" ]
[ if state == Open then
i [ class "fa fa-caret-down" ] []
else
i [ class "fa fa-caret-right" ] []
]
, div [ class "flex flex-col" ]
[ div [ class "px-2 font-semibold" ]
[ text tab.title
]
, div [ class "px-2 opacity-50 text-sm" ]
[ text (Maybe.withDefault "" tab.info)
]
]
]
tabContent =
div
[ classList [ ( "hidden", state == Closed ) ]
, class style.bodyClasses
]
tab.body
in
div
[ class style.tabClasses
, class "flex flex-col"
, classList [ ( "hidden", state == Hidden ) ]
]
[ tabTitle
, tabContent
]