Skip to content

Commit 64b41eb

Browse files
Add BasicHalogenHooks (#175)
* Add BasicHalogenHooks * Fix readme
1 parent 143fe1e commit 64b41eb

File tree

7 files changed

+77
-0
lines changed

7 files changed

+77
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Running a web-compatible recipe:
8484
| Node | Web Browser | Recipe | Description |
8585
| :-: | :-: | - | - |
8686
| | :heavy_check_mark: | [AddRemoveEventListenerJs](recipes/AddRemoveEventListenerJs) | This recipe shows how to add and remove an event listener to an HTML element. |
87+
| | :heavy_check_mark: | [BasicHalogenHooks](recipes/BasicHalogenHooks) | Displays a button that toggles the label to "On" and "Off". |
8788
| :heavy_check_mark: | :heavy_check_mark: | [BigIntJs](recipes/BigIntJs) | This recipe shows how to print, create, and use values of the `BigIntJs` type in either the node.js or web browser console. |
8889
| | :heavy_check_mark: | [BookHalogenHooks](recipes/BookHalogenHooks) | A Halogen port of the ["HTTP - Book" Elm Example](https://elm-lang.org/examples/book). |
8990
| | :heavy_check_mark: | [BookReactHooks](recipes/BookReactHooks) | A React port of the ["HTTP - Book" Elm Example](https://elm-lang.org/examples/book). |

recipes/BasicHalogenHooks/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*
10+
/.spago
11+
/.cache/
12+
/dist/
13+
/web-dist/
14+
/prod-dist/
15+
/prod/

recipes/BasicHalogenHooks/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# BasicHalogenHooks
2+
3+
Displays a button that toggles the label to "On" and "Off".

recipes/BasicHalogenHooks/spago.dhall

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ name = "BasicHalogenHooks"
2+
, dependencies =
3+
[ "console"
4+
, "effect"
5+
, "halogen-hooks"
6+
, "psci-support"
7+
]
8+
, packages = ../../packages.dhall
9+
, sources = [ "recipes/BasicHalogenHooks/src/**/*.purs" ]
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module BasicHalogenHooks.Main where
2+
3+
import Prelude
4+
5+
import Data.Maybe (Maybe(..))
6+
import Data.Tuple.Nested ((/\))
7+
import Effect (Effect)
8+
import Halogen as H
9+
import Halogen.Aff as HA
10+
import Halogen.HTML as HH
11+
import Halogen.HTML.Events as HE
12+
import Halogen.HTML.Properties as HP
13+
import Halogen.Hooks as Hooks
14+
import Halogen.VDom.Driver (runUI)
15+
16+
main :: Effect Unit
17+
main =
18+
HA.runHalogenAff do
19+
body <- HA.awaitBody
20+
void $ runUI hookComponent Nothing body
21+
22+
hookComponent
23+
:: forall unusedQuery unusedInput unusedOutput anyMonad
24+
. H.Component HH.HTML unusedQuery unusedInput unusedOutput anyMonad
25+
hookComponent = Hooks.component \_ _ -> Hooks.do
26+
enabled /\ enabledIdx <- Hooks.useState false
27+
let label = if enabled then "On" else "Off"
28+
Hooks.pure $
29+
HH.button
30+
[ HP.title label
31+
, HE.onClick \_ -> Just $ Hooks.modify_ enabledIdx not
32+
]
33+
[ HH.text label ]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>BasicHalogenHooks</title>
7+
</head>
8+
9+
<body>
10+
<script src="./index.js"></script>
11+
</body>
12+
13+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
require("../../../output/BasicHalogenHooks.Main/index.js").main();

0 commit comments

Comments
 (0)