-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add article and sidebar menu organisms and main/sidebar template #86
Conversation
var menuToggle = document.querySelector('.mzp-js-toggle'); | ||
|
||
// Add class to reflect javascript availability for CSS | ||
$doc.className = $doc.className.replace(/\bno-js\b/, 'js'); |
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.
This is may be redundant here and would collide with any other scripts doing the same thing. We should consider some kind of minimal global JS as part of protocol-core, even if all it does is set this class.
OR we can totally rethink it and not rely on this root-level script-is-working indicator. Each component can make its own check and set a class for a style hook for that component, but it sure is handy to have one hook in one place.
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 think ideally this piece of JS should be run in the <head>
, so as to avoid content flicker. So making this a piece of global JS probably makes sense?
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 added a protocol-base.js that so far does nothing but this JS detection class but could possibly include other essentials down the road.
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.
A few comments / suggestions but this looks great. Nice work!
var menuToggle = document.querySelector('.mzp-js-toggle'); | ||
|
||
// Add class to reflect javascript availability for CSS | ||
$doc.className = $doc.className.replace(/\bno-js\b/, 'js'); |
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 think ideally this piece of JS should be run in the <head>
, so as to avoid content flicker. So making this a piece of global JS probably makes sense?
(function() { | ||
'use strict'; | ||
|
||
var $doc = document.documentElement; |
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.
Nit: rename variable to doc
? (the $
is a carryover from jQuery days gone by)
// Toggle the sidebar menu | ||
menuToggle.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
menu.classList.toggle('mzp-is-active'); |
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.
This toggle on small screens here is currently a <section>
element, which isn't ideal for a11y. I'd suggest adding some aria roles here? Using aria-role="button"
would give context that the element is clickable, but we could also add arai-controls
and then aria-expanded
to the menu itself and toggle the state?
src/assets/sass/demos/article.scss
Outdated
@@ -0,0 +1,567 @@ | |||
// Define paths | |||
$font-path: '/assets/protocol/protocol/fonts'; |
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.
These paths are already set in docs/protocol.scss
along with the imports below. Could we import that here (in the same way the type demo does) to avoid repeating?
src/assets/sass/demos/article.scss
Outdated
'../protocol/components/sidebar-menu'; | ||
|
||
|
||
// Article links... is this a component? |
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've been struggling with this too, and settled on that if something is an organism it should probably be classed as a component. But then we have two names for the same thing which seems... confusing. Maybe something we could bikeshed on later?
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.
This was a holdover from the security page this was originally based on, and on that page at least this set of links is a one-off thing. We'll have to figure out what to do about that when we're actually reskinning the security pages in bedrock, but I think for now I can just delete this bit here since we're not using it in the demo.
|
||
li { | ||
margin-bottom: .25em; | ||
|
||
&:before { | ||
content: '•'; |
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.
Just curious, what's the rationale for using a pseudo element for list styles over allowing the browser to manage it - just for more control over size/spacing?
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.
Yeah, just for size and spacing. We can talk to Vince about it but this was what bulleted lists looked like in the mockup so I tried to match it. I'm happy with browser defaults if the designers are.
text-align: left; | ||
padding-bottom: 1px; /* fix to get it to look nice in many browsers */ | ||
margin-bottom: -1px; | ||
@include bidi(((text-align, left, right),)); |
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.
🔥
.mzp-c-article { | ||
max-width: $content-md; | ||
|
||
// Step down the heading levels |
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.
The frequency that we seem to do this suggests we probably need to revisit our default heading levels. Maybe something we should open an issue for discussion on?
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.
A revision of the type scale is in the works.
RTL: float: right; | ||
A list with four properties overrides the ltr value in rtl locales | ||
AND provides a new rtl only property value | ||
@include bidi(((margin-right, 20px, margin-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.
Should this be @include bidi(((margin-right, 10px, margin-left, 0),))
?
<li><a href="#">And one more menu item</a></li> | ||
</ul> | ||
</section> | ||
</nav> |
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.
Include the JS for the side menu here?
<script src="/assets/protocol/protocol/js/protocol-sidemenu.min.js"></script>
One minor thing: The concatJS gulp task is joining every JS file in |
var menu = document.querySelector('.mzp-c-sidemenu'); | ||
var menuToggle = document.querySelector('.mzp-js-toggle'); | ||
|
||
// Add class to reflect javascript availability for CSS |
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.
Should we remove this from the sidemenu JS now that we have a separate base JS file?
This doesn't need to be a blocker, but currently we aren't compiling any CSS files for either the article or side menu, and it's up to the consuming site to compile the sass. This might be ok if it's what we decide we want to do, but it's currently not possible to include |
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.
A couple of suggestions, and an open question about if we should publish the compiled CSS files for these new components. But I think this is just about ready to merge? There are no doubt more things we will continue tweaking in the CSS, but we can always follow up later.
Yeah I've been thinking about the best way to publish components without creating one huge monolith. Dozens of individual CSS files isn't any better than one big one (probably worse). For bedrock we'll do our own compilation anyway and just @import the components we need per page, but longer term if we want to offer pre-compiled CSS we'll probably need to make a tool to pick your components, like https://foundation.zurb.com/sites/download.html/#customizeFoundation In the short term we'll still need to get these components published and consumable as SCSS. Taking more inspiration from what Spark is doing, I think we'll need to make a separate package for protocol-components. |
In an http2 world, I think making individual CSS files is probably the better solution honestly. Sites will move away from bundling, and monolith CSS/JS files will be considered an anti-pattern. We could go all the way to publish a separate package a-la |
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.
Couple of things to tidy up in the menu JS, but otherwise r+wc
menuExpanded = 'true'; | ||
} | ||
menuMain.setAttribute('aria-expanded', menuExpanded); | ||
alert(menuExpanded); |
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.
Remove alert
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.
Doh.
--- | ||
|
||
<nav class="mzp-c-sidemenu"> | ||
<section class="mzp-c-sidemenu-summary mzp-js-toggle" aria-role="button" aria-controls=""> |
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 think the value for aria-controls
should be the ID of the menu?
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.
Should both this and aria-role="button"
be set in the JS along with where you set tabindex
? They probably don't apply when JS is disabled?
menu.classList.toggle('mzp-is-active'); | ||
|
||
menuExpanded = menuMain.getAttribute('aria-expanded'); | ||
if (menuExpanded == 'true') { |
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.
You could make this logic a little simpler with something like:
var menuExpanded = menuMain.getAttribute('aria-expanded') == 'true' ? 'false' : 'true';
var menu = document.querySelector('.mzp-c-sidemenu'); | ||
var menuMain = document.querySelector('.mzp-c-sidemenu-main'); | ||
var menuToggle = document.querySelector('.mzp-js-toggle'); | ||
var menuExpanded; |
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 don't think this variable needs to be in this scope for any reason, you can probably just declare it inside the click
even listener?
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.
🎉
🍾 |
For #37
This introduces a bunch of new bits and slightly updates a few existing bits. It looks bigger than it is, but it does have lots of small changes going on.
Staged at https://demo2--mozilla-protocol.netlify.com/