New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature navbar #146
Feature navbar #146
Conversation
Compoiled -> Compiled
- Filename matches format of other standard files in the repo (README, etc.) - Include title and copyright notice per the template text: - http://choosealicense.com/licenses/isc/ - https://opensource.org/licenses/isc-license - http://spdx.org/licenses/ISC.html#licenseText
The new navbar looks great, but I think the bottom-border on each links is a bit too big. What are your thoughts @rhyneav? |
The SCSS could still need a bit of cleanup. @dallinbjohnson you can further nest some selectors and use the resp mixing for the |
I have never worked with SCSS before and I looked at the resp mixin and I am not sure how to integrate it into my code. I did everything that I understood the rest is a little confusing to me. sorry. @koester |
Being new or not knowing something is not a problem at all. We've all been there. When I'm at the office I'll edit this comment and explain how to use the resp mixing (or scss mixins in general) and give you some examples. By just reading the code it's sometimes hard to see the bigger picture, especially when you're new to scss. I'll show you why this mixing exists and how it solves a common problem. -- Ok let's dive into it. To ensure a consitent style in colors, breakpoints, sizes and general layout PaperCSS uses a special papercss/src/core/_config.scss Lines 66 to 70 in c395349
These variables define the screen width of the most common breakpoints. These range from $large-screen: 1200px to $xsmall-screen: 480px . You could read them like this:
$large-screen: 1200px !default; // For Laptops
$medium-screen: 992px !default; // Tablets in landscape mode
$small-screen: 768px !default; // Tablets in portrait mode
$xsmall-screen: 480px !default; // Smartphones Why did we define those? When you need a breakpoint to get your component to be responsive (just like you did with the So in theory you dont have to find out when your navbar should change "states", because the first time you probably want a burger navigation, instead of the usual navbar, is for tablet and smartphone devices. So you could just write something like this: @media (max-width: $small-screen) {
nav .collapsible .collapsible-body {
display: contents;
}
} and the SCSS compiler will translate it for you to: @media (max-width: 768px) {
nav .collapsible .collapsible-body {
display: contents;
}
} Nice! Now we dont have to remeber the 768px breakpoint everytime we need it, because we know that the Thaaaat's where the papercss/src/core/_config.scss Lines 129 to 138 in c395349
This is how I read that code: // A new mixin with the name 'resp' is defined and its arguments '$max' and '$min' are given a default value of null. That is if you include the mixin without providing any arguments, both of them will be null. If you provide just one, the other will default to null.
@mixin resp($max:null, $min:null) {
// These if-conditions check if the first argument ($max) is either large, medium, small or xsmall or the shorter syntax lg, md, sm and xs. If you include the mixin with @include resp(large) {...} this if-condition will resolve to true. If it is true, the value of $max will change from null (the default) to $large-screen.
// In a sentance this would read as:
// Is $max equal to the string 'large' or 'lg'? If so, change the value of $max to $large-screen. If not, go on to the next line. Now lets see if $max is equal to the string 'medium' or 'md'. If so, change the value of $max to $medium-screen. If not, go on to the next.
@if $max == large or $max == lg { $max: $large-screen; }
@if $max == medium or $max == md { $max: $medium-screen; }
@if $max == small or $max == sm { $max: $small-screen; }
@if $max == xsmall or $max == xs { $max: $xsmall-screen; }
// After those checks we check one last time if $min and $max are NOT null. This way we allow the user to use the mixin with a pixel, em or rem value for a custom breakpoint and also check if the mixin was included with atleast one parameter.
// If $min AND $max are not equal to null then the mixin will return @media only screen and (max-width: $max) and (min-width: $min) { ... }
@if ($min != null and $max != null) {@media only screen and (max-width: $max) and (min-width: $min) { @content; }}
// If $max is not equal to null but $min is still null the mixin will return @media only screen and (max-wdith: $max) {...}
@else if($max != null and $min == null){@media only screen and (max-width: $max) { @content; }}
// If $min is not equal to null but $max is still null the mixin will return @media only screen and (min-width: $min) { ... }
@else if($min != null and $max == null){@media only screen and (min-width: $min) { @content; }}
// If not a single if condition before this line was met then it will throw an error.
@else { @error "no matching size found";}
} So how do we apply this now? Consider this simple example: .box {
width: 50%;
} We have a Class with the name .box {
width: 50%;
@include resp(small) {
width: 100%;
}
}
// CSS Output
.box {
width: 50%;
}
@media only screen and (max-width: 768px) {
.box {
width: 100%;
}
} Doesn't that read a lot better? Just by looking at the code you know that the .box will change its width from 50% to 100% when the given screen size is met. The compiled CSS output will stay the same as to what you wrote before, but I didnt have to remember what exact value my width needed to be. I just used the variables defined in the config. This also allows for 'stacking' breakpoints. Maybe the box should be 75% for laptops? Sure: .box {
width: 50%;
@include resp(medium) {
width: 75%;
}
@include resp(small) {
width: 100%;
}
}
// CSS:
.box {
width: 50%;
}
@media only screen and (max-width: 992px) {
.box {
width: 75%;
}
}
@media only screen and (max-width: 768px) {
.box {
width: 100%;
}
} Again, just by reading the SCSS Code now it is made clear how the box will behave. The mixin allows you to set breakpoints in a fast and consistent manner and also "connect" the @media queries to the class you want to change, instead of having your class definitions at the top of the file and the media-queries at the bottom. nav {
ul.inline {
padding: 0;
margin-bottom: 0;
li {
display: inline-block;
margin: 0 .5rem;
@include resp(small) {
margin: 0 1rem;
}
&:before {
content: "";
}
a {
font-size: 1.3rem;
}
}
}
}
//CSS:
nav ul.inline {
padding: 0;
margin-bottom: 0;
}
nav ul.inline li {
display: inline-block;
margin: 0 .5rem;
}
@media only screen and (max-width: 768px) {
nav ul.inline li {
margin: 0 1rem;
}
}
nav ul.inline li:before {
content: "";
}
nav ul.inline li a {
font-size: 1.3rem;
} With nesting you can create a logical hierarchy and save yourself the time to write the same selector more than once. nav ul.inline { ... }
nav ul.inline a { ... }
nav ul.inline h1 { ... }
nav ul.inline h2 { ... }
nav ul.inline p { ... } You could just do nav {
ul.inline {
a { ... }
h1 { ... }
h2 { ... }
p { ... }
}
} This will give you the exact same css output above, but it is easier to read, easier to maintain and a lot faster to write. We could even take this a step further if we consider that the nav {
ul {
li { }
}
} So <nav>
<ul>
<li></li>
</ul>
</nav> With nesting selectors and & we can mimic this in our SCSS files. But what about a case where we dont want to go a level deeper but stay on the same level? How could we possibly say that the .inline class should not be inside of ul but on the ul element itself. This is how we do it: nav {
ul {
&.inline {
li { color: pink; }
}
li { color: blue }
}
} The nav ul.inline li {
color: pink;
}
nav ul li {
color: blue;
} To really see what the SCSS compiler is doing to your code behind the scenes and how the SCSS code you write will translate to plain CSS I'd advice you to play around with https://www.sassmeister.com/. When I was starting to learn SCSS this was a great way to learn for me. Give it a try. Another great resource to learn SCSS is the official starter guide: http://sass-lang.com/guide Try to apply the new things you've learned to your navbar component. I apologize for any spelling mistakes and if you still have some questions left or anything I just wrote is unclear feel free to ask. |
src/components/_navbar.scss
Outdated
-webkit-transform: rotate(45deg) translate(-8px, -9px); | ||
transform: rotate(45deg) translate(-8px, -9px); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see a pattern here. Is there a way to further nest those selectors and reduce the duplicated code?
src/components/_navbar.scss
Outdated
top: 0; | ||
right: 0; | ||
left: 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different Classes for the same parent? How could you nest them together so you only have one nav
with everything else nested inside?
I'm usually more of a reader than a writer. But for $5 I'll start a blog 😂🍻 |
@koester thoughtsofkoester.com |
@rhyneav Oh shieeet, thats one hell of a domain name for a blog. Now I'm really thinking of starting one. Just this small problem remains.. what the hell should I blog about? 🤔 @dallinbjohnson Do you need further help? If there are still questions left feel free to ask. |
Sorry I have not had time to work on this I am working and going to school. It's getting close to finals. I will make time to work on it though. Everything that you taught me was great it really helped me understand. |
How do I create another pull request with the changes that I have made to my feture-navbar? @rhyneav |
You can just add additional commits to this If you want a fresh PR, you can copy your
Then open a new PR through Github. |
what are the checks that are not successful? and is there anything else I need to change to make my code so it can be merged? @rhyneav |
I think the checks are giving an error because of the way npm is being installed in the test runner. I'm working on the fix in another branch. I don't think they're breaking from anything you're adding, don't worry! Before getting your code merged in, make sure you are working off of the develop branch. With this, in Github, request to merge into the develop branch (rather than master). Also, @koester gave some great advice about DRYing up your code. Could you refactor your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit:
Nevermind, you already fixed it. Very good job! I didnt see your last commit before I submitted my review, so dont mind what I just wrote 🎉
Looks great @dallinbjohnson thank you for taking care of those edits! Since this PR and #145 are identical, I'll merge #145 into develop since it is already pointing at it. Great work, very excited to have a navbar added to PaperCSS! |
Brief description
reformatted the scss.
Developer Certificate of Origin
Sample pictures
...
Further details
...