Legend.purs 997 Bytes
Newer Older
James Laver's avatar
James Laver committed
1 2 3 4
module Gargantext.Components.GraphExplorer.Legend
  ( Props, legend, legendCpt
  ) where

5 6 7
import Prelude hiding (map)

import Data.Sequence (Seq)
8
import Data.Traversable (foldMap)
James Laver's avatar
James Laver committed
9 10
import Reactix as R
import Reactix.DOM.HTML as RH
11

12
import Gargantext.Components.GraphExplorer.Types (Legend(..), intColor)
13 14 15
import Gargantext.Utils.Reactix as R2

thisModule = "Gargantext.Components.GraphExplorer.Legend"
James Laver's avatar
James Laver committed
16 17 18 19 20 21 22

type Props = ( items :: Seq Legend )

legend :: Record Props -> R.Element
legend props = R.createElement legendCpt props []

legendCpt :: R.Component Props
23
legendCpt = R.hooksComponentWithModule thisModule "legend" cpt
James Laver's avatar
James Laver committed
24
  where
25
    cpt {items} _ = pure $ RH.div {} [foldMap entry items]
James Laver's avatar
James Laver committed
26 27 28 29

entry :: Legend -> R.Element
entry (Legend {id_, label}) =
  RH.p {}
30 31 32 33 34 35
  [ RH.span { style: { width : 10
                     , height: 10
                     , backgroundColor: intColor id_
                     , display: "inline-block"
                     } 
            } []
36 37
  , RH.text $ " " <> label
  ]