GithubHelp home page GithubHelp logo

dhruvbhatia / clojurescript-css-modules-demo Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 2.0 51 KB

An example of a reloadable Clojurescript workflow using CSS Modules

License: MIT License

CSS 8.99% JavaScript 50.63% Clojure 38.28% HTML 2.10%

clojurescript-css-modules-demo's Introduction

CSS Modules in ClojureScript

A sample ClojureScript project showcasing a workflow with live-reloadable CSS Modules using Gulp & Figwheel.

How It Works

The basic premise is as follows:

  1. A Gulp task watches and compiles your CSS Modules to JS.
    • Note: CSS Module namespaces to be exported are defined in src/clojurescript_css_modules_demo/css/settings.js.
  2. This JS file is hooked into your CLJS app through a foreign-lib named cssModules.
  3. Figwheel reloads your project whenever it detects changes to cssModules.
  4. This module is exposed to your CLJS project, allowing you to easily access the class names of your CSS Modules.
    • Note: a helper macro is provided for use with Reagent's hiccup-style syntax, but you can use this flow with any CLJS project.

Installation

Clone, npm install and gulp watch in one REPL. lein figwheel in another REPL. Change your .css modules within src/css/ and notice how Gulp/Figwheel live reload your project.

Note: Remember to change css/settings.js if you add additional CSS Module namespaces.

Usage With Reagent

At first - import CSS modules to project with foreign-libs. After it you can use aget to lookup and replace classes in Reagent templates with the correct css classes from your files.

For example: in filename.css we get CSS rule with selector .logo:

(defn my-component[]
	[:div { :class-name (aget js/cssModules "filename" "logo") }])

Syntax Sugar

There is a pretty syntax sugar inside demo:

(defn my-component[]
	(get-css 
		[:div.CSS>filename>logo]))

Which is equivalent to code above. Or you can use macro defcomponent which wraps your component function with get-css.

(defcomponent my-component[]
	[:div.CSS>filename>logo])

TODO:

  • Expand on this documentation!
  • Structure CSS Modules, add advanced examples.
  • Explore making this a standalone Clojure plugin (thereby removing the NodeJS/Gulp dependency).

Contributions welcome!

clojurescript-css-modules-demo's People

Contributors

dhruvbhatia avatar zefirka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

zefirka

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.