Skip to content

Instantly share code, notes, and snippets.

@starryeyez024
Created June 24, 2015 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save starryeyez024/f02d6680448f3802985d to your computer and use it in GitHub Desktop.
Save starryeyez024/f02d6680448f3802985d to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<h1>Theming UI Components</h1>
<p>Each component needs to be aware that it may be used within a colour scheme so it needs to own the process
of creating the various classes required to support different uses. Sometimes semantic classes are the way forward,
but perhaps we should just allow the use of names to describe the particular style (think Solarized & Darcula, not Primary, Secondary, Success, etc.)</p>
<p>Here we create a themes map, which contains the colour definitions for a variety of named themes.
This makes it easier to re-use a colour scheme across components and removes the cases where
two component modifier classes (with different names) confusingly implement the same colour scheme.
e.g. no <code>.btn--primary</code> and <code>.panel--brand</code> which actually use the same colours</p>
<p>Read more about this approach in this blog post - <a href="http://www.ian-thomas.net/a-sassy-approach-to-theming-components/" class="link-t-sassmeister-dark">A Sassy Approach To Theming Components</a></p>
<hr class="rule"/>
<div class="band codepen">
<h2 class="heading">Codepen Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band codepen-light">
<h2 class="heading">Codepen light Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band sassmeister">
<h2 class="heading">Sassmeister Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band sassmeister-dark">
<h2 class="heading">Sassmeister Dark Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
// ----
// libsass (v3.2.5)
// ----
// Boilerplate code and basic styles
$color-primary: #fff;
$color-primary-background: #E86EA4;
body {
line-height: 1.5;
padding: 2% 10%;
color: #5B5B5B;
font-family: "Helvetica";
}
.band {
padding: 20px;
margin: 20px 0;
}
.note {
padding: 2em;
font-size: 1.2rem;
font-weight: 300;
margin: 2em 0 2em 4em;
width: 50%;
}
.note--small {
font-size: 0.8rem;
padding: 0.5em 1em;
margin: 1em 0;
}
.note--inline {
display: inline-block;
}
.rule {
border: 0;
margin: 2em 0;
width: 100%;
height: 1px;
background-color: #ccc;
}
.btn {
display: block;
width: 100%;
padding: 0.8em 1em;
margin-bottom: 0.8em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial;
font-size: 1.2em;
border-width: 1px;
border-style: solid;
&:after {
content: attr(class);
margin-left: 6px;
font-style: italic;
opacity: 0.5;
}
}
a {
font-weight: bold;
}
//////////////////////////
// THEMES
/**
Themes are all stored in a map data-structure which gives flexibilty
when traversing based on keys and also looking up values based on strings
*/
$themes: (
sassmeister: (
foreground: #efefef,
background: #E86EA4,
border: darken(#E86EA4, 10),
emphasis: darken(#FFFFFF, 10),
subtle: lighten(#E86EA4, 10),
highlight: lighten(#E86EA4, 10),
radius: 0
),
sassmeister-dark: (
foreground: #E86EA4,
background: #eee,
border: darken(#fff, 10),
emphasis: darken(#E86EA4, 10),
subtle: lighten(#E86EA4, 10),
highlight: darken(#fff, 10),
radius: 0
),
codepen: (
foreground: #CCCCCC,
background: #1D1F20,
border: #000000,
emphasis: darken(#999999, 10),
subtle: lighten(#999999, 10),
highlight: lighten(#1D1F20, 10),
radius: 3px
),
codepen-light: (
foreground: #1D1F20,
background: #e8e8e8,
border: darken(#F2F2F2, 15),
emphasis: lighten(#1D1F20, 10),
subtle: darken(#1D1F20, 10),
highlight: darken(#F2F2F2, 10),
radius: 3px
),
info: (
foreground: #FFFFFF,
background: #809BBD,
border: darken(#809BBD, 15),
subtle: darken(#FFFFFF, 10),
highlight: lighten(#809BBD, 10),
radius: 6px,
font-style: italic
)
);
@function get-theme($name) {
@return map-get($themes, $name);
}
/**
* This function should warn if a theme requirement isn't met,
* helping to catch any issues at compile time in development
*/
@function requires($themeName, $props) {
$theme: get-theme($themeName);
@each $key in $props {
@if (map-has-key($theme, $key) == false) {
@warn "To use this theme requires #{$key} to be set in the map";
@return false;
}
}
@return true;
}
//////////////////////////
// Band theme
$band-requirements: foreground;
@mixin band-theme($name) {
$theme: map-get($themes, $name);
.#{$name}.band {
background-color: map-get($theme, "foreground");
}
}
//////////////////////////
// Links
$link-requirements: foreground emphasis;
@mixin link-theme($name) {
$theme: get-theme($name);
.link-t-#{$name} {
color: map-get($theme, foreground);
&:hover, &:active {
color: map-get($theme, emphasis);
}
}
}
//////////////////////////
// Buttons
$button-requirements: foreground background border radius highlight;
@mixin button-theme($name) {
$theme: map-get($themes, $name);
.#{$name} .btn {
color: map-get($theme, "foreground");
background-color: map-get($theme, "background");
border-color: map-get($theme, "border");
border-radius: map-get($theme, "radius");
&:hover {
background-color: map-get($theme, "highlight");
}
}
}
//////////////////////////
// Notes
$note-requirements: background foreground; // font-style is optional
@mixin note-theme($name) {
$theme: map-get($themes, $name);
.#{$name} .note {
background: lighten(map-get($theme, "background"), 8%);
color: map-get($theme, "foreground");
@if map-has-key($theme, "font-style") {
font-style: map-get($theme, "font-style");
}
}
}
//////////////////////////
// Rule lines
$rule-requirements: background;
@mixin rule-theme($name) {
$theme: map-get($themes, $name);
.#{$name} .rule {
background-color: map-get($theme, "background");
}
}
//////////////////////////
// Headings
$heading-requirements: background;
@mixin heading-theme($name) {
$theme: map-get($themes, $name);
.#{$name} .heading {
color: map-get($theme, "background");
}
}
@each $themeName in map-keys($themes) {
@if (requires($themeName, $band-requirements)) {
@include band-theme($themeName);
}
@if (requires($themeName, $button-requirements)) {
@include button-theme($themeName);
}
@if (requires($themeName, $note-requirements)) {
@include note-theme($themeName);
}
@if (requires($themeName, $rule-requirements)) {
@include rule-theme($themeName);
}
@if (requires($themeName, $link-requirements)) {
@include link-theme($themeName);
}
@if (requires($themeName, $heading-requirements)) {
@include heading-theme($themeName);
}
}
body {
line-height: 1.5;
padding: 2% 10%;
color: #5B5B5B;
font-family: "Helvetica";
}
.band {
padding: 20px;
margin: 20px 0;
}
.note {
padding: 2em;
font-size: 1.2rem;
font-weight: 300;
margin: 2em 0 2em 4em;
width: 50%;
}
.note--small {
font-size: 0.8rem;
padding: 0.5em 1em;
margin: 1em 0;
}
.note--inline {
display: inline-block;
}
.rule {
border: 0;
margin: 2em 0;
width: 100%;
height: 1px;
background-color: #ccc;
}
.btn {
display: block;
width: 100%;
padding: 0.8em 1em;
margin-bottom: 0.8em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial;
font-size: 1.2em;
border-width: 1px;
border-style: solid;
}
.btn:after {
content: attr(class);
margin-left: 6px;
font-style: italic;
opacity: 0.5;
}
a {
font-weight: bold;
}
/**
Themes are all stored in a map data-structure which gives flexibilty
when traversing based on keys and also looking up values based on strings
*/
/**
* This function should warn if a theme requirement isn't met,
* helping to catch any issues at compile time in development
*/
.sassmeister.band {
background-color: #efefef;
}
.sassmeister .btn {
color: #efefef;
background-color: #E86EA4;
border-color: #e14288;
border-radius: 0;
}
.sassmeister .btn:hover {
background-color: #ef9ac0;
}
.sassmeister .note {
background: #ee91ba;
color: #efefef;
}
.sassmeister .rule {
background-color: #E86EA4;
}
.link-t-sassmeister {
color: #efefef;
}
.link-t-sassmeister:hover, .link-t-sassmeister:active {
color: #e6e6e6;
}
.sassmeister .heading {
color: #E86EA4;
}
.sassmeister-dark.band {
background-color: #E86EA4;
}
.sassmeister-dark .btn {
color: #E86EA4;
background-color: #eee;
border-color: #e6e6e6;
border-radius: 0;
}
.sassmeister-dark .btn:hover {
background-color: #e6e6e6;
}
.sassmeister-dark .note {
background: white;
color: #E86EA4;
}
.sassmeister-dark .rule {
background-color: #eee;
}
.link-t-sassmeister-dark {
color: #E86EA4;
}
.link-t-sassmeister-dark:hover, .link-t-sassmeister-dark:active {
color: #e14288;
}
.sassmeister-dark .heading {
color: #eee;
}
.codepen.band {
background-color: #CCCCCC;
}
.codepen .btn {
color: #CCCCCC;
background-color: #1D1F20;
border-color: #000000;
border-radius: 3px;
}
.codepen .btn:hover {
background-color: #35393b;
}
.codepen .note {
background: #303435;
color: #CCCCCC;
}
.codepen .rule {
background-color: #1D1F20;
}
.link-t-codepen {
color: #CCCCCC;
}
.link-t-codepen:hover, .link-t-codepen:active {
color: gray;
}
.codepen .heading {
color: #1D1F20;
}
.codepen-light.band {
background-color: #1D1F20;
}
.codepen-light .btn {
color: #1D1F20;
background-color: #e8e8e8;
border-color: #cccccc;
border-radius: 3px;
}
.codepen-light .btn:hover {
background-color: #d8d8d8;
}
.codepen-light .note {
background: #fcfcfc;
color: #1D1F20;
}
.codepen-light .rule {
background-color: #e8e8e8;
}
.link-t-codepen-light {
color: #1D1F20;
}
.link-t-codepen-light:hover, .link-t-codepen-light:active {
color: #35393b;
}
.codepen-light .heading {
color: #e8e8e8;
}
.info.band {
background-color: #FFFFFF;
}
.info .btn {
color: #FFFFFF;
background-color: #809BBD;
border-color: #52749e;
border-radius: 6px;
}
.info .btn:hover {
background-color: #a2b5ce;
}
.info .note {
background: #9bb0cb;
color: #FFFFFF;
font-style: italic;
}
.info .rule {
background-color: #809BBD;
}
.info .heading {
color: #809BBD;
}
<h1>Theming UI Components</h1>
<p>Each component needs to be aware that it may be used within a colour scheme so it needs to own the process
of creating the various classes required to support different uses. Sometimes semantic classes are the way forward,
but perhaps we should just allow the use of names to describe the particular style (think Solarized & Darcula, not Primary, Secondary, Success, etc.)</p>
<p>Here we create a themes map, which contains the colour definitions for a variety of named themes.
This makes it easier to re-use a colour scheme across components and removes the cases where
two component modifier classes (with different names) confusingly implement the same colour scheme.
e.g. no <code>.btn--primary</code> and <code>.panel--brand</code> which actually use the same colours</p>
<p>Read more about this approach in this blog post - <a href="http://www.ian-thomas.net/a-sassy-approach-to-theming-components/" class="link-t-sassmeister-dark">A Sassy Approach To Theming Components</a></p>
<hr class="rule"/>
<div class="band codepen">
<h2 class="heading">Codepen Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band codepen-light">
<h2 class="heading">Codepen light Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band sassmeister">
<h2 class="heading">Sassmeister Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
<div class="band sassmeister-dark">
<h2 class="heading">Sassmeister Dark Theme</h2>
<blockquote class="note">Names such as Primary, Secondary, etc. could and should be used to set other theme properties, such as size or font</blockquote>
<button class="btn">I'm a button</button>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment