styles added

styles added

module RNX.Styles where

import RNX.Color (Color)
import Prelude
import React.DOM.Props (Props)

foreign import data StyleSheet :: *
foreign import data StyleProp :: *

type StyleId = Int
data Style = Style String (Array StyleProp)
type StyleSheet' = Array {name:: String, styles:: Array StyleProp}

foreign import _createStyleSheet :: StyleSheet' -> StyleSheet

createStyleSheet :: Array Style -> StyleSheet
createStyleSheet s =
 _createStyleSheet $ map getStyle s
 where
   getStyle (Style name styleProps) = {name: name, styles: styleProps}

-- TODO: make this type safe!
foreign import getStyleId :: StyleSheet -> String -> StyleId
foreign import unsafeMkStyleProp :: forall val. String -> val -> StyleProp
foreign import unsafeMkStyleSheet :: forall val. String -> val -> Props

style :: StyleId -> Props
style = unsafeMkStyleSheet "style"

styles :: Array StyleId -> Props
styles = unsafeMkStyleSheet "style"

--------- Styles ---------------

data Visibility = Visible | Hidden

-- A

data AlignItems
  = AlignItemsFlexStart
  | AlignItemsFlexEnd
  | AlignItemsCenter
  | AlignItemsStretch

alignItems :: AlignItems -> StyleProp
alignItems AlignItemsFlexStart = unsafeMkStyleProp "alignItems" "flex-start"
alignItems AlignItemsFlexEnd   = unsafeMkStyleProp "alignItems" "flex-end"
alignItems AlignItemsCenter    = unsafeMkStyleProp "alignItems" "center"
alignItems AlignItemsStretch   = unsafeMkStyleProp "alignItems" "stretch"

data AlignSelf
  = AlignSelfAuto
  | AlignSelfFlexStart
  | AlignSelfFlexEnd
  | AlignSelfCenter
  | AlignSelfStretch

alignSelf :: AlignSelf -> StyleProp
alignSelf AlignSelfAuto      = unsafeMkStyleProp "alignSelf" "auto"
alignSelf AlignSelfFlexStart = unsafeMkStyleProp "alignSelf" "flex-start"
alignSelf AlignSelfFlexEnd   = unsafeMkStyleProp "alignSelf" "flex-end"
alignSelf AlignSelfCenter    = unsafeMkStyleProp "alignSelf" "center"
alignSelf AlignSelfStretch   = unsafeMkStyleProp "alignSelf" "stretch"

-- B

backfaceVisibility :: Visibility -> StyleProp
backfaceVisibility Visible = unsafeMkStyleProp "backfaceVisibility" "visible"
backfaceVisibility Hidden  = unsafeMkStyleProp "backfaceVisibility" "hidden"

backgroundColor :: Color -> StyleProp
backgroundColor c = unsafeMkStyleProp "backgroundColor" (show c)

backgroundVisibility :: Visibility -> StyleProp
backgroundVisibility Visible = unsafeMkStyleProp "backgroundVisibility" "visible"
backgroundVisibility Hidden  = unsafeMkStyleProp "backgroundVisibility" "hidden"

borderBottomColor :: Color -> StyleProp
borderBottomColor c = unsafeMkStyleProp "borderBottomColor" (show c)

borderTopColor :: Color -> StyleProp
borderTopColor c = unsafeMkStyleProp "borderTopColor" (show c)

borderBottomRightRadius :: Int -> StyleProp
borderBottomRightRadius = unsafeMkStyleProp "borderBottomRightRadius"

borderBottomLeftRadius :: Int -> StyleProp
borderBottomLeftRadius = unsafeMkStyleProp "borderBottomLeftRadius"

borderBottomWidth :: Int -> StyleProp
borderBottomWidth = unsafeMkStyleProp "borderBottomWidth"

borderColor :: Color -> StyleProp
borderColor c = unsafeMkStyleProp "borderColor" (show c)

borderLeftColor :: Color -> StyleProp
borderLeftColor c = unsafeMkStyleProp "borderLeftColor" (show c)

borderLeftWidth :: Int -> StyleProp
borderLeftWidth = unsafeMkStyleProp "borderLeftWidth"

borderRadius :: Int -> StyleProp
borderRadius = unsafeMkStyleProp "borderRadius"

borderRightColor :: Color -> StyleProp
borderRightColor c = unsafeMkStyleProp "borderRightColor" (show c)

borderRightWidth :: Int -> StyleProp
borderRightWidth = unsafeMkStyleProp "borderRightWidth"

data BorderStyle
  = BorderSolid
  | BorderDotted
  | BorderDashed

borderStyle :: BorderStyle -> StyleProp
borderStyle BorderSolid  = unsafeMkStyleProp "borderStyle" "solid"
borderStyle BorderDotted = unsafeMkStyleProp "borderStyle" "dotted"
borderStyle BorderDashed = unsafeMkStyleProp "borderStyle" "dashed"

borderTopLeftRadius :: Int -> StyleProp
borderTopLeftRadius = unsafeMkStyleProp "borderTopLeftRadius"

borderTopRightRadius :: Int -> StyleProp
borderTopRightRadius = unsafeMkStyleProp "borderTopRightRadius"

borderTopWidth :: Int -> StyleProp
borderTopWidth = unsafeMkStyleProp "borderTopWidth"

borderWidth :: Int -> StyleProp
borderWidth = unsafeMkStyleProp "borderWidth"

bottom :: Int -> StyleProp
bottom = unsafeMkStyleProp "bottom"

-- C

color :: Color -> StyleProp
color c = unsafeMkStyleProp "color" (show c)

-- E

elevation :: Int -> StyleProp
elevation = unsafeMkStyleProp "elevation"

-- F

