Skip to content

Commit 56fde10

Browse files
authored
Add outline and constituent properties. (Resolves #84, #85, #144.) (#145)
1 parent 9900cc3 commit 56fde10

File tree

10 files changed

+286
-54
lines changed

10 files changed

+286
-54
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: spago build --no-install --purs-args '--censor-lib --strict'
3434

3535
- name: Run tests
36-
run: spago test --no-install
36+
run: spago -x test.dhall test
3737

3838
- name: Check formatting
3939
run: purs-tidy check src test

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Breaking changes:
88
- Add support for `calc` expressions (#140 by @nsaunders)
99
- Add table selector (#141 by @plurip-software)
1010
- Update the box-shadow implementation (#88 by @vyorkin)
11+
- Add outline and constituent properties (#145 by @nsaunders)
1112

1213
New features:
1314
- Add smart constructors for generic font families (#68, #136 by @Unisay and @JordanMartinez)

spago.dhall

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
, "console"
66
, "effect"
77
, "either"
8-
, "exceptions"
98
, "exists"
109
, "foldable-traversable"
1110
, "maybe"
@@ -19,5 +18,5 @@
1918
, "tuples"
2019
]
2120
, packages = ./packages.dhall
22-
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
21+
, sources = [ "src/**/*.purs" ]
2322
}

src/CSS.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module CSS (module X) where
22

33
import CSS.Animation (AnimationDirection(..), AnimationName(..), FillMode(..), IterationCount(..), alternate, alternateReverse, animation, backwards, forwards, infinite, iterationCount, normalAnimationDirection, reverse) as X
44
import CSS.Background (class Background, class Loc, BackgroundAttachment, BackgroundClip, BackgroundImage, BackgroundOrigin, BackgroundPosition, BackgroundRepeat, BackgroundSize, Direction, Location, Side, angular, attachFixed, attachScroll, background, backgroundAttachment, backgroundAttachments, backgroundClip, backgroundClips, backgroundColor, backgroundImage, backgroundImages, backgroundOrigin, backgroundOrigins, backgroundPosition, backgroundPositions, backgroundRepeat, backgroundRepeats, backgroundSize, backgroundSizes, boxClip, by, contain, cover, location, noRepeat, origin, placed, positioned, repeat, repeatX, repeatY, round, sideBottom, sideCenter, sideLeft, sideMiddle, sideRight, sideTop, space, straight, url, xyRepeat) as X
5-
import CSS.Border (Stroke(..), border, borderBottom, borderColor, borderLeft, borderRadius, borderRight, borderSpacing, borderTop, dashed, dotted, double, groove, inset, outset, ridge, solid, wavy) as X
5+
import CSS.Border (Stroke(..), border, borderBottom, borderColor, borderLeft, borderRadius, borderRight, borderSpacing, borderTop, dashed, dotted, double, groove, inset, outline, outlineColor, outlineOffset, outlineStyle, outlineWidth, outset, ridge, solid, wavy) as X
66
import CSS.Box (BoxType, BoxShadow, borderBox, boxShadow, boxSizing, contentBox, paddingBox) as X
77
import CSS.Color (Color, ColorSpace(..), aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond, blue, blueviolet, brightness, brown, burlywood, cadetblue, chartreuse, chocolate, complementary, contrast, coral, cornflowerblue, cornsilk, crimson, cssStringHSLA, cssStringRGBA, cyan, darkblue, darkcyan, darken, darkgoldenrod, darkgray, darkgreen, darkgrey, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkslategrey, darkturquoise, darkviolet, deeppink, deepskyblue, desaturate, dimgray, dimgrey, distance, dodgerblue, firebrick, floralwhite, forestgreen, fromHexString, fromInt, fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, graytone, green, greenyellow, grey, honeydew, hotpink, hsl, hsla, indianred, indigo, isLight, isReadable, ivory, khaki, lab, lavender, lavenderblush, lawngreen, lch, lemonchiffon, lightblue, lightcoral, lightcyan, lighten, lightgoldenrodyellow, lightgray, lightgreen, lightgrey, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightslategrey, lightsteelblue, lightyellow, lime, limegreen, linen, luminance, magenta, maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, mix, moccasin, navajowhite, navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple, red, rgb, rgb', rgba, rgba', rosybrown, rotateHue, royalblue, saddlebrown, salmon, sandybrown, saturate, seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, slategrey, snow, springgreen, steelblue, tan, teal, textColor, thistle, toGray, toHSLA, toHexString, toLCh, toLab, toRGBA, toRGBA', toXYZ, tomato, turquoise, violet, wheat, white, whitesmoke, xyz, yellow, yellowgreen) as X
88
import CSS.Display (ClearFloat(..), Display(..), Float(..), Position(..), absolute, block, clear, clearBoth, clearInlineEnd, clearInlineStart, clearLeft, clearRight, display, displayInherit, displayNone, fixed, flex, float, floatLeft, floatRight, grid, inline, inlineBlock, inlineFlex, inlineGrid, inlineTable, listItem, position, relative, runIn, static, displayTable, tableCaption, tableCell, tableColumn, tableColumnGroup, tableFooterGroup, tableHeaderGroup, tableRow, tableRowGroup, zIndex, opacity) as X

src/CSS/Border.purs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1-
module CSS.Border where
1+
module CSS.Border
2+
(
3+
-- * Stroke type, used for border-style and outline-style.
4+
Stroke(..)
5+
, solid
6+
, dotted
7+
, dashed
8+
, double
9+
, wavy
10+
, groove
11+
, ridge
12+
, inset
13+
, outset
14+
15+
-- * Border properties.
16+
17+
, border
18+
, borderTop
19+
, borderLeft
20+
, borderBottom
21+
, borderRight
22+
, borderColor
23+
24+
-- * Outline properties.
25+
26+
, outline
27+
, outlineColor
28+
, outlineStyle
29+
, outlineWidth
30+
, outlineOffset
31+
32+
-- * Border radius.
33+
34+
, borderRadius
35+
36+
-- * Collapsing borders model for a table
37+
, borderSpacing
38+
) where
239

340
import Prelude
441

542
import CSS.Color (Color)
6-
import CSS.Property (class Val, Value)
43+
import CSS.Common (class Inherit, class Initial, class Unset)
44+
import CSS.Property (class Val, Value, (!))
745
import CSS.Size (Size, LengthUnit)
8-
import CSS.String (fromString)
46+
import CSS.String (class IsString, fromString)
947
import CSS.Stylesheet (CSS, key)
1048
import Data.Tuple (Tuple(..))
1149

@@ -14,9 +52,21 @@ newtype Stroke = Stroke Value
1452
derive instance eqStroke :: Eq Stroke
1553
derive instance ordStroke :: Ord Stroke
1654

55+
instance isStringStroke :: IsString Stroke where
56+
fromString = Stroke <<< fromString
57+
1758
instance valStroke :: Val Stroke where
1859
value (Stroke v) = v
1960

61+
instance inheritStroke :: Inherit Stroke where
62+
inherit = fromString "inherit"
63+
64+
instance initialStroke :: Initial Stroke where
65+
initial = fromString "initial"
66+
67+
instance unsetStroke :: Unset Stroke where
68+
unset = fromString "unset"
69+
2070
solid :: Stroke
2171
solid = Stroke $ fromString "solid"
2272

@@ -62,6 +112,25 @@ borderRight a b c = key (fromString "border-right") (Tuple a (Tuple b c))
62112
borderColor :: Color -> CSS
63113
borderColor = key $ fromString "border-color"
64114

115+
-------------------------------------------------------------------------------
116+
117+
outline :: Stroke -> Size LengthUnit -> Color -> CSS
118+
outline a b c = key (fromString "outline") (a ! b ! c)
119+
120+
outlineColor :: Color -> CSS
121+
outlineColor = key (fromString "outline-color")
122+
123+
outlineStyle :: Stroke -> CSS
124+
outlineStyle = key (fromString "outline-style")
125+
126+
outlineWidth :: Size LengthUnit -> CSS
127+
outlineWidth = key (fromString "outline-width")
128+
129+
outlineOffset :: Size LengthUnit -> CSS
130+
outlineOffset = key (fromString "outline-offset")
131+
132+
-------------------------------------------------------------------------------
133+
65134
borderRadius :: forall a. Size a -> Size a -> Size a -> Size a -> CSS
66135
borderRadius a b c d = key (fromString "border-radius") (Tuple (Tuple a b) (Tuple c d))
67136

src/CSS/Size.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module CSS.Size where
22

33
import Prelude
4-
import CSS.Common (class Auto, browsers)
4+
5+
import CSS.Common (class Auto, class Inherit, class Initial, class Unset, browsers)
56
import CSS.Property (class Val, Prefixed(Plain), Value(..), plain, value)
67
import CSS.String (class IsString, fromString)
78
import Data.Exists (Exists, mkExists, runExists)
@@ -39,6 +40,15 @@ instance valSize :: Val (Size a) where
3940
instance autoSize :: Auto (Size a) where
4041
auto = fromString "auto"
4142

43+
instance inheritSize :: Inherit (Size a) where
44+
inherit = fromString "inherit"
45+
46+
instance initialSize :: Initial (Size a) where
47+
initial = fromString "initial"
48+
49+
instance unsetSize :: Unset (Size a) where
50+
unset = fromString "unset"
51+
4252
-- | Zero size.
4353
nil :: forall a. Size a
4454
nil = BasicSize $ fromString "0"

test.dhall

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let conf = ./spago.dhall
2+
3+
in conf // {
4+
sources = conf.sources # ["test/**/*.purs"],
5+
dependencies = conf.dependencies # ["aff", "control", "exceptions", "partial", "spec"]
6+
}

test/CSS/BorderSpec.purs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
module CSS.BorderSpec where
2+
3+
import Prelude
4+
5+
import CSS.Border (dashed, dotted, double, groove, inset, outline, outlineColor, outlineOffset, outlineStyle, outlineWidth, ridge, solid)
6+
import CSS.Color (green)
7+
import CSS.Color as Color
8+
import CSS.Common (inherit, initial, unset)
9+
import CSS.Size (em, px)
10+
import Common (shouldRenderFrom)
11+
import Data.Maybe (fromJust)
12+
import Data.Traversable (traverse_)
13+
import Data.Tuple.Nested ((/\))
14+
import Partial.Unsafe (unsafePartial)
15+
import Test.Spec (Spec, describe)
16+
17+
spec :: Spec Unit
18+
spec = do
19+
20+
describe "outline (Mozilla examples)" $
21+
"outline: solid 3.0px hsl(120.0, 100.0%, 25.1%)" `shouldRenderFrom` outline solid (px 3.0) green
22+
23+
describe "outline-style (Mozilla examples)" do
24+
let testOutlineStyle (s /\ v) = ("outline-style: " <> s) `shouldRenderFrom` outlineStyle v
25+
describe "Keyword values" $
26+
traverse_
27+
testOutlineStyle
28+
[ "dotted" /\ dotted
29+
, "dashed" /\ dashed
30+
, "solid" /\ solid
31+
, "double" /\ double
32+
, "groove" /\ groove
33+
, "ridge" /\ ridge
34+
, "inset" /\ inset
35+
]
36+
describe "Global values" $
37+
traverse_
38+
testOutlineStyle
39+
[ "inherit" /\ inherit
40+
, "initial" /\ initial
41+
, "unset" /\ unset
42+
]
43+
44+
describe "outline-color (Mozilla examples)" $
45+
let
46+
testOutlineColor (s /\ v) = ("outline-color: " <> s) `shouldRenderFrom` outlineColor v
47+
in
48+
describe "<color> values" $
49+
traverse_
50+
testOutlineColor
51+
[ "hsl(0.0, 94.64%, 56.08%)" /\ (unsafePartial $ fromJust $ Color.fromHexString "#f92525")
52+
, "hsl(148.44, 76.19%, 49.41%)" /\ Color.rgb 30 222 121
53+
, "hsl(240.0, 100.0%, 50.0%)" /\ Color.blue
54+
]
55+
56+
describe "outline-width (Mozilla examples)" do
57+
let testOutlineWidth (s /\ v) = ("outline-width: " <> s) `shouldRenderFrom` outlineWidth v
58+
describe "<length> values" $
59+
traverse_
60+
testOutlineWidth
61+
[ "1.0px" /\ px 1.0
62+
, "0.1em" /\ em 0.1
63+
]
64+
describe "Global values" $
65+
traverse_
66+
testOutlineWidth
67+
[ "inherit" /\ inherit
68+
, "initial" /\ initial
69+
, "unset" /\ unset
70+
]
71+
72+
describe "outline-offset (Mozilla examples)" do
73+
let testOutlineOffset (s /\ v) = ("outline-offset: " <> s) `shouldRenderFrom` outlineOffset v
74+
describe "<length> values" $
75+
traverse_
76+
testOutlineOffset
77+
[ "3.0px" /\ px 3.0
78+
, "0.2em" /\ em 0.2
79+
]
80+
describe "Global values" $
81+
traverse_
82+
testOutlineOffset
83+
[ "inherit" /\ inherit
84+
, "initial" /\ initial
85+
, "unset" /\ unset
86+
]

test/Common.purs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Common where
2+
3+
import Prelude
4+
5+
import CSS (renderedInline)
6+
import CSS.Render (render, renderedSheet)
7+
import CSS.Stylesheet (CSS)
8+
import Control.Alt ((<|>))
9+
import Control.Monad.Error.Class (class MonadThrow)
10+
import Effect.Exception (Error)
11+
import Test.Spec (SpecT, it)
12+
import Test.Spec.Assertions (shouldEqual)
13+
14+
shouldRenderFrom
15+
:: forall g m
16+
. Monad m
17+
=> MonadThrow Error g
18+
=> String
19+
-> CSS
20+
-> SpecT g Unit m Unit
21+
shouldRenderFrom expected given =
22+
it ("renders " <> expected) $ expected `shouldRenderItFrom` given
23+
24+
shouldRenderItFrom
25+
:: forall m
26+
. MonadThrow Error m
27+
=> String
28+
-> CSS
29+
-> m Unit
30+
shouldRenderItFrom expected given =
31+
let
32+
r = render given
33+
actual = renderedInline r <|> renderedSheet r
34+
in
35+
actual `shouldEqual` pure expected

0 commit comments

Comments
 (0)