Skip to content

Fix selector operators #78

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/CSS/Selector.purs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ element e = Selector (Refinement []) (Elem e)

deep :: Selector -> Selector -> Selector
deep a b = Selector (Refinement []) (Deep a b)
infix 0 deep as **
infix 6 deep as **

child :: Selector -> Selector -> Selector
child a b = Selector (Refinement []) (PathChild a b)
infix 0 child as |>
infix 6 child as |>

with :: Selector -> Refinement -> Selector
with (Selector (Refinement fs) e) (Refinement ps) = Selector (Refinement (fs <> ps)) e
infix 0 child as ##
infix 6 with as ##
23 changes: 22 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude

import Effect (Effect)
import Effect.Exception (error, throwException)
import CSS (Rendered, Path(..), Predicate(..), Refinement(..), Selector(..), FontFaceSrc(..), FontFaceFormat(..), renderedSheet, renderedInline, fromString, selector, block, display, render, borderBox, boxSizing, contentBox, blue, color, body, px, dashed, border, inlineBlock, red, (?), fontFaceSrc, zIndex)
import CSS (Rendered, Path(..), Predicate(..), Refinement(..), Selector(..), FontFaceSrc(..), FontFaceFormat(..), renderedSheet, renderedInline, fromString, selector, block, display, render, borderBox, boxSizing, contentBox, blue, color, body, a, p, px, dashed, border, inlineBlock, red, (?), (##), (|>), (**), hover, fontFaceSrc, zIndex)
import Data.Maybe (Maybe(..))
import Data.NonEmpty (singleton)

Expand Down Expand Up @@ -41,6 +41,23 @@ example7 :: Rendered
example7 = render do
zIndex 11

withSelector :: Rendered
withSelector = render do
a ? do
color blue
a ## hover ? do
color red

childSelector :: Rendered
childSelector = render do
p |> a ? do
zIndex 9

deepSelector :: Rendered
deepSelector = render do
p ** a ? do
display block

nestedNodes :: Rendered
nestedNodes = render do
fromString "#parent" ? do
Expand Down Expand Up @@ -69,6 +86,10 @@ main = do

renderedInline example5 `assertEqual` Just "box-sizing: content-box; box-sizing: border-box"

renderedSheet withSelector `assertEqual` Just "a { color: hsl(240.0, 100.0%, 50.0%) }\na:hover { color: hsl(0.0, 100.0%, 50.0%) }\n"
renderedSheet childSelector `assertEqual` Just "p > a { z-index: 9 }\n"
renderedSheet deepSelector `assertEqual` Just "p a { display: block }\n"

renderedSheet nestedNodes `assertEqual` Just "#parent { display: block }\n#parent #child { display: block }\n"

renderedSheet nestedNodesWithEmptyParent `assertEqual` Just "#parent #child { display: block }\n"
Expand Down