Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid Support #210

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
10ad518
Implement more of the Css grid spec
CharlesTaylor7 Jul 24, 2020
ec6e6a2
Set linux style line endings
CharlesTaylor7 Jul 24, 2020
cbac4f5
Tentative changelog
CharlesTaylor7 Jul 24, 2020
d70aa02
Wrap each row in quotes
CharlesTaylor7 Jul 24, 2020
4da0bd8
Restore gridGap, but deprecate it
CharlesTaylor7 Jul 24, 2020
56b89a8
Test gridTemplateAreas
CharlesTaylor7 Jul 25, 2020
414ea66
Remove deepseq dependency
CharlesTaylor7 Jul 25, 2020
b0dd86b
Formatting
CharlesTaylor7 Jul 25, 2020
298835a
Use smart constructor pattern
CharlesTaylor7 Jul 25, 2020
f8c3e2f
Allow keyword values for gridTemplateAreas
CharlesTaylor7 Jul 25, 2020
7ecce2d
Test stuff
CharlesTaylor7 Jul 25, 2020
afb5b6c
Test gridArea
CharlesTaylor7 Jul 25, 2020
21cf7a6
Mixed units in gridTemplateRows/gridTemplateColumns
CharlesTaylor7 Jul 26, 2020
6ff4864
Integer & keyword grid coordinates
CharlesTaylor7 Jul 26, 2020
c9d875a
Use Data.These to model GridLocation
CharlesTaylor7 Jul 26, 2020
1265b88
Fix a test
CharlesTaylor7 Jul 26, 2020
b381784
Use bi-directional pattern to simplify
CharlesTaylor7 Jul 26, 2020
21c7d41
Drop browser prefixes from calc
CharlesTaylor7 Jul 26, 2020
367fc84
update statistic
CharlesTaylor7 Jul 26, 2020
7c0568d
Implement minmax css function
CharlesTaylor7 Jul 26, 2020
59bc059
Use formal syntax name
CharlesTaylor7 Jul 26, 2020
ade2300
grid-auto-* properties
CharlesTaylor7 Jul 26, 2020
fbde8a8
fixup! Drop browser prefixes from calc
CharlesTaylor7 Jul 26, 2020
5d68bee
WIP - MinContent / MaxContent
CharlesTaylor7 Jul 26, 2020
c4c2c1d
grid-auto-rows & grid-auto-columns
CharlesTaylor7 Jul 26, 2020
07d665b
Document
CharlesTaylor7 Jul 26, 2020
57cf1b7
grid-auto-flow support
CharlesTaylor7 Jul 26, 2020
2a4bdb3
Include package version bound for these
CharlesTaylor7 Jul 26, 2020
0d44926
Add keyword size values
CharlesTaylor7 Jul 26, 2020
ee7746b
Fix failing test
CharlesTaylor7 Jul 26, 2020
f1f4485
Deal with warnings
CharlesTaylor7 Jul 26, 2020
2af5ae8
Minor changes
CharlesTaylor7 Jul 26, 2020
891b626
Make language pragmas consistent
CharlesTaylor7 Jul 27, 2020
1596848
Limit exports to necessary functionality
CharlesTaylor7 Jul 27, 2020
2737110
Undo version bump
CharlesTaylor7 Jul 29, 2020
8fd45d9
Delete gridGap
CharlesTaylor7 Jul 29, 2020
33fc6c7
Document gap, rowGap, & columnGap
CharlesTaylor7 Jul 29, 2020
8844e04
Update src/Clay/Grid.hs
CharlesTaylor7 Aug 1, 2020
b6d68df
Update src/Clay/Grid.hs
CharlesTaylor7 Aug 1, 2020
26eca85
Remove unnecessary coerce
CharlesTaylor7 Aug 1, 2020
945facd
Delete unused method
CharlesTaylor7 Aug 1, 2020
5d934b3
Update changelog
CharlesTaylor7 Jan 8, 2022
37ccb8a
Merge conflict
CharlesTaylor7 Jan 8, 2022
389e0cd
Include lower bound for these package
CharlesTaylor7 Jan 8, 2022
874a1f5
Handle underscores
CharlesTaylor7 Jan 8, 2022
561cdae
Rename type
CharlesTaylor7 Jan 8, 2022
da09a3e
Replace partial instance with a constructor
CharlesTaylor7 Jan 8, 2022
53a5bb8
Remove more partial instances
CharlesTaylor7 Jan 8, 2022
6cf06cd
Don't derive exception
CharlesTaylor7 Jan 8, 2022
5250c66
Fix typo
CharlesTaylor7 Jan 9, 2022
148bf30
Remove invalid keywords from GridAutoTrackList
CharlesTaylor7 Jan 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
22 changes: 21 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@ CHANGELOG
- Added `text-align-last`
- Fix typo in `stepsStart`
Thanks to Vasiliy Yorkin and Florian Grignon.

