sebastiaanvisser / clay

A CSS preprocessor as embedded Haskell.
Other
360 stars 73 forks source link

No instance for Monoid Refinement #167

Closed RamiroPastor closed 6 years ago

RamiroPastor commented 6 years ago

The code:

withPseudo :: String -> Refinement -> Css -> Css
withPseudo x y z =
  (byClass $ pack x) <> y & z

The error:

src/common/Tools/Css/Utils/Class.hs:22:3: error:
    • No instance for (Monoid Refinement) arising from a use of ‘<>’
    • In the first argument of ‘(&)’, namely ‘(byClass $ pack x) <> y’
      In the expression: (byClass $ pack x) <> y & z
      In an equation for ‘withPseudo’:
          withPseudo x y z = (byClass $ pack x) <> y & z
   |
22 |   (byClass $ pack x) <> y & z
   |   ^^^^^^^^^^^^^^^^^^^^^^^
RamiroPastor commented 6 years ago

Happens when importing only Clay, as well as when importing both Clay and Clay.Selector

dbaynard commented 6 years ago

See #53

Just to be clear, you can sort of achieve what you seem to want with

withPseudo :: String -> Refinement -> Css -> Css
withPseudo x y z =
  star # byClass (pack x) <> star # y <? z

or better,

withPseudo :: Text -> Refinement -> Css -> Css
withPseudo class ref z =
  foldMap (star #) [byClass class. ref] <? z

Depending on what you're doing, you may wish to throw in a pop 1 $ immediately before the foldMap.

RamiroPastor commented 6 years ago

I intended to do something like

withPseudo "some-class" (hover <> focus) $ do
  color red
  display inlineFlex

Simply because there seemed to be a Monoid instance for Refinement

RamiroPastor commented 6 years ago

Ok, i just learned to do this, so im closing the issue:

  fontColor       white
  backgroundColor footerCol
  hover & backgroundColor crimson