flex :: Int -> StyleProp
flex = unsafeMkStyleProp "flex"

flexBasis :: Int -> StyleProp
flexBasis = unsafeMkStyleProp "flexBasis"

data FlexDirection
  = Row
  | Column
  | RowReverse
  | ColumnReverse

flexDirection :: FlexDirection -> StyleProp
flexDirection Row           = unsafeMkStyleProp "flexDirection" "row"
flexDirection Column        = unsafeMkStyleProp "flexDirection" "column"
flexDirection ColumnReverse = unsafeMkStyleProp "flexDirection" "column-reverse"
flexDirection RowReverse    = unsafeMkStyleProp "flexDirection" "row-reverse"

flexGrow :: Int -> StyleProp
flexGrow = unsafeMkStyleProp "flexGrow"

flexShrink :: Int -> StyleProp
flexShrink = unsafeMkStyleProp "flexShrink"

data WrapProp = Wrap | NoWrap

flexWrap :: WrapProp -> StyleProp
flexWrap Wrap   = unsafeMkStyleProp "flexWrap" "wrap"
flexWrap NoWrap = unsafeMkStyleProp "flexWrap" "nowrap"

fontFamily :: String -> StyleProp
fontFamily = unsafeMkStyleProp "fontFamily"

fontSize :: Int -> StyleProp
fontSize = unsafeMkStyleProp "fontSize"

data FontStyle = FontNormal | FontItalic

fontStyle :: FontStyle -> StyleProp
fontStyle FontNormal = unsafeMkStyleProp "fontStyle" "normal"
fontStyle FontItalic = unsafeMkStyleProp "fontStyle" "italic"

data FontVariant
  = SmallCap
  | OldStyleNum
  | LiningNum
  | TabularNum
  | ProportionalNum

fontVariant :: Array FontVariant -> StyleProp
fontVariant ary = unsafeMkStyleProp "fontVariant" (map fontVariantNum ary)

fontVariantNum :: FontVariant -> String
fontVariantNum SmallCap        = "small-caps"
fontVariantNum OldStyleNum     = "oldstyle-nums"
fontVariantNum LiningNum       = "lining-nums"
fontVariantNum TabularNum      = "tabular-nums"
fontVariantNum ProportionalNum = "proportional-nums"

data FontWeight
  = WeightNormal
  | WeightBold
  | Weight100
  | Weight200
  | Weight300
  | Weight400
  | Weight500
  | Weight600
  | Weight700
  | Weight800
  | Weight900

fontWeight :: FontWeight -> StyleProp
fontWeight WeightNormal = unsafeMkStyleProp "fontWeight" "normal"
fontWeight WeightBold   = unsafeMkStyleProp "fontWeight" "bold"
fontWeight Weight100    = unsafeMkStyleProp "fontWeight" "100"
fontWeight Weight200    = unsafeMkStyleProp "fontWeight" "200"
fontWeight Weight300    = unsafeMkStyleProp "fontWeight" "300"
fontWeight Weight400    = unsafeMkStyleProp "fontWeight" "400"
fontWeight Weight500    = unsafeMkStyleProp "fontWeight" "500"
fontWeight Weight600    = unsafeMkStyleProp "fontWeight" "600"
fontWeight Weight700    = unsafeMkStyleProp "fontWeight" "700"
fontWeight Weight800    = unsafeMkStyleProp "fontWeight" "800"
fontWeight Weight900    = unsafeMkStyleProp "fontWeight" "900"

-- H

height :: Int -> StyleProp
height = unsafeMkStyleProp "height"

--J

data JustifyContent
  = JustifyContentFlexStart
  | JustifyContentFlexEnd
  | JustifyContentCenter
  | JustifyContentSpaceBetween
  | JustifyContentSpaceAround

justifyContent :: JustifyContent -> StyleProp
justifyContent JustifyContentFlexStart    = unsafeMkStyleProp "justifyContent" "flex-start"
justifyContent JustifyContentFlexEnd      = unsafeMkStyleProp "justifyContent" "flex-end"
justifyContent JustifyContentCenter       = unsafeMkStyleProp "justifyContent" "center"
justifyContent JustifyContentSpaceBetween = unsafeMkStyleProp "justifyContent" "space-between"
justifyContent JustifyContentSpaceAround  = unsafeMkStyleProp "justifyContent" "space-around"

-- L

left :: Int -> StyleProp
left = unsafeMkStyleProp "left"

letterSpacing :: Int -> StyleProp
letterSpacing = unsafeMkStyleProp "letterSpacing"

lineHeight :: Int -> StyleProp
lineHeight = unsafeMkStyleProp "lineHeight"

-- M

margin :: Int -> StyleProp
margin = unsafeMkStyleProp "margin"

marginBottom :: Int -> StyleProp
marginBottom = unsafeMkStyleProp "marginBottom"

marginHorizontal :: Int -> StyleProp
marginHorizontal = unsafeMkStyleProp "marginHorizontal"

marginLeft :: Int -> StyleProp
marginLeft = unsafeMkStyleProp "marginLeft"

marginRight :: Int -> StyleProp
marginRight = unsafeMkStyleProp "marginRight"

marginTop :: Int -> StyleProp
marginTop = unsafeMkStyleProp "marginTop"

marginVertical :: Int -> StyleProp
marginVertical = unsafeMkStyleProp "marginVertical"

maxHeight :: Int -> StyleProp
maxHeight = unsafeMkStyleProp "maxHeight"

maxWidth :: Int -> StyleProp
maxWidth = unsafeMkStyleProp "maxWidth"

minHeight :: Int -> StyleProp
minHeight = unsafeMkStyleProp "minHeight"

minWidth :: Int -> StyleProp
minWidth = unsafeMkStyleProp "minWidth"

