2021-06-04 08:57:18 +02:00
|
|
|
<script>
|
|
|
|
import { getContext } from "svelte"
|
2021-06-14 18:41:18 +02:00
|
|
|
import Placeholder from "./Placeholder.svelte"
|
2021-06-04 08:57:18 +02:00
|
|
|
|
2021-06-18 13:41:15 +02:00
|
|
|
const { styleable, builderStore } = getContext("sdk")
|
2021-06-04 08:57:18 +02:00
|
|
|
const component = getContext("component")
|
2021-06-14 18:41:18 +02:00
|
|
|
|
2021-06-04 08:57:18 +02:00
|
|
|
export let type = "mainSidebar"
|
2021-06-11 14:47:57 +02:00
|
|
|
export let minSize = 250
|
2021-06-04 14:34:52 +02:00
|
|
|
|
|
|
|
let layoutMap = {
|
|
|
|
mainSidebar: 2,
|
|
|
|
sidebarMain: 2,
|
|
|
|
twoColumns: 2,
|
|
|
|
threeColumns: 3,
|
|
|
|
}
|
2021-06-04 15:52:05 +02:00
|
|
|
|
|
|
|
let containerWidth
|
|
|
|
$: columnsDependingOnSize = calculateColumns(containerWidth)
|
|
|
|
|
|
|
|
function calculateColumns(parentWidth) {
|
2021-06-11 14:47:57 +02:00
|
|
|
const numberOfAllowedColumns = Math.floor(parentWidth / minSize) || 100
|
2021-06-04 15:52:05 +02:00
|
|
|
if (layoutMap[type] <= numberOfAllowedColumns) {
|
|
|
|
return false
|
|
|
|
} else if (layoutMap[type] > numberOfAllowedColumns) {
|
|
|
|
return numberOfAllowedColumns
|
|
|
|
}
|
|
|
|
}
|
2021-06-04 08:57:18 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div
|
2021-06-04 15:52:05 +02:00
|
|
|
bind:clientWidth={containerWidth}
|
|
|
|
class="{type} columns-{columnsDependingOnSize}"
|
2021-06-09 10:23:42 +02:00
|
|
|
use:styleable={$component.styles}
|
2021-06-04 08:57:18 +02:00
|
|
|
>
|
|
|
|
<slot />
|
2021-06-04 14:34:52 +02:00
|
|
|
{#if layoutMap[type] - $component.children > 0}
|
|
|
|
{#each new Array(layoutMap[type] - $component.children) as _}
|
2021-06-14 18:41:18 +02:00
|
|
|
<div class:placeholder={$builderStore.inBuilder}>
|
|
|
|
<Placeholder />
|
|
|
|
</div>
|
2021-06-04 14:34:52 +02:00
|
|
|
{/each}
|
|
|
|
{/if}
|
2021-06-04 08:57:18 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
display: grid;
|
|
|
|
grid-gap: 16px;
|
|
|
|
}
|
|
|
|
.mainSidebar {
|
2021-06-09 10:23:42 +02:00
|
|
|
grid-template-columns: 3fr 1fr;
|
2021-06-04 08:57:18 +02:00
|
|
|
}
|
|
|
|
.sidebarMain {
|
2021-06-09 10:23:42 +02:00
|
|
|
grid-template-columns: 1fr 3fr;
|
2021-06-04 08:57:18 +02:00
|
|
|
}
|
|
|
|
.twoColumns {
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
}
|
|
|
|
.threeColumns {
|
|
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
|
|
}
|
2021-06-04 15:52:05 +02:00
|
|
|
.columns-1 {
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
}
|
|
|
|
.columns-2 {
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
}
|
2021-06-14 18:41:18 +02:00
|
|
|
.placeholder {
|
2021-07-05 15:02:49 +02:00
|
|
|
border: 2px dashed var(--spectrum-global-color-gray-600);
|
2021-06-14 18:41:18 +02:00
|
|
|
padding: var(--spacing-l);
|
|
|
|
}
|
2021-06-04 08:57:18 +02:00
|
|
|
</style>
|