Legend.purs 777 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
import Gargantext.Components.GraphExplorer.Types (Legend(..), intColor)
James Laver's avatar
James Laver committed
12 13 14 15 16 17 18 19 20

type Props = ( items :: Seq Legend )

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

legendCpt :: R.Component Props
legendCpt = R.hooksComponent "Legend" cpt
  where
21
    cpt {items} _ = pure $ RH.div {} [foldMap entry items]
James Laver's avatar
James Laver committed
22 23 24 25 26

entry :: Legend -> R.Element
entry (Legend {id_, label}) =
  RH.p {}
  [ RH.span { style: { width: 10, height: 10, backgroundColor: intColor id_, display: "inline-block" } } []
27 28
  , RH.text $ " " <> label
  ]