-- O

opacity :: Int -> StyleProp
opacity = unsafeMkStyleProp "opacity"

overflow :: Visibility -> StyleProp
overflow Visible = unsafeMkStyleProp "overflow" "visible"
overflow Hidden  = unsafeMkStyleProp "overflow" "hidden"

overlayColor :: String -> StyleProp
overlayColor = unsafeMkStyleProp "overlayColor"

-- P

padding :: Int -> StyleProp
padding = unsafeMkStyleProp "padding"

paddingBottom :: Int -> StyleProp
paddingBottom = unsafeMkStyleProp "paddingBottom"

paddingHorizontal :: Int -> StyleProp
paddingHorizontal = unsafeMkStyleProp "paddingHorizontal"

paddingLeft :: Int -> StyleProp
paddingLeft = unsafeMkStyleProp "paddingLeft"

paddingRight :: Int -> StyleProp
paddingRight = unsafeMkStyleProp "paddingRight"

paddingTop :: Int -> StyleProp
paddingTop = unsafeMkStyleProp "paddingTop"

paddingVertical :: Int -> StyleProp
paddingVertical = unsafeMkStyleProp "paddingVertical"

data Position = Absolute | Relative

position :: Position -> StyleProp
position Absolute = unsafeMkStyleProp "position" "absolute"
position Relative = unsafeMkStyleProp "position" "relative"

-- R

right :: Int -> StyleProp
right = unsafeMkStyleProp "right"

-- S

shadowColor :: Color -> StyleProp
shadowColor c = unsafeMkStyleProp "shadowColor" (show c)

shadowOffset :: {width :: Int, height :: Int} -> StyleProp
shadowOffset = unsafeMkStyleProp "shadowOffset"

shadowOpacity :: Int -> StyleProp
shadowOpacity = unsafeMkStyleProp "shadowOpacity"

shadowRadius :: Int -> StyleProp
shadowRadius = unsafeMkStyleProp "shadowRadius"

-- T

data TextAlign
  = TextAlignAuto
  | TextAlignLeft
  | TextAlignRight
  | TextAlignCenter
  | TextAlignJustify

textAlign :: TextAlign -> StyleProp
textAlign TextAlignAuto    = unsafeMkStyleProp "textAlign" "auto"
textAlign TextAlignLeft    = unsafeMkStyleProp "textAlign" "left"
textAlign TextAlignRight   = unsafeMkStyleProp "textAlign" "right"
textAlign TextAlignCenter  = unsafeMkStyleProp "textAlign" "center"
textAlign TextAlignJustify = unsafeMkStyleProp "textAlign" "justify"

data TextAlignVertical
  = TextAlignVerticalAuto
  | TextAlignVerticalTop
  | TextAlignVerticalBottom
  | TextAlignVerticalCenter

textAlignVertical :: TextAlignVertical -> StyleProp
textAlignVertical TextAlignVerticalAuto   = unsafeMkStyleProp "textAlignVertical" "auto"
textAlignVertical TextAlignVerticalTop    = unsafeMkStyleProp "textAlignVertical" "top"
textAlignVertical TextAlignVerticalBottom = unsafeMkStyleProp "textAlignVertical" "bottom"
textAlignVertical TextAlignVerticalCenter = unsafeMkStyleProp "textAlignVertical" "center"

textDecorationColor :: Color -> StyleProp
textDecorationColor c = unsafeMkStyleProp "textDecorationColor" (show c)

data TextDecorationLine
  = None
  | Underline
  | LineThrough
  | UnderlineLineThrough

textDecorationLine :: TextDecorationLine -> StyleProp
textDecorationLine None                 = unsafeMkStyleProp "textDecorationLine" "none"
textDecorationLine Underline            = unsafeMkStyleProp "textDecorationLine" "underline"
textDecorationLine LineThrough          = unsafeMkStyleProp "textDecorationLine" "line-through"
textDecorationLine UnderlineLineThrough = unsafeMkStyleProp "textDecorationLine" "underline line-through"

data TextDecorationStyle
  = TextSolid
  | TextDouble
  | TextDotted
  | TextDashed

textDecorationStyle :: TextDecorationStyle -> StyleProp
textDecorationStyle TextSolid  = unsafeMkStyleProp "textDecorationStyle" "solid"
textDecorationStyle TextDouble = unsafeMkStyleProp "textDecorationStyle" "double"
textDecorationStyle TextDotted = unsafeMkStyleProp "textDecorationStyle" "dotted"
textDecorationStyle TextDashed = unsafeMkStyleProp "textDecorationStyle" "dashed"

textShadowColor :: Color -> StyleProp
textShadowColor c = unsafeMkStyleProp "textShadowColor" (show c)

textShadowOffset :: {width :: Int, height :: Int} -> StyleProp
textShadowOffset = unsafeMkStyleProp "textShadowOffset"

textShadowRadius :: Int -> StyleProp
textShadowRadius = unsafeMkStyleProp "textShadowRadius"

top :: Int -> StyleProp
top = unsafeMkStyleProp "top"

-- W

width :: Int -> StyleProp
width = unsafeMkStyleProp "width"

data WritingDirection
  = WritingDirectionAuto
  | WritingDirectionLtr
  | WritingDirectionRtl

writingDirection :: WritingDirection -> StyleProp
writingDirection WritingDirectionAuto = unsafeMkStyleProp "writingDirection" "auto"
writingDirection WritingDirectionLtr  = unsafeMkStyleProp "writingDirection" "ltr"
writingDirection WritingDirectionRtl  = unsafeMkStyleProp "writingDirection" "rtl"

-- Z

zIndex :: Int -> StyleProp
zIndex = unsafeMkStyleProp "zIndex"

