Popover.purs 897 Bytes
Newer Older
1 2
module Gargantext.Utils.Popover where

3
import Data.Maybe (maybe)
4 5
import Data.Nullable (Nullable, toMaybe)
import DOM.Simple as DOM
6
import Effect (Effect)
7
import Effect.Uncurried (EffectFn2, runEffectFn2)
8 9 10 11
import Reactix as R

import Gargantext.Prelude

12 13
type PopoverRef = R.Ref (Nullable DOM.Element)

14 15
type Props =
  (
16 17
    arrow :: Boolean
  , open :: Boolean
18 19
  , onClose :: Unit -> Effect Unit
  , onOpen :: Unit -> Effect Unit
20
  , ref :: PopoverRef
21
  )
22 23 24 25 26

foreign import popoverCpt :: R.Component Props

popover :: Record Props -> Array R.Element -> R.Element
popover = R.rawCreateElement popoverCpt
27

28
foreign import _setState :: forall a. EffectFn2 DOM.Element a Unit
29

30
setState :: forall a. DOM.Element -> a -> Effect Unit
31 32 33
setState = runEffectFn2 _setState

setOpen :: PopoverRef -> Boolean -> Effect Unit
34
setOpen ref val = maybe (pure unit) (\p -> setState p {open: val}) $ toMaybe $ R.readRef ref