What are a few things we need to pay attention to when making a custom component?
How to build a component that resembles a facebook post or tweet.
Create a
_post.scss
file and work exclusively in it.
Think of a base class that will act as the main anchor for all styles.
.post
.post{
}
We need to carefully think about our internal classes.
We want to leverage classes to prevent accidental conflicts.
.post{
/*This may inherit other properties if there
is another .title class somewhere */
.title{
}
}
.post{
/*This rule will not inherit any rules from other SCSS */
.post-title{
}
.post-body{
}
.post-author{
}
}
That's a lot of
.post
s
.post{
.post-{
&title{
}
&body{
}
&author{
}
}
}
.post .post-title{
}
.post .post-body{
}
.post .post-author{
}
You wont need to be as specific with our rules when you are nesting.
.post{
.post-{
&title{
}
&body{
}
&author{
.post-author-image{
}
}
}
}
.post{
.post-{
&title{
}
&body{
}
&author{
}
&author-image{
}
}
}
You may not always know what's going on with your global variables.
During development, your h3 bottom margin may go from 1.1 to 1.3.
You initially want 1.1 and don't declare it because the global style sheet declares it.
The change from 1.1 to 1.3 breaks your layout.
Be as specific as you can event when you don't think you need to.
Document everything.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-3685134-9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXX-X');
</script>
gtag('event', 'login');
gtag('event', 'event_name', {
'event_category': categoryName,
'event_label': labelName
});
////
gtag('event', 'login', {
'event_category': 'access',
'event_label': 'Google'
});