Skip to content

Commit

Permalink
💎 style(util.ts): truncate long texts
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinsOnuoha committed Oct 28, 2023
1 parent 65b8faf commit 1432455
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/components/AppCategory/AppCategory.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts" setup>
import { useDark } from '@vueuse/core'
import type { PropType } from 'vue'
import type { Category } from '@/stores/db'
import { randomChoice } from '@/utils/util'
Expand Down
3 changes: 2 additions & 1 deletion src/components/AppStatementCard/AppStatementCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { PropType } from 'vue'
import type { Statement } from '@/stores/db'
import { useDBStore } from '@/stores/db'
import AppCategory from '@/components/AppCategory/AppCategory.vue'
import { truncate } from '../../utils/util'
const props = defineProps({
statement: { type: Object as PropType<Statement>, required: true }
Expand All @@ -17,7 +18,7 @@ const getCategories = useDBStore().categories.filter(
<div class="AppStatementCardContainer" tabindex="0">
<div class="AppStatementCard">
<div class="AppStatementCard__content">
{{ statement.description }}
{{ truncate(statement.description) }}
</div>
<div class="AppStatementCard__categories">
<AppCategory v-for="(category, index) in getCategories" :key="index" :category="category" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppStatementCard/_AppStatementCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@apply bg-white h-52 w-full shadow-none cursor-pointer p-5 rounded-lg relative hover:bg-gradient-to-tr from-amber-100 via-transparent to-transparent text-[var(--color-dark-text)];
border: 1px solid var(--color-border-gray);
&__content {
@apply text-lg;
@apply text-lg max-h-32;
}

&__categories {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function randomChoice<T>(arr: Array<T>): T {
return arr[Math.floor(Math.random() * arr.length)]
}

export function truncate(text: string, MAX_COUNT = 178): string {
return text.length > MAX_COUNT ? `${text.slice(0, MAX_COUNT)}...` : text
}

0 comments on commit 1432455

Please sign in to comment.