noredink-ui/styleguide-app/Examples/Table.elm

109 lines
3.7 KiB
Elm
Raw Normal View History

2020-03-31 22:43:32 +03:00
module Examples.Table exposing (Msg, State, example)
{-|
@docs Msg, State, example
-}
2020-06-19 23:41:28 +03:00
import AtomicDesignType exposing (AtomicDesignType(..))
import Category exposing (Category(..))
import Css exposing (..)
2020-03-31 23:20:03 +03:00
import Example exposing (Example)
import Html.Styled as Html
import Nri.Ui.Button.V5 as Button
2019-08-05 21:48:02 +03:00
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Heading.V2 as Heading
2019-08-05 21:48:02 +03:00
import Nri.Ui.Table.V5 as Table
{-| -}
2020-03-31 22:43:32 +03:00
type alias State =
()
{-| -}
2020-03-31 22:43:32 +03:00
type alias Msg =
()
{-| -}
2020-03-31 23:20:03 +03:00
example : Example State Msg
2020-03-31 22:43:32 +03:00
example =
2019-08-05 22:38:34 +03:00
{ name = "Nri.Ui.Table.V5"
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:16:10 +03:00
, atomicDesignType = Molecule
2020-03-31 22:43:32 +03:00
, view =
\() ->
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
, view =
\_ ->
Button.button
{ size = Button.Small
, style = Button.Primary
, onClick = ()
, width = Button.WidthUnbounded
}
{ label = "Action"
, state = Button.Enabled
, icon = Nothing
}
, cellStyles = always []
}
]
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
]
}