- 'Clay.Grid':
new properties:
gap: `gap` & `grid-gap`
rowGap: `row-gap` & `grid-row-gap`
columnGap: `column-gap` & `grid-column-gap`
gridArea: `grid-area`
gridAutoRows: `grid-auto-rows`
gridAutoColumns: `grid-auto-columns`
gridAutoFlow: `grid-auto-flow`
gridTemplateRows: `grid-template-rows`
gridTemplateColumns: `grid-template-columns`
gridTemplateAreas: `grid-template-areas`
- 'Clay.Size':
AnyUnit, a size parameter for lists of mixed units
minmax :: Size a -> Size a -> Size AnyUnit
remove `available`, `normal`: not valid css sizes
include `initial`, `unset` keyword values
upgrade `fitContent` from value to function, it's not valid without an argument:
https://drafts.csswg.org/css-sizing-3/#valdef-width-fit-content-length-percentage
minContent & maxContent are now type class overloaded values

0.13.3:
- Improve README
- Relax types for `sym2` and `sym3` combinators
Expand Down
6 changes: 4 additions & 2 deletions clay.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Library
Clay.FontFace
Clay.Geometry
Clay.Gradient
Clay.Grid
Clay.Grid
Clay.List
Clay.Media
Clay.Mask
Expand All @@ -75,7 +75,8 @@ Library
Build-Depends:
base >= 4.11 && < 5,
mtl >= 1 && < 2.3,
text >= 0.11 && < 1.3
text >= 0.11 && < 1.3,
these >= 0.2 && < 1.2
GHC-Options: -Wall -Wcompat

Test-Suite Test-Clay
Expand All @@ -87,6 +88,7 @@ Test-Suite Test-Clay
base >= 4.11 && < 5,
mtl >= 1 && < 2.3,
text >= 0.11 && < 1.3,
these >= 0.2 && < 1.2,
hspec >= 2.2.0 && < 2.8,
hspec-discover >= 2.2.0 && < 2.8
GHC-Options: -Wall -Wcompat
6 changes: 3 additions & 3 deletions nix/clay.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text }:
{ mkDerivation, base, hspec, hspec-discover, mtl, stdenv, lib, text, these }:
mkDerivation {
pname = "clay";
version = "0.14.0";
src = ./..;
libraryHaskellDepends = [ base mtl text ];
testHaskellDepends = [ base hspec hspec-discover mtl text ];
libraryHaskellDepends = [ base mtl text these ];
testHaskellDepends = [ base hspec hspec-discover mtl text these ];
homepage = "http://fvisser.nl/clay";
description = "CSS preprocessor as embedded Haskell";
license = lib.licenses.bsd3;
Expand Down
165 changes: 165 additions & 0 deletions spec/Clay/GridSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}
module Clay.GridSpec where

import Test.Hspec
import Common
import Clay
import Data.These (These (..))


spec :: Spec
spec = do
describe "gap" $ do
"{gap:10px;grid-gap:10px}"
`shouldRenderFrom`
gap (px 10)

describe "rowGap" $ do
"{row-gap:5px;grid-row-gap:5px}"
`shouldRenderFrom`
rowGap (px 5)

describe "columnGap" $ do
"{column-gap:1em;grid-column-gap:1em}"
`shouldRenderFrom`
columnGap (em 1)

describe "gridTemplateRows" $ do
describe "keyword" $ do
"{grid-template-rows:none}"
`shouldRenderFrom`
gridTemplateRows none

describe "list of sizes" $ do
"{grid-template-rows:50px fit-content(500px) minmax(400em,50%)}"
`shouldRenderFrom`
gridTemplateRows [upcast (px 50), upcast $ fitContent (px 500), minmax (em 400) (pct 50)]

describe "gridTemplateColumns" $ do
describe "keyword" $ do
"{grid-template-columns:none}"
`shouldRenderFrom`
gridTemplateColumns none

describe "list of sizes" $ do
"{grid-template-columns:1em calc(20% + 1fr) auto}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the grid spec:

Note: <flex> values are not <length>s (nor are they compatible with <length>s, like some <percentage> values), so they cannot be represented in or combined with other unit types in calc() expressions.

