Skip to content

Commit b7d762c

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

File tree

4 files changed

+199
-19
lines changed

4 files changed

+199
-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: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
module CSS.Cursor where
2+
3+
import Prelude
4+
5+
import CSS.Property (class Val)
6+
import CSS.String (fromString)
7+
import CSS.Stylesheet (CSS, key)
8+
9+
data Cursor
10+
= Default
11+
| Help
12+
| Pointer
13+
| Progress
14+
| Wait
15+
| Cell
16+
| Crosshair
17+
| Text
18+
| VerticalText
19+
| Alias
20+
| Copy
21+
| Move
22+
| NoDrop
23+
| NotAllowed
24+
| Grab
25+
| Grabbing
26+
| AllScroll
27+
| ColResize
28+
| RowResize
29+
| NResize
30+
| EResize
31+
| SResize
32+
| WResize
33+
| NEResize
34+
| NWResize
35+
| SEResize
36+
| SWResize
37+
| EWResize
38+
| NSResize
39+
| NESWResize
40+
| NWSEResize
41+
| ZoomIn
42+
| ZoomOut
43+
44+
derive instance eqCursor :: Eq Cursor
45+
derive instance ordCursor :: Ord Cursor
46+
47+
instance valCursor :: Val Cursor where
48+
value Default = fromString "default"
49+
value Help = fromString "help"
50+
value Pointer = fromString "pointer"
51+
value Progress = fromString "progress"
52+
value Wait = fromString "wait"
53+
value Cell = fromString "cell"
54+
value Crosshair = fromString "crosshair"
55+
value Text = fromString "text"
56+
value VerticalText = fromString "vertical-text"
57+
value Alias = fromString "alias"
58+
value Copy = fromString "copy"
59+
value Move = fromString "move"
60+
value NoDrop = fromString "no-drop"
61+
value NotAllowed = fromString "not-allowed"
62+
value Grab = fromString "grab"
63+
value Grabbing = fromString "grabbing"
64+
value AllScroll = fromString "all-scroll"
65+
value ColResize = fromString "col-resize"
66+
value RowResize = fromString "row-resize"
67+
value NResize = fromString "n-resize"
68+
value EResize = fromString "e-resize"
69+
value SResize = fromString "s-resize"
70+
value WResize = fromString "w-resize"
71+
value NEResize = fromString "ne-resize"
72+
value NWResize = fromString "nw-resize"
73+
value SEResize = fromString "se-resize"
74+
value SWResize = fromString "sw-resize"
75+
value EWResize = fromString "ew-resize"
76+
value NSResize = fromString "ns-resize"
77+
value NESWResize = fromString "nesw-resize"
78+
value NWSEResize = fromString "nwse-resize"
79+
value ZoomIn = fromString "zoom-in"
80+
value ZoomOut = fromString "zoom-out"
81+
82+
cursor :: Cursor -> CSS
83+
cursor = key $ fromString "cursor"
84+
85+
default :: Cursor
86+
default = Default
87+
88+
help :: Cursor
89+
help = Help
90+
91+
pointer :: Cursor
92+
pointer = Pointer
93+
94+
progress :: Cursor
95+
progress = Progress
96+
97+
wait :: Cursor
98+
wait = Wait
99+
100+
cell :: Cursor
101+
cell = Cell
102+
103+
crosshair :: Cursor
104+
crosshair = Crosshair
105+
106+
text :: Cursor
107+
text = Text
108+
109+
verticalText :: Cursor
110+
verticalText = VerticalText
111+
112+
alias :: Cursor
113+
alias = Alias
114+
115+
copy :: Cursor
116+
copy = Copy
117+
118+
move :: Cursor
119+
move = Move
120+
121+
noDrop :: Cursor
122+
noDrop = NoDrop
123+
124+
notAllowed :: Cursor
125+
notAllowed = NotAllowed
126+
127+
grab :: Cursor
128+
grab = Grab
129+
130+
grabbing :: Cursor
131+
grabbing = Grabbing
132+
133+
allScroll :: Cursor
134+
allScroll = AllScroll
135+
136+
colResize :: Cursor
137+
colResize = ColResize
138+
139+
rowResize :: Cursor
140+
rowResize = RowResize
141+
142+
nResize :: Cursor
143+
nResize = NResize
144+
145+
eResize :: Cursor
146+
eResize = EResize
147+
148+
sResize :: Cursor
149+
sResize = SResize
150+
151+
wResize :: Cursor
152+
wResize = WResize
153+
154+
neResize :: Cursor
155+
neResize = NEResize
156+
157+
nwResize :: Cursor
158+
nwResize = NWResize
159+
160+
seResize :: Cursor
161+
seResize = SEResize
162+
163+
swResize :: Cursor
164+
swResize = SWResize
165+
166+
ewResize :: Cursor
167+
ewResize = EWResize
168+
169+
nsResize :: Cursor
170+
nsResize = NSResize
171+
172+
neswResize :: Cursor
173+
neswResize = NESWResize
174+
175+
nwseResize :: Cursor
176+
nwseResize = NWSEResize
177+
178+
zoomIn :: Cursor
179+
zoomIn = ZoomIn
180+
181+
zoomOut :: Cursor
182+
zoomOut = ZoomOut

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)