Skip to content

Complete PR 83 - Add Text Direction #137

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 4 commits into from
Sep 23, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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)

Bugfixes:

Expand Down
1 change: 1 addition & 0 deletions src/CSS.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CSS.Size (Abs, Angle(..), Deg, Rad, Rel, Size(..), deg, em, ex, nil, pct,
import CSS.String (class IsString, fromString) as X
import CSS.Stylesheet (App(..), CSS, Feature(..), Keyframes(..), MediaQuery(..), MediaType(..), NotOrOnly(..), Rule(..), StyleM(..), fontFace, importUrl, key, keyframes, keyframesFromTo, prefixed, query, rule, runS, select, (?)) as X
import CSS.Text (TextDecoration(..), blink, letterSpacing, lineThrough, noneTextDecoration, overline, textDecoration, underline) as X
import CSS.Text.Direction (TextDirection(..), direction) as X
import CSS.Text.Whitespace (TextWhitespace, textWhitespace, whitespaceNoWrap, whitespaceNormal, whitespacePre, whitespacePreLine, whitespacePreWrap) as X
import CSS.Text.Transform (TextTransform, textTransform) as X
import CSS.Text.Overflow (TextOverflow, textOverflow) as X
Expand Down
2 changes: 1 addition & 1 deletion src/CSS/Text.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ letterSpacing = key $ fromString "letter-spacing"
newtype TextDecoration = TextDecoration Value

derive instance eqTextDecoration :: Eq TextDecoration
derive instance ordTextDecoration:: Ord TextDecoration
derive instance ordTextDecoration :: Ord TextDecoration

instance valTextDecoration :: Val TextDecoration where
value (TextDecoration v) = v
Expand Down
24 changes: 24 additions & 0 deletions src/CSS/Text/Direction.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module CSS.Text.Direction where

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

data TextDirection = Ltr | Rtl

derive instance eqTextDirection :: Eq TextDirection
derive instance ordTextDirection :: Ord TextDirection

instance valTextDirection :: Val TextDirection where
value Ltr = fromString "ltr"
value Rtl = fromString "rtl"

direction :: TextDirection -> CSS
direction = key $ fromString "direction"

ltr :: TextDirection
ltr = Ltr

rtl :: TextDirection
rtl = Rtl
9 changes: 8 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import Prelude

import Effect (Effect)
import Effect.Exception (error, throwException)
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, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity, cursor, transform, transition, easeInOut, cubicBezier, ms)
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, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity, cursor, transform, transition, easeInOut, cubicBezier, ms, direction)
import CSS.Cursor as Cursor
import CSS.Flexbox (flex)
import CSS.FontStyle as FontStyle
import CSS.Text.Direction as TextDirection
import CSS.Text.Overflow as TextOverflow
import CSS.Transform as Transform
import Data.Maybe (Maybe(..))
Expand Down Expand Up @@ -132,6 +133,10 @@ exampleTextOverflow2 :: Rendered
exampleTextOverflow2 = render do
textOverflow $ TextOverflow.custom "foobar"

exampleDirection :: Rendered
exampleDirection = render do
direction TextDirection.rtl

exampleCursor :: Rendered
exampleCursor = render do
cursor Cursor.notAllowed
Expand Down Expand Up @@ -202,6 +207,8 @@ main = do
renderedSheet attrSpace `assertEqual` Just "p[foo~='bar'] { display: block }\n"
renderedSheet attrHyph `assertEqual` Just "p[foo|='bar'] { display: block }\n"

renderedInline exampleDirection `assertEqual` Just "direction: rtl"

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

renderedInline scaleTransform1 `assertEqual` Just "transform: scaleX(1.0); transform: scaleY(0.5); transform: scaleZ(0.5)"
Expand Down