`shouldRenderFrom`
gridTemplateColumns [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto]

describe "gridAutoRows" $ do
describe "keywords" $ do
"{grid-auto-rows:min-content}"
`shouldRenderFrom`
gridAutoRows minContent

"{grid-auto-rows:max-content}"
`shouldRenderFrom`
gridAutoRows maxContent

describe "list of sizes" $ do
"{grid-auto-rows:1em calc(20% + 1fr) auto}"
`shouldRenderFrom`
gridAutoRows [upcast $ em 1, pct 20 @+@ fr 1, upcast $ auto]

describe "gridAutoFlow" $ do
"{grid-auto-flow:row}"
`shouldRenderFrom`
gridAutoFlow row

"{grid-auto-flow:column}"
`shouldRenderFrom`
gridAutoFlow column

"{grid-auto-flow:dense}"
`shouldRenderFrom`
gridAutoFlow dense

"{grid-auto-flow:row dense}"
`shouldRenderFrom`
gridAutoFlow rowDense

"{grid-auto-flow:column dense}"
`shouldRenderFrom`
gridAutoFlow columnDense

describe "gridArea" $ do
"{grid-area:header}"
`shouldRenderFrom`
gridArea "header"

describe "grid coordinate properties" $ do

"{grid-row-start:3}"
`shouldRenderFrom`
gridRowStart 3

"{grid-row-end:-2}"
`shouldRenderFrom`
gridRowEnd (-2)

"{grid-column-start:span nav}"
`shouldRenderFrom`
gridColumnStart $ gridLocation Span (That "nav")

"{grid-column-end:3 footer}"
`shouldRenderFrom`
gridColumnEnd $ gridLocation NoSpan (These 3 "footer")


describe "gridTemplateAreas" $ do
describe "keyword values" $ do
"{grid-template-areas:none}"
`shouldRenderFrom`
gridTemplateAreas none

"{grid-template-areas:inherit}"
`shouldRenderFrom`
gridTemplateAreas inherit

"{grid-template-areas:initial}"
`shouldRenderFrom`
gridTemplateAreas initial

"{grid-template-areas:unset}"
`shouldRenderFrom`
gridTemplateAreas unset

describe "mozilla example" $ do
let
area_a = "a"
area_b = "b"
area_c = "c"
area_blank = blankGridArea

"{grid-template-areas:\"a a .\"\n\"a a .\"\n\". b c\"}"
`shouldRenderFrom`
gridTemplateAreas
[ [ area_a, area_a, area_blank]
, [ area_a, area_a, area_blank]
, [ area_blank, area_b, area_c]
]
describe "non rectangular template areas should error" $ do
let
area_a = "a"
area_b = "b"
area_c = "c"
area_blank = blankGridArea

InvalidGridTemplateNotRectangular
`shouldErrorFromRender`
gridTemplateAreas
[ [ area_blank] -- length 1
, [ area_a, area_blank] -- length 2
, [ area_blank, area_b, area_c] -- length 3
]

describe "empty template should error" $ do
InvalidGridTemplateEmpty
`shouldErrorFromRender`
gridTemplateAreas []

describe "template with empty row(s) should error" $ do
InvalidGridTemplateEmptyRow
`shouldErrorFromRender`
gridTemplateAreas [[], []]
11 changes: 2 additions & 9 deletions spec/Clay/SizeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import Data.List
sizeRepr :: Size a -> Text
sizeRepr = plain . unValue . value

hasAllPrefixes :: Val a => a -> Bool
hasAllPrefixes a = checkPrefixed ((unValue . value) a) browsers
where checkPrefixed (Prefixed pa) (Prefixed pb) = sort (fmap fst pa) == sort (fmap fst pb)
checkPrefixed _ _ = False

compactRender :: Css -> Text
compactRender css = toStrict $ renderWith compact [] css

Expand All @@ -31,8 +26,8 @@ spec = do
describe "render results" $ do
it "marginLeft auto" $
(compactRender $ marginLeft auto) `shouldBe` "{margin-left:auto}"
it "marginLeft normal" $
(compactRender $ marginLeft normal) `shouldBe` "{margin-left:normal}"
it "marginLeft initial" $
(compactRender $ marginLeft initial) `shouldBe` "{margin-left:initial}"
it "marginLeft inherit" $
(compactRender $ marginLeft inherit) `shouldBe` "{margin-left:inherit}"
it "marginLeft none" $
Expand All @@ -47,8 +42,6 @@ spec = do
sizeRepr (em 2 @+@ px 1) `shouldBe` "calc(2em + 1px)"
it "returns calc for nested sum" $
sizeRepr (em 2 @+@ pt 1 @+@ px 3) `shouldBe` "calc((2em + 1pt) + 3px)"
it "returns prefixed calc for simple sum" $
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

