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-10-23 19:55:30 +03:00
|
|
|
import Html.Styled as Html
|
2018-04-24 18:49:29 +03:00
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
2018-10-23 19:55:30 +03:00
|
|
|
import Nri.Ui.Button.V5 as Button
|
2019-08-05 21:48:02 +03:00
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
2019-07-23 17:58:23 +03:00
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2019-08-05 21:48:02 +03:00
|
|
|
import Nri.Ui.Table.V5 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 =
|
2019-08-05 22:38:34 +03:00
|
|
|
{ name = "Nri.Ui.Table.V5"
|
2019-05-03 19:08:23 +03:00
|
|
|
, category = Tables
|
2018-04-24 18:49:29 +03:00
|
|
|
, content =
|
|
|
|
let
|
|
|
|
columns =
|
|
|
|
[ Table.string
|
|
|
|
{ header = "First Name"
|
|
|
|
, value = .firstName
|
2019-08-05 21:48:02 +03:00
|
|
|
, width = calc (pct 50) minus (px 250)
|
|
|
|
, cellStyles = always []
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
, Table.string
|
|
|
|
{ header = "Last Name"
|
|
|
|
, value = .lastName
|
2019-08-05 21:48:02 +03:00
|
|
|
, width = calc (pct 50) minus (px 250)
|
|
|
|
, cellStyles = always []
|
|
|
|
}
|
|
|
|
, Table.string
|
|
|
|
{ header = "# Submitted"
|
|
|
|
, value = .submitted >> String.fromInt
|
|
|
|
, width = px 125
|
|
|
|
, cellStyles =
|
|
|
|
\value ->
|
|
|
|
if value.submitted < 5 then
|
|
|
|
[ backgroundColor Colors.redLight
|
|
|
|
, textAlign center
|
|
|
|
]
|
|
|
|
|
|
|
|
else
|
|
|
|
[ textAlign center ]
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
, Table.custom
|
2018-04-25 20:25:34 +03:00
|
|
|
{ header =
|
|
|
|
Html.text "Actions"
|
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
|
2018-10-23 19:55:30 +03:00
|
|
|
, width = Button.WidthUnbounded
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
{ label = "Action"
|
|
|
|
, state = Button.Enabled
|
2018-04-30 14:16:36 +03:00
|
|
|
, icon = Nothing
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
2019-08-05 21:48:02 +03:00
|
|
|
, cellStyles = always []
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
data =
|
2019-08-05 21:48:02 +03:00
|
|
|
[ { firstName = "First1", lastName = "Last1", submitted = 10 }
|
|
|
|
, { firstName = "First2", lastName = "Last2", submitted = 0 }
|
|
|
|
, { firstName = "First3", lastName = "Last3", submitted = 3 }
|
|
|
|
, { firstName = "First4", lastName = "Last4", submitted = 15 }
|
|
|
|
, { firstName = "First5", lastName = "Last5", submitted = 8 }
|
2018-04-24 18:49:29 +03:00
|
|
|
]
|
|
|
|
in
|
2019-07-23 17:58:23 +03:00
|
|
|
[ Heading.h4 [] [ Html.text "With header" ]
|
2018-04-25 20:29:22 +03:00
|
|
|
, Table.view columns data
|
2019-07-23 17:58:23 +03:00
|
|
|
, Heading.h4 [] [ Html.text "Without header" ]
|
2018-04-25 20:29:22 +03:00
|
|
|
, Table.viewWithoutHeader columns data
|
2019-08-05 21:48:02 +03:00
|
|
|
, Heading.h4 [] [ Html.text "With additional cell styles" ]
|
|
|
|
, Table.view columns data
|
2019-07-23 17:58:23 +03:00
|
|
|
, Heading.h4 [] [ Html.text "Loading" ]
|
2018-04-25 20:29:22 +03:00
|
|
|
, Table.viewLoading columns
|
2019-07-23 17:58:23 +03:00
|
|
|
, Heading.h4 [] [ Html.text "Loading without header" ]
|
2018-04-25 20:29:22 +03:00
|
|
|
, Table.viewLoadingWithoutHeader columns
|
|
|
|
]
|
|
|
|
|> 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 )
|