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,37 +4,50 @@
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> {:else if label === Labels.fish}
{:else if label === Labels.fish} <li class="fish"><Fish weight="fill" /></li>
<li class="fish"><Fish weight="fill" /></li> {:else if label === Labels.nut}
{:else if label === Labels.nut} <li class="nut"><Acorn weight="fill" /></li>
<li class="nut"><Acorn weight="fill" /></li> {:else if label === Labels.gluten}
{:else if label === Labels.gluten} <li class="gluten"><GrainsSlash weight="fill" /></li>
<li class="gluten"><GrainsSlash weight="fill" /></li> {:else if label === Labels.spicy}
{:else if label === Labels.spicy} <li class="spicy"><Pepper weight="fill" /></li>
<li class="spicy"><Pepper weight="fill" /></li> {/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 {
margin: 0;
}
} }
li {
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,84 +21,89 @@
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 { > li {
padding: 0 0 0 $spacing-normal; margin: 0 0 0 -15px;
display: flex;
flex-direction: row;
> li {
margin: 0 0 0 -15px;
width: 30px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
border-radius: $border-radius-circle;
background-color: $color-dark;
color: $color-on-dark;
list-style: none;
&.vegan {
background-color: $color-vegan;
}
&.fish {
background-color: $color-fish;
}
&.nut {
background-color: $color-nut;
}
&.gluten {
background-color: $color-gluten;
}
&.spicy {
background-color: $color-spicy;
}
}
}
> a {
padding-left: 10px;
padding-right: 10px;
width: 30px;
height: 30px; height: 30px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
text-decoration: none;
font-size: 14px;
border-radius: $border-radius-circle; border-radius: $border-radius-circle;
background-color: $color-dark; background-color: $color-dark;
color: $color-on-dark; color: $color-on-dark;
&:hover { list-style: none;
background-color: $color-light;
color: $color-on-light; &.vegan {
background-color: $color-vegan;
}
&.fish {
background-color: $color-fish;
}
&.nut {
background-color: $color-nut;
}
&.gluten {
background-color: $color-gluten;
}
&.spicy {
background-color: $color-spicy;
} }
} }
} }
.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;
} }
} }