(em 2 @+@ pt 2) `shouldSatisfy` hasAllPrefixes
it "return calc for sum of different types" $
sizeRepr (em 2 @+@ pct 10) `shouldBe` "calc(2em + 10%)"
it "returns calc for simple difference" $
Expand Down
22 changes: 20 additions & 2 deletions spec/Common.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
module Common where
module Common
( shouldRenderFrom
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to filter the exports. Or was there a name clash?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No name clash. I introduced a new top level binding of testRender & was preventing its export. It's not a big deal either way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'm fine if you don't restrict the exports in that case.

, shouldRenderAsFrom
, shouldRenderItFrom
, shouldErrorFromRender
)
where

import Test.Hspec
import Clay
import Data.Text.Lazy (Text, unpack)
import Control.Exception (Exception(..), evaluate)


shouldRenderFrom :: Text -> Css -> SpecWith ()
shouldRenderFrom txt css =
Expand All @@ -15,5 +23,15 @@ shouldRenderAsFrom des txt css =
infixr 3 `shouldRenderAsFrom`

shouldRenderItFrom :: Text -> Css -> Expectation
shouldRenderItFrom = flip $ shouldBe . renderWith compact []
shouldRenderItFrom = flip $ shouldBe . testRender
infixr 0 `shouldRenderItFrom`

testRender :: Css -> Text
testRender = renderWith compact []

shouldErrorFromRender :: (Exception e, Eq e) => e -> Css -> SpecWith ()
shouldErrorFromRender exception css = do
let errorMsg = show exception
let rendered = evaluate $! testRender css
it ("throws " <> errorMsg) $
(rendered `shouldThrow` (== exception))
64 changes: 40 additions & 24 deletions src/Clay/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ import Data.String (IsString)

-------------------------------------------------------------------------------

class All a where all :: a
class Auto a where auto :: a
class Baseline a where baseline :: a
class Center a where center :: a
class Inherit a where inherit :: a
class None a where none :: a
class Normal a where normal :: a
class Visible a where visible :: a
class Hidden a where hidden :: a
class Initial a where initial :: a
class Unset a where unset :: a
class All a where all :: a
class Auto a where auto :: a
class Baseline a where baseline :: a
class Center a where center :: a
class Inherit a where inherit :: a
class None a where none :: a
class Normal a where normal :: a
class Visible a where visible :: a
class Hidden a where hidden :: a
class Initial a where initial :: a
class Unset a where unset :: a
class MinContent a where minContent :: a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that some other types than Value will also be instances of your new classes?

class MaxContent a where maxContent :: a
class Row a where row :: a
class Column a where column :: a

-- | The other type class is used to escape from the type safety introduced by
-- embedding CSS properties into the typed world of Clay. `Other` allows you to
Expand Down Expand Up @@ -55,19 +59,31 @@ initialValue :: Value
initialValue = "initial"
unsetValue :: Value
unsetValue = "unset"

instance All Value where all = allValue
instance Auto Value where auto = autoValue
instance Baseline Value where baseline = baselineValue
instance Center Value where center = centerValue
instance Inherit Value where inherit = inheritValue
instance Normal Value where normal = normalValue
instance None Value where none = noneValue
instance Visible Value where visible = visibleValue
instance Hidden Value where hidden = hiddenValue
instance Other Value where other = id
instance Initial Value where initial = initialValue
instance Unset Value where unset = unsetValue
minContentValue :: Value
minContentValue = "min-content"
maxContentValue :: Value
maxContentValue = "max-content"
rowValue :: Value
rowValue = "row"
columnValue :: Value
columnValue = "column"

instance All Value where all = allValue
instance Auto Value where auto = autoValue
instance Baseline Value where baseline = baselineValue
instance Center Value where center = centerValue
instance Inherit Value where inherit = inheritValue
instance Normal Value where normal = normalValue
instance None Value where none = noneValue
instance Visible Value where visible = visibleValue
instance Hidden Value where hidden = hiddenValue
instance Other Value where other = id
instance Initial Value where initial = initialValue
instance Unset Value where unset = unsetValue
instance MinContent Value where minContent = minContentValue
instance MaxContent Value where maxContent = maxContentValue
instance Row Value where row = rowValue
instance Column Value where column = columnValue

-------------------------------------------------------------------------------

Expand Down
Loading