Keep the Menu Items square, while filling container

This commit is contained in:
Michał 2024-05-05 14:22:30 +01:00
parent 200aa6b04f
commit 17476d3f2c
4 changed files with 119 additions and 90 deletions

View file

@ -4,19 +4,32 @@
import { type Item, Labels} from "../lib/types"; import { type Item, Labels} from "../lib/types";
import LoadingImage from '/MenuItemLoadingAlt.svg'; import LoadingImage from '/MenuItemLoadingAlt.svg';
import {onMount} from "svelte";
export let item: Item; export let item: Item;
let element: HTMLElement;
onMount(() => {
keepSquare();
})
function keepSquare() {
element.style.height = "";
element.style.height = element.offsetWidth + "px";
}
</script> </script>
<div class="menu-item"> <svelte:window on:resize={keepSquare}></svelte:window>
<div class="menu-item" bind:this={element}>
{#if item.images} {#if item.images}
<img src={item.images[0]} alt="" class="menu-item-image"> <img src={item.images[0]} alt="" class="menu-item-image">
{:else} {:else}
<img src={LoadingImage} alt="" class="menu-item-image"> <img src={LoadingImage} alt="" class="menu-item-image">
{/if} {/if}
<div class="menu-item-header"> <ul class="menu-item-labels">
<ul>
{#each item.labels as label} {#each item.labels as label}
{#if label === Labels.vegan} {#if label === Labels.vegan}
<li class="vegan"><Leaf weight="fill" /></li> <li class="vegan"><Leaf weight="fill" /></li>
@ -31,10 +44,10 @@
{/if} {/if}
{/each} {/each}
</ul> </ul>
<a href="/item/{item.uuid}" use:link>
<a class="menu-item-link" href="/item/{item.uuid}" use:link>
View&nbsp;<ArrowUpRight /> View&nbsp;<ArrowUpRight />
</a> </a>
</div>
<ul class="menu-item-detail"> <ul class="menu-item-detail">
<li>{item.name}</li> <li>{item.name}</li>

View file

@ -14,16 +14,24 @@
</ul> </ul>
<style lang="scss"> <style lang="scss">
@import "../styles/vars";
ul { ul {
list-style-type: none; list-style-type: none;
padding: 0; padding: 0;
margin: 0; margin: 0;
display: flex; display: grid;
flex-direction: row; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
flex-wrap: wrap; gap: $spacing-small;
gap: 16px
} > li {
li {
margin: 0; margin: 0;
} }
}
@media only screen and (max-width: 900px) {
ul {
grid-template-columns: 1fr 1fr 1fr;
}
}
</style> </style>

View file

@ -202,7 +202,14 @@
} }
} }
@media only screen and (max-width: 670px) { @media only screen and (max-width: 900px) {
#filter {
min-width: calc(250px - $spacing-normal);
max-width: calc(250px - $spacing-normal);
}
}
@media only screen and (max-width: 700px) {
.menu { .menu {
flex-direction: column; flex-direction: column;
} }

View file

@ -1,15 +1,8 @@
.menu-item { .menu-item {
padding: $spacing-normal; padding: $spacing-normal;
width: 200px;
height: 200px;
position: relative; position: relative;
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: $border-radius-large; border-radius: $border-radius-large;
background-color: $color-dark; background-color: $color-dark;
@ -28,20 +21,46 @@
z-index: 1; z-index: 1;
} }
.menu-item-header { .menu-item-link {
position: relative; padding-left: 10px;
padding-right: 10px;
height: 30px;
position: absolute;
top: $spacing-small;
right: $spacing-small;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
font-size: 14px;
border-radius: $border-radius-circle;
background-color: $color-dark;
color: $color-on-dark;
z-index: +2;
&:hover {
background-color: $color-light;
color: $color-on-light;
}
}
.menu-item-labels {
padding: 0;
position: absolute;
top: $spacing-small;
left: calc($spacing-normal + $spacing-small);
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between;
z-index: 2; z-index: +2;
> ul {
padding: 0 0 0 $spacing-normal;
display: flex;
flex-direction: row;
> li { > li {
margin: 0 0 0 -15px; margin: 0 0 0 -15px;
@ -75,37 +94,16 @@
background-color: $color-spicy; background-color: $color-spicy;
} }
} }
}
> a {
padding-left: 10px;
padding-right: 10px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
font-size: 14px;
border-radius: $border-radius-circle;
background-color: $color-dark;
color: $color-on-dark;
&:hover {
background-color: $color-light;
color: $color-on-light;
}
}
} }
.menu-item-detail { .menu-item-detail {
margin: -$spacing-normal;
padding: $spacing-normal; padding: $spacing-normal;
position: relative; width: 100%;
position: absolute;
left: 0;
bottom: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -119,5 +117,8 @@
> li { > li {
list-style: none; list-style: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
} }
} }