Skip to content

Add cursor CSS property #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CSS.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CSS.Flexbox (class FlexEnd, class FlexStart, class SpaceAround, class Spa
import CSS.FontFace (FontFaceFormat(..), FontFaceSrc(..), fontFaceFamily, fontFaceSrc, formatName) as X
import CSS.Font (FontWeight(..), GenericFontFamily(..), bold, bolder, color, fontFamily, fontSize, fontWeight, lighter, sansSerif, weight) as X
import CSS.FontStyle (FontStyle, fontStyle) as X
import CSS.Cursor (Cursor, cursor) as X
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
import CSS.Gradient (Extend, Radial, Ramp, circle, circular, closestCorner, closestSide, ellipse, elliptical, farthestCorner, farthestSide, hGradient, hRepeatingGradient, linearGradient, radialGradient, repeatingLinearGradient, repeatingRadialGradient, vGradient, vRepeatingGradient) as X
import CSS.Property (class Val, Key(..), Literal(..), Prefixed(..), Value(..), cast, noCommas, plain, quote, value, (!)) as X
Expand Down
27 changes: 9 additions & 18 deletions src/CSS/Common.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- | A bunch of type classes representing common values shared between multiple
-- CSS properties, like `Auto`, `Inherit`, `None`, `Normal` and several more.
--
-- All the common value type classes have an instance for the Value type,
-- making them easily derivable for custom value types.
-- | CSS properties, like `Auto`, `Inherit`, `None`, `Normal` and several more.
-- |
-- | All the common value type classes have an instance for the `Value` type,
-- | making them easily derivable for custom value types.

module CSS.Common where

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

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

class All a where all :: a
class Auto a where auto :: a
class Baseline a where baseline :: a
Expand All @@ -31,10 +29,9 @@ class Bottom a where bottom :: a
class URL a where url :: String -> a

-- | The other type class is used to escape from the type safety introduced by
-- embedding CSS properties into the typed world of purescript-css.
-- `Other` allows you to cast any `Value` to a specific value type.

class Other a where other :: Value -> a
-- | embedding CSS properties into the typed world of purescript-css.
-- | `Other` allows you to cast any `Value` to a specific value type.
class Other a where other :: Value -> a

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

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

-- | Common list browser prefixes to make experimental properties work in
-- different browsers.

-- | Common list browser prefixes to make
-- | experimental properties work in different browsers.
browsers :: Prefixed
browsers = Prefixed
[ Tuple "-webkit-" ""
Expand All @@ -67,9 +61,6 @@ browsers = Prefixed
, Tuple "" ""
]

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

-- | Syntax for CSS function call.

call :: forall s. IsString s => Monoid s => s -> s -> s
call fn arg = fn <> fromString "(" <> arg <> fromString ")"
182 changes: 182 additions & 0 deletions src/CSS/Cursor.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
module CSS.Cursor where

import Prelude

import CSS.Property (class Val)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)

data Cursor
= Default
| Help
| Pointer
| Progress
| Wait
| Cell
| Crosshair
| Text
| VerticalText
| Alias
| Copy
| Move
| NoDrop
| NotAllowed
| Grab
| Grabbing
| AllScroll
| ColResize
| RowResize
| NResize
| EResize
| SResize
| WResize
| NEResize
| NWResize
| SEResize
| SWResize
| EWResize
| NSResize
| NESWResize
Copy link
Collaborator Author

@vyorkin vyorkin Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the best names, but that's how its named in CSS :)

| NWSEResize
| ZoomIn
| ZoomOut

derive instance eqCursor :: Eq Cursor
derive instance ordCursor :: Ord Cursor

