{-# OPTIONS_GHC -Wno-missing-role-annotations #-}
module Dashi.Layout.Page where
import Clay hiding (action, aside, main_, not)
import Clay qualified
import Clay.Media (minDeviceWidth)
import Dashi.Components.Widget
import Dashi.Prelude hiding (all, aside, has, rem, (&))
import Dashi.Style.Util
import Data.List qualified as List
import Miso.Html.Element (aside_, div_, header_, nav_)
import Miso.Html.Element qualified as Html
import Miso.Html.Property (id_)
data Page model action = Page
{ forall model action. Page model action -> Maybe [View model action]
banner :: Maybe [View model action]
, forall model action. Page model action -> Maybe [View model action]
topBar :: Maybe [View model action]
, forall model action. Page model action -> Maybe [View model action]
sideNav :: Maybe [View model action]
, forall model action. Page model action -> [View model action]
main_ :: [View model action]
, forall model action. Page model action -> Maybe [View model action]
aside :: Maybe [View model action]
}
instance Widget (Page model action) model action where
widget' :: [Attribute action] -> Page model action -> View model action
widget' [Attribute action]
attrs Page{[View model action]
Maybe [View model action]
banner :: forall model action. Page model action -> Maybe [View model action]
topBar :: forall model action. Page model action -> Maybe [View model action]
sideNav :: forall model action. Page model action -> Maybe [View model action]
main_ :: forall model action. Page model action -> [View model action]
aside :: forall model action. Page model action -> Maybe [View model action]
banner :: Maybe [View model action]
topBar :: Maybe [View model action]
sideNav :: Maybe [View model action]
main_ :: [View model action]
aside :: Maybe [View model action]
..} =
[Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
div_ (MisoString -> Attribute action
forall action. MisoString -> Attribute action
id_ MisoString
"page" Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
attrs)
([View model action] -> View model action)
-> ([Maybe (View model action)] -> [View model action])
-> [Maybe (View model action)]
-> View model action
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [Maybe (View model action)] -> [View model action]
forall a. [Maybe a] -> [a]
catMaybes
([Maybe (View model action)] -> View model action)
-> [Maybe (View model action)] -> View model action
forall a b. (a -> b) -> a -> b
$ [ [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
header_ [] ([View model action] -> View model action)
-> Maybe [View model action] -> Maybe (View model action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [View model action]
topBar
, [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
nav_ [] ([View model action] -> View model action)
-> Maybe [View model action] -> Maybe (View model action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [View model action]
sideNav
, View model action -> Maybe (View model action)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (View model action -> Maybe (View model action))
-> View model action -> Maybe (View model action)
forall a b. (a -> b) -> a -> b
$ [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
Html.main_ [] [View model action]
main_
, [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
aside_ [] ([View model action] -> View model action)
-> Maybe [View model action] -> Maybe (View model action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [View model action]
aside
]
style :: Css
style = do
Selector
"#page" Selector -> Css -> Css
? do
Size LengthUnit -> Css
forall a. Size a -> Css
minHeight (Size LengthUnit -> Css) -> Size LengthUnit -> Css
forall a b. (a -> b) -> a -> b
$ Number -> Size LengthUnit
vh Number
100
Display -> Css
display Display
grid
[[Value]] -> Css
gridTemplateAreas [[Value
"top-bar"], [Value
"main"], [Value
"aside"]]
Key MisoString
"grid-template-rows" Key MisoString -> MisoString -> Css
-: MisoString
"auto 1fr auto"
MediaType -> [Feature] -> Css -> Css
query MediaType
forall a. All a => a
all [Size LengthUnit -> Feature
minDeviceWidth (Size LengthUnit -> Feature) -> Size LengthUnit -> Feature
forall a b. (a -> b) -> a -> b
$ Number -> Size LengthUnit
rem Number
64] do
[[Value]] -> Css
gridTemplateAreas
[ Int -> Value -> [Value]
forall a. Int -> a -> [a]
List.replicate Int
2 Value
"top-bar"
, [Value
"side-nav", Value
"main"]
]
Key MisoString
"grid-template-rows" Key MisoString -> MisoString -> Css
-: MisoString
"auto 1fr"
Key MisoString
"grid-template-columns" Key MisoString -> MisoString -> Css
-: MisoString
"auto 1fr"
Selector -> Refinement
has Selector
Clay.aside Refinement -> Css -> Css
& do
[[Value]] -> Css
gridTemplateAreas
[ Int -> Value -> [Value]
forall a. Int -> a -> [a]
List.replicate Int
3 Value
"top-bar"
, [Value
"side-nav", Value
"main", Value
"aside"]
]
Key MisoString
"grid-template-columns" Key MisoString -> MisoString -> Css
-: MisoString
"auto 1fr auto"
Selector
nav Selector -> Css -> Css
? do
Key MisoString
"grid-area" Key MisoString -> MisoString -> Css
-: MisoString
"side-nav"
Selector
header Selector -> Css -> Css
? do
Key MisoString
"grid-area" Key MisoString -> MisoString -> Css
-: MisoString
"top-bar"
Selector
nav Selector -> Css -> Css
? do
Key MisoString
"grid-area" Key MisoString -> MisoString -> Css
-: MisoString
"main"
Selector
Clay.main_ Selector -> Css -> Css
? do
Key MisoString
"grid-area" Key MisoString -> MisoString -> Css
-: MisoString
"main"
Key MisoString
"isolation" Key MisoString -> MisoString -> Css
-: MisoString
"isolate"
Overflow -> Css
overflow Overflow
forall a. Auto a => a
auto
MediaType -> [Feature] -> Css -> Css
query MediaType
forall a. All a => a
all [Size LengthUnit -> Feature
minDeviceWidth (Size LengthUnit -> Feature) -> Size LengthUnit -> Feature
forall a b. (a -> b) -> a -> b
$ Number -> Size LengthUnit
rem Number
64] do
Key MisoString
"isolation" Key MisoString -> MisoString -> Css
-: MisoString
"auto"
Position -> Css
position Position
sticky