Move game description to its own component and clamp extra long text

This commit is contained in:
Roman Cervantes 2019-11-21 13:49:58 -07:00
parent 2855955172
commit 02ddb5cb83
2 changed files with 77 additions and 8 deletions

View file

@ -0,0 +1,73 @@
<template lang="html">
<div class="game-description" @click="expand">
<p :class="{ collapsed }">
{{ game.summary }}
</p>
<a class="read-more" v-if="collapsed">Read more</a>
</div>
</template>
<script>
import { mapState } from 'vuex';
export default {
data() {
return {
expanded: false,
characterLimit: 500,
};
},
computed: {
...mapState(['game']),
collapsed() {
return !this.expanded && this.game.summary && this.game.summary.length > this.characterLimit;
}
},
methods: {
expand() {
if (this.collapsed) {
this.expanded = true
};
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
@import "~styles/styles";
.game-description {
margin-bottom: $gp;
}
p {
line-height: 1.4rem;
font-size: 16px;
letter-spacing: .01em;
&.collapsed {
margin-bottom: $gp / 2;
@media($small) {
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 6;
-webkit-box-orient: vertical;
}
}
}
.read-more {
display: none;
@media($small) {
display: inline;
}
}
</style>

View file

@ -1,3 +1,4 @@
<!-- TODO: rename to Game.vue -->
<template lang="html">
<div class="game-detail">
<header>
@ -30,8 +31,7 @@
</div>
<div v-if="game" class="details">
<p class="game-description" v-html="game.summary" />
<game-description />
<div class="actions">
<button
@ -93,6 +93,7 @@ import GameNotes from '@/components/GameNotes';
import GameTags from '@/components/GameDetail/GameTags';
import GameRating from '@/components/GameDetail/GameRating';
import GameLinks from '@/components/GameDetail/GameLinks';
import GameDescription from '@/components/GameDetail/GameDescription';
import GameVideos from '@/components/GameDetail/GameVideos';
import GameDetails from '@/components/GameDetail/GameDetails';
import Platform from '@/components/Platforms/Platform';
@ -105,6 +106,7 @@ export default {
IgdbCredit,
GameRating,
GameLinks,
GameDescription,
Placeholder,
GameScreenshots,
GameNotes,
@ -231,12 +233,6 @@ aside {
}
}
.game-description {
line-height: 1.4rem;
font-size: 16px;
letter-spacing: .01em
}
.actions {
display: flex;
align-items: center;