Skip to content

Commit a88ef45

Browse files
committed
Add cursor CSS property
1 parent f86824b commit a88ef45

File tree

4 files changed

+134
-19
lines changed

4 files changed

+134
-19
lines changed

src/CSS.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import CSS.Flexbox (class FlexEnd, class FlexStart, class SpaceAround, class Spa
1111
import CSS.FontFace (FontFaceFormat(..), FontFaceSrc(..), fontFaceFamily, fontFaceSrc, formatName) as X
1212
import CSS.Font (FontWeight(..), GenericFontFamily(..), bold, bolder, color, fontFamily, fontSize, fontWeight, lighter, sansSerif, weight) as X
1313
import CSS.FontStyle (FontStyle, fontStyle) as X
14+
import CSS.Cursor (Cursor(..), cursor) as X
1415
import CSS.Geometry (bottom, height, left, lineHeight, margin, marginBottom, marginLeft, marginRight, marginTop, maxHeight, maxWidth, minHeight, minWidth, padding, paddingBottom, paddingLeft, paddingRight, paddingTop, right, top, width) as X
1516
import CSS.Gradient (Extend, Radial, Ramp, circle, circular, closestCorner, closestSide, ellipse, elliptical, farthestCorner, farthestSide, hGradient, hRepeatingGradient, linearGradient, radialGradient, repeatingLinearGradient, repeatingRadialGradient, vGradient, vRepeatingGradient) as X
1617
import CSS.Property (class Val, Key(..), Literal(..), Prefixed(..), Value(..), cast, noCommas, plain, quote, value, (!)) as X

src/CSS/Common.purs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- | A bunch of type classes representing common values shared between multiple
2-
-- CSS properties, like `Auto`, `Inherit`, `None`, `Normal` and several more.
3-
--
4-
-- All the common value type classes have an instance for the Value type,
5-
-- making them easily derivable for custom value types.
2+
-- | CSS properties, like `Auto`, `Inherit`, `None`, `Normal` and several more.
3+
-- |
4+
-- | All the common value type classes have an instance for the `Value` type,
5+
-- | making them easily derivable for custom value types.
66

77
module CSS.Common where
88

@@ -12,8 +12,6 @@ import Data.Tuple (Tuple(..))
1212
import CSS.Property (Prefixed(..), Value)
1313
import CSS.String (class IsString, fromString)
1414

15-
-------------------------------------------------------------------------------
16-
1715
class All a where all :: a
1816
class Auto a where auto :: a
1917
class Baseline a where baseline :: a
@@ -31,10 +29,9 @@ class Bottom a where bottom :: a
3129
class URL a where url :: String -> a
3230

3331
-- | The other type class is used to escape from the type safety introduced by
34-
-- embedding CSS properties into the typed world of purescript-css.
35-
-- `Other` allows you to cast any `Value` to a specific value type.
36-
37-
class Other a where other :: Value -> a
32+
-- | embedding CSS properties into the typed world of purescript-css.
33+
-- | `Other` allows you to cast any `Value` to a specific value type.
34+
class Other a where other :: Value -> a
3835

3936
instance allValue :: All Value where all = fromString "all"
4037
instance autoValue :: Auto Value where auto = fromString "auto"
@@ -53,11 +50,8 @@ instance middleValue :: Middle Value where middle = fromString "middle"
5350
instance bottomValue :: Bottom Value where bottom = fromString "bottom"
5451
instance urlValue :: URL Value where url s = fromString ("url(\"" <> s <> "\")")
5552

56-
-------------------------------------------------------------------------------
57-
58-
-- | Common list browser prefixes to make experimental properties work in
59-
-- different browsers.
60-
53+
-- | Common list browser prefixes to make
54+
-- | experimental properties work in different browsers.
6155
browsers :: Prefixed
6256
browsers = Prefixed
6357
[ Tuple "-webkit-" ""
@@ -67,9 +61,6 @@ browsers = Prefixed
6761
, Tuple "" ""
6862
]
6963

70-
-------------------------------------------------------------------------------
71-
7264
-- | Syntax for CSS function call.
73-
7465
call :: forall s. IsString s => Monoid s => s -> s -> s
7566
call fn arg = fn <> fromString "(" <> arg <> fromString ")"

src/CSS/Cursor.purs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
module CSS.Cursor where
2+
3+
import Prelude
4+
5+
import CSS.Property (class Val, Value)
6+
import CSS.String (fromString)
7+
import CSS.Stylesheet (CSS, key)
8+
9+
newtype Cursor = Cursor Value
10+
11+
derive instance eqCursor :: Eq Cursor
12+
derive instance ordCursor :: Ord Cursor
13+
14+
instance valCursor :: Val Cursor where
15+
value (Cursor v) = v
16+
17+
cursor :: Cursor -> CSS
18+
cursor = key $ fromString "cursor"
19+
20+
default :: Cursor
21+
default = Cursor $ fromString "default"
22+
23+
help :: Cursor
24+
help = Cursor $ fromString "help"
25+
26+
pointer :: Cursor
27+
pointer = Cursor $ fromString "pointer"
28+
29+
progress :: Cursor
30+
progress = Cursor $ fromString "progress"
31+
32+
wait :: Cursor
33+
wait = Cursor $ fromString "wait"
34+
35+
cell :: Cursor
36+
cell = Cursor $ fromString "cell"
37+
38+
crosshair :: Cursor
39+
crosshair = Cursor $ fromString "crosshair"
40+
41+
text :: Cursor
42+
text = Cursor $ fromString "text"
43+
44+
verticalText :: Cursor
45+
verticalText = Cursor $ fromString "vertical-text"
46+
47+
alias :: Cursor
48+
alias = Cursor $ fromString "alias"
49+
50+
copy :: Cursor
51+
copy = Cursor $ fromString "copy"
52+
53+
move :: Cursor
54+
move = Cursor $ fromString "move"
55+
56+
noDrop :: Cursor
57+
noDrop = Cursor $ fromString "no-drop"
58+
59+
notAllowed :: Cursor
60+
notAllowed = Cursor $ fromString "not-allowed"
61+
62+
grab :: Cursor
63+
grab = Cursor $ fromString "grab"
64+
65+
grabbing :: Cursor
66+
grabbing = Cursor $ fromString "grabbing"
67+
68+
allScroll :: Cursor
69+
allScroll = Cursor $ fromString "all-scroll"
70+
71+
colResize :: Cursor
72+
colResize = Cursor $ fromString "col-resize"
73+
74+
rowResize :: Cursor
75+
rowResize = Cursor $ fromString "row-resize"
76+
77+
nResize :: Cursor
78+
nResize = Cursor $ fromString "n-resize"
79+
80+
eResize :: Cursor
81+
eResize = Cursor $ fromString "e-resize"
82+
83+
sResize :: Cursor
84+
sResize = Cursor $ fromString "s-resize"
85+
86+
wResize :: Cursor
87+
wResize = Cursor $ fromString "w-resize"
88+
89+
neResize :: Cursor
90+
neResize = Cursor $ fromString "ne-resize"
91+
92+
nwResize :: Cursor
93+
nwResize = Cursor $ fromString "nw-resize"
94+
95+
seResize :: Cursor
96+
seResize = Cursor $ fromString "se-resize"
97+
98+
swResize :: Cursor
99+
swResize = Cursor $ fromString "sw-resize"
100+
101+
ewResize :: Cursor
102+
ewResize = Cursor $ fromString "ew-resize"
103+
104+
nsResize :: Cursor
105+
nsResize = Cursor $ fromString "ns-resize"
106+
107+
neswResize :: Cursor
108+
neswResize = Cursor $ fromString "nesw-resize"
109+
110+
nwseResize :: Cursor
111+
nwseResize = Cursor $ fromString "nwse-resize"
112+
113+
zoomIn :: Cursor
114+
zoomIn = Cursor $ fromString "zoom-in"
115+
116+
zoomOut :: Cursor
117+
zoomOut = Cursor $ fromString "zoom-out"

test/Main.purs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import Prelude
44

55
import Effect (Effect)
66
import Effect.Exception (error, throwException)
7-
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, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity)
7+
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, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity, cursor)
88
import CSS.FontStyle as FontStyle
99
import CSS.Text.Overflow as TextOverflow
10+
import CSS.Cursor as Cursor
1011
import Data.Maybe (Maybe(..))
1112
import Data.NonEmpty (singleton)
1213

@@ -115,6 +116,10 @@ exampleTextOverflow2 :: Rendered
115116
exampleTextOverflow2 = render do
116117
textOverflow $ TextOverflow.custom "foobar"
117118

119+
exampleCursor :: Rendered
120+
exampleCursor = render do
121+
cursor Cursor.notAllowed
122+
118123
nestedNodes :: Rendered
119124
nestedNodes = render do
120125
fromString "#parent" ? do
@@ -171,3 +176,4 @@ main = do
171176
renderedSheet attrSpace `assertEqual` Just "p[foo~='bar'] { display: block }\n"
172177
renderedSheet attrHyph `assertEqual` Just "p[foo|='bar'] { display: block }\n"
173178

179+
renderedInline exampleCursor `assertEqual` Just "cursor: not-allowed"

0 commit comments

Comments
 (0)