auto-wrapping on size collapse

This commit is contained in:
Keviin Åberg Kultalahti 2021-06-04 15:52:05 +02:00
parent f2139849ee
commit 1ce9089d3a
1 changed files with 23 additions and 2 deletions

View File

@ -12,12 +12,24 @@
twoColumns: 2, twoColumns: 2,
threeColumns: 3, threeColumns: 3,
} }
let containerWidth
$: columnsDependingOnSize = calculateColumns(containerWidth)
function calculateColumns(parentWidth) {
const numberOfAllowedColumns = Math.floor(parentWidth / 250) || 100
if (layoutMap[type] <= numberOfAllowedColumns) {
return false
} else if (layoutMap[type] > numberOfAllowedColumns) {
return numberOfAllowedColumns
}
}
</script> </script>
<div <div
bind:clientWidth={containerWidth}
in:transition={{ type: $component.transition }} in:transition={{ type: $component.transition }}
use:styleable={$component.styles} class="{type} columns-{columnsDependingOnSize}"
class={type}
> >
<slot /> <slot />
{#if layoutMap[type] - $component.children > 0} {#if layoutMap[type] - $component.children > 0}
@ -44,6 +56,15 @@
.threeColumns { .threeColumns {
grid-template-columns: 1fr 1fr 1fr; grid-template-columns: 1fr 1fr 1fr;
} }
.containerSmall {
grid-template-columns: 1fr;
}
.columns-1 {
grid-template-columns: 1fr;
}
.columns-2 {
grid-template-columns: 1fr 1fr;
}
p { p {
background-color: var(--grey-3); background-color: var(--grey-3);