Button.purs 1.12 KB
Newer Older
1
module Gargantext.Components.GraphExplorer.Button
2
  ( centerButton
3 4 5 6 7 8
  , Props
  , simpleButton
  ) where

import Prelude
import Data.Maybe (Maybe(..))
9
import DOM.Simple.Console (log2)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import Effect (Effect)
import Reactix as R
import Reactix.DOM.HTML as H

import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Sigma as Sigma

type Props = (
    onClick :: forall e. e -> Effect Unit
  , text :: String
  )

simpleButton :: Record Props -> R.Element
simpleButton props = R.createElement simpleButtonCpt props []

simpleButtonCpt :: R.Component Props
simpleButtonCpt = R.hooksComponent "SimpleButton" cpt
  where
    cpt {onClick, text} _ = do
      pure $
        H.span {}
          [
            H.button
              { className: "btn btn-primary", on: {click: onClick} }
              [ H.text text ]
          ]

37
centerButton :: R.Ref Sigmax.Sigma -> R.Element
38 39
centerButton sigmaRef = simpleButton {
    onClick: \_ -> do
40 41 42
      let sigma = R.readRef sigmaRef
      Sigmax.dependOnSigma sigma "[centerButton] sigma: Nothing" $ \s ->
        Sigma.goToAllCameras s {x: 0.0, y: 0.0, ratio: 1.0, angle: 0.0}
43 44
  , text: "Center"
  }