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

[Docs] Hide example code by default #2888

Closed
mbrookes opened this issue Jan 12, 2016 · 20 comments
Closed

[Docs] Hide example code by default #2888

mbrookes opened this issue Jan 12, 2016 · 20 comments
Labels
docs Improvements or additions to the documentation

Comments

@mbrookes
Copy link
Member

Given the number of examples for some components resulting in a large page, (even with some of the code hidden as it currently is), and due to the scrolling behaviour when scrolling past the partially shown code, I think it would look cleaner, and be easier to navigate to the properties if we hide the example code completely by default.

I have made a simple change locally (but not submitted yet) that looks like this:

Code hidden (default)

screen shot 2016-01-12 at 01 03 22

#### Code revealed

screen shot 2016-01-12 at 01 12 02

Let me know what you think.

@oliviertassinari
Copy link
Member

I had the same feeling. I have reduced the number of displayed lines from 17 to 7. That wasn't deployed, the material-ui website still use 17 lines.
Do you think it's enought?

@oliviertassinari
Copy link
Member

due to the scrolling behaviour when scrolling past the partially shown code

Well, that's a good point.

@mbrookes
Copy link
Member Author

Hi Olivier, yes, I had looked at it with the reduction to 7 and it's certainly an improvement, but personally I still think it looks cleaner and is easier to navigate with the code hidden.

Another benefit is comparing different component variations side-by-side.

I know css frameworks often show the markup, but usually it is just a few lines of html / css inline with the docs.

@oliviertassinari
Copy link
Member

Well, that sounds like a good idea. I'm up for it. Let see what @alitaheri and @newoga think.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Jan 12, 2016
@oliviertassinari
Copy link
Member

I was also wondering, we will have more space, should we add a title to each example?

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

@mbrookes @oliviertassinari Yeah I agree how the examples are currently shown could be improved. Still not completely sure about best approach and haven't tinkered myself but I think @mbrookes suggestion is worth a shot.

@mbrookes Could you make a PR so I can check out the branch?

I think it would look cleaner, and be easier to navigate to the properties if we hide the example code completely by default.

Another idea (that maybe could be done in addition) is to put id tags on examples and props. We could link to the props from the top.

@mbrookes
Copy link
Member Author

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

Mm, yeah I think I like this better 👍

I think I agree that a title for example could be worth it, might help give each example more context, though I'd be curious to see how it looks and I'm not sure how easy it would be to appropriately naming the examples (naming things is hard).

Adding a new title bar on the top of the example would probably take up too much space. However, the bar that has Show the code could be a good place to put a title, but only if we can have the title stay in that position and not cascade to the bottom of the example, that could be confusing.

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

For what it's worth, I still think at some point we should look at implementing number 2 of this list.

The API/props docs would be nice to have in its own section.

@mbrookes
Copy link
Member Author

@newoga I'd had the same thought about giving the examples some context.

Are you proposing to have the title appear beside the button when collapsed, but above the code when opened?

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

@mbrookes Yeah that's what I currently have in mind but it's just an idea. I'm not sure if that would work well in reality. Feel free to take a stab if you have some time.

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

Another idea is to do it similarly to angular material. https://material.angularjs.org/latest/demo/autocomplete

They just put everything, including the code above the rendered example.

What they do is actually pretty interesting because they almost write docs for the example inline with the rendered element. So it doesn't seem like a random element in a box. That also helps with the "context" problem.

@mbrookes
Copy link
Member Author

Okay, let me have a go at that.

@mbrookes
Copy link
Member Author

Ok, take a look: https://github.com/mbrookes/material-ui/tree/docs-hide-examples

The first example in AppBar is the only one I've updated to take full advantage of the new layout, but hopefully you can see the potential.

CodeBlock now has a title-bar (which is an AppBar), and takes an optional title and description prop.

title defaults to "Example", and description is blank by default, so docs updates to add a title ad description can be dome in stages while still looking fine with the defaults.

The description can be markdown, either in a string in SomeComponent/Page.jsx or optionally in its own file, as in the AppBar example - probably only necessary for longer descriptions, but we can agree on the best approach.

The whole title-bar is currently clickable to open the code example, but that can easily be changed, for example if we manage to get CodePen or similar working at some point and want to add another icon to the title-bar. And I'm not set on the icon, it was the first one that seemed remotely relevant, so can be happily changed.

Hope you like it! 😀

@mbrookes
Copy link
Member Author

Code hidden (default)

screen shot 2016-01-13 at 00 28 26

Code revealed

screen shot 2016-01-13 at 00 29 43

@newoga
Copy link
Contributor

newoga commented Jan 12, 2016

Mmmmmm, I like it! Nice work! 👍 I'd probably be fine with the code icon. I'll check the latest from you branch and try it out in a bit.

@oliviertassinari @alitaheri Thoughts?

@oliviertassinari
Copy link
Member

I love it 😍. @newoga I agree with you for the icon.

@mbrookes
Copy link
Member Author

Found, it thanks - now updated. I'll submit a PR for review, as I'm sure there will be other tweaks needed.

@mbrookes
Copy link
Member Author

I've updated the screenshots.

@alitaheri
Copy link
Member

Wow! nice work @mbrookes It's fantastic 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

No branches or pull requests

4 participants