2020-03-31 22:43:32 +03:00
|
|
|
module Examples.Table exposing (Msg, State, example)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs Msg, State, example
|
2018-04-24 18:49:29 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2018-04-25 20:10:34 +03:00
|
|
|
import Css exposing (..)
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2018-10-23 19:55:30 +03:00
|
|
|
import Html.Styled as Html
|
2020-06-20 00:45:32 +03:00
|
|
|
import KeyboardSupport exposing (Direction(..), Key(..))
|
2020-06-23 03:46:20 +03:00
|
|
|
import Nri.Ui.Button.V10 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
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 22:43:32 +03:00
|
|
|
type alias State =
|
|
|
|
()
|
2018-04-24 18:49:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 22:43:32 +03:00
|
|
|
type alias Msg =
|
2018-04-24 18:49:29 +03:00
|
|
|
()
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 23:20:03 +03:00
|
|
|
example : Example State Msg
|
2020-03-31 22:43:32 +03:00
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "Table"
|
|
|
|
, version = 5
|
2020-03-31 22:43:32 +03:00
|
|
|
, state = ()
|
|
|
|
, update = \_ state -> ( state, Cmd.none )
|
2020-03-31 22:48:26 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2020-06-19 23:41:28 +03:00
|
|
|
, categories = [ Tables, Layout ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2021-11-06 00:01:10 +03:00
|
|
|
, preview =
|
|
|
|
[ Table.view
|
|
|
|
[ Table.string
|
|
|
|
{ header = "A"
|
|
|
|
, value = .a
|
|
|
|
, width = px 50
|
|
|
|
, cellStyles = always []
|
|
|
|
}
|
|
|
|
, Table.string
|
|
|
|
{ header = "B"
|
|
|
|
, value = .b
|
|
|
|
, width = px 50
|
|
|
|
, cellStyles = always []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
[ { a = "Row 1 A"
|
|
|
|
, b = "Row 1 B"
|
|
|
|
}
|
|
|
|
, { a = "Row 2 A"
|
|
|
|
, b = "Row 2 B"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
2020-03-31 22:43:32 +03:00
|
|
|
, view =
|
2020-04-29 02:29:00 +03:00
|
|
|
\() ->
|
2020-03-31 22:43:32 +03:00
|
|
|
let
|
|
|
|
columns =
|
|
|
|
[ Table.string
|
|
|
|
{ header = "First Name"
|
|
|
|
, value = .firstName
|
|
|
|
, width = calc (pct 50) minus (px 250)
|
|
|
|
, cellStyles = always []
|
|
|
|
}
|
|
|
|
, Table.string
|
|
|
|
{ header = "Last Name"
|
|
|
|
, value = .lastName
|
|
|
|
, 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
|
|
|
|
]
|
2019-08-05 21:48:02 +03:00
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
else
|
|
|
|
[ textAlign center ]
|
|
|
|
}
|
|
|
|
, Table.custom
|
|
|
|
{ header =
|
|
|
|
Html.text "Actions"
|
|
|
|
, width = px 250
|
2020-06-23 03:46:20 +03:00
|
|
|
, view = \_ -> Button.button "Action" [ Button.small, Button.onClick () ]
|
2020-03-31 22:43:32 +03:00
|
|
|
, cellStyles = always []
|
|
|
|
}
|
|
|
|
]
|
2018-04-24 18:49:29 +03:00
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
data =
|
|
|
|
[ { 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 }
|
|
|
|
]
|
|
|
|
in
|
|
|
|
[ Heading.h3 [] [ Html.text "With header" ]
|
|
|
|
, Table.view columns data
|
|
|
|
, Heading.h3 [] [ Html.text "Without header" ]
|
|
|
|
, Table.viewWithoutHeader columns data
|
|
|
|
, Heading.h3 [] [ Html.text "With additional cell styles" ]
|
|
|
|
, Table.view columns data
|
|
|
|
, Heading.h3 [] [ Html.text "Loading" ]
|
|
|
|
, Table.viewLoading columns
|
|
|
|
, Heading.h3 [] [ Html.text "Loading without header" ]
|
|
|
|
, Table.viewLoadingWithoutHeader columns
|
|
|
|
]
|
2018-04-24 18:49:29 +03:00
|
|
|
}
|