Position.purs 1.5 KB
Newer Older
Sudhir Kumar's avatar
Sudhir Kumar committed
1
module Gargantext.Components.Charts.Options.Position
2 3 4 5 6 7 8 9 10
       (
         Position(),
         numberPosition,
         percentPosition,
         relativePosition,
         Align(..),
         TopRelativePosition(..),
         LeftRelativePosition(..)
       ) where
11

Sudhir Kumar's avatar
Sudhir Kumar committed
12 13
import Prelude

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import Unsafe.Coerce (unsafeCoerce)

-- | The type `Position` is made to render a css position.
-- | It should be either a `Number`, a `"Number%"` or a `Position` type (`TopRelativePosition` for exemple)
-- | To construct such a type you will have to use one of the smart constructor
foreign import data Position :: Type -> Type

-- | Smart constructor to build a JS Number
numberPosition :: forall r. Number -> Position r
numberPosition = unsafeCoerce

-- | Smart constructor to build a JS Percent
percentPosition :: forall r. Number -> Position r
percentPosition n = unsafeCoerce $ (show n) <> "%"

-- | Smart constructor to build a JS String giving position's detail ("top", "left", ...)
relativePosition :: forall a. Show a => Align a -> Position a
relativePosition (Auto) = unsafeCoerce "auto"
relativePosition (Relative r) = unsafeCoerce $ show r

data Align p = Auto | Relative p

data TopRelativePosition = Top | Middle | Bottom
37
instance Show TopRelativePosition
38 39 40 41 42
  where show (Top) = "top"
        show (Middle) = "middle"
        show (Bottom) = "bottom"

data LeftRelativePosition = LeftPos | Center | RightPos
43
instance Show LeftRelativePosition
44 45 46
  where show (LeftPos) = "left"
        show (Center) = "center"
        show (RightPos) = "right"