-- TODO: Transform StyleProp
-- TODO: resizeMode

module RNX.Styles where

import RNX.Color (Color)
import Prelude
import React.DOM.Props (Props)

foreign import data StyleSheet :: *
foreign import data StyleProp :: *

type StyleId = Int
data Style = Style String (Array StyleProp)
type StyleSheet' = Array {name:: String, styles:: Array StyleProp}

foreign import _createStyleSheet :: StyleSheet' -> StyleSheet

createStyleSheet :: Array Style -> StyleSheet
createStyleSheet s =
 _createStyleSheet $ map getStyle s
 where
   getStyle (Style name styleProps) = {name: name, styles: styleProps}

-- TODO: make this type safe!
foreign import getStyleId :: StyleSheet -> String -> StyleId
foreign import unsafeMkStyleProp :: forall val. String -> val -> StyleProp
foreign import unsafeMkStyleSheet :: forall val. String -> val -> Props

style :: StyleId -> Props
style = unsafeMkStyleSheet "style"

styles :: Array StyleId -> Props
styles = unsafeMkStyleSheet "style"

--------- Styles ---------------

data Visibility = Visible | Hidden

-- A

data AlignItems
  = AlignItemsFlexStart
  | AlignItemsFlexEnd
  | AlignItemsCenter
  | AlignItemsStretch

alignItems :: AlignItems -> StyleProp
alignItems AlignItemsFlexStart = unsafeMkStyleProp "alignItems" "flex-start"
alignItems AlignItemsFlexEnd   = unsafeMkStyleProp "alignItems" "flex-end"
alignItems AlignItemsCenter    = unsafeMkStyleProp "alignItems" "center"
alignItems AlignItemsStretch   = unsafeMkStyleProp "alignItems" "stretch"

data AlignSelf
  = AlignSelfAuto
  | AlignSelfFlexStart
  | AlignSelfFlexEnd
  | AlignSelfCenter
  | AlignSelfStretch

alignSelf :: AlignSelf -> StyleProp
alignSelf AlignSelfAuto      = unsafeMkStyleProp "alignSelf" "auto"
alignSelf AlignSelfFlexStart = unsafeMkStyleProp "alignSelf" "flex-start"
alignSelf AlignSelfFlexEnd   = unsafeMkStyleProp "alignSelf" "flex-end"
alignSelf AlignSelfCenter    = unsafeMkStyleProp "alignSelf" "center"
alignSelf AlignSelfStretch   = unsafeMkStyleProp "alignSelf" "stretch"

-- B

backfaceVisibility :: Visibility -> StyleProp
backfaceVisibility Visible = unsafeMkStyleProp "backfaceVisibility" "visible"
backfaceVisibility Hidden  = unsafeMkStyleProp "backfaceVisibility" "hidden"

backgroundColor :: Color -> StyleProp
backgroundColor c = unsafeMkStyleProp "backgroundColor" (show c)

backgroundVisibility :: Visibility -> StyleProp
backgroundVisibility Visible = unsafeMkStyleProp "backgroundVisibility" "visible"
backgroundVisibility Hidden  = unsafeMkStyleProp "backgroundVisibility" "hidden"

borderBottomColor :: Color -> StyleProp
borderBottomColor c = unsafeMkStyleProp "borderBottomColor" (show c)

borderBottomRightRadius :: Int -> StyleProp
borderBottomRightRadius = unsafeMkStyleProp "borderBottomRightRadius"

borderBottomWidth :: Int -> StyleProp
borderBottomWidth = unsafeMkStyleProp "borderBottomWidth"

borderColor :: Color -> StyleProp
borderColor c = unsafeMkStyleProp "borderColor" (show c)

borderLeftColor :: Color -> StyleProp
borderLeftColor c = unsafeMkStyleProp "borderLeftColor" (show c)

borderLeftWidth :: Int -> StyleProp
borderLeftWidth = unsafeMkStyleProp "borderLeftWidth"

borderRadius :: Int -> StyleProp
borderRadius = unsafeMkStyleProp "borderRadius"

borderRightColor :: Color -> StyleProp
borderRightColor c = unsafeMkStyleProp "borderRightColor" (show c)

borderRightWidth :: Int -> StyleProp
borderRightWidth = unsafeMkStyleProp "borderRightWidth"

data BorderStyle
  = BorderSolid
  | BorderDotted
  | BorderDashed

borderStyle :: BorderStyle -> StyleProp
borderStyle BorderSolid  = unsafeMkStyleProp "borderStyle" "solid"
borderStyle BorderDotted = unsafeMkStyleProp "borderStyle" "dotted"
borderStyle BorderDashed = unsafeMkStyleProp "borderStyle" "dashed"

borderTopLeftRadius :: Int -> StyleProp
borderTopLeftRadius = unsafeMkStyleProp "borderTopLeftRadius"

borderTopRightRadius :: Int -> StyleProp
borderTopRightRadius = unsafeMkStyleProp "borderTopRightRadius"

borderTopWidth :: Int -> StyleProp
borderTopWidth = unsafeMkStyleProp "borderTopWidth"

borderWidth :: Int -> StyleProp
borderWidth = unsafeMkStyleProp "borderWidth"

bottom :: Int -> StyleProp
bottom = unsafeMkStyleProp "bottom"

-- C

color :: Color -> StyleProp
color c = unsafeMkStyleProp "color" (show c)

-- E

elevation :: Int -> StyleProp
elevation = unsafeMkStyleProp "elevation"

-- F

flex :: Int -> StyleProp
flex = unsafeMkStyleProp "flex"

flexBasis :: Int -> StyleProp
flexBasis = unsafeMkStyleProp "flexBasis"

data FlexDirection
  = Row
  | Column
  | RowReverse
  | ColumnReverse

