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 new component: show/hide truncated text #66

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions comparisons/components/show_hide_truncated_text/caniuse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Target: http://caniuse.com/#feat=css-sel3
line-camp: http://caniuse.com/#search=line-clamp
Flex: http://caniuse.com/#search=flex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p data-height="265" data-theme-id="light" data-slug-hash="WGBzZa" data-default-tab="html,result" data-user="srekoble" data-embed-version="2" class="codepen">See the Pen <a href="http://codepen.io/srekoble/pen/WGBzZa/">show/hide text with row truncate</a> by Vangel Tzo (<a href="http://codepen.io/srekoble">@srekoble</a>) on <a href="http://codepen.io">CodePen</a>.</p>
7 changes: 7 additions & 0 deletions comparisons/components/show_hide_truncated_text/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="show-hide-text">
<a id="show-more" class="show-less" href="#show-less">Show less</a>
<a id="show-less" class="show-more" href="#show-more">Show more</a>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vangel Tzo show/hide text: http://codepen.io/srekoble/pen/WGBzZa
79 changes: 79 additions & 0 deletions comparisons/components/show_hide_truncated_text/scss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@mixin row-truncate($rows, $line-height, $background: '') {
position: relative;
overflow: hidden;
max-height: $line-height * $rows;
line-height: $line-height;

&:after {
content: "";
position: absolute;
right: 0;
bottom: 0;
width: 100px;
height: $line-height;

@if $background != '' {
background: -moz-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba($background, 0)), color-stop(100%, rgba($background, 1)));
background: -webkit-linear-gradient(left, rgba($background, 0) 0%,rgba($background, 1) 100%);
background: -o-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%);
background: -ms-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%);
background: linear-gradient(to right, rgba($background, 0) 0%, rgba($background, 1) 100%);
}
}

// If supports line-clamp then add an ellipsis overflow and hide the gradient
// This will work in Chrome and Opera, otherwise a gradient will gradually hide the text.

@supports (-webkit-line-clamp: $rows) {
display: -webkit-box;
-webkit-line-clamp: $rows;
-webkit-box-orient: vertical;

&:after {
display: none;
}
}
}

.show-hide-text {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;

a {
-webkit-box-ordinal-group: 3;
-webkit-order: 2;
-ms-flex-order: 2;
order: 2;
}

p {
@include truncate(3, 20px, #fff); // rows, line-height, gradient fallback
}
}

.show-less {
display: none;

&:target {
display: block;

~ p {
display: block;
max-height: 100%;

&:after {
display: none;
}
}

+ a {
display: none;
}
}
}