Recall & Review
beginner
What is component variant generation in Sass?
It is a way to create different styles of the same component by reusing code with small changes, like colors or sizes, using Sass features like mixins or functions.
Click to reveal answer
beginner
How does a Sass mixin help in generating component variants?
A mixin lets you write reusable style blocks that accept parameters. You can change these parameters to create different variants of a component without repeating code.
Click to reveal answer
intermediate
What Sass feature allows you to loop through variant names to generate styles automatically?
The @each directive lets you loop over a list or map of variant names and generate CSS for each variant, making variant generation efficient.
Click to reveal answer
intermediate
Why is using maps useful in component variant generation?
Maps store key-value pairs like variant names and their colors. This helps organize variant data and makes it easy to loop through and apply styles dynamically.
Click to reveal answer
beginner
Show a simple example of a Sass mixin for button variants with color as a parameter.
@mixin button-variant($color) {
background-color: $color;
color: white;
padding: 0.5rem 1rem;
border-radius: 0.25rem;
border: none;
cursor: pointer;
}
// Usage:
.button-primary {
@include button-variant(blue);
}
.button-danger {
@include button-variant(red);
}
Click to reveal answer
Which Sass feature is best for creating reusable style blocks with parameters?
✗ Incorrect
Mixins allow reusable style blocks that accept parameters to customize styles.
What Sass directive helps you loop through a list or map to generate multiple variants?
✗ Incorrect
@each loops through lists or maps to generate repeated styles.
Why use maps in Sass for component variants?
✗ Incorrect
Maps store key-value pairs, useful for organizing variant data.
What is the main benefit of generating component variants in Sass?
✗ Incorrect
Variant generation reduces repetition and keeps code DRY (Don't Repeat Yourself).
Which of these is NOT a good practice when generating variants?
✗ Incorrect
Hardcoding each variant separately leads to repetitive code and is not efficient.
Explain how you would use Sass mixins and loops to create multiple button color variants.
Think about passing colors to a mixin and looping through them to generate classes.
You got /4 concepts.
Describe the advantages of using maps in Sass for component variant generation.
Maps help keep variant info tidy and accessible.
You got /4 concepts.