Skip to content
Nubgrammer
Menu
  • Home
  • Contact Me
Menu
Spray.JS Featured Image

Is this Framework a Good Idea?

Posted on November 3, 2018November 3, 2018 by Tyler Sells

Alright, so I need some opinions on something I’m working on.  It’s a JS/CSS/LESS framework that is designed to handle all the colors in a website or web app.

Here’s the repo for the project if you don’t want to bother reading the rest of the post:

https://github.com/vtsells/Spray

And here is a VERY rough demo. Remember, it’s still in alpha:
(enter a selector like h3, choose a spray class, and hit the add button)

This is some of the JS that’s driving the demo.  addDiv fires when the corresponding button is clicked to demo the spray.watchFor() function:

function addDiv() {
    const div = document.createElement("div");
    const p = document.createElement("p");
    p.textContent="Some text";
    div.appendChild(p);
    div.classList.add("some-class");
    div.style.padding = "10px";
    document.querySelector("p").appendChild(div);
}
(() => {

    const spray = new Spray();
    spray.addToSelector("p", "pri");
    spray.watchFor(document.querySelector("p"), [{ ".some-class": "sec" },{ "p": "ter hover" }])
    sprayWidget(spray);
})();

And here are what the classes will look like. All of these colors are based off one LESS color variable:

Why?

In an effort to bolster my portfolio, I decided to pick up a project I started a year or two ago.  When I was first learning the Bootstrap 3 framework, there was something that always nagged me.  I didn’t like that Bootstrap decided what colors I had to use for pretty much everything in my app unless I wanted to override a bunch of things.  While I did find this site that helps tremendously with building a custom-themed Boostrap implementation, it still didn’t give me the control I wanted.

What happens if I sell an app to a customer who wants the color scheme of the app to match their company colors?  Does it make sense to create a new Bootstrap theme entirely?  What if I sold a copy of the app to 10 different people and they all wanted different color schemes?  Is that 10 different themes that I now have to manage and backup?

My Solution:

Enter LESS variables and color functions.  I use LESS for pretty much all of my CSS these days.  Using variables to hold a starting color and then the built-in LESS color functions to manipulate them, it’s super easy to build a simple (or complex) color pallet based off a single color.

This is what I did.  I built some mixins that create a whole bunch of classes that I can use to manage the colors of my apps.  Then, I built a JS script that will add and remove classes to selected elements either on-the-fly or when the document is finished loading.  I think this all counts as a framework, right?

.contrast-text-color(@color) {
  color: contrast(@color, @quaternary, lighten(@primary, 50%), 50%);
}
.color-style-inner(@color) {
  background: @color;
  &.text {
    background: unset;
    color: @color;
  }
  &.hover:hover {
    background: lighten(@color, 15%);
    .contrast-text-color(lighten(@color, 15%));
  }
}
.color-style(@color) {
  .color-style-inner(@color);
  .contrast-text-color(@color);
  &.bordered {
    border: 5px solid darken(@color, 15%);
  }
  &.trans-light {
    .color-style-inner(fade(@color, 90%));
  }
  &.trans {
    .color-style-inner(fade(@color, 60%));
  }
  &.trans-heavy {
    .color-style-inner(fade(@color, 30%));
  }
}

The other advantage of this is that all colors can be completely decoupled from any positioning or typography frameworks that you may be using.

It’s Alpha…

So this is my first foray into the world of developing a JS plugin/framework.  I don’t even know if you can really call it that.  However, it’s an alpha project that I would love to get some feedback on.  Would this be something useful to you?  What features would you like to see?  Is it even a good idea to manage colors this way?  I’m working on a true demo site that will demonstrate things much better in regards to component styling and live color pallet changes but that takes time and I wanted to get this idea out there.

Author: Tyler Sells

Github

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • More
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Reddit (Opens in new window) Reddit

Like this:

Like Loading...

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow me on Twitter

My Tweets

Github Repos

vtsells (Tyler Sells)

Tyler Sells

vtsells
http://www.nubgrammer.com
Joined on Jun 21, 2017
9 Public Repositories
100DaysOfCode
embers
MultiSelect
MVC-Project-Start
nubgrammer.com
PermIT
Spray
vtsells.github.io
Wizard
0 Public Gists

Categories

  • #100DaysOfCode (4)
  • ASP.NET (7)
  • ASP.NET Core (1)
  • ASP.NET MVC (3)
  • CSS (4)
  • General (13)
  • JS (3)
  • LESS (2)
  • Snippets (4)
  • Tools (4)
  • Tutorials (9)

Recent Posts

  • Creating a Knockout.js project on Codepen
  • 100DaysOfCode Day 3 – A State of Mind
  • 100DaysOfCode Day 2 – The Building Blocks
  • 100DaysOfCode Day 1 (Sort of cheated already)
  • Committing to #100DaysOfCode
© 2025 Nubgrammer | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT
%d

    Privacy Policy