Last active
October 25, 2019 12:24
-
-
Save mankyKitty/96d432dee9f80c368bbbb3be1ac6ba50 to your computer and use it in GitHub Desktop.
Type level BEM declarations because why not....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data CSS_BEM (block :: Symbol) = CSS_BEM | |
{ cssBEMBlock :: Text | |
, cssBEMElem :: Text -> Text | |
, cssBEMMod :: Text -> Text | |
, cssBEMElemMod :: Text -> Text -> Text | |
} | |
mkCSSBEM :: forall t. KnownSymbol t => CSS_BEM t | |
mkCSSBEM = CSS_BEM @t tb (mappend tb__) (mappend (tb <> "--")) (\e m -> tb__ <> e <> "--" <> m) | |
where | |
tb__ = tb <> "__" | |
tb = T.pack (symbolVal (Proxy @t)) | |
setupBEM :: CSS_BEM "setup" | |
setupBEM = mkCSSBEM | |
{- | |
*BEM> cssBEMElem setupBEM "wrapper" | |
"setup__wrapper" | |
*BEM> cssBEMMod setupBEM "hidden" | |
"setup--hidden" | |
*BEM> cssBEMElemMod setupBEM "wrapper" "hidden" | |
"setup__wrapper--hidden" | |
*BEM> cssBEMBlock setupBEM | |
"setup" | |
*BEM> | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment