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

Make code snippets collapsed blocks that could be expanded #212

Open
pmackay opened this issue Jan 4, 2017 · 2 comments
Open

Make code snippets collapsed blocks that could be expanded #212

pmackay opened this issue Jan 4, 2017 · 2 comments

Comments

@pmackay
Copy link

pmackay commented Jan 4, 2017

It would support a more compact, visually focussed styleguide if the code blocks could be displayed collapsed by default and be dynamically expanded if the user wishes to review them.

Is there any current way to do this? Would it be of interest to others?

@vkoves
Copy link

vkoves commented Oct 8, 2017

Conveniently, this is fully possible with the current system!

Here's a GIF of a quick demo of this I made. Although you can't see my cursor in the GIF, I'm clicking on the block to toggle it.

peek 2017-10-08 01-59

I achieved this by taking advantage of the fact that you can just put in CSS and JS into your styleguide files.

Here's the example block being used:

<div class="red-back">
	Some nice long structure
	<ul>
		<li>One</li>
		<li>Two</li>
	</ul>
</div>
@css {
	.red-back {
		background: #ffbbbb;
		padding: 10px;
	}
}

And then some code I inserted after it that creates the styling and functionality for the toggleable code block. I've commented the snippet so it's clear what it does.

<!-- Import jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
// Prepend a clickable area and hide code by default
$(".lsg-code-block").prepend('<div class="toggle-code">Toggle Code</div>');
$(".lsg-code").hide();

// Make all code blocks toggle the inner code on click
$(".lsg-code-block").click(function() {
	$(this).children(".lsg-code").slideToggle();
});
</script>
@scss {
	.lsg-code-block {
		padding: 0px;

		> * { padding: 10px; }
		.toggle-code { background: #c1c1c1; }
	}
}

Not sure if the issue creator still needs this solved, but hopefully this helps out anyone else looking for something like this.

@hagenburger
Copy link
Member

I’m thinking of an API to attach such code (maybe as plug in) for the next version.

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

No branches or pull requests

3 participants