instance valCursor :: Val Cursor where
value Default = fromString "default"
value Help = fromString "help"
value Pointer = fromString "pointer"
value Progress = fromString "progress"
value Wait = fromString "wait"
value Cell = fromString "cell"
value Crosshair = fromString "crosshair"
value Text = fromString "text"
value VerticalText = fromString "vertical-text"
value Alias = fromString "alias"
value Copy = fromString "copy"
value Move = fromString "move"
value NoDrop = fromString "no-drop"
value NotAllowed = fromString "not-allowed"
value Grab = fromString "grab"
value Grabbing = fromString "grabbing"
value AllScroll = fromString "all-scroll"
value ColResize = fromString "col-resize"
value RowResize = fromString "row-resize"
value NResize = fromString "n-resize"
value EResize = fromString "e-resize"
value SResize = fromString "s-resize"
value WResize = fromString "w-resize"
value NEResize = fromString "ne-resize"
value NWResize = fromString "nw-resize"
value SEResize = fromString "se-resize"
value SWResize = fromString "sw-resize"
value EWResize = fromString "ew-resize"
value NSResize = fromString "ns-resize"
value NESWResize = fromString "nesw-resize"
value NWSEResize = fromString "nwse-resize"
value ZoomIn = fromString "zoom-in"
value ZoomOut = fromString "zoom-out"

cursor :: Cursor -> CSS
cursor = key $ fromString "cursor"

default :: Cursor
default = Default

help :: Cursor
help = Help

pointer :: Cursor
pointer = Pointer

progress :: Cursor
progress = Progress

wait :: Cursor
wait = Wait

cell :: Cursor
cell = Cell

crosshair :: Cursor
crosshair = Crosshair

text :: Cursor
text = Text

verticalText :: Cursor
verticalText = VerticalText

alias :: Cursor
alias = Alias

copy :: Cursor
copy = Copy

move :: Cursor
move = Move

noDrop :: Cursor
noDrop = NoDrop

notAllowed :: Cursor
notAllowed = NotAllowed

grab :: Cursor
grab = Grab

grabbing :: Cursor
grabbing = Grabbing

allScroll :: Cursor
allScroll = AllScroll

colResize :: Cursor
colResize = ColResize

rowResize :: Cursor
rowResize = RowResize

nResize :: Cursor
nResize = NResize

eResize :: Cursor
eResize = EResize

sResize :: Cursor
sResize = SResize

wResize :: Cursor
wResize = WResize

neResize :: Cursor
neResize = NEResize

nwResize :: Cursor
nwResize = NWResize

seResize :: Cursor
seResize = SEResize

swResize :: Cursor
swResize = SWResize

ewResize :: Cursor
ewResize = EWResize

nsResize :: Cursor
nsResize = NSResize

neswResize :: Cursor
neswResize = NESWResize

nwseResize :: Cursor
nwseResize = NWSEResize

zoomIn :: Cursor
zoomIn = ZoomIn

zoomOut :: Cursor
zoomOut = ZoomOut
9 changes: 8 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Prelude

import Effect (Effect)
import Effect.Exception (error, throwException)
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, transform, transition, easeInOut, cubicBezier, ms)
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, transform, transition, easeInOut, cubicBezier, ms)
import CSS.Cursor as Cursor
import CSS.FontStyle as FontStyle
import CSS.Text.Overflow as TextOverflow
import CSS.Transform as Transform
Expand Down Expand Up @@ -126,6 +127,10 @@ exampleTextOverflow2 :: Rendered
exampleTextOverflow2 = render do
textOverflow $ TextOverflow.custom "foobar"

exampleCursor :: Rendered
exampleCursor = render do
cursor Cursor.notAllowed

nestedNodes :: Rendered
nestedNodes = render do
fromString "#parent" ? do
Expand Down Expand Up @@ -190,6 +195,8 @@ main = do
renderedSheet attrSpace `assertEqual` Just "p[foo~='bar'] { display: block }\n"
renderedSheet attrHyph `assertEqual` Just "p[foo|='bar'] { display: block }\n"

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

renderedInline scaleTransform1 `assertEqual` Just "transform: scaleX(1.0); transform: scaleY(0.5); transform: scaleZ(0.5)"
renderedInline scaleTransform2 `assertEqual` Just "transform: scale(0.2, 0.8)"

Expand Down