Skip to content

Commit 79b2367

Browse files
committed
rules, declarations
1 parent a69713a commit 79b2367

5 files changed

Lines changed: 16 additions & 31 deletions

File tree

example/app/Main.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ tooltips = do
151151
css
152152
"tooltips"
153153
".tooltips:hover > .tooltip"
154-
[Declaration "visibility" "visible"]
154+
(declarations hidden)
155155

156156
red = HexColor "#F00"
157157

@@ -224,8 +224,8 @@ texts = col ~ gap 10 . pad 20 $ do
224224
-- el ~ bg Error . bg Warning ~ if True then bold else id $ "Warning"
225225

226226
el ~ pad 10 $ do
227-
el ~ descendentOf "htmx-request" flexRow . hide $ "Loading..."
228-
el ~ descendentOf "htmx-request" hide . flexRow $ "Normal Content"
227+
el ~ descendentOf "htmx-request" flexRow . display None $ "Loading..."
228+
el ~ descendentOf "htmx-request" (display None) . flexRow $ "Normal Content"
229229

230230
el ~ italic $ "Italic Text"
231231
el ~ underline $ "Underline Text"

src/Web/Atomic/CSS/Layout.hs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ left :: (Styleable h) => Length -> CSS h -> CSS h
196196
left l = utility ("left" -. l) ["left" :. style l]
197197

198198

199-
-- | Hide an element. See 'display'
200-
hide :: (Styleable h) => CSS h -> CSS h
201-
hide = display None
202-
203-
204199
data FlexDirection
205200
= Row
206201
| Column
@@ -270,10 +265,6 @@ visible :: (Styleable h) => CSS h -> CSS h
270265
visible = utility "hidden" ["visibility" :. "visible"]
271266

272267

273-
-- what if you set flex-shrink later?
274-
-- it has undefined behavior
275-
--
276-
277268
-- | Set to a specific width
278269
width :: (Styleable h) => Length -> CSS h -> CSS h
279270
width n =

src/Web/Atomic/Types/Rule.hs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,6 @@ ruleSelectorF rs =
139139
GeneratedRule _ f -> f
140140

141141

142-
-- where
143-
-- pseudos = mconcat . fmap pseudoSuffix
144-
145-
-- rulePseudo :: Rule -> [Pseudo]
146-
-- rulePseudo r =
147-
-- case r.selector of
148-
-- CustomRule _ -> []
149-
-- FromClass ps _ -> ps
150-
151142
ruleCustomSelector :: Rule -> Maybe Selector
152143
ruleCustomSelector r =
153144
case r.selector of

src/Web/Atomic/Types/Styleable.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ newtype CSS h = CSS {rules :: [Rule]}
4444
deriving newtype (Monoid, Semigroup)
4545

4646

47-
runCSS :: (CSS h -> CSS h) -> [Rule]
48-
runCSS f =
49-
let CSS rs = f mempty
50-
in rs
51-
52-
5347
mapRules :: (Rule -> Rule) -> CSS a -> CSS a
5448
mapRules f (CSS rs) = CSS $ fmap f rs
5549

@@ -70,5 +64,14 @@ utility cn ds (CSS rs) =
7064
CSS $ rule cn ds : rs
7165

7266

73-
test :: (Styleable h) => Int -> CSS h -> CSS h
74-
test n = utility "woot" ["key" :. style n]
67+
-- | Get all the rules for combined utilities
68+
rules :: (CSS [Rule] -> CSS [Rule]) -> [Rule]
69+
rules f =
70+
let CSS rs = f mempty
71+
in rs
72+
73+
74+
-- | Get all the declarations for a utility or combination of them
75+
declarations :: (CSS [Rule] -> CSS [Rule]) -> [Declaration]
76+
declarations f =
77+
mconcat $ fmap (.properties) (rules f)

test/Test/StyleSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ mainSpec :: Spec
1616
mainSpec = do
1717
describe "PropertyStyle" $ do
1818
it "should compile, and set both the className and styles" $ do
19-
let rs = runCSS @[Rule] $ list Decimal
19+
let rs = rules $ list Decimal
2020
length rs `shouldBe` 1
2121
[c] <- pure rs
2222
ruleClassName c `shouldBe` ClassName "list-decimal"
2323
ruleSelector c `shouldBe` ".list-decimal"
2424
c.properties `shouldBe` ["list-style-type" :. "decimal"]
2525

2626
it "should work with outside member None" $ do
27-
let rs = runCSS @[Rule] $ list None
27+
let rs = rules $ list None
2828
length rs `shouldBe` 1
2929
[c] <- pure rs
3030
ruleClassName c `shouldBe` ClassName "list-none"

0 commit comments

Comments
 (0)