SASS Tutorial (build your own CSS library) #13 - Functions
Skills:
HTML & CSS53%
Key Takeaways
Builds a SASS library using various SASS features
Full Transcript
all right then gang so the next thing i want to talk about is functions in sas and functions are kind of like mix-ins but they're very different as well whereas a mix-in will give us a load of different properties or group them together and also taking arguments for those properties a function instead will return normally a single value it might take in an argument it might do some manipulation with that and at the end it returns a single value which we can sometimes use for properties so this is a function right this is a built-in function this lighting function in sas and what that does is taking some arguments and returns to us a value which we use for the background color so what we're essentially going to do is create a new function a custom function like this that takes in maybe an argument or it might not need to take an argument and then returns a value now to demonstrate this i'm going to create another variant of our button so we have the normal buttons for each of the different colors which is button hyphen primary or secondary et cetera then we have the outlined variant now we're going to create a third one which i'm going to paste in called button complement hyphen whatever the key is so primary secondary etc now we're still including the button mixing and passing in the value as the color so it's still going to do exactly the same as this so far however this time what we're going to do is override the color of the button so we're going to have a color property right here and to do this we want to create a function which is going to get us a complementary color to whatever we use right here so if it's primary we're going to get a complementary color for that so to do this let's create a functions file inside the shinobi folder so underscore functions.scss okay then so to create a function we say at function then we give it a name i'm going to call it light hyphen comp so it's a complementary color which we're also going to lighten and inside this function we're going to take in an argument which is going to be a color so we could pass in the color primary for example and it's going to find us the complementary color for that color and also lighten it once we have it so inside here i'm going to create first of all a variable and we can do that inside functions we can just create variables for inside this function and this is going to be called complement now to get this complementary color first of all we are just going to use a built-in function in sas which is called complement and we can pass in the color so it gets us the complementary color for whatever we pass in right here the second thing we want to do is lighten that so i'll create another variable which is called light and then complement like that and i'm going to set that equal to oops i think this is spelt complement not complement i'm going to set that equal to another built-in function lighten but passing this value right here the complementary color so now we're doing two things with our value that we pass in and then at the end all i'm going to do is return so that's at return to return a value and it's going to be this variable right here the light complement okay and that's all there is to it so we've taken in a color we've done a little bit of manipulation and it could be more complex than this i didn't want to do something too complex because i just want to demonstrate how we use these functions and return the values at the end of it so it takes in that doesn't manipulation and then returns a value at the end so now i could first of all include the functions at the top over here i'm going to say at import and it's the functions file we want i'm going to save that and then inside this button components for the color of this complement button i'm going to call that function so all i need to do is say light hyphen comp which is the name of the function and we can use it remember because the button component inside the index is imported after the functions so we can use it inside the buttons file we're going to pass in the value which is the color so that could be the primary color or purple or red or something else in our color map all right then i also want to give this a background color on hover so i'm going to say background hyphen color and again we're going to call that function and we'll say light hyphen comp and passing the vowel so when we hover over this the background color is going to change to this to begin with just the color of the text is this all right so let's save that and head over to our index file so that we can use this new variant of the button inside the template so if we scroll down to the bottom of the buttons i'm going to paste in two more so two anchor tags the first one has a class of button hyphen complement hyphen purple so it's gonna run the function for this purple color and find a complementary color for that and the second one is button hyphen complement hyphen primary so i'm going to save this now and then preview it in a browser now i can see those two buttons but they don't seem to be working so let me just go back and have a look at what's going on here and we can see in the terminal that we get this error and it says we need an amount basically for the lighting function we're not passing that in as a second argument so we need to pass in how much we basically want to lighten this buy in a percentage so i'll say 30 percent and i'm going to save that and then hopefully there's gonna be no error and now we can preview this in a browser and we can see these two buttons right here so the text at the minute is the complementary color which is also a bit lighter to the background and when we hover over it they switch around awesome
Original Description
Hey gang, in this SASS tutorial you'll learn how to use SASS functions.
🐱👤 Get the full SASS course now on Net Ninja Pro:
https://netninja.dev/p/complete-sass-tutorial
🐱👤 Get access to all other premium courses on Net Ninja Pro:
https://netninja.dev/
🐱💻 Access the course files on GitHub:
https://github.com/iamshaunjp/complete-sass-tutorial
🐱💻 HTML & CSS Crash Course:
On Net Ninja Pro - https://netninja.dev/p/html-css-crash-course
On YouTube - https://www.youtube.com/watch?v=hu-q2zYwEYs&list=PL4cUxeGkcC9ivBf_eKCPIAYXWzLlPAm6G
🐱💻 Modern JavaScript Course:
On Net Ninja Pro - https://netninja.dev/p/modern-javascript-from-novice-to-ninja
On YouTube - https://www.youtube.com/watch?v=iWOYAxlnaww&list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc
🐱💻 CSS Flexbox Course (on YouTube):
https://www.youtube.com/watch?v=Y8zMYaD1bz0&list=PL4cUxeGkcC9i3FXJSUfmsNOx8E7u6UuhG
🐱💻 SASS docs - https://sass-lang.com/documentation
🐱💻 VS Code - https://code.visualstudio.com/
-------------- Net Ninja Links:
🐱💻 My Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
🐱👤 Get access premium courses on Net Ninja Pro:
https://netninja.dev/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
Building a Browser-Based Tiled Poster PDF Generator
Dev.to · Gaven
3 Next.js Micro-Interactions to Make Your App Feel Premium
Dev.to · jackke88
Test your vanilla JS app in the real browser, with no build step
Dev.to · Kevin Julián Martínez Escobar
Modern Frontends Don’t Have One “Ready” State
Dev.to · Markus Gasser
🎓
Tutor Explanation
DeepCamp AI