flexDirection :: FlexDirection -> StyleProp
flexDirection Row           = unsafeMkStyleProp "flexDirection" "row"
flexDirection Column        = unsafeMkStyleProp "flexDirection" "column"
flexDirection ColumnReverse = unsafeMkStyleProp "flexDirection" "column-reverse"
flexDirection RowReverse    = unsafeMkStyleProp "flexDirection" "row-reverse"

flexGrow :: Int -> StyleProp
flexGrow = unsafeMkStyleProp "flexGrow"

flexShrink :: Int -> StyleProp
flexShrink = unsafeMkStyleProp "flexShrink"

data WrapProp = Wrap | NoWrap

flexWrap :: WrapProp -> StyleProp
flexWrap Wrap   = unsafeMkStyleProp "flexWrap" "wrap"
flexWrap NoWrap = unsafeMkStyleProp "flexWrap" "nowrap"

fontFamily :: String -> StyleProp
fontFamily = unsafeMkStyleProp "fontFamily"

fontSize :: Int -> StyleProp
fontSize = unsafeMkStyleProp "fontSize"

data FontStyle = FontNormal | FontItalic

fontStyle :: FontStyle -> StyleProp
fontStyle FontNormal = unsafeMkStyleProp "fontStyle" "normal"
fontStyle FontItalic = unsafeMkStyleProp "fontStyle" "italic"

data FontVariant
  = SmallCap
  | OldStyleNum
  | LiningNum
  | TabularNum
  | ProportionalNum

fontVariant :: Array FontVariant -> StyleProp
fontVariant ary = unsafeMkStyleProp "fontVariant" (map fontVariantNum ary)

fontVariantNum :: FontVariant -> String
fontVariantNum SmallCap        = "small-caps"
fontVariantNum OldStyleNum     = "oldstyle-nums"
fontVariantNum LiningNum       = "lining-nums"
fontVariantNum TabularNum      = "tabular-nums"
fontVariantNum ProportionalNum = "proportional-nums"

data FontWeight
  = WeightNormal
  | WeightBold
  | Weight100
  | Weight200
  | Weight300
  | Weight400
  | Weight500
  | Weight600
  | Weight700
  | Weight800
  | Weight900

fontWeight :: FontWeight -> StyleProp
fontWeight WeightNormal = unsafeMkStyleProp "fontWeight" "normal"
fontWeight WeightBold   = unsafeMkStyleProp "fontWeight" "bold"
fontWeight Weight100    = unsafeMkStyleProp "fontWeight" "100"
fontWeight Weight200    = unsafeMkStyleProp "fontWeight" "200"
fontWeight Weight300    = unsafeMkStyleProp "fontWeight" "300"
fontWeight Weight400    = unsafeMkStyleProp "fontWeight" "400"
fontWeight Weight500    = unsafeMkStyleProp "fontWeight" "500"
fontWeight Weight600    = unsafeMkStyleProp "fontWeight" "600"
fontWeight Weight700    = unsafeMkStyleProp "fontWeight" "700"
fontWeight Weight800    = unsafeMkStyleProp "fontWeight" "800"
fontWeight Weight900    = unsafeMkStyleProp "fontWeight" "900"

-- H

height :: Int -> StyleProp
height = unsafeMkStyleProp "height"

--J

data JustifyContent
  = JustifyContentFlexStart
  | JustifyContentFlexEnd
  | JustifyContentCenter
  | JustifyContentSpaceBetween
  | JustifyContentSpaceAround

justifyContent :: JustifyContent -> StyleProp
justifyContent JustifyContentFlexStart    = unsafeMkStyleProp "justifyContent" "flex-start"
justifyContent JustifyContentFlexEnd      = unsafeMkStyleProp "justifyContent" "flex-end"
justifyContent JustifyContentCenter       = unsafeMkStyleProp "justifyContent" "center"
justifyContent JustifyContentSpaceBetween = unsafeMkStyleProp "justifyContent" "space-between"
justifyContent JustifyContentSpaceAround  = unsafeMkStyleProp "justifyContent" "space-around"

-- L

left :: Int -> StyleProp
left = unsafeMkStyleProp "left"

letterSpacing :: Int -> StyleProp
letterSpacing = unsafeMkStyleProp "letterSpacing"

lineHeight :: Int -> StyleProp
lineHeight = unsafeMkStyleProp "lineHeight"

-- M

margin :: Int -> StyleProp
margin = unsafeMkStyleProp "margin"

marginBottom :: Int -> StyleProp
marginBottom = unsafeMkStyleProp "marginBottom"

marginHorizontal :: Int -> StyleProp
marginHorizontal = unsafeMkStyleProp "marginHorizontal"

marginLeft :: Int -> StyleProp
marginLeft = unsafeMkStyleProp "marginLeft"

marginRight :: Int -> StyleProp
marginRight = unsafeMkStyleProp "marginRight"

marginTop :: Int -> StyleProp
marginTop = unsafeMkStyleProp "marginTop"

marginVertical :: Int -> StyleProp
marginVertical = unsafeMkStyleProp "marginVertical"

maxHeight :: Int -> StyleProp
maxHeight = unsafeMkStyleProp "maxHeight"

maxWidth :: Int -> StyleProp
maxWidth = unsafeMkStyleProp "maxWidth"

minHeight :: Int -> StyleProp
minHeight = unsafeMkStyleProp "minHeight"

minWidth :: Int -> StyleProp
minWidth = unsafeMkStyleProp "minWidth"

-- O

opacity :: Int -> StyleProp
opacity = unsafeMkStyleProp "opacity"

overflow :: Visibility -> StyleProp
overflow Visible = unsafeMkStyleProp "overflow" "visible"
overflow Hidden  = unsafeMkStyleProp "overflow" "hidden"

overlayColor :: String -> StyleProp
overlayColor = unsafeMkStyleProp "overlayColor"

-- P

padding :: Int -> StyleProp
padding = unsafeMkStyleProp "padding"

paddingBottom :: Int -> StyleProp
paddingBottom = unsafeMkStyleProp "paddingBottom"

paddingHorizontal :: Int -> StyleProp
paddingHorizontal = unsafeMkStyleProp "paddingHorizontal"

paddingLeft :: Int -> StyleProp
paddingLeft = unsafeMkStyleProp "paddingLeft"

paddingRight :: Int -> StyleProp
paddingRight = unsafeMkStyleProp "paddingRight"

paddingTop :: Int -> StyleProp
paddingTop = unsafeMkStyleProp "paddingTop"

paddingVertical :: Int -> StyleProp
paddingVertical = unsafeMkStyleProp "paddingVertical"

data Position = Absolute | Relative

position :: Position -> StyleProp
position Absolute = unsafeMkStyleProp "position" "absolute"
position Relative = unsafeMkStyleProp "position" "relative"

-- R

right :: Int -> StyleProp
right = unsafeMkStyleProp "right"

-- S

shadowColor :: Color -> StyleProp
shadowColor c = unsafeMkStyleProp "shadowColor" (show c)

shadowOffset :: {width :: Int, height :: Int} -> StyleProp
shadowOffset = unsafeMkStyleProp "shadowOffset"

shadowOpacity :: Int -> StyleProp
shadowOpacity = unsafeMkStyleProp "shadowOpacity"

shadowRadius :: Int -> StyleProp
shadowRadius = unsafeMkStyleProp "shadowRadius"

-- T

data TextAlign
  = TextAlignAuto
  | TextAlignLeft
  | TextAlignRight
  | TextAlignCenter
  | TextAlignJustify

textAlign :: TextAlign -> StyleProp
textAlign TextAlignAuto    = unsafeMkStyleProp "textAlign" "auto"
textAlign TextAlignLeft    = unsafeMkStyleProp "textAlign" "left"
textAlign TextAlignRight   = unsafeMkStyleProp "textAlign" "right"
textAlign TextAlignCenter  = unsafeMkStyleProp "textAlign" "center"
textAlign TextAlignJustify = unsafeMkStyleProp "textAlign" "justify"

data TextAlignVertical
  = TextAlignVerticalAuto
  | TextAlignVerticalTop
  | TextAlignVerticalBottom
  | TextAlignVerticalCenter

textAlignVertical :: TextAlignVertical -> StyleProp
textAlignVertical TextAlignVerticalAuto   = unsafeMkStyleProp "textAlignVertical" "auto"
textAlignVertical TextAlignVerticalTop    = unsafeMkStyleProp "textAlignVertical" "top"
textAlignVertical TextAlignVerticalBottom = unsafeMkStyleProp "textAlignVertical" "bottom"
textAlignVertical TextAlignVerticalCenter = unsafeMkStyleProp "textAlignVertical" "center"

textDecorationColor :: Color -> StyleProp
textDecorationColor c = unsafeMkStyleProp "textDecorationColor" (show c)

data TextDecorationLine
  = None
  | Underline
  | LineThrough
  | UnderlineLineThrough

textDecorationLine :: TextDecorationLine -> StyleProp
textDecorationLine None                 = unsafeMkStyleProp "textDecorationLine" "none"
textDecorationLine Underline            = unsafeMkStyleProp "textDecorationLine" "underline"
textDecorationLine LineThrough          = unsafeMkStyleProp "textDecorationLine" "line-through"
textDecorationLine UnderlineLineThrough = unsafeMkStyleProp "textDecorationLine" "underline line-through"

data TextDecorationStyle
  = TextSolid
  | TextDouble
  | TextDotted
  | TextDashed

textDecorationStyle :: TextDecorationStyle -> StyleProp
textDecorationStyle TextSolid  = unsafeMkStyleProp "textDecorationStyle" "solid"
textDecorationStyle TextDouble = unsafeMkStyleProp "textDecorationStyle" "double"
textDecorationStyle TextDotted = unsafeMkStyleProp "textDecorationStyle" "dotted"
textDecorationStyle TextDashed = unsafeMkStyleProp "textDecorationStyle" "dashed"

textShadowColor :: Color -> StyleProp
textShadowColor c = unsafeMkStyleProp "textShadowColor" (show c)

textShadowOffset :: {width :: Int, height :: Int} -> StyleProp
textShadowOffset = unsafeMkStyleProp "textShadowOffset"

textShadowRadius :: Int -> StyleProp
textShadowRadius = unsafeMkStyleProp "textShadowRadius"

top :: Int -> StyleProp
top = unsafeMkStyleProp "top"

-- W

width :: Int -> StyleProp
width = unsafeMkStyleProp "width"

data WritingDirection
  = WritingDirectionAuto
  | WritingDirectionLtr
  | WritingDirectionRtl

writingDirection :: WritingDirection -> StyleProp
writingDirection WritingDirectionAuto = unsafeMkStyleProp "writingDirection" "auto"
writingDirection WritingDirectionLtr  = unsafeMkStyleProp "writingDirection" "ltr"
writingDirection WritingDirectionRtl  = unsafeMkStyleProp "writingDirection" "rtl"

-- Z

zIndex :: Int -> StyleProp
zIndex = unsafeMkStyleProp "zIndex"

-- TODO: Transform StyleProp
-- TODO: resizeMode


Delete Main.purs

Delete Main.purs

module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)

main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
  log "You should add some tests."


8.17.1 Rewrite the safeDivide function to throw an exception using throwException if the denominator is zero.

