Skip to content

Commit 262bcc2

Browse files
committed
css themes wip
1 parent ef2fa3e commit 262bcc2

File tree

8 files changed

+61
-21
lines changed

8 files changed

+61
-21
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ else
5151
reanimate-svg:*,
5252
tdlib:*,
5353
secp256k1-haskell,
54+
ghc,
5455
packages:
5556
pub/hs-bitcoin-hash/bitcoin-hash/*.cabal
5657
pub/hs-bitcoin-keys/bitcoin-keys/*.cabal

ghcjs/delivery-calculator/src/App/Types.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import qualified Data.Generics as Syb
4141
import qualified Data.Version as Version
4242
import Functora.Cfg
4343
import Functora.Miso.Prelude
44+
import qualified Functora.Miso.Theme as Theme
4445
import Functora.Miso.Types as X hiding
4546
( newFieldPair,
4647
newFieldPairId,
@@ -90,7 +91,8 @@ data St f = St
9091
stOnlineOrOffline :: OnlineOrOffline,
9192
stFavName :: Field Unicode f,
9293
stPreview :: Field Unicode f,
93-
stScreen :: Screen
94+
stScreen :: Screen,
95+
stTheme :: Theme
9496
}
9597
deriving stock (Generic)
9698

@@ -130,7 +132,8 @@ newSt = do
130132
stOnlineOrOffline = Online,
131133
stFavName = fav,
132134
stPreview = pre & #fieldType .~ FieldTypeTitle,
133-
stScreen = Main
135+
stScreen = Main,
136+
stTheme = Theme.Paper
134137
}
135138

136139
data Asset f = Asset

ghcjs/delivery-calculator/src/App/Widgets/Menu.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ menu st =
274274
& #optsLabel
275275
.~ Just ("QR title" :: Unicode)
276276
)
277+
<> [ Select.select
278+
( Select.defOpts
279+
& #optsLabel
280+
.~ Just "Theme"
281+
)
282+
Select.Args
283+
{ Select.argsModel = st,
284+
Select.argsOptic = #modelState . #stTheme,
285+
Select.argsAction = PushUpdate . Instant,
286+
Select.argsOptions = constTraversal $ enumerate @Theme
287+
}
288+
]
277289
}
278290

279291
qrButton :: Model -> View Action

ghcjs/delivery-calculator/src/Main.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ runApp app = do
8484
where
8585
router js req =
8686
case Wai.pathInfo req of
87-
("static" : _) ->
88-
staticApp (defaultWebAppSettings ".") req
87+
("static" : "css" : path) ->
88+
staticApp
89+
(defaultWebAppSettings "../miso-functora/dist/css")
90+
req {Wai.pathInfo = path}
8991
("node_modules" : _) ->
9092
staticApp (defaultWebAppSettings ".") req
9193
("favicon.ico" : _) ->
@@ -242,18 +244,16 @@ viewModel st =
242244
[ rel_ "stylesheet",
243245
href_ "static/css/fontawesome.min.css"
244246
],
247+
-- href_ "https://unpkg.com/[email protected]/css/nes.min.css"
248+
-- href_ "node_modules/@lowlighter/matcha/dist/matcha.css"
249+
-- href_ "https://unpkg.com/@sakun/system.css"
250+
-- href_ "https://unpkg.com/papercss/dist/paper.min.css"
251+
-- href_ "https://unpkg.com/[email protected]/dist/terminal.min.css"
252+
-- href_ "https://vinibiavatti1.github.io/TuiCss/dist/tuicss.min.css"
253+
-- href_ "https://fieber.hack.re/fieber.css"
245254
link_
246255
[ rel_ "stylesheet",
247-
-- href_ "https://unpkg.com/[email protected]/css/nes.min.css"
248-
-- href_ "static/css/mvp.css"
249-
-- href_ "static/css/simple.min.css"
250-
-- href_ "static/css/tacit-css-1.8.1.min.css"
251-
-- href_ "node_modules/@lowlighter/matcha/dist/matcha.css"
252-
-- href_ "https://unpkg.com/@sakun/system.css"
253-
-- href_ "https://unpkg.com/papercss/dist/paper.min.css"
254-
-- href_ "https://unpkg.com/[email protected]/dist/terminal.min.css"
255-
-- href_ "https://vinibiavatti1.github.io/TuiCss/dist/tuicss.min.css"
256-
href_ "https://fieber.hack.re/fieber.css"
256+
href_ $ "static/css/" <> themeCssFile (st ^. #modelState . #stTheme)
257257
],
258258
link_
259259
[ rel_ "stylesheet",

ghcjs/miso-functora/Setup.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{-# OPTIONS_GHC -Wno-safe #-}
1818
{-# OPTIONS_GHC -Wno-unsafe #-}
1919
{-# OPTIONS_GHC -fprint-potential-instances #-}
20+
#if MIN_VERSION_ghc(9,0,0)
21+
{-# OPTIONS_GHC -Wno-missing-kind-signatures #-}
22+
{-# OPTIONS_GHC -Wno-prepositive-qualified-module #-}
23+
{-# OPTIONS_GHC -Wno-missing-safe-haskell-mode #-}
24+
#endif
2025

2126
import qualified Data.Text as T
2227
import Distribution.Simple hiding (Module (..))
@@ -77,10 +82,12 @@ codeGenHook _ = do
7782
sort . fmap (dropEnd 8) $ filter (isSuffixOf ".min.css") cssRaw
7883
let cssPascal =
7984
fmap Casing.pascal cssKebab
80-
when (cssKebab /= fmap Casing.kebab cssPascal)
81-
. error
82-
$ "Bad kebab <-> pascal isomorphism in "
83-
<> inspect @Text cssKebab
85+
if cssKebab == fmap Casing.kebab cssPascal
86+
then putStrLn $ inspect @Text cssPascal
87+
else
88+
error
89+
$ "Bad kebab <-> pascal isomorphism in "
90+
<> inspect @Text cssKebab
8491
liftIO
8592
. writeFileIfChanged
8693
. showPpr dflags
@@ -98,6 +105,7 @@ generateCode prog css =
98105
import'
99106
[ "Prelude",
100107
"Data.Data",
108+
"Data.Binary",
101109
"GHC.Generics"
102110
]
103111
)
@@ -118,7 +126,8 @@ generateCode prog css =
118126
"Enum",
119127
"Bounded"
120128
]
121-
]
129+
],
130+
instance' (var "Binary" @@ var "Theme") mempty
122131
]
123132
}
124133
where

ghcjs/miso-functora/miso-functora.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ custom-setup
1919
, functora-ghcjs
2020
, ghc
2121
, ghc-paths
22-
, ghc-source-gen ==0.4.2.0
22+
, ghc-source-gen
2323
, text
2424

2525
common pkg
@@ -85,6 +85,7 @@ common pkg
8585
build-depends:
8686
, barbies
8787
, base
88+
, binary
8889
, bytestring
8990
, casing
9091
, functora-ghcjs
@@ -127,6 +128,7 @@ library
127128
Functora.Miso.Jsm.Specific
128129
Functora.Miso.Orphan
129130
Functora.Miso.Prelude
131+
Functora.Miso.Theme
130132
Functora.Miso.Types
131133
Functora.Miso.Widgets.BrowserLink
132134
Functora.Miso.Widgets.Currency

ghcjs/miso-functora/src/Functora/Miso/Theme.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Functora.Miso.Theme (
44
) where
55
import Prelude
66
import Data.Data
7+
import Data.Binary
78
import GHC.Generics
89
data Theme
910
= A11yana |
@@ -139,4 +140,5 @@ data Theme
139140
Wing |
140141
Writ |
141142
Yorha
142-
deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)
143+
deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)
144+
instance Binary Theme

ghcjs/miso-functora/src/Functora/Miso/Types.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ module Functora.Miso.Types
5050
LeadingOrTrailing (..),
5151
OpenedOrClosed (..),
5252
Update (..),
53+
themeCssFile,
5354
evalUpdate,
55+
module X,
5456
)
5557
where
5658

@@ -59,8 +61,10 @@ import Data.Functor.Barbie
5961
import qualified Data.Generics as Syb
6062
import Functora.Cfg
6163
import Functora.Miso.Prelude
64+
import Functora.Miso.Theme as X (Theme)
6265
import Functora.Money hiding (Currency, Money)
6366
import qualified Miso.Html.Types as Miso
67+
import qualified Text.Casing as Casing
6468
import qualified Text.URI as URI
6569

6670
type Typ a =
@@ -542,6 +546,13 @@ data Update model
542546
| PureAndEffectUpdate (model -> model) (JSM ())
543547
deriving stock (Generic)
544548

549+
themeCssFile :: Theme -> Unicode
550+
themeCssFile =
551+
(<> ".min.css")
552+
. from @String @Unicode
553+
. Casing.kebab
554+
. inspect @String
555+
545556
evalUpdate :: model -> Update model -> JSM model
546557
evalUpdate x = \case
547558
PureUpdate f -> pure $ f x

0 commit comments

Comments
 (0)