Semantic-UI icon indicating copy to clipboard operation
Semantic-UI copied to clipboard

CSS Preprocessing

Open jlukic opened this issue 13 years ago • 79 comments

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.

jlukic avatar Oct 09 '13 05:10 jlukic

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 avatar Oct 09 '13 06:10 brigand

@brigand , CamelCase is better and more readable as it's so close to the Javascript style "We are JS lovers!"

elkebirmed avatar Oct 09 '13 09:10 elkebirmed

@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.

elkebirmed avatar Oct 09 '13 15:10 elkebirmed

@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 avatar Oct 09 '13 16:10 jlukic

@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.

brigand avatar Oct 09 '13 18:10 brigand

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

jlukic avatar Oct 09 '13 23:10 jlukic

SCSS doesn't have a JavaScript port, so we wouldn't be able to use it in the browser.

brigand avatar Oct 09 '13 23:10 brigand

:+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 avatar Oct 10 '13 00:10 Pym

@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 avatar Oct 10 '13 00:10 brigand

@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/

Pym avatar Oct 10 '13 00:10 Pym

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;
  }
}

jlukic avatar Oct 10 '13 00:10 jlukic

@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 avatar Oct 10 '13 00:10 brigand

@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 avatar Oct 10 '13 01:10 Pym

@Pym the builder works like this:

  1. Download the ZIP
  2. Extract the ZIP
  3. Join the .LESS files
  4. Add the users variables to the top
  5. Compile using the less.js parser
  6. 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.

brigand avatar Oct 10 '13 01:10 brigand

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 avatar Oct 10 '13 01:10 jlukic

@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 avatar Oct 10 '13 01:10 brigand

@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!

Pym avatar Oct 10 '13 01:10 Pym

@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.

jlukic avatar Oct 10 '13 01:10 jlukic

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.

brigand avatar Oct 10 '13 01:10 brigand

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

jlukic avatar Oct 10 '13 02:10 jlukic