Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from muhbaasu/flexbox
Add flexbox support.
- Loading branch information
Showing
6 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ Library | |
Clay.Display | ||
Clay.Elements | ||
Clay.Filter | ||
Clay.Flexbox | ||
Clay.Font | ||
Clay.FontFace | ||
Clay.Geometry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, OverloadedStrings #-} | ||
module Clay.Flexbox where | ||
|
||
import Clay.Common (Auto, Baseline, Center, Inherit, Other) | ||
import Clay.Property | ||
import Clay.Size (Size) | ||
import Clay.Stylesheet | ||
import Data.String (fromString) | ||
|
||
-- | CSS Flexible Box Layout | ||
-- http://dev.w3.org/csswg/css-flexbox-1 | ||
|
||
class FlexEnd a where flexEnd :: a | ||
class FlexStart a where flexStart :: a | ||
class SpaceAround a where spaceAround :: a | ||
class SpaceBetween a where spaceBetween :: a | ||
class Stretch a where stretch :: a | ||
|
||
instance FlexEnd Value where flexEnd = "flex-end" | ||
instance FlexStart Value where flexStart = "flex-start" | ||
instance SpaceAround Value where spaceAround = "space-around" | ||
instance SpaceBetween Value where spaceBetween = "space-between" | ||
instance Stretch Value where stretch = "stretch" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype AlignContentValue = AlignContentValue Value | ||
deriving (Val, Other, Inherit, FlexStart, FlexEnd | ||
, Center, SpaceBetween, SpaceAround, Stretch) | ||
|
||
alignContent :: AlignContentValue -> Css | ||
alignContent = key "align-content" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype AlignItemsValue = AlignItemValue Value | ||
deriving (Val, Other, Inherit, Baseline | ||
, Center, FlexEnd, FlexStart, Stretch) | ||
|
||
alignItems :: AlignItemsValue -> Css | ||
alignItems = key "align-items" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype AlignSelfValue = AlignSelfValue Value | ||
deriving (Val, Other, Inherit, Auto, Baseline | ||
, Center, FlexEnd, FlexStart, Stretch) | ||
|
||
alignSelf :: AlignSelfValue -> Css | ||
alignSelf = key "align-self" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
flex :: Int -> Int -> Size b -> Css | ||
flex g s b = key "flex" (gs ! ss ! value b) | ||
where gs = fromString (show g) :: Value | ||
ss = fromString (show s) :: Value | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
flexBasis :: Size a -> Css | ||
flexBasis = key "flex-basis" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype FlexDirection = FlexDirection Value | ||
deriving (Val, Other) | ||
|
||
row, rowReverse, column, columnReverse :: FlexDirection | ||
|
||
row = FlexDirection "row" | ||
rowReverse = FlexDirection "row-reverse" | ||
column = FlexDirection "column" | ||
columnReverse = FlexDirection "column-reverse" | ||
|
||
flexDirection :: FlexDirection -> Css | ||
flexDirection = key "flex-direction" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
flexFlow :: FlexDirection -> FlexWrap -> Css | ||
flexFlow d w = key "flex-flow" (d ! w) | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
flexGrow :: Int -> Css | ||
flexGrow i = key "flex-grow" (fromString (show i) :: Value) | ||
|
||
flexShrink :: Int -> Css | ||
flexShrink i = key "flex-shrink" (fromString (show i) :: Value) | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype FlexWrap = FlexWrap Value | ||
deriving (Val, Other) | ||
|
||
nowrap, wrap, wrapReverse :: FlexWrap | ||
|
||
nowrap = FlexWrap "nowrap" | ||
wrap = FlexWrap "wrap" | ||
wrapReverse = FlexWrap "wrap-reverse" | ||
|
||
flexWrap :: FlexWrap -> Css | ||
flexWrap = key "flex-wrap" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype JustifyContentValue = JustifyContentValue Value | ||
deriving (Val, Other, Inherit, Center, FlexEnd | ||
, FlexStart, SpaceAround, SpaceBetween) | ||
|
||
justifyContent :: JustifyContentValue -> Css | ||
justifyContent = key "justify-content" | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
order :: Int -> Css | ||
order i = key "order" (fromString (show i) :: Value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters