Skip to main content

Posts

Showing posts from 2014

Naming Booleans

Naming conventions are one of those little things that can become a big thing when you multiply the scale of the project and/or people involved. I was just looking through some code yesterday, and I saw a variable with a fairly typical boolean name that followed the format isObjectState This felt awkward to me, and I took a moment to consider why this is. In Logic, a boolean is a statement that is either true or false . However, this variable name is written as a yes or no question. It is an easy misconception to equate true with yes and false with no , but though they are similar, they are not exactly the same, and, especially as programmers, we should not treat them as such. When we expand our variables into full sentences, the awkwardness becomes more apparent. Especially when we insert them into control structures. Let’s rename our variable to: is this menu item active? So our control blocks will read: if is this menu item active?, then highlight it. while is this men

Automatically Calculating Foreground Color using SASS

I ran into the problem, as I'm sure many others have, where I wanted to dynamically assign background colors to my components, but also needed to adjust the foreground color to be readable and visually appealing. It's easy for something to fall through the cracks when changing colors, and then we end up with unreadable text. So to try and avoid this, I put together a SASS function that selects a color for text based on the background color you give it. This also performs checks to make sure the contrast meets a given Accessibility spec (as per W3C rules). So far I've had pretty good results with it. Please feel free to tinker and use this in your own projects. It's far from perfect, but it has See the Pen Calculate Foreground Color by Thomas Pietrosanti ( @Rykus0 ) on CodePen .

SASS Mixin for Creating CSS Triangles

I feel like one of the most common shapes that we can reliably create with CSS vs images is the triangle. One of the reasons for this is that it works as far back as IE7 (IE6 works, but doesn't support background-color: transparent ). Another is how frequently a little triangle icon can be used (e.g., ascending/descending buttons, expanding menus, open/close state, etc.) I'm not going to cover the techniques of creating triangles with CSS . That's been done already , and probably better than I would do it. What I'm going to share with you, is a little SASS mixin that I've been using to generate triangles. See the Pen SASS Triangles by Thomas Pietrosanti ( @Rykus0 ) on CodePen . I'm using a SASS placeholder ( %triangle-base ) as a base to contain the common styles. This makes it easy to extend without generating tons of extra code each time I want to make a triangle. When this compiles, it creates a rule that applies to all of th