Skip to content

Commit 0534354

Browse files
authored
Merge pull request #54 from citizennet/davezuch/PS-3041/buttons
PS-3041 Add form buttons
2 parents 5c4712d + e187c7e commit 0534354

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

dist/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<meta charset="utf-8">
55
<title>CitizenNet UI Guide</title>
66
<link rel="stylesheet" href="css/cn-tailwind.css" />
7+
<!-- temp styles until Ocelot gets updated -->
8+
<style>.container { max-width: 1200px; }</style>
79
</head>
810

911
<body class="bg-grey-light">

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/Lynx/Component/Router.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Effect.Aff.Class (class MonadAff)
1313
import Halogen as H
1414
import Halogen.Component.ChildPath as CP
1515
import Halogen.HTML as HH
16+
import Halogen.HTML.Events as HE
1617
import Lynx.Expr as Lynx.Expr
1718
import Lynx.Form as Lynx.Form
1819
import Lynx.List as Lynx.List
@@ -29,7 +30,7 @@ data Query a
2930
= Navigate Route a
3031

3132
type Input
32-
= Unit
33+
= Route
3334

3435
type Message
3536
= Void
@@ -49,7 +50,7 @@ component =
4950
{ initialState: const Home
5051
, eval
5152
, render
52-
, receiver: const Nothing
53+
, receiver: HE.input Navigate
5354
}
5455
where
5556
eval :: Query ~> H.ParentDSL State Query ChildQueries ChildSlots Message m

example/Lynx/Page/Form.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Lynx.Page.Form where
22

33
import Prelude hiding ((/))
4+
45
import Data.Const (Const)
56
import Data.Either.Nested (type (\/))
67
import Data.Functor.Coproduct.Nested (type (<\/>))
@@ -9,6 +10,7 @@ import Data.Generic.Rep.Show (genericShow)
910
import Data.NonEmpty as Data.NonEmpty
1011
import Effect.Aff (Aff)
1112
import Effect.Aff.Class (class MonadAff)
13+
import Effect.Class.Console (log, logShow)
1214
import Halogen as H
1315
import Halogen.Component.ChildPath (cp1)
1416
import Halogen.HTML as HH
@@ -121,4 +123,10 @@ eval = case _ of
121123
Initialize { fragment, route } a -> do
122124
H.modify_ _ { fragment = fragment, route = route }
123125
pure a
124-
LynxQuery message _ -> absurd message
126+
LynxQuery message a ->
127+
case message of
128+
Lynx.Canceled -> pure a
129+
Lynx.Submitted { expr } -> do
130+
log "Form submitted:"
131+
logShow expr
132+
pure a

example/Main.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Halogen.HTML as HH
1010
import Halogen.VDom.Driver (runUI)
1111
import Lynx.AppM (runAppM)
1212
import Lynx.Component.Router as Router
13-
import Lynx.Route (routeCodec)
13+
import Lynx.Route (Route(..), routeCodec)
1414
import Routing.Duplex (parse)
1515
import Routing.Hash (matchesWith)
1616

@@ -19,9 +19,9 @@ main =
1919
HA.runHalogenAff do
2020
body <- HA.awaitBody
2121
let
22-
router :: H.Component HH.HTML Router.Query Unit Void Aff
22+
router :: H.Component HH.HTML Router.Query Router.Input Void Aff
2323
router = H.hoist (runAppM {}) Router.component
24-
driver <- runUI router unit body
24+
driver <- runUI router Home body
2525
void $ H.liftEffect
2626
$ matchesWith (parse routeCodec) \old new ->
2727
when (old /= Just new) do

src/Lynx.purs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ data Query a
6464
| TypeaheadSingleQuery Key (Typeahead.Message Query Maybe ExprType) a
6565
| AddSection Key a
6666
| RemoveSection Key Int a
67+
| Cancel a
68+
| Submit a
6769

6870
type ParentInput
6971
= { activeTab :: String
@@ -84,8 +86,9 @@ type ChildSlot
8486
\/ Key
8587
\/ Void
8688

87-
type Message
88-
= Void
89+
data Message
90+
= Canceled
91+
| Submitted { expr :: Page Expr }
8992

9093
component ::
9194
m.
@@ -113,16 +116,24 @@ component =
113116
]
114117
Right page ->
115118
HH.div_
116-
[ Header.header_
117-
[ Format.headingDark_ [ HH.text page.name ]
118-
]
119-
, Header.header_
120-
[ NavigationTab.navigationTabs_
121-
{ activePage: activeTab
122-
, tabs:
123-
Data.Array.fromFoldable (map (fromTab fragment) page.tabs)
124-
}
125-
]
119+
[ Header.stickyFormHeader
120+
{ brand: Just "https://citizennet.com/manager/images/logo.svg"
121+
, name: [ HH.text page.name ]
122+
, title: []
123+
, buttons:
124+
[ HH.a
125+
[ HE.onClick (HE.input_ Cancel)
126+
, css "cursor-pointer no-underline text-grey-70 mr-6"
127+
]
128+
[ HH.text "Cancel" ]
129+
, Button.buttonPrimary
130+
[ HE.onClick (HE.input_ Submit) ]
131+
[ HH.text "Submit" ]
132+
]
133+
}
134+
{ activePage: activeTab
135+
, tabs: Data.Array.fromFoldable (map (fromTab fragment) page.tabs)
136+
}
126137
, Layout.grid_
127138
[ renderTab activeTab page.tabs
128139
, Layout.side_ []
@@ -375,6 +386,13 @@ eval = case _ of
375386
RemoveSection key index a -> do
376387
{ expr } <- H.get
377388
eval (EvalForm (Lynx.Form.unstamp key index expr) a)
389+
Cancel a -> do
390+
H.raise Canceled
391+
pure a
392+
Submit a -> do
393+
{ expr } <- H.get
394+
H.raise (Submitted { expr })
395+
pure a
378396

379397
fromTab :: forall a. Fragment -> Tab a -> NavigationTab.Tab String
380398
fromTab fragment { sections: sections'', name, link } =

0 commit comments

Comments
 (0)