2019-10-24 20:23:19 +03:00
|
|
|
module Examples.Accordion exposing
|
|
|
|
( example
|
2020-03-31 22:14:18 +03:00
|
|
|
, State, Msg
|
2019-10-24 20:23:19 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
2020-03-31 22:14:18 +03:00
|
|
|
@docs example
|
|
|
|
@docs State, Msg
|
2019-10-24 20:23:19 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-06-19 23:41:28 +03:00
|
|
|
import AtomicDesignType exposing (AtomicDesignType(..))
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2019-10-24 20:23:19 +03:00
|
|
|
import Css exposing (..)
|
|
|
|
import Dict exposing (Dict)
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2020-03-31 21:31:14 +03:00
|
|
|
import Html.Styled as Html exposing (Html)
|
2019-10-24 20:23:19 +03:00
|
|
|
import Html.Styled.Attributes exposing (css)
|
2020-06-20 00:45:32 +03:00
|
|
|
import KeyboardSupport exposing (Direction(..), Key(..))
|
2020-09-11 22:02:46 +03:00
|
|
|
import Nri.Ui.Accordion.V2 as Accordion
|
2019-10-24 20:23:19 +03:00
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
2019-10-24 20:32:26 +03:00
|
|
|
import Nri.Ui.Fonts.V1 as Fonts
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
|
|
|
import Nri.Ui.Text.V4 as Text
|
2019-10-24 20:23:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 23:20:03 +03:00
|
|
|
example : Example State Msg
|
2020-03-31 22:14:18 +03:00
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "Accordion"
|
2020-09-11 22:02:46 +03:00
|
|
|
, version = 2
|
2020-03-31 21:31:14 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2020-03-31 22:48:26 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2020-03-31 21:31:14 +03:00
|
|
|
, view = view
|
|
|
|
, categories = [ Layout ]
|
2020-06-20 00:16:10 +03:00
|
|
|
, atomicDesignType = Molecule
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2020-03-31 21:31:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
view : State -> List (Html Msg)
|
|
|
|
view model =
|
|
|
|
[ Heading.h3 [] [ Html.text "Accordion.view with default styles" ]
|
|
|
|
, Accordion.view
|
|
|
|
{ entries =
|
|
|
|
[ { id = 1, title = "Entry 1", content = "Content for the first accordion" }
|
|
|
|
, { id = 2, title = "Entry 2", content = "Content for the second accordion" }
|
|
|
|
, { id = 3, title = "Super long entry that is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long", content = "Content for the third accordion" }
|
|
|
|
]
|
|
|
|
|> List.map
|
|
|
|
(\entry ->
|
2020-09-11 22:08:07 +03:00
|
|
|
( "accordion-entry__" ++ String.fromInt entry.id
|
|
|
|
, entry
|
|
|
|
, Dict.get entry.id model |> Maybe.withDefault False
|
|
|
|
)
|
2020-03-31 21:31:14 +03:00
|
|
|
)
|
|
|
|
, viewHeader = .title >> Html.text
|
|
|
|
, viewContent = \{ content } -> Text.smallBody [ Html.text content ]
|
|
|
|
, customStyles = Nothing
|
|
|
|
, toggle = \entry toExpand -> Toggle entry.id toExpand
|
|
|
|
, caret = Accordion.DefaultCaret
|
|
|
|
}
|
|
|
|
, Heading.h3 [] [ Html.text "Accordion.view with custom styles from peer reviews" ]
|
|
|
|
, Accordion.view
|
|
|
|
{ entries =
|
|
|
|
[ { id = 4
|
|
|
|
, title = "Firstname Lastname"
|
|
|
|
, content =
|
|
|
|
Html.div
|
|
|
|
[ css [ Fonts.baseFont, fontSize (px 13) ]
|
|
|
|
]
|
|
|
|
[ Html.text "has not started writing" ]
|
|
|
|
}
|
|
|
|
, { id = 5
|
|
|
|
, title = "LongFirstnameAnd EvenLongerLastname"
|
|
|
|
, content =
|
|
|
|
Html.div
|
|
|
|
[ css [ Fonts.baseFont, fontSize (px 13) ] ]
|
|
|
|
[ Html.text "has started writing" ]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|> List.map
|
|
|
|
(\entry ->
|
2020-09-11 22:08:07 +03:00
|
|
|
( "accordion-entry__" ++ String.fromInt entry.id
|
|
|
|
, entry
|
|
|
|
, Dict.get entry.id model |> Maybe.withDefault False
|
|
|
|
)
|
2020-03-31 21:31:14 +03:00
|
|
|
)
|
|
|
|
, viewHeader = .title >> Html.text
|
|
|
|
, viewContent = .content
|
|
|
|
, customStyles =
|
|
|
|
Just
|
|
|
|
(\_ ->
|
|
|
|
{ entryStyles =
|
|
|
|
[ borderTop3 (px 1) solid Colors.gray75
|
|
|
|
, marginBottom zero
|
|
|
|
, width (px 284)
|
|
|
|
]
|
|
|
|
, entryExpandedStyles = []
|
|
|
|
, entryClosedStyles = []
|
|
|
|
, headerStyles =
|
|
|
|
[ height (px 46)
|
|
|
|
, paddingLeft (px 8)
|
|
|
|
, paddingRight (px 8)
|
|
|
|
, Css.alignItems Css.center
|
|
|
|
]
|
|
|
|
, headerExpandedStyles =
|
|
|
|
[ backgroundColor Colors.gray96
|
|
|
|
, borderRadius zero
|
|
|
|
]
|
|
|
|
, headerClosedStyles = [ backgroundColor transparent ]
|
|
|
|
, contentStyles =
|
|
|
|
[ backgroundColor Colors.gray96
|
|
|
|
, paddingLeft (px 8)
|
|
|
|
, paddingRight (px 8)
|
|
|
|
, paddingBottom (px 8)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
, toggle = \entry toExpand -> Toggle entry.id toExpand
|
|
|
|
, caret = Accordion.DefaultCaret
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-10-24 20:23:19 +03:00
|
|
|
type Msg
|
|
|
|
= Toggle Int Bool
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
Dict.fromList
|
|
|
|
[ ( 1, False )
|
|
|
|
, ( 2, False )
|
|
|
|
, ( 3, False )
|
|
|
|
, ( 4, False )
|
|
|
|
, ( 5, False )
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
Dict Int Bool
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 21:31:14 +03:00
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
2019-10-24 20:23:19 +03:00
|
|
|
update (Toggle id toExpanded) model =
|
2020-03-31 21:31:14 +03:00
|
|
|
( Dict.insert id toExpanded model, Cmd.none )
|