css-class-bindings: generates Haskell bindings for CSS classes

[ bsd3, library, system ] [ Propose Tags ] [ Report a vulnerability ]

Motivation

Recently I migrated the vpn-router frontend to Miso, I noticed that DOM functions (e.g. div_) accept CSS class names as plain strings. This prevents GHC from catching typos in referenced names, even if stylesheets are correct and defined with clay.

Usage

The library leverages the power of TH to parse CSS snippets from quasi quotes or style files and to define Haskell constants for every class mentioned in the input.

Quasi-quote input

{-# LANGUAGE QuasiQuotes #-}
module Css where
import CssClassBindings ( css )

[css|
.foo-bar {
  color: #fc2c2c;
}
|]
module Main where

import Css (fooBar, cssAsLiteralText)
import CssClassBindings qualified as C
import Miso
import Miso.Html.Element (div_, button_)
import Miso.Html.Property qualified as P

class_ :: C.CssClass MisoString -> Attribute action
class_ = P.class_ . C.class_

app :: App Model Action
app = (component emptyModel updateModel viewModel)
  { styles = [ Style cssAsLiteralText ]
  }

viewModel :: Model -> View Model Action
viewModel m = div_ [] [ button_ [ class_ fooBar ] [ "Submit" ] ]

The library has been created to improve a miso-based app, but it does not depend on miso and it can be used in other setups.

fooBar :: IsString s => CssClass s
cssAsLiteralText :: IsString s => s

File input

{-# LANGUAGE TemplateHaskell #-}
module Css where
import CssClassBindings ( includeCss )

includeCss "assets/style.css"
module Main where

import Css (fooBar, style)
-- ...

Development environment

HLS should be available inside the default dev shell.

$ nix develop
$ emacs src/*/*/Qq.hs &
$ cabal build

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.2
Change log changelog.md
Dependencies base (>=4.7 && <5), containers (<1), css-syntax (<1), directory (<2), filepath (<2), template-haskell (<3), text (<3) [details]
Tested with ghc ==9.12.2
License BSD-3-Clause
Copyright Daniil Iaitkov 2026
Author Daniil Iaitskov
Maintainer dyaitskov@gmail.com
Uploaded by DaniilIaitskov at 2026-03-28T19:24:23Z
Category System
Home page http://github.com/yaitskov/css-class-bindings
Bug tracker https://github.com/yaitskov/css-class-bindings/issues
Source repo head: git clone https://github.com/yaitskov/css-class-bindings.git
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]