module Test.Main where

import Control.Monad.Eff.Console (print)

import Prelude
import Solution
import Data.Maybe
import Control.Apply (lift2)
import qualified Data.Array as A
import qualified Data.List as L
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Debug.Trace (trace)

main = do
  -- 8.7.1
  print $ third ([] :: Array Int)
  print $ third [1]
  print $ third [1,2]
  print $ third [1,2,3]
  print $ third [1,2,3,4]
  -- 8.7.2
  print $ sums [] -- [0]
  print $ sums [1, 2, 10] -- [0,1,2,3,10,11,12,13]
  -- 8.7.5
  print $ filterM (\a -> Just (a>6)) (L.toList [1,3,10,11])
  print $ filterM (\a -> if a == 3 then Nothing else Just (a>0)) (L.toList [1,3,10,11])
  print $ filterM (\a -> [true,false,true]) (L.toList [1,2])
  print $ A.filterM (\a -> [true,false])  [1,2,3]
  -- 8.7.6
  print $ map2 ((+) 1) [1,2,3]
  print $ lift2 (+) [1] [2]
  print $ lift2'4 (+) [1] [2]
  print $ lift2 (+) Nothing (Just 2)
  print $ lift2 (+) (Just 1) (Just 2)
  -- 8.17.1
  -- result <- safeDivide 10 5
  -- print $ result
  -- print "This was OK."
  -- this would throw a runtime exception
  --  error <- safeDivide 10 0
  --  print $ error
  --  print "This was NOT OK."
  valueOrDefault <- catchException printExceptionReturnDefault $ safeDivide 10 0
  print valueOrDefault

  where
  printExceptionReturnDefault :: forall eff. Error -> Eff eff Int
  printExceptionReturnDefault e = trace (message e) (\_ -> return 23)

module Test.Main where

import Control.Monad.Eff.Console (print)

import Prelude
import Solution
import Data.Maybe
import Control.Apply (lift2)
import qualified Data.Array as A
import qualified Data.List as L
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Debug.Trace (trace)

main = do
  -- 8.7.1
  print $ third ([] :: Array Int)
  print $ third [1]
  print $ third [1,2]
  print $ third [1,2,3]
  print $ third [1,2,3,4]
  -- 8.7.2
  print $ sums [] -- [0]
  print $ sums [1, 2, 10] -- [0,1,2,3,10,11,12,13]
  -- 8.7.5
  print $ filterM (\a -> Just (a>6)) (L.toList [1,3,10,11])
  print $ filterM (\a -> if a == 3 then Nothing else Just (a>0)) (L.toList [1,3,10,11])
  print $ filterM (\a -> [true,false,true]) (L.toList [1,2])
  print $ A.filterM (\a -> [true,false])  [1,2,3]
  -- 8.7.6
  print $ map2 ((+) 1) [1,2,3]
  print $ lift2 (+) [1] [2]
  print $ lift2'4 (+) [1] [2]
  print $ lift2 (+) Nothing (Just 2)
  print $ lift2 (+) (Just 1) (Just 2)
  -- 8.17.1
  -- result <- safeDivide 10 5
  -- print $ result
  -- print "This was OK."
  -- this would throw a runtime exception
  --  error <- safeDivide 10 0
  --  print $ error
  --  print "This was NOT OK."
  valueOrDefault <- catchException printException $ safeDivide 10 0
  print valueOrDefault

  where
  printException :: forall eff. Error -> Eff eff Int
  printException e = trace (message e) (\_ -> return 23)


Added more tests.

Added more tests.

module Main where

import Debug.Trace
import Control.Monad.State
import Control.Monad.State.Class

-- Import the library's module(s)
import Gattaca.Experiments.Rx
import Gattaca.Experiments.Utils

-- Import Test.QuickCheck, which supports property-based testing
import Test.QuickCheck

-- Main.main is the entry point of the application
--
-- In the case of the test suite, Main.main will use QuickCheck to test a collection
-- of properties that we expect of the diffs function.

toList :: forall a.Observable (State [a]) a -> [a]
toList os = execState (os |> subscribe (\x -> modify (\xs -> xs ++ [x])) (\unit -> return unit)) []

testObservable :: forall a.(Observable (State [a]) a -> Observable (State [a]) a) -> [a] -> [a]
testObservable f =  toObservable >>> f >>> toList

main = do trace "Functor laws:"

          trace "First Law"
          quickCheck $ \ns -> let xs = id (toObservable ns) :: Observable (State [Number]) Number
                                  ys = id <$> (toObservable ns) :: Observable (State [Number]) Number
                              in  toList xs == toList ys

          trace "Applicative laws:"

          trace "Identity"
          quickCheck $ \ns -> let v = toObservable ns :: Observable (State [Number]) Number
                                  xs = pure id <*> v :: Observable (State [Number]) Number
                              in toList v == toList xs
          trace "Composition"
          quickCheck $ \ns -> let u = toObservable [\x -> x * x, \x -> x + 5] :: Observable (State [Number]) (Number -> Number)
                                  v = toObservable [\x -> x * x * x, \x -> x / 2, \x -> x ^ 2] :: Observable (State [Number]) (Number -> Number)
                                  w = toObservable ns :: Observable (State [Number]) Number
                                  xs = (pure (<<<)) <*> u <*> v <*> w :: Observable (State [(Number)]) Number
                                  ys = u <*> (v <*> w) :: Observable (State [(Number)]) (Number)
                             in  toList xs == toList ys

          trace "Homomorphism"
          quickCheck $ \x -> let f x = x * x + 2 * x + 1
                                 xs = (pure f) <*> (pure x) :: Observable (State [Number]) Number
                                 ys = pure (f x) :: Observable (State [Number]) Number
                             in toList xs == toList ys

