ybbond-reason

My old site written in ReasonReact
Log | Files | Refs | README

commit 1da01ba68a4993bfe033f6482d7bd27a630d99c2
parent 2d2babe7f657ba9529debfde4b55fc323767071e
Author: Yohanes Bandung <bandungpenting@gmail.com>
Date:   Mon, 19 Aug 2019 19:29:56 +0700

feature(Link) => enhance <Link />

Diffstat:
Msrc/components/Link.re | 18++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/components/Link.re b/src/components/Link.re
@@ -1,3 +1,17 @@
+let handleClick = (internal, event) =>
+  if (!ReactEvent.Mouse.defaultPrevented(event) && internal !== "") {
+    ReactEvent.Mouse.preventDefault(event);
+    ReasonReact.Router.push(internal);
+  };
+
 [@react.component]
-let make = (~href: string, ~text: string) =>
-  <mark> <a href> {ReasonReact.string(text)} </a> </mark>;
+let make = (~href="", ~text: string, ~internal="") =>
+  <mark>
+    <a
+      href
+      target="_blank"
+      rel="noopener noreferrer"
+      onClick={event => handleClick(internal, event)}>
+      {ReasonReact.string(text)}
+    </a>
+  </mark>;