2018-04-24 18:49:29 +03:00
|
|
|
module Examples.Table exposing (Msg, State, example, init, update)
|
|
|
|
|
|
|
|
{- \
|
|
|
|
@docs Msg, State, example, init, update
|
|
|
|
-}
|
|
|
|
|
2018-04-25 20:10:34 +03:00
|
|
|
import Css exposing (..)
|
2018-04-24 18:49:29 +03:00
|
|
|
import Html
|
2018-04-25 20:25:34 +03:00
|
|
|
import Html.Styled
|
2018-04-24 18:49:29 +03:00
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
|
|
|
import Nri.Ui.Button.V1 as Button
|
2018-04-25 20:10:34 +03:00
|
|
|
import Nri.Ui.Table.V2 as Table
|
2018-04-24 18:49:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= NoOp
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
()
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : (Msg -> msg) -> State -> ModuleExample msg
|
|
|
|
example parentMessage state =
|
|
|
|
{ filename = "Nri/Table.elm"
|
|
|
|
, category = Layout
|
|
|
|
, content =
|
|
|
|
let
|
|
|
|
columns =
|
|
|
|
[ Table.string
|
|
|
|
{ header = "First Name"
|
|
|
|
, value = .firstName
|
2018-04-25 20:10:34 +03:00
|
|
|
, width = calc (pct 50) minus (px 125)
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
, Table.string
|
|
|
|
{ header = "Last Name"
|
|
|
|
, value = .lastName
|
2018-04-25 20:10:34 +03:00
|
|
|
, width = calc (pct 50) minus (px 125)
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
, Table.custom
|
2018-04-25 20:25:34 +03:00
|
|
|
{ header =
|
|
|
|
Html.text "Actions"
|
|
|
|
|> Html.Styled.fromUnstyled
|
2018-04-25 20:10:34 +03:00
|
|
|
, width = px 250
|
2018-04-24 18:49:29 +03:00
|
|
|
, view =
|
|
|
|
\_ ->
|
|
|
|
Button.button
|
|
|
|
{ size = Button.Small
|
|
|
|
, style = Button.Primary
|
|
|
|
, onClick = NoOp
|
|
|
|
}
|
|
|
|
{ label = "Action"
|
|
|
|
, state = Button.Enabled
|
|
|
|
}
|
2018-04-25 20:25:34 +03:00
|
|
|
|> Html.Styled.fromUnstyled
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
data =
|
|
|
|
[ { firstName = "First1", lastName = "Last1" }
|
|
|
|
, { firstName = "First2", lastName = "Last2" }
|
|
|
|
, { firstName = "First3", lastName = "Last3" }
|
|
|
|
, { firstName = "First4", lastName = "Last4" }
|
|
|
|
, { firstName = "First5", lastName = "Last5" }
|
|
|
|
]
|
|
|
|
in
|
2018-04-25 20:25:34 +03:00
|
|
|
[ Html.Styled.toUnstyled Table.keyframeStyles
|
2018-04-25 20:10:34 +03:00
|
|
|
, Html.h4 [] [ Html.text "With header" ]
|
|
|
|
, Table.view columns data
|
2018-04-25 20:25:34 +03:00
|
|
|
|> Html.Styled.toUnstyled
|
2018-04-25 20:10:34 +03:00
|
|
|
, Html.h4 [] [ Html.text "Without header" ]
|
|
|
|
, Table.viewWithoutHeader columns data
|
2018-04-25 20:25:34 +03:00
|
|
|
|> Html.Styled.toUnstyled
|
2018-04-25 20:10:34 +03:00
|
|
|
, Html.h4 [] [ Html.text "Loading" ]
|
|
|
|
, Table.viewLoading columns
|
2018-04-25 20:25:34 +03:00
|
|
|
|> Html.Styled.toUnstyled
|
2018-04-25 20:10:34 +03:00
|
|
|
, Html.h4 [] [ Html.text "Loading without header" ]
|
|
|
|
, Table.viewLoadingWithoutHeader columns
|
2018-04-25 20:25:34 +03:00
|
|
|
|> Html.Styled.toUnstyled
|
2018-04-25 20:10:34 +03:00
|
|
|
]
|
|
|
|
|> List.map (Html.map parentMessage)
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
()
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
NoOp ->
|
|
|
|
( state, Cmd.none )
|