Skip to content

Commit

Permalink
Add support for visibility property. Resolves #146. (#148)
Browse files Browse the repository at this point in the history
* Add support for visibility property. Resolves #146.

* Remove redundant import.
  • Loading branch information
nsaunders committed Mar 3, 2022
1 parent 56fde10 commit 975f884
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Breaking changes:
New features:
- Add smart constructors for generic font families (#68, #136 by @Unisay and @JordanMartinez)
- Add support for `text-direction` (#83, #137 by @vyorkin and @JordanMartinez)
- Add support for `visibility` property (#148 by @nsaunders)

Bugfixes:

Expand Down
22 changes: 21 additions & 1 deletion src/CSS/Display.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CSS.Display where

import Prelude

import CSS.Common (class Inherit, class None)
import CSS.Common (class Hidden, class Inherit, class Initial, class None, class Other, class Unset, class Visible)
import CSS.Property (class Val, Value)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)
Expand Down Expand Up @@ -186,5 +186,25 @@ clear = key (fromString "clear")
opacity :: Number -> CSS
opacity = key $ fromString "opacity"

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

newtype Visibility = Visibility Value

derive newtype instance Val Visibility
derive newtype instance Other Visibility
derive newtype instance Inherit Visibility
derive newtype instance Initial Visibility
derive newtype instance Unset Visibility
derive newtype instance Hidden Visibility
derive newtype instance Visible Visibility

collapse :: Visibility
collapse = Visibility $ fromString "collapse"

visibility :: Visibility -> CSS
visibility = key $ fromString "visibility"

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

zIndex :: Int -> CSS
zIndex = key (fromString "z-index") <<< show
35 changes: 35 additions & 0 deletions test/CSS/DisplaySpec.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module CSS.DisplaySpec where

import Prelude

import CSS.Color (green)
import CSS.Color as Color
import CSS.Common (hidden, inherit, initial, unset, visible)
import CSS.Display (collapse, visibility)
import CSS.Size (em, px)
import Common (shouldRenderFrom)
import Data.Maybe (fromJust)
import Data.Traversable (traverse_)
import Data.Tuple.Nested ((/\))
import Partial.Unsafe (unsafePartial)
import Test.Spec (Spec, describe)

spec :: Spec Unit
spec = do

describe "visibility (Mozilla examples)" do
let testVisibility (s /\ v) = ("visibility: " <> s) `shouldRenderFrom` visibility v
describe "Keyword values" $
traverse_
testVisibility
[ "visible" /\ visible
, "hidden" /\ hidden
, "collapse" /\ collapse
]
describe "Global values" $
traverse_
testVisibility
[ "inherit" /\ inherit
, "initial" /\ initial
, "unset" /\ unset
]
5 changes: 4 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Prelude

import CSS (Rendered, Path(..), Predicate(..), Refinement(..), Selector(..), FontFaceSrc(..), FontFaceFormat(..), pct, renderedSheet, renderedInline, fromString, selector, block, display, render, borderBox, boxSizing, contentBox, blue, color, body, a, p, px, dashed, border, inlineBlock, red, gold, teal, olive, black, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, rgba, zIndex, textOverflow, opacity, cursor, transform, transition, easeInOut, cubicBezier, ms, direction, width, em, (@+@), (@-@), (@*), (*@), (@/))
import CSS.BorderSpec as BorderSpec
import CSS.DisplaySpec as DisplaySpec
import CSS.Cursor as Cursor
import CSS.Flexbox (flex)
import CSS.FontStyle as FontStyle
Expand Down Expand Up @@ -291,4 +292,6 @@ main = do
log $ "\x1b[32m" <> show count <> " test" <> if count == 1 then "" else "s" <> " passed. These will be migrated to the new format in the future.\x1b[0m\n"

launchAff_ $
runSpec [ consoleReporter ] BorderSpec.spec
runSpec [ consoleReporter ] do
BorderSpec.spec
DisplaySpec.spec

0 comments on commit 975f884

Please sign in to comment.