module Main where

import Debug.Trace
import Control.Monad.State
import Control.Monad.State.Class

-- Import the library's module(s)
import Gattaca.Experiments.Rx
import Gattaca.Experiments.Utils

-- Import Test.QuickCheck, which supports property-based testing
import Test.QuickCheck

-- Main.main is the entry point of the application
--
-- In the case of the test suite, Main.main will use QuickCheck to test a collection
-- of properties that we expect of the diffs function.

toList :: forall a.Observable (State [a]) a -> [a]
toList os = execState (os |> subscribe (\x -> modify (\xs -> xs ++ [x])) (\unit -> return unit)) []

testObservable :: forall a.(Observable (State [a]) a -> Observable (State [a]) a) -> [a] -> [a]
testObservable f =  toObservable >>> f >>> toList

main = do
          trace "Applicative laws:"

          trace "Identity"
          quickCheck $ \ns -> let v = toObservable ns :: Observable (State [Number]) Number
                                  xs = pure id <*> v :: Observable (State [Number]) Number
                              in toList v == toList xs
          trace "Composition"
          quickCheck $ \ns -> let u = toObservable [\x -> x * x, \x -> x + 5] :: Observable (State [Number]) (Number -> Number)
                                  v = toObservable [\x -> x * x * x, \x -> x / 2, \x -> x ^ 2] :: Observable (State [Number]) (Number -> Number)
                                  w = toObservable ns :: Observable (State [Number]) Number
                                  xs = (pure (<<<)) <*> u <*> v <*> w :: Observable (State [(Number)]) Number
                                  ys = u <*> (v <*> w) :: Observable (State [(Number)]) (Number)
                             in  toList xs == toList ys

          trace "Homomorphism"
          quickCheck $ \x -> let f x = x * x + 2 * x + 1
                                 xs = (pure f) <*> (pure x) :: Observable (State [Number]) Number
                                 ys = pure (f x) :: Observable (State [Number]) Number
                             in toList xs == toList ys


fix typo

fix typo

-- | This module defines the `MonadWriter` type class and its instances.

module Control.Monad.Writer.Class where

import Prelude

import Data.Tuple (Tuple(..))

-- | The `MonadTell w` type class represents those monads which support a
-- | monoidal accumulator of type `w`, where `tell` appends a value to the
-- | accumulator.
-- |
-- | An implementation is provided for `WriterT`, and for other monad
-- | transformers defined in this library.
-- |
-- | Law:
-- |
-- | - `do { tell x ; tell y } = tell (x <> y)`
class Monad m <= MonadTell w m | m -> w where
  tell :: w -> m Unit

-- | An extension of the `MonadTell` class that introduces some operations on
-- | the accumulator:
-- |
-- | - `listen` modifies the result to include the changes to the accumulator.
-- | - `pass` applies the returned function to the accumulator.
-- |
-- | An implementation is provided for `WriterT`, and for other monad
-- | transformers defined in this library.
-- |
-- | Laws in addition to the `MonadTell` law:
-- |
-- | - `do { tell x ; tell y } = tell (x <> y)`
-- | - `listen (pure a) = pure (Tuple a mempty)`
-- | - `listen (writer a x) = tell x $> Tuple a x`
class MonadTell w m <= MonadWriter w m | m -> w where
  listen :: forall a. m a -> m (Tuple a w)
  pass :: forall a. m (Tuple a (w -> w)) -> m a

-- | Projects a value from modifications made to the accumulator during an
-- | action.
listens :: forall w m a b. MonadWriter w m => (w -> b) -> m a -> m (Tuple a b)
listens f m = do
  Tuple a w <- listen m
  pure $ Tuple a (f w)

-- | Modify the final accumulator value by applying a function.
censor :: forall w m a. MonadWriter w m => (w -> w) -> m a -> m a
censor f m = pass do
  a <- m
  pure $ Tuple a f

-- | This module defines the `MonadWriter` type class and its instances.

module Control.Monad.Writer.Class where

import Prelude

import Data.Tuple (Tuple(..))

-- | The `MonadTell w` type class represents those monads which support a
-- | monoidal accumulator of type `w`, were `tell` appends a value to the
-- | accumulator.
-- |
-- | An implementation is provided for `WriterT`, and for other monad
-- | transformers defined in this library.
-- |
-- | Law:
-- |
-- | - `do { tell x ; tell y } = tell (x <> y)`
class Monad m <= MonadTell w m | m -> w where
  tell :: w -> m Unit

-- | An extension of the `MonadTell` class that introduces some operations on
-- | the accumulator:
-- |
-- | - `listen` modifies the result to include the changes to the accumulator.
-- | - `pass` applies the returned function to the accumulator.
-- |
-- | An implementation is provided for `WriterT`, and for other monad
-- | transformers defined in this library.
-- |
-- | Laws in addition to the `MonadTell` law:
-- |
-- | - `do { tell x ; tell y } = tell (x <> y)`
-- | - `listen (pure a) = pure (Tuple a mempty)`
-- | - `listen (writer a x) = tell x $> Tuple a x`
class MonadTell w m <= MonadWriter w m | m -> w where
  listen :: forall a. m a -> m (Tuple a w)
  pass :: forall a. m (Tuple a (w -> w)) -> m a

-- | Projects a value from modifications made to the accumulator during an
-- | action.
listens :: forall w m a b. MonadWriter w m => (w -> b) -> m a -> m (Tuple a b)
listens f m = do
  Tuple a w <- listen m
  pure $ Tuple a (f w)

-- | Modify the final accumulator value by applying a function.
censor :: forall w m a. MonadWriter w m => (w -> w) -> m a -> m a
censor f m = pass do
  a <- m
  pure $ Tuple a f