Skip to content
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 a sidebar navigation to the styleguide #170

Open
jhilden opened this issue Aug 20, 2015 · 6 comments
Open

Add a sidebar navigation to the styleguide #170

jhilden opened this issue Aug 20, 2015 · 6 comments

Comments

@jhilden
Copy link
Contributor

jhilden commented Aug 20, 2015

For bigger styleguides it's very nice to have a fixed sidebar navigation to:
a) navigate to other parts of the styleguide
b) see where you are in the styleguide

This code inside my main .lsg file already works pretty decently:

@javascript-after transpiler: coffee-script
  $ ->
    $nav = $('<nav id="toc" class="lsg--toc"></nav>')

    $.each $('.lsg--anchor'), (index, anchor) ->
      $anchor = $ anchor
      $navLink = $ "<a href=\"#{$anchor.attr('href')}\">#{$anchor.parent().text()}</a>"
      $navLink.addClass "active" if index == 0
      $nav.append $navLink

    $('body').append $nav

    $(window).on 'scroll', ->
      scrollPosition = $(window).scrollTop()
      $firstVisibleHeadlineAnchor = $('.lsg--anchor').filter ->
        $(this).position().top >= scrollPosition

      $("#toc .active").removeClass 'active'
      $("#toc [href=#{$firstVisibleHeadlineAnchor.attr('href')}]").addClass 'active'
@sass
  @at-root
    .lsg--toc
      position: fixed
      top: 20px
      left: 0px
      width: 200px

      > a
        display: block
        padding: 2px 8px

        &.active
          font-weight: bold

      @media only screen and (max-width: 840px)
        display: none 

It's required that you have jQuery included in the stylguide.

It does not yet handle different levels of (sub)headlines.

This is what it currently looks like:
selection_011

@hagenburger
Copy link
Member

Our RailsGirlsSoC team planned on working on #72 next. This is a good start.

/cc @fanxhe-pair @freewomancode @anxhe

@jhilden
Copy link
Contributor Author

jhilden commented Aug 20, 2015

Sounds good. Let me know if I can help in any way.

@hagenburger
Copy link
Member

Let’s have the discussion in here. (FYI: They are based in Mexico and 7 h behind us.)

This should be released as a plugin. People might have very different requirements on a navigation.

I don’t know yet if we can implement everything in JavaScript. In future, the LivingStyleGuide should accept projects as inputs (in other words multiple in/output files). But maybe the navigation between and within a file are two different things anyway.

@jhilden
Copy link
Contributor Author

jhilden commented Aug 20, 2015

I can see the idea behind making this a plugin, however I personally would think this would be something useful for almost every styleguide. But that's not really important.

But maybe the navigation between and within a file are two different things anyway.

I also think that the navigation between pages of the styleguide and the navigation within one file should be somewhat separate UI components.

@hagenburger
Copy link
Member

For version 2 I’m fine with having it in. For later versions we should think about what is a core feature and what’s better delivered as plugin.

@anxhe
Copy link
Member

anxhe commented Aug 20, 2015

We have thought about doing it with ruby, would you like we use a filter to allow the user to choose how to display the menu: horizontal or vertical.

For the vertical one, we could use Jakob's styles, using the lsg-- variables.

This afternoon we will be looking at how to do it with ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants