CSS Preprocessing
CSS Updates
Developing
LESS updates is a major feature for 1.0 and will be found in css branch.
Global Variables
- One global.less file will exist with global variables
- Primary Color
- Text Direction
- Secondary Color
- Page Background Color
- Positive / Negative Color
- Size Name Array -> EM
- Color Name Array -> Hex
- Default fonts (Header + Body)
- Base Font Size
- Link Color + Link State Colors
UI Variables
- Each file with variables will have a variable section at the top of the file
- Variables can either:
- Inherit value from global
- Have a specified value
- Use a color mix-in (lighten etc)
Other Pre-processing Features
- Add vendor prefixes mix-ins
- Add color mix-ins for hover,down state of colors when appropriate
NO NOs
- No plans to using whitespace significant rules. Standard CSS styles whenever possible.
- No use of mix-ins unless using to modify a color or vendor prefix or perform a critical calculation impossible any other way.
Should variables use-hyphens or camelCase?
@linkHover: red;
/* or */
@link-hover: red;
Also applies to namespacing, which less only offers support for in nested rules.
I ask because bootstrap had an issue where about half of the variables were camel and the other half hyphenated.
@brigand , CamelCase is better and more readable as it's so close to the Javascript style "We are JS lovers!"
@layoutDirection will be a LESS variable that has body { text-align: left; }
I know that this is a default property, but it's useful for cssjanus to flip it for RTL layout.
@brigand With regards to camel case, dashed case. I think both have their arguments.
Camelcase means that we can immediately recognize LESS variables as being different than css, since for semantic we're using lower case dashed words for css classes.
Alternatively using dashed case for variables means that it will fit in to the style of the rest of the code because everything else would be dashed words as well.
@jlukic personally I prefer camel, but it really doesn't matter. There just needs to be one documented correct way; and pull requests that use the other should be rejected.
So this has gone full circle. After spending the afternoon experimenting I realize that real loops are not and will not be available in LESS
See the creators comments https://github.com/less/less.js/issues/249#issuecomment-1138637
So i guess we either have to remove loops and create variables like @color1 @color1hex or we can use SCSS.
My buck is on swapping to SCSS/Compass. It looks like there's a lot of support, and honestly if we just use the good parts we can keep the preprocessing stuff simple so we can make adjustments in the future if we need to.
Control directives like each loops are pretty simple in SCSS http://codepen.io/jlukic/pen/Lziuw
SCSS doesn't have a JavaScript port, so we wouldn't be able to use it in the browser.
:+1: for camelCase
@jlukic where are you using loops in Semantic-UI right now?
@brigand I don't think it's a big deal.
@Pym, I was mostly referring to the customizer (#189); which needs to take the LESS; put new variables in; and compile. We'd have to change it to a server build tool, which well... requires our own server.
@brigand in that case, what about a "Preview/Edit on CodePen" button or something? (instead of generating previews ourselves)
EDIT: see http://blog.codepen.io/documentation/features/can-i-pre-fill-codepen-editors-with-code-i-send/
LESS would make the build tools much easier, since there is a direct javascript port for less. It would also make an inpage customizer with preview pretty badass for UI definitions.
BUT man do i hate some of the syntax
LESS loop (Requires color Count, variables declared separately, insanely retarded esoteric mixin syntax) http://codepen.io/jlukic/pen/fvojG
.createColor (@index,@selector) when (@index > 0) {
@class: ~'.ui.@{color@{index}}@{selector}';
@colorHex: ~'@{colorHex@{index}}';
@{class} {
color: @colorHex;
}
.createColor(@index - 1, @selector);
}
.createColor (0, @_) {}
SCSS loop http://codepen.io/jlukic/pen/Lziuw
@for $index from 1 through length($colors) {
$color: nth($colors, $index);
$colorHex: nth($colorHex, $index);
.ui.#{$color}.button {
color: $colorHex;
}
}
@Pym we're building a zip file so I don't think that really works. We'd have to set up a server, and depending on use it'd probably be about $15/mo.
It's not a terribly large amount of code to just write it out. Neither of those loops look good.
this
$colors: red blue green;
$colorHex: #AA3333 #33AA33 #3333AA;
@for $index from 1 through length($colors) {
$color: nth($colors, $index);
.ui.#{$color}.button {
color: nth($colors, $index);
}
}
or this:
@red: #AA3333;
@green: #33AA33;
@blue: #3333AA;
.ui.red.button {
color: @red;
}
.ui.green.button {
color: @green;
}
.ui.blue.button {
color: @blue;
}
How often are we really going to be changing the way colors work?
@brigand as @jlukic, I prefer the SCSS loop :)
But I still doesn't really know how much loops are used in Semantic-UI right now...
Anyway, if you plan to build a zip, you'll have to compile either with LESS or SCSS. So, why not compile also for the preview? I mean, is a "live" preview really necessary?
@Pym the builder works like this:
- Download the ZIP
- Extract the ZIP
- Join the .LESS files
- Add the users variables to the top
- Compile using the less.js parser
- Put the compiled file in the zip so the user can download it
Everything would be fine with SCSS except for steps 4 and 5. There's no way to compile SCSS in the browser currently.
Man looking at all these css preprocessors makes me want to write my own. They just seem like really lame versions of other templating languages with a few extra built-ins for understanding color manipulation.
I kind of feel like compiling all our css with handlebars instead. It can be parsed in the browser, and everyone knows it really well already.
Ideally the names of colors and other groups of variations should be user defined and have arbitrary length.
colors: {
blue: '#2c72b3',
turquoise: '#2cb38b'
}
sizes: {
minute: '0.0001em',
small: '0.5em',
medium: '1em'
}
So if i generate a palette i get to name my own colors and those colors are used throughout all UI elements with the names i've given them.
<div class="ui minute turquoise button"></div>
@jlukic that would kill portability of HTML. You should be able to change the stylesheet without losing styling. People can change gray to eggshell; but still call it gray.
Yeah, CSS processors are somewhat lame. Go for it!
@brigand I missed the JSZip part... I had no idea that you were planning to build the zip from the browser ;)
They just seem like really lame versions of other templating languages with a few extra built-ins for understanding color manipulation.
@jlukic I couldn't agree more!
@brigand I guess you're right. The issue though is most color palettes use similar colors. Just browse through Kuler
I guess in English color names are a pretty arbitrary anyways, so perhaps getting too serious about them in the library could be a fairly frustrating and fruitless task.
Maybe we should just limit the number of colors of elements to a reasonable amount and use ordinality.
Primary - Strongest brand color Secondary - Supplementary brand color
<div class="ui primary button"></div>
Then just migrate away from using named colors since they promote crazy rainbow sites anyways.
One option is to use other blue, etc. So if the user needs more colors, those can be included. If someone loads this element on their page (without extra colors), it just renders as a blue ui button
<div class="other blue ui button"></div>
That's require a much more complicated system (or a ton of code), which LESS doesn't really provide. Maybe 2.0.
Yeah, either way we're running into the same issue with loops not being great in LESS.
I think for 1.0 lets just go with named colors
pink
red
orange
blue
green
yellow
gold
silver
white
then
light gray
gray
dark gray