0.2.0 • Published 8 years ago

toolbox-css v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

toolbox.scss

toolbox.scss provides a number of utility classes and mixins. It's an unopinionated library meant to save you time when starting new projects, and is best used in conjunction with another CSS framework or writing methodology.

How do I get it?

If you're using npm:

npm install toolbox-css

Then include the toolbox.scss file from within the node-modules directory. Don't forget to edit the toolbox-config file for your needs. Its in the same directory.

Otherwise download and include toolbox.scss and toolbox-config.scss in your project. Modify the config to your liking, by following the information in the comments or in the guide below. If you're not using Sass, just download toolbox.css - a CSS compiled version of the library using default settings. It should be fine for most projects.

Toolbox does

  • Offer many common utility classes.
  • Simplify responsive design.
  • Promote simple selectors and performant CSS.

Toolbox doesn't

  • Add vendor prefixes. Use tools like Autoprefixer to achieve cross-browser compatibility.
  • Style common components such as buttons, inputs or navigation.
  • Make assumptions about the layout of the your page.

What's the point?

Often I've found that I need to create new classes to apply a single, often common style to an element. Or worse I've seen people try to just use whatever they have available to style very nested elements, resulting in things like .component > div span:nth-child(2), this is both inefficient and very dependent on the HTML structure. The best solution I've found is using simple utility methods for common properties and values, but it's tedious to write all of them, every time you begin a new project, and here are we.

toolbox provides some of the most common properties and values, described with sane names, and mixins that work in unison with a config file to suit every project's need.

The config file

At the heart of toolbox, lies the config. A file consisting of only commented variables, with some sensible defaults in case you don't care much about customizing the library. The settings are divided in categories, and comments in the source code describe their functionality, however let's go over them in more detail here.

General

PropertyParameterDefaultDescription
namespaceAny valid selector or nullnullA namespace to apply to all classes from the library.
short-namestrue, falsefalseWhether the class names should use their short variant. For example .absolute or .abs.
dashed-namestrue, falsetrueWhether to include the - character in class names. For example .float-left or .floatleft.
prefixnull or stringnullA prefix to prepend to all class names. For example .pre-relative.
suffixnull or stringnullA suffix to append to all class names. For example .relative-suf.
visualize-errorstrue, falsetrueWhether to show toolbox errors as a pseudo element in the HTML or not.

Media queries

PropertyParameterDefaultDescription
breakpointsA map of key: value pairs(large, 1235px, medium: 1024px, small: 768px, mobile: 320px)The described list will be used in conjunction with the breakpoint mixin, to easily create @media rules.
breakpoint-offsetinteger0A pixel value offset to account for any static content.

Dimensions

PropertyParameterDefaultDescription
padding-iteratorinteger10The offset between two padding classes.
padding-mininteger10The minimum padding class value.
padding-maxinteger50The maximum padding class value.
margin-iteratorinteger10The offset between two margin classes.
margin-mininteger10The minimum margin class value.
margin-maxinteger50The maximum margin class value.

Text

PropertyParameterDefaultDescription
font-sizesA list of (key, value) pairs('base', 16)Used to generate font-size classes. For instance .base-font { font-size: 16px; font-size: 1.6rems; }
rem-friendlytrue, falsetrueWhether to try and set the values to rem units. Note that this will add some styling to the html and body elements.

Colors

PropertyParameterDefaultDescription
colorsA list of (key, value) pairs('white', #fff), ('black', #000)Used to generate color classes.
background-color-classestrue, falsetrueWhether to generate color classes for background-color. For instance .white-background { background-color: #fff; }.
text-color-classestrue, falsefalseWhether to generate color classes for color. For instance .white-text { color: #fff; }.
border-color-classestrue, falsefalseWhether to generate color classes for border-color. For instance .white-borders { border-color: #fff; }.

Classes

The classes are all generated through a Sass compiler, based on the settings in your config. While some have static names, others are more dynamic, usually using keywords or even numeric values, denoted below with #. If you want to define your own class, which will be treated with the same manipulations from the config file, use the class mixin like so:

@include class('long-name', 'short-name'(optional))

If you've set a string for the $tb-namespace variable in the config, you can use the namespace mixin, which will wrap all it's @content in the passes selector string. This is particularly useful when the code you want to namespace is spread out through several files, as changing the namespace becomes much easier and less error prone.

As for the full list of classes and their properties, they are as follows:

NameShortStyles
.static.staposition: static;
.relative.relposition: relative;
.absolute.absposition: absolute;
.fixed.fixposition: fixed;
.inline-block.in-bldisplay: inline-block;
.inline.indisplay: inline;
.block.bldisplay: block;
.table.tbdisplay: table;
.table-row.trdisplay: table-row;
.table-cell.tddisplay: table-cell;
.hidden.hidedisplay: none;
.flex.fldisplay: flex;
.inline-flex.in-fldisplay: inline-flex;
.float-left.flo-lfloat: left;
.float-right.flo-rfloat: right;
.flip-horizontal.f-htransform: scaleX(-1); filter: FlipH;
.flip-vertical.f-vtransform: scaleY(-1); filter: FlipV;
.clear.clcontent: ''; display: block; clear: both;
.centered.cenmargin-right: auto; margin-left: auto;
.border-box.b-bobox-sizing: border-box;
.vertical-margin.v-marmargin-left: initial; margin-right: initial;
.horizontal-margin.h-marmargin-top: initial; margin-bottom: initial;
.vertical-padding.v-padpadding-left: initial; padding-right: initial;
.horizontal-padding.h-padpadding-top: initial; padding-bottom: initial;
.#-padding.#-padpadding: #px;
.#-margin.#-marmargin: #px;
.full-width.f-wiwidth: 100%;
.half-width.h-wiwidth: 50%;
.third-width.t-wiwidth: 33.33%;
.quarter-width.q-wiwidth: 25%;
.full-height.f-heheight: 100%;
.half-height.h-heheight: 50%;
.third-height.t-heheight: 33.33%;
.quarter-height.q-heheight: 25%;
.text-center.t-centext-align: center;
.text-left.t-letext-align: left;
.text-right.t-ritext-align: right;
.text-middle.t-midvertical-align: middle;
.bold.bfont-weight: bold;
.italic.ifont-style: italic;
.underlined.untext-decoration: underlined;
.line-through.li-ttext-decoration: line-through;
.uppercase.uptext-transform: uppercase;
.lowercase.lowtext-transform: lowercase;
.capitalize.captext-transform: capitalize;
.small-caps.sm-captext-variant: small-caps;
.#-font.#-ffont-size: #px; font-size: #rem;
.#-background.#-bgbackground-color: #;
.#-text.#-tcolor: #;
.#-borders.#-bborder-color: #;
.#-hide.#-hdisplay: none;
.#-show.#-sdisplay: none;

Breakpoints

When working on responsive design, you can use the breakpoint, below and above mixins, by passing the first a keyword from the $tb-breakpoints list, and the other two a pixel width they should apply styles to. Additionally they take a @content block, which are the rules they'll apply. For instance:

@include breakpoint(small) { .element-to-modify-on-small-screens { background-color: red; } }

You also have the listed above media classes, ending in -show and -hidden. These classes will be generated for each element in your breakpoints list, and when added to an element will either show or hide it based on the screen width.

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago