Skip to content

Commit 73a954c

Browse files
committed
receive text from parent Input
1 parent 28d70e3 commit 73a954c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Clipboard.purs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ type ComponentM m
3030
= Halogen.HalogenM State Action ChildSlot Output m
3131

3232
type State
33-
= { copied :: Boolean }
33+
= { copied :: Boolean
34+
, input :: Input
35+
}
3436

3537
data Action
3638
= Copy
39+
| Receive Input
3740

3841
data Query (a :: Type)
3942

4043
type Input
41-
= Unit
44+
= { text :: String }
4245

4346
type Output
4447
= Void
@@ -56,14 +59,16 @@ component =
5659
Halogen.mkEval
5760
Halogen.defaultEval
5861
{ handleAction = handleAction
62+
, receive = Just <<< Receive
5963
}
6064
, initialState
6165
, render
6266
}
6367

6468
initialState :: Input -> State
65-
initialState _ =
69+
initialState input =
6670
{ copied: false
71+
, input
6772
}
6873

6974
handleAction ::
@@ -73,6 +78,7 @@ handleAction ::
7378
ComponentM m Unit
7479
handleAction = case _ of
7580
Copy -> copy
81+
Receive input -> receive input
7682

7783
copy ::
7884
forall m.
@@ -85,6 +91,13 @@ copy = do
8591
$ Effect.Aff.delay (Effect.Aff.Milliseconds 1000.0)
8692
Halogen.modify_ _ { copied = false }
8793

94+
receive ::
95+
forall m.
96+
Input ->
97+
ComponentM m Unit
98+
receive input = do
99+
Halogen.modify_ _ { input = input }
100+
88101
render ::
89102
forall m.
90103
State ->

ui-guide/Components/Button.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ renderClipboardButtons =
413413
[ HH.text "Standard" ]
414414
, HH.slot_ _clipboard unit
415415
Ocelot.Clipboard.component
416-
unit
416+
{ text: "copied from UIGuide" }
417417
]
418418
]
419419
]

0 commit comments

Comments
 (0)