Skip to content

Commit 55e12a1

Browse files
committed
Add text direction
1 parent f86824b commit 55e12a1

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/CSS.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import CSS.Size (Abs, Angle(..), Deg, Rad, Rel, Size(..), deg, em, ex, nil, pct,
2121
import CSS.String (class IsString, fromString) as X
2222
import CSS.Stylesheet (App(..), CSS, Feature(..), Keyframes(..), MediaQuery(..), MediaType(..), NotOrOnly(..), Rule(..), StyleM(..), fontFace, importUrl, key, keyframes, keyframesFromTo, prefixed, query, rule, runS, select, (?)) as X
2323
import CSS.Text (TextDecoration(..), blink, letterSpacing, lineThrough, noneTextDecoration, overline, textDecoration, underline) as X
24+
import CSS.Text.Direction (TextDirection(..), direction) as X
2425
import CSS.Text.Whitespace (TextWhitespace, textWhitespace, whitespaceNoWrap, whitespaceNormal, whitespacePre, whitespacePreLine, whitespacePreWrap) as X
2526
import CSS.Text.Transform (TextTransform, textTransform) as X
2627
import CSS.Text.Overflow (TextOverflow, textOverflow) as X

src/CSS/Text.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ letterSpacing = key $ fromString "letter-spacing"
1212
newtype TextDecoration = TextDecoration Value
1313

1414
derive instance eqTextDecoration :: Eq TextDecoration
15-
derive instance ordTextDecoration:: Ord TextDecoration
15+
derive instance ordTextDecoration :: Ord TextDecoration
1616

1717
instance valTextDecoration :: Val TextDecoration where
1818
value (TextDecoration v) = v

src/CSS/Text/Direction.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module CSS.Text.Direction where
2+
3+
import Prelude
4+
import CSS.Property (class Val)
5+
import CSS.String (fromString)
6+
import CSS.Stylesheet (CSS, key)
7+
8+
data TextDirection = Ltr | Rtl
9+
10+
derive instance eqTextDirection :: Eq TextDirection
11+
derive instance ordTextDirection :: Ord TextDirection
12+
13+
instance valTextDirection :: Val TextDirection where
14+
value Ltr = fromString "ltr"
15+
value Rtl = fromString "rtl"
16+
17+
direction :: TextDirection -> CSS
18+
direction = key $ fromString "direction"
19+
20+
ltr :: TextDirection
21+
ltr = Ltr
22+
23+
rtl :: TextDirection
24+
rtl = Rtl

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, direction)
88
import CSS.FontStyle as FontStyle
99
import CSS.Text.Overflow as TextOverflow
10+
import CSS.Text.Direction as TextDirection
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+
exampleDirection :: Rendered
120+
exampleDirection = render do
121+
direction TextDirection.rtl
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 exampleDirection `assertEqual` Just "direction: rtl"

0 commit comments

Comments
 (0)