Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
Re-factoring your color can make it better.
You'll be working in Sassmeister for this course.
Like what you see and want to read more? Check out 'Sass in the Real World' for more on Advanced Sass!
-
0:00
We can even make this better, right?
-
0:01
So, let's go back and [SOUND] success.
-
0:08
Yeah we got success here primary?
-
0:11
So see how all that worked.
-
0:13
I'll get back to our blue button.
-
0:14
Here we go.
-
0:15
So, there's the original blue button that we we're working with.
-
0:18
So a quick refactor we can do with this tool is that say, I wanna do primary and
-
0:24
then success.
-
0:27
Right? And, [SOUND] so we have these two buttons,
-
0:33
but if we come back over here and
-
0:38
we make another button and we call this [SOUND] success.
-
0:45
Kay?
-
0:47
This works.
-
0:49
This is great.
-
0:50
This is good stuff.
-
0:52
But the problem that we have here is that we have all these rules for primary.
-
0:56
And then we have all these exact same rules for success.
-
1:00
So that is a lot of duplicated CSS for
-
1:03
no reason other than the pure sake of duplication.
-
1:06
So how we can make this better is I want to get this include
-
1:09
default-button out of here.
-
1:10
I'm gonna get rid of that guy.
-
1:11
Because we don't need that right now.
-
1:13
Now what I'm gonna do is that I'm going to create a placeholder selector.
-
1:18
[SOUND].
-
1:24
And in the placeholder selector here I'm going to create [SOUND] default-button.
-
1:33
And I'm gonna include that default-button there.
-
1:37
Then what I'm gonna do down here, is that inside of primary @extend default-button.
-
1:45
@extend default-button.
-
1:52
Put our semicolons in here, and then we have our buttons back.
-
1:56
So we have our green, we have our blue button.
-
1:59
And if we come over here and we look at our output CSS we see that primary and
-
2:02
success are reusing these rules.
-
2:04
And then primary success are only reusing, are only using the rules that need,
-
2:08
they need to use in order to make their individual things.
-
2:12
Okay.
-
2:13
So this is getting really awesome right now, but we can make it even better.
-
2:18
Okay? So getting back to
-
2:20
advanced color functions, we have four hex values here.
-
2:26
I don't wanna use four hex values.
-
2:27
I want, I wanna create all of these different things based off of
-
2:30
a single primary color.
-
2:32
So, we're just gonna use primary.
-
2:35
So success, warning, and alert are all gonna be derivatives of primary, right?
-
2:42
So one of the things that I can use is adjust hue.
-
2:45
Now adjust hue is another SASS color function.
-
2:49
And then what I can actually do is I'm going to take success here and I'm gonna
-
2:54
adjust the hue by 260 on the color wheel, and I'm gonna use that primary color.
-
2:59
All right?
-
3:00
So we have success and we're using success down there right here and
-
3:04
as we can see here you know, that's that same color green.
-
3:08
So then we can do the same thing with warning.
-
3:11
Now warning, let's just change that real quick.
-
3:15
[SOUND]. Okay.
-
3:16
So we have warning which is that orange.
-
3:20
So warning is warning is actually a combination of
-
3:23
a hue adjustment and saturation.
-
3:25
So to get this one in here, again, I'm chaining functions together and
-
3:30
I'm saying I want to adjust the hue of primary by 188 points on the color wheel,
-
3:35
but I wanna saturate it by 43.
-
3:37
Well, one too many.
-
3:38
And we get our final color again.
-
3:41
And again you know, this is the same orange we were working with before.
-
3:45
This is pretty awesome.
-
3:47
So let's use alert down here, so we have our alert red.
-
3:50
Now in order to get to that red again from our primary blue color,
-
3:58
what we are gonna use again is three color functions at the exact same time.
-
4:06
So, I'm going to adjust the hue of primary by 162 points on the color wheel.
-
4:10
I'm gonna saturate this by 12.
-
4:12
And I need, and I can have the ability to lighten it, as well.
-
4:16
So if I wanted just to make this a little bit lighter.
-
4:19
You know a little bit lighter.
-
4:20
You know, I have that ability to do that by chaining all of these things together.
-
4:24
So I, I like that one a little bit better, all right?
-
4:26
So, there you have it.
-
4:29
I mean, what's really cool here is I can come back in here [SOUND],
-
4:34
change that to purple.
-
4:36
Then, yeah of course purple's gonna get kind of weird, but
-
4:41
let's go back to maybe, red.
-
4:44
Woah, that's, that's a good one.
-
4:46
So, what we're showing here is that I can basically change one value here, and
-
4:51
then I can have that cascade down into all the different button
-
4:54
colors that are the different states for the buttons.
-
4:58
Then I can also generate, create a mixin which then at the point that
-
5:04
I'm calling in that mixin I can change the color of the button again on the fly.
-
5:09
And all the colors inside of that button be it, you know,
-
5:11
it's border, it's shadow, any type of highlights that we're putting on it.
-
5:15
All of these colors are generated on the fly just using SASS color functions.
-
5:20
And that's, is amazingly powerful to me.
-
5:23
Working with other designers, I asked them to help me in the definition of colors.
-
5:28
And not just give me the final hex value.
-
5:32
But what I'm really interested in is the process used in generating that color.
-
5:38
What is the application's core color palette.
-
5:41
When creating the new color I asked how did you get there.
-
5:45
If I can reproduce the how, versus just coding the end,
-
5:49
then we are way ahead of the game in changes coming down the road.
You need to sign up for Treehouse in order to download course files.
Sign up