feat: add FilteredList component

This commit is contained in:
Sebin Nyshkim 2023-07-18 21:50:06 +02:00
parent d196c1e680
commit f100c524af

View file

@ -0,0 +1,295 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { Kink } from '@/interfaces'
interface Props {
data: Kink[]
}
const props = defineProps<Props>()
const filterOptions = ref<number[]>([])
const filteredItems = computed(() =>
props.data
.sort((a, b) => a.rating - b.rating)
.filter((kink) => filterOptions.value.some((filterNum) => kink.rating === filterNum))
)
const toLabel = (rating: number) => {
switch (rating) {
case 1:
return 'Love'
case 2:
return 'Yes'
case 3:
return 'Maybe'
case 4:
return 'No'
}
}
</script>
<template>
<div class="filter-list">
<div class="filter-list__filters">
<input type="checkbox" name="rating" id="fave" :value="1" v-model="filterOptions" />
<label for="fave" class="filter-list__button love">Love</label>
<input type="checkbox" name="rating" id="like" :value="2" v-model="filterOptions" />
<label for="like" class="filter-list__button yes">Yes</label>
<input type="checkbox" name="rating" id="maybe" :value="3" v-model="filterOptions" />
<label for="maybe" class="filter-list__button maybe">Maybe</label>
<input type="checkbox" name="rating" id="no" :value="4" v-model="filterOptions" />
<label for="no" class="filter-list__button no">No</label>
</div>
<div class="filter-list__list-container">
<template v-if="filterOptions.length > 0">
<ul class="filter-list__list">
<li v-for="(item, idx) in filteredItems" :key="idx" class="filter-list__item">
<span class="filter-list__item-name">
{{ item.name }}
<span
v-if="filterOptions.length > 1"
class="filter-list__tag"
:class="toLabel(item.rating)?.toLowerCase()"
>
{{ toLabel(item.rating) }}
</span>
</span>
<span class="filter-list__tag-list">
<span v-if="item.receive" class="filter-list__tag receive">receive</span>
<span v-if="item.give" class="filter-list__tag give">give</span>
</span>
</li>
</ul>
</template>
<template v-else>
<p class="filter-list__intro-msg">Select one of the categories above</p>
</template>
</div>
</div>
</template>
<style lang="scss">
.filter-list {
background: var(--quickfacts-background);
border-radius: 1rem;
box-shadow: var(--container-box-shadow);
&__options {
display: flex;
gap: 1rem;
margin: 0;
padding: 0;
list-style: none;
}
&__filters {
display: flex;
gap: 0.75rem;
border-collapse: collapse;
padding: 0.5rem 0.75rem;
input {
display: none;
&:checked + label {
top: 0.25rem;
box-shadow: 0 0.25rem 0 0 var(--color-button-box-shadow);
&.love {
box-shadow: 0 0.25rem 0 0 var(--theme-c-love-dark);
}
&.yes {
box-shadow: 0 0.25rem 0 0 var(--theme-c-yes-dark);
}
&.maybe {
box-shadow: 0 0.25rem 0 0 var(--theme-c-maybe-dark);
}
&.no {
box-shadow: 0 0.25rem 0 0 var(--theme-c-no-dark);
}
}
}
}
&__button {
flex: 1 1 0;
position: relative;
top: 0;
background-color: var(--color-button);
font-weight: 700;
text-decoration: none;
text-align: center;
margin: 0.5rem 0;
border-radius: 0.25rem;
padding: 0.5rem 1rem;
box-shadow: 0 0.5rem 0 0 var(--color-button-box-shadow);
transition: all 0.1s ease-out;
&:hover {
cursor: pointer;
top: -0.25rem;
box-shadow: 0 0.75rem 0 0 var(--color-button-box-shadow);
}
&:active {
top: 0.25rem;
box-shadow: 0 0.25rem 0 0 var(--color-button-box-shadow);
}
&.love {
background-color: var(--theme-c-love);
box-shadow: 0 0.5rem 0 0 var(--theme-c-love-dark);
&:hover {
box-shadow: 0 0.75rem 0 0 var(--theme-c-love-dark);
}
&:active {
box-shadow: 0 0.25rem 0 0 var(--theme-c-love-dark);
}
}
&.yes {
background-color: var(--theme-c-yes);
box-shadow: 0 0.5rem 0 0 var(--theme-c-yes-dark);
&:hover {
box-shadow: 0 0.75rem 0 0 var(--theme-c-yes-dark);
}
&:active {
box-shadow: 0 0.25rem 0 0 var(--theme-c-yes-dark);
}
}
&.maybe {
background-color: var(--theme-c-maybe);
box-shadow: 0 0.5rem 0 0 var(--theme-c-maybe-dark);
&:hover {
box-shadow: 0 0.75rem 0 0 var(--theme-c-maybe-dark);
}
&:active {
box-shadow: 0 0.25rem 0 0 var(--theme-c-maybe-dark);
}
}
&.no {
background-color: var(--theme-c-no);
box-shadow: 0 0.5rem 0 0 var(--theme-c-no-dark);
&:hover {
box-shadow: 0 0.75rem 0 0 var(--theme-c-no-dark);
}
&:active {
box-shadow: 0 0.25rem 0 0 var(--theme-c-no-dark);
}
}
}
&__intro-msg {
font-size: 3rem;
font-weight: bold;
font-style: italic;
text-align: center;
hyphens: none;
}
&__list-container {
border-top: 0.125rem solid var(--color-quickfacts-border);
border-collapse: collapse;
}
&__list {
max-height: 30rem;
margin: 0;
padding: 0;
overflow: scroll;
}
&__item {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding: 0.25rem 0.875rem;
&:hover {
background: rgba(#000, 0.3);
}
}
&__item-name {
line-height: 2;
}
&__tag-list {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
gap: 0.5rem;
}
&__tag {
font-size: 0.75rem;
font-weight: bold;
background: rgba(#f5f5f5, 0.7);
border: 1px solid #f5f5f5;
border-radius: 1em;
padding: 0 0.5em;
&.love {
background: var(--theme-c-love);
border: 1px solid var(--theme-c-love-dark);
}
&.yes {
background: var(--theme-c-yes);
border: 1px solid var(--theme-c-yes-dark);
}
&.maybe {
background: var(--theme-c-maybe);
border: 1px solid var(--theme-c-maybe-dark);
}
&.no {
background: var(--theme-c-no);
border: 1px solid var(--theme-c-no-dark);
}
&.receive {
background: var(--theme-c-receive);
border: 1px solid var(--theme-c-receive);
}
&.give {
background: var(--theme-c-give);
border: 1px solid var(--theme-c-give);
}
}
}
</style>