Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(theme): SASS-based themes #322

Merged
merged 10 commits into from
Oct 28, 2015
5,623 changes: 3,515 additions & 2,108 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"mocha-jsdom": "^1.0.0",
"mversion": "^1.10.1",
"nd": "^1.2.0",
"node-sass": "^3.3.3",
"nodemon": "^1.7.1",
"phantomjs": "^1.9.18",
"pretty-bytes": "^2.0.1",
Expand Down
9 changes: 7 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -ev # exit when error

ROOT=`dirname "$0"`/..

mkdir -p dist/themes

license="/*! instantsearch.js ${VERSION:-UNRELEASED} | © Algolia SAS | github.com/algolia/instantsearch.js */"
Expand All @@ -17,8 +19,11 @@ printf "\n\nBuild: minify"
cat dist/$bundle.js | uglifyjs -c warnings=false -m > dist/$bundle.min.js

printf "\n\nBuild: CSS"
cp themes/default.css dist/themes/default.css
cleancss dist/themes/default.css > dist/themes/default.min.css
for source in "$ROOT"/themes/[^_]*.sass; do
base=`basename "$source" .sass`
node-sass "$source" > dist/themes/$base.css
cleancss dist/themes/$base.css > dist/themes/$base.min.css
done

printf "\n\nBuild: prepend license"
printf "$license" | cat - dist/"$bundle".js > /tmp/out && mv /tmp/out dist/"$bundle".js
Expand Down
11 changes: 11 additions & 0 deletions themes/_base.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@mixin component($component)
.ais-#{$component}
@content

@mixin modifier($modifier)
&--#{$modifier}
@content

@mixin element($element)
&__#{$element}
@content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you use that?

Hmm, the goal of BEM is to not have to do any nesting. Sass can let you easily do a lot of nesting, but we should actually never nest more than 2 or 3 levels deep.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, the good thing it that is doesn't nest anything :) The nesting is just use to build the class names from the parent using that &-- and &__ syntax.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I did not know that syntax.

I'm not sure the end result in Sass will be any more readable than plain CSS, though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the end result in Sass will be any more readable than plain CSS, though :)

For me, no-brainer :)

/* REFINEMENT LIST */
.ais-refinement-list {
}
.ais-refinement-list--header {
  font-size: 1.2em;
}
.ais-refinement-list--body {
}
.ais-refinement-list--list {
}
.ais-refinement-list--item {
}
.ais-refinement-list--item__active {
  font-weight: bold;
}
.ais-refinement-list--label {
}
.ais-refinement-list--checkbox {
}
.ais-refinement-list--count {
  float: right;
  display: inline-block;
  background: black;
  color: white;
}
.ais-refinement-list--footer {
}

VS

// REFINEMENT LIST
+component(refinement-list)
  +modifier(header)
    font-size: 1.2em
  +modifier(body)
  +modifier(list)
  +modifier(item)
    +element(active)
       font-weight: bold
  +modifier(label)
  +modifier(checkbox)
  +modifier(count)
    float: right
    display: inline-block
    background: black
    color: white
  +modifier(footer)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my point exactly. I find the first one easier to read :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you can use the other mixin:

// REFINEMENT LIST
+bem(refinement-list, header)
  font-size: 1.2em
+bem(refinement-list, body)
+bem(refinement-list, list)
+bem(refinement-list, header)
+bem(refinement-list, item)
+bem(refinement-list, item, active)
     font-weight: bold
+bem(refinement-list, label)
+bem(refinement-list, checkbox)
+bem(refinement-list, count)
    float: right
    display: inline-block
    background: black
    color: white
+bem(refinement-list, footer)

253 changes: 0 additions & 253 deletions themes/default.css

This file was deleted.

Loading