From 68d6b3b095eca8edd1fff2e4f61362757a64c695 Mon Sep 17 00:00:00 2001 From: Nick Saunders Date: Wed, 2 Mar 2022 06:00:59 -0700 Subject: [PATCH 1/2] Add support for visibility property. Resolves #146. --- CHANGELOG.md | 1 + src/CSS/Display.purs | 22 +++++++++++++++++++++- test/CSS/DisplaySpec.purs | 35 +++++++++++++++++++++++++++++++++++ test/Main.purs | 5 ++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 test/CSS/DisplaySpec.purs diff --git a/CHANGELOG.md b/CHANGELOG.md index 8752f69..1163130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/src/CSS/Display.purs b/src/CSS/Display.purs index 1f1ac4a..02bc19d 100644 --- a/src/CSS/Display.purs +++ b/src/CSS/Display.purs @@ -2,7 +2,7 @@ module CSS.Display where import Prelude -import CSS.Common (class Inherit, class None) +import CSS.Common (class Auto, 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) @@ -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 diff --git a/test/CSS/DisplaySpec.purs b/test/CSS/DisplaySpec.purs new file mode 100644 index 0000000..1b5d918 --- /dev/null +++ b/test/CSS/DisplaySpec.purs @@ -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 + ] diff --git a/test/Main.purs b/test/Main.purs index 55c4d93..8e54d79 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -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 @@ -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 From 60e7ac98b81accd6221b90e9175e43e24613accb Mon Sep 17 00:00:00 2001 From: Nick Saunders Date: Wed, 2 Mar 2022 15:58:19 -0700 Subject: [PATCH 2/2] Remove redundant import. --- src/CSS/Display.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CSS/Display.purs b/src/CSS/Display.purs index 02bc19d..1b6c661 100644 --- a/src/CSS/Display.purs +++ b/src/CSS/Display.purs @@ -2,7 +2,7 @@ module CSS.Display where import Prelude -import CSS.Common (class Auto, class Hidden, class Inherit, class Initial, class None, class Other, class Unset, class Visible) +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)